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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "display-types.h"
|
|
|
|
|
2010-09-20 05:20:36 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
#include "gimpcanvasitem.h"
|
|
|
|
#include "gimpdisplayshell.h"
|
|
|
|
#include "gimpdisplayshell-style.h"
|
|
|
|
|
|
|
|
|
2010-09-20 05:20:36 +08:00
|
|
|
typedef struct _GimpCanvasItemPrivate GimpCanvasItemPrivate;
|
|
|
|
|
|
|
|
struct _GimpCanvasItemPrivate
|
|
|
|
{
|
2010-09-24 01:25:22 +08:00
|
|
|
gboolean highlight;
|
2010-09-26 20:12:54 +08:00
|
|
|
gint suspend_stroking;
|
2010-09-20 05:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GET_PRIVATE(item) \
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (item, \
|
|
|
|
GIMP_TYPE_CANVAS_ITEM, \
|
|
|
|
GimpCanvasItemPrivate)
|
|
|
|
|
|
|
|
|
2010-09-20 01:45:51 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2010-09-20 05:20:36 +08:00
|
|
|
static void gimp_canvas_item_real_draw (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr);
|
|
|
|
static GdkRegion * gimp_canvas_item_real_get_extents (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell);
|
2010-09-20 01:45:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpCanvasItem, gimp_canvas_item,
|
|
|
|
GIMP_TYPE_OBJECT)
|
|
|
|
|
|
|
|
#define parent_class gimp_canvas_item_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_canvas_item_class_init (GimpCanvasItemClass *klass)
|
|
|
|
{
|
2010-09-20 05:20:36 +08:00
|
|
|
klass->draw = gimp_canvas_item_real_draw;
|
|
|
|
klass->get_extents = gimp_canvas_item_real_get_extents;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GimpCanvasItemPrivate));
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_canvas_item_init (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_canvas_item_real_draw (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
g_warn_if_reached ();
|
|
|
|
}
|
|
|
|
|
2010-09-20 05:20:36 +08:00
|
|
|
static GdkRegion *
|
|
|
|
gimp_canvas_item_real_get_extents (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_item_draw (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
GIMP_CANVAS_ITEM_GET_CLASS (item)->draw (item, shell, cr);
|
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
2010-09-20 05:20:36 +08:00
|
|
|
GdkRegion *
|
|
|
|
gimp_canvas_item_get_extents (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
|
|
|
|
|
|
|
|
return GIMP_CANVAS_ITEM_GET_CLASS (item)->get_extents (item, shell);
|
|
|
|
}
|
|
|
|
|
2010-09-24 01:25:22 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_set_highlight (GimpCanvasItem *item,
|
|
|
|
gboolean highlight)
|
|
|
|
{
|
2010-09-26 20:12:54 +08:00
|
|
|
GimpCanvasItemPrivate *private;
|
2010-09-24 01:25:22 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
private = GET_PRIVATE (item);
|
|
|
|
|
2010-09-24 01:25:22 +08:00
|
|
|
private->highlight = highlight ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
void
|
|
|
|
gimp_canvas_item_suspend_stroking (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
GimpCanvasItemPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
|
|
|
private = GET_PRIVATE (item);
|
|
|
|
|
|
|
|
private->suspend_stroking++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_canvas_item_resume_stroking (GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
GimpCanvasItemPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
|
|
|
private = GET_PRIVATE (item);
|
|
|
|
|
|
|
|
g_return_if_fail (private->suspend_stroking > 0);
|
|
|
|
|
|
|
|
private->suspend_stroking--;
|
|
|
|
}
|
|
|
|
|
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-09-20 01:45:51 +08:00
|
|
|
void
|
|
|
|
_gimp_canvas_item_stroke (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
2010-09-24 01:25:22 +08:00
|
|
|
GimpCanvasItemPrivate *private = GET_PRIVATE (item);
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
if (private->suspend_stroking == 0)
|
|
|
|
{
|
|
|
|
gimp_display_shell_set_tool_bg_style (shell, cr);
|
|
|
|
cairo_stroke_preserve (cr);
|
|
|
|
|
|
|
|
gimp_display_shell_set_tool_fg_style (shell, cr, private->highlight);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_new_sub_path (cr);
|
|
|
|
}
|
2010-09-20 01:45:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gimp_canvas_item_fill (GimpCanvasItem *item,
|
|
|
|
GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
2010-09-24 01:25:22 +08:00
|
|
|
GimpCanvasItemPrivate *private = GET_PRIVATE (item);
|
|
|
|
|
2010-09-26 20:12:54 +08:00
|
|
|
if (private->suspend_stroking > 0)
|
|
|
|
g_warning ("_gimp_canvas_item_fill() on an item that is in a stroking group");
|
|
|
|
|
2010-09-23 06:11:49 +08:00
|
|
|
gimp_display_shell_set_tool_bg_style (shell, cr);
|
|
|
|
cairo_set_line_width (cr, 2.0);
|
|
|
|
cairo_stroke_preserve (cr);
|
|
|
|
|
2010-09-24 01:25:22 +08:00
|
|
|
gimp_display_shell_set_tool_fg_style (shell, cr, private->highlight);
|
2010-09-20 01:45:51 +08:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|