2010-09-20 01:45:51 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2010-09-20 05:46:06 +08:00
|
|
|
* gimpcanvasitem.c
|
|
|
|
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2010-09-20 01:45:51 +08:00
|
|
|
* 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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2010-09-20 01:45:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2019-07-31 16:16:21 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2010-10-01 23:13:00 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
#include "display-types.h"
|
|
|
|
|
2013-04-18 20:21:20 +08:00
|
|
|
#include "gimpcanvas-style.h"
|
2010-09-20 01:45:51 +08:00
|
|
|
#include "gimpcanvasitem.h"
|
2013-04-18 19:53:42 +08:00
|
|
|
#include "gimpdisplay.h"
|
2010-09-20 01:45:51 +08:00
|
|
|
#include "gimpdisplayshell.h"
|
2013-04-18 19:53:42 +08:00
|
|
|
#include "gimpdisplayshell-transform.h"
|
2010-09-20 01:45:51 +08:00
|
|
|
|
|
|
|
|
2010-09-26 23:40:10 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2010-10-01 20:13:45 +08:00
|
|
|
PROP_SHELL,
|
2010-10-02 02:41:27 +08:00
|
|
|
PROP_VISIBLE,
|
2010-09-26 23:40:10 +08:00
|
|
|
PROP_LINE_CAP,
|
|
|
|
PROP_HIGHLIGHT
|
|
|
|
};
|
|
|
|
|
2010-10-01 23:13:00 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
UPDATE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2010-09-26 23:40:10 +08:00
|
|
|
|
2010-09-20 05:20:36 +08:00
|
|
|
struct _GimpCanvasItemPrivate
|
|
|
|
{
|
2010-10-01 20:13:45 +08:00
|
|
|
GimpDisplayShell *shell;
|
2010-10-02 02:41:27 +08:00
|
|
|
gboolean visible;
|
2010-10-01 20:13:45 +08:00
|
|
|
cairo_line_cap_t line_cap;
|
|
|
|
gboolean highlight;
|
|
|
|
gint suspend_stroking;
|
|
|
|
gint suspend_filling;
|
2010-10-02 02:41:27 +08:00
|
|
|
gint change_count;
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_t *change_region;
|
2010-09-20 05:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2017-06-11 04:00:38 +08:00
|
|
|
static void gimp_canvas_item_dispose (GObject *object);
|
2013-04-18 21:45:08 +08:00
|
|
|
static void gimp_canvas_item_constructed (GObject *object);
|
|
|
|
static void gimp_canvas_item_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_canvas_item_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_canvas_item_dispatch_properties_changed (GObject *object,
|
|
|
|
guint n_pspecs,
|
|
|
|
GParamSpec **pspecs);
|
|
|
|
|
|
|
|
static void gimp_canvas_item_real_draw (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr);
|
|
|
|
static cairo_region_t * gimp_canvas_item_real_get_extents (GimpCanvasItem *item);
|
|
|
|
static void gimp_canvas_item_real_stroke (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr);
|
|
|
|
static void gimp_canvas_item_real_fill (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr);
|
|
|
|
static gboolean gimp_canvas_item_real_hit (GimpCanvasItem *item,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
2010-09-20 01:45:51 +08:00
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpCanvasItem, gimp_canvas_item, GIMP_TYPE_OBJECT)
|
2010-09-20 01:45:51 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_canvas_item_parent_class
|
|
|
|
|
2010-10-01 23:13:00 +08:00
|
|
|
static guint item_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_canvas_item_class_init (GimpCanvasItemClass *klass)
|
|
|
|
{
|
2010-09-26 23:40:10 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2017-06-11 04:00:38 +08:00
|
|
|
object_class->dispose = gimp_canvas_item_dispose;
|
2010-10-01 23:13:00 +08:00
|
|
|
object_class->constructed = gimp_canvas_item_constructed;
|
|
|
|
object_class->set_property = gimp_canvas_item_set_property;
|
|
|
|
object_class->get_property = gimp_canvas_item_get_property;
|
|
|
|
object_class->dispatch_properties_changed = gimp_canvas_item_dispatch_properties_changed;
|
|
|
|
|
|
|
|
klass->update = NULL;
|
|
|
|
klass->draw = gimp_canvas_item_real_draw;
|
|
|
|
klass->get_extents = gimp_canvas_item_real_get_extents;
|
|
|
|
klass->stroke = gimp_canvas_item_real_stroke;
|
|
|
|
klass->fill = gimp_canvas_item_real_fill;
|
2011-03-29 00:54:02 +08:00
|
|
|
klass->hit = gimp_canvas_item_real_hit;
|
2010-10-01 23:13:00 +08:00
|
|
|
|
|
|
|
item_signals[UPDATE] =
|
|
|
|
g_signal_new ("update",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpCanvasItemClass, update),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2010-10-01 23:13:00 +08:00
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
2010-09-26 23:40:10 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_SHELL,
|
|
|
|
g_param_spec_object ("shell",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_DISPLAY_SHELL,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_VISIBLE,
|
|
|
|
g_param_spec_boolean ("visible",
|
|
|
|
NULL, NULL,
|
|
|
|
TRUE,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2010-09-26 23:40:10 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_LINE_CAP,
|
|
|
|
g_param_spec_int ("line-cap",
|
|
|
|
NULL, NULL,
|
|
|
|
CAIRO_LINE_CAP_BUTT,
|
|
|
|
CAIRO_LINE_CAP_SQUARE,
|
|
|
|
CAIRO_LINE_CAP_ROUND,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_HIGHLIGHT,
|
|
|
|
g_param_spec_boolean ("highlight",
|
|
|
|
NULL, NULL,
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_canvas_item_init (GimpCanvasItem *item)
|
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
GimpCanvasItemPrivate *private;
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
item->private = gimp_canvas_item_get_instance_private (item);
|
2016-11-07 21:12:24 +08:00
|
|
|
private = item->private;
|
2010-09-26 23:40:10 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
private->shell = NULL;
|
2010-10-02 02:41:27 +08:00
|
|
|
private->visible = TRUE;
|
2010-09-26 23:40:10 +08:00
|
|
|
private->line_cap = CAIRO_LINE_CAP_ROUND;
|
|
|
|
private->highlight = FALSE;
|
|
|
|
private->suspend_stroking = 0;
|
2010-09-28 04:59:36 +08:00
|
|
|
private->suspend_filling = 0;
|
2010-10-02 02:41:27 +08:00
|
|
|
private->change_count = 1; /* avoid emissions during construction */
|
|
|
|
private->change_region = NULL;
|
2010-09-26 23:40:10 +08:00
|
|
|
}
|
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
static void
|
|
|
|
gimp_canvas_item_constructed (GObject *object)
|
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
GimpCanvasItem *item = GIMP_CANVAS_ITEM (object);
|
2010-10-01 20:13:45 +08:00
|
|
|
|
2018-02-12 05:23:10 +08:00
|
|
|
gimp_assert (GIMP_IS_DISPLAY_SHELL (item->private->shell));
|
2010-10-01 20:13:45 +08:00
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
item->private->change_count = 0; /* undo hack from init() */
|
2010-10-02 02:41:27 +08:00
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2010-10-01 20:13:45 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 04:00:38 +08:00
|
|
|
static void
|
|
|
|
gimp_canvas_item_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item = GIMP_CANVAS_ITEM (object);
|
|
|
|
|
|
|
|
item->private->change_count++; /* avoid emissions during destruction */
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2010-09-26 23:40:10 +08:00
|
|
|
static void
|
|
|
|
gimp_canvas_item_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
GimpCanvasItem *item = GIMP_CANVAS_ITEM (object);
|
|
|
|
GimpCanvasItemPrivate *private = item->private;
|
2010-09-26 23:40:10 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2010-10-01 20:13:45 +08:00
|
|
|
case PROP_SHELL:
|
|
|
|
private->shell = g_value_get_object (value); /* don't ref */
|
|
|
|
break;
|
2010-10-02 02:41:27 +08:00
|
|
|
case PROP_VISIBLE:
|
|
|
|
private->visible = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-09-26 23:40:10 +08:00
|
|
|
case PROP_LINE_CAP:
|
|
|
|
private->line_cap = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_HIGHLIGHT:
|
|
|
|
private->highlight = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_canvas_item_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
GimpCanvasItem *item = GIMP_CANVAS_ITEM (object);
|
|
|
|
GimpCanvasItemPrivate *private = item->private;
|
2010-09-26 23:40:10 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2010-10-01 20:13:45 +08:00
|
|
|
case PROP_SHELL:
|
|
|
|
g_value_set_object (value, private->shell);
|
|
|
|
break;
|
2010-10-02 02:41:27 +08:00
|
|
|
case PROP_VISIBLE:
|
|
|
|
g_value_set_boolean (value, private->visible);
|
|
|
|
break;
|
2010-09-26 23:40:10 +08:00
|
|
|
case PROP_LINE_CAP:
|
|
|
|
g_value_set_int (value, private->line_cap);
|
|
|
|
break;
|
|
|
|
case PROP_HIGHLIGHT:
|
|
|
|
g_value_set_boolean (value, private->highlight);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|
|
|
|
|
2010-10-01 23:13:00 +08:00
|
|
|
static void
|
|
|
|
gimp_canvas_item_dispatch_properties_changed (GObject *object,
|
|
|
|
guint n_pspecs,
|
|
|
|
GParamSpec **pspecs)
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item = GIMP_CANVAS_ITEM (object);
|
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object,
|
|
|
|
n_pspecs,
|
|
|
|
pspecs);
|
2010-10-01 23:43:41 +08:00
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
if (_gimp_canvas_item_needs_update (item))
|
|
|
|
{
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_t *region = gimp_canvas_item_get_extents (item);
|
2010-10-01 23:43:41 +08:00
|
|
|
|
|
|
|
if (region)
|
|
|
|
{
|
|
|
|
g_signal_emit (object, item_signals[UPDATE], 0,
|
|
|
|
region);
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_destroy (region);
|
2010-10-01 23:43:41 +08:00
|
|
|
}
|
2010-10-01 23:13:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
static void
|
2013-04-18 21:45:08 +08:00
|
|
|
gimp_canvas_item_real_draw (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr)
|
2010-09-20 01:45:51 +08:00
|
|
|
{
|
|
|
|
g_warn_if_reached ();
|
|
|
|
}
|
|
|
|
|
2010-10-19 01:59:13 +08:00
|
|
|
static cairo_region_t *
|
2013-04-18 21:45:08 +08:00
|
|
|
gimp_canvas_item_real_get_extents (GimpCanvasItem *item)
|
2010-09-20 01:45:51 +08:00
|
|
|
{
|
2010-09-22 16:33:41 +08:00
|
|
|
return NULL;
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|
|
|
|
|
2010-09-30 05:40:45 +08:00
|
|
|
static void
|
2013-04-18 21:45:08 +08:00
|
|
|
gimp_canvas_item_real_stroke (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr)
|
2010-09-30 05:40:45 +08:00
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
cairo_set_line_cap (cr, item->private->line_cap);
|
2010-09-30 05:40:45 +08:00
|
|
|
|
2013-04-18 20:21:20 +08:00
|
|
|
gimp_canvas_set_tool_bg_style (gimp_canvas_item_get_canvas (item), cr);
|
2010-09-30 05:40:45 +08:00
|
|
|
cairo_stroke_preserve (cr);
|
|
|
|
|
2013-04-18 20:21:20 +08:00
|
|
|
gimp_canvas_set_tool_fg_style (gimp_canvas_item_get_canvas (item), cr,
|
2016-11-07 21:12:24 +08:00
|
|
|
item->private->highlight);
|
2010-09-30 05:40:45 +08:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 21:45:08 +08:00
|
|
|
gimp_canvas_item_real_fill (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr)
|
2010-09-30 05:40:45 +08:00
|
|
|
{
|
2013-04-18 20:21:20 +08:00
|
|
|
gimp_canvas_set_tool_bg_style (gimp_canvas_item_get_canvas (item), cr);
|
2010-09-30 05:40:45 +08:00
|
|
|
cairo_set_line_width (cr, 2.0);
|
|
|
|
cairo_stroke_preserve (cr);
|
|
|
|
|
2013-04-18 20:21:20 +08:00
|
|
|
gimp_canvas_set_tool_fg_style (gimp_canvas_item_get_canvas (item), cr,
|
2016-11-07 21:12:24 +08:00
|
|
|
item->private->highlight);
|
2010-09-30 05:40:45 +08:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
2011-03-29 00:54:02 +08:00
|
|
|
static gboolean
|
2013-04-18 21:45:08 +08:00
|
|
|
gimp_canvas_item_real_hit (GimpCanvasItem *item,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
2011-03-29 00:54:02 +08:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2013-04-18 21:45:08 +08:00
|
|
|
GimpDisplayShell *
|
|
|
|
gimp_canvas_item_get_shell (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), NULL);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
return item->private->shell;
|
2013-04-18 21:45:08 +08:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:53:42 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_canvas_item_get_image (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), NULL);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
return gimp_display_get_image (item->private->shell->display);
|
2013-04-18 19:53:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_canvas_item_get_canvas (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), NULL);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
return item->private->shell->canvas;
|
2013-04-18 19:53:42 +08:00
|
|
|
}
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
void
|
2010-10-01 20:54:53 +08:00
|
|
|
gimp_canvas_item_draw (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr)
|
2010-09-20 01:45:51 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->visible)
|
2010-10-02 02:41:27 +08:00
|
|
|
{
|
|
|
|
cairo_save (cr);
|
2013-04-18 21:45:08 +08:00
|
|
|
GIMP_CANVAS_ITEM_GET_CLASS (item)->draw (item, cr);
|
2010-10-02 02:41:27 +08:00
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|
|
|
|
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_t *
|
2010-10-01 20:54:53 +08:00
|
|
|
gimp_canvas_item_get_extents (GimpCanvasItem *item)
|
2010-09-20 05:20:36 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), NULL);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->visible)
|
2013-04-18 21:45:08 +08:00
|
|
|
return GIMP_CANVAS_ITEM_GET_CLASS (item)->get_extents (item);
|
2010-10-02 02:41:27 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-29 00:54:02 +08:00
|
|
|
gboolean
|
|
|
|
gimp_canvas_item_hit (GimpCanvasItem *item,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
2011-03-29 06:23:10 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), FALSE);
|
2011-03-29 00:54:02 +08:00
|
|
|
|
2017-06-14 06:15:09 +08:00
|
|
|
if (item->private->visible)
|
|
|
|
return GIMP_CANVAS_ITEM_GET_CLASS (item)->hit (item, x, y);
|
|
|
|
|
|
|
|
return FALSE;
|
2011-03-29 00:54:02 +08:00
|
|
|
}
|
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_set_visible (GimpCanvasItem *item,
|
|
|
|
gboolean visible)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->visible != visible)
|
2010-10-02 02:41:27 +08:00
|
|
|
{
|
|
|
|
gimp_canvas_item_begin_change (item);
|
|
|
|
g_object_set (G_OBJECT (item),
|
|
|
|
"visible", visible,
|
|
|
|
NULL);
|
|
|
|
gimp_canvas_item_end_change (item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_canvas_item_get_visible (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), FALSE);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
return item->private->visible;
|
2010-09-20 05:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-09-26 23:40:10 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_set_line_cap (GimpCanvasItem *item,
|
|
|
|
cairo_line_cap_t line_cap)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->line_cap != line_cap)
|
2010-10-01 23:43:41 +08:00
|
|
|
{
|
2010-10-02 02:41:27 +08:00
|
|
|
gimp_canvas_item_begin_change (item);
|
|
|
|
g_object_set (G_OBJECT (item),
|
|
|
|
"line-cap", line_cap,
|
|
|
|
NULL);
|
|
|
|
gimp_canvas_item_end_change (item);
|
2010-10-01 23:43:41 +08:00
|
|
|
}
|
2010-09-26 23:40:10 +08:00
|
|
|
}
|
|
|
|
|
2010-09-24 01:25:22 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_set_highlight (GimpCanvasItem *item,
|
|
|
|
gboolean highlight)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->highlight != highlight)
|
2010-10-01 23:43:41 +08:00
|
|
|
{
|
2010-10-02 02:41:27 +08:00
|
|
|
g_object_set (G_OBJECT (item),
|
|
|
|
"highlight", highlight,
|
|
|
|
NULL);
|
2010-10-01 23:43:41 +08:00
|
|
|
}
|
2010-09-24 01:25:22 +08:00
|
|
|
}
|
|
|
|
|
2010-09-30 05:46:36 +08:00
|
|
|
gboolean
|
|
|
|
gimp_canvas_item_get_highlight (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), FALSE);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
return item->private->highlight;
|
2010-09-30 05:46:36 +08:00
|
|
|
}
|
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_begin_change (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
GimpCanvasItemPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
private = item->private;
|
2010-10-02 02:41:27 +08:00
|
|
|
|
|
|
|
private->change_count++;
|
|
|
|
|
|
|
|
if (private->change_count == 1 &&
|
|
|
|
g_signal_has_handler_pending (item, item_signals[UPDATE], 0, FALSE))
|
|
|
|
{
|
|
|
|
private->change_region = gimp_canvas_item_get_extents (item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_item_end_change (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
GimpCanvasItemPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
private = item->private;
|
2010-10-02 02:41:27 +08:00
|
|
|
|
|
|
|
g_return_if_fail (private->change_count > 0);
|
|
|
|
|
|
|
|
private->change_count--;
|
|
|
|
|
2010-10-03 03:52:42 +08:00
|
|
|
if (private->change_count == 0)
|
2010-10-02 02:41:27 +08:00
|
|
|
{
|
2010-10-03 03:52:42 +08:00
|
|
|
if (g_signal_has_handler_pending (item, item_signals[UPDATE], 0, FALSE))
|
2010-10-02 02:41:27 +08:00
|
|
|
{
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_t *region = gimp_canvas_item_get_extents (item);
|
2010-10-03 03:52:42 +08:00
|
|
|
|
|
|
|
if (! region)
|
|
|
|
{
|
|
|
|
region = private->change_region;
|
|
|
|
}
|
|
|
|
else if (private->change_region)
|
|
|
|
{
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_union (region, private->change_region);
|
|
|
|
cairo_region_destroy (private->change_region);
|
2010-10-03 03:52:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private->change_region = NULL;
|
|
|
|
|
|
|
|
if (region)
|
|
|
|
{
|
|
|
|
g_signal_emit (item, item_signals[UPDATE], 0,
|
|
|
|
region);
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_destroy (region);
|
2010-10-03 03:52:42 +08:00
|
|
|
}
|
2010-10-02 02:41:27 +08:00
|
|
|
}
|
2017-07-16 00:38:01 +08:00
|
|
|
else
|
2010-10-02 02:41:27 +08:00
|
|
|
{
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_pointer (&private->change_region, cairo_region_destroy);
|
2010-10-02 02:41:27 +08:00
|
|
|
}
|
2010-10-03 01:57:41 +08:00
|
|
|
}
|
2010-10-02 02:41:27 +08:00
|
|
|
}
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_suspend_stroking (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
item->private->suspend_stroking++;
|
2010-09-26 20:12:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_item_resume_stroking (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
g_return_if_fail (item->private->suspend_stroking > 0);
|
2010-09-26 20:12:54 +08:00
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
item->private->suspend_stroking--;
|
2010-09-26 20:12:54 +08:00
|
|
|
}
|
|
|
|
|
2010-09-28 04:59:36 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_suspend_filling (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
item->private->suspend_filling++;
|
2010-09-28 04:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_item_resume_filling (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
g_return_if_fail (item->private->suspend_filling > 0);
|
2010-09-28 04:59:36 +08:00
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
item->private->suspend_filling--;
|
2010-09-28 04:59:36 +08:00
|
|
|
}
|
|
|
|
|
2013-04-18 21:45:08 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_transform (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GimpCanvasItemPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
private = item->private;
|
2013-04-18 21:45:08 +08:00
|
|
|
|
|
|
|
cairo_translate (cr, -private->shell->offset_x, -private->shell->offset_y);
|
|
|
|
cairo_scale (cr, private->shell->scale_x, private->shell->scale_y);
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:53:42 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_transform_xy (GimpCanvasItem *item,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint *tx,
|
|
|
|
gint *ty)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
gimp_display_shell_zoom_xy (item->private->shell, x, y, tx, ty);
|
2013-04-18 19:53:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_item_transform_xy_f (GimpCanvasItem *item,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble *tx,
|
|
|
|
gdouble *ty)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
gimp_display_shell_zoom_xy_f (item->private->shell, x, y, tx, ty);
|
2013-04-18 19:53:42 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 03:55:40 +08:00
|
|
|
/**
|
|
|
|
* gimp_canvas_item_transform_distance:
|
|
|
|
* @item: a #GimpCanvasItem
|
|
|
|
* @x1: start point X in image coordinates
|
|
|
|
* @y1: start point Y in image coordinates
|
|
|
|
* @x2: end point X in image coordinates
|
|
|
|
* @y2: end point Y in image coordinates
|
|
|
|
*
|
|
|
|
* If you just need to compare distances, consider to use
|
|
|
|
* gimp_canvas_item_transform_distance_square() instead.
|
|
|
|
*
|
|
|
|
* Returns: the distance between the given points in display coordinates
|
|
|
|
**/
|
|
|
|
gdouble
|
|
|
|
gimp_canvas_item_transform_distance (GimpCanvasItem *item,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
|
|
|
{
|
|
|
|
return sqrt (gimp_canvas_item_transform_distance_square (item,
|
|
|
|
x1, y1, x2, y2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_canvas_item_transform_distance_square:
|
|
|
|
* @item: a #GimpCanvasItem
|
|
|
|
* @x1: start point X in image coordinates
|
|
|
|
* @y1: start point Y in image coordinates
|
|
|
|
* @x2: end point X in image coordinates
|
|
|
|
* @y2: end point Y in image coordinates
|
|
|
|
*
|
|
|
|
* This function is more effective than
|
|
|
|
* gimp_canvas_item_transform_distance() as it doesn't perform a
|
|
|
|
* sqrt(). Use this if you just need to compare distances.
|
|
|
|
*
|
|
|
|
* Returns: the square of the distance between the given points in
|
|
|
|
* display coordinates
|
|
|
|
**/
|
|
|
|
gdouble
|
|
|
|
gimp_canvas_item_transform_distance_square (GimpCanvasItem *item,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
|
|
|
{
|
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), 0.0);
|
|
|
|
|
|
|
|
gimp_canvas_item_transform_xy_f (item, x1, y1, &tx1, &ty1);
|
|
|
|
gimp_canvas_item_transform_xy_f (item, x2, y2, &tx2, &ty2);
|
|
|
|
|
|
|
|
return SQR (tx2 - tx1) + SQR (ty2 - ty1);
|
|
|
|
}
|
|
|
|
|
2019-09-04 23:28:21 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_untransform_viewport (GimpCanvasItem *item,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *w,
|
|
|
|
gint *h)
|
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble x1, y1;
|
|
|
|
gdouble x2, y2;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
|
|
|
shell = item->private->shell;
|
|
|
|
|
|
|
|
gimp_display_shell_unrotate_bounds (shell,
|
|
|
|
0.0, 0.0,
|
|
|
|
shell->disp_width, shell->disp_height,
|
|
|
|
&x1, &y1,
|
|
|
|
&x2, &y2);
|
|
|
|
|
|
|
|
*x = floor (x1);
|
|
|
|
*y = floor (y1);
|
|
|
|
*w = ceil (x2) - *x;
|
|
|
|
*h = ceil (y2) - *y;
|
|
|
|
}
|
|
|
|
|
2010-09-20 05:20:36 +08:00
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
/* protected functions */
|
2010-09-20 05:20:36 +08:00
|
|
|
|
2010-10-02 02:41:27 +08:00
|
|
|
void
|
|
|
|
_gimp_canvas_item_update (GimpCanvasItem *item,
|
2010-10-19 01:59:13 +08:00
|
|
|
cairo_region_t *region)
|
2010-10-02 02:41:27 +08:00
|
|
|
{
|
|
|
|
g_signal_emit (item, item_signals[UPDATE], 0,
|
|
|
|
region);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gimp_canvas_item_needs_update (GimpCanvasItem *item)
|
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
return (item->private->change_count == 0 &&
|
2010-10-02 02:41:27 +08:00
|
|
|
g_signal_has_handler_pending (item, item_signals[UPDATE], 0, FALSE));
|
|
|
|
}
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
void
|
2010-10-01 20:54:53 +08:00
|
|
|
_gimp_canvas_item_stroke (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr)
|
2010-09-20 01:45:51 +08:00
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->suspend_filling > 0)
|
2010-09-28 04:59:36 +08:00
|
|
|
g_warning ("_gimp_canvas_item_stroke() on an item that is in a filling group");
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->suspend_stroking == 0)
|
2010-09-26 20:12:54 +08:00
|
|
|
{
|
2013-04-18 21:45:08 +08:00
|
|
|
GIMP_CANVAS_ITEM_GET_CLASS (item)->stroke (item, cr);
|
2010-09-26 20:12:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_new_sub_path (cr);
|
|
|
|
}
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-07 21:12:24 +08:00
|
|
|
_gimp_canvas_item_fill (GimpCanvasItem *item,
|
|
|
|
cairo_t *cr)
|
2010-09-20 01:45:51 +08:00
|
|
|
{
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->suspend_stroking > 0)
|
2010-09-26 20:12:54 +08:00
|
|
|
g_warning ("_gimp_canvas_item_fill() on an item that is in a stroking group");
|
|
|
|
|
2016-11-07 21:12:24 +08:00
|
|
|
if (item->private->suspend_filling == 0)
|
2010-09-28 04:59:36 +08:00
|
|
|
{
|
2013-04-18 21:45:08 +08:00
|
|
|
GIMP_CANVAS_ITEM_GET_CLASS (item)->fill (item, cr);
|
2010-09-28 04:59:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_new_sub_path (cr);
|
|
|
|
}
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|