app: small style cleanup in the merged cage code

This commit is contained in:
Michael Natterer 2011-03-23 22:29:00 +01:00
parent f2d5831ee2
commit 1659f62e2c
4 changed files with 215 additions and 156 deletions

View File

@ -21,12 +21,12 @@
#include <gegl.h> #include <gegl.h>
#include "gimp-gegl-types.h"
#include "libgimpconfig/gimpconfig.h" #include "libgimpconfig/gimpconfig.h"
#include "libgimpmath/gimpmath.h" #include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h" #include "libgimpbase/gimpbase.h"
#include "gimp-gegl-types.h"
#include "gimpcageconfig.h" #include "gimpcageconfig.h"
@ -52,6 +52,7 @@ static void gimp_cage_config_set_property (GObject *object,
static void gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc); static void gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc);
static void gimp_cage_config_compute_edges_normal (GimpCageConfig *gcc); static void gimp_cage_config_compute_edges_normal (GimpCageConfig *gcc);
G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config, G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config,
GIMP_TYPE_IMAGE_MAP_CONFIG, GIMP_TYPE_IMAGE_MAP_CONFIG,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
@ -59,31 +60,34 @@ G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config,
#define parent_class gimp_cage_config_parent_class #define parent_class gimp_cage_config_parent_class
#ifdef DEBUG_CAGE #ifdef DEBUG_CAGE
static void static void
print_cage (GimpCageConfig *gcc) print_cage (GimpCageConfig *gcc)
{ {
gint i; gint i;
GeglRectangle bounding_box; GeglRectangle bounding_box;
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
bounding_box = gimp_cage_config_get_bounding_box (gcc); bounding_box = gimp_cage_config_get_bounding_box (gcc);
for (i = 0; i < gcc->n_cage_vertices; i++) for (i = 0; i < gcc->n_cage_vertices; i++)
{ {
printf("cgx: %.0f cgy: %.0f cvdx: %.0f cvdy: %.0f sf: %.2f normx: %.2f normy: %.2f %s\n", g_printerr ("cgx: %.0f cgy: %.0f cvdx: %.0f cvdy: %.0f sf: %.2f normx: %.2f normy: %.2f %s\n",
gcc->cage_points[i].src_point.x + ((gcc->cage_mode==GIMP_CAGE_MODE_CAGE_CHANGE)?gcc->displacement_x:0), gcc->cage_points[i].src_point.x + ((gcc->cage_mode==GIMP_CAGE_MODE_CAGE_CHANGE)?gcc->displacement_x:0),
gcc->cage_points[i].src_point.y + ((gcc->cage_mode==GIMP_CAGE_MODE_CAGE_CHANGE)?gcc->displacement_y:0), gcc->cage_points[i].src_point.y + ((gcc->cage_mode==GIMP_CAGE_MODE_CAGE_CHANGE)?gcc->displacement_y:0),
gcc->cage_points[i].dest_point.x + ((gcc->cage_mode==GIMP_CAGE_MODE_DEFORM)?gcc->displacement_x:0), gcc->cage_points[i].dest_point.x + ((gcc->cage_mode==GIMP_CAGE_MODE_DEFORM)?gcc->displacement_x:0),
gcc->cage_points[i].dest_point.y + ((gcc->cage_mode==GIMP_CAGE_MODE_DEFORM)?gcc->displacement_y:0), gcc->cage_points[i].dest_point.y + ((gcc->cage_mode==GIMP_CAGE_MODE_DEFORM)?gcc->displacement_y:0),
gcc->cage_points[i].edge_scaling_factor, gcc->cage_points[i].edge_scaling_factor,
gcc->cage_points[i].edge_normal.x, gcc->cage_points[i].edge_normal.x,
gcc->cage_points[i].edge_normal.y, gcc->cage_points[i].edge_normal.y,
((gcc->cage_points[i].selected) ? "S" : "NS")); ((gcc->cage_points[i].selected) ? "S" : "NS"));
} }
printf("bounding box: x: %d y: %d width: %d height: %d\n", bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height);
printf("disp x: %f disp y: %f\n", gcc->displacement_x, gcc->displacement_y); g_printerr ("bounding box: x: %d y: %d width: %d height: %d\n", bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height);
printf("done\n"); g_printerr ("disp x: %f disp y: %f\n", gcc->displacement_x, gcc->displacement_y);
g_printerr ("done\n");
} }
#endif #endif
@ -110,7 +114,7 @@ gimp_cage_config_init (GimpCageConfig *self)
static void static void
gimp_cage_config_finalize (GObject *object) gimp_cage_config_finalize (GObject *object)
{ {
GimpCageConfig *gcc = GIMP_CAGE_CONFIG (object); GimpCageConfig *gcc = GIMP_CAGE_CONFIG (object);
g_free (gcc->cage_points); g_free (gcc->cage_points);
@ -210,11 +214,11 @@ gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc)
* Returns: the real position of the given point, as a GimpVector2 * Returns: the real position of the given point, as a GimpVector2
*/ */
GimpVector2 GimpVector2
gimp_cage_config_get_point_coordinate (GimpCageConfig *gcc, gimp_cage_config_get_point_coordinate (GimpCageConfig *gcc,
GimpCageMode mode, GimpCageMode mode,
gint point_number) gint point_number)
{ {
GimpVector2 point = {0.0, 0.0}; GimpVector2 point = { 0.0, 0.0 };
g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), point); g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), point);
g_return_val_if_fail (point_number < gcc->n_cage_vertices, point); g_return_val_if_fail (point_number < gcc->n_cage_vertices, point);
@ -262,10 +266,10 @@ gimp_cage_config_get_point_coordinate (GimpCageConfig *gcc,
* This displacement need to be commited to become effective. * This displacement need to be commited to become effective.
*/ */
void void
gimp_cage_config_add_displacement (GimpCageConfig *gcc, gimp_cage_config_add_displacement (GimpCageConfig *gcc,
GimpCageMode mode, GimpCageMode mode,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
@ -285,7 +289,7 @@ gimp_cage_config_add_displacement (GimpCageConfig *gcc,
* Apply the displacement to the cage * Apply the displacement to the cage
*/ */
void void
gimp_cage_config_commit_displacement (GimpCageConfig *gcc) gimp_cage_config_commit_displacement (GimpCageConfig *gcc)
{ {
gint i; gint i;
@ -309,6 +313,7 @@ gimp_cage_config_commit_displacement (GimpCageConfig *gcc)
} }
} }
} }
gimp_cage_config_compute_scaling_factor (gcc); gimp_cage_config_compute_scaling_factor (gcc);
gimp_cage_config_compute_edges_normal (gcc); gimp_cage_config_compute_edges_normal (gcc);
gimp_cage_config_reset_displacement (gcc); gimp_cage_config_reset_displacement (gcc);
@ -321,7 +326,7 @@ gimp_cage_config_commit_displacement (GimpCageConfig *gcc)
* Set the displacement to zero. * Set the displacement to zero.
*/ */
void void
gimp_cage_config_reset_displacement (GimpCageConfig *gcc) gimp_cage_config_reset_displacement (GimpCageConfig *gcc)
{ {
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
@ -338,7 +343,7 @@ gimp_cage_config_reset_displacement (GimpCageConfig *gcc)
* Returns: the bounding box of the source cage, as a GeglRectangle * Returns: the bounding box of the source cage, as a GeglRectangle
*/ */
GeglRectangle GeglRectangle
gimp_cage_config_get_bounding_box (GimpCageConfig *gcc) gimp_cage_config_get_bounding_box (GimpCageConfig *gcc)
{ {
GeglRectangle bounding_box = { 0, }; GeglRectangle bounding_box = { 0, };
gint i; gint i;
@ -629,9 +634,9 @@ gimp_cage_config_select_area (GimpCageConfig *gcc,
* Select cage's point inside the given area. Already selected point stay selected. * Select cage's point inside the given area. Already selected point stay selected.
*/ */
void void
gimp_cage_config_select_add_area (GimpCageConfig *gcc, gimp_cage_config_select_add_area (GimpCageConfig *gcc,
GimpCageMode mode, GimpCageMode mode,
GeglRectangle area) GeglRectangle area)
{ {
gint i; gint i;
@ -670,8 +675,8 @@ gimp_cage_config_select_add_area (GimpCageConfig *gcc,
* Toggle the selection of the given cage point * Toggle the selection of the given cage point
*/ */
void void
gimp_cage_config_toggle_point_selection (GimpCageConfig *gcc, gimp_cage_config_toggle_point_selection (GimpCageConfig *gcc,
gint point_number) gint point_number)
{ {
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
g_return_if_fail (point_number < gcc->n_cage_vertices); g_return_if_fail (point_number < gcc->n_cage_vertices);
@ -687,7 +692,7 @@ gimp_cage_config_toggle_point_selection (GimpCageConfig *gcc,
* Deselect all cage points. * Deselect all cage points.
*/ */
void void
gimp_cage_config_deselect_points (GimpCageConfig *gcc) gimp_cage_config_deselect_points (GimpCageConfig *gcc)
{ {
gint i; gint i;
@ -697,4 +702,4 @@ gimp_cage_config_deselect_points (GimpCageConfig *gcc)
{ {
gcc->cage_points[i].selected = FALSE; gcc->cage_points[i].selected = FALSE;
} }
} }

View File

@ -86,4 +86,5 @@ void gimp_cage_config_toggle_point_selection (GimpCageConfig *gcc,
gint point_number); gint point_number);
void gimp_cage_config_deselect_points (GimpCageConfig *gcc); void gimp_cage_config_deselect_points (GimpCageConfig *gcc);
#endif /* __GIMP_CAGE_CONFIG_H__ */ #endif /* __GIMP_CAGE_CONFIG_H__ */

View File

@ -128,7 +128,7 @@ gimp_operation_cage_transform_init (GimpOperationCageTransform *self)
} }
static void static void
gimp_operation_cage_transform_finalize (GObject *object) gimp_operation_cage_transform_finalize (GObject *object)
{ {
GimpOperationCageTransform *self = GIMP_OPERATION_CAGE_TRANSFORM (object); GimpOperationCageTransform *self = GIMP_OPERATION_CAGE_TRANSFORM (object);
@ -190,7 +190,7 @@ gimp_operation_cage_transform_set_property (GObject *object,
} }
static void static void
gimp_operation_cage_transform_prepare (GeglOperation *operation) gimp_operation_cage_transform_prepare (GeglOperation *operation)
{ {
GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation); GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation);
GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config); GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);

View File

@ -61,6 +61,19 @@
#include "gimp-intl.h" #include "gimp-intl.h"
enum
{
CAGE_STATE_INIT,
CAGE_STATE_WAIT,
CAGE_STATE_MOVE_HANDLE,
CAGE_STATE_SELECTING,
CAGE_STATE_CLOSING,
DEFORM_STATE_WAIT,
DEFORM_STATE_MOVE_HANDLE,
DEFORM_STATE_SELECTING
};
static void gimp_cage_tool_finalize (GObject *object); static void gimp_cage_tool_finalize (GObject *object);
static void gimp_cage_tool_start (GimpCageTool *ct, static void gimp_cage_tool_start (GimpCageTool *ct,
GimpDisplay *display); GimpDisplay *display);
@ -122,21 +135,11 @@ static void gimp_cage_tool_image_map_update (GimpCageTool *ct);
static void gimp_cage_tool_create_render_node (GimpCageTool *ct); static void gimp_cage_tool_create_render_node (GimpCageTool *ct);
static void gimp_cage_tool_render_node_update (GimpCageTool *ct); static void gimp_cage_tool_render_node_update (GimpCageTool *ct);
G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL) G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL)
#define parent_class gimp_cage_tool_parent_class #define parent_class gimp_cage_tool_parent_class
enum
{
CAGE_STATE_INIT,
CAGE_STATE_WAIT,
CAGE_STATE_MOVE_HANDLE,
CAGE_STATE_SELECTING,
CAGE_STATE_CLOSING,
DEFORM_STATE_WAIT,
DEFORM_STATE_MOVE_HANDLE,
DEFORM_STATE_SELECTING
};
void void
gimp_cage_tool_register (GimpToolRegisterCallback callback, gimp_cage_tool_register (GimpToolRegisterCallback callback,
@ -313,12 +316,14 @@ gimp_cage_tool_options_notify (GimpTool *tool,
NULL); NULL);
if (mode == GIMP_CAGE_MODE_DEFORM) if (mode == GIMP_CAGE_MODE_DEFORM)
/* switch to deform mode */
{ {
/* switch to deform mode */
ct->cage_complete = TRUE; ct->cage_complete = TRUE;
gimp_cage_config_reset_displacement (ct->config); gimp_cage_config_reset_displacement (ct->config);
gimp_cage_config_reverse_cage_if_needed (ct->config); gimp_cage_config_reverse_cage_if_needed (ct->config);
gimp_tool_push_status (tool, tool->display, _("Press ENTER to commit the transform")); gimp_tool_push_status (tool, tool->display,
_("Press ENTER to commit the transform"));
ct->tool_state = DEFORM_STATE_WAIT; ct->tool_state = DEFORM_STATE_WAIT;
if (ct->dirty_coef) if (ct->dirty_coef)
@ -335,14 +340,16 @@ gimp_cage_tool_options_notify (GimpTool *tool,
{ {
GimpImage *image = gimp_display_get_image (tool->display); GimpImage *image = gimp_display_get_image (tool->display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpDrawable *drawable = gimp_image_get_active_drawable (image);
gimp_cage_tool_create_image_map (ct, drawable); gimp_cage_tool_create_image_map (ct, drawable);
} }
gimp_cage_tool_image_map_update (ct); gimp_cage_tool_image_map_update (ct);
} }
else else
/* switch to edit mode */
{ {
/* switch to edit mode */
gimp_image_map_clear (ct->image_map); gimp_image_map_clear (ct->image_map);
gimp_image_flush (gimp_display_get_image (tool->display)); gimp_image_flush (gimp_display_get_image (tool->display));
gimp_tool_pop_status (tool, tool->display); gimp_tool_pop_status (tool, tool->display);
@ -419,14 +426,14 @@ gimp_cage_tool_motion (GimpTool *tool,
switch (ct->tool_state) switch (ct->tool_state)
{ {
case CAGE_STATE_MOVE_HANDLE: case CAGE_STATE_MOVE_HANDLE:
case CAGE_STATE_CLOSING: case CAGE_STATE_CLOSING:
case DEFORM_STATE_MOVE_HANDLE: case DEFORM_STATE_MOVE_HANDLE:
gimp_cage_config_add_displacement (ct->config, gimp_cage_config_add_displacement (ct->config,
options->cage_mode, options->cage_mode,
ct->cursor_x - ct->movement_start_x, ct->cursor_x - ct->movement_start_x,
ct->cursor_y - ct->movement_start_y); ct->cursor_y - ct->movement_start_y);
break; break;
} }
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
@ -489,7 +496,9 @@ gimp_cage_tool_button_press (GimpTool *tool,
switch (ct->tool_state) switch (ct->tool_state)
{ {
case CAGE_STATE_INIT: case CAGE_STATE_INIT:
/* No handle yet, we add the first one and swith the tool to moving handle state. */ /* No handle yet, we add the first one and swith the tool to
* moving handle state.
*/
gimp_cage_config_add_cage_point (ct->config, gimp_cage_config_add_cage_point (ct->config,
coords->x - ct->offset_x, coords->x - ct->offset_x,
coords->y - ct->offset_y); coords->y - ct->offset_y);
@ -501,64 +510,84 @@ gimp_cage_tool_button_press (GimpTool *tool,
if (ct->cage_complete == FALSE) if (ct->cage_complete == FALSE)
{ {
if (handle == -1) if (handle == -1)
/* User clicked on the background, we add a new handle and move it */
{ {
/* User clicked on the background, we add a new handle
* and move it
*/
gimp_cage_config_add_cage_point (ct->config, gimp_cage_config_add_cage_point (ct->config,
coords->x - ct->offset_x, coords->x - ct->offset_x,
coords->y - ct->offset_y); coords->y - ct->offset_y);
gimp_cage_config_select_point (ct->config, ct->config->n_cage_vertices - 1); gimp_cage_config_select_point (ct->config, ct->config->n_cage_vertices - 1);
ct->tool_state = CAGE_STATE_MOVE_HANDLE; ct->tool_state = CAGE_STATE_MOVE_HANDLE;
} }
if (handle == 0 && ct->config->n_cage_vertices > 2) if (handle == 0 && ct->config->n_cage_vertices > 2)
/* User clicked on the first handle, we wait for release for closing the cage and switching to deform if possible */
{ {
/* User clicked on the first handle, we wait for
* release for closing the cage and switching to
* deform if possible
*/
gimp_cage_config_select_point (ct->config, 0); gimp_cage_config_select_point (ct->config, 0);
ct->tool_state = CAGE_STATE_CLOSING; ct->tool_state = CAGE_STATE_CLOSING;
} }
if (handle > 0) if (handle > 0)
/* User clicked on a handle, so we move it */
{ {
/* User clicked on a handle, so we move it */
if (state & GDK_SHIFT_MASK) if (state & GDK_SHIFT_MASK)
/* Multiple selection */
{ {
/* Multiple selection */
gimp_cage_config_toggle_point_selection (ct->config, handle); gimp_cage_config_toggle_point_selection (ct->config, handle);
} }
else else
/* New selection */
{ {
/* New selection */
if (! ct->config->cage_points[handle].selected) if (! ct->config->cage_points[handle].selected)
{ {
gimp_cage_config_select_point (ct->config, handle); gimp_cage_config_select_point (ct->config, handle);
} }
} }
ct->tool_state = CAGE_STATE_MOVE_HANDLE; ct->tool_state = CAGE_STATE_MOVE_HANDLE;
} }
} }
else /* Cage already closed */ else
{ {
/* Cage already closed */
if (handle == -1) if (handle == -1)
/* User clicked on the background, we start a rubber band selection */
{ {
/* User clicked on the background, we start a rubber
* band selection
*/
ct->selection_start_x = coords->x; ct->selection_start_x = coords->x;
ct->selection_start_y = coords->y; ct->selection_start_y = coords->y;
ct->tool_state = CAGE_STATE_SELECTING; ct->tool_state = CAGE_STATE_SELECTING;
} }
if (handle >= 0) if (handle >= 0)
/* User clicked on a handle, so we move it */
{ {
/* User clicked on a handle, so we move it */
if (state & GDK_SHIFT_MASK) if (state & GDK_SHIFT_MASK)
/* Multiple selection */
{ {
/* Multiple selection */
gimp_cage_config_toggle_point_selection (ct->config, handle); gimp_cage_config_toggle_point_selection (ct->config, handle);
} }
else else
/* New selection */
{ {
/* New selection */
if (! ct->config->cage_points[handle].selected) if (! ct->config->cage_points[handle].selected)
{ {
gimp_cage_config_select_point (ct->config, handle); gimp_cage_config_select_point (ct->config, handle);
} }
} }
ct->tool_state = CAGE_STATE_MOVE_HANDLE; ct->tool_state = CAGE_STATE_MOVE_HANDLE;
} }
} }
@ -566,28 +595,35 @@ gimp_cage_tool_button_press (GimpTool *tool,
case DEFORM_STATE_WAIT: case DEFORM_STATE_WAIT:
if (handle == -1) if (handle == -1)
/* User clicked on the background, we start a rubber band selection */
{ {
/* User clicked on the background, we start a rubber band
* selection
*/
ct->selection_start_x = coords->x; ct->selection_start_x = coords->x;
ct->selection_start_y = coords->y; ct->selection_start_y = coords->y;
ct->tool_state = DEFORM_STATE_SELECTING; ct->tool_state = DEFORM_STATE_SELECTING;
} }
if (handle >= 0) if (handle >= 0)
/* User clicked on a handle, so we move it */
{ {
/* User clicked on a handle, so we move it */
if (state & GDK_SHIFT_MASK) if (state & GDK_SHIFT_MASK)
/* Multiple selection */
{ {
/* Multiple selection */
gimp_cage_config_toggle_point_selection (ct->config, handle); gimp_cage_config_toggle_point_selection (ct->config, handle);
} }
else else
/* New selection */
{ {
/* New selection */
if (! ct->config->cage_points[handle].selected) if (! ct->config->cage_points[handle].selected)
{ {
gimp_cage_config_select_point (ct->config, handle); gimp_cage_config_select_point (ct->config, handle);
} }
} }
ct->tool_state = DEFORM_STATE_MOVE_HANDLE; ct->tool_state = DEFORM_STATE_MOVE_HANDLE;
} }
break; break;
@ -608,94 +644,105 @@ gimp_cage_tool_button_release (GimpTool *tool,
gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct)); gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
if (state & GDK_BUTTON3_MASK) if (state & GDK_BUTTON3_MASK)
/* Cancelling */
{ {
switch(ct->tool_state) /* Cancelling */
switch (ct->tool_state)
{ {
case CAGE_STATE_CLOSING: case CAGE_STATE_CLOSING:
ct->tool_state = CAGE_STATE_WAIT; ct->tool_state = CAGE_STATE_WAIT;
break; break;
case CAGE_STATE_MOVE_HANDLE: case CAGE_STATE_MOVE_HANDLE:
gimp_cage_config_remove_last_cage_point (ct->config); gimp_cage_config_remove_last_cage_point (ct->config);
ct->tool_state = CAGE_STATE_WAIT; ct->tool_state = CAGE_STATE_WAIT;
break; break;
case CAGE_STATE_SELECTING: case CAGE_STATE_SELECTING:
ct->tool_state = CAGE_STATE_WAIT; ct->tool_state = CAGE_STATE_WAIT;
break; break;
case DEFORM_STATE_MOVE_HANDLE: case DEFORM_STATE_MOVE_HANDLE:
gimp_cage_tool_image_map_update (ct); gimp_cage_tool_image_map_update (ct);
ct->tool_state = DEFORM_STATE_WAIT; ct->tool_state = DEFORM_STATE_WAIT;
break; break;
case DEFORM_STATE_SELECTING: case DEFORM_STATE_SELECTING:
ct->tool_state = DEFORM_STATE_WAIT; ct->tool_state = DEFORM_STATE_WAIT;
break; break;
} }
gimp_cage_config_reset_displacement (ct->config); gimp_cage_config_reset_displacement (ct->config);
} }
else else
/* Normal release */
{ {
switch(ct->tool_state) /* Normal release */
switch (ct->tool_state)
{ {
case CAGE_STATE_CLOSING: case CAGE_STATE_CLOSING:
ct->dirty_coef = TRUE; ct->dirty_coef = TRUE;
gimp_cage_config_commit_displacement (ct->config); gimp_cage_config_commit_displacement (ct->config);
g_object_set (options, "cage-mode", GIMP_CAGE_MODE_DEFORM, NULL); g_object_set (options, "cage-mode", GIMP_CAGE_MODE_DEFORM, NULL);
break; break;
case CAGE_STATE_MOVE_HANDLE:
ct->dirty_coef = TRUE;
ct->tool_state = CAGE_STATE_WAIT;
gimp_cage_config_commit_displacement (ct->config);
break;
case CAGE_STATE_SELECTING:
{
GeglRectangle area = { MIN (ct->selection_start_x, coords->x) - ct->offset_x,
MIN (ct->selection_start_y, coords->y) - ct->offset_y,
abs (ct->selection_start_x - coords->x),
abs (ct->selection_start_y - coords->y) };
if (state & GDK_SHIFT_MASK)
{
gimp_cage_config_select_add_area (ct->config,
GIMP_CAGE_MODE_CAGE_CHANGE,
area);
}
else
{
gimp_cage_config_select_area (ct->config,
GIMP_CAGE_MODE_CAGE_CHANGE,
area);
}
case CAGE_STATE_MOVE_HANDLE:
ct->dirty_coef = TRUE;
ct->tool_state = CAGE_STATE_WAIT; ct->tool_state = CAGE_STATE_WAIT;
gimp_cage_config_commit_displacement (ct->config); }
break; break;
case CAGE_STATE_SELECTING: case DEFORM_STATE_MOVE_HANDLE:
ct->tool_state = DEFORM_STATE_WAIT;
gimp_cage_config_commit_displacement (ct->config);
gimp_cage_tool_image_map_update (ct);
break;
case DEFORM_STATE_SELECTING:
{
GeglRectangle area = { MIN (ct->selection_start_x, coords->x) - ct->offset_x,
MIN (ct->selection_start_y, coords->y) - ct->offset_y,
abs (ct->selection_start_x - coords->x),
abs (ct->selection_start_y - coords->y) };
if (state & GDK_SHIFT_MASK)
{ {
GeglRectangle area = {MIN(ct->selection_start_x, coords->x) - ct->offset_x, gimp_cage_config_select_add_area (ct->config,
MIN(ct->selection_start_y, coords->y) - ct->offset_y, GIMP_CAGE_MODE_DEFORM, area);
abs (ct->selection_start_x - coords->x), }
abs (ct->selection_start_y - coords->y)}; else
{
if (state & GDK_SHIFT_MASK) gimp_cage_config_select_area (ct->config,
{ GIMP_CAGE_MODE_DEFORM, area);
gimp_cage_config_select_add_area (ct->config, GIMP_CAGE_MODE_CAGE_CHANGE, area);
}
else
{
gimp_cage_config_select_area (ct->config, GIMP_CAGE_MODE_CAGE_CHANGE, area);
}
ct->tool_state = CAGE_STATE_WAIT;
} }
break;
case DEFORM_STATE_MOVE_HANDLE:
ct->tool_state = DEFORM_STATE_WAIT; ct->tool_state = DEFORM_STATE_WAIT;
gimp_cage_config_commit_displacement (ct->config); }
gimp_cage_tool_image_map_update (ct); break;
break;
case DEFORM_STATE_SELECTING:
{
GeglRectangle area = {MIN(ct->selection_start_x, coords->x) - ct->offset_x,
MIN(ct->selection_start_y, coords->y) - ct->offset_y,
abs (ct->selection_start_x - coords->x),
abs (ct->selection_start_y - coords->y)};
if (state & GDK_SHIFT_MASK)
{
gimp_cage_config_select_add_area (ct->config, GIMP_CAGE_MODE_DEFORM, area);
}
else
{
gimp_cage_config_select_area (ct->config, GIMP_CAGE_MODE_DEFORM, area);
}
ct->tool_state = DEFORM_STATE_WAIT;
}
break;
} }
} }
@ -750,9 +797,14 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
gimp_draw_tool_push_group (draw_tool, stroke_group); gimp_draw_tool_push_group (draw_tool, stroke_group);
/* If needed, draw ligne to the cursor. */ /* If needed, draw ligne to the cursor. */
if (!ct->cage_complete) if (! ct->cage_complete)
{ {
GimpVector2 last_point = gimp_cage_config_get_point_coordinate (ct->config, GIMP_CAGE_MODE_CAGE_CHANGE, n_vertices - 1); GimpVector2 last_point;
last_point = gimp_cage_config_get_point_coordinate (ct->config,
GIMP_CAGE_MODE_CAGE_CHANGE,
n_vertices - 1);
gimp_draw_tool_add_line (draw_tool, gimp_draw_tool_add_line (draw_tool,
last_point.x + ct->offset_x, last_point.x + ct->offset_x,
last_point.y + ct->offset_y, last_point.y + ct->offset_y,
@ -775,7 +827,7 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
if (i > 0 || ct->cage_complete) if (i > 0 || ct->cage_complete)
{ {
gint index_point2; gint index_point2;
if (i == 0) if (i == 0)
index_point2 = n_vertices - 1; index_point2 = n_vertices - 1;
@ -824,28 +876,29 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
} }
} }
if (ct->tool_state == DEFORM_STATE_SELECTING || ct->tool_state == CAGE_STATE_SELECTING) if (ct->tool_state == DEFORM_STATE_SELECTING ||
ct->tool_state == CAGE_STATE_SELECTING)
{ {
gimp_draw_tool_add_rectangle (draw_tool, gimp_draw_tool_add_rectangle (draw_tool,
FALSE, FALSE,
MIN(ct->selection_start_x, ct->cursor_x), MIN (ct->selection_start_x, ct->cursor_x),
MIN(ct->selection_start_y, ct->cursor_y), MIN (ct->selection_start_y, ct->cursor_y),
abs (ct->selection_start_x - ct->cursor_x), abs (ct->selection_start_x - ct->cursor_x),
abs (ct->selection_start_y - ct->cursor_y)); abs (ct->selection_start_y - ct->cursor_y));
} }
} }
static gint static gint
gimp_cage_tool_is_on_handle (GimpCageTool *ct, gimp_cage_tool_is_on_handle (GimpCageTool *ct,
GimpDrawTool *draw_tool, GimpDrawTool *draw_tool,
GimpDisplay *display, GimpDisplay *display,
gdouble x, gdouble x,
gdouble y, gdouble y,
gint handle_size) gint handle_size)
{ {
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct); GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
GimpCageConfig *config = ct->config; GimpCageConfig *config = ct->config;
gdouble dist = G_MAXDOUBLE; gdouble dist = G_MAXDOUBLE;
gint i; gint i;
GimpVector2 cage_point; GimpVector2 cage_point;