[gimp] app: add "x" and "y" properties to GimpCanvasPath



commit 99e0e73fc65eb5b1431dbd27e01027d971c23386
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 4 20:58:38 2011 +0200

    app: add "x" and "y" properties to GimpCanvasPath
    
    so paths can be rendered at any position. Pass 0,0 from all places
    that draw GimpVectors.

 app/display/gimpcanvaspath.c            |   40 +++++++++++++++++++++++++++++-
 app/display/gimpcanvaspath.h            |    2 +
 app/display/gimpdisplayshell-handlers.c |    1 +
 app/tools/gimpdrawtool.c                |    6 +++-
 app/tools/gimpdrawtool.h                |    4 ++-
 app/tools/gimpvectortool.c              |    2 +-
 6 files changed, 49 insertions(+), 6 deletions(-)
---
diff --git a/app/display/gimpcanvaspath.c b/app/display/gimpcanvaspath.c
index cb12067..389c30e 100644
--- a/app/display/gimpcanvaspath.c
+++ b/app/display/gimpcanvaspath.c
@@ -41,6 +41,8 @@ enum
 {
   PROP_0,
   PROP_PATH,
+  PROP_X,
+  PROP_Y,
   PROP_FILLED,
   PROP_PATH_STYLE
 };
@@ -51,6 +53,8 @@ typedef struct _GimpCanvasPathPrivate GimpCanvasPathPrivate;
 struct _GimpCanvasPathPrivate
 {
   cairo_path_t *path;
+  gdouble       x;
+  gdouble       y;
   gboolean      filled;
   gboolean      path_style;
 };
@@ -107,6 +111,18 @@ gimp_canvas_path_class_init (GimpCanvasPathClass *klass)
                                                        GIMP_TYPE_BEZIER_DESC,
                                                        GIMP_PARAM_READWRITE));
 
+  g_object_class_install_property (object_class, PROP_X,
+                                   g_param_spec_double ("x", NULL, NULL,
+                                                        -GIMP_MAX_IMAGE_SIZE,
+                                                        GIMP_MAX_IMAGE_SIZE, 0,
+                                                        GIMP_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class, PROP_Y,
+                                   g_param_spec_double ("y", NULL, NULL,
+                                                        -GIMP_MAX_IMAGE_SIZE,
+                                                        GIMP_MAX_IMAGE_SIZE, 0,
+                                                        GIMP_PARAM_READWRITE));
+
   g_object_class_install_property (object_class, PROP_FILLED,
                                    g_param_spec_boolean ("filled", NULL, NULL,
                                                          FALSE,
@@ -155,6 +171,12 @@ gimp_canvas_path_set_property (GObject      *object,
         gimp_bezier_desc_free (private->path);
       private->path = g_value_dup_boxed (value);
       break;
+    case PROP_X:
+      private->x = g_value_get_double (value);
+      break;
+    case PROP_Y:
+      private->y = g_value_get_double (value);
+      break;
     case PROP_FILLED:
       private->filled = g_value_get_boolean (value);
       break;
@@ -181,6 +203,12 @@ gimp_canvas_path_get_property (GObject    *object,
     case PROP_PATH:
       g_value_set_boxed (value, private->path);
       break;
+    case PROP_X:
+      g_value_set_double (value, private->x);
+      break;
+    case PROP_Y:
+      g_value_set_double (value, private->y);
+      break;
     case PROP_FILLED:
       g_value_set_boolean (value, private->filled);
       break;
@@ -204,7 +232,9 @@ gimp_canvas_path_draw (GimpCanvasItem   *item,
   if (private->path)
     {
       cairo_save (cr);
-      cairo_translate (cr, - shell->offset_x, - shell->offset_y);
+      cairo_translate (cr,
+                       - shell->offset_x + private->x,
+                       - shell->offset_y + private->y);
       cairo_scale (cr, shell->scale_x, shell->scale_y);
 
       cairo_append_path (cr, private->path);
@@ -232,7 +262,9 @@ gimp_canvas_path_get_extents (GimpCanvasItem   *item,
       cr = gdk_cairo_create (gtk_widget_get_window (shell->canvas));
 
       cairo_save (cr);
-      cairo_translate (cr, - shell->offset_x, - shell->offset_y);
+      cairo_translate (cr,
+                       - shell->offset_x + private->x,
+                       - shell->offset_y + private->y);
       cairo_scale (cr, shell->scale_x, shell->scale_y);
 
       cairo_append_path (cr, private->path);
@@ -289,6 +321,8 @@ gimp_canvas_path_stroke (GimpCanvasItem   *item,
 GimpCanvasItem *
 gimp_canvas_path_new (GimpDisplayShell     *shell,
                       const GimpBezierDesc *bezier,
+                      gdouble               x,
+                      gdouble               y,
                       gboolean              filled,
                       gboolean              path_style)
 {
@@ -297,6 +331,8 @@ gimp_canvas_path_new (GimpDisplayShell     *shell,
   return g_object_new (GIMP_TYPE_CANVAS_PATH,
                        "shell",      shell,
                        "path",       bezier,
+                       "x",          x,
+                       "y",          y,
                        "filled",     filled,
                        "path-style", path_style,
                        NULL);
diff --git a/app/display/gimpcanvaspath.h b/app/display/gimpcanvaspath.h
index 9bfe4d6..92a45bf 100644
--- a/app/display/gimpcanvaspath.h
+++ b/app/display/gimpcanvaspath.h
@@ -51,6 +51,8 @@ GType            gimp_canvas_path_get_type (void) G_GNUC_CONST;
 
 GimpCanvasItem * gimp_canvas_path_new      (GimpDisplayShell     *shell,
                                             const GimpBezierDesc *bezier,
+                                            gdouble               x,
+                                            gdouble               y,
                                             gboolean              filled,
                                             gboolean              path_style);
 
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index 904d7d6..b3e4983 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -875,6 +875,7 @@ gimp_display_shell_vectors_add_handler (GimpContainer    *container,
 
   item = gimp_canvas_path_new (shell,
                                gimp_vectors_get_bezier (vectors),
+                               0, 0,
                                FALSE,
                                TRUE);
   gimp_canvas_item_set_visible (item,
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index 73e96e2..c001221 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -749,7 +749,9 @@ gimp_draw_tool_add_strokes (GimpDrawTool     *draw_tool,
 
 GimpCanvasItem *
 gimp_draw_tool_add_path (GimpDrawTool         *draw_tool,
-                         const GimpBezierDesc *desc)
+                         const GimpBezierDesc *desc,
+                         gdouble               x,
+                         gdouble               y)
 {
   GimpCanvasItem *item;
 
@@ -757,7 +759,7 @@ gimp_draw_tool_add_path (GimpDrawTool         *draw_tool,
   g_return_val_if_fail (desc != NULL, NULL);
 
   item = gimp_canvas_path_new (gimp_display_get_shell (draw_tool->display),
-                               desc, FALSE, FALSE);
+                               desc, x, y, FALSE, FALSE);
 
   gimp_draw_tool_add_item (draw_tool, item);
   g_object_unref (item);
diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h
index 9bf8dc9..84765a3 100644
--- a/app/tools/gimpdrawtool.h
+++ b/app/tools/gimpdrawtool.h
@@ -167,7 +167,9 @@ GimpCanvasItem * gimp_draw_tool_add_strokes          (GimpDrawTool     *draw_too
                                                       gint              n_points,
                                                       gboolean          filled);
 GimpCanvasItem * gimp_draw_tool_add_path             (GimpDrawTool     *draw_tool,
-                                                      const GimpBezierDesc *desc);
+                                                      const GimpBezierDesc *desc,
+                                                      gdouble           x,
+                                                      gdouble           y);
 
 GimpCanvasItem * gimp_draw_tool_add_pen              (GimpDrawTool     *draw_tool,
                                                       const GimpVector2 *points,
diff --git a/app/tools/gimpvectortool.c b/app/tools/gimpvectortool.c
index 6ff526f..00aa97b 100644
--- a/app/tools/gimpvectortool.c
+++ b/app/tools/gimpvectortool.c
@@ -1413,7 +1413,7 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool)
 
   /* the stroke itself */
   if (! gimp_item_get_visible (GIMP_ITEM (vectors)))
-    gimp_draw_tool_add_path (draw_tool, gimp_vectors_get_bezier (vectors));
+    gimp_draw_tool_add_path (draw_tool, gimp_vectors_get_bezier (vectors), 0, 0);
 
   for (cur_stroke = gimp_vectors_stroke_get_next (vectors, NULL);
        cur_stroke;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]