Advertisement
Guest User

gimpmovetool.c

a guest
Mar 2nd, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 29.62 KB | None | 0 0
  1. /* GIMP - The GNU Image Manipulation Program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This program is free software: you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 3 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17.  
  18. #include "config.h"
  19.  
  20. #include <string.h>
  21.  
  22. #include <gegl.h>
  23. #include <gtk/gtk.h>
  24.  
  25. #include "libgimpmath/gimpmath.h"
  26. #include "libgimpwidgets/gimpwidgets.h"
  27.  
  28. #include "tools-types.h"
  29.  
  30. #include "config/gimpdisplayconfig.h"
  31. #include "config/gimpguiconfig.h"
  32.  
  33. #include "core/gimp.h"
  34. #include "core/gimpguide.h"
  35. #include "core/gimpdrawable.h" 
  36. #include "core/gimperror.h"
  37. #include "core/gimpimage.h"
  38. #include "core/gimpimage-guides.h"
  39. #include "core/gimpimage-pick-layer.h"
  40. #include "core/gimplayer.h"
  41. #include "core/gimpimage-undo.h"
  42. #include "core/gimplayermask.h"
  43. #include "core/gimplayer-floating-sel.h"
  44. #include "core/gimpundostack.h"
  45.  
  46. #include "widgets/gimphelp-ids.h"
  47. #include "widgets/gimpwidgets-utils.h"
  48.  
  49. #include "display/gimpcanvasitem.h"
  50. #include "display/gimpdisplay.h"
  51. #include "display/gimpdisplayshell.h"
  52. #include "display/gimpdisplayshell-appearance.h"
  53. #include "display/gimpdisplayshell-selection.h"
  54. #include "display/gimpdisplayshell-transform.h"
  55.  
  56. #include "gimpeditselectiontool.h"
  57. #include "gimpmoveoptions.h"
  58. #include "gimpmovetool.h"
  59. #include "gimptoolcontrol.h"
  60.  
  61. #include "gimp-intl.h"
  62.  
  63.  
  64. #define GUIDE_POSITION_INVALID G_MININT
  65.  
  66. #define SWAP_ORIENT(orient) ((orient) == GIMP_ORIENTATION_HORIZONTAL ? \
  67.                              GIMP_ORIENTATION_VERTICAL : \
  68.                              GIMP_ORIENTATION_HORIZONTAL)
  69.  
  70.  
  71. /*  local function prototypes  */
  72.  
  73. static void   gimp_move_tool_button_press   (GimpTool              *tool,
  74.                                              const GimpCoords      *coords,
  75.                                              guint32                time,
  76.                                              GdkModifierType        state,
  77.                                              GimpButtonPressType    press_type,
  78.                                              GimpDisplay           *display);
  79. static void   gimp_move_tool_button_release (GimpTool              *tool,
  80.                                              const GimpCoords      *coords,
  81.                                              guint32                time,
  82.                                              GdkModifierType        state,
  83.                                              GimpButtonReleaseType  release_type,
  84.                                              GimpDisplay           *display);
  85. static void   gimp_move_tool_motion         (GimpTool              *tool,
  86.                                              const GimpCoords      *coords,
  87.                                              guint32                time,
  88.                                              GdkModifierType        state,
  89.                                              GimpDisplay           *display);
  90. static gboolean gimp_move_tool_key_press    (GimpTool              *tool,
  91.                                              GdkEventKey           *kevent,
  92.                                              GimpDisplay           *display);
  93. static void   gimp_move_tool_modifier_key   (GimpTool              *tool,
  94.                                              GdkModifierType        key,
  95.                                              gboolean               press,
  96.                                              GdkModifierType        state,
  97.                                              GimpDisplay           *display);
  98. static void   gimp_move_tool_oper_update    (GimpTool              *tool,
  99.                                              const GimpCoords      *coords,
  100.                                              GdkModifierType        state,
  101.                                              gboolean               proximity,
  102.                                              GimpDisplay           *display);
  103. static void   gimp_move_tool_cursor_update  (GimpTool              *tool,
  104.                                              const GimpCoords      *coords,
  105.                                              GdkModifierType        state,
  106.                                              GimpDisplay           *display);
  107.  
  108. static void   gimp_move_tool_draw           (GimpDrawTool          *draw_tool);
  109.  
  110. static void   gimp_move_tool_start_guide    (GimpMoveTool          *move,
  111.                                              GimpDisplay           *display,
  112.                                              GimpOrientationType    orientation);
  113.  
  114.  
  115. G_DEFINE_TYPE (GimpMoveTool, gimp_move_tool, GIMP_TYPE_DRAW_TOOL)
  116.  
  117. #define parent_class gimp_move_tool_parent_class
  118.  
  119.  
  120. void
  121. gimp_move_tool_register (GimpToolRegisterCallback  callback,
  122.                          gpointer                  data)
  123. {
  124.   (* callback) (GIMP_TYPE_MOVE_TOOL,
  125.                 GIMP_TYPE_MOVE_OPTIONS,
  126.                 gimp_move_options_gui,
  127.                 0,
  128.                 "gimp-move-tool",
  129.                 C_("tool", "Move"),
  130.                 _("Move Tool: Move layers, selections, and other objects"),
  131.                 N_("_Move"), "M",
  132.                 NULL, GIMP_HELP_TOOL_MOVE,
  133.                 GIMP_STOCK_TOOL_MOVE,
  134.                 data);
  135. }
  136.  
  137. static void
  138. gimp_move_tool_class_init (GimpMoveToolClass *klass)
  139. {
  140.   GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
  141.   GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
  142.  
  143.   tool_class->button_press   = gimp_move_tool_button_press;
  144.   tool_class->button_release = gimp_move_tool_button_release;
  145.   tool_class->motion         = gimp_move_tool_motion;
  146.   tool_class->key_press      = gimp_move_tool_key_press;
  147.   tool_class->modifier_key   = gimp_move_tool_modifier_key;
  148.   tool_class->oper_update    = gimp_move_tool_oper_update;
  149.   tool_class->cursor_update  = gimp_move_tool_cursor_update;
  150.  
  151.   draw_tool_class->draw      = gimp_move_tool_draw;
  152. }
  153.  
  154. static void
  155. gimp_move_tool_init (GimpMoveTool *move_tool)
  156. {
  157.   GimpTool *tool = GIMP_TOOL (move_tool);
  158.  
  159.   gimp_tool_control_set_motion_mode        (tool->control,
  160.                                             GIMP_MOTION_MODE_COMPRESS);
  161.   gimp_tool_control_set_snap_to            (tool->control, FALSE);
  162.   gimp_tool_control_set_handle_empty_image (tool->control, TRUE);
  163.   gimp_tool_control_set_tool_cursor        (tool->control,
  164.                                             GIMP_TOOL_CURSOR_MOVE);
  165.  
  166.   move_tool->floating_layer     = NULL;
  167.   move_tool->guide              = NULL;
  168.  
  169.   move_tool->moving_guide       = FALSE;
  170.   move_tool->guide_position     = GUIDE_POSITION_INVALID;
  171.   move_tool->guide_orientation  = GIMP_ORIENTATION_UNKNOWN;
  172.  
  173.   move_tool->saved_type         = GIMP_TRANSFORM_TYPE_LAYER;
  174.  
  175.   move_tool->old_active_layer   = NULL;
  176.   move_tool->old_active_vectors = NULL;
  177. }
  178.  
  179. static void
  180. gimp_move_tool_button_press (GimpTool            *tool,
  181.                              const GimpCoords    *coords,
  182.                              guint32              time,
  183.                              GdkModifierType      state,
  184.                              GimpButtonPressType  press_type,
  185.                              GimpDisplay         *display)
  186. {
  187.   GimpMoveTool     *move    = GIMP_MOVE_TOOL (tool);
  188.   GimpMoveOptions  *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
  189.   GimpDisplayShell *shell   = gimp_display_get_shell (display);
  190.   GimpImage        *image   = gimp_display_get_image (display);
  191.   GimpDrawable     *drawable = gimp_image_get_active_drawable (image);
  192.  
  193.   tool->display = display;
  194.  
  195.   move->floating_layer     = NULL;
  196.   move->guide              = NULL;
  197.   move->moving_guide       = FALSE;
  198.   move->old_active_layer   = NULL;
  199.   move->old_active_vectors = NULL;
  200.  
  201.  
  202.   if (! options->move_current)
  203.     {
  204.       if (options->move_type == GIMP_TRANSFORM_TYPE_PATH)
  205.         {
  206.           GimpVectors *vectors;
  207.  
  208.           if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
  209.                                          coords, 7, 7,
  210.                                          NULL, NULL, NULL, NULL, NULL,
  211.                                          &vectors))
  212.             {
  213.               move->old_active_vectors =
  214.                 gimp_image_get_active_vectors (image);
  215.  
  216.               gimp_image_set_active_vectors (image, vectors);
  217.             }
  218.           else
  219.             {
  220.               /*  no path picked  */
  221.               return;
  222.             }
  223.         }
  224.       else if (options->move_type == GIMP_TRANSFORM_TYPE_LAYER)
  225.         {
  226.           GimpGuide  *guide;
  227.           GimpLayer  *layer;
  228.           const gint  snap_distance = display->config->snap_distance;
  229.  
  230.           if (gimp_display_shell_get_show_guides (shell) &&
  231.               (guide = gimp_image_find_guide (image,
  232.                                               coords->x, coords->y,
  233.                                               FUNSCALEX (shell, snap_distance),
  234.                                               FUNSCALEY (shell, snap_distance))))
  235.             {
  236.               move->guide             = guide;
  237.               move->moving_guide      = TRUE;
  238.               move->guide_position    = gimp_guide_get_position (guide);
  239.               move->guide_orientation = gimp_guide_get_orientation (guide);
  240.  
  241.               gimp_tool_control_set_scroll_lock (tool->control, TRUE);
  242.               gimp_tool_control_set_precision   (tool->control,
  243.                                                  GIMP_CURSOR_PRECISION_PIXEL_BORDER);
  244.  
  245.               gimp_tool_control_activate (tool->control);
  246.  
  247.               gimp_display_shell_selection_pause (shell);
  248.  
  249.               if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
  250.                 gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
  251.  
  252.               gimp_tool_push_status_length (tool, display,
  253.                                             _("Move Guide: "),
  254.                                             SWAP_ORIENT (move->guide_orientation),
  255.                                             move->guide_position,
  256.                                             NULL);
  257.  
  258.               return;
  259.             }
  260.           else if ((layer = gimp_image_pick_layer (image,
  261.                                                    coords->x,
  262.                                                    coords->y)))
  263.             {
  264.               if (gimp_image_get_floating_selection (image) &&
  265.                   ! gimp_layer_is_floating_sel (layer))
  266.                 {
  267.                   /*  If there is a floating selection, and this aint it,
  268.                    *  use the move tool to anchor it.
  269.                    */
  270.                   move->floating_layer =
  271.                     gimp_image_get_floating_selection (image);
  272.  
  273.                   gimp_tool_control_activate (tool->control);
  274.  
  275.                   return;
  276.                 }
  277.               else
  278.                 {
  279.                   move->old_active_layer = gimp_image_get_active_layer (image);
  280.  
  281.                   gimp_image_set_active_layer (image, layer);
  282.                 }
  283.             }
  284.           else
  285.             {
  286.               /*  no guide and no layer picked  */
  287.  
  288.               return;
  289.             }
  290.         }
  291.     }
  292.  
  293.  
  294.  
  295.   switch (options->move_type)
  296.     {
  297.     case GIMP_TRANSFORM_TYPE_PATH:
  298.       if (gimp_image_get_active_vectors (image))
  299.         {
  300.           gimp_tool_control_activate (tool->control);
  301.           gimp_edit_selection_tool_start (tool, display, coords,
  302.                                           GIMP_TRANSLATE_MODE_VECTORS, TRUE);
  303.         }
  304.       break;
  305.  
  306.     case GIMP_TRANSFORM_TYPE_SELECTION:
  307.       if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
  308.         {
  309.           gimp_tool_control_activate (tool->control);
  310.           gimp_edit_selection_tool_start (tool, display, coords,
  311.                                           GIMP_TRANSLATE_MODE_MASK, TRUE);
  312.         }
  313.       break;
  314.  
  315.     case GIMP_TRANSFORM_TYPE_LAYER:
  316.       {
  317.         GimpDrawable *drawable = gimp_image_get_active_drawable (image);
  318.  
  319.         if (GIMP_IS_LAYER_MASK (drawable))
  320.           {
  321.             gimp_tool_control_activate (tool->control);
  322.             gimp_edit_selection_tool_start (tool, display, coords,
  323.                                             GIMP_TRANSLATE_MODE_LAYER_MASK, TRUE);
  324.           }
  325.         else if (GIMP_IS_CHANNEL (drawable))
  326.           {
  327.             gimp_tool_control_activate (tool->control);
  328.             gimp_edit_selection_tool_start (tool, display, coords,
  329.                                             GIMP_TRANSLATE_MODE_CHANNEL, TRUE);
  330.           }
  331.         else if (GIMP_IS_LAYER (drawable))
  332.           {
  333.                 if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
  334.                     {
  335.                     gimp_tool_message_literal (tool, display,
  336.                                  _("The active layer's pixels are locked."));
  337.                     return;
  338.                     }
  339.             else
  340.             {
  341.                 gimp_tool_control_activate (tool->control);
  342.                 gimp_edit_selection_tool_start (tool, display, coords,
  343.                                             GIMP_TRANSLATE_MODE_LAYER, TRUE);
  344.                         }          
  345.           }
  346.       }
  347.       break;
  348.     }
  349. }
  350.  
  351. static void
  352. gimp_move_tool_button_release (GimpTool              *tool,
  353.                                const GimpCoords      *coords,
  354.                                guint32                time,
  355.                                GdkModifierType        state,
  356.                                GimpButtonReleaseType  release_type,
  357.                                GimpDisplay           *display)
  358. {
  359.   GimpMoveTool     *move   = GIMP_MOVE_TOOL (tool);
  360.   GimpGuiConfig    *config = GIMP_GUI_CONFIG (display->gimp->config);
  361.   GimpDisplayShell *shell  = gimp_display_get_shell (display);
  362.   GimpImage        *image  = gimp_display_get_image (display);
  363.  
  364.   gimp_tool_control_halt (tool->control);
  365.  
  366.   if (move->moving_guide)
  367.     {
  368.       gboolean delete_guide = FALSE;
  369.       gint     x, y, width, height;
  370.  
  371.       gimp_tool_pop_status (tool, display);
  372.  
  373.       gimp_tool_control_set_scroll_lock (tool->control, FALSE);
  374.       gimp_tool_control_set_precision   (tool->control,
  375.                                          GIMP_CURSOR_PRECISION_PIXEL_CENTER);
  376.  
  377.       gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
  378.  
  379.       if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
  380.         {
  381.           move->moving_guide      = FALSE;
  382.           move->guide_position    = GUIDE_POSITION_INVALID;
  383.           move->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
  384.  
  385.           gimp_display_shell_selection_resume (shell);
  386.           return;
  387.         }
  388.  
  389.       gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
  390.  
  391.       switch (move->guide_orientation)
  392.         {
  393.         case GIMP_ORIENTATION_HORIZONTAL:
  394.           if ((move->guide_position < y) ||
  395.               (move->guide_position > (y + height)))
  396.             delete_guide = TRUE;
  397.           break;
  398.  
  399.         case GIMP_ORIENTATION_VERTICAL:
  400.           if ((move->guide_position < x) ||
  401.               (move->guide_position > (x + width)))
  402.             delete_guide = TRUE;
  403.           break;
  404.  
  405.         default:
  406.           break;
  407.         }
  408.  
  409.       if (delete_guide)
  410.         {
  411.           if (move->guide)
  412.             {
  413.               gimp_image_remove_guide (image, move->guide, TRUE);
  414.               move->guide = NULL;
  415.             }
  416.         }
  417.       else
  418.         {
  419.           if (move->guide)
  420.             {
  421.               gimp_image_move_guide (image, move->guide,
  422.                                      move->guide_position, TRUE);
  423.             }
  424.           else
  425.             {
  426.               switch (move->guide_orientation)
  427.                 {
  428.                 case GIMP_ORIENTATION_HORIZONTAL:
  429.                   move->guide = gimp_image_add_hguide (image,
  430.                                                        move->guide_position,
  431.                                                        TRUE);
  432.                   break;
  433.  
  434.                 case GIMP_ORIENTATION_VERTICAL:
  435.                   move->guide = gimp_image_add_vguide (image,
  436.                                                        move->guide_position,
  437.                                                        TRUE);
  438.                   break;
  439.  
  440.                 default:
  441.                   g_assert_not_reached ();
  442.                 }
  443.             }
  444.         }
  445.  
  446.       gimp_display_shell_selection_resume (shell);
  447.       gimp_image_flush (image);
  448.  
  449.       move->moving_guide      = FALSE;
  450.       move->guide_position    = GUIDE_POSITION_INVALID;
  451.       move->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
  452.  
  453.       if (move->guide)
  454.         gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
  455.     }
  456.   else
  457.     {
  458.       gboolean flush = FALSE;
  459.  
  460.       if (! config->move_tool_changes_active ||
  461.           (release_type == GIMP_BUTTON_RELEASE_CANCEL))
  462.         {
  463.           if (move->old_active_layer)
  464.             {
  465.               gimp_image_set_active_layer (image, move->old_active_layer);
  466.               move->old_active_layer = NULL;
  467.  
  468.               flush = TRUE;
  469.             }
  470.  
  471.           if (move->old_active_vectors)
  472.             {
  473.               gimp_image_set_active_vectors (image, move->old_active_vectors);
  474.               move->old_active_vectors = NULL;
  475.  
  476.               flush = TRUE;
  477.             }
  478.         }
  479.  
  480.       if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
  481.         {
  482.           if (move->floating_layer)
  483.             {
  484.               floating_sel_anchor (move->floating_layer);
  485.  
  486.               flush = TRUE;
  487.             }
  488.         }
  489.  
  490.       if (flush)
  491.         gimp_image_flush (image);
  492.     }
  493. }
  494.  
  495. static void
  496. gimp_move_tool_motion (GimpTool         *tool,
  497.                        const GimpCoords *coords,
  498.                        guint32           time,
  499.                        GdkModifierType   state,
  500.                        GimpDisplay      *display)
  501.  
  502. {
  503.   GimpMoveTool     *move  = GIMP_MOVE_TOOL (tool);
  504.   GimpDisplayShell *shell = gimp_display_get_shell (display);
  505.  
  506.   if (move->moving_guide)
  507.     {
  508.       gint      tx, ty;
  509.       gboolean  delete_guide = FALSE;
  510.  
  511.       gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
  512.  
  513.       gimp_display_shell_transform_xy (shell,
  514.                                        coords->x, coords->y,
  515.                                        &tx, &ty);
  516.  
  517.       if (tx < 0 || tx >= shell->disp_width ||
  518.           ty < 0 || ty >= shell->disp_height)
  519.         {
  520.           move->guide_position = GUIDE_POSITION_INVALID;
  521.  
  522.           delete_guide = TRUE;
  523.         }
  524.       else
  525.         {
  526.           gint x, y, width, height;
  527.  
  528.           if (move->guide_orientation == GIMP_ORIENTATION_HORIZONTAL)
  529.             move->guide_position = RINT (coords->y);
  530.           else
  531.             move->guide_position = RINT (coords->x);
  532.  
  533.           gimp_display_shell_untransform_viewport (shell, &x, &y,
  534.                                                    &width, &height);
  535.  
  536.           switch (move->guide_orientation)
  537.             {
  538.             case GIMP_ORIENTATION_HORIZONTAL:
  539.               if ((move->guide_position < y) ||
  540.                   (move->guide_position > (y + height)))
  541.                 delete_guide = TRUE;
  542.               break;
  543.  
  544.             case GIMP_ORIENTATION_VERTICAL:
  545.               if ((move->guide_position < x) ||
  546.                   (move->guide_position > (x + width)))
  547.                 delete_guide = TRUE;
  548.               break;
  549.  
  550.             default:
  551.               break;
  552.             }
  553.         }
  554.  
  555.       gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
  556.  
  557.       gimp_tool_pop_status (tool, display);
  558.  
  559.       if (delete_guide)
  560.         {
  561.           gimp_tool_push_status (tool, display,
  562.                                  move->guide ?
  563.                                  _("Remove Guide") : _("Cancel Guide"));
  564.         }
  565.       else
  566.         {
  567.           gimp_tool_push_status_length (tool, display,
  568.                                         move->guide ?
  569.                                         _("Move Guide: ") : _("Add Guide: "),
  570.                                         SWAP_ORIENT (move->guide_orientation),
  571.                                         move->guide_position,
  572.                                         NULL);
  573.         }
  574.     }
  575. }
  576.  
  577. static gboolean
  578. gimp_move_tool_key_press (GimpTool    *tool,
  579.                           GdkEventKey *kevent,
  580.                           GimpDisplay *display)
  581. {
  582.   GimpMoveOptions *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
  583.  
  584.   return gimp_edit_selection_tool_translate (tool, kevent,
  585.                                              options->move_type,
  586.                                              display);
  587. }
  588.  
  589. static void
  590. gimp_move_tool_modifier_key (GimpTool        *tool,
  591.                              GdkModifierType  key,
  592.                              gboolean         press,
  593.                              GdkModifierType  state,
  594.                              GimpDisplay     *display)
  595. {
  596.   GimpMoveTool    *move    = GIMP_MOVE_TOOL (tool);
  597.   GimpMoveOptions *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
  598.  
  599.   if (key == GDK_SHIFT_MASK)
  600.     {
  601.       g_object_set (options, "move-current", ! options->move_current, NULL);
  602.     }
  603.   else if (key == GDK_MOD1_MASK ||
  604.            key == gimp_get_toggle_behavior_mask ())
  605.     {
  606.       GimpTransformType button_type;
  607.  
  608.       button_type = options->move_type;
  609.  
  610.       if (press)
  611.         {
  612.           if (key == (state & (GDK_MOD1_MASK |
  613.                                gimp_get_toggle_behavior_mask ())))
  614.             {
  615.               /*  first modifier pressed  */
  616.  
  617.               move->saved_type = options->move_type;
  618.             }
  619.         }
  620.       else
  621.         {
  622.           if (! (state & (GDK_MOD1_MASK |
  623.                           gimp_get_toggle_behavior_mask ())))
  624.             {
  625.               /*  last modifier released  */
  626.  
  627.               button_type = move->saved_type;
  628.             }
  629.         }
  630.  
  631.       if (state & GDK_MOD1_MASK)
  632.         {
  633.           button_type = GIMP_TRANSFORM_TYPE_SELECTION;
  634.         }
  635.       else if (state & gimp_get_toggle_behavior_mask ())
  636.         {
  637.           button_type = GIMP_TRANSFORM_TYPE_PATH;
  638.         }
  639.  
  640.       if (button_type != options->move_type)
  641.         {
  642.           g_object_set (options, "move-type", button_type, NULL);
  643.         }
  644.     }
  645. }
  646.  
  647. static void
  648. gimp_move_tool_oper_update (GimpTool         *tool,
  649.                             const GimpCoords *coords,
  650.                             GdkModifierType   state,
  651.                             gboolean          proximity,
  652.                             GimpDisplay      *display)
  653. {
  654.   GimpMoveTool     *move    = GIMP_MOVE_TOOL (tool);
  655.   GimpMoveOptions  *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
  656.   GimpDisplayShell *shell   = gimp_display_get_shell (display);
  657.   GimpImage        *image   = gimp_display_get_image (display);
  658.   GimpGuide        *guide   = NULL;
  659.  
  660.   if (options->move_type == GIMP_TRANSFORM_TYPE_LAYER &&
  661.       ! options->move_current                         &&
  662.       gimp_display_shell_get_show_guides (shell)      &&
  663.       proximity)
  664.     {
  665.       gint snap_distance = display->config->snap_distance;
  666.  
  667.       guide = gimp_image_find_guide (image, coords->x, coords->y,
  668.                                      FUNSCALEX (shell, snap_distance),
  669.                                      FUNSCALEY (shell, snap_distance));
  670.     }
  671.  
  672.   if (move->guide != guide)
  673.     {
  674.       GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
  675.  
  676.       gimp_draw_tool_pause (draw_tool);
  677.  
  678.       if (gimp_draw_tool_is_active (draw_tool) &&
  679.           draw_tool->display != display)
  680.         gimp_draw_tool_stop (draw_tool);
  681.  
  682.       move->guide = guide;
  683.  
  684.       if (! gimp_draw_tool_is_active (draw_tool))
  685.         gimp_draw_tool_start (draw_tool, display);
  686.  
  687.       gimp_draw_tool_resume (draw_tool);
  688.     }
  689. }
  690.  
  691. static void
  692. gimp_move_tool_cursor_update (GimpTool         *tool,
  693.                               const GimpCoords *coords,
  694.                               GdkModifierType   state,
  695.                               GimpDisplay      *display)
  696. {
  697.   GimpMoveOptions    *options     = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
  698.   GimpDisplayShell   *shell       = gimp_display_get_shell (display);
  699.   GimpImage          *image       = gimp_display_get_image (display);
  700.   GimpCursorType      cursor      = GIMP_CURSOR_MOUSE;
  701.   GimpToolCursorType  tool_cursor = GIMP_TOOL_CURSOR_MOVE;
  702.   GimpCursorModifier  modifier    = GIMP_CURSOR_MODIFIER_NONE;
  703.  
  704.   if (options->move_type == GIMP_TRANSFORM_TYPE_PATH)
  705.     {
  706.       tool_cursor = GIMP_TOOL_CURSOR_PATHS;
  707.       modifier    = GIMP_CURSOR_MODIFIER_MOVE;
  708.  
  709.       if (options->move_current)
  710.         {
  711.           if (! gimp_image_get_active_vectors (image))
  712.             modifier = GIMP_CURSOR_MODIFIER_BAD;
  713.         }
  714.       else
  715.         {
  716.           if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
  717.                                          coords, 7, 7,
  718.                                          NULL, NULL, NULL, NULL, NULL, NULL))
  719.             {
  720.               tool_cursor = GIMP_TOOL_CURSOR_HAND;
  721.             }
  722.           else
  723.             {
  724.               modifier = GIMP_CURSOR_MODIFIER_BAD;
  725.             }
  726.         }
  727.     }
  728.   else if (options->move_type == GIMP_TRANSFORM_TYPE_SELECTION)
  729.     {
  730.       tool_cursor = GIMP_TOOL_CURSOR_RECT_SELECT;
  731.       modifier    = GIMP_CURSOR_MODIFIER_MOVE;
  732.  
  733.       if (gimp_channel_is_empty (gimp_image_get_mask (image)))
  734.         modifier = GIMP_CURSOR_MODIFIER_BAD;
  735.     }
  736.   else if (options->move_current)
  737.     {
  738.       if (! gimp_image_get_active_drawable (image))
  739.         modifier = GIMP_CURSOR_MODIFIER_BAD;
  740.     }
  741.   else
  742.     {
  743.       GimpGuide  *guide;
  744.       GimpLayer  *layer;
  745.       const gint  snap_distance = display->config->snap_distance;
  746.  
  747.       if (gimp_display_shell_get_show_guides (shell) &&
  748.           (guide = gimp_image_find_guide (image, coords->x, coords->y,
  749.                                           FUNSCALEX (shell, snap_distance),
  750.                                           FUNSCALEY (shell, snap_distance))))
  751.         {
  752.           tool_cursor = GIMP_TOOL_CURSOR_HAND;
  753.           modifier    = GIMP_CURSOR_MODIFIER_MOVE;
  754.         }
  755.       else if ((layer = gimp_image_pick_layer (image,
  756.                                                coords->x, coords->y)))
  757.         {
  758.           /*  if there is a floating selection, and this aint it...  */
  759.           if (gimp_image_get_floating_selection (image) &&
  760.               ! gimp_layer_is_floating_sel (layer))
  761.             {
  762.               tool_cursor = GIMP_TOOL_CURSOR_MOVE;
  763.               modifier    = GIMP_CURSOR_MODIFIER_ANCHOR;
  764.             }
  765.           else if (layer != gimp_image_get_active_layer (image))
  766.             {
  767.               tool_cursor = GIMP_TOOL_CURSOR_HAND;
  768.               modifier    = GIMP_CURSOR_MODIFIER_MOVE;
  769.             }
  770.         }
  771.       else
  772.         {
  773.           modifier = GIMP_CURSOR_MODIFIER_BAD;
  774.         }
  775.     }
  776.  
  777.   gimp_tool_control_set_cursor          (tool->control, cursor);
  778.   gimp_tool_control_set_tool_cursor     (tool->control, tool_cursor);
  779.   gimp_tool_control_set_cursor_modifier (tool->control, modifier);
  780.  
  781.   GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
  782. }
  783.  
  784. static void
  785. gimp_move_tool_draw (GimpDrawTool *draw_tool)
  786. {
  787.   GimpMoveTool *move = GIMP_MOVE_TOOL (draw_tool);
  788.  
  789.   if (move->guide)
  790.     {
  791.       GimpCanvasItem *item;
  792.  
  793.       item = gimp_draw_tool_add_guide (draw_tool,
  794.                                        gimp_guide_get_orientation (move->guide),
  795.                                        gimp_guide_get_position (move->guide),
  796.                                        TRUE);
  797.       gimp_canvas_item_set_highlight (item, TRUE);
  798.     }
  799.  
  800.   if (move->moving_guide && move->guide_position != GUIDE_POSITION_INVALID)
  801.     {
  802.       gimp_draw_tool_add_guide (draw_tool,
  803.                                 move->guide_orientation,
  804.                                 move->guide_position,
  805.                                 FALSE);
  806.     }
  807. }
  808.  
  809. void
  810. gimp_move_tool_start_hguide (GimpTool    *tool,
  811.                              GimpDisplay *display)
  812. {
  813.   g_return_if_fail (GIMP_IS_MOVE_TOOL (tool));
  814.   g_return_if_fail (GIMP_IS_DISPLAY (display));
  815.  
  816.   gimp_move_tool_start_guide (GIMP_MOVE_TOOL (tool), display,
  817.                               GIMP_ORIENTATION_HORIZONTAL);
  818. }
  819.  
  820. void
  821. gimp_move_tool_start_vguide (GimpTool    *tool,
  822.                              GimpDisplay *display)
  823. {
  824.   g_return_if_fail (GIMP_IS_MOVE_TOOL (tool));
  825.   g_return_if_fail (GIMP_IS_DISPLAY (display));
  826.  
  827.   gimp_move_tool_start_guide (GIMP_MOVE_TOOL (tool), display,
  828.                               GIMP_ORIENTATION_VERTICAL);
  829. }
  830.  
  831. static void
  832. gimp_move_tool_start_guide (GimpMoveTool        *move,
  833.                             GimpDisplay         *display,
  834.                             GimpOrientationType  orientation)
  835. {
  836.   GimpTool *tool = GIMP_TOOL (move);
  837.  
  838.   gimp_display_shell_selection_pause (gimp_display_get_shell (display));
  839.  
  840.   tool->display = display;
  841.   gimp_tool_control_activate (tool->control);
  842.   gimp_tool_control_set_scroll_lock (tool->control, TRUE);
  843.  
  844.   if (gimp_draw_tool_is_active  (GIMP_DRAW_TOOL (tool)))
  845.     gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
  846.  
  847.   move->guide             = NULL;
  848.   move->moving_guide      = TRUE;
  849.   move->guide_position    = GUIDE_POSITION_INVALID;
  850.   move->guide_orientation = orientation;
  851.  
  852.   gimp_tool_set_cursor (tool, display,
  853.                         GIMP_CURSOR_MOUSE,
  854.                         GIMP_TOOL_CURSOR_HAND,
  855.                         GIMP_CURSOR_MODIFIER_MOVE);
  856.  
  857.   gimp_draw_tool_start (GIMP_DRAW_TOOL (move), display);
  858. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement