1997-11-24 22:05:25 +00: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 05:44:11 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-12-16 21:37:03 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-29 15:22:01 +00:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2001-01-23 18:49:44 +00:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
#include "paint-types.h"
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2001-05-15 11:25:25 +00:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-04-07 15:58:26 +00:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-07 12:17:23 +00:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpgradient.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2002-02-21 16:02:30 +00:00
|
|
|
#include "gimppaintoptions.h"
|
2002-02-14 19:31:16 +00:00
|
|
|
#include "gimppencil.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-04-27 17:27:28 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
static void gimp_pencil_class_init (GimpPencilClass *klass);
|
|
|
|
static void gimp_pencil_init (GimpPencil *pencil);
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
static void gimp_pencil_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
2002-02-21 16:02:30 +00:00
|
|
|
GimpPaintOptions *paint_options,
|
2002-02-14 19:31:16 +00:00
|
|
|
GimpPaintCoreState paint_state);
|
2000-12-31 04:07:42 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
static void gimp_pencil_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
2002-02-21 16:02:30 +00:00
|
|
|
GimpPaintOptions *paint_options);
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2000-12-31 04:07:42 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
static GimpPaintCoreClass *parent_class = NULL;
|
2000-12-31 04:07:42 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2002-02-27 13:57:49 +00:00
|
|
|
void
|
|
|
|
gimp_pencil_register (Gimp *gimp,
|
|
|
|
GimpPaintRegisterCallback callback)
|
|
|
|
{
|
|
|
|
(* callback) (gimp, GIMP_TYPE_PENCIL);
|
|
|
|
}
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
GType
|
2002-02-14 19:31:16 +00:00
|
|
|
gimp_pencil_get_type (void)
|
2001-03-12 04:40:17 +00:00
|
|
|
{
|
2002-02-14 19:31:16 +00:00
|
|
|
static GType type = 0;
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
if (! type)
|
2001-03-12 04:40:17 +00:00
|
|
|
{
|
2002-02-14 19:31:16 +00:00
|
|
|
static const GTypeInfo info =
|
2001-03-12 04:40:17 +00:00
|
|
|
{
|
2002-02-14 19:31:16 +00:00
|
|
|
sizeof (GimpPencilClass),
|
2001-08-14 14:53:55 +00:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
2002-02-14 19:31:16 +00:00
|
|
|
(GClassInitFunc) gimp_pencil_class_init,
|
2001-08-14 14:53:55 +00:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2002-02-14 19:31:16 +00:00
|
|
|
sizeof (GimpPencil),
|
2001-08-14 14:53:55 +00:00
|
|
|
0, /* n_preallocs */
|
2002-02-14 19:31:16 +00:00
|
|
|
(GInstanceInitFunc) gimp_pencil_init,
|
2001-03-12 04:40:17 +00:00
|
|
|
};
|
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
type = g_type_register_static (GIMP_TYPE_PAINT_CORE,
|
2002-02-26 05:42:14 +00:00
|
|
|
"GimpPencil",
|
2002-02-14 19:31:16 +00:00
|
|
|
&info, 0);
|
2001-03-12 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
return type;
|
2001-03-12 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-14 19:31:16 +00:00
|
|
|
gimp_pencil_class_init (GimpPencilClass *klass)
|
2001-03-12 04:40:17 +00:00
|
|
|
{
|
2002-02-14 19:31:16 +00:00
|
|
|
GimpPaintCoreClass *paint_core_class;
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
paint_core_class->paint = gimp_pencil_paint;
|
2001-03-12 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-14 19:31:16 +00:00
|
|
|
gimp_pencil_init (GimpPencil *pencil)
|
2001-03-12 04:40:17 +00:00
|
|
|
{
|
2002-02-14 19:31:16 +00:00
|
|
|
GimpPaintCore *paint_core;
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2002-02-14 19:31:16 +00:00
|
|
|
paint_core = GIMP_PAINT_CORE (pencil);
|
2001-03-12 04:40:17 +00:00
|
|
|
|
2002-02-15 17:44:05 +00:00
|
|
|
paint_core->flags |= CORE_HANDLES_CHANGING_BRUSH;
|
2001-03-12 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-14 19:31:16 +00:00
|
|
|
gimp_pencil_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
2002-02-21 16:02:30 +00:00
|
|
|
GimpPaintOptions *paint_options,
|
2002-02-14 19:31:16 +00:00
|
|
|
GimpPaintCoreState paint_state)
|
2001-03-12 04:40:17 +00:00
|
|
|
{
|
2002-02-14 19:31:16 +00:00
|
|
|
switch (paint_state)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2000-01-14 12:41:00 +00:00
|
|
|
case MOTION_PAINT:
|
2002-02-14 19:31:16 +00:00
|
|
|
gimp_pencil_motion (paint_core, drawable, paint_options);
|
1997-11-24 22:05:25 +00:00
|
|
|
break;
|
|
|
|
|
2000-01-14 12:41:00 +00:00
|
|
|
default:
|
1997-11-24 22:05:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-18 22:35:31 +00:00
|
|
|
static void
|
2002-02-21 16:02:30 +00:00
|
|
|
gimp_pencil_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2002-06-09 13:56:09 +00:00
|
|
|
GimpPressureOptions *pressure_options;
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpContext *context;
|
|
|
|
TempBuf *area;
|
|
|
|
guchar col[MAX_CHANNELS];
|
|
|
|
gdouble opacity;
|
|
|
|
gdouble scale;
|
2002-03-19 15:05:38 +00:00
|
|
|
GimpPaintApplicationMode paint_appl_mode;
|
2001-01-14 21:11:52 +00:00
|
|
|
|
2002-06-09 13:56:09 +00:00
|
|
|
pressure_options = paint_options->pressure_options;
|
|
|
|
|
2002-02-25 17:58:50 +00:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-07-07 12:17:23 +00:00
|
|
|
context = gimp_get_current_context (gimage->gimp);
|
|
|
|
|
2002-03-19 15:05:38 +00:00
|
|
|
paint_appl_mode = (paint_options->incremental ?
|
|
|
|
GIMP_PAINT_INCREMENTAL : GIMP_PAINT_CONSTANT);
|
2002-02-14 19:31:16 +00:00
|
|
|
|
2002-06-09 13:56:09 +00:00
|
|
|
if (pressure_options->size)
|
2002-02-14 19:31:16 +00:00
|
|
|
scale = paint_core->cur_coords.pressure;
|
1999-09-09 01:47:54 +00:00
|
|
|
else
|
|
|
|
scale = 1.0;
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* Get a region which can be used to paint to */
|
2002-02-14 19:31:16 +00:00
|
|
|
if (! (area = gimp_paint_core_get_paint_area (paint_core, drawable, scale)))
|
1997-11-24 22:05:25 +00:00
|
|
|
return;
|
|
|
|
|
1999-11-13 01:02:27 +00:00
|
|
|
/* color the pixels */
|
2002-06-09 13:56:09 +00:00
|
|
|
if (pressure_options->color)
|
1999-11-13 01:02:27 +00:00
|
|
|
{
|
2001-01-20 16:28:05 +00:00
|
|
|
GimpRGB color;
|
2001-02-10 19:35:29 +00:00
|
|
|
|
2001-07-07 12:17:23 +00:00
|
|
|
gimp_gradient_get_color_at (gimp_context_get_gradient (context),
|
2002-02-14 19:31:16 +00:00
|
|
|
paint_core->cur_coords.pressure,
|
|
|
|
&color);
|
2001-01-20 16:28:05 +00:00
|
|
|
|
|
|
|
gimp_rgba_get_uchar (&color,
|
|
|
|
&col[RED_PIX],
|
|
|
|
&col[GREEN_PIX],
|
|
|
|
&col[BLUE_PIX],
|
|
|
|
&col[ALPHA_PIX]);
|
|
|
|
|
2002-03-19 15:05:38 +00:00
|
|
|
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
|
1999-11-13 01:02:27 +00:00
|
|
|
color_pixels (temp_buf_data (area), col,
|
2002-02-14 19:31:16 +00:00
|
|
|
area->width * area->height,
|
|
|
|
area->bytes);
|
1999-11-13 01:02:27 +00:00
|
|
|
}
|
2002-02-14 19:31:16 +00:00
|
|
|
else if (paint_core->brush && paint_core->brush->pixmap)
|
1999-08-13 20:50:30 +00:00
|
|
|
{
|
1999-09-09 01:47:54 +00:00
|
|
|
/* if its a pixmap, do pixmap stuff */
|
2002-02-14 19:31:16 +00:00
|
|
|
gimp_paint_core_color_area_with_pixmap (paint_core,
|
|
|
|
gimage, drawable,
|
2002-03-19 15:05:38 +00:00
|
|
|
area, scale, GIMP_BRUSH_HARD);
|
|
|
|
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
|
1999-08-13 20:50:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-12-29 15:22:01 +00:00
|
|
|
gimp_image_get_foreground (gimage, drawable, col);
|
1999-11-13 01:02:27 +00:00
|
|
|
col[area->bytes - 1] = OPAQUE_OPACITY;
|
1999-08-13 20:50:30 +00:00
|
|
|
color_pixels (temp_buf_data (area), col,
|
2002-02-14 19:31:16 +00:00
|
|
|
area->width * area->height,
|
|
|
|
area->bytes);
|
1999-08-13 20:50:30 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2002-05-29 17:13:12 +00:00
|
|
|
opacity = gimp_context_get_opacity (context);
|
2002-02-14 19:31:16 +00:00
|
|
|
|
2002-06-09 13:56:09 +00:00
|
|
|
if (pressure_options->opacity)
|
2002-02-14 19:31:16 +00:00
|
|
|
opacity = opacity * 2.0 * paint_core->cur_coords.pressure;
|
1999-08-13 20:50:30 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* paste the newly painted canvas to the gimage which is being worked on */
|
2002-02-14 19:31:16 +00:00
|
|
|
gimp_paint_core_paste_canvas (paint_core, drawable,
|
2002-05-29 17:13:12 +00:00
|
|
|
MIN (opacity, GIMP_OPACITY_OPAQUE),
|
|
|
|
gimp_context_get_opacity (context),
|
2001-07-07 12:17:23 +00:00
|
|
|
gimp_context_get_paint_mode (context),
|
2002-06-09 13:56:09 +00:00
|
|
|
GIMP_BRUSH_HARD,
|
|
|
|
scale,
|
|
|
|
paint_appl_mode);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|