took the fade options out of GimpGradientOptions and added them to the new

2003-07-15  Michael Natterer  <mitch@gimp.org>

	* app/paint/gimppaintoptions.[ch]: took the fade options out of
	GimpGradientOptions and added them to the new GimpFadeOptions
	struct. Added a GObject::finalize() implementation.

	* app/paint/gimppaintbrush.[ch]: changed accordingly. Made
	gimp_paintbrush_motion() a protected function and renamed it to
	_gimp_paintbrush_motion() added a "gdouble opacity" parameter so
	an initial brush opacity can be passed in by subclasses.

	* app/paint/gimpairbrush.[ch]: derive it from GimpPaintbrush so it
	gets all its rendering features. Removed own rendering code and
	use _gimp_paintbrush_motion(), passing airbrush_options->pressure
	as initial opacity. Removed all static variables.

	* app/tools/gimpairbrushtool.[ch]
	* app/tools/gimppenciltool.[ch]: derive them from GimpPaintbrushTool.

	* app/tools/gimppaintoptions-gui.c: changed accordingly. Added the
	full paintbrush options overkill to the airbrush GUI. Cleanup.

	* app/tools/gimperasertool.c: forgot to remove the "Hard Edge"
	toggle here.
This commit is contained in:
Michael Natterer
2003-07-15 15:38:24 +00:00
committed by Michael Natterer
parent b64dfbee05
commit 562865a092
13 changed files with 223 additions and 264 deletions

View File

@ -1,3 +1,28 @@
2003-07-15 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintoptions.[ch]: took the fade options out of
GimpGradientOptions and added them to the new GimpFadeOptions
struct. Added a GObject::finalize() implementation.
* app/paint/gimppaintbrush.[ch]: changed accordingly. Made
gimp_paintbrush_motion() a protected function and renamed it to
_gimp_paintbrush_motion() added a "gdouble opacity" parameter so
an initial brush opacity can be passed in by subclasses.
* app/paint/gimpairbrush.[ch]: derive it from GimpPaintbrush so it
gets all its rendering features. Removed own rendering code and
use _gimp_paintbrush_motion(), passing airbrush_options->pressure
as initial opacity. Removed all static variables.
* app/tools/gimpairbrushtool.[ch]
* app/tools/gimppenciltool.[ch]: derive them from GimpPaintbrushTool.
* app/tools/gimppaintoptions-gui.c: changed accordingly. Added the
full paintbrush options overkill to the airbrush GUI. Cleanup.
* app/tools/gimperasertool.c: forgot to remove the "Hard Edge"
toggle here.
2003-07-15 Sven Neumann <sven@gimp.org> 2003-07-15 Sven Neumann <sven@gimp.org>
* plug-ins/common/psd.c: use the new CMYK->RGB conversion routine to * plug-ins/common/psd.c: use the new CMYK->RGB conversion routine to

View File

@ -40,16 +40,6 @@
#include "gimp-intl.h" #include "gimp-intl.h"
typedef struct _AirbrushTimeout AirbrushTimeout;
struct _AirbrushTimeout
{
GimpPaintCore *paint_core;
GimpDrawable *drawable;
GimpPaintOptions *paint_options;
};
static void gimp_airbrush_class_init (GimpAirbrushClass *klass); static void gimp_airbrush_class_init (GimpAirbrushClass *klass);
static void gimp_airbrush_init (GimpAirbrush *airbrush); static void gimp_airbrush_init (GimpAirbrush *airbrush);
@ -59,17 +49,13 @@ static void gimp_airbrush_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpPaintOptions *paint_options, GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state); GimpPaintCoreState paint_state);
static void gimp_airbrush_motion (GimpPaintCore *paint_core, static void gimp_airbrush_motion (GimpPaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpPaintOptions *paint_options); GimpPaintOptions *paint_options);
static gboolean gimp_airbrush_timeout (gpointer data); static gboolean gimp_airbrush_timeout (gpointer data);
static guint timeout_id = 0; static GimpPaintbrushClass *parent_class = NULL;
static AirbrushTimeout airbrush_timeout;
static GimpPaintCoreClass *parent_class = NULL;
void void
@ -102,7 +88,7 @@ gimp_airbrush_get_type (void)
(GInstanceInitFunc) gimp_airbrush_init, (GInstanceInitFunc) gimp_airbrush_init,
}; };
type = g_type_register_static (GIMP_TYPE_PAINT_CORE, type = g_type_register_static (GIMP_TYPE_PAINTBRUSH,
"GimpAirbrush", "GimpAirbrush",
&info, 0); &info, 0);
} }
@ -129,20 +115,18 @@ gimp_airbrush_class_init (GimpAirbrushClass *klass)
static void static void
gimp_airbrush_init (GimpAirbrush *airbrush) gimp_airbrush_init (GimpAirbrush *airbrush)
{ {
GimpPaintCore *paint_core; airbrush->timeout_id = 0;
paint_core = GIMP_PAINT_CORE (airbrush);
paint_core->flags |= CORE_HANDLES_CHANGING_BRUSH;
} }
static void static void
gimp_airbrush_finalize (GObject *object) gimp_airbrush_finalize (GObject *object)
{ {
if (timeout_id) GimpAirbrush *airbrush = GIMP_AIRBRUSH (object);
if (airbrush->timeout_id)
{ {
g_source_remove (timeout_id); g_source_remove (airbrush->timeout_id);
timeout_id = 0; airbrush->timeout_id = 0;
} }
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
@ -154,25 +138,30 @@ gimp_airbrush_paint (GimpPaintCore *paint_core,
GimpPaintOptions *paint_options, GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state) GimpPaintCoreState paint_state)
{ {
GimpAirbrush *airbrush;
GimpAirbrushOptions *options; GimpAirbrushOptions *options;
options = (GimpAirbrushOptions *) paint_options; airbrush = GIMP_AIRBRUSH (paint_core);
options = GIMP_AIRBRUSH_OPTIONS (paint_options);
switch (paint_state) switch (paint_state)
{ {
case INIT_PAINT: case INIT_PAINT:
if (timeout_id) if (airbrush->timeout_id)
{ {
g_source_remove (timeout_id); g_source_remove (airbrush->timeout_id);
timeout_id = 0; airbrush->timeout_id = 0;
} }
GIMP_PAINT_CORE_CLASS (parent_class)->paint (paint_core, drawable,
paint_options, paint_state);
break; break;
case MOTION_PAINT: case MOTION_PAINT:
if (timeout_id) if (airbrush->timeout_id)
{ {
g_source_remove (timeout_id); g_source_remove (airbrush->timeout_id);
timeout_id = 0; airbrush->timeout_id = 0;
} }
gimp_airbrush_motion (paint_core, drawable, paint_options); gimp_airbrush_motion (paint_core, drawable, paint_options);
@ -181,29 +170,33 @@ gimp_airbrush_paint (GimpPaintCore *paint_core,
{ {
gdouble timeout; gdouble timeout;
airbrush_timeout.paint_core = paint_core; airbrush->drawable = drawable;
airbrush_timeout.drawable = drawable; airbrush->paint_options = paint_options;
airbrush_timeout.paint_options = paint_options;
timeout = (paint_options->pressure_options->rate ? timeout = (paint_options->pressure_options->rate ?
(10000 / (options->rate * 2.0 * paint_core->cur_coords.pressure)) : (10000 / (options->rate * 2.0 * paint_core->cur_coords.pressure)) :
(10000 / options->rate)); (10000 / options->rate));
timeout_id = g_timeout_add (timeout, airbrush->timeout_id = g_timeout_add (timeout,
gimp_airbrush_timeout, gimp_airbrush_timeout,
NULL); airbrush);
} }
break; break;
case FINISH_PAINT: case FINISH_PAINT:
if (timeout_id) if (airbrush->timeout_id)
{ {
g_source_remove (timeout_id); g_source_remove (airbrush->timeout_id);
timeout_id = 0; airbrush->timeout_id = 0;
} }
GIMP_PAINT_CORE_CLASS (parent_class)->paint (paint_core, drawable,
paint_options, paint_state);
break; break;
default: default:
GIMP_PAINT_CORE_CLASS (parent_class)->paint (paint_core, drawable,
paint_options, paint_state);
break; break;
} }
} }
@ -213,111 +206,35 @@ gimp_airbrush_motion (GimpPaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpPaintOptions *paint_options) GimpPaintOptions *paint_options)
{ {
GimpImage *gimage; GimpAirbrushOptions *options;
GimpContext *context; gdouble opacity;
TempBuf *area; gboolean saved_pressure;
guchar col[MAX_CHANNELS];
gdouble scale;
gdouble pressure;
GimpPaintApplicationMode paint_appl_mode;
if (! (gimage = gimp_item_get_image (GIMP_ITEM (drawable)))) options = GIMP_AIRBRUSH_OPTIONS (paint_options);
return;
context = GIMP_CONTEXT (paint_options); opacity = options->pressure / 100.0;
paint_appl_mode = paint_options->application_mode; saved_pressure = paint_options->pressure_options->pressure;
pressure = GIMP_AIRBRUSH_OPTIONS (paint_options)->pressure / 100.0; if (saved_pressure)
opacity *= 2.0 * paint_core->cur_coords.pressure;
if (paint_options->pressure_options->size) paint_options->pressure_options->pressure = FALSE;
scale = paint_core->cur_coords.pressure; _gimp_paintbrush_motion (paint_core, drawable, paint_options, opacity);
else paint_options->pressure_options->pressure = saved_pressure;
scale = 1.0;
if (! (area = gimp_paint_core_get_paint_area (paint_core, drawable, scale)))
return;
/* color the pixels */
if (paint_options->pressure_options->color)
{
GimpRGB color;
gimp_gradient_get_color_at (gimp_context_get_gradient (context),
paint_core->cur_coords.pressure, &color);
gimp_rgba_get_uchar (&color,
&col[RED_PIX],
&col[GREEN_PIX],
&col[BLUE_PIX],
&col[ALPHA_PIX]);
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
color_pixels (temp_buf_data (area), col,
area->width * area->height,
area->bytes);
}
else if (paint_core->brush && paint_core->brush->pixmap)
{
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
gimp_paint_core_color_area_with_pixmap (paint_core, gimage,
drawable, area,
scale, GIMP_BRUSH_SOFT);
}
else
{
gimp_image_get_foreground (gimage, drawable, col);
col[area->bytes - 1] = OPAQUE_OPACITY;
color_pixels (temp_buf_data (area), col,
area->width * area->height, area->bytes);
}
if (paint_options->pressure_options->pressure)
pressure = pressure * 2.0 * paint_core->cur_coords.pressure;
/* paste the newly painted area to the image */
gimp_paint_core_paste_canvas (paint_core, drawable,
MIN (pressure, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
gimp_context_get_paint_mode (context),
GIMP_BRUSH_SOFT,
scale,
paint_appl_mode);
} }
static gboolean static gboolean
gimp_airbrush_timeout (gpointer client_data) gimp_airbrush_timeout (gpointer data)
{ {
gdouble rate; GimpAirbrush *airbrush = GIMP_AIRBRUSH (data);
gimp_airbrush_motion (airbrush_timeout.paint_core, gimp_airbrush_paint (GIMP_PAINT_CORE (airbrush),
airbrush_timeout.drawable, airbrush->drawable,
airbrush_timeout.paint_options); airbrush->paint_options,
MOTION_PAINT);
gimp_image_flush (gimp_item_get_image (GIMP_ITEM (airbrush_timeout.drawable))); gimp_image_flush (gimp_item_get_image (GIMP_ITEM (airbrush->drawable)));
rate = GIMP_AIRBRUSH_OPTIONS (airbrush_timeout.paint_options)->rate;
/* restart the timer */
if (rate != 0.0)
{
if (airbrush_timeout.paint_options->pressure_options->rate)
{
if (timeout_id)
g_source_remove (timeout_id);
timeout_id = g_timeout_add ((10000 /
(rate * 2.0 *
airbrush_timeout.paint_core->cur_coords.pressure)),
gimp_airbrush_timeout,
NULL);
return FALSE;
}
return TRUE;
}
return FALSE; return FALSE;
} }

View File

@ -20,7 +20,7 @@
#define __GIMP_AIRBRUSH_H__ #define __GIMP_AIRBRUSH_H__
#include "gimppaintcore.h" #include "gimppaintbrush.h"
#define GIMP_TYPE_AIRBRUSH (gimp_airbrush_get_type ()) #define GIMP_TYPE_AIRBRUSH (gimp_airbrush_get_type ())
@ -36,12 +36,16 @@ typedef struct _GimpAirbrushClass GimpAirbrushClass;
struct _GimpAirbrush struct _GimpAirbrush
{ {
GimpPaintCore parent_instance; GimpPaintbrush parent_instance;
guint timeout_id;
GimpDrawable *drawable;
GimpPaintOptions *paint_options;
}; };
struct _GimpAirbrushClass struct _GimpAirbrushClass
{ {
GimpPaintCoreClass parent_class; GimpPaintbrushClass parent_class;
}; };

View File

@ -49,9 +49,6 @@ static void gimp_paintbrush_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpPaintOptions *paint_options, GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state); GimpPaintCoreState paint_state);
static void gimp_paintbrush_motion (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options);
static GimpPaintCoreClass *parent_class = NULL; static GimpPaintCoreClass *parent_class = NULL;
@ -126,7 +123,8 @@ gimp_paintbrush_paint (GimpPaintCore *paint_core,
switch (paint_state) switch (paint_state)
{ {
case MOTION_PAINT: case MOTION_PAINT:
gimp_paintbrush_motion (paint_core, drawable, paint_options); _gimp_paintbrush_motion (paint_core, drawable, paint_options,
GIMP_OPACITY_OPAQUE);
break; break;
default: default:
@ -134,20 +132,20 @@ gimp_paintbrush_paint (GimpPaintCore *paint_core,
} }
} }
static void void
gimp_paintbrush_motion (GimpPaintCore *paint_core, _gimp_paintbrush_motion (GimpPaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpPaintOptions *paint_options) GimpPaintOptions *paint_options,
gdouble opacity)
{ {
GimpPressureOptions *pressure_options; GimpPressureOptions *pressure_options;
GimpFadeOptions *fade_options;
GimpGradientOptions *gradient_options; GimpGradientOptions *gradient_options;
GimpContext *context; GimpContext *context;
GimpImage *gimage; GimpImage *gimage;
TempBuf *area; TempBuf *area;
gdouble gradient_length; gdouble gradient_length;
guchar local_blend = OPAQUE_OPACITY;
guchar col[MAX_CHANNELS]; guchar col[MAX_CHANNELS];
gdouble opacity;
gdouble scale; gdouble scale;
GimpPaintApplicationMode paint_appl_mode; GimpPaintApplicationMode paint_appl_mode;
@ -157,42 +155,42 @@ gimp_paintbrush_motion (GimpPaintCore *paint_core,
context = GIMP_CONTEXT (paint_options); context = GIMP_CONTEXT (paint_options);
pressure_options = paint_options->pressure_options; pressure_options = paint_options->pressure_options;
fade_options = paint_options->fade_options;
gradient_options = paint_options->gradient_options; gradient_options = paint_options->gradient_options;
paint_appl_mode = paint_options->application_mode; paint_appl_mode = paint_options->application_mode;
if (gradient_options->use_fade) if (fade_options->use_fade)
{ {
gdouble fade_out = 0.0; gdouble fade_out = 0.0;
gdouble unit_factor; gdouble unit_factor;
switch (gradient_options->fade_unit) switch (fade_options->fade_unit)
{ {
case GIMP_UNIT_PIXEL: case GIMP_UNIT_PIXEL:
fade_out = gradient_options->fade_length; fade_out = fade_options->fade_length;
break; break;
case GIMP_UNIT_PERCENT: case GIMP_UNIT_PERCENT:
fade_out = (MAX (gimage->width, gimage->height) * fade_out = (MAX (gimage->width, gimage->height) *
gradient_options->fade_length / 100); fade_options->fade_length / 100);
break; break;
default: default:
unit_factor = gimp_unit_get_factor (gradient_options->fade_unit); unit_factor = gimp_unit_get_factor (fade_options->fade_unit);
fade_out = (gradient_options->fade_length * fade_out = (fade_options->fade_length *
MAX (gimage->xresolution, MAX (gimage->xresolution,
gimage->yresolution) / unit_factor); gimage->yresolution) / unit_factor);
break; break;
} }
/* factor in the fade out value */ /* factor in the fade out value */
if (fade_out) if (fade_out)
{ {
gdouble x, paint_left; gdouble x;
/* Model the amount of paint left as a gaussian curve */ /* Model the amount of paint left as a gaussian curve */
x = ((gdouble) paint_core->pixel_dist / fade_out); x = ((gdouble) paint_core->pixel_dist / fade_out);
paint_left = exp (- x * x * 5.541); /* ln (1/255) */
local_blend = (gint) (255 * paint_left); opacity = exp (- x * x * 5.541); /* ln (1/255) */
} }
} }
@ -234,13 +232,8 @@ gimp_paintbrush_motion (GimpPaintCore *paint_core,
if (! (area = gimp_paint_core_get_paint_area (paint_core, drawable, scale))) if (! (area = gimp_paint_core_get_paint_area (paint_core, drawable, scale)))
return; return;
if (local_blend) if (opacity > 0.0)
{ {
guchar temp_blend;
/* set the alpha channel */
temp_blend = local_blend;
if (gradient_length) if (gradient_length)
{ {
GimpGradient *gradient; GimpGradient *gradient;
@ -259,7 +252,7 @@ gimp_paintbrush_motion (GimpPaintCore *paint_core,
&color, &color,
gradient_options->gradient_type); gradient_options->gradient_type);
temp_blend = (gint) ((color.a * local_blend)); opacity *= color.a;
gimp_rgb_get_uchar (&color, gimp_rgb_get_uchar (&color,
&col[RED_PIX], &col[RED_PIX],
@ -268,13 +261,11 @@ gimp_paintbrush_motion (GimpPaintCore *paint_core,
col[ALPHA_PIX] = OPAQUE_OPACITY; col[ALPHA_PIX] = OPAQUE_OPACITY;
color_pixels (temp_buf_data (area), col, color_pixels (temp_buf_data (area), col,
area->width * area->height, area->bytes); area->width * area->height,
area->bytes);
paint_appl_mode = GIMP_PAINT_INCREMENTAL; paint_appl_mode = GIMP_PAINT_INCREMENTAL;
} }
/* we check to see if this is a pixmap, if so composite the
* pixmap image into the area instead of the color
*/
else if (paint_core->brush && paint_core->brush->pixmap) else if (paint_core->brush && paint_core->brush->pixmap)
{ {
/* if it's a pixmap, do pixmap stuff */ /* if it's a pixmap, do pixmap stuff */
@ -290,13 +281,12 @@ gimp_paintbrush_motion (GimpPaintCore *paint_core,
gimp_image_get_foreground (gimage, drawable, col); gimp_image_get_foreground (gimage, drawable, col);
col[area->bytes - 1] = OPAQUE_OPACITY; col[area->bytes - 1] = OPAQUE_OPACITY;
color_pixels (temp_buf_data (area), col, color_pixels (temp_buf_data (area), col,
area->width * area->height, area->bytes); area->width * area->height,
area->bytes);
} }
opacity = (gdouble) temp_blend / 255.0;
if (pressure_options->opacity) if (pressure_options->opacity)
opacity = opacity * 2.0 * paint_core->cur_coords.pressure; opacity *= 2.0 * paint_core->cur_coords.pressure;
gimp_paint_core_paste_canvas (paint_core, drawable, gimp_paint_core_paste_canvas (paint_core, drawable,
MIN (opacity, GIMP_OPACITY_OPAQUE), MIN (opacity, GIMP_OPACITY_OPAQUE),

View File

@ -51,4 +51,12 @@ void gimp_paintbrush_register (Gimp *gimp,
GType gimp_paintbrush_get_type (void) G_GNUC_CONST; GType gimp_paintbrush_get_type (void) G_GNUC_CONST;
/* protected */
void _gimp_paintbrush_motion (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
gdouble opacity);
#endif /* __GIMP_PAINTBRUSH_H__ */ #endif /* __GIMP_PAINTBRUSH_H__ */

View File

@ -72,6 +72,7 @@ enum
static void gimp_paint_options_init (GimpPaintOptions *options); static void gimp_paint_options_init (GimpPaintOptions *options);
static void gimp_paint_options_class_init (GimpPaintOptionsClass *options_class); static void gimp_paint_options_class_init (GimpPaintOptionsClass *options_class);
static void gimp_paint_options_finalize (GObject *object);
static void gimp_paint_options_set_property (GObject *object, static void gimp_paint_options_set_property (GObject *object,
guint property_id, guint property_id,
const GValue *value, const GValue *value,
@ -124,6 +125,7 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_paint_options_finalize;
object_class->set_property = gimp_paint_options_set_property; object_class->set_property = gimp_paint_options_set_property;
object_class->get_property = gimp_paint_options_get_property; object_class->get_property = gimp_paint_options_get_property;
object_class->notify = gimp_paint_options_notify; object_class->notify = gimp_paint_options_notify;
@ -196,9 +198,22 @@ gimp_paint_options_init (GimpPaintOptions *options)
options->application_mode_save = DEFAULT_APPLICATION_MODE; options->application_mode_save = DEFAULT_APPLICATION_MODE;
options->pressure_options = g_new0 (GimpPressureOptions, 1); options->pressure_options = g_new0 (GimpPressureOptions, 1);
options->fade_options = g_new0 (GimpFadeOptions, 1);
options->gradient_options = g_new0 (GimpGradientOptions, 1); options->gradient_options = g_new0 (GimpGradientOptions, 1);
} }
static void
gimp_paint_options_finalize (GObject *object)
{
GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);
g_free (options->pressure_options);
g_free (options->fade_options);
g_free (options->gradient_options);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void static void
gimp_paint_options_set_property (GObject *object, gimp_paint_options_set_property (GObject *object,
guint property_id, guint property_id,
@ -207,11 +222,13 @@ gimp_paint_options_set_property (GObject *object,
{ {
GimpPaintOptions *options; GimpPaintOptions *options;
GimpPressureOptions *pressure_options; GimpPressureOptions *pressure_options;
GimpFadeOptions *fade_options;
GimpGradientOptions *gradient_options; GimpGradientOptions *gradient_options;
options = GIMP_PAINT_OPTIONS (object); options = GIMP_PAINT_OPTIONS (object);
pressure_options = options->pressure_options; pressure_options = options->pressure_options;
fade_options = options->fade_options;
gradient_options = options->gradient_options; gradient_options = options->gradient_options;
switch (property_id) switch (property_id)
@ -240,13 +257,13 @@ gimp_paint_options_set_property (GObject *object,
break; break;
case PROP_USE_FADE: case PROP_USE_FADE:
gradient_options->use_fade = g_value_get_boolean (value); fade_options->use_fade = g_value_get_boolean (value);
break; break;
case PROP_FADE_LENGTH: case PROP_FADE_LENGTH:
gradient_options->fade_length = g_value_get_double (value); fade_options->fade_length = g_value_get_double (value);
break; break;
case PROP_FADE_UNIT: case PROP_FADE_UNIT:
gradient_options->fade_unit = g_value_get_int (value); fade_options->fade_unit = g_value_get_int (value);
break; break;
case PROP_USE_GRADIENT: case PROP_USE_GRADIENT:
@ -276,11 +293,13 @@ gimp_paint_options_get_property (GObject *object,
{ {
GimpPaintOptions *options; GimpPaintOptions *options;
GimpPressureOptions *pressure_options; GimpPressureOptions *pressure_options;
GimpFadeOptions *fade_options;
GimpGradientOptions *gradient_options; GimpGradientOptions *gradient_options;
options = GIMP_PAINT_OPTIONS (object); options = GIMP_PAINT_OPTIONS (object);
pressure_options = options->pressure_options; pressure_options = options->pressure_options;
fade_options = options->fade_options;
gradient_options = options->gradient_options; gradient_options = options->gradient_options;
switch (property_id) switch (property_id)
@ -309,13 +328,13 @@ gimp_paint_options_get_property (GObject *object,
break; break;
case PROP_USE_FADE: case PROP_USE_FADE:
g_value_set_boolean (value, gradient_options->use_fade); g_value_set_boolean (value, fade_options->use_fade);
break; break;
case PROP_FADE_LENGTH: case PROP_FADE_LENGTH:
g_value_set_double (value, gradient_options->fade_length); g_value_set_double (value, fade_options->fade_length);
break; break;
case PROP_FADE_UNIT: case PROP_FADE_UNIT:
g_value_set_int (value, gradient_options->fade_unit); g_value_set_int (value, fade_options->fade_unit);
break; break;
case PROP_USE_GRADIENT: case PROP_USE_GRADIENT:

View File

@ -29,6 +29,7 @@
typedef struct _GimpPressureOptions GimpPressureOptions; typedef struct _GimpPressureOptions GimpPressureOptions;
typedef struct _GimpFadeOptions GimpFadeOptions;
typedef struct _GimpGradientOptions GimpGradientOptions; typedef struct _GimpGradientOptions GimpGradientOptions;
struct _GimpPressureOptions struct _GimpPressureOptions
@ -40,12 +41,15 @@ struct _GimpPressureOptions
gboolean color; gboolean color;
}; };
struct _GimpGradientOptions struct _GimpFadeOptions
{ {
gboolean use_fade; gboolean use_fade;
gdouble fade_length; gdouble fade_length;
GimpUnit fade_unit; GimpUnit fade_unit;
};
struct _GimpGradientOptions
{
gboolean use_gradient; gboolean use_gradient;
gdouble gradient_length; gdouble gradient_length;
GimpUnit gradient_unit; GimpUnit gradient_unit;
@ -73,6 +77,7 @@ struct _GimpPaintOptions
gboolean hard; gboolean hard;
GimpPressureOptions *pressure_options; GimpPressureOptions *pressure_options;
GimpFadeOptions *fade_options;
GimpGradientOptions *gradient_options; GimpGradientOptions *gradient_options;
}; };

View File

@ -44,7 +44,7 @@ static void gimp_airbrush_tool_init (GimpAirbrushTool *airbrush);
static GtkWidget * gimp_airbrush_options_gui (GimpToolOptions *tool_options); static GtkWidget * gimp_airbrush_options_gui (GimpToolOptions *tool_options);
static GimpPaintToolClass *parent_class = NULL; static GimpPaintbrushToolClass *parent_class = NULL;
/* functions */ /* functions */
@ -86,7 +86,7 @@ gimp_airbrush_tool_get_type (void)
(GInstanceInitFunc) gimp_airbrush_tool_init, (GInstanceInitFunc) gimp_airbrush_tool_init,
}; };
tool_type = g_type_register_static (GIMP_TYPE_PAINT_TOOL, tool_type = g_type_register_static (GIMP_TYPE_PAINTBRUSH_TOOL,
"GimpAirbrushTool", "GimpAirbrushTool",
&tool_info, 0); &tool_info, 0);
} }

View File

@ -20,7 +20,7 @@
#define __GIMP_AIRBRUSH_TOOL_H__ #define __GIMP_AIRBRUSH_TOOL_H__
#include "gimppainttool.h" #include "gimppaintbrushtool.h"
#define GIMP_TYPE_AIRBRUSH_TOOL (gimp_airbrush_tool_get_type ()) #define GIMP_TYPE_AIRBRUSH_TOOL (gimp_airbrush_tool_get_type ())
@ -36,12 +36,12 @@ typedef struct _GimpAirbrushToolClass GimpAirbrushToolClass;
struct _GimpAirbrushTool struct _GimpAirbrushTool
{ {
GimpPaintTool parent_instance; GimpPaintbrushTool parent_instance;
}; };
struct _GimpAirbrushToolClass struct _GimpAirbrushToolClass
{ {
GimpPaintToolClass parent_class; GimpPaintbrushToolClass parent_class;
}; };

View File

@ -154,8 +154,7 @@ gimp_eraser_tool_modifier_key (GimpTool *tool,
NULL); NULL);
} }
GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state, gdisp);
key, press, state, gdisp);
} }
static void static void
@ -197,10 +196,5 @@ gimp_eraser_options_gui (GimpToolOptions *tool_options)
g_free (str); g_free (str);
/* the hard toggle */
button = gimp_prop_check_button_new (config, "hard", _("Hard Edge"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
return vbox; return vbox;
} }

View File

@ -57,16 +57,16 @@
#include "gimp-intl.h" #include "gimp-intl.h"
static GtkWidget * pressure_options_gui (GimpPressureOptions *pressure, static GtkWidget * pressure_options_gui (GimpPressureOptions *pressure,
GimpPaintOptions *paint_options, GimpPaintOptions *paint_options,
GType tool_type); GType tool_type);
static GtkWidget * fade_options_gui (GimpGradientOptions *gradient, static GtkWidget * fade_options_gui (GimpFadeOptions *fade,
GimpPaintOptions *paint_options, GimpPaintOptions *paint_options,
GType tool_type); GType tool_type);
static GtkWidget * gradient_options_gui (GimpGradientOptions *gradient, static GtkWidget * gradient_options_gui (GimpGradientOptions *gradient,
GimpPaintOptions *paint_options, GimpPaintOptions *paint_options,
GType tool_type, GType tool_type,
GtkWidget *incremental_toggle); GtkWidget *incremental_toggle);
GtkWidget * GtkWidget *
@ -83,7 +83,8 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
GtkWidget *button; GtkWidget *button;
GimpDialogFactory *dialog_factory; GimpDialogFactory *dialog_factory;
GtkWidget *incremental_toggle = NULL; GtkWidget *incremental_toggle = NULL;
gint table_row = 0; gint table_row = 0;
GType tool_type;
options = GIMP_PAINT_OPTIONS (tool_options); options = GIMP_PAINT_OPTIONS (tool_options);
context = GIMP_CONTEXT (tool_options); context = GIMP_CONTEXT (tool_options);
@ -93,6 +94,8 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
dialog_factory = gimp_dialog_factory_from_name ("dock"); dialog_factory = gimp_dialog_factory_from_name ("dock");
tool_type = tool_options->tool_info->tool_type;
/* the main table */ /* the main table */
table = gtk_table_new (3, 3, FALSE); table = gtk_table_new (3, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2); gtk_table_set_col_spacings (GTK_TABLE (table), 2);
@ -113,19 +116,19 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
_("Mode:"), 1.0, 0.5, _("Mode:"), 1.0, 0.5,
optionmenu, 2, TRUE); optionmenu, 2, TRUE);
if (tool_options->tool_info->tool_type == GIMP_TYPE_ERASER_TOOL || if (tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_CONVOLVE_TOOL || tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_DODGEBURN_TOOL || tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_SMUDGE_TOOL) tool_type == GIMP_TYPE_SMUDGE_TOOL)
{ {
gtk_widget_set_sensitive (optionmenu, FALSE); gtk_widget_set_sensitive (optionmenu, FALSE);
gtk_widget_set_sensitive (mode_label, FALSE); gtk_widget_set_sensitive (mode_label, FALSE);
} }
/* the brush preview */ /* the brush preview */
if (tool_options->tool_info->tool_type != GIMP_TYPE_BUCKET_FILL_TOOL && if (tool_type != GIMP_TYPE_BUCKET_FILL_TOOL &&
tool_options->tool_info->tool_type != GIMP_TYPE_BLEND_TOOL && tool_type != GIMP_TYPE_BLEND_TOOL &&
tool_options->tool_info->tool_type != GIMP_TYPE_INK_TOOL) tool_type != GIMP_TYPE_INK_TOOL)
{ {
button = gimp_viewable_button_new (context->gimp->brush_factory->container, button = gimp_viewable_button_new (context->gimp->brush_factory->container,
context, context,
@ -141,8 +144,8 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
} }
/* the pattern preview */ /* the pattern preview */
if (tool_options->tool_info->tool_type == GIMP_TYPE_BUCKET_FILL_TOOL || if (tool_type == GIMP_TYPE_BUCKET_FILL_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_CLONE_TOOL) tool_type == GIMP_TYPE_CLONE_TOOL)
{ {
button = gimp_viewable_button_new (context->gimp->pattern_factory->container, button = gimp_viewable_button_new (context->gimp->pattern_factory->container,
context, context,
@ -158,8 +161,7 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
} }
/* the gradient preview */ /* the gradient preview */
if (tool_options->tool_info->tool_type == GIMP_TYPE_PAINTBRUSH_TOOL || if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL) ||
tool_options->tool_info->tool_type == GIMP_TYPE_PENCIL_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_BLEND_TOOL) tool_options->tool_info->tool_type == GIMP_TYPE_BLEND_TOOL)
{ {
button = gimp_viewable_button_new (context->gimp->gradient_factory->container, button = gimp_viewable_button_new (context->gimp->gradient_factory->container,
@ -179,10 +181,8 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
} }
/* the "incremental" toggle */ /* the "incremental" toggle */
if (tool_options->tool_info->tool_type == GIMP_TYPE_AIRBRUSH_TOOL || if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL) ||
tool_options->tool_info->tool_type == GIMP_TYPE_ERASER_TOOL || tool_options->tool_info->tool_type == GIMP_TYPE_ERASER_TOOL)
tool_options->tool_info->tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_PENCIL_TOOL)
{ {
incremental_toggle = incremental_toggle =
gimp_prop_enum_check_button_new (config, gimp_prop_enum_check_button_new (config,
@ -194,18 +194,28 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (incremental_toggle); gtk_widget_show (incremental_toggle);
} }
/* the "hard edge" toggle */
if (tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
button = gimp_prop_check_button_new (config, "hard", _("Hard Edge"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
}
frame = pressure_options_gui (options->pressure_options, frame = pressure_options_gui (options->pressure_options,
options, options, tool_type);
tool_options->tool_info->tool_type);
if (frame) if (frame)
{ {
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame); gtk_widget_show (frame);
} }
frame = fade_options_gui (options->gradient_options, frame = fade_options_gui (options->fade_options,
options, options, tool_type);
tool_options->tool_info->tool_type);
if (frame) if (frame)
{ {
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
@ -213,8 +223,7 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
} }
frame = gradient_options_gui (options->gradient_options, frame = gradient_options_gui (options->gradient_options,
options, options, tool_type,
tool_options->tool_info->tool_type,
incremental_toggle); incremental_toggle);
if (frame) if (frame)
{ {
@ -240,19 +249,17 @@ pressure_options_gui (GimpPressureOptions *pressure,
config = G_OBJECT (paint_options); config = G_OBJECT (paint_options);
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL || if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL) ||
tool_type == GIMP_TYPE_CLONE_TOOL || tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL || tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGEBURN_TOOL || tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL || tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_PENCIL_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL) tool_type == GIMP_TYPE_SMUDGE_TOOL)
{ {
frame = gtk_frame_new (_("Pressure Sensitivity")); frame = gtk_frame_new (_("Pressure Sensitivity"));
wbox = gtk_hwrap_box_new (FALSE); wbox = gtk_hwrap_box_new (FALSE);
gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (wbox), 6); gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (wbox), 7);
gtk_container_add (GTK_CONTAINER (frame), wbox); gtk_container_add (GTK_CONTAINER (frame), wbox);
gtk_widget_show (wbox); gtk_widget_show (wbox);
} }
@ -296,13 +303,11 @@ pressure_options_gui (GimpPressureOptions *pressure,
} }
/* the size toggle */ /* the size toggle */
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL || if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL) ||
tool_type == GIMP_TYPE_CLONE_TOOL || tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL || tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGEBURN_TOOL || tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL || tool_type == GIMP_TYPE_ERASER_TOOL)
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_PENCIL_TOOL)
{ {
button = gimp_prop_check_button_new (config, "pressure-size", button = gimp_prop_check_button_new (config, "pressure-size",
_("Size")); _("Size"));
@ -311,9 +316,7 @@ pressure_options_gui (GimpPressureOptions *pressure,
} }
/* the color toggle */ /* the color toggle */
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL || if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL))
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_PENCIL_TOOL)
{ {
button = gimp_prop_check_button_new (config, "pressure-color", button = gimp_prop_check_button_new (config, "pressure-color",
_("Color")); _("Color"));
@ -325,9 +328,9 @@ pressure_options_gui (GimpPressureOptions *pressure,
} }
static GtkWidget * static GtkWidget *
fade_options_gui (GimpGradientOptions *gradient, fade_options_gui (GimpFadeOptions *fade,
GimpPaintOptions *paint_options, GimpPaintOptions *paint_options,
GType tool_type) GType tool_type)
{ {
GObject *config; GObject *config;
GtkWidget *frame = NULL; GtkWidget *frame = NULL;
@ -338,8 +341,7 @@ fade_options_gui (GimpGradientOptions *gradient,
config = G_OBJECT (paint_options); config = G_OBJECT (paint_options);
if (tool_type == GIMP_TYPE_PAINTBRUSH_TOOL || if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL))
tool_type == GIMP_TYPE_PENCIL_TOOL)
{ {
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);
@ -354,7 +356,7 @@ fade_options_gui (GimpGradientOptions *gradient,
gtk_frame_set_label_widget (GTK_FRAME (frame), button); gtk_frame_set_label_widget (GTK_FRAME (frame), button);
gtk_widget_show (button); gtk_widget_show (button);
gtk_widget_set_sensitive (table, gradient->use_fade); gtk_widget_set_sensitive (table, fade->use_fade);
g_object_set_data (G_OBJECT (button), "set_sensitive", table); g_object_set_data (G_OBJECT (button), "set_sensitive", table);
/* the fade-out sizeentry */ /* the fade-out sizeentry */
@ -394,8 +396,7 @@ gradient_options_gui (GimpGradientOptions *gradient,
config = G_OBJECT (paint_options); config = G_OBJECT (paint_options);
if (tool_type == GIMP_TYPE_PAINTBRUSH_TOOL || if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL))
tool_type == GIMP_TYPE_PENCIL_TOOL)
{ {
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);

View File

@ -38,7 +38,7 @@ static void gimp_pencil_tool_class_init (GimpPencilToolClass *klass);
static void gimp_pencil_tool_init (GimpPencilTool *pancil); static void gimp_pencil_tool_init (GimpPencilTool *pancil);
static GimpPaintToolClass *parent_class = NULL; static GimpPaintbrushToolClass *parent_class = NULL;
/* functions */ /* functions */
@ -80,7 +80,7 @@ gimp_pencil_tool_get_type (void)
(GInstanceInitFunc) gimp_pencil_tool_init, (GInstanceInitFunc) gimp_pencil_tool_init,
}; };
tool_type = g_type_register_static (GIMP_TYPE_PAINT_TOOL, tool_type = g_type_register_static (GIMP_TYPE_PAINTBRUSH_TOOL,
"GimpPencilTool", "GimpPencilTool",
&tool_info, 0); &tool_info, 0);
} }

View File

@ -19,12 +19,8 @@
#ifndef __GIMP_PENCIL_TOOL_H__ #ifndef __GIMP_PENCIL_TOOL_H__
#define __GIMP_PENCIL_TOOL_H__ #define __GIMP_PENCIL_TOOL_H__
/* FIXME: This whole tool should probably just be a paintbrush tool that
* has an option of hard edge. It'll give the "pencil tool" all the
* flashy stuff the paintbrush tool has, and not duplicate code.
*/
#include "gimppainttool.h" #include "gimppaintbrushtool.h"
#define GIMP_TYPE_PENCIL_TOOL (gimp_pencil_tool_get_type ()) #define GIMP_TYPE_PENCIL_TOOL (gimp_pencil_tool_get_type ())
@ -40,12 +36,12 @@ typedef struct _GimpPencilToolClass GimpPencilToolClass;
struct _GimpPencilTool struct _GimpPencilTool
{ {
GimpPaintTool parent_instance; GimpPaintbrushTool parent_instance;
}; };
struct _GimpPencilToolClass struct _GimpPencilToolClass
{ {
GimpPaintToolClass parent_class; GimpPaintbrushToolClass parent_class;
}; };