1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 02:49:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-08-06 00:08:19 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpgradient.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
#include "gimppenciltool.h"
|
|
|
|
#include "gimppainttool.h"
|
1999-04-22 22:34:00 +08:00
|
|
|
#include "paint_options.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "tool_options.h"
|
2001-03-12 07:28:16 +08:00
|
|
|
#include "tool_manager.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
#define PENCIL_INCREMENTAL_DEFAULT FALSE
|
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
|
|
|
|
static void gimp_pencil_tool_class_init (GimpPencilToolClass *klass);
|
|
|
|
static void gimp_pencil_tool_init (GimpPencilTool *pancil);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-04-07 19:01:22 +08:00
|
|
|
static void gimp_pencil_tool_paint (GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintState state);
|
|
|
|
static void gimp_pencil_tool_motion (GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintPressureOptions *pressure_options,
|
|
|
|
gboolean incremental);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
/* private variables */
|
|
|
|
static gboolean non_gui_incremental = PENCIL_INCREMENTAL_DEFAULT;
|
|
|
|
|
2001-04-01 04:41:39 +08:00
|
|
|
static PaintOptions *pencil_options = NULL;
|
2001-03-12 12:40:17 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
static GimpPaintToolClass *parent_class = NULL;
|
1999-08-14 04:50:30 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_pencil_tool_register (Gimp *gimp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_PENCIL_TOOL,
|
2001-03-12 12:40:17 +08:00
|
|
|
TRUE,
|
|
|
|
"gimp:pencil_tool",
|
|
|
|
_("Pencil"),
|
|
|
|
_("Paint hard edged pixels"),
|
|
|
|
N_("/Tools/Paint Tools/Pencil"), "P",
|
|
|
|
NULL, "tools/pencil.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_PENCIL);
|
2001-03-12 12:40:17 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-03-12 12:40:17 +08:00
|
|
|
gimp_pencil_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-03-12 12:40:17 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-03-12 12:40:17 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpPencilToolClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_pencil_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpPencilTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_pencil_tool_init,
|
2001-03-12 12:40:17 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_PAINT_TOOL,
|
|
|
|
"GimpPencilTool",
|
|
|
|
&tool_info, 0);
|
2001-03-12 12:40:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pencil_tool_class_init (GimpPencilToolClass *klass)
|
|
|
|
{
|
|
|
|
GimpPaintToolClass *paint_tool_class;
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
paint_tool_class = GIMP_PAINT_TOOL_CLASS (klass);
|
2001-03-12 12:40:17 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-12 12:40:17 +08:00
|
|
|
|
|
|
|
paint_tool_class->paint = gimp_pencil_tool_paint;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pencil_tool_init (GimpPencilTool *pencil)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
GimpPaintTool *paint_tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (pencil);
|
|
|
|
paint_tool = GIMP_PAINT_TOOL (pencil);
|
|
|
|
|
|
|
|
if (! pencil_options)
|
|
|
|
{
|
2001-04-01 04:41:39 +08:00
|
|
|
pencil_options = paint_options_new (GIMP_TYPE_PENCIL_TOOL,
|
|
|
|
paint_options_reset);
|
2001-03-12 12:40:17 +08:00
|
|
|
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_PENCIL_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) pencil_options);
|
2001-03-12 12:40:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tool->tool_cursor = GIMP_PENCIL_TOOL_CURSOR;
|
|
|
|
|
|
|
|
paint_tool->pick_colors = TRUE;
|
|
|
|
paint_tool->flags |= TOOL_CAN_HANDLE_CHANGING_BRUSH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pencil_tool_paint (GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintState state)
|
|
|
|
{
|
|
|
|
PaintPressureOptions *pressure_options;
|
|
|
|
gboolean incremental;
|
|
|
|
|
|
|
|
if (pencil_options)
|
|
|
|
{
|
2001-04-01 04:41:39 +08:00
|
|
|
pressure_options = pencil_options->pressure_options;
|
|
|
|
incremental = pencil_options->incremental;
|
2001-03-12 12:40:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressure_options = &non_gui_pressure_options;
|
|
|
|
incremental = non_gui_incremental;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (state)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
case INIT_PAINT:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
case MOTION_PAINT:
|
2001-03-12 12:40:17 +08:00
|
|
|
gimp_pencil_tool_motion (paint_tool, drawable,
|
|
|
|
pressure_options, incremental);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
case FINISH_PAINT:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
default:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_pencil_tool_motion (GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintPressureOptions *pressure_options,
|
2001-03-12 12:40:17 +08:00
|
|
|
gboolean incremental)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-12 07:28:16 +08:00
|
|
|
GimpImage *gimage;
|
2001-07-07 20:17:23 +08:00
|
|
|
GimpContext *context;
|
2001-01-15 05:11:52 +08:00
|
|
|
TempBuf *area;
|
|
|
|
guchar col[MAX_CHANNELS];
|
|
|
|
gint opacity;
|
|
|
|
gdouble scale;
|
2001-03-12 12:40:17 +08:00
|
|
|
PaintApplicationMode paint_appl_mode = incremental ? INCREMENTAL : CONSTANT;
|
2001-01-15 05:11:52 +08:00
|
|
|
|
|
|
|
if (! (gimage = gimp_drawable_gimage (drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
context = gimp_get_current_context (gimage->gimp);
|
|
|
|
|
1999-09-09 09:47:54 +08:00
|
|
|
if (pressure_options->size)
|
2001-11-14 00:21:34 +08:00
|
|
|
scale = paint_tool->cur_coords.pressure;
|
1999-09-09 09:47:54 +08:00
|
|
|
else
|
|
|
|
scale = 1.0;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Get a region which can be used to paint to */
|
2001-03-12 07:28:16 +08:00
|
|
|
if (! (area = gimp_paint_tool_get_paint_area (paint_tool, drawable, scale)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1999-11-13 09:02:27 +08:00
|
|
|
/* color the pixels */
|
|
|
|
if (pressure_options->color)
|
|
|
|
{
|
2001-01-21 00:28:05 +08:00
|
|
|
GimpRGB color;
|
2001-02-11 03:35:29 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_gradient_get_color_at (gimp_context_get_gradient (context),
|
2001-11-14 00:21:34 +08:00
|
|
|
paint_tool->cur_coords.pressure, &color);
|
2001-01-21 00:28:05 +08:00
|
|
|
|
|
|
|
gimp_rgba_get_uchar (&color,
|
|
|
|
&col[RED_PIX],
|
|
|
|
&col[GREEN_PIX],
|
|
|
|
&col[BLUE_PIX],
|
|
|
|
&col[ALPHA_PIX]);
|
|
|
|
|
1999-11-13 09:02:27 +08:00
|
|
|
paint_appl_mode = INCREMENTAL;
|
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height, area->bytes);
|
|
|
|
}
|
2001-03-12 07:28:16 +08:00
|
|
|
else if (paint_tool->brush && paint_tool->brush->pixmap)
|
1999-08-14 04:50:30 +08:00
|
|
|
{
|
1999-09-09 09:47:54 +08:00
|
|
|
/* if its a pixmap, do pixmap stuff */
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_paint_tool_color_area_with_pixmap (paint_tool, gimage, drawable,
|
|
|
|
area, scale, HARD);
|
Actually use the enum types GimpImageType, GimpImageBaseType,
* app/*.[ch]: Actually use the enum types GimpImageType,
GimpImageBaseType, LayerModeEffects, PaintApplicationMode,
BrushApplicationMode, GimpFillType and ConvertPaletteType, instead
of just int or gint. Hopefully I catched most of the places
where these should be used.
Add an enum ConvolutionType, suffix the too general constants
NORMAL, ABSOLUTE and NEGATIVE with _CONVOL. Use NORMAL_MODE
instead of NORMAL in some places (this was what was intended). Fix
some minor gccisms.
* app/apptypes.h: New file. This file contains the above
enumeration types, and some opaque struct typedefs. It was
necessary to collect these in one header that doesn't include
other headers, because when we started using the above mentioned
types in the headers, all hell broke loose because of the
spaghetti-like cross-inclusion mess between headers.
(An example: Header A includes header B, which includes header C
which includes A. B uses a type defined in A. This is not defined,
because A hasn't defined it yet at the point where it includes B,
and A included from B of course is skipped as we already are
reading A.)
1999-08-19 07:41:39 +08:00
|
|
|
paint_appl_mode = INCREMENTAL;
|
1999-08-14 04:50:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_get_foreground (gimage, drawable, col);
|
1999-11-13 09:02:27 +08:00
|
|
|
col[area->bytes - 1] = OPAQUE_OPACITY;
|
1999-08-14 04:50:30 +08:00
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height, area->bytes);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
opacity = 255 * gimp_context_get_opacity (context);
|
1999-09-09 09:47:54 +08:00
|
|
|
if (pressure_options->opacity)
|
2001-11-14 00:21:34 +08:00
|
|
|
opacity = opacity * 2.0 * paint_tool->cur_coords.pressure;
|
1999-08-14 04:50:30 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* paste the newly painted canvas to the gimage which is being worked on */
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_paint_tool_paste_canvas (paint_tool, drawable,
|
2001-03-12 12:40:17 +08:00
|
|
|
MIN (opacity, 255),
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_context_get_opacity (context) * 255,
|
|
|
|
gimp_context_get_paint_mode (context),
|
2001-03-12 12:40:17 +08:00
|
|
|
HARD, scale, paint_appl_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
|
|
|
|
/* non-gui stuff */
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
gboolean
|
|
|
|
pencil_non_gui (GimpDrawable *drawable,
|
2001-04-07 19:01:22 +08:00
|
|
|
gint num_strokes,
|
|
|
|
gdouble *stroke_array)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-12 12:40:17 +08:00
|
|
|
static GimpPencilTool *non_gui_pencil = NULL;
|
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
GimpPaintTool *paint_tool;
|
2001-03-12 12:40:17 +08:00
|
|
|
gint i;
|
2001-03-12 07:28:16 +08:00
|
|
|
|
|
|
|
if (! non_gui_pencil)
|
2001-03-12 12:40:17 +08:00
|
|
|
{
|
2001-08-10 22:41:39 +08:00
|
|
|
non_gui_pencil = g_object_new (GIMP_TYPE_PENCIL_TOOL, NULL);
|
2001-03-12 12:40:17 +08:00
|
|
|
}
|
2001-03-12 07:28:16 +08:00
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
paint_tool = GIMP_PAINT_TOOL (non_gui_pencil);
|
2001-03-12 07:28:16 +08:00
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
if (gimp_paint_tool_start (paint_tool, drawable,
|
|
|
|
stroke_array[0],
|
|
|
|
stroke_array[1]))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-14 00:21:34 +08:00
|
|
|
paint_tool->start_coords.x = paint_tool->last_coords.x = stroke_array[0];
|
|
|
|
paint_tool->start_coords.y = paint_tool->last_coords.y = stroke_array[1];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_pencil_tool_paint (paint_tool, drawable, MOTION_PAINT);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
2001-04-07 19:01:22 +08:00
|
|
|
{
|
2001-11-14 00:21:34 +08:00
|
|
|
paint_tool->cur_coords.x = stroke_array[i * 2 + 0];
|
|
|
|
paint_tool->cur_coords.y = stroke_array[i * 2 + 1];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-04-07 19:01:22 +08:00
|
|
|
gimp_paint_tool_interpolate (paint_tool, drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-14 00:21:34 +08:00
|
|
|
paint_tool->last_coords.x = paint_tool->cur_coords.x;
|
|
|
|
paint_tool->last_coords.y = paint_tool->cur_coords.y;
|
2001-04-07 19:01:22 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_paint_tool_finish (paint_tool, drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-03-12 07:28:16 +08:00
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
return FALSE;
|
2001-03-12 07:28:16 +08:00
|
|
|
}
|