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"
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include "apptypes.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "drawable.h"
|
|
|
|
#include "gdisplay.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "gimpbrush.h"
|
|
|
|
#include "gimpcontext.h"
|
2001-02-11 03:35:29 +08:00
|
|
|
#include "gimpgradient.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "gimpimage.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "paint_funcs.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "selection.h"
|
|
|
|
#include "temp_buf.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 "pixmaps2.h"
|
|
|
|
#include "libgimp/gimpintl.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
#define PENCIL_INCREMENTAL_DEFAULT FALSE
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the pencil tool options */
|
1999-08-31 14:13:30 +08:00
|
|
|
typedef struct _PencilOptions PencilOptions;
|
2000-01-14 20:41:00 +08:00
|
|
|
|
1999-08-31 14:13:30 +08:00
|
|
|
struct _PencilOptions
|
|
|
|
{
|
|
|
|
PaintOptions paint_options;
|
|
|
|
};
|
1999-09-09 09:47:54 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* forward function declarations */
|
2001-03-12 07:28:16 +08:00
|
|
|
static void gimp_pencil_tool_motion (
|
|
|
|
GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintPressureOptions *pressure_options,
|
|
|
|
gboolean increment );
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
static void gimp_pencil_tool_paint ( GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintState state);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
static void gimp_pencil_tool_class_init (GimpPencilToolClass *klass);
|
|
|
|
static void gimp_pencil_tool_init (GimpPencilTool *tool);
|
|
|
|
|
|
|
|
static void gimp_pencil_tool_options_reset (void);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
/* module level globals */
|
|
|
|
static PencilOptions *pencil_options = NULL;
|
|
|
|
static GimpPaintToolClass *parent_class = NULL;
|
|
|
|
static GimpPencilTool *non_gui_pencil = NULL;
|
1999-08-20 03:53:30 +08:00
|
|
|
static gboolean non_gui_incremental = FALSE;
|
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
|
|
|
|
gimp_pencil_tool_paint (GimpPaintTool *paint_tool,
|
1999-04-09 06:25:54 +08:00
|
|
|
GimpDrawable *drawable,
|
2000-12-31 12:07:42 +08:00
|
|
|
PaintState state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-12 07:28:16 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
PaintPressureOptions *pressure_options;
|
|
|
|
gboolean incremental;
|
|
|
|
|
|
|
|
gimage = gimp_drawable_gimage(drawable);
|
|
|
|
|
|
|
|
if (! gimage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* In keeping parallel with paintbrush... */
|
|
|
|
if (pencil_options)
|
|
|
|
{
|
|
|
|
pressure_options = pencil_options->paint_options.pressure_options;
|
|
|
|
/* gradient_options = pencil_options->paint_options.gradient_options; */
|
|
|
|
incremental = pencil_options->paint_options.incremental;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressure_options = &non_gui_pressure_options;
|
|
|
|
/* gradient_options = &non_gui_gradient_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 07:28:16 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-31 14:13:30 +08:00
|
|
|
static PencilOptions *
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_pencil_tool_options_new (void)
|
1999-08-31 14:13:30 +08:00
|
|
|
{
|
|
|
|
PencilOptions *options;
|
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
options = g_new (PencilOptions, 1);
|
1999-08-31 14:13:30 +08:00
|
|
|
paint_options_init ((PaintOptions *) options,
|
2001-03-12 07:28:16 +08:00
|
|
|
GIMP_TYPE_PENCIL_TOOL,
|
|
|
|
gimp_pencil_tool_options_reset);
|
2000-01-14 20:41:00 +08:00
|
|
|
|
1999-08-31 14:13:30 +08:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_pencil_tool_options_reset (void)
|
1999-04-22 22:34:00 +08:00
|
|
|
{
|
1999-08-31 14:13:30 +08:00
|
|
|
paint_options_reset ((PaintOptions *) pencil_options);
|
1999-04-22 22:34:00 +08:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
gboolean increment)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-12 07:28:16 +08:00
|
|
|
GimpImage *gimage;
|
2001-01-15 05:11:52 +08:00
|
|
|
TempBuf *area;
|
|
|
|
guchar col[MAX_CHANNELS];
|
|
|
|
gint opacity;
|
|
|
|
gdouble scale;
|
|
|
|
PaintApplicationMode paint_appl_mode = increment ? INCREMENTAL : CONSTANT;
|
|
|
|
|
|
|
|
if (! (gimage = gimp_drawable_gimage (drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1999-09-09 09:47:54 +08:00
|
|
|
if (pressure_options->size)
|
2001-03-12 07:28:16 +08:00
|
|
|
scale = paint_tool->curpressure;
|
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
|
|
|
|
|
|
|
gimp_gradient_get_color_at (gimp_context_get_gradient (NULL),
|
2001-03-12 07:28:16 +08:00
|
|
|
paint_tool->curpressure, &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
|
|
|
|
1999-09-09 09:47:54 +08:00
|
|
|
opacity = 255 * gimp_context_get_opacity (NULL);
|
|
|
|
if (pressure_options->opacity)
|
2001-03-12 07:28:16 +08:00
|
|
|
opacity = opacity * 2.0 * paint_tool->curpressure;
|
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,
|
1999-09-09 09:47:54 +08:00
|
|
|
MIN (opacity, 255),
|
1999-07-06 23:18:25 +08:00
|
|
|
(int) (gimp_context_get_opacity (NULL) * 255),
|
|
|
|
gimp_context_get_paint_mode (NULL),
|
1999-09-09 09:47:54 +08:00
|
|
|
HARD, scale, paint_appl_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
gboolean
|
|
|
|
pencil_non_gui (GimpDrawable *drawable,
|
1999-08-20 03:53:30 +08:00
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-12 07:28:16 +08:00
|
|
|
GimpPaintTool *paint_tool;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
|
|
if (! non_gui_pencil)
|
|
|
|
{
|
|
|
|
non_gui_pencil = gtk_type_new (GIMP_TYPE_PENCIL_TOOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
paint_tool = GIMP_PAINT_TOOL(non_gui_pencil);
|
|
|
|
|
|
|
|
if (gimp_paint_tool_start(paint_tool, drawable,
|
|
|
|
stroke_array[0],
|
|
|
|
stroke_array[1]))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-12 07:28:16 +08:00
|
|
|
paint_tool->startx = paint_tool->lastx = stroke_array[0];
|
|
|
|
paint_tool->starty = paint_tool->lasty = 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++)
|
1999-05-14 08:37:58 +08:00
|
|
|
{
|
2001-03-12 07:28:16 +08:00
|
|
|
paint_tool->curx = stroke_array[i * 2 + 0];
|
|
|
|
paint_tool->cury = stroke_array[i * 2 + 1];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
gimp_paint_tool_interpolate (paint_tool, drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-12 07:28:16 +08:00
|
|
|
paint_tool->lastx = paint_tool->curx;
|
|
|
|
paint_tool->lasty = paint_tool->cury;
|
1999-05-14 08:37:58 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Finish the painting */
|
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
|
|
|
}
|
1999-04-19 05:22:41 +08:00
|
|
|
else
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-03-12 07:28:16 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_pencil_tool_register (void)
|
|
|
|
{
|
|
|
|
tool_manager_register_tool (GIMP_TYPE_PENCIL_TOOL,
|
|
|
|
TRUE,
|
|
|
|
"gimp:pencil_tool",
|
|
|
|
_("Pencil"),
|
|
|
|
_("Paint hard edged pixels"),
|
|
|
|
N_("/Tools/Paint Tools/Pencil"), "P",
|
|
|
|
NULL, "tools/pencil.html",
|
|
|
|
(const gchar **) pencil_bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkType
|
|
|
|
gimp_pencil_tool_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType tool_type = 0;
|
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo tool_info =
|
|
|
|
{
|
|
|
|
"GimpPencilTool",
|
|
|
|
sizeof (GimpPencilTool),
|
|
|
|
sizeof (GimpPencilToolClass),
|
|
|
|
(GtkClassInitFunc) gimp_pencil_tool_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_pencil_tool_init,
|
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
tool_type = gtk_type_unique (GIMP_TYPE_PAINT_TOOL, &tool_info);
|
|
|
|
}
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpTool *
|
|
|
|
gimp_pencil_tool_new (void)
|
|
|
|
{
|
|
|
|
return gtk_type_new (GIMP_TYPE_PENCIL_TOOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
pencil_options = gimp_pencil_tool_options_new ();
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_PENCIL_TOOL,
|
|
|
|
(ToolOptions *) pencil_options);
|
|
|
|
}
|
|
|
|
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_class_init (GimpPencilToolClass *klass)
|
|
|
|
{
|
|
|
|
GimpPaintToolClass *paint_tool_class;
|
|
|
|
|
|
|
|
|
|
|
|
paint_tool_class = (GimpPaintToolClass *) klass;
|
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_PAINT_TOOL);
|
|
|
|
paint_tool_class->paint = gimp_pencil_tool_paint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|