add "update" signal with the same signature as GimpImage::update().

2008-11-02  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpdrawablestack.[ch]: add "update" signal with the
	same signature as GimpImage::update(). Install handlers for the
	drawables' "update" and "visibility-changed" signals and emit
	"update" accordingly, item offsets taken into account. Also emit
	"update" when drawables are added, removed and reordered.

	* app/core/gimpimage.[ch]: remove handlers and tons of code that
	makes sure the image emits "update" on any of the above handled
	events and simply connect the layer and channel stacks' "update"
	signal to gimp_image_update().


svn path=/trunk/; revision=27523
This commit is contained in:
Michael Natterer
2008-11-02 19:53:51 +00:00
committed by Michael Natterer
parent 50ac74be1e
commit c14c84ba63
5 changed files with 224 additions and 218 deletions

View File

@ -1,3 +1,16 @@
2008-11-02 Michael Natterer <mitch@gimp.org>
* app/core/gimpdrawablestack.[ch]: add "update" signal with the
same signature as GimpImage::update(). Install handlers for the
drawables' "update" and "visibility-changed" signals and emit
"update" accordingly, item offsets taken into account. Also emit
"update" when drawables are added, removed and reordered.
* app/core/gimpimage.[ch]: remove handlers and tons of code that
makes sure the image emits "update" on any of the above handled
events and simply connect the layer and channel stacks' "update"
signal to gimp_image_update().
2008-11-02 Michael Natterer <mitch@gimp.org> 2008-11-02 Michael Natterer <mitch@gimp.org>
* app/core/gimplayer.[ch]: remove the mask_node and simply set * app/core/gimplayer.[ch]: remove the mask_node and simply set

View File

@ -27,6 +27,14 @@
#include "gimpdrawable.h" #include "gimpdrawable.h"
#include "gimpdrawablestack.h" #include "gimpdrawablestack.h"
#include "gimpmarshal.h"
enum
{
UPDATE,
LAST_SIGNAL
};
#ifdef __GNUC__ #ifdef __GNUC__
@ -44,26 +52,45 @@ GeglNode * gegl_node_remove_child (GeglNode *self,
/* local function prototypes */ /* local function prototypes */
static void gimp_drawable_stack_finalize (GObject *object); static GObject * gimp_drawable_stack_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_drawable_stack_finalize (GObject *object);
static void gimp_drawable_stack_add (GimpContainer *container, static void gimp_drawable_stack_add (GimpContainer *container,
GimpObject *object); GimpObject *object);
static void gimp_drawable_stack_remove (GimpContainer *container, static void gimp_drawable_stack_remove (GimpContainer *container,
GimpObject *object); GimpObject *object);
static void gimp_drawable_stack_reorder (GimpContainer *container, static void gimp_drawable_stack_reorder (GimpContainer *container,
GimpObject *object, GimpObject *object,
gint new_index); gint new_index);
static void gimp_drawable_stack_add_node (GimpDrawableStack *stack, static void gimp_drawable_stack_add_node (GimpDrawableStack *stack,
GimpDrawable *drawable); GimpDrawable *drawable);
static void gimp_drawable_stack_remove_node (GimpDrawableStack *stack, static void gimp_drawable_stack_remove_node (GimpDrawableStack *stack,
GimpDrawable *drawable); GimpDrawable *drawable);
static void gimp_drawable_stack_update (GimpDrawableStack *stack,
gint x,
gint y,
gint width,
gint height);
static void gimp_drawable_stack_drawable_update (GimpItem *item,
gint x,
gint y,
gint width,
gint height,
GimpDrawableStack *stack);
static void gimp_drawable_stack_drawable_visible (GimpItem *item,
GimpDrawableStack *stack);
G_DEFINE_TYPE (GimpDrawableStack, gimp_drawable_stack, GIMP_TYPE_LIST) G_DEFINE_TYPE (GimpDrawableStack, gimp_drawable_stack, GIMP_TYPE_LIST)
#define parent_class gimp_drawable_stack_parent_class #define parent_class gimp_drawable_stack_parent_class
static guint stack_signals[LAST_SIGNAL] = { 0 };
static void static void
gimp_drawable_stack_class_init (GimpDrawableStackClass *klass) gimp_drawable_stack_class_init (GimpDrawableStackClass *klass)
@ -71,18 +98,56 @@ gimp_drawable_stack_class_init (GimpDrawableStackClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass); GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass);
object_class->finalize = gimp_drawable_stack_finalize; stack_signals[UPDATE] =
g_signal_new ("update",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpDrawableStackClass, update),
NULL, NULL,
gimp_marshal_VOID__INT_INT_INT_INT,
G_TYPE_NONE, 4,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT);
container_class->add = gimp_drawable_stack_add; object_class->constructor = gimp_drawable_stack_constructor;
container_class->remove = gimp_drawable_stack_remove; object_class->finalize = gimp_drawable_stack_finalize;
container_class->reorder = gimp_drawable_stack_reorder;
container_class->add = gimp_drawable_stack_add;
container_class->remove = gimp_drawable_stack_remove;
container_class->reorder = gimp_drawable_stack_reorder;
} }
static void static void
gimp_drawable_stack_init (GimpDrawableStack *list) gimp_drawable_stack_init (GimpDrawableStack *stack)
{ {
} }
static GObject *
gimp_drawable_stack_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpContainer *container;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
container = GIMP_CONTAINER (object);
g_assert (g_type_is_a (container->children_type, GIMP_TYPE_DRAWABLE));
gimp_container_add_handler (container, "update",
G_CALLBACK (gimp_drawable_stack_drawable_update),
container);
gimp_container_add_handler (container, "visibility-changed",
G_CALLBACK (gimp_drawable_stack_drawable_visible),
container);
return object;
}
static void static void
gimp_drawable_stack_finalize (GObject *object) gimp_drawable_stack_finalize (GObject *object)
{ {
@ -107,6 +172,9 @@ gimp_drawable_stack_add (GimpContainer *container,
if (stack->graph) if (stack->graph)
gimp_drawable_stack_add_node (stack, GIMP_DRAWABLE (object)); gimp_drawable_stack_add_node (stack, GIMP_DRAWABLE (object));
if (gimp_item_get_visible (GIMP_ITEM (object)))
gimp_drawable_stack_drawable_visible (GIMP_ITEM (object), stack);
} }
static void static void
@ -124,6 +192,9 @@ gimp_drawable_stack_remove (GimpContainer *container,
} }
GIMP_CONTAINER_CLASS (parent_class)->remove (container, object); GIMP_CONTAINER_CLASS (parent_class)->remove (container, object);
if (gimp_item_get_visible (GIMP_ITEM (object)))
gimp_drawable_stack_drawable_visible (GIMP_ITEM (object), stack);
} }
static void static void
@ -140,6 +211,9 @@ gimp_drawable_stack_reorder (GimpContainer *container,
if (stack->graph) if (stack->graph)
gimp_drawable_stack_add_node (stack, GIMP_DRAWABLE (object)); gimp_drawable_stack_add_node (stack, GIMP_DRAWABLE (object));
if (gimp_item_get_visible (GIMP_ITEM (object)))
gimp_drawable_stack_drawable_visible (GIMP_ITEM (object), stack);
} }
@ -297,3 +371,50 @@ gimp_drawable_stack_remove_node (GimpDrawableStack *stack,
gegl_node_disconnect (node_above, "input"); gegl_node_disconnect (node_above, "input");
} }
} }
static void
gimp_drawable_stack_update (GimpDrawableStack *stack,
gint x,
gint y,
gint width,
gint height)
{
g_signal_emit (stack, stack_signals[UPDATE], 0,
x, y, width, height);
}
static void
gimp_drawable_stack_drawable_update (GimpItem *item,
gint x,
gint y,
gint width,
gint height,
GimpDrawableStack *stack)
{
if (gimp_item_get_visible (item))
{
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_drawable_stack_update (stack,
x + offset_x, y + offset_y,
width, height);
}
}
static void
gimp_drawable_stack_drawable_visible (GimpItem *item,
GimpDrawableStack *stack)
{
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_drawable_stack_update (stack,
offset_x, offset_y,
gimp_item_width (item),
gimp_item_height (item));
}

View File

@ -44,6 +44,12 @@ struct _GimpDrawableStack
struct _GimpDrawableStackClass struct _GimpDrawableStackClass
{ {
GimpListClass parent_class; GimpListClass parent_class;
void (* update) (GimpDrawableStack *stack,
gint x,
gint y,
gint width,
gint height);
}; };

View File

@ -131,74 +131,60 @@ GeglNode * gegl_node_add_child (GeglNode *self,
static void gimp_color_managed_iface_init (GimpColorManagedInterface *iface); static void gimp_color_managed_iface_init (GimpColorManagedInterface *iface);
static GObject *gimp_image_constructor (GType type, static GObject *gimp_image_constructor (GType type,
guint n_params, guint n_params,
GObjectConstructParam *params); GObjectConstructParam *params);
static void gimp_image_set_property (GObject *object, static void gimp_image_set_property (GObject *object,
guint property_id, guint property_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_image_get_property (GObject *object, static void gimp_image_get_property (GObject *object,
guint property_id, guint property_id,
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_image_dispose (GObject *object); static void gimp_image_dispose (GObject *object);
static void gimp_image_finalize (GObject *object); static void gimp_image_finalize (GObject *object);
static void gimp_image_name_changed (GimpObject *object); static void gimp_image_name_changed (GimpObject *object);
static gint64 gimp_image_get_memsize (GimpObject *object, static gint64 gimp_image_get_memsize (GimpObject *object,
gint64 *gui_size); gint64 *gui_size);
static gboolean gimp_image_get_size (GimpViewable *viewable, static gboolean gimp_image_get_size (GimpViewable *viewable,
gint *width, gint *width,
gint *height); gint *height);
static void gimp_image_invalidate_preview (GimpViewable *viewable); static void gimp_image_invalidate_preview (GimpViewable *viewable);
static void gimp_image_size_changed (GimpViewable *viewable); static void gimp_image_size_changed (GimpViewable *viewable);
static gchar * gimp_image_get_description (GimpViewable *viewable, static gchar * gimp_image_get_description (GimpViewable *viewable,
gchar **tooltip); gchar **tooltip);
static void gimp_image_real_size_changed_detailed static void gimp_image_real_size_changed_detailed
(GimpImage *image, (GimpImage *image,
gint previous_origin_x, gint previous_origin_x,
gint previous_origin_y, gint previous_origin_y,
gint previous_width, gint previous_width,
gint previous_height); gint previous_height);
static void gimp_image_real_colormap_changed (GimpImage *image, static void gimp_image_real_colormap_changed (GimpImage *image,
gint color_index); gint color_index);
static void gimp_image_real_flush (GimpImage *image, static void gimp_image_real_flush (GimpImage *image,
gboolean invalidate_preview); gboolean invalidate_preview);
static void gimp_image_mask_update (GimpDrawable *drawable, static void gimp_image_mask_update (GimpDrawable *drawable,
gint x, gint x,
gint y, gint y,
gint width, gint width,
gint height, gint height,
GimpImage *image); GimpImage *image);
static void gimp_image_drawable_update (GimpDrawable *drawable, static void gimp_image_layer_alpha_changed (GimpDrawable *drawable,
gint x, GimpImage *image);
gint y, static void gimp_image_channel_add (GimpContainer *container,
gint width, GimpChannel *channel,
gint height, GimpImage *image);
GimpImage *image); static void gimp_image_channel_remove (GimpContainer *container,
static void gimp_image_drawable_visibility (GimpItem *item, GimpChannel *channel,
GimpImage *image); GimpImage *image);
static void gimp_image_layer_alpha_changed (GimpDrawable *drawable, static void gimp_image_channel_name_changed (GimpChannel *channel,
GimpImage *image); GimpImage *image);
static void gimp_image_layer_add (GimpContainer *container, static void gimp_image_channel_color_changed (GimpChannel *channel,
GimpLayer *layer, GimpImage *image);
GimpImage *image);
static void gimp_image_layer_remove (GimpContainer *container,
GimpLayer *layer,
GimpImage *image);
static void gimp_image_channel_add (GimpContainer *container,
GimpChannel *channel,
GimpImage *image);
static void gimp_image_channel_remove (GimpContainer *container,
GimpChannel *channel,
GimpImage *image);
static void gimp_image_channel_name_changed (GimpChannel *channel,
GimpImage *image);
static void gimp_image_channel_color_changed (GimpChannel *channel,
GimpImage *image);
static const guint8 * gimp_image_get_icc_profile (GimpColorManaged *managed, static const guint8 * gimp_image_get_icc_profile (GimpColorManaged *managed,
gsize *len); gsize *len);
@ -631,27 +617,19 @@ gimp_image_init (GimpImage *image)
image->vectors = gimp_list_new (GIMP_TYPE_VECTORS, TRUE); image->vectors = gimp_list_new (GIMP_TYPE_VECTORS, TRUE);
image->layer_stack = NULL; image->layer_stack = NULL;
image->layer_update_handler = g_signal_connect_swapped (image->layers, "update",
gimp_container_add_handler (image->layers, "update", G_CALLBACK (gimp_image_update),
G_CALLBACK (gimp_image_drawable_update), image);
image);
image->layer_visible_handler =
gimp_container_add_handler (image->layers, "visibility-changed",
G_CALLBACK (gimp_image_drawable_visibility),
image);
image->layer_alpha_handler = image->layer_alpha_handler =
gimp_container_add_handler (image->layers, "alpha-changed", gimp_container_add_handler (image->layers, "alpha-changed",
G_CALLBACK (gimp_image_layer_alpha_changed), G_CALLBACK (gimp_image_layer_alpha_changed),
image); image);
image->channel_update_handler = g_signal_connect_swapped (image->channels, "update",
gimp_container_add_handler (image->channels, "update", G_CALLBACK (gimp_image_update),
G_CALLBACK (gimp_image_drawable_update), image);
image);
image->channel_visible_handler =
gimp_container_add_handler (image->channels, "visibility-changed",
G_CALLBACK (gimp_image_drawable_visibility),
image);
image->channel_name_changed_handler = image->channel_name_changed_handler =
gimp_container_add_handler (image->channels, "name-changed", gimp_container_add_handler (image->channels, "name-changed",
G_CALLBACK (gimp_image_channel_name_changed), G_CALLBACK (gimp_image_channel_name_changed),
@ -661,13 +639,6 @@ gimp_image_init (GimpImage *image)
G_CALLBACK (gimp_image_channel_color_changed), G_CALLBACK (gimp_image_channel_color_changed),
image); image);
g_signal_connect (image->layers, "add",
G_CALLBACK (gimp_image_layer_add),
image);
g_signal_connect (image->layers, "remove",
G_CALLBACK (gimp_image_layer_remove),
image);
g_signal_connect (image->channels, "add", g_signal_connect (image->channels, "add",
G_CALLBACK (gimp_image_channel_add), G_CALLBACK (gimp_image_channel_add),
image); image);
@ -851,29 +822,22 @@ gimp_image_dispose (GObject *object)
gimp_image_undo_free (image); gimp_image_undo_free (image);
gimp_container_remove_handler (image->layers, g_signal_handlers_disconnect_by_func (image->layers,
image->layer_update_handler); gimp_image_update,
gimp_container_remove_handler (image->layers, image);
image->layer_visible_handler);
gimp_container_remove_handler (image->layers, gimp_container_remove_handler (image->layers,
image->layer_alpha_handler); image->layer_alpha_handler);
gimp_container_remove_handler (image->channels, g_signal_handlers_disconnect_by_func (image->channels,
image->channel_update_handler); gimp_image_update,
gimp_container_remove_handler (image->channels, image);
image->channel_visible_handler);
gimp_container_remove_handler (image->channels, gimp_container_remove_handler (image->channels,
image->channel_name_changed_handler); image->channel_name_changed_handler);
gimp_container_remove_handler (image->channels, gimp_container_remove_handler (image->channels,
image->channel_color_changed_handler); image->channel_color_changed_handler);
g_signal_handlers_disconnect_by_func (image->layers,
gimp_image_layer_add,
image);
g_signal_handlers_disconnect_by_func (image->layers,
gimp_image_layer_remove,
image);
g_signal_handlers_disconnect_by_func (image->channels, g_signal_handlers_disconnect_by_func (image->channels,
gimp_image_channel_add, gimp_image_channel_add,
image); image);
@ -1205,42 +1169,6 @@ gimp_image_mask_update (GimpDrawable *drawable,
image->flush_accum.mask_changed = TRUE; image->flush_accum.mask_changed = TRUE;
} }
static void
gimp_image_drawable_update (GimpDrawable *drawable,
gint x,
gint y,
gint width,
gint height,
GimpImage *image)
{
GimpItem *item = GIMP_ITEM (drawable);
if (gimp_item_get_visible (item))
{
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_image_update (image, x + offset_x, y + offset_y, width, height);
}
}
static void
gimp_image_drawable_visibility (GimpItem *item,
GimpImage *image)
{
gint offset_x;
gint offset_y;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_image_update (image,
offset_x, offset_y,
gimp_item_width (item),
gimp_item_height (item));
}
static void static void
gimp_image_layer_alpha_changed (GimpDrawable *drawable, gimp_image_layer_alpha_changed (GimpDrawable *drawable,
GimpImage *image) GimpImage *image)
@ -1249,38 +1177,11 @@ gimp_image_layer_alpha_changed (GimpDrawable *drawable,
image->flush_accum.alpha_changed = TRUE; image->flush_accum.alpha_changed = TRUE;
} }
static void
gimp_image_layer_add (GimpContainer *container,
GimpLayer *layer,
GimpImage *image)
{
GimpItem *item = GIMP_ITEM (layer);
if (gimp_item_get_visible (item))
gimp_image_drawable_visibility (item, image);
}
static void
gimp_image_layer_remove (GimpContainer *container,
GimpLayer *layer,
GimpImage *image)
{
GimpItem *item = GIMP_ITEM (layer);
if (gimp_item_get_visible (item))
gimp_image_drawable_visibility (item, image);
}
static void static void
gimp_image_channel_add (GimpContainer *container, gimp_image_channel_add (GimpContainer *container,
GimpChannel *channel, GimpChannel *channel,
GimpImage *image) GimpImage *image)
{ {
GimpItem *item = GIMP_ITEM (channel);
if (gimp_item_get_visible (item))
gimp_image_drawable_visibility (item, image);
if (! strcmp (GIMP_IMAGE_QUICK_MASK_NAME, if (! strcmp (GIMP_IMAGE_QUICK_MASK_NAME,
gimp_object_get_name (GIMP_OBJECT (channel)))) gimp_object_get_name (GIMP_OBJECT (channel))))
{ {
@ -1293,11 +1194,6 @@ gimp_image_channel_remove (GimpContainer *container,
GimpChannel *channel, GimpChannel *channel,
GimpImage *image) GimpImage *image)
{ {
GimpItem *item = GIMP_ITEM (channel);
if (gimp_item_get_visible (item))
gimp_image_drawable_visibility (item, image);
if (! strcmp (GIMP_IMAGE_QUICK_MASK_NAME, if (! strcmp (GIMP_IMAGE_QUICK_MASK_NAME,
gimp_object_get_name (GIMP_OBJECT (channel)))) gimp_object_get_name (GIMP_OBJECT (channel))))
{ {
@ -3278,18 +3174,6 @@ gimp_image_position_layer (GimpImage *image,
gimp_container_reorder (image->layers, GIMP_OBJECT (layer), new_index); gimp_container_reorder (image->layers, GIMP_OBJECT (layer), new_index);
if (gimp_item_get_visible (GIMP_ITEM (layer)))
{
gint off_x, off_y;
gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
gimp_image_update (image,
off_x, off_y,
gimp_item_width (GIMP_ITEM (layer)),
gimp_item_height (GIMP_ITEM (layer)));
}
return TRUE; return TRUE;
} }
@ -3520,20 +3404,7 @@ gimp_image_position_channel (GimpImage *image,
if (push_undo) if (push_undo)
gimp_image_undo_push_channel_reposition (image, undo_desc, channel); gimp_image_undo_push_channel_reposition (image, undo_desc, channel);
gimp_container_reorder (image->channels, gimp_container_reorder (image->channels, GIMP_OBJECT (channel), new_index);
GIMP_OBJECT (channel), new_index);
if (gimp_item_get_visible (GIMP_ITEM (channel)))
{
gint off_x, off_y;
gimp_item_offsets (GIMP_ITEM (channel), &off_x, &off_y);
gimp_image_update (image,
off_x, off_y,
gimp_item_width (GIMP_ITEM (channel)),
gimp_item_height (GIMP_ITEM (channel)));
}
return TRUE; return TRUE;
} }
@ -3740,8 +3611,7 @@ gimp_image_position_vectors (GimpImage *image,
if (push_undo) if (push_undo)
gimp_image_undo_push_vectors_reposition (image, undo_desc, vectors); gimp_image_undo_push_vectors_reposition (image, undo_desc, vectors);
gimp_container_reorder (image->vectors, gimp_container_reorder (image->vectors, GIMP_OBJECT (vectors), new_index);
GIMP_OBJECT (vectors), new_index);
return TRUE; return TRUE;
} }

View File

@ -138,11 +138,7 @@ struct _GimpImage
GimpContainer *vectors; /* the list of vectors */ GimpContainer *vectors; /* the list of vectors */
GSList *layer_stack; /* the layers in MRU order */ GSList *layer_stack; /* the layers in MRU order */
GQuark layer_update_handler;
GQuark layer_visible_handler;
GQuark layer_alpha_handler; GQuark layer_alpha_handler;
GQuark channel_update_handler;
GQuark channel_visible_handler;
GQuark channel_name_changed_handler; GQuark channel_name_changed_handler;
GQuark channel_color_changed_handler; GQuark channel_color_changed_handler;