2010-09-25 23:14:57 +08:00
|
|
|
/* 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
|
|
|
|
{
|
2010-09-26 20:12:54 +08:00
|
|
|
PROP_0,
|
2010-09-28 04:59:36 +08:00
|
|
|
PROP_GROUP_STROKING,
|
|
|
|
PROP_GROUP_FILLING
|
2010-09-25 23:14:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _GimpCanvasGroupPrivate GimpCanvasGroupPrivate;
|
|
|
|
|
|
|
|
struct _GimpCanvasGroupPrivate
|
|
|
|
{
|
2010-09-26 20:12:54 +08:00
|
|
|
GList *items;
|
|
|
|
gboolean group_stroking;
|
2010-09-28 04:59:36 +08:00
|
|
|
gboolean group_filling;
|
2010-09-25 23:14:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#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);
|
2010-10-01 23:13:00 +08:00
|
|
|
static void gimp_canvas_group_child_update (GimpCanvasItem *item,
|
|
|
|
GdkRegion *region,
|
|
|
|
GimpCanvasGroup *group);
|
2010-09-25 23:14:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_GROUP_STROKING,
|
|
|
|
g_param_spec_boolean ("group-stroking",
|
|
|
|
NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2010-09-28 04:59:36 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_GROUP_FILLING,
|
|
|
|
g_param_spec_boolean ("group-filling",
|
|
|
|
NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2010-09-25 23:14:57 +08:00
|
|
|
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)
|
|
|
|
{
|
2010-09-26 20:12:54 +08:00
|
|
|
GimpCanvasGroupPrivate *private = GET_PRIVATE (object);
|
2010-09-25 23:14:57 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2010-09-26 20:12:54 +08:00
|
|
|
case PROP_GROUP_STROKING:
|
|
|
|
private->group_stroking = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-09-28 04:59:36 +08:00
|
|
|
case PROP_GROUP_FILLING:
|
|
|
|
private->group_filling = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-09-26 20:12:54 +08:00
|
|
|
|
2010-09-25 23:14:57 +08:00
|
|
|
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)
|
|
|
|
{
|
2010-09-26 20:12:54 +08:00
|
|
|
GimpCanvasGroupPrivate *private = GET_PRIVATE (object);
|
2010-09-25 23:14:57 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2010-09-26 20:12:54 +08:00
|
|
|
case PROP_GROUP_STROKING:
|
|
|
|
g_value_set_boolean (value, private->group_stroking);
|
|
|
|
break;
|
2010-09-28 04:59:36 +08:00
|
|
|
case PROP_GROUP_FILLING:
|
|
|
|
g_value_set_boolean (value, private->group_filling);
|
|
|
|
break;
|
2010-09-26 20:12:54 +08:00
|
|
|
|
2010-09-25 23:14:57 +08:00
|
|
|
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;
|
|
|
|
|
2010-10-01 20:54:53 +08:00
|
|
|
gimp_canvas_item_draw (sub_item, cr);
|
2010-09-25 23:14:57 +08:00
|
|
|
}
|
2010-09-26 20:12:54 +08:00
|
|
|
|
|
|
|
if (private->group_stroking)
|
2010-10-01 20:54:53 +08:00
|
|
|
_gimp_canvas_item_stroke (item, cr);
|
2010-09-28 04:59:36 +08:00
|
|
|
|
|
|
|
if (private->group_filling)
|
2010-10-01 20:54:53 +08:00
|
|
|
_gimp_canvas_item_fill (item, cr);
|
2010-09-25 23:14:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-10-01 20:54:53 +08:00
|
|
|
GdkRegion *sub_region = gimp_canvas_item_get_extents (sub_item);
|
2010-09-25 23:14:57 +08:00
|
|
|
|
2010-09-28 04:59:36 +08:00
|
|
|
if (! region)
|
2010-09-25 23:14:57 +08:00
|
|
|
{
|
2010-09-28 04:59:36 +08:00
|
|
|
region = sub_region;
|
2010-09-25 23:14:57 +08:00
|
|
|
}
|
2010-09-28 04:59:36 +08:00
|
|
|
else if (sub_region)
|
2010-09-25 23:14:57 +08:00
|
|
|
{
|
2010-09-28 04:59:36 +08:00
|
|
|
gdk_region_union (region, sub_region);
|
|
|
|
gdk_region_destroy (sub_region);
|
2010-09-25 23:14:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2010-10-01 23:13:00 +08:00
|
|
|
static void
|
|
|
|
gimp_canvas_group_child_update (GimpCanvasItem *item,
|
|
|
|
GdkRegion *region,
|
|
|
|
GimpCanvasGroup *group)
|
|
|
|
{
|
2010-10-02 02:41:27 +08:00
|
|
|
if (_gimp_canvas_item_needs_update (GIMP_CANVAS_ITEM (group)))
|
|
|
|
_gimp_canvas_item_update (GIMP_CANVAS_ITEM (group), region);
|
2010-10-01 23:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2010-09-25 23:14:57 +08:00
|
|
|
GimpCanvasItem *
|
2010-10-01 20:13:45 +08:00
|
|
|
gimp_canvas_group_new (GimpDisplayShell *shell)
|
2010-09-25 23:14:57 +08:00
|
|
|
{
|
2010-10-01 20:13:45 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_CANVAS_GROUP,
|
|
|
|
"shell", shell,
|
|
|
|
NULL);
|
2010-09-25 23:14:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
if (private->group_stroking)
|
|
|
|
gimp_canvas_item_suspend_stroking (item);
|
|
|
|
|
2010-09-28 04:59:36 +08:00
|
|
|
if (private->group_filling)
|
|
|
|
gimp_canvas_item_suspend_filling (item);
|
|
|
|
|
2010-09-25 23:14:57 +08:00
|
|
|
private->items = g_list_append (private->items, g_object_ref (item));
|
2010-10-01 23:13:00 +08:00
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
if (_gimp_canvas_item_needs_update (GIMP_CANVAS_ITEM (group)))
|
2010-10-01 23:13:00 +08:00
|
|
|
{
|
2010-10-02 02:41:27 +08:00
|
|
|
GdkRegion *region = gimp_canvas_item_get_extents (item);
|
|
|
|
|
|
|
|
if (region)
|
|
|
|
{
|
|
|
|
_gimp_canvas_item_update (GIMP_CANVAS_ITEM (group), region);
|
|
|
|
gdk_region_destroy (region);
|
|
|
|
}
|
2010-10-01 23:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (item, "update",
|
|
|
|
G_CALLBACK (gimp_canvas_group_child_update),
|
|
|
|
group);
|
2010-09-25 23:14:57 +08:00
|
|
|
}
|
2010-09-26 20:12:54 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_group_remove_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));
|
|
|
|
|
|
|
|
private = GET_PRIVATE (group);
|
|
|
|
|
|
|
|
g_return_if_fail (g_list_find (private->items, item));
|
|
|
|
|
|
|
|
private->items = g_list_remove (private->items, item);
|
2010-10-01 23:13:00 +08:00
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
if (_gimp_canvas_item_needs_update (GIMP_CANVAS_ITEM (group)))
|
2010-10-01 23:13:00 +08:00
|
|
|
{
|
2010-10-02 02:41:27 +08:00
|
|
|
GdkRegion *region = gimp_canvas_item_get_extents (item);
|
|
|
|
|
|
|
|
if (region)
|
|
|
|
{
|
|
|
|
_gimp_canvas_item_update (GIMP_CANVAS_ITEM (group), region);
|
|
|
|
gdk_region_destroy (region);
|
|
|
|
}
|
2010-10-01 23:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (item,
|
|
|
|
gimp_canvas_group_child_update,
|
|
|
|
group);
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_group_set_group_stroking (GimpCanvasGroup *group,
|
|
|
|
gboolean group_stroking)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_GROUP (group));
|
|
|
|
|
|
|
|
g_object_set (group,
|
|
|
|
"group-stroking", group_stroking ? TRUE : FALSE,
|
|
|
|
NULL);
|
|
|
|
}
|
2010-09-28 04:59:36 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_group_set_group_filling (GimpCanvasGroup *group,
|
|
|
|
gboolean group_filling)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_GROUP (group));
|
|
|
|
|
|
|
|
g_object_set (group,
|
|
|
|
"group-filling", group_filling ? TRUE : FALSE,
|
|
|
|
NULL);
|
|
|
|
}
|