app: move all GimpGroupLayer members to a private struct

This commit is contained in:
Michael Natterer 2011-02-03 22:29:25 +01:00
parent 1efd387354
commit a116681982
3 changed files with 198 additions and 162 deletions

View File

@ -674,7 +674,7 @@ view_use_gegl_cmd_callback (GtkAction *action,
GimpLayer *layer = list->data;
if (GIMP_IS_GROUP_LAYER (layer))
GIMP_GROUP_LAYER (layer)->projection->use_gegl = active;
gimp_group_layer_get_projection (GIMP_GROUP_LAYER (layer))->use_gegl = active;
}
g_list_free (layers);

View File

@ -42,8 +42,25 @@
#include "gimp-intl.h"
typedef struct _GimpGroupLayerPrivate GimpGroupLayerPrivate;
struct _GimpGroupLayerPrivate
{
GimpContainer *children;
GimpProjection *projection;
GeglNode *graph;
GeglNode *offset_node;
gint suspend_resize;
};
#define GET_PRIVATE(item) G_TYPE_INSTANCE_GET_PRIVATE (item, \
GIMP_TYPE_GROUP_LAYER, \
GimpGroupLayerPrivate)
static void gimp_projectable_iface_init (GimpProjectableInterface *iface);
static void gimp_group_layer_finalize (GObject *object);
static void gimp_group_layer_set_property (GObject *object,
guint property_id,
const GValue *value,
@ -52,7 +69,6 @@ static void gimp_group_layer_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_group_layer_finalize (GObject *object);
static gint64 gimp_group_layer_get_memsize (GimpObject *object,
gint64 *gui_size);
@ -186,6 +202,8 @@ gimp_group_layer_class_init (GimpGroupLayerClass *klass)
drawable_class->estimate_memsize = gimp_group_layer_estimate_memsize;
drawable_class->convert_type = gimp_group_layer_convert_type;
g_type_class_add_private (klass, sizeof (GimpGroupLayerPrivate));
}
static void
@ -204,36 +222,74 @@ gimp_projectable_iface_init (GimpProjectableInterface *iface)
static void
gimp_group_layer_init (GimpGroupLayer *group)
{
group->children = gimp_drawable_stack_new (GIMP_TYPE_LAYER);
GimpGroupLayerPrivate *private = GET_PRIVATE (group);
g_signal_connect (group->children, "add",
private->children = gimp_drawable_stack_new (GIMP_TYPE_LAYER);
g_signal_connect (private->children, "add",
G_CALLBACK (gimp_group_layer_child_add),
group);
g_signal_connect (group->children, "remove",
g_signal_connect (private->children, "remove",
G_CALLBACK (gimp_group_layer_child_remove),
group);
gimp_container_add_handler (group->children, "notify::offset-x",
gimp_container_add_handler (private->children, "notify::offset-x",
G_CALLBACK (gimp_group_layer_child_move),
group);
gimp_container_add_handler (group->children, "notify::offset-y",
gimp_container_add_handler (private->children, "notify::offset-y",
G_CALLBACK (gimp_group_layer_child_move),
group);
gimp_container_add_handler (group->children, "size-changed",
gimp_container_add_handler (private->children, "size-changed",
G_CALLBACK (gimp_group_layer_child_resize),
group);
g_signal_connect (group->children, "update",
g_signal_connect (private->children, "update",
G_CALLBACK (gimp_group_layer_stack_update),
group);
group->projection = gimp_projection_new (GIMP_PROJECTABLE (group));
private->projection = gimp_projection_new (GIMP_PROJECTABLE (group));
g_signal_connect (group->projection, "update",
g_signal_connect (private->projection, "update",
G_CALLBACK (gimp_group_layer_proj_update),
group);
}
static void
gimp_group_layer_finalize (GObject *object)
{
GimpGroupLayerPrivate *private = GET_PRIVATE (object);
if (private->children)
{
g_signal_handlers_disconnect_by_func (private->children,
gimp_group_layer_child_add,
object);
g_signal_handlers_disconnect_by_func (private->children,
gimp_group_layer_child_remove,
object);
g_signal_handlers_disconnect_by_func (private->children,
gimp_group_layer_stack_update,
object);
g_object_unref (private->children);
private->children = NULL;
}
if (private->projection)
{
g_object_unref (private->projection);
private->projection = NULL;
}
if (private->graph)
{
g_object_unref (private->graph);
private->graph = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_group_layer_set_property (GObject *object,
guint property_id,
@ -262,51 +318,15 @@ gimp_group_layer_get_property (GObject *object,
}
}
static void
gimp_group_layer_finalize (GObject *object)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (object);
if (group->children)
{
g_signal_handlers_disconnect_by_func (group->children,
gimp_group_layer_child_add,
group);
g_signal_handlers_disconnect_by_func (group->children,
gimp_group_layer_child_remove,
group);
g_signal_handlers_disconnect_by_func (group->children,
gimp_group_layer_stack_update,
group);
g_object_unref (group->children);
group->children = NULL;
}
if (group->projection)
{
g_object_unref (group->projection);
group->projection = NULL;
}
if (group->graph)
{
g_object_unref (group->graph);
group->graph = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gint64
gimp_group_layer_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (object);
gint64 memsize = 0;
GimpGroupLayerPrivate *private = GET_PRIVATE (object);
gint64 memsize = 0;
memsize += gimp_object_get_memsize (GIMP_OBJECT (group->children), gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (group->projection), gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (private->children), gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (private->projection), gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@ -315,9 +335,7 @@ gimp_group_layer_get_memsize (GimpObject *object,
static GimpContainer *
gimp_group_layer_get_children (GimpViewable *viewable)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (viewable);
return group->children;
return GET_PRIVATE (viewable)->children;
}
static GimpItem *
@ -332,14 +350,15 @@ gimp_group_layer_duplicate (GimpItem *item,
if (GIMP_IS_GROUP_LAYER (new_item))
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpGroupLayer *new_group = GIMP_GROUP_LAYER (new_item);
gint position = 0;
GList *list;
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GimpGroupLayer *new_group = GIMP_GROUP_LAYER (new_item);
GimpGroupLayerPrivate *new_private = GET_PRIVATE (new_item);
gint position = 0;
GList *list;
gimp_group_layer_suspend_resize (new_group, FALSE);
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -367,7 +386,7 @@ gimp_group_layer_duplicate (GimpItem *item,
gimp_viewable_set_parent (GIMP_VIEWABLE (new_child),
GIMP_VIEWABLE (new_group));
gimp_container_insert (new_group->children,
gimp_container_insert (new_private->children,
GIMP_OBJECT (new_child),
position++);
}
@ -387,10 +406,10 @@ static void
gimp_group_layer_convert (GimpItem *item,
GimpImage *dest_image)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GList *list;
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GList *list;
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -408,14 +427,15 @@ gimp_group_layer_translate (GimpItem *item,
gint offset_y,
gboolean push_undo)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpLayerMask *mask;
GList *list;
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GimpLayerMask *mask;
GList *list;
/* don't push an undo here because undo will call us again */
gimp_group_layer_suspend_resize (group, FALSE);
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -449,13 +469,14 @@ gimp_group_layer_scale (GimpItem *item,
GimpInterpolationType interpolation_type,
GimpProgress *progress)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpLayerMask *mask;
GList *list;
gdouble width_factor;
gdouble height_factor;
gint old_offset_x;
gint old_offset_y;
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GimpLayerMask *mask;
GList *list;
gdouble width_factor;
gdouble height_factor;
gint old_offset_x;
gint old_offset_y;
width_factor = (gdouble) new_width / (gdouble) gimp_item_get_width (item);
height_factor = (gdouble) new_height / (gdouble) gimp_item_get_height (item);
@ -465,7 +486,7 @@ gimp_group_layer_scale (GimpItem *item,
gimp_group_layer_suspend_resize (group, TRUE);
list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
while (list)
{
@ -502,7 +523,7 @@ gimp_group_layer_scale (GimpItem *item,
}
else
{
gimp_container_remove (group->children, GIMP_OBJECT (child));
gimp_container_remove (private->children, GIMP_OBJECT (child));
}
}
@ -525,17 +546,18 @@ gimp_group_layer_resize (GimpItem *item,
gint offset_x,
gint offset_y)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpLayerMask *mask;
GList *list;
gint x, y;
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GimpLayerMask *mask;
GList *list;
gint x, y;
x = gimp_item_get_offset_x (item) - offset_x;
y = gimp_item_get_offset_y (item) - offset_y;
gimp_group_layer_suspend_resize (group, TRUE);
list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
while (list)
{
@ -575,7 +597,7 @@ gimp_group_layer_resize (GimpItem *item,
}
else
{
gimp_container_remove (group->children, GIMP_OBJECT (child));
gimp_container_remove (private->children, GIMP_OBJECT (child));
}
}
@ -595,13 +617,14 @@ gimp_group_layer_flip (GimpItem *item,
gdouble axis,
gboolean clip_result)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpLayerMask *mask;
GList *list;
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GimpLayerMask *mask;
GList *list;
gimp_group_layer_suspend_resize (group, TRUE);
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -628,13 +651,14 @@ gimp_group_layer_rotate (GimpItem *item,
gdouble center_y,
gboolean clip_result)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpLayerMask *mask;
GList *list;
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GimpLayerMask *mask;
GList *list;
gimp_group_layer_suspend_resize (group, TRUE);
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -663,13 +687,14 @@ gimp_group_layer_transform (GimpItem *item,
GimpTransformResize clip_result,
GimpProgress *progress)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpLayerMask *mask;
GList *list;
GimpGroupLayer *group = GIMP_GROUP_LAYER (item);
GimpGroupLayerPrivate *private = GET_PRIVATE (item);
GimpLayerMask *mask;
GList *list;
gimp_group_layer_suspend_resize (group, TRUE);
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -697,12 +722,12 @@ gimp_group_layer_estimate_memsize (const GimpDrawable *drawable,
gint width,
gint height)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (drawable);
GList *list;
GimpImageBaseType base_type;
gint64 memsize = 0;
GimpGroupLayerPrivate *private = GET_PRIVATE (drawable);
GList *list;
GimpImageBaseType base_type;
gint64 memsize = 0;
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -737,9 +762,10 @@ gimp_group_layer_convert_type (GimpDrawable *drawable,
GimpImageBaseType new_base_type,
gboolean push_undo)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (drawable);
TileManager *tiles;
GimpImageType new_type;
GimpGroupLayer *group = GIMP_GROUP_LAYER (drawable);
GimpGroupLayerPrivate *private = GET_PRIVATE (drawable);
TileManager *tiles;
GimpImageType new_type;
if (push_undo)
{
@ -762,7 +788,7 @@ gimp_group_layer_convert_type (GimpDrawable *drawable,
gimp_projectable_structure_changed (GIMP_PROJECTABLE (drawable));
tiles = gimp_projection_get_tiles_at_level (group->projection,
tiles = gimp_projection_get_tiles_at_level (private->projection,
0, NULL);
gimp_drawable_set_tiles_full (drawable,
@ -775,47 +801,48 @@ gimp_group_layer_convert_type (GimpDrawable *drawable,
static GeglNode *
gimp_group_layer_get_graph (GimpProjectable *projectable)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (projectable);
GeglNode *layers_node;
GeglNode *output;
gint off_x;
gint off_y;
GimpGroupLayer *group = GIMP_GROUP_LAYER (projectable);
GimpGroupLayerPrivate *private = GET_PRIVATE (projectable);
GeglNode *layers_node;
GeglNode *output;
gint off_x;
gint off_y;
if (group->graph)
return group->graph;
if (private->graph)
return private->graph;
group->graph = gegl_node_new ();
private->graph = gegl_node_new ();
layers_node =
gimp_drawable_stack_get_graph (GIMP_DRAWABLE_STACK (group->children));
gimp_drawable_stack_get_graph (GIMP_DRAWABLE_STACK (private->children));
gegl_node_add_child (group->graph, layers_node);
gegl_node_add_child (private->graph, layers_node);
gimp_item_get_offset (GIMP_ITEM (group), &off_x, &off_y);
group->offset_node = gegl_node_new_child (group->graph,
"operation", "gegl:translate",
"x", (gdouble) -off_x,
"y", (gdouble) -off_y,
NULL);
private->offset_node = gegl_node_new_child (private->graph,
"operation", "gegl:translate",
"x", (gdouble) -off_x,
"y", (gdouble) -off_y,
NULL);
gegl_node_connect_to (layers_node, "output",
group->offset_node, "input");
gegl_node_connect_to (layers_node, "output",
private->offset_node, "input");
output = gegl_node_get_output_proxy (group->graph, "output");
output = gegl_node_get_output_proxy (private->graph, "output");
gegl_node_connect_to (group->offset_node, "output",
output, "input");
gegl_node_connect_to (private->offset_node, "output",
output, "input");
return group->graph;
return private->graph;
}
static GList *
gimp_group_layer_get_layers (GimpProjectable *projectable)
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (projectable);
GimpGroupLayerPrivate *private = GET_PRIVATE (projectable);
return gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
return gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
}
@ -837,11 +864,19 @@ gimp_group_layer_new (GimpImage *image)
type));
if (gimp_image_get_projection (image)->use_gegl)
group->projection->use_gegl = TRUE;
GET_PRIVATE (group)->projection->use_gegl = TRUE;
return GIMP_LAYER (group);
}
GimpProjection *
gimp_group_layer_get_projection (GimpGroupLayer *group)
{
g_return_val_if_fail (GIMP_IS_GROUP_LAYER (group), NULL);
return GET_PRIVATE (group)->projection;
}
void
gimp_group_layer_suspend_resize (GimpGroupLayer *group,
gboolean push_undo)
@ -859,17 +894,21 @@ gimp_group_layer_suspend_resize (GimpGroupLayer *group,
gimp_image_undo_push_group_layer_suspend (gimp_item_get_image (item),
NULL, group);
group->suspend_resize++;
GET_PRIVATE (group)->suspend_resize++;
}
void
gimp_group_layer_resume_resize (GimpGroupLayer *group,
gboolean push_undo)
{
GimpItem *item;
GimpGroupLayerPrivate *private;
GimpItem *item;
g_return_if_fail (GIMP_IS_GROUP_LAYER (group));
g_return_if_fail (group->suspend_resize > 0);
private = GET_PRIVATE (group);
g_return_if_fail (private->suspend_resize > 0);
item = GIMP_ITEM (group);
@ -880,9 +919,9 @@ gimp_group_layer_resume_resize (GimpGroupLayer *group,
gimp_image_undo_push_group_layer_resume (gimp_item_get_image (item),
NULL, group);
group->suspend_resize--;
private->suspend_resize--;
if (group->suspend_resize == 0)
if (private->suspend_resize == 0)
{
gimp_group_layer_update_size (group);
}
@ -925,7 +964,7 @@ gimp_group_layer_child_resize (GimpLayer *child,
static void
gimp_group_layer_update (GimpGroupLayer *group)
{
if (group->suspend_resize == 0)
if (GET_PRIVATE (group)->suspend_resize == 0)
{
gimp_group_layer_update_size (group);
}
@ -934,19 +973,20 @@ gimp_group_layer_update (GimpGroupLayer *group)
static void
gimp_group_layer_update_size (GimpGroupLayer *group)
{
GimpItem *item = GIMP_ITEM (group);
gint old_x = gimp_item_get_offset_x (item);
gint old_y = gimp_item_get_offset_y (item);
gint old_width = gimp_item_get_width (item);
gint old_height = gimp_item_get_height (item);
gint x = 0;
gint y = 0;
gint width = 1;
gint height = 1;
gboolean first = TRUE;
GList *list;
GimpGroupLayerPrivate *private = GET_PRIVATE (group);
GimpItem *item = GIMP_ITEM (group);
gint old_x = gimp_item_get_offset_x (item);
gint old_y = gimp_item_get_offset_y (item);
gint old_width = gimp_item_get_width (item);
gint old_height = gimp_item_get_height (item);
gint x = 0;
gint y = 0;
gint width = 1;
gint height = 1;
gboolean first = TRUE;
GList *list;
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (group->children));
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
list;
list = g_list_next (list))
{
@ -991,7 +1031,7 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
gimp_projectable_structure_changed (GIMP_PROJECTABLE (group));
tiles = gimp_projection_get_tiles_at_level (group->projection,
tiles = gimp_projection_get_tiles_at_level (private->projection,
0, NULL);
/* FIXME: need to set the item's extents back to the old
@ -1020,8 +1060,8 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
x, y, width, height);
}
if (group->offset_node)
gegl_node_set (group->offset_node,
if (private->offset_node)
gegl_node_set (private->offset_node,
"x", (gdouble) -x,
"y", (gdouble) -y,
NULL);
@ -1054,7 +1094,7 @@ gimp_group_layer_stack_update (GimpDrawableStack *stack,
* when the actual read happens, so this it not a performance
* problem)
*/
gimp_pickable_flush (GIMP_PICKABLE (group->projection));
gimp_pickable_flush (GIMP_PICKABLE (GET_PRIVATE (group)->projection));
}
static void

View File

@ -37,13 +37,7 @@ typedef struct _GimpGroupLayerClass GimpGroupLayerClass;
struct _GimpGroupLayer
{
GimpLayer parent_instance;
GimpContainer *children;
GimpProjection *projection;
GeglNode *graph;
GeglNode *offset_node;
gint suspend_resize;
GimpLayer parent_instance;
};
struct _GimpGroupLayerClass
@ -52,14 +46,16 @@ struct _GimpGroupLayerClass
};
GType gimp_group_layer_get_type (void) G_GNUC_CONST;
GType gimp_group_layer_get_type (void) G_GNUC_CONST;
GimpLayer * gimp_group_layer_new (GimpImage *image);
GimpLayer * gimp_group_layer_new (GimpImage *image);
void gimp_group_layer_suspend_resize (GimpGroupLayer *group,
gboolean push_undo);
void gimp_group_layer_resume_resize (GimpGroupLayer *group,
gboolean push_undo);
GimpProjection * gimp_group_layer_get_projection (GimpGroupLayer *group);
void gimp_group_layer_suspend_resize (GimpGroupLayer *group,
gboolean push_undo);
void gimp_group_layer_resume_resize (GimpGroupLayer *group,
gboolean push_undo);
#endif /* __GIMP_GROUP_LAYER_H__ */