gimp r24622 - in trunk: . app/tools



Author: martinn
Date: Tue Jan 15 20:01:39 2008
New Revision: 24622
URL: http://svn.gnome.org/viewvc/gimp?rev=24622&view=rev

Log:
2008-01-15  Martin Nordholts  <martinn svn gnome org>

	* app/tools/gimpeditselectiontool.[ch]: Made it possible to
	constrain movement with the Move Tool in 45 degree angles by
	holding Ctrl when a move has been initiated. This fixes the
	essential part of bug #78730.


Modified:
   trunk/ChangeLog
   trunk/app/tools/gimpeditselectiontool.c
   trunk/app/tools/gimpeditselectiontool.h

Modified: trunk/app/tools/gimpeditselectiontool.c
==============================================================================
--- trunk/app/tools/gimpeditselectiontool.c	(original)
+++ trunk/app/tools/gimpeditselectiontool.c	Tue Jan 15 20:01:39 2008
@@ -55,6 +55,7 @@
 #include "gimpeditselectiontool.h"
 #include "gimptoolcontrol.h"
 #include "tool_manager.h"
+#include "tools-utils.h"
 
 #include "gimp-intl.h"
 
@@ -62,20 +63,30 @@
 #define EDIT_SELECT_SCROLL_LOCK FALSE
 #define ARROW_VELOCITY          25
 
-
-static void   gimp_edit_selection_tool_button_release (GimpTool              *tool,
-                                                       GimpCoords            *coords,
-                                                       guint32                time,
-                                                       GdkModifierType        state,
-                                                       GimpButtonReleaseType  release_type,
-                                                       GimpDisplay           *display);
-static void   gimp_edit_selection_tool_motion         (GimpTool              *tool,
-                                                       GimpCoords            *coords,
-                                                       guint32                time,
-                                                       GdkModifierType        state,
-                                                       GimpDisplay           *display);
-
-static void   gimp_edit_selection_tool_draw           (GimpDrawTool          *tool);
+/**
+ * The number of evenly distributed lines onto which moving will be
+ * constrained when movement constraint is active.
+ */
+#define N_SNAP_LINES            4
+
+
+static void    gimp_edit_selection_tool_button_release      (GimpTool              *tool,
+                                                             GimpCoords            *coords,
+                                                             guint32                time,
+                                                             GdkModifierType        state,
+                                                             GimpButtonReleaseType  release_type,
+                                                             GimpDisplay           *display);
+static void    gimp_edit_selection_tool_motion              (GimpTool              *tool,
+                                                             GimpCoords            *coords,
+                                                             guint32                time,
+                                                             GdkModifierType        state,
+                                                             GimpDisplay           *display);
+static void    gimp_edit_selection_tool_active_modifier_key (GimpTool              *tool,
+                                                             GdkModifierType        key,
+                                                             gboolean               press,
+                                                             GdkModifierType        state,
+                                                             GimpDisplay           *display);
+static void    gimp_edit_selection_tool_draw                (GimpDrawTool          *tool);
 
 
 G_DEFINE_TYPE (GimpEditSelectionTool, gimp_edit_selection_tool,
@@ -87,13 +98,14 @@
 static void
 gimp_edit_selection_tool_class_init (GimpEditSelectionToolClass *klass)
 {
-  GimpToolClass     *tool_class = GIMP_TOOL_CLASS (klass);
-  GimpDrawToolClass *draw_class = GIMP_DRAW_TOOL_CLASS (klass);
+  GimpToolClass     *tool_class   = GIMP_TOOL_CLASS (klass);
+  GimpDrawToolClass *draw_class   = GIMP_DRAW_TOOL_CLASS (klass);
 
-  tool_class->button_release = gimp_edit_selection_tool_button_release;
-  tool_class->motion         = gimp_edit_selection_tool_motion;
+  tool_class->button_release      = gimp_edit_selection_tool_button_release;
+  tool_class->motion              = gimp_edit_selection_tool_motion;
+  tool_class->active_modifier_key = gimp_edit_selection_tool_active_modifier_key;
 
-  draw_class->draw           = gimp_edit_selection_tool_draw;
+  draw_class->draw                = gimp_edit_selection_tool_draw;
 }
 
 static void
@@ -111,6 +123,8 @@
   edit_selection_tool->cumly      = 0;
 
   edit_selection_tool->first_move = TRUE;
+
+  edit_selection_tool->constrain  = FALSE;
 }
 
 static void
@@ -207,6 +221,12 @@
   edit_select->x = edit_select->origx = coords->x - off_x;
   edit_select->y = edit_select->origy = coords->y - off_y;
 
+  /* Remember starting point for use in constrained movement */
+  edit_select->start_x = coords->x;
+  edit_select->start_y = coords->y;
+
+  edit_select->constrain = FALSE;
+
   switch (edit_select->edit_mode)
     {
     case GIMP_TRANSLATE_MODE_CHANNEL:
@@ -542,6 +562,13 @@
 
   gimp_item_offsets (active_item, &off_x, &off_y);
 
+  if (edit_select->constrain)
+    {
+      gimp_tool_motion_constrain (edit_select->start_x, edit_select->start_y,
+                                  &coords->x, &coords->y,
+                                  N_SNAP_LINES);
+    }
+
   motion_x = coords->x - off_x;
   motion_y = coords->y - off_y;
 
@@ -677,6 +704,18 @@
 }
 
 static void
+gimp_edit_selection_tool_active_modifier_key (GimpTool        *tool,
+                                              GdkModifierType  key,
+                                              gboolean         press,
+                                              GdkModifierType  state,
+                                              GimpDisplay     *display)
+{
+  GimpEditSelectionTool *edit_select = GIMP_EDIT_SELECTION_TOOL (tool);
+
+  edit_select->constrain = state & GDK_CONTROL_MASK ? TRUE : FALSE;
+}
+
+static void
 gimp_edit_selection_tool_draw (GimpDrawTool *draw_tool)
 {
   GimpEditSelectionTool *edit_select = GIMP_EDIT_SELECTION_TOOL (draw_tool);

Modified: trunk/app/tools/gimpeditselectiontool.h
==============================================================================
--- trunk/app/tools/gimpeditselectiontool.h	(original)
+++ trunk/app/tools/gimpeditselectiontool.h	Tue Jan 15 20:01:39 2008
@@ -53,6 +53,9 @@
   gboolean            first_move;      /*  Don't push undos after the first  */
 
   gboolean            propagate_release;
+
+  gboolean            constrain;       /*  Constrain the movement            */
+  gdouble             start_x, start_y;/*  Coords when button was pressed    */
 };
 
 struct _GimpEditSelectionToolClass



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