[gimp] Bug 668016 - Accidentally clicking ruler loses active tool's state



commit 7889ec08f7c2bd119ddbdc8982272597e340721a
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 3 16:27:41 2016 +0200

    Bug 668016 - Accidentally clicking ruler loses active tool's state
    
    Add two new tools, GimpGuideTool and GimpSamplePointTool. They are
    one-trick-ponies and can only create new or move existing guides and
    sample points. They can't be selected from the toolbox, only
    temporarily pushed as active tools on top of any active tool using
    their public start() APIs.
    
    Use that API to enable them when the rulers are clicked, and replace
    the entire guide and sample point moving code in GimpMoveTool and
    GimpColorTool by simple calls to that API.
    
    This might look like overkill but can easily be used for other
    features like moving guides from within the paint tools (mirror
    painting) or gegl filters (preview curtain).

 app/display/gimpdisplayshell-tool-events.c |   60 ++---
 app/tools/Makefile.am                      |    4 +
 app/tools/gimpcolortool.c                  |  225 +---------------
 app/tools/gimpcolortool.h                  |   16 +-
 app/tools/gimpguidetool.c                  |  390 ++++++++++++++++++++++++++++
 app/tools/gimpguidetool.h                  |   61 +++++
 app/tools/gimpmovetool.c                   |  324 ++---------------------
 app/tools/gimpmovetool.h                   |    4 -
 app/tools/gimpsamplepointtool.c            |  348 +++++++++++++++++++++++++
 app/tools/gimpsamplepointtool.h            |   60 +++++
 po/POTFILES.in                             |    2 +
 11 files changed, 925 insertions(+), 569 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index 8a00bc7..fc811b5 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -43,9 +43,9 @@
 #include "widgets/gimpuimanager.h"
 #include "widgets/gimpwidgets-utils.h"
 
-#include "tools/gimpimagemaptool.h"
+#include "tools/gimpguidetool.h"
 #include "tools/gimpmovetool.h"
-#include "tools/gimppainttool.h"
+#include "tools/gimpsamplepointtool.h"
 #include "tools/gimptoolcontrol.h"
 #include "tools/tool_manager.h"
 
@@ -1278,10 +1278,10 @@ gimp_display_shell_buffer_hover (GimpMotionBuffer *buffer,
 }
 
 static gboolean
-gimp_display_shell_ruler_button_press (GtkWidget        *widget,
-                                       GdkEventButton   *event,
-                                       GimpDisplayShell *shell,
-                                       gboolean          horizontal)
+gimp_display_shell_ruler_button_press (GtkWidget           *widget,
+                                       GdkEventButton      *event,
+                                       GimpDisplayShell    *shell,
+                                       GimpOrientationType  orientation)
 {
   GimpDisplay *display = shell->display;
 
@@ -1293,34 +1293,7 @@ gimp_display_shell_ruler_button_press (GtkWidget        *widget,
 
   if (event->type == GDK_BUTTON_PRESS && event->button == 1)
     {
-      GimpTool *active_tool;
-      gboolean  sample_point;
-
-      active_tool  = tool_manager_get_active (display->gimp);
-      sample_point = (event->state & gimp_get_toggle_behavior_mask ());
-
-      if (! ((sample_point && (GIMP_IS_COLOR_TOOL (active_tool) &&
-                               ! GIMP_IS_IMAGE_MAP_TOOL (active_tool) &&
-                               ! (GIMP_IS_PAINT_TOOL (active_tool) &&
-                                  ! GIMP_PAINT_TOOL (active_tool)->pick_colors)))
-
-             ||
-
-             (! sample_point && GIMP_IS_MOVE_TOOL (active_tool))))
-        {
-          GimpToolInfo *tool_info;
-
-          tool_info = gimp_get_tool_info (display->gimp,
-                                          sample_point ?
-                                          "gimp-color-picker-tool" :
-                                          "gimp-move-tool");
-
-          if (tool_info)
-            gimp_context_set_tool (gimp_get_user_context (display->gimp),
-                                   tool_info);
-        }
-
-      active_tool = tool_manager_get_active (display->gimp);
+      GimpTool *active_tool = tool_manager_get_active (display->gimp);
 
       if (active_tool)
         {
@@ -1332,12 +1305,15 @@ gimp_display_shell_ruler_button_press (GtkWidget        *widget,
               if (gimp_display_shell_keyboard_grab (shell,
                                                     (GdkEvent *) event))
                 {
-                  if (sample_point)
-                    gimp_color_tool_start_sample_point (active_tool, display);
-                  else if (horizontal)
-                    gimp_move_tool_start_hguide (active_tool, display);
+                  if (event->state & gimp_get_toggle_behavior_mask ())
+                    {
+                      gimp_sample_point_tool_start_new (active_tool, display);
+                    }
                   else
-                    gimp_move_tool_start_vguide (active_tool, display);
+                    {
+                      gimp_guide_tool_start_new (active_tool, display,
+                                                 orientation);
+                    }
 
                   return TRUE;
                 }
@@ -1357,7 +1333,8 @@ gimp_display_shell_hruler_button_press (GtkWidget        *widget,
                                         GdkEventButton   *event,
                                         GimpDisplayShell *shell)
 {
-  return gimp_display_shell_ruler_button_press (widget, event, shell, TRUE);
+  return gimp_display_shell_ruler_button_press (widget, event, shell,
+                                                GIMP_ORIENTATION_HORIZONTAL);
 }
 
 gboolean
@@ -1365,7 +1342,8 @@ gimp_display_shell_vruler_button_press (GtkWidget        *widget,
                                         GdkEventButton   *event,
                                         GimpDisplayShell *shell)
 {
-  return gimp_display_shell_ruler_button_press (widget, event, shell, FALSE);
+  return gimp_display_shell_ruler_button_press (widget, event, shell,
+                                                GIMP_ORIENTATION_VERTICAL);
 }
 
 
diff --git a/app/tools/Makefile.am b/app/tools/Makefile.am
index 86f1cc8..3e1111d 100644
--- a/app/tools/Makefile.am
+++ b/app/tools/Makefile.am
@@ -94,6 +94,8 @@ libapptools_a_sources = \
        gimpfuzzyselecttool.h           \
        gimpgegltool.c                  \
        gimpgegltool.h                  \
+       gimpguidetool.c                 \
+       gimpguidetool.h                 \
        gimphandletransformoptions.c    \
        gimphandletransformoptions.h    \
        gimphandletransformtool.c       \
@@ -168,6 +170,8 @@ libapptools_a_sources = \
        gimpregionselecttool.h          \
        gimprotatetool.c                \
        gimprotatetool.h                \
+       gimpsamplepointtool.c           \
+       gimpsamplepointtool.h           \
        gimpscaletool.c                 \
        gimpscaletool.h                 \
        gimpseamlesscloneoptions.c      \
diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c
index 5656865..cf43186 100644
--- a/app/tools/gimpcolortool.c
+++ b/app/tools/gimpcolortool.c
@@ -20,7 +20,6 @@
 #include <gegl.h>
 #include <gtk/gtk.h>
 
-#include "libgimpmath/gimpmath.h"
 #include "libgimpcolor/gimpcolor.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -33,7 +32,6 @@
 #include "core/gimpimage.h"
 #include "core/gimpimage-pick-color.h"
 #include "core/gimpimage-sample-points.h"
-#include "core/gimpitem.h"
 #include "core/gimpmarshal.h"
 #include "core/gimpsamplepoint.h"
 
@@ -54,14 +52,12 @@
 
 #include "gimpcoloroptions.h"
 #include "gimpcolortool.h"
+#include "gimpsamplepointtool.h"
 #include "gimptoolcontrol.h"
 
 #include "gimp-intl.h"
 
 
-#define SAMPLE_POINT_POSITION_INVALID G_MININT
-
-
 enum
 {
   PICKED,
@@ -173,17 +169,7 @@ gimp_color_tool_init (GimpColorTool *color_tool)
   gimp_tool_control_set_action_size (tool->control,
                                      "tools/tools-color-average-radius-set");
 
-  color_tool->enabled             = FALSE;
-  color_tool->center_x            = 0;
-  color_tool->center_y            = 0;
-  color_tool->pick_mode           = GIMP_COLOR_PICK_MODE_NONE;
-
-  color_tool->options             = NULL;
-
-  color_tool->sample_point        = NULL;
-  color_tool->moving_sample_point = FALSE;
-  color_tool->sample_point_x      = SAMPLE_POINT_POSITION_INVALID;
-  color_tool->sample_point_y      = SAMPLE_POINT_POSITION_INVALID;
+  color_tool->pick_mode = GIMP_COLOR_PICK_MODE_NONE;
 }
 
 static void
@@ -208,8 +194,7 @@ gimp_color_tool_button_press (GimpTool            *tool,
                               GimpButtonPressType  press_type,
                               GimpDisplay         *display)
 {
-  GimpColorTool    *color_tool = GIMP_COLOR_TOOL (tool);
-  GimpDisplayShell *shell      = gimp_display_get_shell (display);
+  GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
 
   /*  Chain up to activate the tool  */
   GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
@@ -220,32 +205,18 @@ gimp_color_tool_button_press (GimpTool            *tool,
 
   if (color_tool->sample_point)
     {
-      color_tool->moving_sample_point = TRUE;
-      gimp_sample_point_get_position (color_tool->sample_point,
-                                      &color_tool->sample_point_x,
-                                      &color_tool->sample_point_y);
-
-      gimp_tool_control_set_scroll_lock (tool->control, TRUE);
+      gimp_tool_control_halt (tool->control);
 
-      gimp_display_shell_selection_pause (shell);
-
-      if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
-        gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
-
-      gimp_tool_push_status_coords (tool, display,
-                                    gimp_tool_control_get_precision (tool->control),
-                                    _("Move Sample Point: "),
-                                    color_tool->sample_point_x,
-                                    ", ",
-                                    color_tool->sample_point_y,
-                                    NULL);
+      gimp_sample_point_tool_start_edit (tool, display,
+                                         color_tool->sample_point);
     }
   else
     {
       color_tool->center_x = coords->x;
       color_tool->center_y = coords->y;
 
-      gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
+      if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
+        gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
 
       gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_START,
                             coords->x, coords->y);
@@ -260,8 +231,7 @@ gimp_color_tool_button_release (GimpTool              *tool,
                                 GimpButtonReleaseType  release_type,
                                 GimpDisplay           *display)
 {
-  GimpColorTool    *color_tool = GIMP_COLOR_TOOL (tool);
-  GimpDisplayShell *shell      = gimp_display_get_shell (display);
+  GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
 
   /*  Chain up to halt the tool  */
   GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
@@ -270,72 +240,7 @@ gimp_color_tool_button_release (GimpTool              *tool,
   if (! color_tool->enabled)
     return;
 
-  if (color_tool->moving_sample_point)
-    {
-      GimpImage *image  = gimp_display_get_image (display);
-      gint       width  = gimp_image_get_width  (image);
-      gint       height = gimp_image_get_height (image);
-
-      gimp_tool_pop_status (tool, display);
-
-      gimp_tool_control_set_scroll_lock (tool->control, FALSE);
-      gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
-
-      if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
-        {
-          color_tool->moving_sample_point = FALSE;
-          color_tool->sample_point_x      = SAMPLE_POINT_POSITION_INVALID;
-          color_tool->sample_point_y      = SAMPLE_POINT_POSITION_INVALID;
-
-          gimp_display_shell_selection_resume (shell);
-          return;
-        }
-
-      if (color_tool->sample_point_x == SAMPLE_POINT_POSITION_INVALID ||
-          color_tool->sample_point_x <  0                             ||
-          color_tool->sample_point_x >= width                         ||
-          color_tool->sample_point_y == SAMPLE_POINT_POSITION_INVALID ||
-          color_tool->sample_point_y <  0                             ||
-          color_tool->sample_point_y >= height)
-        {
-          if (color_tool->sample_point)
-            {
-              gimp_image_remove_sample_point (image,
-                                              color_tool->sample_point, TRUE);
-              color_tool->sample_point = NULL;
-            }
-        }
-      else
-        {
-          if (color_tool->sample_point)
-            {
-              gimp_image_move_sample_point (image,
-                                            color_tool->sample_point,
-                                            color_tool->sample_point_x,
-                                            color_tool->sample_point_y,
-                                            TRUE);
-            }
-          else
-            {
-              color_tool->sample_point =
-                gimp_image_add_sample_point_at_pos (image,
-                                                    color_tool->sample_point_x,
-                                                    color_tool->sample_point_y,
-                                                    TRUE);
-            }
-        }
-
-      gimp_display_shell_selection_resume (shell);
-      gimp_image_flush (image);
-
-      color_tool->moving_sample_point = FALSE;
-      color_tool->sample_point_x      = SAMPLE_POINT_POSITION_INVALID;
-      color_tool->sample_point_y      = SAMPLE_POINT_POSITION_INVALID;
-
-      if (color_tool->sample_point)
-        gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
-    }
-  else
+  if (! color_tool->sample_point)
     {
       gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
 
@@ -351,74 +256,12 @@ gimp_color_tool_motion (GimpTool         *tool,
                         GdkModifierType   state,
                         GimpDisplay      *display)
 {
-  GimpColorTool    *color_tool = GIMP_COLOR_TOOL (tool);
-  GimpDisplayShell *shell      = gimp_display_get_shell (display);
+  GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
 
   if (! color_tool->enabled)
     return;
 
-  if (color_tool->moving_sample_point)
-    {
-      gint      tx, ty;
-      gboolean  delete_point = FALSE;
-
-      gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
-
-      gimp_display_shell_transform_xy (shell,
-                                       coords->x, coords->y,
-                                       &tx, &ty);
-
-      if (tx < 0 || tx > shell->disp_width ||
-          ty < 0 || ty > shell->disp_height)
-        {
-          color_tool->sample_point_x = SAMPLE_POINT_POSITION_INVALID;
-          color_tool->sample_point_y = SAMPLE_POINT_POSITION_INVALID;
-
-          delete_point = TRUE;
-        }
-      else
-        {
-          GimpImage *image  = gimp_display_get_image (display);
-          gint       width  = gimp_image_get_width  (image);
-          gint       height = gimp_image_get_height (image);
-
-          color_tool->sample_point_x = floor (coords->x);
-          color_tool->sample_point_y = floor (coords->y);
-
-          if (color_tool->sample_point_x <  0     ||
-              color_tool->sample_point_x >= width ||
-              color_tool->sample_point_y <  0     ||
-              color_tool->sample_point_y >= height)
-            {
-              delete_point = TRUE;
-            }
-        }
-
-      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
-
-      gimp_tool_pop_status (tool, display);
-
-      if (delete_point)
-        {
-          gimp_tool_push_status (tool, display,
-                                 color_tool->sample_point ?
-                                 _("Remove Sample Point") :
-                                 _("Cancel Sample Point"));
-        }
-      else
-        {
-          gimp_tool_push_status_coords (tool, display,
-                                        gimp_tool_control_get_precision (tool->control),
-                                        color_tool->sample_point ?
-                                        _("Move Sample Point: ") :
-                                        _("Add Sample Point: "),
-                                        color_tool->sample_point_x,
-                                        ", ",
-                                        color_tool->sample_point_y,
-                                        NULL);
-        }
-    }
-  else
+  if (! color_tool->sample_point)
     {
       gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
 
@@ -554,17 +397,6 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
           item = gimp_draw_tool_add_sample_point (draw_tool, x, y, index);
           gimp_canvas_item_set_highlight (item, TRUE);
         }
-
-      if (color_tool->moving_sample_point)
-        {
-          if (color_tool->sample_point_x != SAMPLE_POINT_POSITION_INVALID &&
-              color_tool->sample_point_y != SAMPLE_POINT_POSITION_INVALID)
-            {
-              gimp_draw_tool_add_crosshair (draw_tool,
-                                            color_tool->sample_point_x,
-                                            color_tool->sample_point_y);
-            }
-        }
       else if (color_tool->options->sample_average &&
                gimp_tool_control_is_active (GIMP_TOOL (draw_tool)->control))
         {
@@ -789,36 +621,3 @@ gimp_color_tool_is_enabled (GimpColorTool *color_tool)
 {
   return color_tool->enabled;
 }
-
-void
-gimp_color_tool_start_sample_point (GimpTool    *tool,
-                                    GimpDisplay *display)
-{
-  GimpColorTool *color_tool;
-
-  g_return_if_fail (GIMP_IS_COLOR_TOOL (tool));
-  g_return_if_fail (GIMP_IS_DISPLAY (display));
-
-  color_tool = GIMP_COLOR_TOOL (tool);
-
-  gimp_display_shell_selection_pause (gimp_display_get_shell (display));
-
-  tool->display = display;
-  gimp_tool_control_activate (tool->control);
-  gimp_tool_control_set_scroll_lock (tool->control, TRUE);
-
-  if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
-    gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
-
-  color_tool->sample_point        = NULL;
-  color_tool->moving_sample_point = TRUE;
-  color_tool->sample_point_x      = SAMPLE_POINT_POSITION_INVALID;
-  color_tool->sample_point_y      = SAMPLE_POINT_POSITION_INVALID;
-
-  gimp_tool_set_cursor (tool, display,
-                        GIMP_CURSOR_MOUSE,
-                        GIMP_TOOL_CURSOR_COLOR_PICKER,
-                        GIMP_CURSOR_MODIFIER_MOVE);
-
-  gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
-}
diff --git a/app/tools/gimpcolortool.h b/app/tools/gimpcolortool.h
index 56b949c..5511c10 100644
--- a/app/tools/gimpcolortool.h
+++ b/app/tools/gimpcolortool.h
@@ -46,9 +46,6 @@ struct _GimpColorTool
   GimpColorOptions  *options;
 
   GimpSamplePoint   *sample_point;
-  gboolean           moving_sample_point;
-  gint               sample_point_x;
-  gint               sample_point_y;
 };
 
 struct _GimpColorToolClass
@@ -74,15 +71,12 @@ struct _GimpColorToolClass
 };
 
 
-GType      gimp_color_tool_get_type           (void) G_GNUC_CONST;
+GType      gimp_color_tool_get_type   (void) G_GNUC_CONST;
 
-void       gimp_color_tool_enable             (GimpColorTool    *color_tool,
-                                               GimpColorOptions *options);
-void       gimp_color_tool_disable            (GimpColorTool    *color_tool);
-gboolean   gimp_color_tool_is_enabled         (GimpColorTool    *color_tool);
-
-void       gimp_color_tool_start_sample_point (GimpTool         *tool,
-                                               GimpDisplay      *display);
+void       gimp_color_tool_enable     (GimpColorTool    *color_tool,
+                                       GimpColorOptions *options);
+void       gimp_color_tool_disable    (GimpColorTool    *color_tool);
+gboolean   gimp_color_tool_is_enabled (GimpColorTool    *color_tool);
 
 
 #endif  /*  __GIMP_COLOR_TOOL_H__  */
diff --git a/app/tools/gimpguidetool.c b/app/tools/gimpguidetool.c
new file mode 100644
index 0000000..97d8251
--- /dev/null
+++ b/app/tools/gimpguidetool.c
@@ -0,0 +1,390 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpmath/gimpmath.h"
+
+#include "tools-types.h"
+
+#include "core/gimp.h"
+#include "core/gimpguide.h"
+#include "core/gimpimage.h"
+#include "core/gimpimage-guides.h"
+
+#include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-selection.h"
+#include "display/gimpdisplayshell-transform.h"
+
+#include "gimpguidetool.h"
+#include "gimptoolcontrol.h"
+#include "tool_manager.h"
+
+#include "gimp-intl.h"
+
+
+#define SWAP_ORIENT(orient) ((orient) == GIMP_ORIENTATION_HORIZONTAL ? \
+                             GIMP_ORIENTATION_VERTICAL : \
+                             GIMP_ORIENTATION_HORIZONTAL)
+
+
+/*  local function prototypes  */
+
+static void   gimp_guide_tool_button_release (GimpTool              *tool,
+                                              const GimpCoords      *coords,
+                                              guint32                time,
+                                              GdkModifierType        state,
+                                              GimpButtonReleaseType  release_type,
+                                              GimpDisplay           *display);
+static void   gimp_guide_tool_motion         (GimpTool              *tool,
+                                              const GimpCoords      *coords,
+                                              guint32                time,
+                                              GdkModifierType        state,
+                                              GimpDisplay           *display);
+
+static void   gimp_guide_tool_draw           (GimpDrawTool          *draw_tool);
+
+static void   gimp_guide_tool_start          (GimpTool              *parent_tool,
+                                              GimpDisplay           *display,
+                                              GimpGuide             *guide,
+                                              GimpOrientationType    orientation);
+
+
+G_DEFINE_TYPE (GimpGuideTool, gimp_guide_tool, GIMP_TYPE_DRAW_TOOL)
+
+#define parent_class gimp_guide_tool_parent_class
+
+
+static void
+gimp_guide_tool_class_init (GimpGuideToolClass *klass)
+{
+  GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
+  GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
+
+  tool_class->button_release = gimp_guide_tool_button_release;
+  tool_class->motion         = gimp_guide_tool_motion;
+
+  draw_tool_class->draw      = gimp_guide_tool_draw;
+}
+
+static void
+gimp_guide_tool_init (GimpGuideTool *guide_tool)
+{
+  GimpTool *tool = GIMP_TOOL (guide_tool);
+
+  gimp_tool_control_set_snap_to            (tool->control, FALSE);
+  gimp_tool_control_set_handle_empty_image (tool->control, TRUE);
+  gimp_tool_control_set_tool_cursor        (tool->control,
+                                            GIMP_TOOL_CURSOR_MOVE);
+  gimp_tool_control_set_scroll_lock        (tool->control, TRUE);
+  gimp_tool_control_set_precision          (tool->control,
+                                            GIMP_CURSOR_PRECISION_PIXEL_BORDER);
+
+  guide_tool->guide             = NULL;
+  guide_tool->guide_position    = GIMP_GUIDE_POSITION_UNDEFINED;
+  guide_tool->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
+}
+
+static void
+gimp_guide_tool_button_release (GimpTool              *tool,
+                                const GimpCoords      *coords,
+                                guint32                time,
+                                GdkModifierType        state,
+                                GimpButtonReleaseType  release_type,
+                                GimpDisplay           *display)
+{
+  GimpGuideTool    *guide_tool = GIMP_GUIDE_TOOL (tool);
+  GimpDisplayShell *shell      = gimp_display_get_shell (display);
+  GimpImage        *image      = gimp_display_get_image (display);
+
+  gimp_tool_pop_status (tool, display);
+
+  gimp_tool_control_halt (tool->control);
+
+  gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
+
+  if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
+    {
+      gint     width        = gimp_image_get_width  (image);
+      gint     height       = gimp_image_get_height (image);
+      gboolean delete_guide = FALSE;
+
+      switch (guide_tool->guide_orientation)
+        {
+        case GIMP_ORIENTATION_HORIZONTAL:
+          if (guide_tool->guide_position == GIMP_GUIDE_POSITION_UNDEFINED ||
+              guide_tool->guide_position <  0                             ||
+              guide_tool->guide_position >= height)
+            {
+              delete_guide = TRUE;
+            }
+          break;
+
+        case GIMP_ORIENTATION_VERTICAL:
+          if (guide_tool->guide_position == GIMP_GUIDE_POSITION_UNDEFINED ||
+              guide_tool->guide_position <  0                             ||
+              guide_tool->guide_position >= width)
+            {
+              delete_guide = TRUE;
+            }
+          break;
+
+        default:
+          break;
+        }
+
+      if (delete_guide)
+        {
+          if (guide_tool->guide)
+            {
+              gimp_image_remove_guide (image, guide_tool->guide, TRUE);
+              guide_tool->guide = NULL;
+            }
+        }
+      else
+        {
+          if (guide_tool->guide)
+            {
+              gimp_image_move_guide (image, guide_tool->guide,
+                                     guide_tool->guide_position, TRUE);
+            }
+          else
+            {
+              switch (guide_tool->guide_orientation)
+                {
+                case GIMP_ORIENTATION_HORIZONTAL:
+                  guide_tool->guide =
+                    gimp_image_add_hguide (image,
+                                           guide_tool->guide_position,
+                                           TRUE);
+                  break;
+
+                case GIMP_ORIENTATION_VERTICAL:
+                  guide_tool->guide =
+                    gimp_image_add_vguide (image,
+                                           guide_tool->guide_position,
+                                           TRUE);
+                  break;
+
+                default:
+                  g_assert_not_reached ();
+                }
+            }
+        }
+
+      gimp_image_flush (image);
+    }
+
+  gimp_display_shell_selection_resume (shell);
+
+  guide_tool->guide_position    = GIMP_GUIDE_POSITION_UNDEFINED;
+  guide_tool->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
+
+  tool_manager_pop_tool (display->gimp);
+  g_object_unref (guide_tool);
+
+  {
+    GimpTool *active_tool = tool_manager_get_active (display->gimp);
+
+    if (GIMP_IS_DRAW_TOOL (active_tool))
+      gimp_draw_tool_pause (GIMP_DRAW_TOOL (active_tool));
+
+    tool_manager_oper_update_active (display->gimp, coords, state,
+                                     TRUE, display);
+    tool_manager_cursor_update_active (display->gimp, coords, state,
+                                       display);
+
+    if (GIMP_IS_DRAW_TOOL (active_tool))
+      gimp_draw_tool_resume (GIMP_DRAW_TOOL (active_tool));
+  }
+}
+
+static void
+gimp_guide_tool_motion (GimpTool         *tool,
+                        const GimpCoords *coords,
+                        guint32           time,
+                        GdkModifierType   state,
+                        GimpDisplay      *display)
+
+{
+  GimpGuideTool    *guide_tool   = GIMP_GUIDE_TOOL (tool);
+  GimpDisplayShell *shell        = gimp_display_get_shell (display);
+  gboolean          delete_guide = FALSE;
+  gint              tx, ty;
+
+  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
+
+  gimp_display_shell_transform_xy (shell,
+                                   coords->x, coords->y,
+                                   &tx, &ty);
+
+  if (tx < 0 || tx >= shell->disp_width ||
+      ty < 0 || ty >= shell->disp_height)
+    {
+      guide_tool->guide_position = GIMP_GUIDE_POSITION_UNDEFINED;
+
+      delete_guide = TRUE;
+    }
+  else
+    {
+      GimpImage *image  = gimp_display_get_image (display);
+      gint       width  = gimp_image_get_width  (image);
+      gint       height = gimp_image_get_height (image);
+
+      if (guide_tool->guide_orientation == GIMP_ORIENTATION_HORIZONTAL)
+        guide_tool->guide_position = RINT (coords->y);
+      else
+        guide_tool->guide_position = RINT (coords->x);
+
+      switch (guide_tool->guide_orientation)
+        {
+        case GIMP_ORIENTATION_HORIZONTAL:
+          if (guide_tool->guide_position <  0 ||
+              guide_tool->guide_position >= height)
+            {
+              delete_guide = TRUE;
+            }
+          break;
+
+        case GIMP_ORIENTATION_VERTICAL:
+          if (guide_tool->guide_position <  0 ||
+              guide_tool->guide_position >= width)
+            {
+              delete_guide = TRUE;
+            }
+          break;
+
+        default:
+          break;
+        }
+    }
+
+  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+
+  gimp_tool_pop_status (tool, display);
+
+  if (delete_guide)
+    {
+      gimp_tool_push_status (tool, display,
+                             guide_tool->guide ?
+                             _("Remove Guide") : _("Cancel Guide"));
+    }
+  else
+    {
+      gimp_tool_push_status_length (tool, display,
+                                    guide_tool->guide ?
+                                    _("Move Guide: ") : _("Add Guide: "),
+                                    SWAP_ORIENT (guide_tool->guide_orientation),
+                                    guide_tool->guide_position,
+                                    NULL);
+    }
+}
+
+static void
+gimp_guide_tool_draw (GimpDrawTool *draw_tool)
+{
+  GimpGuideTool *guide_tool = GIMP_GUIDE_TOOL (draw_tool);
+
+  if (guide_tool->guide_position != GIMP_GUIDE_POSITION_UNDEFINED)
+    {
+      gimp_draw_tool_add_guide (draw_tool,
+                                guide_tool->guide_orientation,
+                                guide_tool->guide_position,
+                                GIMP_GUIDE_STYLE_NONE);
+    }
+}
+
+static void
+gimp_guide_tool_start (GimpTool            *parent_tool,
+                       GimpDisplay         *display,
+                       GimpGuide           *guide,
+                       GimpOrientationType  orientation)
+{
+  GimpGuideTool *guide_tool;
+  GimpTool      *tool;
+
+  guide_tool = g_object_new (GIMP_TYPE_GUIDE_TOOL,
+                             "tool-info", parent_tool->tool_info,
+                             NULL);
+
+  tool = GIMP_TOOL (guide_tool);
+
+  gimp_display_shell_selection_pause (gimp_display_get_shell (display));
+
+  if (guide)
+    {
+      guide_tool->guide             = guide;
+      guide_tool->guide_position    = gimp_guide_get_position (guide);
+      guide_tool->guide_orientation = gimp_guide_get_orientation (guide);
+    }
+  else
+    {
+      guide_tool->guide             = NULL;
+      guide_tool->guide_position    = GIMP_GUIDE_POSITION_UNDEFINED;
+      guide_tool->guide_orientation = orientation;
+    }
+
+  gimp_tool_set_cursor (tool, display,
+                        GIMP_CURSOR_MOUSE,
+                        GIMP_TOOL_CURSOR_HAND,
+                        GIMP_CURSOR_MODIFIER_MOVE);
+
+  tool_manager_push_tool (display->gimp, tool);
+
+  tool->display = display;
+  gimp_tool_control_activate (tool->control);
+
+  gimp_draw_tool_start (GIMP_DRAW_TOOL (guide_tool), display);
+
+  gimp_tool_push_status_length (tool, display,
+                                _("Add Guide: "),
+                                SWAP_ORIENT (guide_tool->guide_orientation),
+                                guide_tool->guide_position,
+                                NULL);
+}
+
+
+/*  public functions  */
+
+void
+gimp_guide_tool_start_new (GimpTool            *parent_tool,
+                           GimpDisplay         *display,
+                           GimpOrientationType  orientation)
+{
+  g_return_if_fail (GIMP_IS_TOOL (parent_tool));
+  g_return_if_fail (GIMP_IS_DISPLAY (display));
+
+  gimp_guide_tool_start (parent_tool, display,
+                         NULL, orientation);
+}
+
+void
+gimp_guide_tool_start_edit (GimpTool    *parent_tool,
+                            GimpDisplay *display,
+                            GimpGuide   *guide)
+{
+  g_return_if_fail (GIMP_IS_TOOL (parent_tool));
+  g_return_if_fail (GIMP_IS_DISPLAY (display));
+  g_return_if_fail (GIMP_IS_GUIDE (guide));
+
+  gimp_guide_tool_start (parent_tool, display,
+                         guide, GIMP_ORIENTATION_UNKNOWN);
+}
diff --git a/app/tools/gimpguidetool.h b/app/tools/gimpguidetool.h
new file mode 100644
index 0000000..0f42961
--- /dev/null
+++ b/app/tools/gimpguidetool.h
@@ -0,0 +1,61 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_GUIDE_TOOL_H__
+#define __GIMP_GUIDE_TOOL_H__
+
+
+#include "gimpdrawtool.h"
+
+
+#define GIMP_TYPE_GUIDE_TOOL            (gimp_guide_tool_get_type ())
+#define GIMP_GUIDE_TOOL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_GUIDE_TOOL, 
GimpGuideTool))
+#define GIMP_GUIDE_TOOL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_GUIDE_TOOL, 
GimpGuideToolClass))
+#define GIMP_IS_GUIDE_TOOL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_GUIDE_TOOL))
+#define GIMP_IS_GUIDE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_GUIDE_TOOL))
+#define GIMP_GUIDE_TOOL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_GUIDE_TOOL, 
GimpGuideToolClass))
+
+
+typedef struct _GimpGuideTool      GimpGuideTool;
+typedef struct _GimpGuideToolClass GimpGuideToolClass;
+
+struct _GimpGuideTool
+{
+  GimpDrawTool         parent_instance;
+
+  GimpGuide           *guide;
+  gint                 guide_position;
+  GimpOrientationType  guide_orientation;
+};
+
+struct _GimpGuideToolClass
+{
+  GimpDrawToolClass  parent_class;
+};
+
+
+GType   gimp_guide_tool_get_type   (void) G_GNUC_CONST;
+
+void    gimp_guide_tool_start_new  (GimpTool            *parent_tool,
+                                    GimpDisplay         *display,
+                                    GimpOrientationType  orientation);
+void    gimp_guide_tool_start_edit (GimpTool            *parent_tool,
+                                    GimpDisplay         *display,
+                                    GimpGuide           *guide);
+
+
+#endif  /*  __GIMP_GUIDE_TOOL_H__  */
diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c
index 69fdecf..34969fc 100644
--- a/app/tools/gimpmovetool.c
+++ b/app/tools/gimpmovetool.c
@@ -53,6 +53,7 @@
 #include "display/gimpdisplayshell-transform.h"
 
 #include "gimpeditselectiontool.h"
+#include "gimpguidetool.h"
 #include "gimpmoveoptions.h"
 #include "gimpmovetool.h"
 #include "gimptoolcontrol.h"
@@ -60,11 +61,6 @@
 #include "gimp-intl.h"
 
 
-#define SWAP_ORIENT(orient) ((orient) == GIMP_ORIENTATION_HORIZONTAL ? \
-                             GIMP_ORIENTATION_VERTICAL : \
-                             GIMP_ORIENTATION_HORIZONTAL)
-
-
 /*  local function prototypes  */
 
 static void   gimp_move_tool_button_press   (GimpTool              *tool,
@@ -79,11 +75,6 @@ static void   gimp_move_tool_button_release (GimpTool              *tool,
                                              GdkModifierType        state,
                                              GimpButtonReleaseType  release_type,
                                              GimpDisplay           *display);
-static void   gimp_move_tool_motion         (GimpTool              *tool,
-                                             const GimpCoords      *coords,
-                                             guint32                time,
-                                             GdkModifierType        state,
-                                             GimpDisplay           *display);
 static gboolean gimp_move_tool_key_press    (GimpTool              *tool,
                                              GdkEventKey           *kevent,
                                              GimpDisplay           *display);
@@ -104,10 +95,6 @@ static void   gimp_move_tool_cursor_update  (GimpTool              *tool,
 
 static void   gimp_move_tool_draw           (GimpDrawTool          *draw_tool);
 
-static void   gimp_move_tool_start_guide    (GimpMoveTool          *move,
-                                             GimpDisplay           *display,
-                                             GimpOrientationType    orientation);
-
 
 G_DEFINE_TYPE (GimpMoveTool, gimp_move_tool, GIMP_TYPE_DRAW_TOOL)
 
@@ -139,7 +126,6 @@ gimp_move_tool_class_init (GimpMoveToolClass *klass)
 
   tool_class->button_press   = gimp_move_tool_button_press;
   tool_class->button_release = gimp_move_tool_button_release;
-  tool_class->motion         = gimp_move_tool_motion;
   tool_class->key_press      = gimp_move_tool_key_press;
   tool_class->modifier_key   = gimp_move_tool_modifier_key;
   tool_class->oper_update    = gimp_move_tool_oper_update;
@@ -161,10 +147,6 @@ gimp_move_tool_init (GimpMoveTool *move_tool)
   move_tool->floating_layer     = NULL;
   move_tool->guide              = NULL;
 
-  move_tool->moving_guide       = FALSE;
-  move_tool->guide_position     = GIMP_GUIDE_POSITION_UNDEFINED;
-  move_tool->guide_orientation  = GIMP_ORIENTATION_UNKNOWN;
-
   move_tool->saved_type         = GIMP_TRANSFORM_TYPE_LAYER;
 
   move_tool->old_active_layer   = NULL;
@@ -191,9 +173,6 @@ gimp_move_tool_button_press (GimpTool            *tool,
 
   move->floating_layer     = NULL;
   move->guide              = NULL;
-  move->moving_guide       = FALSE;
-  move->old_active_layer   = NULL;
-  move->old_active_vectors = NULL;
 
   if (! options->move_current)
     {
@@ -229,27 +208,9 @@ gimp_move_tool_button_press (GimpTool            *tool,
                                               FUNSCALEX (shell, snap_distance),
                                               FUNSCALEY (shell, snap_distance))))
             {
-              move->guide             = guide;
-              move->moving_guide      = TRUE;
-              move->guide_position    = gimp_guide_get_position (guide);
-              move->guide_orientation = gimp_guide_get_orientation (guide);
-
-              gimp_tool_control_set_scroll_lock (tool->control, TRUE);
-              gimp_tool_control_set_precision   (tool->control,
-                                                 GIMP_CURSOR_PRECISION_PIXEL_BORDER);
-
-              gimp_tool_control_activate (tool->control);
+              move->guide = guide;
 
-              gimp_display_shell_selection_pause (shell);
-
-              if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
-                gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
-
-              gimp_tool_push_status_length (tool, display,
-                                            _("Move Guide: "),
-                                            SWAP_ORIENT (move->guide_orientation),
-                                            move->guide_position,
-                                            NULL);
+              gimp_guide_tool_start_edit (tool, display, guide);
 
               return;
             }
@@ -396,222 +357,45 @@ gimp_move_tool_button_release (GimpTool              *tool,
                                GimpButtonReleaseType  release_type,
                                GimpDisplay           *display)
 {
-  GimpMoveTool     *move   = GIMP_MOVE_TOOL (tool);
-  GimpGuiConfig    *config = GIMP_GUI_CONFIG (display->gimp->config);
-  GimpDisplayShell *shell  = gimp_display_get_shell (display);
-  GimpImage        *image  = gimp_display_get_image (display);
+  GimpMoveTool  *move   = GIMP_MOVE_TOOL (tool);
+  GimpGuiConfig *config = GIMP_GUI_CONFIG (display->gimp->config);
+  GimpImage     *image  = gimp_display_get_image (display);
+  gboolean       flush  = FALSE;
 
   gimp_tool_control_halt (tool->control);
 
-  if (move->moving_guide)
+  if (! config->move_tool_changes_active ||
+      (release_type == GIMP_BUTTON_RELEASE_CANCEL))
     {
-      gboolean delete_guide = FALSE;
-      gint     width  = gimp_image_get_width  (image);
-      gint     height = gimp_image_get_height (image);
-
-      gimp_tool_pop_status (tool, display);
-
-      gimp_tool_control_set_scroll_lock (tool->control, FALSE);
-      gimp_tool_control_set_precision   (tool->control,
-                                         GIMP_CURSOR_PRECISION_PIXEL_CENTER);
-
-      gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
-
-      if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
+      if (move->old_active_layer)
         {
-          move->moving_guide      = FALSE;
-          move->guide_position    = GIMP_GUIDE_POSITION_UNDEFINED;
-          move->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
+          gimp_image_set_active_layer (image, move->old_active_layer);
+          move->old_active_layer = NULL;
 
-          gimp_display_shell_selection_resume (shell);
-          return;
+          flush = TRUE;
         }
 
-      switch (move->guide_orientation)
+      if (move->old_active_vectors)
         {
-        case GIMP_ORIENTATION_HORIZONTAL:
-          if (move->guide_position == GIMP_GUIDE_POSITION_UNDEFINED ||
-              move->guide_position <  0                             ||
-              move->guide_position >= height)
-            delete_guide = TRUE;
-          break;
-
-        case GIMP_ORIENTATION_VERTICAL:
-          if (move->guide_position == GIMP_GUIDE_POSITION_UNDEFINED ||
-              move->guide_position <  0                             ||
-              move->guide_position >= width)
-            delete_guide = TRUE;
-          break;
-
-        default:
-          break;
-        }
-
-      if (delete_guide)
-        {
-          if (move->guide)
-            {
-              gimp_image_remove_guide (image, move->guide, TRUE);
-              move->guide = NULL;
-            }
-        }
-      else
-        {
-          if (move->guide)
-            {
-              gimp_image_move_guide (image, move->guide,
-                                     move->guide_position, TRUE);
-            }
-          else
-            {
-              switch (move->guide_orientation)
-                {
-                case GIMP_ORIENTATION_HORIZONTAL:
-                  move->guide = gimp_image_add_hguide (image,
-                                                       move->guide_position,
-                                                       TRUE);
-                  break;
-
-                case GIMP_ORIENTATION_VERTICAL:
-                  move->guide = gimp_image_add_vguide (image,
-                                                       move->guide_position,
-                                                       TRUE);
-                  break;
-
-                default:
-                  g_assert_not_reached ();
-                }
-            }
-        }
-
-      gimp_display_shell_selection_resume (shell);
-      gimp_image_flush (image);
-
-      move->moving_guide      = FALSE;
-      move->guide_position    = GIMP_GUIDE_POSITION_UNDEFINED;
-      move->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
-
-      if (move->guide)
-        gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
-    }
-  else
-    {
-      gboolean flush = FALSE;
-
-      if (! config->move_tool_changes_active ||
-          (release_type == GIMP_BUTTON_RELEASE_CANCEL))
-        {
-          if (move->old_active_layer)
-            {
-              gimp_image_set_active_layer (image, move->old_active_layer);
-              move->old_active_layer = NULL;
-
-              flush = TRUE;
-            }
-
-          if (move->old_active_vectors)
-            {
-              gimp_image_set_active_vectors (image, move->old_active_vectors);
-              move->old_active_vectors = NULL;
-
-              flush = TRUE;
-            }
-        }
-
-      if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
-        {
-          if (move->floating_layer)
-            {
-              floating_sel_anchor (move->floating_layer);
+          gimp_image_set_active_vectors (image, move->old_active_vectors);
+          move->old_active_vectors = NULL;
 
-              flush = TRUE;
-            }
+          flush = TRUE;
         }
-
-      if (flush)
-        gimp_image_flush (image);
     }
-}
-
-static void
-gimp_move_tool_motion (GimpTool         *tool,
-                       const GimpCoords *coords,
-                       guint32           time,
-                       GdkModifierType   state,
-                       GimpDisplay      *display)
-
-{
-  GimpMoveTool     *move  = GIMP_MOVE_TOOL (tool);
-  GimpDisplayShell *shell = gimp_display_get_shell (display);
 
-  if (move->moving_guide)
+  if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
     {
-      gint      tx, ty;
-      gboolean  delete_guide = FALSE;
-
-      gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
-
-      gimp_display_shell_transform_xy (shell,
-                                       coords->x, coords->y,
-                                       &tx, &ty);
-
-      if (tx < 0 || tx >= shell->disp_width ||
-          ty < 0 || ty >= shell->disp_height)
-        {
-          move->guide_position = GIMP_GUIDE_POSITION_UNDEFINED;
-
-          delete_guide = TRUE;
-        }
-      else
+      if (move->floating_layer)
         {
-          GimpImage *image  = gimp_display_get_image (display);
-          gint       width  = gimp_image_get_width  (image);
-          gint       height = gimp_image_get_height (image);
-
-          if (move->guide_orientation == GIMP_ORIENTATION_HORIZONTAL)
-            move->guide_position = RINT (coords->y);
-          else
-            move->guide_position = RINT (coords->x);
-
-          switch (move->guide_orientation)
-            {
-            case GIMP_ORIENTATION_HORIZONTAL:
-              if (move->guide_position <  0 ||
-                  move->guide_position >= height)
-                delete_guide = TRUE;
-              break;
-
-            case GIMP_ORIENTATION_VERTICAL:
-              if (move->guide_position <  0 ||
-                  move->guide_position >= width)
-                delete_guide = TRUE;
-              break;
-
-            default:
-              break;
-            }
-        }
+          floating_sel_anchor (move->floating_layer);
 
-      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
-
-      gimp_tool_pop_status (tool, display);
-
-      if (delete_guide)
-        {
-          gimp_tool_push_status (tool, display,
-                                 move->guide ?
-                                 _("Remove Guide") : _("Cancel Guide"));
-        }
-      else
-        {
-          gimp_tool_push_status_length (tool, display,
-                                        move->guide ?
-                                        _("Move Guide: ") : _("Add Guide: "),
-                                        SWAP_ORIENT (move->guide_orientation),
-                                        move->guide_position,
-                                        NULL);
+          flush = TRUE;
         }
     }
+
+  if (flush)
+    gimp_image_flush (image);
 }
 
 static gboolean
@@ -846,64 +630,4 @@ gimp_move_tool_draw (GimpDrawTool *draw_tool)
                                        style);
       gimp_canvas_item_set_highlight (item, TRUE);
     }
-
-  if (move->moving_guide &&
-      move->guide_position != GIMP_GUIDE_POSITION_UNDEFINED)
-    {
-      gimp_draw_tool_add_guide (draw_tool,
-                                move->guide_orientation,
-                                move->guide_position,
-                                GIMP_GUIDE_STYLE_NONE);
-    }
-}
-
-void
-gimp_move_tool_start_hguide (GimpTool    *tool,
-                             GimpDisplay *display)
-{
-  g_return_if_fail (GIMP_IS_MOVE_TOOL (tool));
-  g_return_if_fail (GIMP_IS_DISPLAY (display));
-
-  gimp_move_tool_start_guide (GIMP_MOVE_TOOL (tool), display,
-                              GIMP_ORIENTATION_HORIZONTAL);
-}
-
-void
-gimp_move_tool_start_vguide (GimpTool    *tool,
-                             GimpDisplay *display)
-{
-  g_return_if_fail (GIMP_IS_MOVE_TOOL (tool));
-  g_return_if_fail (GIMP_IS_DISPLAY (display));
-
-  gimp_move_tool_start_guide (GIMP_MOVE_TOOL (tool), display,
-                              GIMP_ORIENTATION_VERTICAL);
-}
-
-static void
-gimp_move_tool_start_guide (GimpMoveTool        *move,
-                            GimpDisplay         *display,
-                            GimpOrientationType  orientation)
-{
-  GimpTool *tool = GIMP_TOOL (move);
-
-  gimp_display_shell_selection_pause (gimp_display_get_shell (display));
-
-  tool->display = display;
-  gimp_tool_control_activate (tool->control);
-  gimp_tool_control_set_scroll_lock (tool->control, TRUE);
-
-  if (gimp_draw_tool_is_active  (GIMP_DRAW_TOOL (tool)))
-    gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
-
-  move->guide             = NULL;
-  move->moving_guide      = TRUE;
-  move->guide_position    = GIMP_GUIDE_POSITION_UNDEFINED;
-  move->guide_orientation = orientation;
-
-  gimp_tool_set_cursor (tool, display,
-                        GIMP_CURSOR_MOUSE,
-                        GIMP_TOOL_CURSOR_HAND,
-                        GIMP_CURSOR_MODIFIER_MOVE);
-
-  gimp_draw_tool_start (GIMP_DRAW_TOOL (move), display);
 }
diff --git a/app/tools/gimpmovetool.h b/app/tools/gimpmovetool.h
index 669ce90..b15ab30 100644
--- a/app/tools/gimpmovetool.h
+++ b/app/tools/gimpmovetool.h
@@ -42,10 +42,6 @@ struct _GimpMoveTool
   GimpLayer           *floating_layer;
   GimpGuide           *guide;
 
-  gboolean             moving_guide;
-  gint                 guide_position;
-  GimpOrientationType  guide_orientation;
-
   GimpTransformType    saved_type;
 
   GimpLayer           *old_active_layer;
diff --git a/app/tools/gimpsamplepointtool.c b/app/tools/gimpsamplepointtool.c
new file mode 100644
index 0000000..d400650
--- /dev/null
+++ b/app/tools/gimpsamplepointtool.c
@@ -0,0 +1,348 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpmath/gimpmath.h"
+
+#include "tools-types.h"
+
+#include "core/gimp.h"
+#include "core/gimpsamplepoint.h"
+#include "core/gimpimage.h"
+#include "core/gimpimage-sample-points.h"
+
+#include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-selection.h"
+#include "display/gimpdisplayshell-transform.h"
+
+#include "gimpsamplepointtool.h"
+#include "gimptoolcontrol.h"
+#include "tool_manager.h"
+
+#include "gimp-intl.h"
+
+
+#define GIMP_SAMPLE_POINT_POSITION_UNDEFINED G_MININT
+
+
+/*  local function prototypes  */
+
+static void   gimp_sample_point_tool_button_release (GimpTool              *tool,
+                                                     const GimpCoords      *coords,
+                                                     guint32                time,
+                                                     GdkModifierType        state,
+                                                     GimpButtonReleaseType  release_type,
+                                                     GimpDisplay           *display);
+static void   gimp_sample_point_tool_motion         (GimpTool              *tool,
+                                                     const GimpCoords      *coords,
+                                                     guint32                time,
+                                                     GdkModifierType        state,
+                                                     GimpDisplay           *display);
+
+static void   gimp_sample_point_tool_draw           (GimpDrawTool          *draw_tool);
+
+static void   gimp_sample_point_tool_start          (GimpTool              *parent_tool,
+                                                     GimpDisplay           *display,
+                                                     GimpSamplePoint       *sample_point);
+
+
+G_DEFINE_TYPE (GimpSamplePointTool, gimp_sample_point_tool, GIMP_TYPE_DRAW_TOOL)
+
+#define parent_class gimp_sample_point_tool_parent_class
+
+
+static void
+gimp_sample_point_tool_class_init (GimpSamplePointToolClass *klass)
+{
+  GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
+  GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
+
+  tool_class->button_release = gimp_sample_point_tool_button_release;
+  tool_class->motion         = gimp_sample_point_tool_motion;
+
+  draw_tool_class->draw      = gimp_sample_point_tool_draw;
+}
+
+static void
+gimp_sample_point_tool_init (GimpSamplePointTool *sp_tool)
+{
+  GimpTool *tool = GIMP_TOOL (sp_tool);
+
+  gimp_tool_control_set_snap_to            (tool->control, FALSE);
+  gimp_tool_control_set_handle_empty_image (tool->control, TRUE);
+  gimp_tool_control_set_tool_cursor        (tool->control,
+                                            GIMP_TOOL_CURSOR_MOVE);
+  gimp_tool_control_set_scroll_lock        (tool->control, TRUE);
+  gimp_tool_control_set_precision          (tool->control,
+                                            GIMP_CURSOR_PRECISION_PIXEL_CENTER);
+
+  sp_tool->sample_point   = NULL;
+  sp_tool->sample_point_x = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+  sp_tool->sample_point_y = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+}
+
+static void
+gimp_sample_point_tool_button_release (GimpTool              *tool,
+                                       const GimpCoords      *coords,
+                                       guint32                time,
+                                       GdkModifierType        state,
+                                       GimpButtonReleaseType  release_type,
+                                       GimpDisplay           *display)
+{
+  GimpSamplePointTool *sp_tool = GIMP_SAMPLE_POINT_TOOL (tool);
+  GimpDisplayShell    *shell   = gimp_display_get_shell (display);
+  GimpImage           *image   = gimp_display_get_image (display);
+
+  gimp_tool_pop_status (tool, display);
+
+  gimp_tool_control_halt (tool->control);
+
+  gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
+
+  if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
+    {
+      gint width  = gimp_image_get_width  (image);
+      gint height = gimp_image_get_height (image);
+
+      if (sp_tool->sample_point_x == GIMP_SAMPLE_POINT_POSITION_UNDEFINED ||
+          sp_tool->sample_point_x <  0                                    ||
+          sp_tool->sample_point_x >= width                                ||
+          sp_tool->sample_point_y == GIMP_SAMPLE_POINT_POSITION_UNDEFINED ||
+          sp_tool->sample_point_y <  0                                    ||
+          sp_tool->sample_point_y >= height)
+        {
+          if (sp_tool->sample_point)
+            {
+              gimp_image_remove_sample_point (image,
+                                              sp_tool->sample_point, TRUE);
+              sp_tool->sample_point = NULL;
+            }
+        }
+      else
+        {
+          if (sp_tool->sample_point)
+            {
+              gimp_image_move_sample_point (image,
+                                            sp_tool->sample_point,
+                                            sp_tool->sample_point_x,
+                                            sp_tool->sample_point_y,
+                                            TRUE);
+            }
+          else
+            {
+              sp_tool->sample_point =
+                gimp_image_add_sample_point_at_pos (image,
+                                                    sp_tool->sample_point_x,
+                                                    sp_tool->sample_point_y,
+                                                    TRUE);
+            }
+        }
+
+      gimp_image_flush (image);
+    }
+
+  gimp_display_shell_selection_resume (shell);
+
+  sp_tool->sample_point_x = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+  sp_tool->sample_point_y = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+
+  tool_manager_pop_tool (display->gimp);
+  g_object_unref (sp_tool);
+
+  {
+    GimpTool *active_tool = tool_manager_get_active (display->gimp);
+
+    if (GIMP_IS_DRAW_TOOL (active_tool))
+      gimp_draw_tool_pause (GIMP_DRAW_TOOL (active_tool));
+
+    tool_manager_oper_update_active (display->gimp, coords, state,
+                                     TRUE, display);
+    tool_manager_cursor_update_active (display->gimp, coords, state,
+                                       display);
+
+    if (GIMP_IS_DRAW_TOOL (active_tool))
+      gimp_draw_tool_resume (GIMP_DRAW_TOOL (active_tool));
+  }
+}
+
+static void
+gimp_sample_point_tool_motion (GimpTool         *tool,
+                               const GimpCoords *coords,
+                               guint32           time,
+                               GdkModifierType   state,
+                               GimpDisplay      *display)
+
+{
+  GimpSamplePointTool *sp_tool      = GIMP_SAMPLE_POINT_TOOL (tool);
+  GimpDisplayShell    *shell        = gimp_display_get_shell (display);
+  gboolean             delete_point = FALSE;
+  gint                 tx, ty;
+
+  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
+
+  gimp_display_shell_transform_xy (shell,
+                                   coords->x, coords->y,
+                                   &tx, &ty);
+
+  if (tx < 0 || tx >= shell->disp_width ||
+      ty < 0 || ty >= shell->disp_height)
+    {
+      sp_tool->sample_point_x = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+      sp_tool->sample_point_y = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+
+      delete_point = TRUE;
+    }
+  else
+    {
+      GimpImage *image  = gimp_display_get_image (display);
+      gint       width  = gimp_image_get_width  (image);
+      gint       height = gimp_image_get_height (image);
+
+      sp_tool->sample_point_x = floor (coords->x);
+      sp_tool->sample_point_y = floor (coords->y);
+
+      if (sp_tool->sample_point_x <  0      ||
+          sp_tool->sample_point_x >= height ||
+          sp_tool->sample_point_y <  0      ||
+          sp_tool->sample_point_y >= width)
+        {
+          delete_point = TRUE;
+        }
+    }
+
+  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+
+  gimp_tool_pop_status (tool, display);
+
+  if (delete_point)
+    {
+      gimp_tool_push_status (tool, display,
+                             sp_tool->sample_point ?
+                             _("Remove Sample Point") :
+                             _("Cancel Sample Point"));
+    }
+  else
+    {
+      gimp_tool_push_status_coords (tool, display,
+                                    gimp_tool_control_get_precision (tool->control),
+                                    sp_tool->sample_point ?
+                                    _("Move Sample Point: ") :
+                                    _("Add Sample Point: "),
+                                    sp_tool->sample_point_x,
+                                    ", ",
+                                    sp_tool->sample_point_x,
+                                    NULL);
+    }
+}
+
+static void
+gimp_sample_point_tool_draw (GimpDrawTool *draw_tool)
+{
+  GimpSamplePointTool *sp_tool = GIMP_SAMPLE_POINT_TOOL (draw_tool);
+
+  if (sp_tool->sample_point_x != GIMP_SAMPLE_POINT_POSITION_UNDEFINED &&
+      sp_tool->sample_point_y != GIMP_SAMPLE_POINT_POSITION_UNDEFINED)
+    {
+      gimp_draw_tool_add_crosshair (draw_tool,
+                                    sp_tool->sample_point_x,
+                                    sp_tool->sample_point_y);
+    }
+}
+
+static void
+gimp_sample_point_tool_start (GimpTool        *parent_tool,
+                              GimpDisplay     *display,
+                              GimpSamplePoint *sample_point)
+{
+  GimpSamplePointTool *sp_tool;
+  GimpTool            *tool;
+
+  sp_tool = g_object_new (GIMP_TYPE_SAMPLE_POINT_TOOL,
+                          "tool-info", parent_tool->tool_info,
+                          NULL);
+
+  tool = GIMP_TOOL (sp_tool);
+
+  gimp_display_shell_selection_pause (gimp_display_get_shell (display));
+
+  if (sample_point)
+    {
+      sp_tool->sample_point = sample_point;
+
+      gimp_sample_point_get_position (sample_point,
+                                      &sp_tool->sample_point_x,
+                                      &sp_tool->sample_point_y);
+    }
+  else
+    {
+      sp_tool->sample_point   = NULL;
+      sp_tool->sample_point_x = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+      sp_tool->sample_point_y = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
+    }
+
+  gimp_tool_set_cursor (tool, display,
+                        GIMP_CURSOR_MOUSE,
+                        GIMP_TOOL_CURSOR_COLOR_PICKER,
+                        GIMP_CURSOR_MODIFIER_MOVE);
+
+  tool_manager_push_tool (display->gimp, tool);
+
+  tool->display = display;
+  gimp_tool_control_activate (tool->control);
+
+  gimp_draw_tool_start (GIMP_DRAW_TOOL (sp_tool), display);
+
+  gimp_tool_push_status_coords (tool, display,
+                                gimp_tool_control_get_precision (tool->control),
+                                sample_point ?
+                                _("Move Sample Point: ") :
+                                _("Add Sample Point: "),
+                                sp_tool->sample_point_x,
+                                ", ",
+                                sp_tool->sample_point_y,
+                                NULL);
+}
+
+
+/*  public functions  */
+
+void
+gimp_sample_point_tool_start_new (GimpTool    *parent_tool,
+                                  GimpDisplay *display)
+{
+  g_return_if_fail (GIMP_IS_TOOL (parent_tool));
+  g_return_if_fail (GIMP_IS_DISPLAY (display));
+
+  gimp_sample_point_tool_start (parent_tool, display, NULL);
+}
+
+void
+gimp_sample_point_tool_start_edit (GimpTool        *parent_tool,
+                                   GimpDisplay     *display,
+                                   GimpSamplePoint *sample_point)
+{
+  g_return_if_fail (GIMP_IS_TOOL (parent_tool));
+  g_return_if_fail (GIMP_IS_DISPLAY (display));
+  g_return_if_fail (sample_point != NULL);
+
+  gimp_sample_point_tool_start (parent_tool, display, sample_point);
+}
diff --git a/app/tools/gimpsamplepointtool.h b/app/tools/gimpsamplepointtool.h
new file mode 100644
index 0000000..4e3a3d9
--- /dev/null
+++ b/app/tools/gimpsamplepointtool.h
@@ -0,0 +1,60 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_SAMPLE_POINT_TOOL_H__
+#define __GIMP_SAMPLE_POINT_TOOL_H__
+
+
+#include "gimpdrawtool.h"
+
+
+#define GIMP_TYPE_SAMPLE_POINT_TOOL            (gimp_sample_point_tool_get_type ())
+#define GIMP_SAMPLE_POINT_TOOL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIMP_TYPE_SAMPLE_POINT_TOOL, GimpSamplePointTool))
+#define GIMP_SAMPLE_POINT_TOOL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GIMP_TYPE_SAMPLE_POINT_TOOL, GimpSamplePointToolClass))
+#define GIMP_IS_SAMPLE_POINT_TOOL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GIMP_TYPE_SAMPLE_POINT_TOOL))
+#define GIMP_IS_SAMPLE_POINT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GIMP_TYPE_SAMPLE_POINT_TOOL))
+#define GIMP_SAMPLE_POINT_TOOL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GIMP_TYPE_SAMPLE_POINT_TOOL, GimpSamplePointToolClass))
+
+
+typedef struct _GimpSamplePointTool      GimpSamplePointTool;
+typedef struct _GimpSamplePointToolClass GimpSamplePointToolClass;
+
+struct _GimpSamplePointTool
+{
+  GimpDrawTool     parent_instance;
+
+  GimpSamplePoint *sample_point;
+  gint             sample_point_x;
+  gint             sample_point_y;
+};
+
+struct _GimpSamplePointToolClass
+{
+  GimpDrawToolClass  parent_class;
+};
+
+
+GType   gimp_sample_point_tool_get_type   (void) G_GNUC_CONST;
+
+void    gimp_sample_point_tool_start_new  (GimpTool        *parent_tool,
+                                           GimpDisplay     *display);
+void    gimp_sample_point_tool_start_edit (GimpTool        *parent_tool,
+                                           GimpDisplay     *display,
+                                           GimpSamplePoint *sample_point);
+
+
+#endif  /*  __GIMP_SAMPLE_POINT_TOOL_H__  */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d8bdd03..abbab92 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -392,6 +392,7 @@ app/tools/gimpforegroundselecttool.c
 app/tools/gimpfreeselecttool.c
 app/tools/gimpfuzzyselecttool.c
 app/tools/gimpgegltool.c
+app/tools/gimpguidetool.c
 app/tools/gimphandletransformoptions.c
 app/tools/gimphandletransformtool.c
 app/tools/gimphealtool.c
@@ -429,6 +430,7 @@ app/tools/gimprectangletool.c
 app/tools/gimpregionselectoptions.c
 app/tools/gimpregionselecttool.c
 app/tools/gimprotatetool.c
+app/tools/gimpsamplepointtool.c
 app/tools/gimpscaletool.c
 app/tools/gimpseamlesscloneoptions.c
 app/tools/gimpseamlessclonetool.c


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