[gimp] app: port GimpMagnifyTool away from draw_tool_pause()/resume()



commit d96091d514a4fc4f8ffcaa87aadcf98b0500ca6a
Author: Michael Natterer <mitch gimp org>
Date:   Mon Mar 28 12:22:29 2011 +0200

    app: port GimpMagnifyTool away from draw_tool_pause()/resume()

 app/display/gimpcanvasrectangle.c |   21 +++++++++++++++++++++
 app/display/gimpcanvasrectangle.h |    6 ++++++
 app/tools/gimpmagnifytool.c       |   31 +++++++++++++++++++++++--------
 app/tools/gimpmagnifytool.h       |    8 +++++---
 4 files changed, 55 insertions(+), 11 deletions(-)
---
diff --git a/app/display/gimpcanvasrectangle.c b/app/display/gimpcanvasrectangle.c
index 55f7607..114eb63 100644
--- a/app/display/gimpcanvasrectangle.c
+++ b/app/display/gimpcanvasrectangle.c
@@ -340,3 +340,24 @@ gimp_canvas_rectangle_new (GimpDisplayShell *shell,
                        "filled", filled,
                        NULL);
 }
+
+void
+gimp_canvas_rectangle_set (GimpCanvasItem *rectangle,
+                           gdouble         x,
+                           gdouble         y,
+                           gdouble         width,
+                           gdouble         height)
+{
+  g_return_if_fail (GIMP_IS_CANVAS_RECTANGLE (rectangle));
+
+  gimp_canvas_item_begin_change (rectangle);
+
+  g_object_set (rectangle,
+                "x",      x,
+                "y",      y,
+                "width",  width,
+                "height", height,
+                NULL);
+
+  gimp_canvas_item_end_change (rectangle);
+}
diff --git a/app/display/gimpcanvasrectangle.h b/app/display/gimpcanvasrectangle.h
index 4eb78c1..f9f6ee5 100644
--- a/app/display/gimpcanvasrectangle.h
+++ b/app/display/gimpcanvasrectangle.h
@@ -56,5 +56,11 @@ GimpCanvasItem * gimp_canvas_rectangle_new      (GimpDisplayShell *shell,
                                                  gdouble           height,
                                                  gboolean          filled);
 
+void             gimp_canvas_rectangle_set      (GimpCanvasItem   *rectangle,
+                                                 gdouble           x,
+                                                 gdouble           y,
+                                                 gdouble           width,
+                                                 gdouble           height);
+
 
 #endif /* __GIMP_CANVAS_RECTANGLE_H__ */
diff --git a/app/tools/gimpmagnifytool.c b/app/tools/gimpmagnifytool.c
index 2a89094..57f78d9 100644
--- a/app/tools/gimpmagnifytool.c
+++ b/app/tools/gimpmagnifytool.c
@@ -29,6 +29,7 @@
 
 #include "widgets/gimphelp-ids.h"
 
+#include "display/gimpcanvasrectangle.h"
 #include "display/gimpdisplay.h"
 #include "display/gimpdisplayshell.h"
 #include "display/gimpdisplayshell-scale.h"
@@ -69,6 +70,8 @@ static void   gimp_magnify_tool_cursor_update  (GimpTool              *tool,
 
 static void   gimp_magnify_tool_draw           (GimpDrawTool          *draw_tool);
 
+static void   gimp_magnify_tool_update_items   (GimpMagnifyTool       *magnify);
+
 
 G_DEFINE_TYPE (GimpMagnifyTool, gimp_magnify_tool, GIMP_TYPE_DRAW_TOOL)
 
@@ -308,12 +311,10 @@ gimp_magnify_tool_motion (GimpTool         *tool,
 {
   GimpMagnifyTool *magnify = GIMP_MAGNIFY_TOOL (tool);
 
-  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
-
   magnify->w = coords->x - magnify->x;
   magnify->h = coords->y - magnify->y;
 
-  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+  gimp_magnify_tool_update_items (magnify);
 }
 
 static void
@@ -362,9 +363,23 @@ gimp_magnify_tool_draw (GimpDrawTool *draw_tool)
 {
   GimpMagnifyTool *magnify = GIMP_MAGNIFY_TOOL (draw_tool);
 
-  gimp_draw_tool_add_rectangle (draw_tool, FALSE,
-                                magnify->x,
-                                magnify->y,
-                                magnify->w,
-                                magnify->h);
+  magnify->rectangle =
+    gimp_draw_tool_add_rectangle (draw_tool, FALSE,
+                                  magnify->x,
+                                  magnify->y,
+                                  magnify->w,
+                                  magnify->h);
+}
+
+static void
+gimp_magnify_tool_update_items (GimpMagnifyTool *magnify)
+{
+  if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (magnify)))
+    {
+      gimp_canvas_rectangle_set (magnify->rectangle,
+                                 magnify->x,
+                                 magnify->y,
+                                 magnify->w,
+                                 magnify->h);
+    }
 }
diff --git a/app/tools/gimpmagnifytool.h b/app/tools/gimpmagnifytool.h
index bc9c70c..17ab99f 100644
--- a/app/tools/gimpmagnifytool.h
+++ b/app/tools/gimpmagnifytool.h
@@ -37,10 +37,12 @@ typedef struct _GimpMagnifyToolClass GimpMagnifyToolClass;
 
 struct _GimpMagnifyTool
 {
-  GimpDrawTool  parent_instance;
+  GimpDrawTool    parent_instance;
 
-  gdouble       x, y;  /*  upper left hand coordinate  */
-  gdouble       w, h;  /*  width and height            */
+  gdouble         x, y;  /*  upper left hand coordinate  */
+  gdouble         w, h;  /*  width and height            */
+
+  GimpCanvasItem *rectangle;
 };
 
 struct _GimpMagnifyToolClass



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