Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimpcroptool.c * app/tools/gimpellipseselecttool.c * app/tools/gimprectangletool.[ch]: code cleanups * app/tools/gimpnewrectselecttool.[ch]: try to do what the user intuitively expects when deciding which selection operation to perform. When modifying an existing rectangle, always use the operation with which it was created.
This commit is contained in:
parent
e2d373d817
commit
4742424b78
9 changed files with 308 additions and 185 deletions
11
ChangeLog
11
ChangeLog
|
|
@ -1,3 +1,14 @@
|
|||
2006-06-10 Bill Skaggs <weskaggs@primate.ucdavis.edu>
|
||||
|
||||
* app/tools/gimpcroptool.c
|
||||
* app/tools/gimpellipseselecttool.c
|
||||
* app/tools/gimprectangletool.[ch]: code cleanups
|
||||
|
||||
* app/tools/gimpnewrectselecttool.[ch]: try to do what
|
||||
the user intuitively expects when deciding which selection
|
||||
operation to perform. When modifying an existing rectangle,
|
||||
always use the operation with which it was created.
|
||||
|
||||
2006-06-10 Kevin Cozens <kcozens@cvs.gnome.org>
|
||||
|
||||
* plug-ins/script-fu/siod-wrapper.c (marshall_proc_db_call):
|
||||
|
|
|
|||
|
|
@ -121,7 +121,6 @@ gimp_crop_tool_class_init (GimpCropToolClass *klass)
|
|||
tool_class->button_release = gimp_crop_tool_button_release;
|
||||
tool_class->motion = gimp_rectangle_tool_motion;
|
||||
tool_class->key_press = gimp_rectangle_tool_key_press;
|
||||
tool_class->modifier_key = gimp_rectangle_tool_modifier_key;
|
||||
tool_class->oper_update = gimp_rectangle_tool_oper_update;
|
||||
tool_class->cursor_update = gimp_crop_tool_cursor_update;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,13 +43,14 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static void gimp_ellipse_select_tool_draw (GimpDrawTool *draw_tool);
|
||||
static void gimp_ellipse_select_tool_draw (GimpDrawTool *draw_tool);
|
||||
|
||||
static void gimp_ellipse_select_tool_rect_select (GimpNewRectSelectTool *rect_tool,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h);
|
||||
static void gimp_ellipse_select_tool_select (GimpNewRectSelectTool *rect_tool,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpEllipseSelectTool, gimp_ellipse_select_tool,
|
||||
|
|
@ -89,9 +90,9 @@ gimp_ellipse_select_tool_class_init (GimpEllipseSelectToolClass *klass)
|
|||
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
||||
rect_tool_class = GIMP_NEW_RECT_SELECT_TOOL_CLASS (klass);
|
||||
|
||||
draw_tool_class->draw = gimp_ellipse_select_tool_draw;
|
||||
draw_tool_class->draw = gimp_ellipse_select_tool_draw;
|
||||
|
||||
rect_tool_class->rect_select = gimp_ellipse_select_tool_rect_select;
|
||||
rect_tool_class->select = gimp_ellipse_select_tool_select;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -128,11 +129,12 @@ gimp_ellipse_select_tool_draw (GimpDrawTool *draw_tool)
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_ellipse_select_tool_rect_select (GimpNewRectSelectTool *rect_tool,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
gimp_ellipse_select_tool_select (GimpNewRectSelectTool *rect_tool,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
{
|
||||
GimpTool *tool;
|
||||
GimpSelectionOptions *options;
|
||||
|
|
@ -142,7 +144,7 @@ gimp_ellipse_select_tool_rect_select (GimpNewRectSelectTool *rect_tool,
|
|||
|
||||
gimp_channel_select_ellipse (gimp_image_get_mask (tool->display->image),
|
||||
x, y, w, h,
|
||||
options->operation,
|
||||
operation,
|
||||
options->antialias,
|
||||
options->feather,
|
||||
options->feather_radius,
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ static void gimp_new_rect_select_tool_cursor_update (GimpTool *
|
|||
GimpCoords *coords,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display);
|
||||
static void gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rect_tool,
|
||||
static void gimp_new_rect_select_tool_select (GimpRectangleTool *rect_tool,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
|
|
@ -104,7 +104,8 @@ static gboolean gimp_new_rect_select_tool_execute (GimpRectangleTool *
|
|||
gint h);
|
||||
static void gimp_new_rect_select_tool_cancel (GimpRectangleTool *rect_tool);
|
||||
static gboolean gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rect_tool);
|
||||
static void gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
|
||||
static void gimp_new_rect_select_tool_real_select (GimpNewRectSelectTool *rect_select,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
|
|
@ -163,17 +164,20 @@ gimp_new_rect_select_tool_class_init (GimpNewRectSelectToolClass *klass)
|
|||
|
||||
draw_tool_class->draw = gimp_rectangle_tool_draw;
|
||||
|
||||
klass->rect_select = gimp_new_rect_select_tool_real_rect_select;
|
||||
klass->select = gimp_new_rect_select_tool_real_select;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_new_rect_select_tool_init (GimpNewRectSelectTool *new_rect_select_tool)
|
||||
gimp_new_rect_select_tool_init (GimpNewRectSelectTool *rect_select)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (new_rect_select_tool);
|
||||
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (new_rect_select_tool);
|
||||
GimpTool *tool = GIMP_TOOL (rect_select);
|
||||
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (rect_select);
|
||||
|
||||
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_RECT_SELECT);
|
||||
gimp_rectangle_tool_set_constrain (rect_tool, TRUE);
|
||||
|
||||
rect_select->undo = NULL;
|
||||
rect_select->redo = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -221,7 +225,8 @@ gimp_new_rect_select_tool_button_press (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
guint function;
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
|
||||
guint function;
|
||||
|
||||
if (tool->display && display != tool->display)
|
||||
gimp_rectangle_tool_cancel (GIMP_RECTANGLE_TOOL (tool));
|
||||
|
|
@ -249,6 +254,34 @@ gimp_new_rect_select_tool_button_press (GimpTool *tool,
|
|||
}
|
||||
|
||||
gimp_rectangle_tool_button_press (tool, coords, time, state, display);
|
||||
|
||||
/* if we have an existing rectangle in the current display, then
|
||||
* we have already "executed", and need to undo at this point,
|
||||
* unless the user has done something in the meantime
|
||||
*/
|
||||
g_object_get (tool, "function", &function, NULL);
|
||||
|
||||
if (function == RECT_CREATING)
|
||||
{
|
||||
rect_select->use_saved_op = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpImage *image = tool->display->image;
|
||||
GimpUndo *undo;
|
||||
|
||||
undo = gimp_undo_stack_peek (image->undo_stack);
|
||||
|
||||
if (undo && rect_select->undo == undo)
|
||||
{
|
||||
gimp_image_undo (image);
|
||||
|
||||
/* we will need to redo if the user cancels */
|
||||
rect_select->redo = gimp_undo_stack_peek (image->redo_stack);
|
||||
}
|
||||
}
|
||||
|
||||
rect_select->undo = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -258,11 +291,23 @@ gimp_new_rect_select_tool_button_release (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
|
||||
|
||||
gimp_tool_pop_status (tool, display);
|
||||
gimp_tool_push_status (tool, display,
|
||||
_("Click or press enter to create the selection."));
|
||||
|
||||
gimp_rectangle_tool_button_release (tool, coords, time, state, display);
|
||||
|
||||
if ((state & GDK_BUTTON3_MASK))
|
||||
{
|
||||
if (rect_select->redo)
|
||||
{
|
||||
gimp_image_redo (tool->display->image);
|
||||
}
|
||||
|
||||
rect_select->use_saved_op = TRUE; /* is this correct? */
|
||||
}
|
||||
|
||||
rect_select->redo = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -272,8 +317,6 @@ gimp_new_rect_select_tool_modifier_key (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
gimp_rectangle_tool_modifier_key (tool, key, press, state, display);
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state,
|
||||
display);
|
||||
}
|
||||
|
|
@ -326,11 +369,11 @@ gimp_new_rect_select_tool_cursor_update (GimpTool *tool,
|
|||
* we clear the selection.
|
||||
*/
|
||||
static void
|
||||
gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rectangle,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
gimp_new_rect_select_tool_select (GimpRectangleTool *rectangle,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (rectangle);
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (rectangle);
|
||||
|
|
@ -338,6 +381,7 @@ gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rectangle,
|
|||
GimpImage *image;
|
||||
gboolean rectangle_exists;
|
||||
gboolean auto_shrink;
|
||||
SelectOps operation;
|
||||
|
||||
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
|
|
@ -358,18 +402,27 @@ gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rectangle,
|
|||
/* FIXME */
|
||||
}
|
||||
|
||||
if (rect_select->use_saved_op)
|
||||
operation = rect_select->operation;
|
||||
else
|
||||
g_object_get (options,
|
||||
"operation", &operation,
|
||||
NULL);
|
||||
|
||||
/* if rectangle exists, turn it into a selection */
|
||||
if (rectangle_exists)
|
||||
GIMP_NEW_RECT_SELECT_TOOL_GET_CLASS (rect_select)->rect_select (rect_select,
|
||||
x, y, w, h);
|
||||
GIMP_NEW_RECT_SELECT_TOOL_GET_CLASS (rect_select)->select (rect_select,
|
||||
operation,
|
||||
x, y, w, h);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
gimp_new_rect_select_tool_real_select (GimpNewRectSelectTool *rect_select,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (rect_select);
|
||||
GimpSelectionOptions *options;
|
||||
|
|
@ -378,7 +431,7 @@ gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
|
|||
|
||||
gimp_channel_select_rectangle (gimp_image_get_mask (tool->display->image),
|
||||
x, y, w, h,
|
||||
options->operation,
|
||||
operation,
|
||||
options->feather,
|
||||
options->feather_radius,
|
||||
options->feather_radius);
|
||||
|
|
@ -501,6 +554,7 @@ gimp_new_rect_select_tool_cancel (GimpRectangleTool *rectangle)
|
|||
}
|
||||
|
||||
rect_select->undo = NULL;
|
||||
rect_select->redo = NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -511,13 +565,14 @@ gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rectangle)
|
|||
if (tool->display)
|
||||
{
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
|
||||
GimpSelectionOptions *options;
|
||||
GimpImage *image = tool->display->image;
|
||||
GimpUndo *undo;
|
||||
gint x1, y1, x2, y2;
|
||||
|
||||
/* if we have an existing rectangle in the current display, then
|
||||
* we have already "executed", and need to undo at this point,
|
||||
* unless the user has done something in the meantime
|
||||
/* if we got here via button release, we have already undone the
|
||||
* previous operation. But if we got here by some other means,
|
||||
* we need to undo it now.
|
||||
*/
|
||||
undo = gimp_undo_stack_peek (image->undo_stack);
|
||||
|
||||
|
|
@ -534,13 +589,21 @@ gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rectangle)
|
|||
"y2", &y2,
|
||||
NULL);
|
||||
|
||||
gimp_new_rect_select_tool_rect_select (rectangle,
|
||||
x1, y1,
|
||||
x2 - x1,
|
||||
y2 - y1);
|
||||
gimp_new_rect_select_tool_select (rectangle, x1, y1, x2 - x1, y2 - y1);
|
||||
|
||||
/* save the undo that we got when executing */
|
||||
rect_select->undo = gimp_undo_stack_peek (image->undo_stack);
|
||||
rect_select->redo = NULL;
|
||||
|
||||
if (! rect_select->use_saved_op)
|
||||
{
|
||||
/* remember the operation now in case we modify the rectangle */
|
||||
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
||||
g_object_get (options,
|
||||
"operation", &rect_select->operation,
|
||||
NULL);
|
||||
rect_select->use_saved_op = TRUE;
|
||||
}
|
||||
|
||||
gimp_image_flush (image);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,18 +37,22 @@ struct _GimpNewRectSelectTool
|
|||
{
|
||||
GimpSelectionTool parent_instance;
|
||||
|
||||
SelectOps operation; /* remember for use when modifying */
|
||||
gboolean use_saved_op; /* use operation or get from options */
|
||||
GimpUndo *undo;
|
||||
GimpUndo *redo;
|
||||
};
|
||||
|
||||
struct _GimpNewRectSelectToolClass
|
||||
{
|
||||
GimpSelectionToolClass parent_class;
|
||||
|
||||
void (* rect_select) (GimpNewRectSelectTool *rect_select,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h);
|
||||
void (* select) (GimpNewRectSelectTool *rect_select,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ static void gimp_new_rect_select_tool_cursor_update (GimpTool *
|
|||
GimpCoords *coords,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display);
|
||||
static void gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rect_tool,
|
||||
static void gimp_new_rect_select_tool_select (GimpRectangleTool *rect_tool,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
|
|
@ -104,7 +104,8 @@ static gboolean gimp_new_rect_select_tool_execute (GimpRectangleTool *
|
|||
gint h);
|
||||
static void gimp_new_rect_select_tool_cancel (GimpRectangleTool *rect_tool);
|
||||
static gboolean gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rect_tool);
|
||||
static void gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
|
||||
static void gimp_new_rect_select_tool_real_select (GimpNewRectSelectTool *rect_select,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
|
|
@ -163,17 +164,20 @@ gimp_new_rect_select_tool_class_init (GimpNewRectSelectToolClass *klass)
|
|||
|
||||
draw_tool_class->draw = gimp_rectangle_tool_draw;
|
||||
|
||||
klass->rect_select = gimp_new_rect_select_tool_real_rect_select;
|
||||
klass->select = gimp_new_rect_select_tool_real_select;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_new_rect_select_tool_init (GimpNewRectSelectTool *new_rect_select_tool)
|
||||
gimp_new_rect_select_tool_init (GimpNewRectSelectTool *rect_select)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (new_rect_select_tool);
|
||||
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (new_rect_select_tool);
|
||||
GimpTool *tool = GIMP_TOOL (rect_select);
|
||||
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (rect_select);
|
||||
|
||||
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_RECT_SELECT);
|
||||
gimp_rectangle_tool_set_constrain (rect_tool, TRUE);
|
||||
|
||||
rect_select->undo = NULL;
|
||||
rect_select->redo = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -221,7 +225,8 @@ gimp_new_rect_select_tool_button_press (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
guint function;
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
|
||||
guint function;
|
||||
|
||||
if (tool->display && display != tool->display)
|
||||
gimp_rectangle_tool_cancel (GIMP_RECTANGLE_TOOL (tool));
|
||||
|
|
@ -249,6 +254,34 @@ gimp_new_rect_select_tool_button_press (GimpTool *tool,
|
|||
}
|
||||
|
||||
gimp_rectangle_tool_button_press (tool, coords, time, state, display);
|
||||
|
||||
/* if we have an existing rectangle in the current display, then
|
||||
* we have already "executed", and need to undo at this point,
|
||||
* unless the user has done something in the meantime
|
||||
*/
|
||||
g_object_get (tool, "function", &function, NULL);
|
||||
|
||||
if (function == RECT_CREATING)
|
||||
{
|
||||
rect_select->use_saved_op = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpImage *image = tool->display->image;
|
||||
GimpUndo *undo;
|
||||
|
||||
undo = gimp_undo_stack_peek (image->undo_stack);
|
||||
|
||||
if (undo && rect_select->undo == undo)
|
||||
{
|
||||
gimp_image_undo (image);
|
||||
|
||||
/* we will need to redo if the user cancels */
|
||||
rect_select->redo = gimp_undo_stack_peek (image->redo_stack);
|
||||
}
|
||||
}
|
||||
|
||||
rect_select->undo = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -258,11 +291,23 @@ gimp_new_rect_select_tool_button_release (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
|
||||
|
||||
gimp_tool_pop_status (tool, display);
|
||||
gimp_tool_push_status (tool, display,
|
||||
_("Click or press enter to create the selection."));
|
||||
|
||||
gimp_rectangle_tool_button_release (tool, coords, time, state, display);
|
||||
|
||||
if ((state & GDK_BUTTON3_MASK))
|
||||
{
|
||||
if (rect_select->redo)
|
||||
{
|
||||
gimp_image_redo (tool->display->image);
|
||||
}
|
||||
|
||||
rect_select->use_saved_op = TRUE; /* is this correct? */
|
||||
}
|
||||
|
||||
rect_select->redo = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -272,8 +317,6 @@ gimp_new_rect_select_tool_modifier_key (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
gimp_rectangle_tool_modifier_key (tool, key, press, state, display);
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state,
|
||||
display);
|
||||
}
|
||||
|
|
@ -326,11 +369,11 @@ gimp_new_rect_select_tool_cursor_update (GimpTool *tool,
|
|||
* we clear the selection.
|
||||
*/
|
||||
static void
|
||||
gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rectangle,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
gimp_new_rect_select_tool_select (GimpRectangleTool *rectangle,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (rectangle);
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (rectangle);
|
||||
|
|
@ -338,6 +381,7 @@ gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rectangle,
|
|||
GimpImage *image;
|
||||
gboolean rectangle_exists;
|
||||
gboolean auto_shrink;
|
||||
SelectOps operation;
|
||||
|
||||
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
|
|
@ -358,18 +402,27 @@ gimp_new_rect_select_tool_rect_select (GimpRectangleTool *rectangle,
|
|||
/* FIXME */
|
||||
}
|
||||
|
||||
if (rect_select->use_saved_op)
|
||||
operation = rect_select->operation;
|
||||
else
|
||||
g_object_get (options,
|
||||
"operation", &operation,
|
||||
NULL);
|
||||
|
||||
/* if rectangle exists, turn it into a selection */
|
||||
if (rectangle_exists)
|
||||
GIMP_NEW_RECT_SELECT_TOOL_GET_CLASS (rect_select)->rect_select (rect_select,
|
||||
x, y, w, h);
|
||||
GIMP_NEW_RECT_SELECT_TOOL_GET_CLASS (rect_select)->select (rect_select,
|
||||
operation,
|
||||
x, y, w, h);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
gimp_new_rect_select_tool_real_select (GimpNewRectSelectTool *rect_select,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (rect_select);
|
||||
GimpSelectionOptions *options;
|
||||
|
|
@ -378,7 +431,7 @@ gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
|
|||
|
||||
gimp_channel_select_rectangle (gimp_image_get_mask (tool->display->image),
|
||||
x, y, w, h,
|
||||
options->operation,
|
||||
operation,
|
||||
options->feather,
|
||||
options->feather_radius,
|
||||
options->feather_radius);
|
||||
|
|
@ -501,6 +554,7 @@ gimp_new_rect_select_tool_cancel (GimpRectangleTool *rectangle)
|
|||
}
|
||||
|
||||
rect_select->undo = NULL;
|
||||
rect_select->redo = NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -511,13 +565,14 @@ gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rectangle)
|
|||
if (tool->display)
|
||||
{
|
||||
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
|
||||
GimpSelectionOptions *options;
|
||||
GimpImage *image = tool->display->image;
|
||||
GimpUndo *undo;
|
||||
gint x1, y1, x2, y2;
|
||||
|
||||
/* if we have an existing rectangle in the current display, then
|
||||
* we have already "executed", and need to undo at this point,
|
||||
* unless the user has done something in the meantime
|
||||
/* if we got here via button release, we have already undone the
|
||||
* previous operation. But if we got here by some other means,
|
||||
* we need to undo it now.
|
||||
*/
|
||||
undo = gimp_undo_stack_peek (image->undo_stack);
|
||||
|
||||
|
|
@ -534,13 +589,21 @@ gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rectangle)
|
|||
"y2", &y2,
|
||||
NULL);
|
||||
|
||||
gimp_new_rect_select_tool_rect_select (rectangle,
|
||||
x1, y1,
|
||||
x2 - x1,
|
||||
y2 - y1);
|
||||
gimp_new_rect_select_tool_select (rectangle, x1, y1, x2 - x1, y2 - y1);
|
||||
|
||||
/* save the undo that we got when executing */
|
||||
rect_select->undo = gimp_undo_stack_peek (image->undo_stack);
|
||||
rect_select->redo = NULL;
|
||||
|
||||
if (! rect_select->use_saved_op)
|
||||
{
|
||||
/* remember the operation now in case we modify the rectangle */
|
||||
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
||||
g_object_get (options,
|
||||
"operation", &rect_select->operation,
|
||||
NULL);
|
||||
rect_select->use_saved_op = TRUE;
|
||||
}
|
||||
|
||||
gimp_image_flush (image);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,18 +37,22 @@ struct _GimpNewRectSelectTool
|
|||
{
|
||||
GimpSelectionTool parent_instance;
|
||||
|
||||
SelectOps operation; /* remember for use when modifying */
|
||||
gboolean use_saved_op; /* use operation or get from options */
|
||||
GimpUndo *undo;
|
||||
GimpUndo *redo;
|
||||
};
|
||||
|
||||
struct _GimpNewRectSelectToolClass
|
||||
{
|
||||
GimpSelectionToolClass parent_class;
|
||||
|
||||
void (* rect_select) (GimpNewRectSelectTool *rect_select,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h);
|
||||
void (* select) (GimpNewRectSelectTool *rect_select,
|
||||
SelectOps operation,
|
||||
gint x,
|
||||
gint y,
|
||||
gint w,
|
||||
gint h);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,32 +63,34 @@ typedef struct _GimpRectangleToolPrivate GimpRectangleToolPrivate;
|
|||
|
||||
struct _GimpRectangleToolPrivate
|
||||
{
|
||||
gint pressx; /* x where button pressed */
|
||||
gint pressy; /* y where button pressed */
|
||||
gint pressx; /* x where button pressed */
|
||||
gint pressy; /* y where button pressed */
|
||||
|
||||
gint x1, y1; /* upper left hand coordinate */
|
||||
gint x2, y2; /* lower right hand coords */
|
||||
gint x1, y1; /* upper left hand coordinate */
|
||||
gint x2, y2; /* lower right hand coords */
|
||||
|
||||
guint function; /* moving or resizing */
|
||||
guint function; /* moving or resizing */
|
||||
|
||||
gboolean constrain; /* constrain to image bounds */
|
||||
gboolean constrain; /* constrain to image bounds */
|
||||
|
||||
/* Internal state */
|
||||
gint startx; /* starting x coord */
|
||||
gint starty; /* starting y coord */
|
||||
gint startx; /* starting x coord */
|
||||
gint starty; /* starting y coord */
|
||||
|
||||
gint lastx; /* previous x coord */
|
||||
gint lasty; /* previous y coord */
|
||||
gint lastx; /* previous x coord */
|
||||
gint lasty; /* previous y coord */
|
||||
|
||||
gint dx1, dy1; /* display coords */
|
||||
gint dx2, dy2; /* */
|
||||
gint dx1, dy1; /* display coords */
|
||||
gint dx2, dy2; /* */
|
||||
|
||||
gint dcw, dch; /* width and height of edges */
|
||||
gint dcw, dch; /* width and height of edges */
|
||||
|
||||
gint saved_x1; /* for saving in case action is canceled */
|
||||
gint saved_y1;
|
||||
gint saved_x2;
|
||||
gint saved_y2;
|
||||
gdouble saved_center_x;
|
||||
gdouble saved_center_y;
|
||||
|
||||
GimpRectangleGuide guide; /* synced with options->guide, only exists for drawing */
|
||||
};
|
||||
|
|
@ -774,9 +776,15 @@ gimp_rectangle_tool_button_press (GimpTool *tool,
|
|||
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
||||
guint function;
|
||||
GimpRectangleToolPrivate *private;
|
||||
gint x = ROUND (coords->x);
|
||||
gint y = ROUND (coords->y);
|
||||
GimpRectangleOptions *options;
|
||||
|
||||
|
||||
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
||||
|
||||
options = GIMP_RECTANGLE_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
if (display != tool->display)
|
||||
{
|
||||
if (gimp_draw_tool_is_active (draw_tool))
|
||||
|
|
@ -784,10 +792,10 @@ gimp_rectangle_tool_button_press (GimpTool *tool,
|
|||
|
||||
function = RECT_CREATING;
|
||||
g_object_set (rectangle, "function", function,
|
||||
"x1", ROUND (coords->x),
|
||||
"y1", ROUND (coords->y),
|
||||
"x2", ROUND (coords->x),
|
||||
"y2", ROUND (coords->y),
|
||||
"x1", x,
|
||||
"y1", y,
|
||||
"x2", x,
|
||||
"y2", y,
|
||||
NULL);
|
||||
gimp_tool_control_set_snap_offsets (tool->control, 0, 0, 0, 0);
|
||||
|
||||
|
|
@ -803,6 +811,10 @@ gimp_rectangle_tool_button_press (GimpTool *tool,
|
|||
"x2", &private->saved_x2,
|
||||
"y2", &private->saved_y2,
|
||||
NULL);
|
||||
g_object_get (options,
|
||||
"center-x", &private->saved_center_x,
|
||||
"center-y", &private->saved_center_y,
|
||||
NULL);
|
||||
|
||||
g_object_get (rectangle,
|
||||
"function", &function,
|
||||
|
|
@ -810,27 +822,32 @@ gimp_rectangle_tool_button_press (GimpTool *tool,
|
|||
|
||||
if (function == RECT_CREATING)
|
||||
{
|
||||
g_object_set (options,
|
||||
"center-x", (gdouble) x,
|
||||
"center-y", (gdouble) y,
|
||||
NULL);
|
||||
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
g_object_set (rectangle,
|
||||
"x1", ROUND (coords->x),
|
||||
"y1", ROUND (coords->y),
|
||||
"x2", ROUND (coords->x),
|
||||
"y2", ROUND (coords->y),
|
||||
"x1", x,
|
||||
"y1", y,
|
||||
"x2", x,
|
||||
"y2", y,
|
||||
NULL);
|
||||
|
||||
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
||||
}
|
||||
|
||||
g_object_set (rectangle,
|
||||
"pressx", ROUND (coords->x),
|
||||
"pressy", ROUND (coords->y),
|
||||
"pressx", x,
|
||||
"pressy", y,
|
||||
NULL);
|
||||
|
||||
private->startx = ROUND (coords->x);
|
||||
private->starty = ROUND (coords->y);
|
||||
private->lastx = ROUND (coords->x);
|
||||
private->lasty = ROUND (coords->y);
|
||||
private->startx = x;
|
||||
private->starty = y;
|
||||
private->lastx = x;
|
||||
private->lasty = y;
|
||||
|
||||
gimp_tool_control_activate (tool->control);
|
||||
}
|
||||
|
|
@ -846,9 +863,12 @@ gimp_rectangle_tool_button_release (GimpTool *tool,
|
|||
GimpRectangleToolPrivate *private;
|
||||
guint function;
|
||||
gint pressx, pressy;
|
||||
GimpRectangleOptions *options;
|
||||
|
||||
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
||||
|
||||
options = GIMP_RECTANGLE_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
gimp_tool_control_halt (tool->control);
|
||||
|
||||
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
||||
|
|
@ -873,6 +893,11 @@ gimp_rectangle_tool_button_release (GimpTool *tool,
|
|||
}
|
||||
else
|
||||
{
|
||||
g_object_set (options,
|
||||
"center-x", private->saved_center_x,
|
||||
"center-y", private->saved_center_y,
|
||||
NULL);
|
||||
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
g_object_set (rectangle,
|
||||
|
|
@ -908,6 +933,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
gboolean fixed_center;
|
||||
gdouble width, height;
|
||||
gdouble center_x, center_y;
|
||||
gboolean aspect_square;
|
||||
|
||||
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
||||
|
||||
|
|
@ -934,10 +960,11 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
options = GIMP_RECTANGLE_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
g_object_get (options,
|
||||
"new-fixed-width", &fixed_width,
|
||||
"new-fixed-width", &fixed_width,
|
||||
"new-fixed-height", &fixed_height,
|
||||
"fixed-aspect", &fixed_aspect,
|
||||
"fixed-center", &fixed_center,
|
||||
"fixed-aspect", &fixed_aspect,
|
||||
"fixed-center", &fixed_center,
|
||||
"aspect-square", &aspect_square,
|
||||
NULL);
|
||||
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
||||
|
|
@ -991,7 +1018,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
x1 = max_x - width;
|
||||
}
|
||||
}
|
||||
else if (fixed_center || state & GDK_CONTROL_MASK)
|
||||
else if (fixed_center)
|
||||
{
|
||||
x2 = x1 + 2 * (center_x - x1);
|
||||
if (x1 < 0)
|
||||
|
|
@ -1030,7 +1057,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
x2 = width;
|
||||
}
|
||||
}
|
||||
else if (fixed_center || state & GDK_CONTROL_MASK)
|
||||
else if (fixed_center)
|
||||
{
|
||||
x1 = x2 - 2 * (x2 - center_x);
|
||||
if (x2 > max_x)
|
||||
|
|
@ -1088,7 +1115,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
y1 = max_y - height;
|
||||
}
|
||||
}
|
||||
else if (fixed_center || state & GDK_CONTROL_MASK)
|
||||
else if (fixed_center)
|
||||
{
|
||||
y2 = y1 + 2 * (center_y - y1);
|
||||
if (y1 < 0)
|
||||
|
|
@ -1127,7 +1154,7 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
y2 = height;
|
||||
}
|
||||
}
|
||||
else if (fixed_center || state & GDK_CONTROL_MASK)
|
||||
else if (fixed_center)
|
||||
{
|
||||
y1 = y2 - 2 * (y2 - center_y);
|
||||
if (y2 > max_y)
|
||||
|
|
@ -1162,13 +1189,17 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
break;
|
||||
}
|
||||
|
||||
if (fixed_aspect)
|
||||
if (fixed_aspect || aspect_square)
|
||||
{
|
||||
gdouble aspect;
|
||||
|
||||
g_object_get (options, "aspect", &aspect, NULL);
|
||||
|
||||
aspect = CLAMP (aspect, 1.0 / max_y, max_x);
|
||||
if (aspect_square)
|
||||
aspect = 1;
|
||||
else
|
||||
{
|
||||
g_object_get (options, "aspect", &aspect, NULL);
|
||||
aspect = CLAMP (aspect, 1.0 / max_y, max_x);
|
||||
}
|
||||
|
||||
switch (function)
|
||||
{
|
||||
|
|
@ -1209,50 +1240,6 @@ gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
}
|
||||
}
|
||||
|
||||
/* If the shift key is down, then make the rectangle square (or
|
||||
* ellipse circular)
|
||||
*/
|
||||
if (state & GDK_SHIFT_MASK)
|
||||
{
|
||||
switch (function)
|
||||
{
|
||||
case RECT_RESIZING_UPPER_LEFT:
|
||||
if (inc_x != 0)
|
||||
y1 = y2 - (x2 - x1);
|
||||
else
|
||||
x1 = x2 - (y2 - y1);
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_UPPER_RIGHT:
|
||||
case RECT_RESIZING_TOP:
|
||||
if (inc_x != 0)
|
||||
y1 = y2 - (x2 - x1);
|
||||
else
|
||||
x2 = x1 + (y2 - y1);
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_LOWER_LEFT:
|
||||
case RECT_RESIZING_LEFT:
|
||||
if (inc_x != 0)
|
||||
y2 = y1 + (x2 - x1);
|
||||
else
|
||||
x1 = x2 - (y2 - y1);
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_LOWER_RIGHT:
|
||||
case RECT_RESIZING_RIGHT:
|
||||
case RECT_RESIZING_BOTTOM:
|
||||
if (inc_x != 0)
|
||||
y2 = y1 + (x2 - x1);
|
||||
else
|
||||
x2 = x1 + (y2 - y1);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* make sure that the coords are in bounds */
|
||||
g_object_set (rectangle,
|
||||
"x1", MIN (x1, x2),
|
||||
|
|
@ -1463,15 +1450,6 @@ gimp_rectangle_tool_key_press (GimpTool *tool,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_rectangle_tool_modifier_key (GimpTool *tool,
|
||||
GdkModifierType key,
|
||||
gboolean press,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
gimp_rectangle_tool_oper_update (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
|
|
@ -2032,6 +2010,7 @@ gimp_rectangle_tool_update_options (GimpRectangleTool *rectangle,
|
|||
gboolean fixed_width;
|
||||
gboolean fixed_height;
|
||||
gboolean fixed_aspect;
|
||||
gboolean aspect_square;
|
||||
|
||||
g_object_get (rectangle,
|
||||
"x1", &x1,
|
||||
|
|
@ -2047,13 +2026,16 @@ gimp_rectangle_tool_update_options (GimpRectangleTool *rectangle,
|
|||
"new-fixed-width", &fixed_width,
|
||||
"new-fixed-height", &fixed_height,
|
||||
"fixed-aspect", &fixed_aspect,
|
||||
"aspect-square", &aspect_square,
|
||||
"dimensions-entry", &entry,
|
||||
NULL);
|
||||
|
||||
width = x2 - x1;
|
||||
height = y2 - y1;
|
||||
|
||||
if (height > 0.01)
|
||||
if (aspect_square)
|
||||
aspect = 1;
|
||||
else if (height > 0.01)
|
||||
aspect = width / height;
|
||||
else
|
||||
aspect = 0.0;
|
||||
|
|
@ -2090,7 +2072,7 @@ gimp_rectangle_tool_update_options (GimpRectangleTool *rectangle,
|
|||
"height", height,
|
||||
NULL);
|
||||
|
||||
if (! fixed_aspect)
|
||||
if (aspect_square || ! fixed_aspect)
|
||||
g_object_set (options,
|
||||
"aspect", aspect,
|
||||
NULL);
|
||||
|
|
|
|||
|
|
@ -109,11 +109,6 @@ void gimp_rectangle_tool_motion (GimpTool *tool,
|
|||
gboolean gimp_rectangle_tool_key_press (GimpTool *tool,
|
||||
GdkEventKey *kevent,
|
||||
GimpDisplay *display);
|
||||
void gimp_rectangle_tool_modifier_key (GimpTool *tool,
|
||||
GdkModifierType key,
|
||||
gboolean press,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display);
|
||||
void gimp_rectangle_tool_oper_update (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
GdkModifierType state,
|
||||
|
|
|
|||
Loading…
Reference in a new issue