cagetool: implement rubber band selection for edit mode, if the cage is closed

This commit is contained in:
Michael Muré 2011-01-22 15:38:35 +01:00
parent aa98319f1b
commit 7056d38681
1 changed files with 32 additions and 1 deletions

View File

@ -131,6 +131,7 @@ enum
CAGE_STATE_INIT, CAGE_STATE_INIT,
CAGE_STATE_WAIT, CAGE_STATE_WAIT,
CAGE_STATE_MOVE_HANDLE, CAGE_STATE_MOVE_HANDLE,
CAGE_STATE_SELECTING,
CAGE_STATE_CLOSING, CAGE_STATE_CLOSING,
DEFORM_STATE_WAIT, DEFORM_STATE_WAIT,
DEFORM_STATE_MOVE_HANDLE, DEFORM_STATE_MOVE_HANDLE,
@ -535,6 +536,13 @@ gimp_cage_tool_button_press (GimpTool *tool,
} }
else /* Cage already closed */ else /* Cage already closed */
{ {
if (handle == -1)
/* User clicked on the background, we start a rubber band selection */
{
ct->selection_start_x = coords->x;
ct->selection_start_y = coords->y;
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 */
{ {
@ -613,6 +621,10 @@ gimp_cage_tool_button_release (GimpTool *tool,
ct->tool_state = CAGE_STATE_WAIT; ct->tool_state = CAGE_STATE_WAIT;
break; break;
case CAGE_STATE_SELECTING:
ct->tool_state = CAGE_STATE_WAIT;
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;
@ -641,6 +653,25 @@ gimp_cage_tool_button_release (GimpTool *tool,
gimp_cage_config_commit_displacement (ct->config); gimp_cage_config_commit_displacement (ct->config);
break; 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);
}
ct->tool_state = CAGE_STATE_WAIT;
}
break;
case DEFORM_STATE_MOVE_HANDLE: 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_config_commit_displacement (ct->config);
@ -793,7 +824,7 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
} }
} }
if (ct->tool_state == DEFORM_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,