[gimp/soc-2010-cage-2] app: use the new shifting API instead of reimplementing it



commit bd08507e66ce21aa637bbd53115a40b554b465ee
Author: Michael Natterer <mitch gimp org>
Date:   Tue Nov 9 11:32:40 2010 +0100

    app: use the new shifting API instead of reimplementing it

 app/tools/gimpdrawtool.c |  161 +++-------------------------------------------
 1 files changed, 9 insertions(+), 152 deletions(-)
---
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index 51b8c86..6663847 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -39,6 +39,7 @@
 #include "display/gimpcanvasgroup.h"
 #include "display/gimpcanvasguide.h"
 #include "display/gimpcanvashandle.h"
+#include "display/gimpcanvasitem-utils.h"
 #include "display/gimpcanvasline.h"
 #include "display/gimpcanvaspath.h"
 #include "display/gimpcanvaspen.h"
@@ -73,23 +74,6 @@ static void          gimp_draw_tool_draw         (GimpDrawTool     *draw_tool);
 static void          gimp_draw_tool_undraw       (GimpDrawTool     *draw_tool);
 static void          gimp_draw_tool_real_draw    (GimpDrawTool     *draw_tool);
 
-static inline void   gimp_draw_tool_shift_to_north_west
-                                                 (gdouble           x,
-                                                  gdouble           y,
-                                                  gint              handle_width,
-                                                  gint              handle_height,
-                                                  GimpHandleAnchor  anchor,
-                                                  gdouble          *shifted_x,
-                                                  gdouble          *shifted_y);
-static inline void   gimp_draw_tool_shift_to_center
-                                                 (gdouble           x,
-                                                  gdouble           y,
-                                                  gint              handle_width,
-                                                  gint              handle_height,
-                                                  GimpHandleAnchor  anchor,
-                                                  gdouble          *shifted_x,
-                                                  gdouble          *shifted_y);
-
 
 G_DEFINE_TYPE (GimpDrawTool, gimp_draw_tool, GIMP_TYPE_TOOL)
 
@@ -886,20 +870,20 @@ gimp_draw_tool_on_handle (GimpDrawTool     *draw_tool,
     case GIMP_HANDLE_SQUARE:
     case GIMP_HANDLE_FILLED_SQUARE:
     case GIMP_HANDLE_CROSS:
-      gimp_draw_tool_shift_to_north_west (handle_tx, handle_ty,
-                                          width, height,
-                                          anchor,
-                                          &handle_tx, &handle_ty);
+      gimp_canvas_item_shift_to_north_west (anchor,
+                                            handle_tx, handle_ty,
+                                            width, height,
+                                            &handle_tx, &handle_ty);
 
       return (tx == CLAMP (tx, handle_tx, handle_tx + width) &&
               ty == CLAMP (ty, handle_ty, handle_ty + height));
 
     case GIMP_HANDLE_CIRCLE:
     case GIMP_HANDLE_FILLED_CIRCLE:
-      gimp_draw_tool_shift_to_center (handle_tx, handle_ty,
-                                      width, height,
-                                      anchor,
-                                      &handle_tx, &handle_ty);
+      gimp_canvas_item_shift_to_center (anchor,
+                                        handle_tx, handle_ty,
+                                        width, height,
+                                        &handle_tx, &handle_ty);
 
       /* FIXME */
       if (width != height)
@@ -1160,130 +1144,3 @@ gimp_draw_tool_on_vectors (GimpDrawTool      *draw_tool,
 
   return FALSE;
 }
-
-
-/*  private functions  */
-
-static inline void
-gimp_draw_tool_shift_to_north_west (gdouble           x,
-                                    gdouble           y,
-                                    gint              handle_width,
-                                    gint              handle_height,
-                                    GimpHandleAnchor  anchor,
-                                    gdouble          *shifted_x,
-                                    gdouble          *shifted_y)
-{
-  switch (anchor)
-    {
-    case GIMP_HANDLE_ANCHOR_CENTER:
-      x -= (handle_width >> 1);
-      y -= (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_NORTH:
-      x -= (handle_width >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_NORTH_WEST:
-      /*  nothing, this is the default  */
-      break;
-
-    case GIMP_HANDLE_ANCHOR_NORTH_EAST:
-      x -= handle_width;
-      break;
-
-    case GIMP_HANDLE_ANCHOR_SOUTH:
-      x -= (handle_width >> 1);
-      y -= handle_height;
-      break;
-
-    case GIMP_HANDLE_ANCHOR_SOUTH_WEST:
-      y -= handle_height;
-      break;
-
-    case GIMP_HANDLE_ANCHOR_SOUTH_EAST:
-      x -= handle_width;
-      y -= handle_height;
-      break;
-
-    case GIMP_HANDLE_ANCHOR_WEST:
-      y -= (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_EAST:
-      x -= handle_width;
-      y -= (handle_height >> 1);
-      break;
-
-    default:
-      break;
-    }
-
-  if (shifted_x)
-    *shifted_x = x;
-
-  if (shifted_y)
-    *shifted_y = y;
-}
-
-static inline void
-gimp_draw_tool_shift_to_center (gdouble           x,
-                                gdouble           y,
-                                gint              handle_width,
-                                gint              handle_height,
-                                GimpHandleAnchor  anchor,
-                                gdouble          *shifted_x,
-                                gdouble          *shifted_y)
-{
-  switch (anchor)
-    {
-    case GIMP_HANDLE_ANCHOR_CENTER:
-      /*  nothing, this is the default  */
-      break;
-
-    case GIMP_HANDLE_ANCHOR_NORTH:
-      y += (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_NORTH_WEST:
-      x += (handle_width >> 1);
-      y += (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_NORTH_EAST:
-      x -= (handle_width >> 1);
-      y += (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_SOUTH:
-      y -= (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_SOUTH_WEST:
-      x += (handle_width >> 1);
-      y -= (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_SOUTH_EAST:
-      x -= (handle_width >> 1);
-      y -= (handle_height >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_WEST:
-      x += (handle_width >> 1);
-      break;
-
-    case GIMP_HANDLE_ANCHOR_EAST:
-      x -= (handle_width >> 1);
-      break;
-
-    default:
-      break;
-    }
-
-  if (shifted_x)
-    *shifted_x = x;
-
-  if (shifted_y)
-    *shifted_y = y;
-}



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