gimp r25068 - in trunk: . app/tools



Author: martinn
Date: Sun Mar  9 10:40:42 2008
New Revision: 25068
URL: http://svn.gnome.org/viewvc/gimp?rev=25068&view=rev

Log:
2008-03-09  Martin Nordholts  <martinn svn gnome org>

	* app/tools/gimprectangletool.c
	(gimp_rectangle_tool_setup_snap_offsets): Make the GimpCoords used
	for snap calculations depend on the precision mode of the
	rectangle. This gives a more pleasant experience when resizing and
	moving the rectangle with image zoom factor larger than 100%.


Modified:
   trunk/ChangeLog
   trunk/app/tools/gimprectangletool.c

Modified: trunk/app/tools/gimprectangletool.c
==============================================================================
--- trunk/app/tools/gimprectangletool.c	(original)
+++ trunk/app/tools/gimprectangletool.c	Sun Mar  9 10:40:42 2008
@@ -313,6 +313,11 @@
                                                                gdouble                  *pub_y1,
                                                                gdouble                  *pub_x2,
                                                                gdouble                  *pub_y2);
+static void          gimp_rectangle_tool_adjust_coord         (GimpRectangleTool        *rect_tool,
+                                                               gdouble                   coord_x_input,
+                                                               gdouble                   coord_y_input,
+                                                               gdouble                  *coord_x_output,
+                                                               gdouble                  *coord_y_output);
 
 
 static guint gimp_rectangle_tool_signals[LAST_SIGNAL] = { 0 };
@@ -2990,12 +2995,16 @@
   GimpTool                 *tool;
   GimpRectangleToolPrivate *private;
   gdouble                   pub_x1, pub_y1, pub_x2, pub_y2;
+  gdouble                   pub_coord_x, pub_coord_y;
 
   tool    = GIMP_TOOL (rect_tool);
   private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
 
   gimp_rectangle_tool_get_public_rect (rect_tool,
                                        &pub_x1, &pub_y1, &pub_x2, &pub_y2);
+  gimp_rectangle_tool_adjust_coord (rect_tool,
+                                    coords->x, coords->y,
+                                    &pub_coord_x, &pub_coord_y);
 
   switch (private->function)
     {
@@ -3004,60 +3013,60 @@
 
     case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          pub_x1 - coords->x,
-                                          pub_y1 - coords->y,
+                                          pub_x1 - pub_coord_x,
+                                          pub_y1 - pub_coord_y,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          pub_x2 - coords->x,
-                                          pub_y1 - coords->y,
+                                          pub_x2 - pub_coord_x,
+                                          pub_y1 - pub_coord_y,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          pub_x1 - coords->x,
-                                          pub_y2 - coords->y,
+                                          pub_x1 - pub_coord_x,
+                                          pub_y2 - pub_coord_y,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          pub_x2 - coords->x,
-                                          pub_y2 - coords->y,
+                                          pub_x2 - pub_coord_x,
+                                          pub_y2 - pub_coord_y,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          pub_x1 - coords->x, 0,
+                                          pub_x1 - pub_coord_x, 0,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          pub_x2 - coords->x, 0,
+                                          pub_x2 - pub_coord_x, 0,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          0, pub_y1 - coords->y,
+                                          0, pub_y1 - pub_coord_y,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          0, pub_y2 - coords->y,
+                                          0, pub_y2 - pub_coord_y,
                                           0, 0);
       break;
 
     case GIMP_RECTANGLE_TOOL_MOVING:
       gimp_tool_control_set_snap_offsets (tool->control,
-                                          pub_x1 - coords->x,
-                                          pub_y1 - coords->y,
+                                          pub_x1 - pub_coord_x,
+                                          pub_y1 - pub_coord_y,
                                           pub_x2 - pub_x1,
                                           pub_y2 - pub_y1);
       break;
@@ -4070,3 +4079,40 @@
         break;
     }
 }
+
+/**
+ * gimp_rectangle_tool_adjust_coord:
+ * @rect_tool:
+ * @ccoord_x_input:
+ * @ccoord_x_input:
+ * @ccoord_x_output:
+ * @ccoord_x_output:
+ *
+ * Transforms a coordinate to better fit the public behaviour of the
+ * rectangle.
+ */
+static void
+gimp_rectangle_tool_adjust_coord (GimpRectangleTool *rect_tool,
+                                  gdouble            coord_x_input,
+                                  gdouble            coord_y_input,
+                                  gdouble           *coord_x_output,
+                                  gdouble           *coord_y_output)
+{
+  GimpRectangleToolPrivate *priv;
+
+  priv = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
+
+  switch (priv->precision)
+    {
+      case GIMP_RECTANGLE_PRECISION_INT:
+        *coord_x_output = ROUND (coord_x_input);
+        *coord_y_output = ROUND (coord_y_input);
+        break;
+
+      case GIMP_RECTANGLE_PRECISION_DOUBLE:
+      default:
+        *coord_x_output = coord_x_input;
+        *coord_y_output = coord_y_input;
+        break;
+    }
+}



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