From 9c3bc6f64b55e8fd9f78530b86b7107f3cf65bc8 Mon Sep 17 00:00:00 2001 From: Karine Delvare Date: Tue, 13 Sep 2005 19:07:17 +0000 Subject: [PATCH] don't modify the rectangle while moving, and stick to edges when going out 2005-09-13 Karine Delvare * app/tools/gimprectangletool.c: don't modify the rectangle while moving, and stick to edges when going out of image boundaries. --- ChangeLog | 5 +++ app/tools/gimprectangletool.c | 62 ++++++++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19a518c207..2816a0c3af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-09-13 Karine Delvare + + * app/tools/gimprectangletool.c: don't modify the rectangle while + moving, and stick to edges when going out of image boundaries. + 2005-09-13 Sven Neumann * app/actions/edit-actions.c: use "Undo History" instead of "Undo diff --git a/app/tools/gimprectangletool.c b/app/tools/gimprectangletool.c index 7696958726..0bab01c3c9 100644 --- a/app/tools/gimprectangletool.c +++ b/app/tools/gimprectangletool.c @@ -156,26 +156,26 @@ gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *tool_iface) g_object_interface_install_property (tool_iface, g_param_spec_int ("startx", NULL, NULL, - 0, GIMP_MAX_IMAGE_SIZE, + -GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE, 0, G_PARAM_READWRITE)); g_object_interface_install_property (tool_iface, g_param_spec_int ("starty", NULL, NULL, - 0, GIMP_MAX_IMAGE_SIZE, + -GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE, 0, G_PARAM_READWRITE)); g_object_interface_install_property (tool_iface, g_param_spec_int ("lastx", NULL, NULL, - 0, GIMP_MAX_IMAGE_SIZE, + -GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE, 0, G_PARAM_READWRITE)); g_object_interface_install_property (tool_iface, g_param_spec_int ("lasty", NULL, NULL, - 0, GIMP_MAX_IMAGE_SIZE, + -GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE, 0, G_PARAM_READWRITE)); @@ -1453,7 +1453,10 @@ gimp_rectangle_tool_motion (GimpTool *tool, case RECT_RESIZING_UPPER_LEFT: case RECT_RESIZING_LOWER_LEFT: case RECT_RESIZING_LEFT: - x1 = rx1 + inc_x; + if (x1 < 0 && x1 + inc_x < 0) + x1 = 0; + else + x1 = rx1 + inc_x; if (fixed_width) { x2 = x1 + width; @@ -1494,7 +1497,10 @@ gimp_rectangle_tool_motion (GimpTool *tool, case RECT_RESIZING_UPPER_RIGHT: case RECT_RESIZING_LOWER_RIGHT: case RECT_RESIZING_RIGHT: - x2 = rx2 + inc_x; + if (x2 > max_x && x2 + inc_x > max_x) + x2 = max_x; + else + x2 = rx2 + inc_x; if (fixed_width) { x1 = x2 - width; @@ -1540,8 +1546,20 @@ gimp_rectangle_tool_motion (GimpTool *tool, break; case RECT_MOVING: - if (rx1 + inc_x < 0 || - rx2 + inc_x > max_x) + // are we getting out of the image? + if (rx1 + inc_x < 0) + { + x1 = 0; + x2 = rx2 - rx1; + } + else if (rx2 + inc_x > max_x) + { + x1 = rx1 + max_x - rx2; + x2 = max_x; + } + // are we staying out of the image? + else if ((x1 < 0 && x1 + inc_x < 0) || + (x2 > max_x && x2 + inc_x > max_x)) { x1 = rx1; x2 = rx2; @@ -1551,6 +1569,7 @@ gimp_rectangle_tool_motion (GimpTool *tool, x1 = rx1 + inc_x; x2 = rx2 + inc_x; } + g_object_set (rectangle, "startx", curx, NULL); break; } @@ -1567,7 +1586,10 @@ gimp_rectangle_tool_motion (GimpTool *tool, case RECT_RESIZING_UPPER_LEFT: case RECT_RESIZING_UPPER_RIGHT: case RECT_RESIZING_TOP: - y1 = ry1 + inc_y; + if (y1 < 0 && y1 + inc_y < 0) + y1 = 0; + else + y1 = ry1 + inc_y; if (fixed_height) { y2 = y1 + height; @@ -1608,7 +1630,10 @@ gimp_rectangle_tool_motion (GimpTool *tool, case RECT_RESIZING_LOWER_LEFT: case RECT_RESIZING_LOWER_RIGHT: case RECT_RESIZING_BOTTOM: - y2 = ry2 + inc_y; + if (y2 > max_y && y2 + inc_y > max_y) + y2 = max_y; + else + y2 = ry2 + inc_y; if (fixed_height) { y1 = y2 - height; @@ -1654,8 +1679,20 @@ gimp_rectangle_tool_motion (GimpTool *tool, break; case RECT_MOVING: - if (ry1 + inc_y < 0 || - ry2 + inc_y > max_y) + // are we getting out of the image? + if (ry1 + inc_y < 0) + { + y1 = 0; + y2 = ry2 - ry1; + } + else if (ry2 + inc_y > max_y) + { + y1 = ry1 + max_y - ry2; + y2 = max_y; + } + // are we staying out of the image? + else if ((y1 < 0 && y1 + inc_y < 0) || + (y2 > max_y && y2 + inc_y > max_y)) { y1 = ry1; y2 = ry2; @@ -1665,6 +1702,7 @@ gimp_rectangle_tool_motion (GimpTool *tool, y1 = ry1 + inc_y; y2 = ry2 + inc_y; } + g_object_set (rectangle, "starty", cury, NULL); break; }