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-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
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-08 09:07:03 +08:00
|
|
|
#include "gimppaintbrushtool.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-08 09:07:03 +08:00
|
|
|
#include "tool_manager.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
#include "pixmaps2.h"
|
1998-12-16 08:37:09 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* defines */
|
|
|
|
#define PAINT_LEFT_THRESHOLD 0.05
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
/* defaults for the tool options */
|
|
|
|
#define PAINTBRUSH_DEFAULT_INCREMENTAL FALSE
|
1999-09-26 03:49:58 +08:00
|
|
|
#define PAINTBRUSH_DEFAULT_USE_FADE FALSE
|
|
|
|
#define PAINTBRUSH_DEFAULT_FADE_OUT 100.0
|
2000-02-08 04:35:13 +08:00
|
|
|
#define PAINTBRUSH_DEFAULT_FADE_UNIT GIMP_UNIT_PIXEL
|
1999-07-20 06:42:49 +08:00
|
|
|
#define PAINTBRUSH_DEFAULT_USE_GRADIENT FALSE
|
1999-09-26 03:49:58 +08:00
|
|
|
#define PAINTBRUSH_DEFAULT_GRADIENT_LENGTH 100.0
|
2000-02-08 04:35:13 +08:00
|
|
|
#define PAINTBRUSH_DEFAULT_GRADIENT_UNIT GIMP_UNIT_PIXEL
|
1999-07-20 06:42:49 +08:00
|
|
|
#define PAINTBRUSH_DEFAULT_GRADIENT_TYPE LOOP_TRIANGLE
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the paintbrush structures */
|
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
typedef struct _PaintbrushOptions PaintbrushOptions;
|
2000-12-31 12:07:42 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
struct _PaintbrushOptions
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintOptions paint_options;
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the paint brush tool options */
|
1999-06-22 06:12:07 +08:00
|
|
|
static PaintbrushOptions * paintbrush_options = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* local variables */
|
2000-02-08 04:35:13 +08:00
|
|
|
static gdouble non_gui_incremental;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-02-28 10:53:27 +08:00
|
|
|
static GimpPaintToolClass *parent_class = NULL;
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* forward function declarations */
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_paintbrush_tool_motion (GimpPaintTool *,
|
|
|
|
GimpDrawable *,
|
|
|
|
PaintPressureOptions *,
|
2001-02-28 07:20:51 +08:00
|
|
|
PaintGradientOptions *,
|
2001-02-28 03:18:01 +08:00
|
|
|
gdouble ,
|
|
|
|
gdouble ,
|
|
|
|
PaintApplicationMode ,
|
|
|
|
GradientPaintMode );
|
|
|
|
static void gimp_paintbrush_tool_paint (GimpPaintTool *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintState state);
|
|
|
|
static void gimp_paintbrush_tool_class_init (GimpPaintbrushToolClass *klass);
|
|
|
|
static void gimp_paintbrush_tool_init (GimpPaintbrushTool *tool);
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
GtkType
|
|
|
|
gimp_paintbrush_tool_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType tool_type = 0;
|
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo tool_info =
|
|
|
|
{
|
|
|
|
"GimpPaintbrushTool",
|
|
|
|
sizeof (GimpPaintbrushTool),
|
|
|
|
sizeof (GimpPaintbrushToolClass),
|
|
|
|
(GtkClassInitFunc) gimp_paintbrush_tool_class_init,
|
2001-02-28 03:18:01 +08:00
|
|
|
(GtkObjectInitFunc) gimp_paintbrush_tool_init,
|
2001-02-27 13:21:12 +08:00
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
tool_type = gtk_type_unique (GIMP_TYPE_PAINT_TOOL, &tool_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paintbrush_tool_options_reset (void)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintbrushOptions *options = paintbrush_options;
|
|
|
|
|
|
|
|
paint_options_reset ((PaintOptions *) options);
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
1999-03-28 13:27:34 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
static PaintbrushOptions *
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paintbrush_tool_options_new (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintbrushOptions *options;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
/* the new paint tool options structure */
|
2001-02-28 07:20:51 +08:00
|
|
|
options = g_new0 (PaintbrushOptions, 1);
|
1999-04-22 22:34:00 +08:00
|
|
|
paint_options_init ((PaintOptions *) options,
|
2001-02-27 13:21:12 +08:00
|
|
|
GIMP_TYPE_PAINTBRUSH_TOOL,
|
|
|
|
gimp_paintbrush_tool_options_reset);
|
1999-09-09 09:47:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_paintbrush_tool_paint (GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintState state)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
PaintPressureOptions *pressure_options;
|
|
|
|
PaintGradientOptions *gradient_options;
|
|
|
|
gboolean incremental;
|
|
|
|
GimpImage *gimage;
|
|
|
|
gdouble fade_out;
|
|
|
|
gdouble gradient_length;
|
|
|
|
gdouble unit_factor;
|
|
|
|
|
|
|
|
gimage = gimp_drawable_gimage (drawable);
|
|
|
|
|
|
|
|
g_return_if_fail (gimage != NULL);
|
|
|
|
|
|
|
|
if (! gimage)
|
|
|
|
return;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
if (paintbrush_options)
|
|
|
|
{
|
|
|
|
pressure_options = paintbrush_options->paint_options.pressure_options;
|
|
|
|
gradient_options = paintbrush_options->paint_options.gradient_options;
|
|
|
|
incremental = paintbrush_options->paint_options.incremental;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressure_options = &non_gui_pressure_options;
|
|
|
|
gradient_options = &non_gui_gradient_options;
|
|
|
|
incremental = non_gui_incremental;
|
|
|
|
}
|
1999-09-26 03:49:58 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (state)
|
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
case INIT_PAINT:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
case MOTION_PAINT:
|
2001-02-28 07:20:51 +08:00
|
|
|
switch (gradient_options->fade_unit)
|
1999-09-26 03:49:58 +08:00
|
|
|
{
|
2000-02-08 04:35:13 +08:00
|
|
|
case GIMP_UNIT_PIXEL:
|
2001-02-28 07:20:51 +08:00
|
|
|
fade_out = gradient_options->fade_out;
|
1999-09-26 03:49:58 +08:00
|
|
|
break;
|
2000-02-08 04:35:13 +08:00
|
|
|
case GIMP_UNIT_PERCENT:
|
2001-02-28 07:20:51 +08:00
|
|
|
fade_out = (MAX (gimage->width, gimage->height) *
|
|
|
|
gradient_options->fade_out / 100);
|
1999-09-26 03:49:58 +08:00
|
|
|
break;
|
|
|
|
default:
|
2001-02-28 07:20:51 +08:00
|
|
|
unit_factor = gimp_unit_get_factor (gradient_options->fade_unit);
|
|
|
|
fade_out = (gradient_options->fade_out *
|
|
|
|
MAX (gimage->xresolution,
|
|
|
|
gimage->yresolution) / unit_factor);
|
1999-09-26 03:49:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
switch (gradient_options->gradient_unit)
|
1999-09-26 03:49:58 +08:00
|
|
|
{
|
2000-02-08 04:35:13 +08:00
|
|
|
case GIMP_UNIT_PIXEL:
|
2001-02-28 07:20:51 +08:00
|
|
|
gradient_length = gradient_options->gradient_length;
|
1999-09-26 03:49:58 +08:00
|
|
|
break;
|
2000-02-08 04:35:13 +08:00
|
|
|
case GIMP_UNIT_PERCENT:
|
2001-02-28 07:20:51 +08:00
|
|
|
gradient_length = (MAX (gimage->width, gimage->height) *
|
|
|
|
gradient_options->gradient_length / 100);
|
1999-09-26 03:49:58 +08:00
|
|
|
break;
|
|
|
|
default:
|
2001-02-28 07:20:51 +08:00
|
|
|
unit_factor = gimp_unit_get_factor (gradient_options->gradient_unit);
|
|
|
|
gradient_length = (gradient_options->gradient_length *
|
|
|
|
MAX (gimage->xresolution,
|
|
|
|
gimage->yresolution) / unit_factor);
|
1999-09-26 03:49:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
gimp_paintbrush_tool_motion (paint_tool, drawable,
|
2001-02-28 07:20:51 +08:00
|
|
|
pressure_options,
|
|
|
|
gradient_options,
|
|
|
|
gradient_options->use_fade ? fade_out : 0,
|
|
|
|
gradient_options->use_gradient ? gradient_length : 0,
|
|
|
|
incremental,
|
|
|
|
gradient_options->gradient_type);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
case FINISH_PAINT:
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
GimpTool *
|
|
|
|
gimp_paintbrush_tool_new (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
return gtk_type_new (GIMP_TYPE_PAINTBRUSH_TOOL);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void
|
|
|
|
gimp_paintbrush_tool_init (GimpPaintbrushTool *paintbrush)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-02-28 03:18:01 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpPaintTool *paint_tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (paintbrush);
|
|
|
|
paint_tool = GIMP_PAINT_TOOL (paintbrush);
|
|
|
|
|
|
|
|
if (! paintbrush_options)
|
|
|
|
{
|
|
|
|
paintbrush_options = gimp_paintbrush_tool_options_new ();
|
|
|
|
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_PAINTBRUSH_TOOL,
|
|
|
|
(ToolOptions *) paintbrush_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
tool->tool_cursor = GIMP_PAINTBRUSH_TOOL_CURSOR;
|
|
|
|
|
|
|
|
paint_tool->pick_colors = TRUE;
|
|
|
|
paint_tool->flags |= TOOL_CAN_HANDLE_CHANGING_BRUSH;
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void
|
|
|
|
gimp_paintbrush_tool_class_init (GimpPaintbrushToolClass *klass)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-02-28 03:18:01 +08:00
|
|
|
GimpPaintToolClass *paint_tool_class;
|
|
|
|
|
|
|
|
paint_tool_class = (GimpPaintToolClass *) klass;
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_PAINT_TOOL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
paint_tool_class->paint = gimp_paintbrush_tool_paint;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paintbrush_tool_register (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
tool_manager_register_tool (GIMP_TYPE_PAINTBRUSH_TOOL,
|
2001-02-28 07:20:51 +08:00
|
|
|
TRUE,
|
2001-02-27 13:21:12 +08:00
|
|
|
"gimp:paintbrush_tool",
|
2001-02-27 22:14:13 +08:00
|
|
|
_("Paintbrush"),
|
|
|
|
_("Paint fuzzy brush strokes"),
|
2001-02-27 13:21:12 +08:00
|
|
|
N_("/Tools/Paint Tools/Paintbrush"), "P",
|
2001-02-27 22:14:13 +08:00
|
|
|
NULL, "tools/paintbrush.html",
|
|
|
|
(const gchar **) paint_bits);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_paintbrush_tool_motion (GimpPaintTool *paint_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PaintPressureOptions *pressure_options,
|
2001-02-28 07:20:51 +08:00
|
|
|
PaintGradientOptions *gradient_options,
|
2001-02-28 03:18:01 +08:00
|
|
|
double fade_out,
|
|
|
|
double gradient_length,
|
|
|
|
PaintApplicationMode incremental,
|
|
|
|
GradientPaintMode gradient_type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 03:18:01 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
TempBuf *area;
|
|
|
|
gdouble x, paint_left;
|
|
|
|
gdouble position;
|
|
|
|
guchar local_blend = OPAQUE_OPACITY;
|
|
|
|
guchar temp_blend = OPAQUE_OPACITY;
|
|
|
|
guchar col[MAX_CHANNELS];
|
|
|
|
GimpRGB color;
|
|
|
|
gint mode;
|
|
|
|
gint opacity;
|
|
|
|
gdouble scale;
|
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
|
|
|
PaintApplicationMode paint_appl_mode = incremental ? INCREMENTAL : CONSTANT;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-03-17 13:40:16 +08:00
|
|
|
position = 0.0;
|
2001-01-15 05:11:52 +08:00
|
|
|
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-02-27 13:21:12 +08:00
|
|
|
scale = paint_tool->curpressure;
|
1999-09-09 09:47:54 +08:00
|
|
|
else
|
|
|
|
scale = 1.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 */
|
|
|
|
|
1999-05-15 08:02:47 +08:00
|
|
|
/* Get a region which can be used to paint to */
|
2001-02-27 13:21:12 +08:00
|
|
|
if (! (area = gimp_paint_tool_get_paint_area (paint_tool, drawable, scale)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* factor in the fade out value */
|
|
|
|
if (fade_out)
|
|
|
|
{
|
|
|
|
/* Model the amount of paint left as a gaussian curve */
|
2001-02-27 13:21:12 +08:00
|
|
|
x = ((double) paint_tool->pixel_dist / fade_out);
|
1999-09-26 03:49:58 +08:00
|
|
|
paint_left = exp (- x * x * 5.541); /* ln (1/255) */
|
1999-03-19 08:42:27 +08:00
|
|
|
local_blend = (int) (255 * paint_left);
|
1999-03-17 13:40:16 +08:00
|
|
|
}
|
|
|
|
|
1999-03-19 08:42:27 +08:00
|
|
|
if (local_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-03-28 13:27:34 +08:00
|
|
|
mode = gradient_type;
|
1999-03-19 08:42:27 +08:00
|
|
|
|
1999-08-20 03:53:30 +08:00
|
|
|
if (gradient_length)
|
1999-03-17 13:40:16 +08:00
|
|
|
{
|
1999-11-13 09:02:27 +08:00
|
|
|
if (pressure_options->color)
|
2001-02-11 03:35:29 +08:00
|
|
|
gimp_gradient_get_color_at (gimp_context_get_gradient (NULL),
|
2001-02-27 13:21:12 +08:00
|
|
|
paint_tool->curpressure, &color);
|
1999-11-13 09:02:27 +08:00
|
|
|
else
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paint_tool_get_color_from_gradient (paint_tool, gradient_length,
|
2001-02-28 03:18:01 +08:00
|
|
|
&color, mode);
|
2001-01-21 00:28:05 +08:00
|
|
|
|
|
|
|
temp_blend = (gint) ((color.a * local_blend));
|
|
|
|
|
|
|
|
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 */
|
1999-08-20 03:53:30 +08:00
|
|
|
paint_appl_mode = 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
|
|
|
|
pixmap image into the are instead of the color */
|
2001-02-27 13:21:12 +08:00
|
|
|
else if (paint_tool->brush && paint_tool->brush->pixmap)
|
1999-08-14 04:50:30 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paint_tool_color_area_with_pixmap (paint_tool, gimage, drawable,
|
2001-02-28 03:18:01 +08:00
|
|
|
area,
|
|
|
|
scale, SOFT);
|
1999-08-20 03:53:30 +08:00
|
|
|
paint_appl_mode = 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
|
|
|
|
1999-09-26 03:49:58 +08:00
|
|
|
opacity = (gdouble)temp_blend;
|
1999-09-09 09:47:54 +08:00
|
|
|
if (pressure_options->opacity)
|
2001-02-27 13:21:12 +08:00
|
|
|
opacity = opacity * 2.0 * paint_tool->curpressure;
|
1999-09-09 09:47:54 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paint_tool_paste_canvas (paint_tool, drawable,
|
2001-02-28 03:18:01 +08:00
|
|
|
MIN (opacity, 255),
|
|
|
|
gimp_context_get_opacity (NULL) * 255,
|
|
|
|
gimp_context_get_paint_mode (NULL),
|
|
|
|
pressure_options->pressure ? PRESSURE : SOFT,
|
|
|
|
scale, paint_appl_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
static GimpPaintbrushTool *non_gui_paintbrush = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
gboolean
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paintbrush_tool_non_gui_default (GimpDrawable *drawable,
|
2001-02-28 03:18:01 +08:00
|
|
|
gint num_strokes,
|
|
|
|
double *stroke_array)
|
1999-07-20 06:42:49 +08:00
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
GimpPaintTool *paint_tool;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (! non_gui_paintbrush)
|
1999-07-20 06:42:49 +08:00
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
non_gui_paintbrush = gtk_type_new (GIMP_TYPE_PAINTBRUSH_TOOL);
|
1999-07-20 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool = GIMP_PAINT_TOOL (non_gui_paintbrush);
|
1999-10-01 06:12:58 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
/* Hmmm... PDB paintbrush should have gradient type added to it!
|
|
|
|
* thats why the code below is duplicated.
|
|
|
|
*/
|
2001-02-28 07:20:51 +08:00
|
|
|
if (gimp_paint_tool_start (paint_tool, drawable,
|
|
|
|
stroke_array[0],
|
|
|
|
stroke_array[1]))
|
1999-07-20 06:42:49 +08:00
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool->startx = paint_tool->lastx = stroke_array[0];
|
|
|
|
paint_tool->starty = paint_tool->lasty = stroke_array[1];
|
1999-09-02 08:17:25 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
gimp_paint_tool_paint (paint_tool, drawable, MOTION_PAINT);
|
1999-07-20 06:42:49 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool->curx = stroke_array[i * 2 + 0];
|
|
|
|
paint_tool->cury = stroke_array[i * 2 + 1];
|
1999-07-20 06:42:49 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
gimp_paint_tool_interpolate (paint_tool, drawable);
|
1999-07-20 06:42:49 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool->lastx = paint_tool->curx;
|
|
|
|
paint_tool->lasty = paint_tool->cury;
|
1999-07-20 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finish the painting */
|
2001-02-28 07:20:51 +08:00
|
|
|
gimp_paint_tool_finish (paint_tool, drawable);
|
1999-07-20 06:42:49 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
2001-02-28 07:20:51 +08:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-07-20 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
gboolean
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_paintbrush_tool_non_gui (GimpDrawable *drawable,
|
2001-02-28 03:18:01 +08:00
|
|
|
gint num_strokes,
|
|
|
|
gdouble *stroke_array,
|
|
|
|
gdouble fade_out,
|
|
|
|
gint method,
|
|
|
|
gdouble gradient_length)
|
1999-03-17 13:40:16 +08:00
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
GimpPaintTool *paint_tool;
|
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
if (! non_gui_paintbrush)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
non_gui_paintbrush = gtk_type_new (GIMP_TYPE_PAINTBRUSH_TOOL);
|
|
|
|
}
|
1999-04-21 07:03:31 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool = GIMP_PAINT_TOOL (non_gui_paintbrush);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
/* Code duplicated above */
|
|
|
|
if (gimp_paint_tool_start (paint_tool, drawable,
|
|
|
|
stroke_array[0],
|
|
|
|
stroke_array[1]))
|
|
|
|
{
|
|
|
|
non_gui_gradient_options.fade_out = fade_out;
|
|
|
|
non_gui_gradient_options.gradient_length = gradient_length;
|
|
|
|
non_gui_gradient_options.gradient_type = LOOP_TRIANGLE;
|
|
|
|
non_gui_incremental = method;
|
1999-03-17 13:40:16 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool->startx = paint_tool->lastx = stroke_array[0];
|
|
|
|
paint_tool->starty = paint_tool->lasty = stroke_array[1];
|
1999-09-02 08:17:25 +08:00
|
|
|
|
1999-03-17 13:40:16 +08:00
|
|
|
if (num_strokes == 1)
|
2001-02-28 07:20:51 +08:00
|
|
|
gimp_paint_tool_paint (paint_tool, drawable, MOTION_PAINT);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
1999-04-23 14:07:09 +08:00
|
|
|
{
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool->curx = stroke_array[i * 2 + 0];
|
|
|
|
paint_tool->cury = stroke_array[i * 2 + 1];
|
1999-03-17 13:40:16 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
gimp_paint_tool_interpolate (paint_tool, drawable);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
2001-02-28 07:20:51 +08:00
|
|
|
paint_tool->lastx = paint_tool->curx;
|
|
|
|
paint_tool->lasty = paint_tool->cury;
|
1999-04-23 14:07:09 +08:00
|
|
|
}
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Finish the painting */
|
2001-02-28 07:20:51 +08:00
|
|
|
gimp_paint_tool_finish (paint_tool, drawable);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
return TRUE;
|
1999-03-17 13:40:16 +08:00
|
|
|
}
|
1999-04-19 05:22:41 +08:00
|
|
|
else
|
2001-02-28 07:20:51 +08:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|