Fix point selection detection

This commit is contained in:
Alexia Death 2010-09-05 13:33:26 +03:00
parent d261248792
commit e133035440
4 changed files with 86 additions and 77 deletions

View File

@ -202,43 +202,7 @@ gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc)
gimp_cage_config_compute_edge_normal (gcc);
}
gint
gimp_cage_config_is_on_handle (GimpCageConfig *gcc,
GimpCageMode mode,
gdouble x,
gdouble y,
gint handle_size)
{
gint i;
gdouble vert_x, vert_y;
g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), -1);
if (gcc->cage_vertice_number == 0)
return -1;
for (i = 0; i < gcc->cage_vertice_number; i++)
{
if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{
vert_x = gcc->cage_vertices[i].x;
vert_y = gcc->cage_vertices[i].y;
}
else
{
vert_x = gcc->cage_vertices_d[i].x;
vert_y = gcc->cage_vertices_d[i].y;
}
if (x < vert_x + handle_size / 2 && x > vert_x -handle_size / 2 &&
y < vert_y + handle_size / 2 && y > vert_y -handle_size / 2)
{
return i;
}
}
return -1;
}
void
gimp_cage_config_move_cage_point (GimpCageConfig *gcc,

View File

@ -76,23 +76,7 @@ void gimp_cage_config_add_cage_point (GimpCageConfig *gcc,
*/
void gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc);
/**
* gimp_cage_config_is_on_handle:
* @gcc: the cage config
* @mode: the actual mode of the cage, GIMP_CAGE_MODE_CAGE_CHANGE or GIMP_CAGE_MODE_DEFORM
* @x: x value to check
* @y: y value to check
* @handle_size: size of the handle, in pixels
*
* Check if a given point is on a handle of the cage, and return his number if yes.
*
* Returns: the number of the handle if the point is on a handle, or -1 if not.
*/
gint gimp_cage_config_is_on_handle (GimpCageConfig *gcc,
GimpCageMode mode,
gdouble x,
gdouble y,
gint handle_size);
/**
* gimp_cage_config_move_cage_point:

View File

@ -212,14 +212,14 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
GimpVector2 p1_s, p2_s, p3_s, p4_s;
GimpVector2 plain_color;
/* pre-fill the out buffer with no-displacement coordinate */
GeglBufferIterator *it = gegl_buffer_iterator_new (out_buf, roi, NULL, GEGL_BUFFER_WRITE);
plain_color.x = (gint) config->cage_vertices[0].x;
plain_color.y = (gint) config->cage_vertices[0].y;
printf ("Color fill picked from (%f, %f)\n", plain_color.x, plain_color.y);
/* pre-fill the out buffer with no-displacement coordinate */
GeglBufferIterator *it = gegl_buffer_iterator_new (out_buf, roi, NULL, GEGL_BUFFER_WRITE);
while (gegl_buffer_iterator_next (it))
{
/* iterate inside the roi */

View File

@ -100,6 +100,14 @@ static void gimp_cage_tool_oper_update (GimpTool *to
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static gint gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
GimpDrawTool *draw_tool,
GimpDisplay *display,
GimpCageMode mode,
gdouble x,
gdouble y,
gint handle_size);
static void gimp_cage_tool_draw (GimpDrawTool *draw_tool);
static void gimp_cage_tool_switch_to_deform (GimpCageTool *ct);
static void gimp_cage_tool_remove_last_handle (GimpCageTool *ct);
@ -115,16 +123,16 @@ G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL)
#define parent_class gimp_cage_tool_parent_class
#define HANDLE_SIZE 14
#define HANDLE_SIZE 25
void
gimp_cage_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_CAGE_TOOL, //Tool type
GIMP_TYPE_CAGE_OPTIONS, //Tool options type
gimp_cage_options_gui, //Tool opions gui
0, //context_props
(* callback) (GIMP_TYPE_CAGE_TOOL, /* Tool type */
GIMP_TYPE_CAGE_OPTIONS, /*Tool options type*/
gimp_cage_options_gui, /*Tool opions gui*/
0, /*context_props*/
"gimp-cage-tool",
_("Cage Transform"),
_("Cage Transform: Deform a selection with a cage"),
@ -328,7 +336,9 @@ gimp_cage_tool_oper_update (GimpTool *tool,
gint active_handle = -1;
if (config)
active_handle = gimp_cage_config_is_on_handle (config,
active_handle = gimp_cage_tool_is_on_handle (config,
draw_tool,
display,
options->cage_mode,
coords->x,
coords->y,
@ -371,7 +381,9 @@ gimp_cage_tool_button_press (GimpTool *tool,
if (ct->handle_moved < 0)
{
ct->handle_moved = gimp_cage_config_is_on_handle (config,
ct->handle_moved = gimp_cage_tool_is_on_handle (config,
GIMP_DRAW_TOOL(ct),
display,
options->cage_mode,
coords->x,
coords->y,
@ -422,7 +434,6 @@ gimp_cage_tool_button_release (GimpTool *tool,
{
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
GimpImage *image = gimp_display_get_image (tool->display);
GimpItem *item = GIMP_ITEM (tool->drawable);
gint x, y;
@ -553,7 +564,9 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
FALSE);
}
on_handle = gimp_cage_config_is_on_handle (config,
on_handle = gimp_cage_tool_is_on_handle (config,
draw_tool,
draw_tool->display,
options->cage_mode,
ct->cursor_position.x,
ct->cursor_position.y,
@ -578,6 +591,54 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
}
}
static gint
gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
GimpDrawTool *draw_tool,
GimpDisplay *display,
GimpCageMode mode,
gdouble x,
gdouble y,
gint handle_size)
{
gint i;
gdouble vert_x;
gdouble vert_y;
gdouble dist = G_MAXDOUBLE;
g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), -1);
if (gcc->cage_vertice_number == 0)
return -1;
for (i = 0; i < gcc->cage_vertice_number; i++)
{
if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{
vert_x = gcc->cage_vertices[i].x;
vert_y = gcc->cage_vertices[i].y;
}
else
{
vert_x = gcc->cage_vertices_d[i].x;
vert_y = gcc->cage_vertices_d[i].y;
}
dist = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (draw_tool),
display,
x,
y,
vert_x,
vert_y);
if (dist <= (handle_size * handle_size))
{
return i;
}
}
return -1;
}
static void
gimp_cage_tool_remove_last_handle (GimpCageTool *ct)
{