Bill Skaggs <weskaggs@primate.ucdavis.edu>

* app/tools/gimprectangleselecttool.c
	* app/tools/gimprectangletool.c: make auto-shrink work.  Does
	the wrong thing for ellipse-select, though.
This commit is contained in:
William Skaggs 2006-06-11 18:52:42 +00:00
parent 8234078a31
commit 990e475d77
3 changed files with 136 additions and 76 deletions

View file

@ -1,3 +1,9 @@
2006-06-11 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimprectangleselecttool.c
* app/tools/gimprectangletool.c: make auto-shrink work. Does
the wrong thing for ellipse-select, though.
2006-06-10 Bill Skaggs <weskaggs@primate.ucdavis.edu>
Following up on previous commit, with assist from yosh.

View file

@ -30,6 +30,7 @@
#include "core/gimpchannel-select.h"
#include "core/gimplayer-floating-sel.h"
#include "core/gimpimage.h"
#include "core/gimpimage-crop.h"
#include "core/gimpimage-undo.h"
#include "core/gimppickable.h"
#include "core/gimptoolinfo.h"
@ -63,6 +64,7 @@ static void gimp_rect_select_tool_rectangle_tool_iface_init (GimpRectangleTo
static GObject *gimp_rect_select_tool_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_rect_select_tool_dispose (GObject *object);
static void gimp_rect_select_tool_finalize (GObject *object);
static void gimp_rect_select_tool_control (GimpTool *tool,
GimpToolAction action,
@ -110,6 +112,11 @@ static void gimp_rect_select_tool_real_select (GimpRectSelectTool *rec
gint w,
gint h);
static void gimp_rect_select_tool_auto_shrink_notify (GimpRectSelectOptions *options,
GParamSpec *pspec,
GimpRectSelectTool *rect_select);
static void gimp_rect_select_tool_auto_shrink (GimpRectSelectTool *rect_select);
G_DEFINE_TYPE_WITH_CODE (GimpRectSelectTool, gimp_rect_select_tool,
GIMP_TYPE_SELECTION_TOOL,
@ -144,7 +151,7 @@ gimp_rect_select_tool_class_init (GimpRectSelectToolClass *klass)
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
object_class->constructor = gimp_rect_select_tool_constructor;
object_class->dispose = gimp_rectangle_tool_dispose;
object_class->dispose = gimp_rect_select_tool_dispose;
object_class->finalize = gimp_rect_select_tool_finalize;
object_class->set_property = gimp_rectangle_tool_set_property;
object_class->get_property = gimp_rectangle_tool_get_property;
@ -192,15 +199,40 @@ gimp_rect_select_tool_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GObject *object;
GObject *options;
GimpTool *tool;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
gimp_rectangle_tool_constructor (object);
tool = GIMP_TOOL (object);
options = G_OBJECT (tool->tool_info->tool_options);
g_signal_connect_object (options, "notify::auto-shrink",
G_CALLBACK (gimp_rect_select_tool_auto_shrink_notify),
GIMP_RECTANGLE_TOOL (tool), 0);
return object;
}
static void
gimp_rect_select_tool_dispose (GObject *object)
{
GimpTool *tool = GIMP_TOOL (object);
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (object);
GObject *options;
options = G_OBJECT (tool->tool_info->tool_options);
gimp_rectangle_tool_dispose (object);
g_signal_handlers_disconnect_by_func (options,
G_CALLBACK (gimp_rect_select_tool_auto_shrink_notify),
rectangle);
}
static void
gimp_rect_select_tool_finalize (GObject *object)
{
@ -290,11 +322,15 @@ gimp_rect_select_tool_button_release (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display)
{
GimpRectSelectTool *rect_select = GIMP_RECT_SELECT_TOOL (tool);
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
GimpRectSelectTool *rect_select = GIMP_RECT_SELECT_TOOL (tool);
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
gboolean auto_shrink;
GimpSelectionOptions *options;
gimp_tool_pop_status (tool, display);
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
/*
* if the user has not moved the mouse, we need to redo the operation
* that was undone on button press.
@ -313,6 +349,13 @@ gimp_rect_select_tool_button_release (GimpTool *tool,
}
}
g_object_get (options,
"auto-shrink", &auto_shrink,
NULL);
if (auto_shrink)
gimp_rect_select_tool_auto_shrink (rect_select);
gimp_rectangle_tool_button_release (tool, coords, time, state, display);
if ((state & GDK_BUTTON3_MASK))
@ -411,15 +454,6 @@ gimp_rect_select_tool_select (GimpRectangleTool *rectangle,
x + w >= 0 && y + h >= 0 &&
w > 0 && h > 0);
g_object_get (options,
"auto-shrink", &auto_shrink,
NULL);
if (auto_shrink)
{
/* FIXME */
}
if (rect_select->use_saved_op)
operation = rect_select->operation;
else
@ -623,3 +657,82 @@ gimp_rect_select_tool_rectangle_changed (GimpRectangleTool *rectangle)
return TRUE;
}
static void
gimp_rect_select_tool_auto_shrink_notify (GimpRectSelectOptions *options,
GParamSpec *pspec,
GimpRectSelectTool *rect_select)
{
gboolean auto_shrink;
g_object_get (GIMP_SELECTION_OPTIONS (options),
"auto-shrink", &auto_shrink,
NULL);
if (auto_shrink)
gimp_rect_select_tool_auto_shrink (rect_select);
g_signal_emit_by_name (GIMP_RECTANGLE_TOOL (rect_select),
"rectangle-changed", NULL);
}
static void
gimp_rect_select_tool_auto_shrink (GimpRectSelectTool *rect_select)
{
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (rect_select);
GimpTool *tool = GIMP_TOOL (rect_select);
GimpDisplay *display = GIMP_TOOL (rect_select)->display;
gint width = display->image->width;
gint height = display->image->height;
gint offset_x = 0;
gint offset_y = 0;
gint rx1, ry1;
gint rx2, ry2;
gint x1, y1;
gint x2, y2;
gint shrunk_x1;
gint shrunk_y1;
gint shrunk_x2;
gint shrunk_y2;
gboolean shrink_merged;
g_object_get (GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options),
"shrink-merged", &shrink_merged,
NULL);
g_object_get (rectangle,
"x1", &rx1,
"y1", &ry1,
"x2", &rx2,
"y2", &ry2,
NULL);
x1 = rx1 - offset_x > 0 ? rx1 - offset_x : 0;
x2 = rx2 - offset_x < width ? rx2 - offset_x : width;
y1 = ry1 - offset_y > 0 ? ry1 - offset_y : 0;
y2 = ry2 - offset_y < height ? ry2 - offset_y : height;
if (gimp_image_crop_auto_shrink (display->image,
x1, y1, x2, y2,
! shrink_merged,
&shrunk_x1,
&shrunk_y1,
&shrunk_x2,
&shrunk_y2))
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rectangle));
g_object_set (rectangle,
"x1", offset_x + shrunk_x1,
"y1", offset_y + shrunk_y1,
"x2", offset_x + shrunk_x2,
"y2", offset_y + shrunk_y2,
NULL);
gimp_rectangle_tool_configure (rectangle);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rectangle));
}
}

View file

@ -28,7 +28,6 @@
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "core/gimpimage-crop.h"
#include "core/gimppickable.h"
#include "core/gimptoolinfo.h"
#include "core/gimpmarshal.h"
@ -133,8 +132,6 @@ static void gimp_rectangle_tool_draw_guides (GimpDrawTool *draw
/* Rectangle dialog functions */
static void rectangle_selection_callback (GtkWidget *widget,
GimpRectangleTool *rectangle);
static void rectangle_automatic_callback (GtkWidget *widget,
GimpRectangleTool *rectangle);
static void gimp_rectangle_tool_update_options (GimpRectangleTool *rectangle,
GimpDisplay *display);
@ -862,7 +859,6 @@ gimp_rectangle_tool_button_release (GimpTool *tool,
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
GimpRectangleToolPrivate *private;
guint function;
gint pressx, pressy;
GimpRectangleOptions *options;
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
@ -879,17 +875,15 @@ gimp_rectangle_tool_button_release (GimpTool *tool,
if (! (state & GDK_BUTTON3_MASK))
{
g_object_get (rectangle,
"pressx", &pressx,
"pressy", &pressy,
NULL);
if (gimp_rectangle_tool_no_movement (rectangle))
{
if (gimp_rectangle_tool_execute (rectangle))
gimp_rectangle_tool_halt (rectangle);
}
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
else
{
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
}
}
else
{
@ -1901,59 +1895,6 @@ rectangle_selection_callback (GtkWidget *widget,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rectangle));
}
static void
rectangle_automatic_callback (GtkWidget *widget,
GimpRectangleTool *rectangle)
{
GimpDisplay *display = GIMP_TOOL (rectangle)->display;
gint width = display->image->width;
gint height = display->image->height;
gint offset_x = 0;
gint offset_y = 0;
gint rx1, ry1;
gint rx2, ry2;
gint x1, y1;
gint x2, y2;
gint shrunk_x1;
gint shrunk_y1;
gint shrunk_x2;
gint shrunk_y2;
g_object_get (rectangle,
"x1", &rx1,
"y1", &ry1,
"x2", &rx2,
"y2", &ry2,
NULL);
x1 = rx1 - offset_x > 0 ? rx1 - offset_x : 0;
x2 = rx2 - offset_x < width ? rx2 - offset_x : width;
y1 = ry1 - offset_y > 0 ? ry1 - offset_y : 0;
y2 = ry2 - offset_y < height ? ry2 - offset_y : height;
if (gimp_image_crop_auto_shrink (display->image,
x1, y1, x2, y2,
FALSE,
&shrunk_x1,
&shrunk_y1,
&shrunk_x2,
&shrunk_y2))
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rectangle));
g_object_set (rectangle,
"x1", offset_x + shrunk_x1,
"y1", offset_y + shrunk_y1,
"x2", offset_x + shrunk_x2,
"y2", offset_y + shrunk_y2,
NULL);
gimp_rectangle_tool_configure (rectangle);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rectangle));
}
}
gboolean
gimp_rectangle_tool_execute (GimpRectangleTool *rectangle)
{