gimpcagetool: draw/edit cage, accordingly to cage mode

This commit is contained in:
Michael Muré
2010-07-17 16:32:46 +02:00
parent d836615ae7
commit db5981a69c

View File

@ -205,6 +205,7 @@ gimp_cage_tool_button_press (GimpTool *tool,
GimpDisplay *display) GimpDisplay *display)
{ {
GimpCageTool *ct = GIMP_CAGE_TOOL (tool); GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
GimpCage *cage = ct->cage; GimpCage *cage = ct->cage;
g_return_if_fail (GIMP_IS_CAGE_TOOL (ct)); g_return_if_fail (GIMP_IS_CAGE_TOOL (ct));
@ -218,13 +219,24 @@ gimp_cage_tool_button_press (GimpTool *tool,
gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct)); gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
if (ct->handle_moved < 0) if (ct->handle_moved < 0)
{
if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{ {
ct->handle_moved = gimp_cage_is_on_handle (cage, ct->handle_moved = gimp_cage_is_on_handle (cage,
coords->x, coords->x,
coords->y, coords->y,
HANDLE_SIZE); HANDLE_SIZE);
} }
else
{
ct->handle_moved = gimp_cage_is_on_handle_d (cage,
coords->x,
coords->y,
HANDLE_SIZE);
}
}
if (ct->handle_moved < 0) if (ct->handle_moved < 0)
{ {
@ -299,6 +311,7 @@ gimp_cage_tool_motion (GimpTool *tool,
{ {
GimpCageTool *ct = GIMP_CAGE_TOOL (tool); GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
GimpCage *cage = ct->cage; GimpCage *cage = ct->cage;
@ -306,12 +319,22 @@ gimp_cage_tool_motion (GimpTool *tool,
if (ct->handle_moved >= 0) if (ct->handle_moved >= 0)
{
if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{ {
gimp_cage_move_cage_point (cage, gimp_cage_move_cage_point (cage,
ct->handle_moved, ct->handle_moved,
coords->x, coords->x,
coords->y); coords->y);
} }
else
{
gimp_cage_move_cage_point_d (cage,
ct->handle_moved,
coords->x,
coords->y);
}
}
gimp_draw_tool_resume (draw_tool); gimp_draw_tool_resume (draw_tool);
} }
@ -399,36 +422,55 @@ static void
gimp_cage_tool_draw (GimpDrawTool *draw_tool) gimp_cage_tool_draw (GimpDrawTool *draw_tool)
{ {
GimpCageTool *ct = GIMP_CAGE_TOOL (draw_tool); GimpCageTool *ct = GIMP_CAGE_TOOL (draw_tool);
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
GimpCage *cage = ct->cage; GimpCage *cage = ct->cage;
gint i = 0; gint i = 0;
gint n = 0; gint n = 0;
gint on_handle = -1; gint on_handle = -1;
GimpVector2 *vertices;
gint (*is_on_handle) (GimpCage *cage,
gdouble x,
gdouble y,
gint handle_size);
if (cage->cage_vertice_number <= 0) if (cage->cage_vertice_number <= 0)
{ {
return; return;
} }
if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{
is_on_handle = gimp_cage_is_on_handle;
vertices = cage->cage_vertices;
}
else
{
is_on_handle = gimp_cage_is_on_handle_d;
vertices = cage->cage_vertices_d;
}
gimp_draw_tool_draw_lines (draw_tool, gimp_draw_tool_draw_lines (draw_tool,
cage->cage_vertices, vertices,
cage->cage_vertice_number, cage->cage_vertice_number,
FALSE, FALSE); FALSE, FALSE);
if (ct->cage_complete) if (ct->cage_complete)
{ {
gimp_draw_tool_draw_line (draw_tool, gimp_draw_tool_draw_line (draw_tool,
cage->cage_vertices[cage->cage_vertice_number - 1].x, vertices[cage->cage_vertice_number - 1].x,
cage->cage_vertices[cage->cage_vertice_number - 1].y, vertices[cage->cage_vertice_number - 1].y,
cage->cage_vertices[0].x, vertices[0].x,
cage->cage_vertices[0].y, vertices[0].y,
FALSE); FALSE);
} }
else else
{ {
gimp_draw_tool_draw_line (draw_tool, gimp_draw_tool_draw_line (draw_tool,
cage->cage_vertices[cage->cage_vertice_number - 1].x, vertices[cage->cage_vertice_number - 1].x,
cage->cage_vertices[cage->cage_vertice_number - 1].y, vertices[cage->cage_vertice_number - 1].y,
ct->cursor_position.x, ct->cursor_position.x,
ct->cursor_position.y, ct->cursor_position.y,
FALSE); FALSE);
@ -436,14 +478,14 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
n = cage->cage_vertice_number; n = cage->cage_vertice_number;
on_handle = gimp_cage_is_on_handle (cage, on_handle = is_on_handle (cage,
ct->cursor_position.x, ct->cursor_position.x,
ct->cursor_position.y, ct->cursor_position.y,
HANDLE_SIZE); HANDLE_SIZE);
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
{ {
GimpVector2 point = cage->cage_vertices[i]; GimpVector2 point = vertices[i];
GimpHandleType handle = GIMP_HANDLE_CIRCLE; GimpHandleType handle = GIMP_HANDLE_CIRCLE;