Commit 2e0757fd authored by Karine Delvare's avatar Karine Delvare Committed by Karine Delvare

app/tools/gimpcroptool.c app/tools/gimprectangleoptions.c

2005-09-13  Karine Delvare  <kdelvare@nerim.net>

  * app/tools/gimpcroptool.c
  * app/tools/gimprectangleoptions.c
  * app/tools/gimprectangletool.c
  * app/tools/gimpnewrectselecttool.c: changed the way we stay inside
  images boundaries so each tool decides whether it does or not.
parent 7015ad10
2005-09-13 Karine Delvare <kdelvare@nerim.net>
* app/tools/gimpcroptool.c
* app/tools/gimprectangleoptions.c
* app/tools/gimprectangletool.c
* app/tools/gimpnewrectselecttool.c: changed the way we stay inside
images boundaries so each tool decides whether it does or not.
2005-09-14 Michael Natterer <mitch@gimp.org>
* app/widgets/gimptoolbox.c (gimp_toolbox_substitute_underscores):
......
......@@ -218,13 +218,32 @@ gimp_crop_tool_execute (GimpRectangleTool *rectangle,
GimpTool *tool = GIMP_TOOL (rectangle);
GimpCropOptions *options;
GimpImage *gimage;
gint max_x, max_y;
gboolean rectangle_exists;
options = GIMP_CROP_OPTIONS (tool->tool_info->tool_options);
gimage = tool->gdisp->gimage;
max_x = gimage->width;
max_y = gimage->height;
rectangle_exists = (w > 0 && h > 0);
rectangle_exists == (x <= max_x && y <= max_y
&& x + w >= 0 && y + h >= 0
&& w > 0 && h > 0);
if (x < 0)
{
w += x;
x = 0;
}
if (y < 0)
{
h += y;
y = 0;
}
if (x + w > max_x)
w = max_x - x;
if (y + h > max_y)
h = max_y - y;
/* if rectangle exists, crop it */
if (rectangle_exists)
......
......@@ -241,6 +241,7 @@ gimp_new_rect_select_tool_execute (GimpRectangleTool *rectangle,
GimpTool *tool = GIMP_TOOL (rectangle);
GimpSelectionOptions *options;
GimpImage *gimage;
gint max_x, max_y;
gboolean rectangle_exists;
gboolean selected;
gint val;
......@@ -251,9 +252,27 @@ gimp_new_rect_select_tool_execute (GimpRectangleTool *rectangle,
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
gimage = tool->gdisp->gimage;
max_x = gimage->width;
max_y = gimage->height;
selection_mask = gimp_image_get_mask (gimage);
rectangle_exists = (w > 0 && h > 0);
rectangle_exists == (x <= max_x && y <= max_y
&& x + w >= 0 && y + h >= 0
&& w > 0 && h > 0);
if (x < 0)
{
w += x;
x = 0;
}
if (y < 0)
{
h += y;
y = 0;
}
if (x + w > max_x)
w = max_x - x;
if (y + h > max_y)
h = max_y - y;
/* If there is a floating selection, anchor it */
if (gimp_image_floating_sel (gimage))
......
......@@ -142,13 +142,13 @@ gimp_rectangle_options_iface_base_init (GimpRectangleOptionsInterface *options_i
g_object_interface_install_property (options_iface,
g_param_spec_double ("center-x",
NULL, NULL,
0.0, GIMP_MAX_IMAGE_SIZE,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0.0,
G_PARAM_READWRITE));
g_object_interface_install_property (options_iface,
g_param_spec_double ("center-y",
NULL, NULL,
0.0, GIMP_MAX_IMAGE_SIZE,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0.0,
G_PARAM_READWRITE));
......
......@@ -241,6 +241,7 @@ gimp_new_rect_select_tool_execute (GimpRectangleTool *rectangle,
GimpTool *tool = GIMP_TOOL (rectangle);
GimpSelectionOptions *options;
GimpImage *gimage;
gint max_x, max_y;
gboolean rectangle_exists;
gboolean selected;
gint val;
......@@ -251,9 +252,27 @@ gimp_new_rect_select_tool_execute (GimpRectangleTool *rectangle,
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
gimage = tool->gdisp->gimage;
max_x = gimage->width;
max_y = gimage->height;
selection_mask = gimp_image_get_mask (gimage);
rectangle_exists = (w > 0 && h > 0);
rectangle_exists == (x <= max_x && y <= max_y
&& x + w >= 0 && y + h >= 0
&& w > 0 && h > 0);
if (x < 0)
{
w += x;
x = 0;
}
if (y < 0)
{
h += y;
y = 0;
}
if (x + w > max_x)
w = max_x - x;
if (y + h > max_y)
h = max_y - y;
/* If there is a floating selection, anchor it */
if (gimp_image_floating_sel (gimage))
......
......@@ -195,25 +195,25 @@ gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *tool_iface)
g_object_interface_install_property (tool_iface,
g_param_spec_int ("x1",
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 ("y1",
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 ("x2",
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 ("y2",
NULL, NULL,
0, GIMP_MAX_IMAGE_SIZE,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0,
G_PARAM_READWRITE));
......@@ -227,25 +227,25 @@ gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *tool_iface)
g_object_interface_install_property (tool_iface,
g_param_spec_int ("dx1",
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 ("dy1",
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 ("dx2",
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 ("dy2",
NULL, NULL,
0, GIMP_MAX_IMAGE_SIZE,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0,
G_PARAM_READWRITE));
......@@ -265,13 +265,13 @@ gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *tool_iface)
g_object_interface_install_property (tool_iface,
g_param_spec_double ("origx",
NULL, NULL,
0.0, GIMP_MAX_IMAGE_SIZE,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0.0,
G_PARAM_READWRITE));
g_object_interface_install_property (tool_iface,
g_param_spec_double ("origy",
NULL, NULL,
0.0, GIMP_MAX_IMAGE_SIZE,
-GIMP_MAX_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
0.0,
G_PARAM_READWRITE));
g_object_interface_install_property (tool_iface,
......@@ -1444,19 +1444,12 @@ gimp_rectangle_tool_motion (GimpTool *tool,
switch (function)
{
case RECT_CREATING:
if (x1 < 0)
x1 = 0;
if (x2 > max_x)
x2 = max_x;
break;
case RECT_RESIZING_UPPER_LEFT:
case RECT_RESIZING_LOWER_LEFT:
case RECT_RESIZING_LEFT:
if (x1 < 0 && x1 + inc_x < 0)
x1 = 0;
else
x1 = rx1 + inc_x;
x1 = rx1 + inc_x;
if (fixed_width)
{
x2 = x1 + width;
......@@ -1488,8 +1481,6 @@ gimp_rectangle_tool_motion (GimpTool *tool,
else
{
x2 = MAX (x1, rx2);
if (x1 < 0)
x1 = 0;
}
g_object_set (rectangle, "startx", curx, NULL);
break;
......@@ -1497,10 +1488,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
case RECT_RESIZING_UPPER_RIGHT:
case RECT_RESIZING_LOWER_RIGHT:
case RECT_RESIZING_RIGHT:
if (x2 > max_x && x2 + inc_x > max_x)
x2 = max_x;
else
x2 = rx2 + inc_x;
x2 = rx2 + inc_x;
if (fixed_width)
{
x1 = x2 - width;
......@@ -1532,8 +1520,6 @@ gimp_rectangle_tool_motion (GimpTool *tool,
else
{
x1 = MIN (rx1, x2);
if (x2 > max_x)
x2 = max_x;
}
g_object_set (rectangle, "startx", curx, NULL);
break;
......@@ -1546,30 +1532,8 @@ gimp_rectangle_tool_motion (GimpTool *tool,
break;
case RECT_MOVING:
// 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;
}
else
{
x1 = rx1 + inc_x;
x2 = rx2 + inc_x;
}
x1 = rx1 + inc_x;
x2 = rx2 + inc_x;
g_object_set (rectangle, "startx", curx, NULL);
break;
}
......@@ -1577,19 +1541,12 @@ gimp_rectangle_tool_motion (GimpTool *tool,
switch (function)
{
case RECT_CREATING:
if (y1 < 0)
y1 = 0;
if (y2 > max_y)
y2 = max_y;
break;
case RECT_RESIZING_UPPER_LEFT:
case RECT_RESIZING_UPPER_RIGHT:
case RECT_RESIZING_TOP:
if (y1 < 0 && y1 + inc_y < 0)
y1 = 0;
else
y1 = ry1 + inc_y;
y1 = ry1 + inc_y;
if (fixed_height)
{
y2 = y1 + height;
......@@ -1621,8 +1578,6 @@ gimp_rectangle_tool_motion (GimpTool *tool,
else
{
y2 = MAX (y1, ry2);
if (y1 < 0)
y1 = 0;
}
g_object_set (rectangle, "starty", cury, NULL);
break;
......@@ -1630,10 +1585,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
case RECT_RESIZING_LOWER_LEFT:
case RECT_RESIZING_LOWER_RIGHT:
case RECT_RESIZING_BOTTOM:
if (y2 > max_y && y2 + inc_y > max_y)
y2 = max_y;
else
y2 = ry2 + inc_y;
y2 = ry2 + inc_y;
if (fixed_height)
{
y1 = y2 - height;
......@@ -1665,8 +1617,6 @@ gimp_rectangle_tool_motion (GimpTool *tool,
else
{
y1 = MIN (ry1, y2);
if (y2 > max_y)
y2 = max_y;
}
g_object_set (rectangle, "starty", cury, NULL);
break;
......@@ -1679,30 +1629,8 @@ gimp_rectangle_tool_motion (GimpTool *tool,
break;
case RECT_MOVING:
// 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;
}
else
{
y1 = ry1 + inc_y;
y2 = ry2 + inc_y;
}
y1 = ry1 + inc_y;
y2 = ry2 + inc_y;
g_object_set (rectangle, "starty", cury, NULL);
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment