[gimp] Move the straight line constrain code to GimpPaintCore.



commit 42b28066b8df10c543eb7a8df2cf31705257e54f
Author: Michael Natterer <mitch gimp org>
Date:   Wed Apr 22 21:22:08 2009 +0200

    Move the straight line constrain code to GimpPaintCore.
    
    * app/paint/gimppaintcore.[ch]: add gimp_paint_core_round_line()
    
    * app/tools/gimppainttool.c: remove gimp_paint_tool_round_line() and call
    above new function instead.
---
 app/paint/gimppaintcore.c |   38 ++++++++++++++++++++++++++++++++++++
 app/paint/gimppaintcore.h |    4 +++
 app/tools/gimppainttool.c |   47 +++-----------------------------------------
 3 files changed, 46 insertions(+), 43 deletions(-)

diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index b6b37a4..49732b1 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -22,6 +22,7 @@
 #include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpmath/gimpmath.h"
 
 #include "paint-types.h"
 
@@ -33,6 +34,7 @@
 #include "paint-funcs/paint-funcs.h"
 
 #include "core/gimp.h"
+#include "core/gimp-utils.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpimage.h"
 #include "core/gimpimage-undo.h"
@@ -572,6 +574,42 @@ gimp_paint_core_interpolate (GimpPaintCore    *core,
                                                  paint_options, time);
 }
 
+/**
+ * gimp_paint_core_round_line:
+ * @core:                 the #GimpPaintCore
+ * @options:              the #GimpPaintOptions to use
+ * @constrain_15_degrees: the modifier state
+ *
+ * Adjusts core->last_coords and core_cur_coords in preparation to
+ * drawing a straight line. If @center_pixels is TRUE the endpoints
+ * get pushed to the center of the pixels. This avoids artefacts
+ * for e.g. the hard mode. The rounding of the slope to 15 degree
+ * steps if ctrl is pressed happens, as does rounding the start and
+ * end coordinates (which may be fractional in high zoom modes) to
+ * the center of pixels.
+ **/
+void
+gimp_paint_core_round_line (GimpPaintCore    *core,
+                            GimpPaintOptions *paint_options,
+                            gboolean          constrain_15_degrees)
+{
+  g_return_if_fail (GIMP_IS_PAINT_CORE (core));
+  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
+
+  if (gimp_paint_options_get_brush_mode (paint_options) == GIMP_BRUSH_HARD)
+    {
+      core->last_coords.x = floor (core->last_coords.x) + 0.5;
+      core->last_coords.y = floor (core->last_coords.y) + 0.5;
+      core->cur_coords.x  = floor (core->cur_coords.x ) + 0.5;
+      core->cur_coords.y  = floor (core->cur_coords.y ) + 0.5;
+    }
+
+  if (constrain_15_degrees)
+    gimp_constrain_line (core->last_coords.x, core->last_coords.y,
+                         &core->cur_coords.x, &core->cur_coords.y,
+                         GIMP_CONSTRAIN_LINE_15_DEGREES);
+}
+
 
 /*  protected functions  */
 
diff --git a/app/paint/gimppaintcore.h b/app/paint/gimppaintcore.h
index 4b53cc2..524db7d 100644
--- a/app/paint/gimppaintcore.h
+++ b/app/paint/gimppaintcore.h
@@ -132,6 +132,10 @@ void      gimp_paint_core_interpolate               (GimpPaintCore    *core,
                                                      GimpPaintOptions *paint_options,
                                                      guint32           time);
 
+void      gimp_paint_core_round_line                (GimpPaintCore    *core,
+                                                     GimpPaintOptions *options,
+                                                     gboolean          constrain_15_degrees);
+
 
 /*  protected functions  */
 
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index 48cb206..a556f8b 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -241,39 +241,6 @@ gimp_paint_tool_control (GimpTool       *tool,
   GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
 }
 
-/**
- * gimp_paint_tool_round_line:
- * @core:          the #GimpPaintCore
- * @center_pixels: push coordinates to pixel centers?
- * @state:         the modifier state
- *
- * Adjusts core->last_coords and core_cur_coords in preparation to
- * drawing a straight line. If @center_pixels is TRUE the endpoints
- * get pushed to the center of the pixels. This avoids artefacts
- * for e.g. the hard mode. The rounding of the slope to 15 degree
- * steps if ctrl is pressed happens, as does rounding the start and
- * end coordinates (which may be fractional in high zoom modes) to
- * the center of pixels.
- **/
-static void
-gimp_paint_tool_round_line (GimpPaintCore   *core,
-                            gboolean         center_pixels,
-                            GdkModifierType  state)
-{
-  if (center_pixels)
-    {
-      core->last_coords.x = floor (core->last_coords.x) + 0.5;
-      core->last_coords.y = floor (core->last_coords.y) + 0.5;
-      core->cur_coords.x  = floor (core->cur_coords.x ) + 0.5;
-      core->cur_coords.y  = floor (core->cur_coords.y ) + 0.5;
-    }
-
-  if (state & GDK_CONTROL_MASK)
-    gimp_constrain_line (core->last_coords.x, core->last_coords.y,
-                         &core->cur_coords.x, &core->cur_coords.y,
-                         GIMP_CONSTRAIN_LINE_15_DEGREES);
-}
-
 static void
 gimp_paint_tool_button_press (GimpTool         *tool,
                               const GimpCoords *coords,
@@ -345,14 +312,10 @@ gimp_paint_tool_button_press (GimpTool         *tool,
       /*  If shift is down and this is not the first paint
        *  stroke, then draw a line from the last coords to the pointer
        */
-      gboolean hard;
-
-      hard = (gimp_paint_options_get_brush_mode (paint_options) ==
-              GIMP_BRUSH_HARD);
-
       core->start_coords = core->last_coords;
 
-      gimp_paint_tool_round_line (core, hard, state);
+      gimp_paint_core_round_line (core, paint_options,
+                                  (state & GDK_CONTROL_MASK) != 0);
     }
 
   /*  chain up to activate the tool  */
@@ -584,7 +547,6 @@ gimp_paint_tool_oper_update (GimpTool         *tool,
           gchar    *status_help;
           gdouble   dx, dy, dist;
           gint      off_x, off_y;
-          gboolean  hard;
 
           core->cur_coords = *coords;
 
@@ -593,9 +555,8 @@ gimp_paint_tool_oper_update (GimpTool         *tool,
           core->cur_coords.x -= off_x;
           core->cur_coords.y -= off_y;
 
-          hard = (gimp_paint_options_get_brush_mode (paint_options) ==
-                  GIMP_BRUSH_HARD);
-          gimp_paint_tool_round_line (core, hard, state);
+          gimp_paint_core_round_line (core, paint_options,
+                                      (state & GDK_CONTROL_MASK) != 0);
 
           dx = core->cur_coords.x - core->last_coords.x;
           dy = core->cur_coords.y - core->last_coords.y;



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