From f81e2f3d688cfd41e279e779278ca95658dcfd41 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 13 Mar 2004 15:07:33 +0000 Subject: [PATCH] implement GimpDrawable functions that affect the tiles and mark the text 2004-03-13 Sven Neumann * app/text/gimptextlayer.[ch]: implement GimpDrawable functions that affect the tiles and mark the text layer as modified. Added new function gimp_drawable_is_text_layer() that checks whether a drawable is an unmodified text layer. * app/display/gimpdisplayshell-dnd.c (gimp_display_shell_bucket_fill): use gimp_drawable_is_text_layer() and only set the text color if the text layer is unmodified. Fixes bug #136623. --- ChangeLog | 11 +++ app/display/gimpdisplayshell-dnd.c | 11 ++- app/text/gimptextlayer.c | 135 +++++++++++++++++++++++------ app/text/gimptextlayer.h | 19 ++-- 4 files changed, 136 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index deb1cb1688..dd5df5d3d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-03-13 Sven Neumann + + * app/text/gimptextlayer.[ch]: implement GimpDrawable functions + that affect the tiles and mark the text layer as modified. Added + new function gimp_drawable_is_text_layer() that checks whether a + drawable is an unmodified text layer. + + * app/display/gimpdisplayshell-dnd.c (gimp_display_shell_bucket_fill): + use gimp_drawable_is_text_layer() and only set the text color if the + text layer is unmodified. Fixes bug #136623. + 2004-03-13 Sven Neumann * app/core/gimpdrawable.[ch]: added new virtual function diff --git a/app/display/gimpdisplayshell-dnd.c b/app/display/gimpdisplayshell-dnd.c index 2649bfbf78..b68ef71b41 100644 --- a/app/display/gimpdisplayshell-dnd.c +++ b/app/display/gimpdisplayshell-dnd.c @@ -177,7 +177,6 @@ gimp_display_shell_bucket_fill (GimpDisplayShell *shell, { GimpImage *gimage = shell->gdisp->gimage; GimpDrawable *drawable; - GimpText *text; if (gimage->gimp->busy) return; @@ -188,12 +187,12 @@ gimp_display_shell_bucket_fill (GimpDisplayShell *shell, return; /* FIXME: there should be a virtual method for this that the - GimpTextLayer can override. */ - - if (color && - GIMP_IS_TEXT_LAYER (drawable) && - (text = gimp_text_layer_get_text (GIMP_TEXT_LAYER (drawable))) != NULL) + * GimpTextLayer can override. + */ + if (color && gimp_drawable_is_text_layer (drawable)) { + GimpText *text = gimp_text_layer_get_text (GIMP_TEXT_LAYER (drawable)); + g_object_set (text, "color", color, NULL); gimp_text_layer_flush (GIMP_TEXT_LAYER (drawable)); } diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c index 36d96dbb10..f2684b9f46 100644 --- a/app/text/gimptextlayer.c +++ b/app/text/gimptextlayer.c @@ -54,26 +54,49 @@ #include "gimp-intl.h" -static void gimp_text_layer_class_init (GimpTextLayerClass *klass); -static void gimp_text_layer_init (GimpTextLayer *layer); -static void gimp_text_layer_dispose (GObject *object); -static void gimp_text_layer_finalize (GObject *object); +static void gimp_text_layer_class_init (GimpTextLayerClass *klass); +static void gimp_text_layer_init (GimpTextLayer *layer); +static void gimp_text_layer_dispose (GObject *object); +static void gimp_text_layer_finalize (GObject *object); -static gint64 gimp_text_layer_get_memsize (GimpObject *object, - gint64 *gui_size); +static gint64 gimp_text_layer_get_memsize (GimpObject *object, + gint64 *gui_size); -static GimpItem * gimp_text_layer_duplicate (GimpItem *item, - GType new_type, - gboolean add_alpha); -static gboolean gimp_text_layer_rename (GimpItem *item, - const gchar *new_name, - const gchar *undo_desc); +static GimpItem * gimp_text_layer_duplicate (GimpItem *item, + GType new_type, + gboolean add_alpha); +static gboolean gimp_text_layer_rename (GimpItem *item, + const gchar *new_name, + const gchar *undo_desc); -static void gimp_text_layer_text_notify (GimpTextLayer *layer); -static gboolean gimp_text_layer_idle_render (GimpTextLayer *layer); -static gboolean gimp_text_layer_render_now (GimpTextLayer *layer); -static void gimp_text_layer_render_layout (GimpTextLayer *layer, - GimpTextLayout *layout); +static void gimp_text_layer_apply_region (GimpDrawable *drawable, + PixelRegion *src2PR, + gboolean push_undo, + const gchar *undo_desc, + gdouble opacity, + GimpLayerModeEffects mode, + TileManager *src1_tiles, + gint x, + gint y); +static void gimp_text_layer_replace_region (GimpDrawable *drawable, + PixelRegion *src2PR, + gboolean push_undo, + const gchar *undo_desc, + gdouble opacity, + PixelRegion *maskPR, + gint x, + gint y); +static void gimp_text_layer_set_tiles (GimpDrawable *drawable, + gboolean push_undo, + const gchar *undo_desc, + TileManager *tiles, + GimpImageType type); + +static void gimp_text_layer_text_notify (GimpTextLayer *layer); +static gboolean gimp_text_layer_idle_render (GimpTextLayer *layer); +static gboolean gimp_text_layer_render_now (GimpTextLayer *layer); +static void gimp_text_layer_render_layout (GimpTextLayer *layer, + GimpTextLayout *layout); static GimpLayerClass *parent_class = NULL; @@ -110,15 +133,11 @@ gimp_text_layer_get_type (void) static void gimp_text_layer_class_init (GimpTextLayerClass *klass) { - GObjectClass *object_class; - GimpObjectClass *gimp_object_class; - GimpViewableClass *viewable_class; - GimpItemClass *item_class; - - object_class = G_OBJECT_CLASS (klass); - gimp_object_class = GIMP_OBJECT_CLASS (klass); - viewable_class = GIMP_VIEWABLE_CLASS (klass); - item_class = GIMP_ITEM_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass); + GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass); + GimpItemClass *item_class = GIMP_ITEM_CLASS (klass); + GimpDrawableClass *drawable_class = GIMP_DRAWABLE_CLASS (klass); parent_class = g_type_class_peek_parent (klass); @@ -139,6 +158,10 @@ gimp_text_layer_class_init (GimpTextLayerClass *klass) item_class->rotate = gimp_text_layer_rotate; item_class->transform = gimp_text_layer_transform; #endif + + drawable_class->apply_region = gimp_text_layer_apply_region; + drawable_class->replace_region = gimp_text_layer_replace_region; + drawable_class->set_tiles = gimp_text_layer_set_tiles; } static void @@ -148,6 +171,7 @@ gimp_text_layer_init (GimpTextLayer *layer) layer->text_parasite = NULL; layer->idle_render_id = 0; layer->auto_rename = TRUE; + layer->modified = FALSE; } static void @@ -245,6 +269,55 @@ gimp_text_layer_rename (GimpItem *item, return FALSE; } +static void +gimp_text_layer_apply_region (GimpDrawable *drawable, + PixelRegion *src2PR, + gboolean push_undo, + const gchar *undo_desc, + gdouble opacity, + GimpLayerModeEffects mode, + TileManager *src1_tiles, + gint x, + gint y) +{ + GIMP_DRAWABLE_CLASS (parent_class)->apply_region (drawable, src2PR, + push_undo, undo_desc, + opacity, mode, + src1_tiles, x, y); + GIMP_TEXT_LAYER (drawable)->modified = TRUE; +} + +static void +gimp_text_layer_replace_region (GimpDrawable *drawable, + PixelRegion *src2PR, + gboolean push_undo, + const gchar *undo_desc, + gdouble opacity, + PixelRegion *maskPR, + gint x, + gint y) +{ + GIMP_DRAWABLE_CLASS (parent_class)->replace_region (drawable, src2PR, + push_undo, undo_desc, + opacity, + maskPR, x, y); + GIMP_TEXT_LAYER (drawable)->modified = TRUE; +} + +static void +gimp_text_layer_set_tiles (GimpDrawable *drawable, + gboolean push_undo, + const gchar *undo_desc, + TileManager *tiles, + GimpImageType type) +{ + GIMP_DRAWABLE_CLASS (parent_class)->set_tiles (drawable, + push_undo, undo_desc, + tiles, type); + GIMP_TEXT_LAYER (drawable)->modified = TRUE; +} + + /** * gimp_text_layer_new: * @image: the #GimpImage the layer should belong to @@ -327,6 +400,16 @@ gimp_text_layer_get_text (GimpTextLayer *layer) return layer->text; } + +gboolean +gimp_drawable_is_text_layer (GimpDrawable *drawable) +{ + return (GIMP_IS_TEXT_LAYER (drawable) && + GIMP_TEXT_LAYER (drawable)->text && + GIMP_TEXT_LAYER (drawable)->modified == FALSE); +} + + /** * gimp_text_layer_discard: * @layer: a #GimpTextLayer diff --git a/app/text/gimptextlayer.h b/app/text/gimptextlayer.h index 49ac54dbdf..1959b7e0a4 100644 --- a/app/text/gimptextlayer.h +++ b/app/text/gimptextlayer.h @@ -47,6 +47,7 @@ struct _GimpTextLayer */ guint idle_render_id; gboolean auto_rename; + gboolean modified; }; struct _GimpTextLayerClass @@ -55,15 +56,17 @@ struct _GimpTextLayerClass }; -GType gimp_text_layer_get_type (void) G_GNUC_CONST; +GType gimp_text_layer_get_type (void) G_GNUC_CONST; -GimpLayer * gimp_text_layer_new (GimpImage *image, - GimpText *text); -GimpText * gimp_text_layer_get_text (GimpTextLayer *layer); -void gimp_text_layer_set_text (GimpTextLayer *layer, - GimpText *text); -void gimp_text_layer_discard (GimpTextLayer *layer); -void gimp_text_layer_flush (GimpTextLayer *layer); +GimpLayer * gimp_text_layer_new (GimpImage *image, + GimpText *text); +GimpText * gimp_text_layer_get_text (GimpTextLayer *layer); +void gimp_text_layer_set_text (GimpTextLayer *layer, + GimpText *text); +void gimp_text_layer_discard (GimpTextLayer *layer); +void gimp_text_layer_flush (GimpTextLayer *layer); + +gboolean gimp_drawable_is_text_layer (GimpDrawable *drawable); #endif /* __GIMP_TEXT_LAYER_H__ */