Bill Skaggs <weskaggs@primate.ucdavis.edu>

* app/tools/gimprectangletool.[ch]: add new signal
	"rectangle-changed" and method rectangle_changed.
	Emit them on button release and when dimensions are
	changed in controls.

	* app/tools/gimpnewrectselecttool.c: use rectangle_changed
	method to change selection, undoing previous change if
	necessary.
This commit is contained in:
William Skaggs 2006-06-04 17:08:26 +00:00
parent c2928c8721
commit 3e4d8075c7
5 changed files with 252 additions and 124 deletions

View File

@ -1,3 +1,14 @@
2006-06-04 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimprectangletool.[ch]: add new signal
"rectangle-changed" and method rectangle_changed.
Emit them on button release and when dimensions are
changed in controls.
* app/tools/gimpnewrectselecttool.c: use rectangle_changed
method to change selection, undoing previous change if
necessary.
2006-06-04 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpthumbbox.c (gimp_thumb_box_new): changed

View File

@ -61,47 +61,48 @@
static void gimp_new_rect_select_tool_rectangle_tool_iface_init (GimpRectangleToolInterface *iface);
static GObject *
gimp_new_rect_select_tool_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_new_rect_select_tool_finalize (GObject *object);
static void gimp_new_rect_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_new_rect_select_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
static gboolean gimp_new_rect_select_tool_execute (GimpRectangleTool *rect_tool,
gint x,
gint y,
gint w,
gint 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_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_new_rect_select_tool_finalize (GObject *object);
static void gimp_new_rect_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_new_rect_select_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
static gboolean gimp_new_rect_select_tool_execute (GimpRectangleTool *rect_tool,
gint x,
gint y,
gint w,
gint h);
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,
gint x,
gint y,
gint w,
gint h);
G_DEFINE_TYPE_WITH_CODE (GimpNewRectSelectTool, gimp_new_rect_select_tool,
@ -173,6 +174,7 @@ static void
gimp_new_rect_select_tool_rectangle_tool_iface_init (GimpRectangleToolInterface *iface)
{
iface->execute = gimp_new_rect_select_tool_execute;
iface->rectangle_changed = gimp_new_rect_select_tool_rectangle_changed;
}
static GObject *
@ -273,27 +275,27 @@ gimp_new_rect_select_tool_button_release (GimpTool *tool,
gimp_rectangle_tool_button_release (tool, coords, time, state, display);
/* if a rectangle still exists, "execute" the tool now */
if (tool->display)
{
gint x1, y1, x2, y2;
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
/* /\* if a rectangle still exists, "execute" the tool now *\/ */
/* if (tool->display) */
/* { */
/* gint x1, y1, x2, y2; */
/* GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool); */
g_object_get (GIMP_RECTANGLE_TOOL (tool),
"x1", &x1,
"y1", &y1,
"x2", &x2,
"y2", &y2,
NULL);
/* g_object_get (GIMP_RECTANGLE_TOOL (tool), */
/* "x1", &x1, */
/* "y1", &y1, */
/* "x2", &x2, */
/* "y2", &y2, */
/* NULL); */
gimp_rectangle_tool_execute (GIMP_RECTANGLE_TOOL (tool),
x1, y1,
x2 - x1,
y2 - y1);
/* gimp_rectangle_tool_execute (GIMP_RECTANGLE_TOOL (tool), */
/* x1, y1, */
/* x2 - x1, */
/* y2 - y1); */
/* save the undo that we got when executing */
rect_select->undo = gimp_undo_stack_peek (display->image->undo_stack);
}
/* /\* save the undo that we got when executing *\/ */
/* rect_select->undo = gimp_undo_stack_peek (display->image->undo_stack); */
/* } */
}
static void
@ -519,3 +521,44 @@ gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
options->feather_radius,
options->feather_radius);
}
static gboolean
gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rectangle)
{
GimpTool *tool = GIMP_TOOL (rectangle);
if (tool->display)
{
gint x1, y1, x2, y2;
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
GimpImage *image = tool->display->image;
GimpUndo *undo;
/* 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 */
undo = gimp_undo_stack_peek (image->undo_stack);
if (undo && rect_select->undo == undo)
{
gimp_image_undo (image);
rect_select->undo = NULL;
}
g_object_get (rectangle,
"x1", &x1,
"y1", &y1,
"x2", &x2,
"y2", &y2,
NULL);
gimp_rectangle_tool_execute (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);
}
return TRUE;
}

View File

@ -61,47 +61,48 @@
static void gimp_new_rect_select_tool_rectangle_tool_iface_init (GimpRectangleToolInterface *iface);
static GObject *
gimp_new_rect_select_tool_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_new_rect_select_tool_finalize (GObject *object);
static void gimp_new_rect_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_new_rect_select_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
static gboolean gimp_new_rect_select_tool_execute (GimpRectangleTool *rect_tool,
gint x,
gint y,
gint w,
gint 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_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_new_rect_select_tool_finalize (GObject *object);
static void gimp_new_rect_select_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_new_rect_select_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_new_rect_select_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
static gboolean gimp_new_rect_select_tool_execute (GimpRectangleTool *rect_tool,
gint x,
gint y,
gint w,
gint h);
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,
gint x,
gint y,
gint w,
gint h);
G_DEFINE_TYPE_WITH_CODE (GimpNewRectSelectTool, gimp_new_rect_select_tool,
@ -173,6 +174,7 @@ static void
gimp_new_rect_select_tool_rectangle_tool_iface_init (GimpRectangleToolInterface *iface)
{
iface->execute = gimp_new_rect_select_tool_execute;
iface->rectangle_changed = gimp_new_rect_select_tool_rectangle_changed;
}
static GObject *
@ -273,27 +275,27 @@ gimp_new_rect_select_tool_button_release (GimpTool *tool,
gimp_rectangle_tool_button_release (tool, coords, time, state, display);
/* if a rectangle still exists, "execute" the tool now */
if (tool->display)
{
gint x1, y1, x2, y2;
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
/* /\* if a rectangle still exists, "execute" the tool now *\/ */
/* if (tool->display) */
/* { */
/* gint x1, y1, x2, y2; */
/* GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool); */
g_object_get (GIMP_RECTANGLE_TOOL (tool),
"x1", &x1,
"y1", &y1,
"x2", &x2,
"y2", &y2,
NULL);
/* g_object_get (GIMP_RECTANGLE_TOOL (tool), */
/* "x1", &x1, */
/* "y1", &y1, */
/* "x2", &x2, */
/* "y2", &y2, */
/* NULL); */
gimp_rectangle_tool_execute (GIMP_RECTANGLE_TOOL (tool),
x1, y1,
x2 - x1,
y2 - y1);
/* gimp_rectangle_tool_execute (GIMP_RECTANGLE_TOOL (tool), */
/* x1, y1, */
/* x2 - x1, */
/* y2 - y1); */
/* save the undo that we got when executing */
rect_select->undo = gimp_undo_stack_peek (display->image->undo_stack);
}
/* /\* save the undo that we got when executing *\/ */
/* rect_select->undo = gimp_undo_stack_peek (display->image->undo_stack); */
/* } */
}
static void
@ -519,3 +521,44 @@ gimp_new_rect_select_tool_real_rect_select (GimpNewRectSelectTool *rect_select,
options->feather_radius,
options->feather_radius);
}
static gboolean
gimp_new_rect_select_tool_rectangle_changed (GimpRectangleTool *rectangle)
{
GimpTool *tool = GIMP_TOOL (rectangle);
if (tool->display)
{
gint x1, y1, x2, y2;
GimpNewRectSelectTool *rect_select = GIMP_NEW_RECT_SELECT_TOOL (tool);
GimpImage *image = tool->display->image;
GimpUndo *undo;
/* 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 */
undo = gimp_undo_stack_peek (image->undo_stack);
if (undo && rect_select->undo == undo)
{
gimp_image_undo (image);
rect_select->undo = NULL;
}
g_object_get (rectangle,
"x1", &x1,
"y1", &y1,
"x2", &x2,
"y2", &y2,
NULL);
gimp_rectangle_tool_execute (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);
}
return TRUE;
}

View File

@ -31,7 +31,7 @@
#include "core/gimpimage-crop.h"
#include "core/gimppickable.h"
#include "core/gimptoolinfo.h"
#include "core/gimpmarshal.h"
#include "display/gimpcanvas.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
@ -44,6 +44,12 @@
#include "gimp-intl.h"
enum
{
RECTANGLE_CHANGED,
LAST_SIGNAL
};
/* speed of key movement */
#define ARROW_VELOCITY 25
@ -161,6 +167,8 @@ gimp_rectangle_tool_interface_get_type (void)
return rectangle_tool_iface_type;
}
static guint gimp_rectangle_tool_signals[LAST_SIGNAL] = { 0 };
static void
gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *iface)
{
@ -168,6 +176,15 @@ gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *iface)
if (! initialized)
{
gimp_rectangle_tool_signals[RECTANGLE_CHANGED] =
g_signal_new ("rectangle-changed",
G_TYPE_FROM_INTERFACE (iface),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpRectangleToolInterface, rectangle_changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
g_object_interface_install_property (iface,
g_param_spec_int ("pressx",
NULL, NULL,
@ -230,6 +247,8 @@ gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *iface)
FALSE,
GIMP_PARAM_READWRITE));
iface->rectangle_changed = NULL;
initialized = TRUE;
}
}
@ -807,6 +826,8 @@ gimp_rectangle_tool_button_release (GimpTool *tool,
gimp_rectangle_tool_response (NULL, GIMP_RECTANGLE_MODE_EXECUTE,
rectangle);
}
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
}
}
@ -2007,6 +2028,8 @@ gimp_rectangle_tool_notify_width (GimpRectangleOptions *options,
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
GIMP_TOOL (rectangle)->display);
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
}
/*
@ -2048,6 +2071,8 @@ gimp_rectangle_tool_notify_height (GimpRectangleOptions *options,
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
GIMP_TOOL (rectangle)->display);
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
}
/*
@ -2089,6 +2114,8 @@ gimp_rectangle_tool_notify_aspect (GimpRectangleOptions *options,
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
GIMP_TOOL (rectangle)->display);
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
}
static void
@ -2208,4 +2235,6 @@ gimp_rectangle_tool_notify_dimensions (GimpRectangleOptions *options,
a bunch of code */
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
GIMP_TOOL (rectangle)->display);
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
}

View File

@ -69,11 +69,13 @@ struct _GimpRectangleToolInterface
{
GTypeInterface base_iface;
gboolean (* execute) (GimpRectangleTool *rect_tool,
gint x,
gint y,
gint w,
gint h);
gboolean (* execute) (GimpRectangleTool *rect_tool,
gint x,
gint y,
gint w,
gint h);
gboolean (* rectangle_changed) (GimpRectangleTool *rect_tool);
};