[gimp] app: port sample point drawing to GimpCanvasItems
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: port sample point drawing to GimpCanvasItems
- Date: Fri, 1 Oct 2010 07:28:51 +0000 (UTC)
commit 0c613ba87d7e976101c1118346ffaec374ab758c
Author: Michael Natterer <mitch gimp org>
Date: Fri Oct 1 09:15:52 2010 +0200
app: port sample point drawing to GimpCanvasItems
- Add GimpImage signal "sample-point-moved" and emit it when needed
- Let the shell connect to the sample point add, remove and move signals
and update the canvas items accordingly
- Remove gimp_display_shell_draw_sample_points()
app/core/gimpimage-sample-points.c | 8 ++-
app/core/gimpimage.c | 23 ++++++
app/core/gimpimage.h | 4 +
app/core/gimpsamplepointundo.c | 3 +
app/display/gimpdisplayshell-callbacks.c | 7 +--
app/display/gimpdisplayshell-draw.c | 50 ------------
app/display/gimpdisplayshell-draw.h | 2 -
app/display/gimpdisplayshell-handlers.c | 128 +++++++++++++++++++++++++++---
8 files changed, 155 insertions(+), 70 deletions(-)
---
diff --git a/app/core/gimpimage-sample-points.c b/app/core/gimpimage-sample-points.c
index 4095ebf..9bb8e0d 100644
--- a/app/core/gimpimage-sample-points.c
+++ b/app/core/gimpimage-sample-points.c
@@ -98,7 +98,8 @@ gimp_image_remove_sample_point (GimpImage *image,
gimp_image_update_sample_point (image, sample_point);
if (push_undo)
- gimp_image_undo_push_sample_point (image, C_("undo-type", "Remove Sample Point"),
+ gimp_image_undo_push_sample_point (image,
+ C_("undo-type", "Remove Sample Point"),
sample_point);
list = g_list_find (private->sample_points, sample_point);
@@ -135,13 +136,16 @@ gimp_image_move_sample_point (GimpImage *image,
g_return_if_fail (y < gimp_image_get_height (image));
if (push_undo)
- gimp_image_undo_push_sample_point (image, C_("undo-type", "Move Sample Point"),
+ gimp_image_undo_push_sample_point (image,
+ C_("undo-type", "Move Sample Point"),
sample_point);
gimp_image_update_sample_point (image, sample_point);
sample_point->x = x;
sample_point->y = y;
gimp_image_update_sample_point (image, sample_point);
+
+ gimp_image_sample_point_moved (image, sample_point);
}
GList *
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 4a4b5d8..cd7cdb2 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -105,6 +105,7 @@ enum
UPDATE_VECTORS,
SAMPLE_POINT_ADDED,
SAMPLE_POINT_REMOVED,
+ SAMPLE_POINT_MOVED,
PARASITE_ATTACHED,
PARASITE_DETACHED,
COLORMAP_CHANGED,
@@ -472,6 +473,16 @@ gimp_image_class_init (GimpImageClass *klass)
G_TYPE_NONE, 1,
G_TYPE_POINTER);
+ gimp_image_signals[SAMPLE_POINT_MOVED] =
+ g_signal_new ("sample-point-moved",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpImageClass, sample_point_moved),
+ NULL, NULL,
+ gimp_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
gimp_image_signals[PARASITE_ATTACHED] =
g_signal_new ("parasite-attached",
G_TYPE_FROM_CLASS (klass),
@@ -556,6 +567,7 @@ gimp_image_class_init (GimpImageClass *klass)
klass->update_vectors = NULL;
klass->sample_point_added = NULL;
klass->sample_point_removed = NULL;
+ klass->sample_point_moved = NULL;
klass->parasite_attached = NULL;
klass->parasite_detached = NULL;
klass->colormap_changed = gimp_image_real_colormap_changed;
@@ -2143,6 +2155,17 @@ gimp_image_sample_point_removed (GimpImage *image,
sample_point);
}
+void
+gimp_image_sample_point_moved (GimpImage *image,
+ GimpSamplePoint *sample_point)
+{
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+ g_return_if_fail (sample_point != NULL);
+
+ g_signal_emit (image, gimp_image_signals[SAMPLE_POINT_MOVED], 0,
+ sample_point);
+}
+
/**
* gimp_image_size_changed_detailed:
* @image:
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 36c9828..5133997 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -141,6 +141,8 @@ struct _GimpImageClass
GimpSamplePoint *sample_point);
void (* sample_point_removed) (GimpImage *image,
GimpSamplePoint *sample_point);
+ void (* sample_point_moved) (GimpImage *image,
+ GimpSamplePoint *sample_point);
void (* parasite_attached) (GimpImage *image,
const gchar *name);
void (* parasite_detached) (GimpImage *image,
@@ -260,6 +262,8 @@ void gimp_image_sample_point_added (GimpImage *image,
GimpSamplePoint *sample_point);
void gimp_image_sample_point_removed (GimpImage *image,
GimpSamplePoint *sample_point);
+void gimp_image_sample_point_moved (GimpImage *image,
+ GimpSamplePoint *sample_point);
void gimp_image_colormap_changed (GimpImage *image,
gint col);
void gimp_image_selection_control (GimpImage *image,
diff --git a/app/core/gimpsamplepointundo.c b/app/core/gimpsamplepointundo.c
index 7068791..bfb5736 100644
--- a/app/core/gimpsamplepointundo.c
+++ b/app/core/gimpsamplepointundo.c
@@ -177,6 +177,9 @@ gimp_sample_point_undo_pop (GimpUndo *undo,
sample_point_undo->sample_point->y = sample_point_undo->y;
gimp_image_update_sample_point (undo->image,
sample_point_undo->sample_point);
+
+ gimp_image_sample_point_moved (undo->image,
+ sample_point_undo->sample_point);
}
sample_point_undo->x = x;
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index 835acec..ccf95d0 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -2345,12 +2345,7 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
gimp_display_shell_draw_guides (shell, cr);
cairo_restore (cr);
- /* draw the sample points */
- cairo_save (cr);
- gimp_display_shell_draw_sample_points (shell, cr);
- cairo_restore (cr);
-
- /* draw tool items */
+ /* draw canvas items */
cairo_save (cr);
gimp_canvas_item_draw (shell->canvas_item, shell, cr);
cairo_restore (cr);
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index e4c506e..dcedf62 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -37,9 +37,7 @@
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
#include "core/gimpimage-guides.h"
-#include "core/gimpimage-sample-points.h"
#include "core/gimpprojection.h"
-#include "core/gimpsamplepoint.h"
#include "vectors/gimpstroke.h"
#include "vectors/gimpvectors.h"
@@ -49,7 +47,6 @@
#include "gimpcanvas.h"
#include "gimpcanvasguide.h"
-#include "gimpcanvassamplepoint.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"
@@ -392,53 +389,6 @@ gimp_display_shell_draw_pen (GimpDisplayShell *shell,
}
void
-gimp_display_shell_draw_sample_points (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_sample_points (shell))
- {
- GimpCanvasItem *item;
- GList *list;
-
- item = gimp_canvas_sample_point_new (0, 0, 0);
- g_object_set (item, "sample-point-style", TRUE, NULL);
-
- for (list = gimp_image_get_sample_points (image);
- list;
- list = g_list_next (list))
- {
- GimpSamplePoint *sample_point = list->data;
-
- if (sample_point->x >= 0 &&
- sample_point->y >= 0)
- {
- gint index;
-
- index = g_list_index (gimp_image_get_sample_points (image),
- sample_point) + 1;
-
- g_object_set (item,
- "x", sample_point->x,
- "y", sample_point->y,
- "index", index,
- NULL);
-
- gimp_canvas_item_draw (item, shell, cr);
- }
- }
-
- g_object_unref (item);
- }
-}
-
-void
gimp_display_shell_draw_layer_boundary (GimpDisplayShell *shell,
cairo_t *cr,
GimpDrawable *drawable,
diff --git a/app/display/gimpdisplayshell-draw.h b/app/display/gimpdisplayshell-draw.h
index d6028cb..4199264 100644
--- a/app/display/gimpdisplayshell-draw.h
+++ b/app/display/gimpdisplayshell-draw.h
@@ -38,8 +38,6 @@ void gimp_display_shell_draw_pen (GimpDisplayShell *shell,
GimpContext *context,
GimpActiveColor color,
gint width);
-void gimp_display_shell_draw_sample_points (GimpDisplayShell *shell,
- cairo_t *cr);
void gimp_display_shell_draw_layer_boundary (GimpDisplayShell *shell,
cairo_t *cr,
GimpDrawable *drawable,
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index 1e9f8c5..2184b4a 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -35,6 +35,7 @@
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
#include "core/gimpimage-quick-mask.h"
+#include "core/gimpimage-sample-points.h"
#include "core/gimpitem.h"
#include "core/gimpsamplepoint.h"
#include "core/gimptreehandler.h"
@@ -44,6 +45,7 @@
#include "widgets/gimpwidgets-utils.h"
#include "gimpcanvasguide.h"
+#include "gimpcanvasproxygroup.h"
#include "gimpcanvassamplepoint.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
@@ -94,7 +96,13 @@ static void gimp_display_shell_quick_mask_changed_handler (GimpImage *i
static void gimp_display_shell_update_guide_handler (GimpImage *image,
GimpGuide *guide,
GimpDisplayShell *shell);
-static void gimp_display_shell_update_sample_point_handler(GimpImage *image,
+static void gimp_display_shell_sample_point_add_handler (GimpImage *image,
+ GimpSamplePoint *sample_point,
+ GimpDisplayShell *shell);
+static void gimp_display_shell_sample_point_remove_handler(GimpImage *image,
+ GimpSamplePoint *sample_point,
+ GimpDisplayShell *shell);
+static void gimp_display_shell_sample_point_move_handler (GimpImage *image,
GimpSamplePoint *sample_point,
GimpDisplayShell *shell);
static void gimp_display_shell_update_vectors_handler (GimpImage *image,
@@ -143,6 +151,7 @@ void
gimp_display_shell_connect (GimpDisplayShell *shell)
{
GimpImage *image;
+ GList *list;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (GIMP_IS_DISPLAY (shell->display));
@@ -181,9 +190,23 @@ gimp_display_shell_connect (GimpDisplayShell *shell)
g_signal_connect (image, "update-guide",
G_CALLBACK (gimp_display_shell_update_guide_handler),
shell);
- g_signal_connect (image, "update-sample-point",
- G_CALLBACK (gimp_display_shell_update_sample_point_handler),
+
+ g_signal_connect (image, "sample-point-added",
+ G_CALLBACK (gimp_display_shell_sample_point_add_handler),
+ shell);
+ g_signal_connect (image, "sample-point-removed",
+ G_CALLBACK (gimp_display_shell_sample_point_remove_handler),
+ shell);
+ g_signal_connect (image, "sample-point-moved",
+ G_CALLBACK (gimp_display_shell_sample_point_move_handler),
shell);
+ for (list = gimp_image_get_sample_points (image);
+ list;
+ list = g_list_next (list))
+ {
+ gimp_display_shell_sample_point_add_handler (image, list->data, shell);
+ }
+
g_signal_connect (image, "update-vectors",
G_CALLBACK (gimp_display_shell_update_vectors_handler),
shell);
@@ -273,6 +296,7 @@ void
gimp_display_shell_disconnect (GimpDisplayShell *shell)
{
GimpImage *image;
+ GList *list;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (GIMP_IS_DISPLAY (shell->display));
@@ -327,10 +351,25 @@ gimp_display_shell_disconnect (GimpDisplayShell *shell)
g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_update_guide_handler,
shell);
+
g_signal_handlers_disconnect_by_func (image,
- gimp_display_shell_update_sample_point_handler,
+ gimp_display_shell_sample_point_add_handler,
shell);
g_signal_handlers_disconnect_by_func (image,
+ gimp_display_shell_sample_point_remove_handler,
+ shell);
+ g_signal_handlers_disconnect_by_func (image,
+ gimp_display_shell_sample_point_move_handler,
+ shell);
+ for (list = gimp_image_get_sample_points (image);
+ list;
+ list = g_list_next (list))
+ {
+ gimp_canvas_proxy_group_remove_item (GIMP_CANVAS_PROXY_GROUP (shell->sample_points),
+ list->data);
+ }
+
+ g_signal_handlers_disconnect_by_func (image,
gimp_display_shell_update_vectors_handler,
shell);
g_signal_handlers_disconnect_by_func (image,
@@ -479,20 +518,89 @@ gimp_display_shell_update_guide_handler (GimpImage *image,
}
static void
-gimp_display_shell_update_sample_point_handler (GimpImage *image,
- GimpSamplePoint *sample_point,
- GimpDisplayShell *shell)
+gimp_display_shell_sample_point_add_handler (GimpImage *image,
+ GimpSamplePoint *sample_point,
+ GimpDisplayShell *shell)
{
- GimpCanvasItem *item;
+ GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->sample_points);
+ GimpCanvasItem *item;
+ GList *list;
+ gint i;
item = gimp_canvas_sample_point_new (sample_point->x,
sample_point->y,
- 0 /* eek */);
+ 0);
g_object_set (item, "sample-point-style", TRUE, NULL);
+ gimp_canvas_proxy_group_add_item (group, sample_point, item);
+ g_object_unref (item);
+
+ for (list = gimp_image_get_sample_points (image), i = 1;
+ list;
+ list = g_list_next (list), i++)
+ {
+ GimpSamplePoint *sample_point = list->data;
+
+ item = gimp_canvas_proxy_group_get_item (group, sample_point);
+
+ g_object_set (item,
+ "index", i,
+ NULL);
+
+ gimp_display_shell_expose_item (shell, item);
+ }
+}
+
+static void
+gimp_display_shell_sample_point_remove_handler (GimpImage *image,
+ GimpSamplePoint *sample_point,
+ GimpDisplayShell *shell)
+{
+ GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->sample_points);
+ GimpCanvasItem *item;
+ GList *list;
+ gint i;
+
+ item = gimp_canvas_proxy_group_get_item (group, sample_point);
+
gimp_display_shell_expose_item (shell, item);
- g_object_unref (item);
+ gimp_canvas_proxy_group_remove_item (group, sample_point);
+
+ for (list = gimp_image_get_sample_points (image), i = 1;
+ list;
+ list = g_list_next (list), i++)
+ {
+ GimpSamplePoint *sample_point = list->data;
+
+ item = gimp_canvas_proxy_group_get_item (group, sample_point);
+
+ g_object_set (item,
+ "index", i,
+ NULL);
+
+ gimp_display_shell_expose_item (shell, item);
+ }
+}
+
+static void
+gimp_display_shell_sample_point_move_handler (GimpImage *image,
+ GimpSamplePoint *sample_point,
+ GimpDisplayShell *shell)
+{
+ GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->sample_points);
+ GimpCanvasItem *item;
+
+ item = gimp_canvas_proxy_group_get_item (group, sample_point);
+
+ gimp_display_shell_expose_item (shell, item);
+
+ g_object_set (item,
+ "x", sample_point->x,
+ "y", sample_point->y,
+ NULL);
+
+ gimp_display_shell_expose_item (shell, item);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]