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
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 02:49:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-21 21:58:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "paint-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/gimpdrawable.h"
|
|
|
|
#include "core/gimpgradient.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "gimppaintbrush.h"
|
2002-02-22 00:02:30 +08:00
|
|
|
#include "gimppaintoptions.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
static void gimp_paintbrush_class_init (GimpPaintbrushClass *klass);
|
|
|
|
static void gimp_paintbrush_init (GimpPaintbrush *paintbrush);
|
1999-07-20 06:42:49 +08:00
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
static void gimp_paintbrush_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2004-07-19 22:37:40 +08:00
|
|
|
GimpPaintState paint_state,
|
2004-05-27 00:13:53 +08:00
|
|
|
guint32 time);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
static GimpPaintCoreClass *parent_class = NULL;
|
2001-03-12 12:40:17 +08:00
|
|
|
|
|
|
|
|
2002-02-27 21:57:49 +08:00
|
|
|
void
|
|
|
|
gimp_paintbrush_register (Gimp *gimp,
|
|
|
|
GimpPaintRegisterCallback callback)
|
|
|
|
{
|
2003-02-14 22:14:29 +08:00
|
|
|
(* callback) (gimp,
|
|
|
|
GIMP_TYPE_PAINTBRUSH,
|
|
|
|
GIMP_TYPE_PAINT_OPTIONS,
|
|
|
|
_("Paintbrush"));
|
2002-02-27 21:57:49 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_paintbrush_get_type (void)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static GType type = 0;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
if (! type)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static const GTypeInfo info =
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
sizeof (GimpPaintbrushClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
2002-02-15 03:31:16 +08:00
|
|
|
(GClassInitFunc) gimp_paintbrush_class_init,
|
2001-08-14 22:53:55 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2002-02-15 03:31:16 +08:00
|
|
|
sizeof (GimpPaintbrush),
|
2001-08-14 22:53:55 +08:00
|
|
|
0, /* n_preallocs */
|
2002-02-15 03:31:16 +08:00
|
|
|
(GInstanceInitFunc) gimp_paintbrush_init,
|
2001-02-27 13:21:12 +08:00
|
|
|
};
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
type = g_type_register_static (GIMP_TYPE_BRUSH_CORE,
|
2002-02-15 03:31:16 +08:00
|
|
|
"GimpPaintbrush",
|
|
|
|
&info, 0);
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
return type;
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_paintbrush_class_init (GimpPaintbrushClass *klass)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
2004-05-28 04:48:49 +08:00
|
|
|
GimpBrushCoreClass *brush_core_class = GIMP_BRUSH_CORE_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
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
paint_core_class->paint = gimp_paintbrush_paint;
|
2004-05-28 04:48:49 +08:00
|
|
|
|
|
|
|
brush_core_class->handles_changing_brush = TRUE;
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
1999-03-28 13:27:34 +08:00
|
|
|
|
2001-03-12 12:40:17 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_paintbrush_init (GimpPaintbrush *paintbrush)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
static void
|
2004-07-19 22:37:40 +08:00
|
|
|
gimp_paintbrush_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
switch (paint_state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-19 22:37:40 +08:00
|
|
|
case GIMP_PAINT_STATE_MOTION:
|
2003-07-15 23:38:24 +08:00
|
|
|
_gimp_paintbrush_motion (paint_core, drawable, paint_options,
|
|
|
|
GIMP_OPACITY_OPAQUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
default:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
void
|
|
|
|
_gimp_paintbrush_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
gdouble opacity)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
|
|
|
GimpPressureOptions *pressure_options = paint_options->pressure_options;
|
2003-02-06 00:59:04 +08:00
|
|
|
GimpImage *gimage;
|
2003-07-22 22:24:11 +08:00
|
|
|
GimpRGB gradient_color;
|
2002-06-09 21:56:09 +08:00
|
|
|
TempBuf *area;
|
|
|
|
guchar col[MAX_CHANNELS];
|
|
|
|
GimpPaintApplicationMode paint_appl_mode;
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
opacity *= gimp_paint_options_get_fade (paint_options, gimage,
|
|
|
|
paint_core->pixel_dist);
|
|
|
|
if (opacity == 0.0)
|
|
|
|
return;
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
paint_appl_mode = paint_options->application_mode;
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2004-05-26 17:32:03 +08:00
|
|
|
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
|
|
|
|
if (! area)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
2003-07-22 22:24:11 +08:00
|
|
|
if (gimp_paint_options_get_gradient_color (paint_options, gimage,
|
|
|
|
paint_core->cur_coords.pressure,
|
|
|
|
paint_core->pixel_dist,
|
|
|
|
&gradient_color))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-07-22 22:24:11 +08:00
|
|
|
opacity *= gradient_color.a;
|
2003-07-16 19:25:37 +08:00
|
|
|
|
2003-07-22 22:24:11 +08:00
|
|
|
gimp_rgb_get_uchar (&gradient_color,
|
2003-07-16 19:25:37 +08:00
|
|
|
&col[RED_PIX],
|
|
|
|
&col[GREEN_PIX],
|
|
|
|
&col[BLUE_PIX]);
|
|
|
|
col[ALPHA_PIX] = OPAQUE_OPACITY;
|
|
|
|
|
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height,
|
|
|
|
area->bytes);
|
|
|
|
|
|
|
|
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
else if (brush_core->brush && brush_core->brush->pixmap)
|
2003-07-16 19:25:37 +08:00
|
|
|
{
|
|
|
|
/* if it's a pixmap, do pixmap stuff */
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_color_area_with_pixmap (brush_core, gimage, drawable,
|
2003-07-16 19:25:37 +08:00
|
|
|
area,
|
2004-05-26 17:32:03 +08:00
|
|
|
brush_core->scale,
|
2003-07-16 19:25:37 +08:00
|
|
|
gimp_paint_options_get_brush_mode (paint_options));
|
|
|
|
|
|
|
|
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_image_get_foreground (gimage, drawable, context, col);
|
2003-07-16 19:25:37 +08:00
|
|
|
col[area->bytes - 1] = OPAQUE_OPACITY;
|
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height,
|
|
|
|
area->bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pressure_options->opacity)
|
2004-05-24 21:11:43 +08:00
|
|
|
opacity *= PRESSURE_SCALE * paint_core->cur_coords.pressure;
|
2003-07-16 19:25:37 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_paste_canvas (brush_core, drawable,
|
2003-07-16 19:25:37 +08:00
|
|
|
MIN (opacity, GIMP_OPACITY_OPAQUE),
|
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
gimp_context_get_paint_mode (context),
|
|
|
|
gimp_paint_options_get_brush_mode (paint_options),
|
|
|
|
paint_appl_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|