implement GimpPaintCore::start() and set paint_core->use_saved_proj to

2006-09-20  Michael Natterer  <mitch@gimp.org>

	* app/paint/gimpsourcecore.c: implement GimpPaintCore::start()
	and set paint_core->use_saved_proj to TRUE when we are using
	the destination drawable image's projection as source. Return
	FALSE from start() if there is no src_drawable set and removed
	checks for src_drawable != NULL further down in the code path.

	* app/tools/gimpperspectiveclonetool.c (button_press)
	* app/tools/gimpsourcetool.c (button_press): don't fiddle with
	paint_core->use_saved_proj here.

	* app/paint/gimpclone.c: implement GimpPaintCore::start() and
	return FALSE if we are in pattern mode and there is no pattern to
	clone from. Removed GimpPaintCore::paint() implementation because
	all it did was popping a message if there is no pattern. Removed
	check for pattern != NULL and cleaned up the file a bit.

	* app/paint/gimpperspectiveclone.c (paint): removed message about
	no pattern to clone from.
This commit is contained in:
Michael Natterer 2006-09-19 23:14:50 +00:00 committed by Michael Natterer
parent ca6afdf530
commit 7b0531aa91
6 changed files with 148 additions and 118 deletions

View file

@ -1,3 +1,24 @@
2006-09-20 Michael Natterer <mitch@gimp.org>
* app/paint/gimpsourcecore.c: implement GimpPaintCore::start()
and set paint_core->use_saved_proj to TRUE when we are using
the destination drawable image's projection as source. Return
FALSE from start() if there is no src_drawable set and removed
checks for src_drawable != NULL further down in the code path.
* app/tools/gimpperspectiveclonetool.c (button_press)
* app/tools/gimpsourcetool.c (button_press): don't fiddle with
paint_core->use_saved_proj here.
* app/paint/gimpclone.c: implement GimpPaintCore::start() and
return FALSE if we are in pattern mode and there is no pattern to
clone from. Removed GimpPaintCore::paint() implementation because
all it did was popping a message if there is no pattern. Removed
check for pattern != NULL and cleaned up the file a bit.
* app/paint/gimpperspectiveclone.c (paint): removed message about
no pattern to clone from.
2006-09-20 Michael Natterer <mitch@gimp.org>
* app/core/gimpgradient.[ch]: added gimp_gradient_flatten() which

View file

@ -45,43 +45,42 @@
#include "gimp-intl.h"
static void gimp_clone_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpPaintState paint_state,
guint32 time);
static gboolean gimp_clone_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
static void gimp_clone_motion (GimpSourceCore *source_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
gdouble opacity,
GimpPickable *src_pickable,
PixelRegion *srcPR,
gint src_offset_x,
gint src_offset_y,
TempBuf *paint_area,
gint paint_area_offset_x,
gint paint_area_offset_y,
gint paint_area_width,
gint paint_area_height);
static void gimp_clone_motion (GimpSourceCore *source_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
gdouble opacity,
GimpPickable *src_pickable,
PixelRegion *srcPR,
gint src_offset_x,
gint src_offset_y,
TempBuf *paint_area,
gint paint_area_offset_x,
gint paint_area_offset_y,
gint paint_area_width,
gint paint_area_height);
static void gimp_clone_line_image (GimpImage *dest,
GimpImage *src,
GimpDrawable *d_drawable,
GimpImageType src_type,
guchar *s,
guchar *d,
gint src_bytes,
gint dest_bytes,
gint width);
static void gimp_clone_line_pattern (GimpImage *dest,
GimpDrawable *drawable,
GimpPattern *pattern,
guchar *d,
gint x,
gint y,
gint bytes,
gint width);
static void gimp_clone_line_image (GimpImage *dest_image,
GimpDrawable *dest_drawable,
GimpImage *src_image,
GimpImageType src_type,
guchar *s,
guchar *d,
gint src_bytes,
gint dest_bytes,
gint width);
static void gimp_clone_line_pattern (GimpImage *dest_image,
GimpDrawable *dest_drawable,
GimpPattern *pattern,
guchar *d,
gint x,
gint y,
gint dest_bytes,
gint width);
G_DEFINE_TYPE (GimpClone, gimp_clone, GIMP_TYPE_SOURCE_CORE)
@ -107,7 +106,7 @@ gimp_clone_class_init (GimpCloneClass *klass)
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
GimpSourceCoreClass *source_core_class = GIMP_SOURCE_CORE_CLASS (klass);
paint_core_class->paint = gimp_clone_paint;
paint_core_class->start = gimp_clone_start;
source_core_class->motion = gimp_clone_motion;
}
@ -117,30 +116,30 @@ gimp_clone_init (GimpClone *clone)
{
}
static void
gimp_clone_paint (GimpPaintCore *paint_core,
static gboolean
gimp_clone_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpPaintState paint_state,
guint32 time)
GimpCoords *coords)
{
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
switch (paint_state)
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
paint_options, coords))
{
case GIMP_PAINT_STATE_INIT:
if (options->clone_type == GIMP_PATTERN_CLONE)
if (! gimp_context_get_pattern (GIMP_CONTEXT (options)))
g_message (_("No patterns available for this operation."));
break;
default:
break;
return FALSE;
}
GIMP_PAINT_CORE_CLASS (parent_class)->paint (paint_core, drawable,
paint_options, paint_state,
time);
if (options->clone_type == GIMP_PATTERN_CLONE)
{
if (! gimp_context_get_pattern (GIMP_CONTEXT (options)))
{
g_message (_("No patterns available for this operation."));
return FALSE;
}
}
return TRUE;
}
static void
@ -158,17 +157,17 @@ gimp_clone_motion (GimpSourceCore *source_core,
gint paint_area_width,
gint paint_area_height)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (source_core);
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
GimpSourceOptions *source_options = GIMP_SOURCE_OPTIONS (paint_options);
GimpContext *context = GIMP_CONTEXT (paint_options);
GimpImage *src_image = NULL;
GimpImageType src_type = 0;
GimpImage *image;
gpointer pr = NULL;
gint y;
PixelRegion destPR;
GimpPattern *pattern = NULL;
GimpPaintCore *paint_core = GIMP_PAINT_CORE (source_core);
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
GimpSourceOptions *source_options = GIMP_SOURCE_OPTIONS (paint_options);
GimpContext *context = GIMP_CONTEXT (paint_options);
GimpImage *src_image = NULL;
GimpImageType src_type = 0;
GimpImage *image;
gpointer pr = NULL;
gint y;
PixelRegion destPR;
GimpPattern *pattern = NULL;
image = gimp_item_get_image (GIMP_ITEM (drawable));
@ -191,8 +190,6 @@ gimp_clone_motion (GimpSourceCore *source_core,
case GIMP_PATTERN_CLONE:
pattern = gimp_context_get_pattern (context);
if (! pattern)
return;
pixel_region_init_temp_buf (&destPR, paint_area,
0, 0,
@ -212,8 +209,8 @@ gimp_clone_motion (GimpSourceCore *source_core,
switch (options->clone_type)
{
case GIMP_IMAGE_CLONE:
gimp_clone_line_image (image, src_image,
drawable, src_type,
gimp_clone_line_image (image, drawable,
src_image, src_type,
s, d,
srcPR->bytes, destPR.bytes, destPR.w);
s += srcPR->rowstride;
@ -253,9 +250,9 @@ gimp_clone_motion (GimpSourceCore *source_core,
}
static void
gimp_clone_line_image (GimpImage *dest,
GimpImage *src,
GimpDrawable *d_drawable,
gimp_clone_line_image (GimpImage *dest_image,
GimpDrawable *dest_drawable,
GimpImage *src_image,
GimpImageType src_type,
guchar *s,
guchar *d,
@ -270,8 +267,9 @@ gimp_clone_line_image (GimpImage *dest,
while (width--)
{
gimp_image_get_color (src, src_type, s, rgba);
gimp_image_transform_color (dest, d_drawable, d, GIMP_RGB, rgba);
gimp_image_get_color (src_image, src_type, s, rgba);
gimp_image_transform_color (dest_image, dest_drawable, d,
GIMP_RGB, rgba);
d[alpha] = rgba[ALPHA_PIX];
@ -281,13 +279,13 @@ gimp_clone_line_image (GimpImage *dest,
}
static void
gimp_clone_line_pattern (GimpImage *dest,
GimpDrawable *drawable,
gimp_clone_line_pattern (GimpImage *dest_image,
GimpDrawable *dest_drawable,
GimpPattern *pattern,
guchar *d,
gint x,
gint y,
gint bytes,
gint dest_bytes,
gint width)
{
guchar *pat, *p;
@ -311,19 +309,20 @@ gimp_clone_line_pattern (GimpImage *dest,
color_type = (pat_bytes == 3 ||
pat_bytes == 4) ? GIMP_RGB : GIMP_GRAY;
alpha = bytes - 1;
alpha = dest_bytes - 1;
for (i = 0; i < width; i++)
{
p = pat + ((i + x) % pattern->mask->width) * pat_bytes;
gimp_image_transform_color (dest, drawable, d, color_type, p);
gimp_image_transform_color (dest_image, dest_drawable, d,
color_type, p);
if (pat_bytes == 2 || pat_bytes == 4)
d[alpha] = p[pat_bytes - 1];
else
d[alpha] = OPAQUE_OPACITY;
d += bytes;
d += dest_bytes;
}
}

View file

@ -176,10 +176,6 @@ gimp_perspective_clone_paint (GimpPaintCore *paint_core,
source_core->first_stroke = TRUE;
}
if (clone_options->clone_type == GIMP_PATTERN_CLONE)
if (! gimp_context_get_pattern (context))
g_message (_("No patterns available for this operation."));
break;
case GIMP_PAINT_STATE_MOTION:

View file

@ -48,23 +48,27 @@ enum
};
static void gimp_source_core_set_property (GObject *object,
static void gimp_source_core_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_source_core_get_property (GObject *object,
static void gimp_source_core_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_source_core_paint (GimpPaintCore *paint_core,
static gboolean gimp_source_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
static void gimp_source_core_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpPaintState paint_state,
guint32 time);
#if 0
static void gimp_source_core_motion (GimpSourceCore *source_core,
static void gimp_source_core_motion (GimpSourceCore *source_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options);
#endif
@ -82,12 +86,14 @@ static gboolean gimp_source_core_real_get_source (GimpSourceCore *source_core,
gint *paint_area_height,
PixelRegion *srcPR);
static void gimp_source_core_set_src_drawable (GimpSourceCore *source_core,
static void gimp_source_core_set_src_drawable (GimpSourceCore *source_core,
GimpDrawable *drawable);
G_DEFINE_TYPE (GimpSourceCore, gimp_source_core, GIMP_TYPE_BRUSH_CORE)
#define parent_class gimp_source_core_parent_class
static void
gimp_source_core_class_init (GimpSourceCoreClass *klass)
@ -99,6 +105,7 @@ gimp_source_core_class_init (GimpSourceCoreClass *klass)
object_class->set_property = gimp_source_core_set_property;
object_class->get_property = gimp_source_core_get_property;
paint_core_class->start = gimp_source_core_start;
paint_core_class->paint = gimp_source_core_paint;
brush_core_class->handles_changing_brush = TRUE;
@ -193,6 +200,39 @@ gimp_source_core_get_property (GObject *object,
}
}
static gboolean
gimp_source_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords)
{
GimpSourceCore *source_core = GIMP_SOURCE_CORE (paint_core);
GimpSourceOptions *options = GIMP_SOURCE_OPTIONS (paint_options);
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
paint_options, coords))
{
return FALSE;
}
paint_core->use_saved_proj = FALSE;
if (! source_core->set_source && options->use_source)
{
if (! source_core->src_drawable)
return FALSE;
if (options->sample_merged &&
gimp_item_get_image (GIMP_ITEM (source_core->src_drawable)) ==
gimp_item_get_image (GIMP_ITEM (drawable)))
{
paint_core->use_saved_proj = TRUE;
}
}
return TRUE;
}
static void
gimp_source_core_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable,
@ -315,17 +355,12 @@ gimp_source_core_motion (GimpSourceCore *source_core,
if (options->use_source)
{
GimpImage *src_image;
if (! source_core->src_drawable)
return;
src_pickable = GIMP_PICKABLE (source_core->src_drawable);
src_image = gimp_pickable_get_image (src_pickable);
if (options->sample_merged)
{
gint off_x, off_y;
GimpImage *src_image = gimp_pickable_get_image (src_pickable);
gint off_x, off_y;
src_pickable = GIMP_PICKABLE (src_image->projection);

View file

@ -334,8 +334,6 @@ gimp_perspective_clone_tool_button_press (GimpTool *tool,
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
paint_tool->core->use_saved_proj = FALSE;
if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
{
source_core->set_source = TRUE;
@ -345,14 +343,6 @@ gimp_perspective_clone_tool_button_press (GimpTool *tool,
else
{
source_core->set_source = FALSE;
if (GIMP_CLONE_OPTIONS (options)->clone_type == GIMP_IMAGE_CLONE &&
GIMP_SOURCE_OPTIONS (options)->sample_merged &&
clone_tool->src_display &&
clone_tool->src_display->image == display->image)
{
paint_tool->core->use_saved_proj = TRUE;
}
}
GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,

View file

@ -172,15 +172,12 @@ gimp_source_tool_button_press (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display)
{
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
GimpSourceCore *source = GIMP_SOURCE_CORE (paint_tool->core);
GimpSourceOptions *options = GIMP_SOURCE_TOOL_GET_OPTIONS (tool);
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
GimpSourceCore *source = GIMP_SOURCE_CORE (paint_tool->core);
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
paint_tool->core->use_saved_proj = FALSE;
if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
{
source->set_source = TRUE;
@ -190,14 +187,6 @@ gimp_source_tool_button_press (GimpTool *tool,
else
{
source->set_source = FALSE;
if (options->use_source &&
options->sample_merged &&
source_tool->src_display &&
source_tool->src_display->image && display->image)
{
paint_tool->core->use_saved_proj = TRUE;
}
}
GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,