[gimp] app: draw guides using GimpCanvasItems
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: draw guides using GimpCanvasItems
- Date: Fri, 1 Oct 2010 08:37:45 +0000 (UTC)
commit 26d0035be040daf87e085c94483f1ceee463164f
Author: Michael Natterer <mitch gimp org>
Date: Fri Oct 1 10:34:15 2010 +0200
app: draw guides using GimpCanvasItems
- Add signals GimpImage::guide_added(), removed() and moved()
- Remove singal GimpImage::update_guide()
- Adapt core code to emit the new signals instead of update_guide()
- Have the shell connect to the new signals and update guide canvas
items as needed
- Remove gimp_display_shell_draw_guides()
app/core/gimpguideundo.c | 8 ++-
app/core/gimpimage-arrange.c | 2 -
app/core/gimpimage-guides.c | 10 ++--
app/core/gimpimage.c | 87 ++++++++++++++++++++++-------
app/core/gimpimage.h | 17 ++++-
app/display/gimpdisplayshell-callbacks.c | 5 --
app/display/gimpdisplayshell-draw.c | 46 ---------------
app/display/gimpdisplayshell-draw.h | 2 -
app/display/gimpdisplayshell-handlers.c | 89 +++++++++++++++++++++++++++---
app/tools/gimpmeasuretool.c | 41 +++++--------
10 files changed, 187 insertions(+), 120 deletions(-)
---
diff --git a/app/core/gimpguideundo.c b/app/core/gimpguideundo.c
index 8db26f2..6e16b75 100644
--- a/app/core/gimpguideundo.c
+++ b/app/core/gimpguideundo.c
@@ -151,6 +151,7 @@ gimp_guide_undo_pop (GimpUndo *undo,
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (undo);
GimpOrientationType orientation;
gint position;
+ gboolean moved = FALSE;
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
@@ -168,13 +169,16 @@ gimp_guide_undo_pop (GimpUndo *undo,
}
else
{
- gimp_image_update_guide (undo->image, guide_undo->guide);
gimp_guide_set_position (guide_undo->guide, guide_undo->position);
- gimp_image_update_guide (undo->image, guide_undo->guide);
+
+ moved = TRUE;
}
gimp_guide_set_orientation (guide_undo->guide, guide_undo->orientation);
+ if (moved || guide_undo->orientation != orientation)
+ gimp_image_guide_moved (undo->image, guide_undo->guide);
+
guide_undo->position = position;
guide_undo->orientation = orientation;
}
diff --git a/app/core/gimpimage-arrange.c b/app/core/gimpimage-arrange.c
index e3194ce..fd51d25 100644
--- a/app/core/gimpimage-arrange.c
+++ b/app/core/gimpimage-arrange.c
@@ -171,12 +171,10 @@ gimp_image_arrange_objects (GimpImage *image,
{
case GIMP_ORIENTATION_VERTICAL:
gimp_image_move_guide (image, guide, z1 + xtranslate, TRUE);
- gimp_image_update_guide (image, guide);
break;
case GIMP_ORIENTATION_HORIZONTAL:
gimp_image_move_guide (image, guide, z1 + ytranslate, TRUE);
- gimp_image_update_guide (image, guide);
break;
default:
diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c
index 647768c..2a4ed74 100644
--- a/app/core/gimpimage-guides.c
+++ b/app/core/gimpimage-guides.c
@@ -98,7 +98,7 @@ gimp_image_add_guide (GimpImage *image,
gimp_guide_set_position (guide, position);
g_object_ref (G_OBJECT (guide));
- gimp_image_update_guide (image, guide);
+ gimp_image_guide_added (image, guide);
}
void
@@ -113,14 +113,14 @@ gimp_image_remove_guide (GimpImage *image,
private = GIMP_IMAGE_GET_PRIVATE (image);
- gimp_image_update_guide (image, guide);
-
if (push_undo)
gimp_image_undo_push_guide (image, C_("undo-type", "Remove Guide"), guide);
private->guides = g_list_remove (private->guides, guide);
gimp_guide_removed (guide);
+ gimp_image_guide_removed (image, guide);
+
gimp_guide_set_position (guide, -1);
g_object_unref (G_OBJECT (guide));
}
@@ -143,9 +143,9 @@ gimp_image_move_guide (GimpImage *image,
if (push_undo)
gimp_image_undo_push_guide (image, C_("undo-type", "Move Guide"), guide);
- gimp_image_update_guide (image, guide);
gimp_guide_set_position (guide, position);
- gimp_image_update_guide (image, guide);
+
+ gimp_image_guide_moved (image, guide);
}
GList *
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 2b94cbe..4952d44 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -100,8 +100,10 @@ enum
DIRTY,
SAVED,
EXPORTED,
- UPDATE_GUIDE,
UPDATE_VECTORS,
+ GUIDE_ADDED,
+ GUIDE_REMOVED,
+ GUIDE_MOVED,
SAMPLE_POINT_ADDED,
SAMPLE_POINT_REMOVED,
SAMPLE_POINT_MOVED,
@@ -422,25 +424,45 @@ gimp_image_class_init (GimpImageClass *klass)
G_TYPE_NONE, 1,
G_TYPE_STRING);
- gimp_image_signals[UPDATE_GUIDE] =
- g_signal_new ("update-guide",
+ gimp_image_signals[UPDATE_VECTORS] =
+ g_signal_new ("update-vectors",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GimpImageClass, update_guide),
+ G_STRUCT_OFFSET (GimpImageClass, update_vectors),
NULL, NULL,
- gimp_marshal_VOID__POINTER,
+ gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- G_TYPE_POINTER);
+ GIMP_TYPE_VECTORS);
- gimp_image_signals[UPDATE_VECTORS] =
- g_signal_new ("update-vectors",
+ gimp_image_signals[GUIDE_ADDED] =
+ g_signal_new ("guide-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GimpImageClass, update_vectors),
+ G_STRUCT_OFFSET (GimpImageClass, guide_added),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- GIMP_TYPE_VECTORS);
+ GIMP_TYPE_GUIDE);
+
+ gimp_image_signals[GUIDE_REMOVED] =
+ g_signal_new ("guide-removed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpImageClass, guide_removed),
+ NULL, NULL,
+ gimp_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GIMP_TYPE_GUIDE);
+
+ gimp_image_signals[GUIDE_MOVED] =
+ g_signal_new ("guide-moved",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpImageClass, guide_moved),
+ NULL, NULL,
+ gimp_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GIMP_TYPE_GUIDE);
gimp_image_signals[SAMPLE_POINT_ADDED] =
g_signal_new ("sample-point-added",
@@ -551,8 +573,10 @@ gimp_image_class_init (GimpImageClass *klass)
klass->dirty = NULL;
klass->saved = NULL;
klass->exported = NULL;
- klass->update_guide = NULL;
klass->update_vectors = NULL;
+ klass->guide_added = NULL;
+ klass->guide_removed = NULL;
+ klass->guide_moved = NULL;
klass->sample_point_added = NULL;
klass->sample_point_removed = NULL;
klass->sample_point_moved = NULL;
@@ -2090,24 +2114,47 @@ gimp_image_invalidate (GimpImage *image,
}
void
-gimp_image_update_guide (GimpImage *image,
- GimpGuide *guide)
+gimp_image_update_vectors (GimpImage *image,
+ GimpVectors *vectors)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
- g_return_if_fail (guide != NULL);
+ g_return_if_fail (GIMP_IS_VECTORS (vectors));
- g_signal_emit (image, gimp_image_signals[UPDATE_GUIDE], 0, guide);
+ g_signal_emit (image, gimp_image_signals[UPDATE_VECTORS], 0,
+ vectors);
}
void
-gimp_image_update_vectors (GimpImage *image,
- GimpVectors *vectors)
+gimp_image_guide_added (GimpImage *image,
+ GimpGuide *guide)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
- g_return_if_fail (GIMP_IS_VECTORS (vectors));
+ g_return_if_fail (GIMP_IS_GUIDE (guide));
- g_signal_emit (image, gimp_image_signals[UPDATE_VECTORS], 0,
- vectors);
+ g_signal_emit (image, gimp_image_signals[GUIDE_ADDED], 0,
+ guide);
+}
+
+void
+gimp_image_guide_removed (GimpImage *image,
+ GimpGuide *guide)
+{
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+ g_return_if_fail (GIMP_IS_GUIDE (guide));
+
+ g_signal_emit (image, gimp_image_signals[GUIDE_REMOVED], 0,
+ guide);
+}
+
+void
+gimp_image_guide_moved (GimpImage *image,
+ GimpGuide *guide)
+{
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+ g_return_if_fail (GIMP_IS_GUIDE (guide));
+
+ g_signal_emit (image, gimp_image_signals[GUIDE_MOVED], 0,
+ guide);
}
void
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 4a83c59..e72079b 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -131,10 +131,14 @@ struct _GimpImageClass
void (* exported) (GimpImage *image,
const gchar *uri);
- void (* update_guide) (GimpImage *image,
- GimpGuide *guide);
void (* update_vectors) (GimpImage *image,
GimpVectors *vectors);
+ void (* guide_added) (GimpImage *image,
+ GimpGuide *guide);
+ void (* guide_removed) (GimpImage *image,
+ GimpGuide *guide);
+ void (* guide_moved) (GimpImage *image,
+ GimpGuide *guide);
void (* sample_point_added) (GimpImage *image,
GimpSamplePoint *sample_point);
void (* sample_point_removed) (GimpImage *image,
@@ -249,11 +253,16 @@ void gimp_image_invalidate (GimpImage *image,
gint y,
gint width,
gint height);
-void gimp_image_update_guide (GimpImage *image,
- GimpGuide *guide);
void gimp_image_update_vectors (GimpImage *image,
GimpVectors *vectors);
+void gimp_image_guide_added (GimpImage *image,
+ GimpGuide *guide);
+void gimp_image_guide_removed (GimpImage *image,
+ GimpGuide *guide);
+void gimp_image_guide_moved (GimpImage *image,
+ GimpGuide *guide);
+
void gimp_image_sample_point_added (GimpImage *image,
GimpSamplePoint *sample_point);
void gimp_image_sample_point_removed (GimpImage *image,
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index ccf95d0..61f2f29 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -2340,11 +2340,6 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
gimp_display_shell_draw_grid (shell, cr);
cairo_restore (cr);
- /* draw the guides */
- cairo_save (cr);
- gimp_display_shell_draw_guides (shell, cr);
- cairo_restore (cr);
-
/* draw canvas items */
cairo_save (cr);
gimp_canvas_item_draw (shell->canvas_item, shell, cr);
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index dcedf62..489586a 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -27,16 +27,13 @@
#include "display-types.h"
-#include "base/boundary.h"
#include "base/tile-manager.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpgrid.h"
-#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
-#include "core/gimpimage-guides.h"
#include "core/gimpprojection.h"
#include "vectors/gimpstroke.h"
@@ -46,7 +43,6 @@
#include "widgets/gimpwidgets-utils.h"
#include "gimpcanvas.h"
-#include "gimpcanvasguide.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"
@@ -128,48 +124,6 @@ gimp_display_shell_draw_get_scaled_image_size_for_scale (GimpDisplayShell *shell
}
void
-gimp_display_shell_draw_guides (GimpDisplayShell *shell,
- cairo_t *cr)
-{
- GimpImage *image;
-
- g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
- g_return_if_fail (cr != NULL);
-
- image = gimp_display_get_image (shell->display);
-
- if (image && gimp_display_shell_get_show_guides (shell))
- {
- GimpCanvasItem *item;
- GList *list;
-
- item = gimp_canvas_guide_new (GIMP_ORIENTATION_HORIZONTAL, 0);
- g_object_set (item, "guide-style", TRUE, NULL);
-
- for (list = gimp_image_get_guides (image);
- list;
- list = g_list_next (list))
- {
- GimpGuide *guide = list->data;
- gint position;
-
- position = gimp_guide_get_position (guide);
-
- if (position >= 0)
- {
- g_object_set (item,
- "orientation", gimp_guide_get_orientation (guide),
- "position", position,
- NULL);
- gimp_canvas_item_draw (item, shell, cr);
- }
- }
-
- g_object_unref (item);
- }
-}
-
-void
gimp_display_shell_draw_grid (GimpDisplayShell *shell,
cairo_t *cr)
{
diff --git a/app/display/gimpdisplayshell-draw.h b/app/display/gimpdisplayshell-draw.h
index 4199264..09843f4 100644
--- a/app/display/gimpdisplayshell-draw.h
+++ b/app/display/gimpdisplayshell-draw.h
@@ -27,8 +27,6 @@ void gimp_display_shell_draw_get_scaled_image_size_for_scale
gdouble scale,
gint *w,
gint *h);
-void gimp_display_shell_draw_guides (GimpDisplayShell *shell,
- cairo_t *cr);
void gimp_display_shell_draw_grid (GimpDisplayShell *shell,
cairo_t *cr);
void gimp_display_shell_draw_pen (GimpDisplayShell *shell,
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index 2184b4a..a504d29 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -34,6 +34,7 @@
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
+#include "core/gimpimage-guides.h"
#include "core/gimpimage-quick-mask.h"
#include "core/gimpimage-sample-points.h"
#include "core/gimpitem.h"
@@ -93,7 +94,13 @@ static void gimp_display_shell_resolution_changed_handler (GimpImage *i
GimpDisplayShell *shell);
static void gimp_display_shell_quick_mask_changed_handler (GimpImage *image,
GimpDisplayShell *shell);
-static void gimp_display_shell_update_guide_handler (GimpImage *image,
+static void gimp_display_shell_guide_add_handler (GimpImage *image,
+ GimpGuide *guide,
+ GimpDisplayShell *shell);
+static void gimp_display_shell_guide_remove_handler (GimpImage *image,
+ GimpGuide *guide,
+ GimpDisplayShell *shell);
+static void gimp_display_shell_guide_move_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell);
static void gimp_display_shell_sample_point_add_handler (GimpImage *image,
@@ -187,9 +194,22 @@ gimp_display_shell_connect (GimpDisplayShell *shell)
g_signal_connect (image, "quick-mask-changed",
G_CALLBACK (gimp_display_shell_quick_mask_changed_handler),
shell);
- g_signal_connect (image, "update-guide",
- G_CALLBACK (gimp_display_shell_update_guide_handler),
+
+ g_signal_connect (image, "guide-added",
+ G_CALLBACK (gimp_display_shell_guide_add_handler),
+ shell);
+ g_signal_connect (image, "guide-removed",
+ G_CALLBACK (gimp_display_shell_guide_remove_handler),
+ shell);
+ g_signal_connect (image, "guide-moved",
+ G_CALLBACK (gimp_display_shell_guide_move_handler),
shell);
+ for (list = gimp_image_get_guides (image);
+ list;
+ list = g_list_next (list))
+ {
+ gimp_display_shell_guide_add_handler (image, list->data, shell);
+ }
g_signal_connect (image, "sample-point-added",
G_CALLBACK (gimp_display_shell_sample_point_add_handler),
@@ -348,9 +368,23 @@ gimp_display_shell_disconnect (GimpDisplayShell *shell)
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_invalidate_preview_handler,
shell);
+
+ g_signal_handlers_disconnect_by_func (image,
+ gimp_display_shell_guide_add_handler,
+ shell);
+ g_signal_handlers_disconnect_by_func (image,
+ gimp_display_shell_guide_remove_handler,
+ shell);
g_signal_handlers_disconnect_by_func (image,
- gimp_display_shell_update_guide_handler,
+ gimp_display_shell_guide_move_handler,
shell);
+ for (list = gimp_image_get_guides (image);
+ list;
+ list = g_list_next (list))
+ {
+ gimp_canvas_proxy_group_remove_item (GIMP_CANVAS_PROXY_GROUP (shell->guides),
+ list->data);
+ }
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_sample_point_add_handler,
@@ -502,19 +536,56 @@ gimp_display_shell_quick_mask_changed_handler (GimpImage *image,
}
static void
-gimp_display_shell_update_guide_handler (GimpImage *image,
- GimpGuide *guide,
- GimpDisplayShell *shell)
+gimp_display_shell_guide_add_handler (GimpImage *image,
+ GimpGuide *guide,
+ GimpDisplayShell *shell)
{
- GimpCanvasItem *item;
+ GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->guides);
+ GimpCanvasItem *item;
item = gimp_canvas_guide_new (gimp_guide_get_orientation (guide),
gimp_guide_get_position (guide));
g_object_set (item, "guide-style", TRUE, NULL);
+ gimp_canvas_proxy_group_add_item (group, guide, item);
+ g_object_unref (item);
+
gimp_display_shell_expose_item (shell, item);
+}
- g_object_unref (item);
+static void
+gimp_display_shell_guide_remove_handler (GimpImage *image,
+ GimpGuide *guide,
+ GimpDisplayShell *shell)
+{
+ GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->guides);
+ GimpCanvasItem *item;
+
+ item = gimp_canvas_proxy_group_get_item (group, guide);
+
+ gimp_display_shell_expose_item (shell, item);
+
+ gimp_canvas_proxy_group_remove_item (group, guide);
+}
+
+static void
+gimp_display_shell_guide_move_handler (GimpImage *image,
+ GimpGuide *guide,
+ GimpDisplayShell *shell)
+{
+ GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->guides);
+ GimpCanvasItem *item;
+
+ item = gimp_canvas_proxy_group_get_item (group, guide);
+
+ gimp_display_shell_expose_item (shell, item);
+
+ g_object_set (item,
+ "orientation", gimp_guide_get_orientation (guide),
+ "position", gimp_guide_get_position (guide),
+ NULL);
+
+ gimp_display_shell_expose_item (shell, item);
}
static void
diff --git a/app/tools/gimpmeasuretool.c b/app/tools/gimpmeasuretool.c
index 4cd2288..8a2c36f 100644
--- a/app/tools/gimpmeasuretool.c
+++ b/app/tools/gimpmeasuretool.c
@@ -224,9 +224,8 @@ gimp_measure_tool_button_press (GimpTool *tool,
{
if (state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
{
- GimpGuide *guide;
- gboolean create_hguide;
- gboolean create_vguide;
+ gboolean create_hguide;
+ gboolean create_vguide;
create_hguide = ((state & GDK_CONTROL_MASK) &&
(measure->y[i] ==
@@ -240,32 +239,24 @@ gimp_measure_tool_button_press (GimpTool *tool,
0,
gimp_image_get_width (image))));
- if (create_hguide && create_vguide)
- gimp_image_undo_group_start (image,
- GIMP_UNDO_GROUP_GUIDE,
- _("Add Guides"));
-
- if (create_hguide)
+ if (create_hguide || create_vguide)
{
- guide = gimp_image_add_hguide (image,
- measure->y[i],
- TRUE);
- gimp_image_update_guide (image, guide);
- }
+ if (create_hguide && create_vguide)
+ gimp_image_undo_group_start (image,
+ GIMP_UNDO_GROUP_GUIDE,
+ _("Add Guides"));
- if (create_vguide)
- {
- guide = gimp_image_add_vguide (image,
- measure->x[i],
- TRUE);
- gimp_image_update_guide (image, guide);
- }
+ if (create_hguide)
+ gimp_image_add_hguide (image, measure->y[i], TRUE);
- if (create_hguide && create_vguide)
- gimp_image_undo_group_end (image);
+ if (create_vguide)
+ gimp_image_add_vguide (image, measure->x[i], TRUE);
- if (create_hguide || create_vguide)
- gimp_image_flush (image);
+ if (create_hguide && create_vguide)
+ gimp_image_undo_group_end (image);
+
+ gimp_image_flush (image);
+ }
measure->function = GUIDING;
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]