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
|
|
|
|
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-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/gimpcontext.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
|
|
|
|
|
|
|
|
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,
|
|
|
|
GimpPaintCoreState paint_state);
|
|
|
|
static void gimp_paintbrush_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options);
|
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-05 22:39:40 +08:00
|
|
|
(* callback) (gimp, GIMP_TYPE_PAINTBRUSH, GIMP_TYPE_PAINT_OPTIONS);
|
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
|
|
|
};
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
type = g_type_register_static (GIMP_TYPE_PAINT_CORE,
|
|
|
|
"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
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
GimpPaintCoreClass *paint_core_class;
|
1999-04-22 22:34:00 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
paint_core_class = GIMP_PAINT_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;
|
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
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
GimpPaintCore *paint_core;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
paint_core = GIMP_PAINT_CORE (paintbrush);
|
1999-09-09 09:47:54 +08:00
|
|
|
|
2002-02-16 01:44:05 +08:00
|
|
|
paint_core->flags |= CORE_HANDLES_CHANGING_BRUSH;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_paintbrush_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
2002-02-22 00:02:30 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
2002-02-15 03:31:16 +08:00
|
|
|
GimpPaintCoreState paint_state)
|
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
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
case MOTION_PAINT:
|
2002-06-09 21:56:09 +08:00
|
|
|
gimp_paintbrush_motion (paint_core, drawable, paint_options);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2002-03-19 23:05:38 +08:00
|
|
|
gimp_paintbrush_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
2002-06-09 21:56:09 +08:00
|
|
|
GimpPaintOptions *paint_options)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-06-09 21:56:09 +08:00
|
|
|
GimpPressureOptions *pressure_options;
|
|
|
|
GimpGradientOptions *gradient_options;
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpContext *context;
|
|
|
|
TempBuf *area;
|
|
|
|
gdouble gradient_length;
|
|
|
|
guchar local_blend = OPAQUE_OPACITY;
|
|
|
|
guchar col[MAX_CHANNELS];
|
|
|
|
gdouble opacity;
|
|
|
|
gdouble scale;
|
|
|
|
GimpPaintApplicationMode paint_appl_mode;
|
|
|
|
|
|
|
|
if (! (gimage = gimp_item_get_image (GIMP_ITEM (drawable))))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pressure_options = paint_options->pressure_options;
|
|
|
|
gradient_options = paint_options->gradient_options;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
context = gimp_get_current_context (gimage->gimp);
|
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
paint_appl_mode = (paint_options->incremental ?
|
|
|
|
GIMP_PAINT_INCREMENTAL : GIMP_PAINT_CONSTANT);
|
|
|
|
|
|
|
|
if (gradient_options->use_fade)
|
|
|
|
{
|
|
|
|
gdouble fade_out = 0.0;
|
|
|
|
gdouble unit_factor;
|
|
|
|
|
|
|
|
switch (gradient_options->fade_unit)
|
|
|
|
{
|
|
|
|
case GIMP_UNIT_PIXEL:
|
|
|
|
fade_out = gradient_options->fade_out;
|
|
|
|
break;
|
|
|
|
case GIMP_UNIT_PERCENT:
|
|
|
|
fade_out = (MAX (gimage->width, gimage->height) *
|
|
|
|
gradient_options->fade_out / 100);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unit_factor = gimp_unit_get_factor (gradient_options->fade_unit);
|
|
|
|
fade_out = (gradient_options->fade_out *
|
|
|
|
MAX (gimage->xresolution,
|
|
|
|
gimage->yresolution) / unit_factor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* factor in the fade out value */
|
|
|
|
if (fade_out)
|
|
|
|
{
|
|
|
|
gdouble x, paint_left;
|
|
|
|
|
|
|
|
/* Model the amount of paint left as a gaussian curve */
|
|
|
|
x = ((gdouble) paint_core->pixel_dist / fade_out);
|
|
|
|
paint_left = exp (- x * x * 5.541); /* ln (1/255) */
|
|
|
|
|
|
|
|
local_blend = (gint) (255 * paint_left);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient_options->use_gradient)
|
|
|
|
{
|
|
|
|
gdouble unit_factor;
|
|
|
|
|
|
|
|
switch (gradient_options->gradient_unit)
|
|
|
|
{
|
|
|
|
case GIMP_UNIT_PIXEL:
|
|
|
|
gradient_length = gradient_options->gradient_length;
|
|
|
|
break;
|
|
|
|
case GIMP_UNIT_PERCENT:
|
|
|
|
gradient_length = (MAX (gimage->width, gimage->height) *
|
|
|
|
gradient_options->gradient_length / 100);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unit_factor = gimp_unit_get_factor (gradient_options->gradient_unit);
|
|
|
|
gradient_length = (gradient_options->gradient_length *
|
|
|
|
MAX (gimage->xresolution,
|
|
|
|
gimage->yresolution) / unit_factor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-09-09 09:47:54 +08:00
|
|
|
else
|
2002-06-09 21:56:09 +08:00
|
|
|
{
|
|
|
|
gradient_length = 0.0;
|
|
|
|
}
|
1999-08-17 09:05:59 +08:00
|
|
|
|
1999-11-13 09:02:27 +08:00
|
|
|
if (pressure_options->color)
|
|
|
|
gradient_length = 1.0; /* not really used, only for if cases */
|
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
if (pressure_options->size)
|
|
|
|
scale = paint_core->cur_coords.pressure;
|
|
|
|
else
|
|
|
|
scale = 1.0;
|
|
|
|
|
1999-05-15 08:02:47 +08:00
|
|
|
/* Get a region which can be used to paint to */
|
2002-02-15 03:31:16 +08:00
|
|
|
if (! (area = gimp_paint_core_get_paint_area (paint_core, drawable, scale)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1999-03-19 08:42:27 +08:00
|
|
|
if (local_blend)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-06-09 21:56:09 +08:00
|
|
|
guchar temp_blend;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* set the alpha channel */
|
1999-03-19 08:42:27 +08:00
|
|
|
temp_blend = local_blend;
|
|
|
|
|
1999-08-20 03:53:30 +08:00
|
|
|
if (gradient_length)
|
1999-03-17 13:40:16 +08:00
|
|
|
{
|
2001-10-22 20:13:44 +08:00
|
|
|
GimpGradient *gradient;
|
2002-06-09 21:56:09 +08:00
|
|
|
GimpRGB color;
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
gradient = gimp_context_get_gradient (context);
|
|
|
|
|
1999-11-13 09:02:27 +08:00
|
|
|
if (pressure_options->color)
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_gradient_get_color_at (gradient,
|
2002-02-15 03:31:16 +08:00
|
|
|
paint_core->cur_coords.pressure,
|
2001-10-22 20:13:44 +08:00
|
|
|
&color);
|
1999-11-13 09:02:27 +08:00
|
|
|
else
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_paint_core_get_color_from_gradient (paint_core,
|
2001-10-22 20:13:44 +08:00
|
|
|
gradient,
|
|
|
|
gradient_length,
|
|
|
|
&color,
|
2002-06-09 21:56:09 +08:00
|
|
|
gradient_options->gradient_type);
|
2001-01-21 00:28:05 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
temp_blend = (gint) ((color.a * local_blend));
|
2001-01-21 00:28:05 +08:00
|
|
|
|
|
|
|
gimp_rgb_get_uchar (&color,
|
|
|
|
&col[RED_PIX],
|
|
|
|
&col[GREEN_PIX],
|
|
|
|
&col[BLUE_PIX]);
|
|
|
|
col[ALPHA_PIX] = OPAQUE_OPACITY;
|
|
|
|
|
1999-03-19 08:42:27 +08:00
|
|
|
/* always use incremental mode with gradients */
|
|
|
|
/* make the gui cool later */
|
2002-03-19 23:05:38 +08:00
|
|
|
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
|
1999-11-13 09:02:27 +08:00
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height, area->bytes);
|
1999-03-17 13:40:16 +08:00
|
|
|
}
|
1999-08-17 09:05:59 +08:00
|
|
|
/* we check to see if this is a pixmap, if so composite the
|
2001-04-07 19:01:22 +08:00
|
|
|
* pixmap image into the area instead of the color
|
|
|
|
*/
|
2002-02-15 03:31:16 +08:00
|
|
|
else if (paint_core->brush && paint_core->brush->pixmap)
|
1999-08-14 04:50:30 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_paint_core_color_area_with_pixmap (paint_core, gimage, drawable,
|
2001-02-28 03:18:01 +08:00
|
|
|
area,
|
2002-03-19 23:05:38 +08:00
|
|
|
scale, GIMP_BRUSH_SOFT);
|
|
|
|
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
|
1999-08-14 04:50:30 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
else
|
1999-08-14 04:50:30 +08:00
|
|
|
{
|
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);
|
|
|
|
}
|
1999-09-09 09:47:54 +08:00
|
|
|
|
2002-03-04 01:38:12 +08:00
|
|
|
opacity = (gdouble) temp_blend / 255.0;
|
2001-03-12 12:40:17 +08:00
|
|
|
|
1999-09-09 09:47:54 +08:00
|
|
|
if (pressure_options->opacity)
|
2002-02-15 03:31:16 +08:00
|
|
|
opacity = opacity * 2.0 * paint_core->cur_coords.pressure;
|
1999-09-09 09:47:54 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_paint_core_paste_canvas (paint_core, drawable,
|
2002-03-04 01:38:12 +08:00
|
|
|
MIN (opacity, GIMP_OPACITY_OPAQUE),
|
|
|
|
gimp_context_get_opacity (context),
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_context_get_paint_mode (context),
|
2002-03-19 23:05:38 +08:00
|
|
|
(pressure_options->pressure ?
|
|
|
|
GIMP_BRUSH_PRESSURE : GIMP_BRUSH_SOFT),
|
2002-06-09 21:56:09 +08:00
|
|
|
scale,
|
|
|
|
paint_appl_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|