added an API to specify a "snap_offset" and a "snap_width/height". Needed
2003-04-17 Michael Natterer <mitch@gimp.org> * app/tools/gimptoolcontrol.[ch]: added an API to specify a "snap_offset" and a "snap_width/height". Needed for tools which want to snap to a rectangle and/or a position which is not the current cursor position. * app/display/gimpdisplayshell.[ch]: removed gimp_display_shell_find_guide(), gimp_display_shell_snap_point() and gimp_display_shell_snap_rectangle(). Added gimp_display_shell_snap_coords() which works on GimpCoords and gets passed the above snap offsets. * app/display/gimpdisplayshell-callbacks.c: use the new snap function, using the values from GimpToolControl. * app/tools/gimpcroptool.c: set snap offsets so the handles can be guide-aligned after creating. Fixes bug #110957. * app/tools/gimpeditselectiontool.c: removed snapping code (which was broken anyway) and set appropriate snap offsets in init_edit_selection().
This commit is contained in:
parent
1e55c4480e
commit
d5edd5308e
10 changed files with 301 additions and 278 deletions
23
ChangeLog
23
ChangeLog
|
|
@ -1,3 +1,26 @@
|
|||
2003-04-17 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/tools/gimptoolcontrol.[ch]: added an API to specify a
|
||||
"snap_offset" and a "snap_width/height". Needed for tools which
|
||||
want to snap to a rectangle and/or a position which is not the
|
||||
current cursor position.
|
||||
|
||||
* app/display/gimpdisplayshell.[ch]: removed
|
||||
gimp_display_shell_find_guide(), gimp_display_shell_snap_point()
|
||||
and gimp_display_shell_snap_rectangle().
|
||||
Added gimp_display_shell_snap_coords() which works on GimpCoords
|
||||
and gets passed the above snap offsets.
|
||||
|
||||
* app/display/gimpdisplayshell-callbacks.c: use the new snap
|
||||
function, using the values from GimpToolControl.
|
||||
|
||||
* app/tools/gimpcroptool.c: set snap offsets so the handles can be
|
||||
guide-aligned after creating. Fixes bug #110957.
|
||||
|
||||
* app/tools/gimpeditselectiontool.c: removed snapping code (which
|
||||
was broken anyway) and set appropriate snap offsets in
|
||||
init_edit_selection().
|
||||
|
||||
2003-04-16 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/print/gimp_main_window.c: 64-bit cleaniless cleanup.
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "core/gimpcontainer.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-guides.h"
|
||||
#include "core/gimpimage-qmask.h"
|
||||
#include "core/gimplayer.h"
|
||||
#include "core/gimptoolinfo.h"
|
||||
|
|
@ -581,15 +582,15 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
|
|||
{
|
||||
if (gimp_tool_control_auto_snap_to (active_tool->control))
|
||||
{
|
||||
gimp_display_shell_snap_point (shell,
|
||||
display_coords.x,
|
||||
display_coords.y,
|
||||
&display_coords.x,
|
||||
&display_coords.y);
|
||||
gint x, y, width, height;
|
||||
|
||||
gimp_display_shell_untransform_coords (shell,
|
||||
&display_coords,
|
||||
&image_coords);
|
||||
gimp_tool_control_snap_offsets (active_tool->control,
|
||||
&x, &y, &width, &height);
|
||||
|
||||
gimp_display_shell_snap_coords (shell,
|
||||
&image_coords,
|
||||
&image_coords,
|
||||
x, y, width, height);
|
||||
|
||||
update_cursor = TRUE;
|
||||
}
|
||||
|
|
@ -669,15 +670,15 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
|
|||
{
|
||||
if (gimp_tool_control_auto_snap_to (active_tool->control))
|
||||
{
|
||||
gimp_display_shell_snap_point (shell,
|
||||
display_coords.x,
|
||||
display_coords.y,
|
||||
&display_coords.x,
|
||||
&display_coords.y);
|
||||
gint x, y, width, height;
|
||||
|
||||
gimp_display_shell_untransform_coords (shell,
|
||||
&display_coords,
|
||||
&image_coords);
|
||||
gimp_tool_control_snap_offsets (active_tool->control,
|
||||
&x, &y, &width, &height);
|
||||
|
||||
gimp_display_shell_snap_coords (shell,
|
||||
&image_coords,
|
||||
&image_coords,
|
||||
x, y, width, height);
|
||||
|
||||
update_cursor = TRUE;
|
||||
}
|
||||
|
|
@ -900,15 +901,15 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
|
|||
|
||||
if (gimp_tool_control_auto_snap_to (active_tool->control))
|
||||
{
|
||||
gimp_display_shell_snap_point (shell,
|
||||
display_coords.x,
|
||||
display_coords.y,
|
||||
&display_coords.x,
|
||||
&display_coords.y);
|
||||
gint x, y, width, height;
|
||||
|
||||
gimp_display_shell_untransform_coords (shell,
|
||||
&display_coords,
|
||||
&image_coords);
|
||||
gimp_tool_control_snap_offsets (active_tool->control,
|
||||
&x, &y, &width, &height);
|
||||
|
||||
gimp_display_shell_snap_coords (shell,
|
||||
&image_coords,
|
||||
&image_coords,
|
||||
x, y, width, height);
|
||||
|
||||
update_cursor = TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -929,114 +929,49 @@ gimp_display_shell_scrolled (GimpDisplayShell *shell)
|
|||
g_signal_emit (shell, display_shell_signals[SCROLLED], 0);
|
||||
}
|
||||
|
||||
GimpGuide *
|
||||
gimp_display_shell_find_guide (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
void
|
||||
gimp_display_shell_snap_coords (GimpDisplayShell *shell,
|
||||
GimpCoords *coords,
|
||||
GimpCoords *snapped_coords,
|
||||
gint snap_offset_x,
|
||||
gint snap_offset_y,
|
||||
gint snap_width,
|
||||
gint snap_height)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
|
||||
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
||||
g_return_if_fail (coords != NULL);
|
||||
g_return_if_fail (snapped_coords != NULL);
|
||||
|
||||
if (gimp_display_shell_get_show_guides (shell))
|
||||
{
|
||||
gdouble image_x, image_y;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x, y,
|
||||
&image_x, &image_y,
|
||||
TRUE);
|
||||
|
||||
return gimp_image_find_guide (shell->gdisp->gimage,
|
||||
(gint) image_x,
|
||||
(gint) image_y);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_display_shell_snap_point (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble *tx,
|
||||
gdouble *ty)
|
||||
{
|
||||
gboolean snapped = FALSE;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
|
||||
g_return_val_if_fail (tx != NULL, FALSE);
|
||||
g_return_val_if_fail (ty != NULL, FALSE);
|
||||
|
||||
*tx = x;
|
||||
*ty = y;
|
||||
*snapped_coords = *coords;
|
||||
|
||||
if (gimp_display_shell_get_show_guides (shell) &&
|
||||
shell->snap_to_guides &&
|
||||
shell->gdisp->gimage->guides)
|
||||
{
|
||||
gdouble image_x, image_y;
|
||||
gint image_tx, image_ty;
|
||||
gint tx, ty;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x, y,
|
||||
&image_x, &image_y,
|
||||
TRUE);
|
||||
|
||||
snapped = gimp_image_snap_point (shell->gdisp->gimage,
|
||||
(gint) image_x,
|
||||
(gint) image_y,
|
||||
&image_tx,
|
||||
&image_ty);
|
||||
|
||||
if (snapped)
|
||||
if (snap_width > 0 && snap_height > 0)
|
||||
{
|
||||
gimp_display_shell_transform_xy_f (shell,
|
||||
(gdouble) image_tx,
|
||||
(gdouble) image_ty,
|
||||
tx, ty,
|
||||
FALSE);
|
||||
gimp_image_snap_rectangle (shell->gdisp->gimage,
|
||||
coords->x + snap_offset_x,
|
||||
coords->y + snap_offset_y,
|
||||
coords->x + snap_offset_x + snap_width,
|
||||
coords->y + snap_offset_y + snap_height,
|
||||
&tx,
|
||||
&ty);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_image_snap_point (shell->gdisp->gimage,
|
||||
coords->x + snap_offset_x,
|
||||
coords->y + snap_offset_y,
|
||||
&tx,
|
||||
&ty);
|
||||
}
|
||||
|
||||
snapped_coords->x = tx - snap_offset_x;
|
||||
snapped_coords->y = ty - snap_offset_y;
|
||||
}
|
||||
|
||||
return snapped;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_display_shell_snap_rectangle (GimpDisplayShell *shell,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2,
|
||||
gdouble *tx1,
|
||||
gdouble *ty1)
|
||||
{
|
||||
gdouble nx1, ny1;
|
||||
gdouble nx2, ny2;
|
||||
gboolean snap1, snap2;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
|
||||
g_return_val_if_fail (tx1 != NULL, FALSE);
|
||||
g_return_val_if_fail (ty1 != NULL, FALSE);
|
||||
|
||||
*tx1 = x1;
|
||||
*ty1 = y1;
|
||||
|
||||
snap1 = gimp_display_shell_snap_point (shell, x1, y1, &nx1, &ny1);
|
||||
snap2 = gimp_display_shell_snap_point (shell, x2, y2, &nx2, &ny2);
|
||||
|
||||
if (snap1 || snap2)
|
||||
{
|
||||
if (x1 != nx1)
|
||||
*tx1 = nx1;
|
||||
else if (x2 != nx2)
|
||||
*tx1 = x1 + (nx2 - x2);
|
||||
|
||||
if (y1 != ny1)
|
||||
*ty1 = ny1;
|
||||
else if (y2 != ny2)
|
||||
*ty1 = y1 + (ny2 - y2);
|
||||
}
|
||||
|
||||
return snap1 || snap2;
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
|
|||
|
|
@ -195,21 +195,13 @@ void gimp_display_shell_reconnect (GimpDisplayShell *shell);
|
|||
void gimp_display_shell_scaled (GimpDisplayShell *shell);
|
||||
void gimp_display_shell_scrolled (GimpDisplayShell *shell);
|
||||
|
||||
GimpGuide * gimp_display_shell_find_guide (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
gboolean gimp_display_shell_snap_point (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble *tx,
|
||||
gdouble *ty);
|
||||
gboolean gimp_display_shell_snap_rectangle (GimpDisplayShell *shell,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2,
|
||||
gdouble *tx1,
|
||||
gdouble *ty1);
|
||||
void gimp_display_shell_snap_coords (GimpDisplayShell *shell,
|
||||
GimpCoords *coords,
|
||||
GimpCoords *snapped_coords,
|
||||
gint snap_offset_x,
|
||||
gint snap_offset_y,
|
||||
gint snap_width,
|
||||
gint snap_height);
|
||||
|
||||
gint gimp_display_shell_mask_value (GimpDisplayShell *shell,
|
||||
gint x,
|
||||
|
|
|
|||
|
|
@ -929,114 +929,49 @@ gimp_display_shell_scrolled (GimpDisplayShell *shell)
|
|||
g_signal_emit (shell, display_shell_signals[SCROLLED], 0);
|
||||
}
|
||||
|
||||
GimpGuide *
|
||||
gimp_display_shell_find_guide (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
void
|
||||
gimp_display_shell_snap_coords (GimpDisplayShell *shell,
|
||||
GimpCoords *coords,
|
||||
GimpCoords *snapped_coords,
|
||||
gint snap_offset_x,
|
||||
gint snap_offset_y,
|
||||
gint snap_width,
|
||||
gint snap_height)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
|
||||
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
||||
g_return_if_fail (coords != NULL);
|
||||
g_return_if_fail (snapped_coords != NULL);
|
||||
|
||||
if (gimp_display_shell_get_show_guides (shell))
|
||||
{
|
||||
gdouble image_x, image_y;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x, y,
|
||||
&image_x, &image_y,
|
||||
TRUE);
|
||||
|
||||
return gimp_image_find_guide (shell->gdisp->gimage,
|
||||
(gint) image_x,
|
||||
(gint) image_y);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_display_shell_snap_point (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble *tx,
|
||||
gdouble *ty)
|
||||
{
|
||||
gboolean snapped = FALSE;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
|
||||
g_return_val_if_fail (tx != NULL, FALSE);
|
||||
g_return_val_if_fail (ty != NULL, FALSE);
|
||||
|
||||
*tx = x;
|
||||
*ty = y;
|
||||
*snapped_coords = *coords;
|
||||
|
||||
if (gimp_display_shell_get_show_guides (shell) &&
|
||||
shell->snap_to_guides &&
|
||||
shell->gdisp->gimage->guides)
|
||||
{
|
||||
gdouble image_x, image_y;
|
||||
gint image_tx, image_ty;
|
||||
gint tx, ty;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x, y,
|
||||
&image_x, &image_y,
|
||||
TRUE);
|
||||
|
||||
snapped = gimp_image_snap_point (shell->gdisp->gimage,
|
||||
(gint) image_x,
|
||||
(gint) image_y,
|
||||
&image_tx,
|
||||
&image_ty);
|
||||
|
||||
if (snapped)
|
||||
if (snap_width > 0 && snap_height > 0)
|
||||
{
|
||||
gimp_display_shell_transform_xy_f (shell,
|
||||
(gdouble) image_tx,
|
||||
(gdouble) image_ty,
|
||||
tx, ty,
|
||||
FALSE);
|
||||
gimp_image_snap_rectangle (shell->gdisp->gimage,
|
||||
coords->x + snap_offset_x,
|
||||
coords->y + snap_offset_y,
|
||||
coords->x + snap_offset_x + snap_width,
|
||||
coords->y + snap_offset_y + snap_height,
|
||||
&tx,
|
||||
&ty);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_image_snap_point (shell->gdisp->gimage,
|
||||
coords->x + snap_offset_x,
|
||||
coords->y + snap_offset_y,
|
||||
&tx,
|
||||
&ty);
|
||||
}
|
||||
|
||||
snapped_coords->x = tx - snap_offset_x;
|
||||
snapped_coords->y = ty - snap_offset_y;
|
||||
}
|
||||
|
||||
return snapped;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_display_shell_snap_rectangle (GimpDisplayShell *shell,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2,
|
||||
gdouble *tx1,
|
||||
gdouble *ty1)
|
||||
{
|
||||
gdouble nx1, ny1;
|
||||
gdouble nx2, ny2;
|
||||
gboolean snap1, snap2;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
|
||||
g_return_val_if_fail (tx1 != NULL, FALSE);
|
||||
g_return_val_if_fail (ty1 != NULL, FALSE);
|
||||
|
||||
*tx1 = x1;
|
||||
*ty1 = y1;
|
||||
|
||||
snap1 = gimp_display_shell_snap_point (shell, x1, y1, &nx1, &ny1);
|
||||
snap2 = gimp_display_shell_snap_point (shell, x2, y2, &nx2, &ny2);
|
||||
|
||||
if (snap1 || snap2)
|
||||
{
|
||||
if (x1 != nx1)
|
||||
*tx1 = nx1;
|
||||
else if (x2 != nx2)
|
||||
*tx1 = x1 + (nx2 - x2);
|
||||
|
||||
if (y1 != ny1)
|
||||
*ty1 = ny1;
|
||||
else if (y2 != ny2)
|
||||
*ty1 = y1 + (ny2 - y2);
|
||||
}
|
||||
|
||||
return snap1 || snap2;
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
|
|||
|
|
@ -195,21 +195,13 @@ void gimp_display_shell_reconnect (GimpDisplayShell *shell);
|
|||
void gimp_display_shell_scaled (GimpDisplayShell *shell);
|
||||
void gimp_display_shell_scrolled (GimpDisplayShell *shell);
|
||||
|
||||
GimpGuide * gimp_display_shell_find_guide (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
gboolean gimp_display_shell_snap_point (GimpDisplayShell *shell,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble *tx,
|
||||
gdouble *ty);
|
||||
gboolean gimp_display_shell_snap_rectangle (GimpDisplayShell *shell,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2,
|
||||
gdouble *tx1,
|
||||
gdouble *ty1);
|
||||
void gimp_display_shell_snap_coords (GimpDisplayShell *shell,
|
||||
GimpCoords *coords,
|
||||
GimpCoords *snapped_coords,
|
||||
gint snap_offset_x,
|
||||
gint snap_offset_y,
|
||||
gint snap_width,
|
||||
gint snap_height);
|
||||
|
||||
gint gimp_display_shell_mask_value (GimpDisplayShell *shell,
|
||||
gint x,
|
||||
|
|
|
|||
|
|
@ -300,6 +300,11 @@ gimp_crop_tool_button_press (GimpTool *tool,
|
|||
FALSE))
|
||||
{
|
||||
crop->function = RESIZING_LEFT;
|
||||
|
||||
gimp_tool_control_set_snap_offsets (tool->control,
|
||||
crop->x1 - coords->x,
|
||||
crop->y1 - coords->y,
|
||||
0, 0);
|
||||
}
|
||||
else if (gimp_draw_tool_on_handle (draw_tool, gdisp,
|
||||
coords->x, coords->y,
|
||||
|
|
@ -310,6 +315,11 @@ gimp_crop_tool_button_press (GimpTool *tool,
|
|||
FALSE))
|
||||
{
|
||||
crop->function = RESIZING_RIGHT;
|
||||
|
||||
gimp_tool_control_set_snap_offsets (tool->control,
|
||||
crop->x2 - coords->x,
|
||||
crop->y2 - coords->y,
|
||||
0, 0);
|
||||
}
|
||||
/* If the cursor is in either the upper right or lower left boxes,
|
||||
* The new function will be to translate the current crop area
|
||||
|
|
@ -330,6 +340,12 @@ gimp_crop_tool_button_press (GimpTool *tool,
|
|||
FALSE))
|
||||
{
|
||||
crop->function = MOVING;
|
||||
|
||||
gimp_tool_control_set_snap_offsets (tool->control,
|
||||
crop->x1 - coords->x,
|
||||
crop->y1 - coords->y,
|
||||
crop->x2 - crop->x1,
|
||||
crop->y2 - crop->y1);
|
||||
}
|
||||
/* If the pointer is in the rectangular region, crop or resize it!
|
||||
*/
|
||||
|
|
@ -354,6 +370,8 @@ gimp_crop_tool_button_press (GimpTool *tool,
|
|||
if (gimp_tool_control_is_active (tool->control))
|
||||
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
gimp_tool_control_set_snap_offsets (tool->control, 0, 0, 0, 0);
|
||||
|
||||
tool->gdisp = gdisp;
|
||||
|
||||
crop->x2 = crop->x1 = ROUND (coords->x);
|
||||
|
|
@ -383,6 +401,8 @@ gimp_crop_tool_button_release (GimpTool *tool,
|
|||
|
||||
gimp_tool_pop_status (tool);
|
||||
|
||||
gimp_tool_control_set_snap_offsets (tool->control, 0, 0, 0, 0);
|
||||
|
||||
if (! (state & GDK_BUTTON3_MASK))
|
||||
{
|
||||
if (crop->function == CROPPING)
|
||||
|
|
@ -531,6 +551,34 @@ gimp_crop_tool_motion (GimpTool *tool,
|
|||
/* recalculate the coordinates for crop_draw based on the new values */
|
||||
crop_recalc (crop);
|
||||
|
||||
switch (crop->function)
|
||||
{
|
||||
case RESIZING_LEFT:
|
||||
gimp_tool_control_set_snap_offsets (tool->control,
|
||||
crop->x1 - coords->x,
|
||||
crop->y1 - coords->y,
|
||||
0, 0);
|
||||
break;
|
||||
|
||||
case RESIZING_RIGHT:
|
||||
gimp_tool_control_set_snap_offsets (tool->control,
|
||||
crop->x2 - coords->x,
|
||||
crop->y2 - coords->y,
|
||||
0, 0);
|
||||
break;
|
||||
|
||||
case MOVING:
|
||||
gimp_tool_control_set_snap_offsets (tool->control,
|
||||
crop->x1 - coords->x,
|
||||
crop->y1 - coords->y,
|
||||
crop->x2 - crop->x1,
|
||||
crop->y2 - crop->y1);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (crop->function == CREATING ||
|
||||
crop->function == RESIZING_LEFT ||
|
||||
crop->function == RESIZING_RIGHT)
|
||||
|
|
|
|||
|
|
@ -178,10 +178,8 @@ gimp_edit_selection_tool_init (GimpEditSelectionTool *edit_selection_tool)
|
|||
tool = GIMP_TOOL (edit_selection_tool);
|
||||
|
||||
gimp_tool_control_set_scroll_lock (tool->control, EDIT_SELECT_SCROLL_LOCK);
|
||||
gimp_tool_control_set_snap_to (tool->control, FALSE);
|
||||
gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_COMPRESS);
|
||||
|
||||
|
||||
edit_selection_tool->origx = 0;
|
||||
edit_selection_tool->origy = 0;
|
||||
|
||||
|
|
@ -199,7 +197,6 @@ gimp_edit_selection_tool_snap (GimpEditSelectionTool *edit_select,
|
|||
{
|
||||
GimpDisplayShell *shell;
|
||||
gdouble x1, y1;
|
||||
gdouble x2, y2;
|
||||
gdouble dx, dy;
|
||||
|
||||
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
||||
|
|
@ -210,25 +207,6 @@ gimp_edit_selection_tool_snap (GimpEditSelectionTool *edit_select,
|
|||
x1 = edit_select->x1 + dx;
|
||||
y1 = edit_select->y1 + dy;
|
||||
|
||||
if (gimp_display_shell_get_show_guides (shell) &&
|
||||
shell->snap_to_guides &&
|
||||
gdisp->gimage->guides)
|
||||
{
|
||||
gint image_x1, image_y1;
|
||||
|
||||
x2 = edit_select->x2 + dx;
|
||||
y2 = edit_select->y2 + dy;
|
||||
|
||||
if (gimp_image_snap_rectangle (gdisp->gimage,
|
||||
ROUND (x1), ROUND (y1),
|
||||
ROUND (x2), ROUND (y2),
|
||||
&image_x1, &image_y1))
|
||||
{
|
||||
x1 = image_x1;
|
||||
y1 = image_y1;
|
||||
}
|
||||
}
|
||||
|
||||
edit_select->x = (gint) RINT (x1) - (edit_select->x1 - edit_select->origx);
|
||||
edit_select->y = (gint) RINT (y1) - (edit_select->y1 - edit_select->origy);
|
||||
}
|
||||
|
|
@ -241,6 +219,7 @@ init_edit_selection (GimpTool *tool,
|
|||
{
|
||||
GimpEditSelectionTool *edit_select;
|
||||
GimpDisplayShell *shell;
|
||||
GimpDrawable *active_drawable;
|
||||
gint off_x, off_y;
|
||||
const gchar *undo_desc;
|
||||
|
||||
|
|
@ -278,8 +257,9 @@ init_edit_selection (GimpTool *tool,
|
|||
GIMP_UNDO_GROUP_LAYER_DISPLACE,
|
||||
undo_desc);
|
||||
|
||||
gimp_drawable_offsets (gimp_image_active_drawable (gdisp->gimage),
|
||||
&off_x, &off_y);
|
||||
active_drawable = gimp_image_active_drawable (gdisp->gimage);
|
||||
|
||||
gimp_drawable_offsets (active_drawable, &off_x, &off_y);
|
||||
|
||||
edit_select->edit_type = edit_type;
|
||||
|
||||
|
|
@ -304,7 +284,7 @@ init_edit_selection (GimpTool *tool,
|
|||
* where the translation will result in floating the selection
|
||||
* mask and translating the resulting layer
|
||||
*/
|
||||
gimp_drawable_mask_bounds (gimp_image_active_drawable (gdisp->gimage),
|
||||
gimp_drawable_mask_bounds (active_drawable,
|
||||
&edit_select->x1, &edit_select->y1,
|
||||
&edit_select->x2, &edit_select->y2);
|
||||
|
||||
|
|
@ -312,6 +292,73 @@ init_edit_selection (GimpTool *tool,
|
|||
RINT (edit_select->origx),
|
||||
RINT (edit_select->origy));
|
||||
|
||||
{
|
||||
gint x1, y1, x2, y2;
|
||||
|
||||
switch (edit_select->edit_type)
|
||||
{
|
||||
case EDIT_MASK_TRANSLATE:
|
||||
gimp_image_mask_bounds (gdisp->gimage, &x1, &y1, &x2, &y2);
|
||||
break;
|
||||
|
||||
case EDIT_MASK_TO_LAYER_TRANSLATE:
|
||||
x1 = edit_select->x1 + off_x;
|
||||
y1 = edit_select->y1 + off_y;
|
||||
x2 = edit_select->x2 + off_x;
|
||||
y2 = edit_select->y2 + off_y;
|
||||
break;
|
||||
|
||||
case EDIT_LAYER_TRANSLATE:
|
||||
case EDIT_FLOATING_SEL_TRANSLATE:
|
||||
{
|
||||
GList *layer_list;
|
||||
GimpLayer *layer;
|
||||
gint x3, y3, x4, y4;
|
||||
|
||||
x1 = off_x;
|
||||
y1 = off_y;
|
||||
|
||||
x2 = x1 + gimp_drawable_width (active_drawable);
|
||||
y2 = y1 + gimp_drawable_height (active_drawable);
|
||||
|
||||
/* Now, expand the rectangle to include all linked layers as well */
|
||||
for (layer_list = GIMP_LIST (gdisp->gimage->layers)->list;
|
||||
layer_list;
|
||||
layer_list = g_list_next (layer_list))
|
||||
{
|
||||
layer = (GimpLayer *) layer_list->data;
|
||||
|
||||
if ((layer != (GimpLayer *) active_drawable) &&
|
||||
gimp_layer_get_linked (layer))
|
||||
{
|
||||
g_print ("linked!\n");
|
||||
|
||||
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &x3, &y3);
|
||||
|
||||
x4 = x3 + gimp_drawable_width (GIMP_DRAWABLE (layer));
|
||||
y4 = y3 + gimp_drawable_height (GIMP_DRAWABLE (layer));
|
||||
|
||||
if (x3 < x1)
|
||||
x1 = x3;
|
||||
if (y3 < y1)
|
||||
y1 = y3;
|
||||
if (x4 > x2)
|
||||
x2 = x4;
|
||||
if (y4 > y2)
|
||||
y2 = y4;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
gimp_tool_control_set_snap_offsets (GIMP_TOOL (edit_select)->control,
|
||||
x1 - coords->x,
|
||||
y1 - coords->y,
|
||||
x2 - x1,
|
||||
y2 - y1);
|
||||
}
|
||||
|
||||
gimp_tool_control_activate (GIMP_TOOL (edit_select)->control);
|
||||
GIMP_TOOL (edit_select)->gdisp = gdisp;
|
||||
|
||||
|
|
|
|||
|
|
@ -74,11 +74,16 @@ gimp_tool_control_init (GimpToolControl *control)
|
|||
|
||||
control->toggled = FALSE;
|
||||
|
||||
control->scroll_lock = FALSE; /* Allow scrolling */
|
||||
control->auto_snap_to = TRUE; /* Snap to guides */
|
||||
control->preserve = TRUE; /* Preserve across drawable change */
|
||||
control->handle_empty_image = FALSE; /* Require active drawable */
|
||||
control->motion_mode = GIMP_MOTION_MODE_HINT; /* Use MOTION_HINT compression */
|
||||
control->scroll_lock = FALSE;
|
||||
control->auto_snap_to = TRUE;
|
||||
control->snap_offset_x = 0;
|
||||
control->snap_offset_y = 0;
|
||||
control->snap_width = 0;
|
||||
control->snap_height = 0;
|
||||
|
||||
control->preserve = TRUE;
|
||||
control->handle_empty_image = FALSE;
|
||||
control->motion_mode = GIMP_MOTION_MODE_HINT;
|
||||
|
||||
control->cursor = GIMP_MOUSE_CURSOR;
|
||||
control->tool_cursor = GIMP_TOOL_CURSOR_NONE;
|
||||
|
|
@ -165,6 +170,21 @@ gimp_tool_control_set_snap_to (GimpToolControl *control,
|
|||
control->auto_snap_to = snap_to ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_tool_control_set_snap_offsets (GimpToolControl *control,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
|
||||
|
||||
control->snap_offset_x = offset_x;
|
||||
control->snap_offset_y = offset_y;
|
||||
control->snap_width = width;
|
||||
control->snap_height = height;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_tool_control_set_motion_mode (GimpToolControl *control,
|
||||
GimpMotionMode motion_mode)
|
||||
|
|
@ -271,6 +291,21 @@ gimp_tool_control_auto_snap_to (GimpToolControl *control)
|
|||
return control->auto_snap_to;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_tool_control_snap_offsets (GimpToolControl *control,
|
||||
gint *offset_x,
|
||||
gint *offset_y,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
|
||||
|
||||
if (offset_x) *offset_x = control->snap_offset_x;
|
||||
if (offset_y) *offset_y = control->snap_offset_y;
|
||||
if (width) *width = control->snap_width;
|
||||
if (height) *height = control->snap_height;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_tool_control_preserve (GimpToolControl *control)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ struct _GimpToolControl
|
|||
|
||||
gboolean scroll_lock; /* allow scrolling or not */
|
||||
gboolean auto_snap_to; /* snap to guides automatically */
|
||||
gint snap_offset_x;
|
||||
gint snap_offset_y;
|
||||
gint snap_width;
|
||||
gint snap_height;
|
||||
gboolean preserve; /* Preserve this tool across drawable *
|
||||
* changes */
|
||||
gboolean handle_empty_image; /* invoke the tool on images without *
|
||||
|
|
@ -100,6 +104,17 @@ void gimp_tool_control_set_snap_to (GimpToolControl
|
|||
gboolean snap_to);
|
||||
gboolean gimp_tool_control_auto_snap_to (GimpToolControl *control);
|
||||
|
||||
void gimp_tool_control_set_snap_offsets (GimpToolControl *control,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
gint width,
|
||||
gint height);
|
||||
void gimp_tool_control_snap_offsets (GimpToolControl *control,
|
||||
gint *offset_x,
|
||||
gint *offset_y,
|
||||
gint *width,
|
||||
gint *height);
|
||||
|
||||
GdkCursorType gimp_tool_control_get_cursor (GimpToolControl *control);
|
||||
|
||||
void gimp_tool_control_set_cursor (GimpToolControl *control,
|
||||
|
|
|
|||
Loading…
Reference in a new issue