Commit 3e269083 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added new virtual function GimpPaintCore::post_paint() and call it after

2004-06-14  Michael Natterer  <mitch@gimp.org>

	* app/paint/gimppaintcore.[ch]: added new virtual function
	GimpPaintCore::post_paint() and call it after calling
	GimpPaintCore::paint().

	* app/paint/gimpbrushcore.[ch]: renamed brush_core->grr_brush
	to brush_core->main_brush and reset brush_core->brush
	to brush_core->main_brush in GimpPaintCore::post_paint().

	* app/paint/gimpbrushcore.c
	* app/paint/gimppaintcore-stroke.c
	* app/tools/gimppainttool.c: removed all code which restores
	the brush_core's old brush after painting since post_paint()
	does this automatically now.

	* app/paint/gimpclone.[ch]: moved static variables to the
	GimpClone struct.
parent 0256a2dc
2004-06-14 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintcore.[ch]: added new virtual function
GimpPaintCore::post_paint() and call it after calling
GimpPaintCore::paint().
* app/paint/gimpbrushcore.[ch]: renamed brush_core->grr_brush
to brush_core->main_brush and reset brush_core->brush
to brush_core->main_brush in GimpPaintCore::post_paint().
* app/paint/gimpbrushcore.c
* app/paint/gimppaintcore-stroke.c
* app/tools/gimppainttool.c: removed all code which restores
the brush_core's old brush after painting since post_paint()
does this automatically now.
* app/paint/gimpclone.[ch]: moved static variables to the
GimpClone struct.
2004-06-14 Sven Neumann <sven@gimp.org>
* app/paint-funcs/paint-funcs-generic.h (color_pixels): some code
......
......@@ -58,6 +58,11 @@ static gboolean gimp_brush_core_pre_paint (GimpPaintCore *core,
GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state,
guint32 time);
static void gimp_brush_core_post_paint (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state,
guint32 time);
static void gimp_brush_core_interpolate (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
......@@ -157,6 +162,7 @@ gimp_brush_core_class_init (GimpBrushCoreClass *klass)
paint_core_class->start = gimp_brush_core_start;
paint_core_class->pre_paint = gimp_brush_core_pre_paint;
paint_core_class->post_paint = gimp_brush_core_post_paint;
paint_core_class->interpolate = gimp_brush_core_interpolate;
paint_core_class->get_paint_area = gimp_brush_core_get_paint_area;
......@@ -169,6 +175,7 @@ gimp_brush_core_init (GimpBrushCore *core)
{
gint i, j;
core->main_brush = NULL;
core->brush = NULL;
core->spacing = 1.0;
core->scale = 1.0;
......@@ -201,7 +208,6 @@ gimp_brush_core_init (GimpBrushCore *core)
core->last_brush_mask = NULL;
core->cache_invalid = FALSE;
core->grr_brush = NULL;
core->brush_bound_segs = NULL;
core->n_brush_bound_segs = 0;
}
......@@ -246,13 +252,13 @@ gimp_brush_core_finalize (GObject *object)
core->kernel_brushes[i][j] = NULL;
}
if (core->grr_brush)
if (core->main_brush)
{
g_signal_handlers_disconnect_by_func (core->grr_brush,
g_signal_handlers_disconnect_by_func (core->main_brush,
gimp_brush_core_invalidate_cache,
core);
g_object_unref (core->grr_brush);
core->grr_brush = NULL;
g_object_unref (core->main_brush);
core->main_brush = NULL;
}
if (core->brush_bound_segs)
......@@ -283,7 +289,7 @@ gimp_brush_core_pre_paint (GimpPaintCore *paint_core,
*/
if (paint_core->last_coords.x == paint_core->cur_coords.x &&
paint_core->last_coords.y == paint_core->cur_coords.y &&
! gimp_brush_want_null_motion (core->brush,
! gimp_brush_want_null_motion (core->main_brush,
&paint_core->last_coords,
&paint_core->cur_coords))
{
......@@ -292,7 +298,7 @@ gimp_brush_core_pre_paint (GimpPaintCore *paint_core,
if (GIMP_BRUSH_CORE_GET_CLASS (paint_core)->handles_changing_brush)
{
core->brush = gimp_brush_select_brush (core->brush,
core->brush = gimp_brush_select_brush (core->main_brush,
&paint_core->last_coords,
&paint_core->cur_coords);
}
......@@ -301,6 +307,21 @@ gimp_brush_core_pre_paint (GimpPaintCore *paint_core,
return TRUE;
}
static void
gimp_brush_core_post_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state,
guint32 time)
{
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
if (paint_state == MOTION_PAINT)
{
core->brush = core->main_brush;
}
}
static gboolean
gimp_brush_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
......@@ -313,15 +334,15 @@ gimp_brush_core_start (GimpPaintCore *paint_core,
* the maximum bounds of the active brush...
*/
if (core->grr_brush != gimp_context_get_brush (GIMP_CONTEXT (paint_options)))
if (core->main_brush != gimp_context_get_brush (GIMP_CONTEXT (paint_options)))
{
if (core->grr_brush)
if (core->main_brush)
{
g_signal_handlers_disconnect_by_func (core->grr_brush,
g_signal_handlers_disconnect_by_func (core->main_brush,
gimp_brush_core_invalidate_cache,
core);
g_object_unref (core->grr_brush);
core->grr_brush = NULL;
g_object_unref (core->main_brush);
core->main_brush = NULL;
}
if (core->brush_bound_segs)
......@@ -332,25 +353,25 @@ gimp_brush_core_start (GimpPaintCore *paint_core,
}
}
if (! core->grr_brush)
if (! core->main_brush)
{
core->grr_brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
core->main_brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
if (! core->grr_brush)
if (! core->main_brush)
{
g_message (_("No brushes available for use with this tool."));
return FALSE;
}
g_object_ref (core->grr_brush);
g_signal_connect (core->grr_brush, "invalidate_preview",
g_object_ref (core->main_brush);
g_signal_connect (core->main_brush, "invalidate_preview",
G_CALLBACK (gimp_brush_core_invalidate_cache),
core);
}
core->spacing = (gdouble) gimp_brush_get_spacing (core->grr_brush) / 100.0;
core->spacing = (gdouble) gimp_brush_get_spacing (core->main_brush) / 100.0;
core->brush = core->grr_brush;
core->brush = core->main_brush;
return TRUE;
}
......@@ -590,10 +611,8 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
for (n = 0; n < num_points; n++)
{
GimpBrush *current_brush;
gdouble t = t0 + n * dt;
gdouble p = (gdouble) n / num_points;
gdouble t = t0 + n * dt;
gdouble p = (gdouble) n / num_points;
paint_core->cur_coords.x = paint_core->last_coords.x + t * delta_vec.x;
paint_core->cur_coords.y = paint_core->last_coords.y + t * delta_vec.y;
......@@ -607,14 +626,8 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
paint_core->distance = initial + t * dist;
paint_core->pixel_dist = pixel_initial + t * pixel_dist;
/* save the current brush */
current_brush = core->brush;
gimp_paint_core_paint (paint_core, drawable, paint_options,
MOTION_PAINT, time);
/* restore the current brush pointer */
core->brush = current_brush;
}
paint_core->cur_coords.x = paint_core->last_coords.x + delta_vec.x;
......
......@@ -43,6 +43,7 @@ struct _GimpBrushCore
{
GimpPaintCore parent_instance;
GimpBrush *main_brush;
GimpBrush *brush;
gdouble spacing;
gdouble scale;
......@@ -70,7 +71,6 @@ struct _GimpBrushCore
gboolean cache_invalid;
/* don't use these... */
GimpBrush *grr_brush;
BoundSeg *brush_bound_segs;
gint n_brush_bound_segs;
};
......
......@@ -140,6 +140,9 @@ gimp_clone_init (GimpClone *clone)
clone->src_x = 0.0;
clone->src_y = 0.0;
clone->orig_src_x = 0;
clone->orig_src_y = 0;
clone->offset_x = 0;
clone->offset_y = 0;
clone->first_stroke = TRUE;
......@@ -158,9 +161,6 @@ gimp_clone_paint (GimpPaintCore *paint_core,
GimpPaintCoreState paint_state,
guint32 time)
{
static gint orig_src_x = 0;
static gint orig_src_y = 0;
GimpClone *clone = GIMP_CLONE (paint_core);
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
GimpContext *context = GIMP_CONTEXT (paint_options);
......@@ -189,8 +189,8 @@ gimp_clone_paint (GimpPaintCore *paint_core,
}
else if (options->align_mode == GIMP_CLONE_ALIGN_NO)
{
orig_src_x = clone->src_x;
orig_src_y = clone->src_y;
clone->orig_src_x = clone->src_x;
clone->orig_src_y = clone->src_y;
clone->first_stroke = TRUE;
}
......@@ -249,8 +249,8 @@ gimp_clone_paint (GimpPaintCore *paint_core,
if (options->align_mode == GIMP_CLONE_ALIGN_NO && ! clone->first_stroke)
{
clone->src_x = orig_src_x;
clone->src_y = orig_src_y;
clone->src_x = clone->orig_src_x;
clone->src_y = clone->orig_src_y;
}
break;
......
......@@ -44,6 +44,9 @@ struct _GimpClone
gint src_x;
gint src_y;
gint orig_src_x;
gint orig_src_y;
gint offset_x;
gint offset_y;
gboolean first_stroke;
......
......@@ -29,7 +29,6 @@
#include "vectors/gimpstroke.h"
#include "vectors/gimpvectors.h"
#include "gimpbrushcore.h"
#include "gimppaintcore.h"
#include "gimppaintcore-stroke.h"
#include "gimppaintoptions.h"
......@@ -50,12 +49,7 @@ gimp_paint_core_stroke (GimpPaintCore *core,
if (gimp_paint_core_start (core, drawable, paint_options, &strokes[0]))
{
GimpBrushCore *brush_core = NULL;
GimpBrush *current_brush = NULL;
gint i;
if (GIMP_IS_BRUSH_CORE (core))
brush_core = GIMP_BRUSH_CORE (core);
gint i;
core->start_coords = strokes[0];
core->last_coords = strokes[0];
......@@ -63,15 +57,9 @@ gimp_paint_core_stroke (GimpPaintCore *core,
gimp_paint_core_paint (core, drawable, paint_options,
INIT_PAINT, 0);
if (brush_core)
current_brush = brush_core->brush;
gimp_paint_core_paint (core, drawable, paint_options,
MOTION_PAINT, 0);
if (brush_core)
brush_core->brush = current_brush;
for (i = 1; i < n_strokes; i++)
{
core->cur_coords = strokes[i];
......@@ -147,12 +135,6 @@ gimp_paint_core_stroke_boundary (GimpPaintCore *core,
for (s = 0; s < n_stroke_segs; s++)
{
GimpBrushCore *brush_core = NULL;
GimpBrush *current_brush = NULL;
if (GIMP_IS_BRUSH_CORE (core))
brush_core = GIMP_BRUSH_CORE (core);
while (stroke_segs[seg].x1 != -1 ||
stroke_segs[seg].x2 != -1 ||
stroke_segs[seg].y1 != -1 ||
......@@ -189,15 +171,9 @@ gimp_paint_core_stroke_boundary (GimpPaintCore *core,
gimp_paint_core_paint (core, drawable, paint_options,
INIT_PAINT, 0);
if (brush_core)
current_brush = brush_core->brush;
gimp_paint_core_paint (core, drawable, paint_options,
MOTION_PAINT, 0);
if (brush_core)
brush_core->brush = current_brush;
for (i = 1; i < n_coords; i++)
{
core->cur_coords = coords[i];
......@@ -266,12 +242,7 @@ gimp_paint_core_stroke_vectors (GimpPaintCore *core,
if (coords && coords->len)
{
GimpBrushCore *brush_core = NULL;
GimpBrush *current_brush = NULL;
gint i;
if (GIMP_IS_BRUSH_CORE (core))
brush_core = GIMP_BRUSH_CORE (core);
gint i;
for (i = 0; i < coords->len; i++)
{
......@@ -291,15 +262,9 @@ gimp_paint_core_stroke_vectors (GimpPaintCore *core,
gimp_paint_core_paint (core, drawable, paint_options,
INIT_PAINT, 0);
if (brush_core)
current_brush = brush_core->brush;
gimp_paint_core_paint (core, drawable, paint_options,
MOTION_PAINT, 0);
if (brush_core)
brush_core->brush = current_brush;
for (i = 1; i < coords->len; i++)
{
core->cur_coords = g_array_index (coords, GimpCoords, i);
......
......@@ -67,6 +67,11 @@ static void gimp_paint_core_real_paint (GimpPaintCore *core,
GimpPaintOptions *options,
GimpPaintCoreState paint_state,
guint32 time);
static void gimp_paint_core_real_post_paint (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *options,
GimpPaintCoreState paint_state,
guint32 time);
static void gimp_paint_core_real_interpolate (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *options,
......@@ -130,6 +135,7 @@ gimp_paint_core_class_init (GimpPaintCoreClass *klass)
klass->start = gimp_paint_core_real_start;
klass->pre_paint = gimp_paint_core_real_pre_paint;
klass->paint = gimp_paint_core_real_paint;
klass->post_paint = gimp_paint_core_real_post_paint;
klass->interpolate = gimp_paint_core_real_interpolate;
klass->get_paint_area = gimp_paint_core_real_get_paint_area;
}
......@@ -193,6 +199,15 @@ gimp_paint_core_real_paint (GimpPaintCore *core,
{
}
static void
gimp_paint_core_real_post_paint (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state,
guint32 time)
{
}
static void
gimp_paint_core_real_interpolate (GimpPaintCore *core,
GimpDrawable *drawable,
......@@ -220,14 +235,18 @@ gimp_paint_core_paint (GimpPaintCore *core,
GimpPaintCoreState paint_state,
guint32 time)
{
GimpPaintCoreClass *core_class;
g_return_if_fail (GIMP_IS_PAINT_CORE (core));
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
if (GIMP_PAINT_CORE_GET_CLASS (core)->pre_paint (core, drawable,
paint_options,
paint_state, time))
core_class = GIMP_PAINT_CORE_GET_CLASS (core);
if (core_class->pre_paint (core, drawable,
paint_options,
paint_state, time))
{
if (paint_state == MOTION_PAINT)
{
......@@ -236,9 +255,13 @@ gimp_paint_core_paint (GimpPaintCore *core,
core->last_paint.y = core->cur_coords.y;
}
GIMP_PAINT_CORE_GET_CLASS (core)->paint (core, drawable,
paint_options,
paint_state, time);
core_class->paint (core, drawable,
paint_options,
paint_state, time);
core_class->post_paint (core, drawable,
paint_options,
paint_state, time);
}
}
......
......@@ -104,6 +104,11 @@ struct _GimpPaintCoreClass
GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state,
guint32 time);
void (* post_paint) (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpPaintCoreState paint_state,
guint32 time);
void (* interpolate) (GimpPaintCore *core,
GimpDrawable *drawable,
......
......@@ -140,6 +140,9 @@ gimp_clone_init (GimpClone *clone)
clone->src_x = 0.0;
clone->src_y = 0.0;
clone->orig_src_x = 0;
clone->orig_src_y = 0;
clone->offset_x = 0;
clone->offset_y = 0;
clone->first_stroke = TRUE;
......@@ -158,9 +161,6 @@ gimp_clone_paint (GimpPaintCore *paint_core,
GimpPaintCoreState paint_state,
guint32 time)
{
static gint orig_src_x = 0;
static gint orig_src_y = 0;
GimpClone *clone = GIMP_CLONE (paint_core);
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
GimpContext *context = GIMP_CONTEXT (paint_options);
......@@ -189,8 +189,8 @@ gimp_clone_paint (GimpPaintCore *paint_core,
}
else if (options->align_mode == GIMP_CLONE_ALIGN_NO)
{
orig_src_x = clone->src_x;
orig_src_y = clone->src_y;
clone->orig_src_x = clone->src_x;
clone->orig_src_y = clone->src_y;
clone->first_stroke = TRUE;
}
......@@ -249,8 +249,8 @@ gimp_clone_paint (GimpPaintCore *paint_core,
if (options->align_mode == GIMP_CLONE_ALIGN_NO && ! clone->first_stroke)
{
clone->src_x = orig_src_x;
clone->src_y = orig_src_y;
clone->src_x = clone->orig_src_x;
clone->src_y = clone->orig_src_y;
}
break;
......
......@@ -44,6 +44,9 @@ struct _GimpClone
gint src_x;
gint src_y;
gint orig_src_x;
gint orig_src_y;
gint offset_x;
gint offset_y;
gboolean first_stroke;
......
......@@ -128,18 +128,18 @@ gimp_paint_tool_get_type (void)
static const GTypeInfo tool_info =
{
sizeof (GimpPaintToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_paint_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPaintTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_paint_tool_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_paint_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPaintTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_paint_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL,
"GimpPaintTool",
"GimpPaintTool",
&tool_info, 0);
}
......@@ -359,7 +359,6 @@ gimp_paint_tool_button_press (GimpTool *tool,
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
GimpPaintOptions *paint_options;
GimpPaintCore *core;
GimpBrush *current_brush = NULL;
GimpDrawable *drawable;
GdkDisplay *gdk_display;
GimpCoords curr_coords;
......@@ -439,10 +438,6 @@ gimp_paint_tool_button_press (GimpTool *tool,
/* Let the specific painting function initialize itself */
gimp_paint_core_paint (core, drawable, paint_options, INIT_PAINT, time);
/* store the current brush pointer */
if (GIMP_IS_BRUSH_CORE (core))
current_brush = GIMP_BRUSH_CORE (core)->brush;
if (GIMP_PAINT_CORE_GET_CLASS (core)->traces_on_window)
gimp_paint_core_paint (core, drawable, paint_options, PRETRACE_PAINT, time);
......@@ -460,10 +455,6 @@ gimp_paint_tool_button_press (GimpTool *tool,
if (GIMP_PAINT_CORE_GET_CLASS (core)->traces_on_window)
gimp_paint_core_paint (core, drawable, paint_options, POSTTRACE_PAINT, time);
/* restore the current brush pointer */
if (GIMP_IS_BRUSH_CORE (core))
GIMP_BRUSH_CORE (core)->brush = current_brush;
}
static void
......@@ -798,7 +789,7 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
brush = gimp_context_get_brush (context);
mask = gimp_brush_get_mask (brush);
if (brush != brush_core->grr_brush && brush_core->brush_bound_segs)
if (brush != brush_core->main_brush && brush_core->brush_bound_segs)
{
g_free (brush_core->brush_bound_segs);
brush_core->brush_bound_segs = NULL;
......
......@@ -128,18 +128,18 @@ gimp_paint_tool_get_type (void)
static const GTypeInfo tool_info =
{
sizeof (GimpPaintToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_paint_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPaintTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_paint_tool_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_paint_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPaintTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_paint_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL,
"GimpPaintTool",
"GimpPaintTool",
&tool_info, 0);
}
......@@ -359,7 +359,6 @@ gimp_paint_tool_button_press (GimpTool *tool,
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
GimpPaintOptions *paint_options;
GimpPaintCore *core;
GimpBrush *current_brush = NULL;
GimpDrawable *drawable;
GdkDisplay *gdk_display;
GimpCoords curr_coords;
......@@ -439,10 +438,6 @@ gimp_paint_tool_button_press (GimpTool *tool,
/* Let the specific painting function initialize itself */
gimp_paint_core_paint (core, drawable, paint_options, INIT_PAINT, time);
/* store the current brush pointer */
if (GIMP_IS_BRUSH_CORE (core))
current_brush = GIMP_BRUSH_CORE (core)->brush;
if (GIMP_PAINT_CORE_GET_CLASS (core)->traces_on_window)
gimp_paint_core_paint (core, drawable, paint_options, PRETRACE_PAINT, time);
......@@ -460,10 +455,6 @@ gimp_paint_tool_button_press (GimpTool *tool,
if (GIMP_PAINT_CORE_GET_CLASS (core)->traces_on_window)
gimp_paint_core_paint (core, drawable, paint_options, POSTTRACE_PAINT, time);
/* restore the current brush pointer */
if (GIMP_IS_BRUSH_CORE (core))
GIMP_BRUSH_CORE (core)->brush = current_brush;
}
static void
......@@ -798,7 +789,7 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
brush = gimp_context_get_brush (context);
mask = gimp_brush_get_mask (brush);
if (brush != brush_core->grr_brush && brush_core->brush_bound_segs)
if (brush != brush_core->main_brush && brush_core->brush_bound_segs)
{
g_free (brush_core->brush_bound_segs);
brush_core->brush_bound_segs = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment