[gimp] app: add a canvas group item which keeps around sub-items
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add a canvas group item which keeps around sub-items
- Date: Sat, 25 Sep 2010 15:16:52 +0000 (UTC)
commit 349c1500c94067ec52575ae0ab088a0b31ec8cae
Author: Michael Natterer <mitch gimp org>
Date: Sat Sep 25 17:14:57 2010 +0200
app: add a canvas group item which keeps around sub-items
It can draw them all with one call to draw() and returns a union of
their extents via get_extents().
app/display/Makefile.am | 2 +
app/display/gimpcanvasgroup.c | 209 +++++++++++++++++++++++++++++++++++++++++
app/display/gimpcanvasgroup.h | 58 +++++++++++
3 files changed, 269 insertions(+), 0 deletions(-)
---
diff --git a/app/display/Makefile.am b/app/display/Makefile.am
index 7b16694..3b82f4a 100644
--- a/app/display/Makefile.am
+++ b/app/display/Makefile.am
@@ -25,6 +25,8 @@ libappdisplay_a_sources = \
gimpcanvasboundary.h \
gimpcanvascorner.c \
gimpcanvascorner.h \
+ gimpcanvasgroup.c \
+ gimpcanvasgroup.h \
gimpcanvasguide.c \
gimpcanvasguide.h \
gimpcanvashandle.c \
diff --git a/app/display/gimpcanvasgroup.c b/app/display/gimpcanvasgroup.c
new file mode 100644
index 0000000..6b4d465
--- /dev/null
+++ b/app/display/gimpcanvasgroup.c
@@ -0,0 +1,209 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpcanvasgroup.c
+ * Copyright (C) 2010 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpbase/gimpbase.h"
+#include "libgimpmath/gimpmath.h"
+
+#include "display-types.h"
+
+#include "gimpcanvasgroup.h"
+#include "gimpdisplayshell.h"
+#include "gimpdisplayshell-transform.h"
+
+
+enum
+{
+ PROP_0
+};
+
+
+typedef struct _GimpCanvasGroupPrivate GimpCanvasGroupPrivate;
+
+struct _GimpCanvasGroupPrivate
+{
+ GList *items;
+};
+
+#define GET_PRIVATE(group) \
+ G_TYPE_INSTANCE_GET_PRIVATE (group, \
+ GIMP_TYPE_CANVAS_GROUP, \
+ GimpCanvasGroupPrivate)
+
+
+/* local function prototypes */
+
+static void gimp_canvas_group_dispose (GObject *object);
+static void gimp_canvas_group_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gimp_canvas_group_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gimp_canvas_group_draw (GimpCanvasItem *item,
+ GimpDisplayShell *shell,
+ cairo_t *cr);
+static GdkRegion * gimp_canvas_group_get_extents (GimpCanvasItem *item,
+ GimpDisplayShell *shell);
+
+
+G_DEFINE_TYPE (GimpCanvasGroup, gimp_canvas_group, GIMP_TYPE_CANVAS_ITEM)
+
+#define parent_class gimp_canvas_group_parent_class
+
+
+static void
+gimp_canvas_group_class_init (GimpCanvasGroupClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GimpCanvasItemClass *item_class = GIMP_CANVAS_ITEM_CLASS (klass);
+
+ object_class->dispose = gimp_canvas_group_dispose;
+ object_class->set_property = gimp_canvas_group_set_property;
+ object_class->get_property = gimp_canvas_group_get_property;
+
+ item_class->draw = gimp_canvas_group_draw;
+ item_class->get_extents = gimp_canvas_group_get_extents;
+
+ g_type_class_add_private (klass, sizeof (GimpCanvasGroupPrivate));
+}
+
+static void
+gimp_canvas_group_init (GimpCanvasGroup *group)
+{
+}
+
+static void
+gimp_canvas_group_dispose (GObject *object)
+{
+ GimpCanvasGroupPrivate *private = GET_PRIVATE (object);
+
+ if (private->items)
+ {
+ g_list_foreach (private->items, (GFunc) g_object_unref, NULL);
+ g_list_free (private->items);
+ private->items = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gimp_canvas_group_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ /* GimpCanvasGroupPrivate *private = GET_PRIVATE (object); */
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gimp_canvas_group_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ /* GimpCanvasGroupPrivate *private = GET_PRIVATE (object); */
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gimp_canvas_group_draw (GimpCanvasItem *item,
+ GimpDisplayShell *shell,
+ cairo_t *cr)
+{
+ GimpCanvasGroupPrivate *private = GET_PRIVATE (item);
+ GList *list;
+
+ for (list = private->items; list; list = g_list_next (list))
+ {
+ GimpCanvasItem *sub_item = list->data;
+
+ gimp_canvas_item_draw (sub_item, shell, cr);
+ }
+}
+
+static GdkRegion *
+gimp_canvas_group_get_extents (GimpCanvasItem *item,
+ GimpDisplayShell *shell)
+{
+ GimpCanvasGroupPrivate *private = GET_PRIVATE (item);
+ GdkRegion *region = NULL;
+ GList *list;
+
+ for (list = private->items; list; list = g_list_next (list))
+ {
+ GimpCanvasItem *sub_item = list->data;
+ GdkRegion *sub_region = gimp_canvas_item_get_extents (sub_item,
+ shell);
+
+ if (region)
+ {
+ gdk_region_union (region, sub_region);
+ gdk_region_destroy (sub_region);
+ }
+ else
+ {
+ region = sub_region;
+ }
+ }
+
+ return region;
+}
+
+GimpCanvasItem *
+gimp_canvas_group_new (void)
+{
+ return g_object_new (GIMP_TYPE_CANVAS_GROUP, NULL);
+}
+
+void
+gimp_canvas_group_add_item (GimpCanvasGroup *group,
+ GimpCanvasItem *item)
+{
+ GimpCanvasGroupPrivate *private;
+
+ g_return_if_fail (GIMP_IS_CANVAS_GROUP (group));
+ g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
+ g_return_if_fail (GIMP_CANVAS_ITEM (group) != item);
+
+ private = GET_PRIVATE (group);
+
+ private->items = g_list_append (private->items, g_object_ref (item));
+}
diff --git a/app/display/gimpcanvasgroup.h b/app/display/gimpcanvasgroup.h
new file mode 100644
index 0000000..150bb54
--- /dev/null
+++ b/app/display/gimpcanvasgroup.h
@@ -0,0 +1,58 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpcanvasgroup.h
+ * Copyright (C) 2010 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_CANVAS_GROUP_H__
+#define __GIMP_CANVAS_GROUP_H__
+
+
+#include "gimpcanvasitem.h"
+
+
+#define GIMP_TYPE_CANVAS_GROUP (gimp_canvas_group_get_type ())
+#define GIMP_CANVAS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CANVAS_GROUP, GimpCanvasGroup))
+#define GIMP_CANVAS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CANVAS_GROUP, GimpCanvasGroupClass))
+#define GIMP_IS_CANVAS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CANVAS_GROUP))
+#define GIMP_IS_CANVAS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CANVAS_GROUP))
+#define GIMP_CANVAS_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CANVAS_GROUP, GimpCanvasGroupClass))
+
+
+typedef struct _GimpCanvasGroup GimpCanvasGroup;
+typedef struct _GimpCanvasGroupClass GimpCanvasGroupClass;
+
+struct _GimpCanvasGroup
+{
+ GimpCanvasItem parent_instance;
+};
+
+struct _GimpCanvasGroupClass
+{
+ GimpCanvasItemClass parent_class;
+};
+
+
+GType gimp_canvas_group_get_type (void) G_GNUC_CONST;
+
+GimpCanvasItem * gimp_canvas_group_new (void);
+
+void gimp_canvas_group_add_item (GimpCanvasGroup *group,
+ GimpCanvasItem *item);
+
+
+#endif /* __GIMP_CANVAS_GROUP_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]