Commit 2c470550 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Fixed rounding and double vs. integer inconsistency when dealing with

2006-08-14  Michael Natterer  <mitch@gimp.org>

	Fixed rounding and double vs. integer inconsistency when dealing
	with mouse coordinates. Fixes bug #350694.

	* app/tools/gimpiscissorstool.c
	(clicked_on_vertex)
	(clicked_on_curve): added double x and y parameters and use them
	instead of the integer iscissors->x and ->y. Cleaned up the
	functions a bit.

	(gimp_iscissors_tool_button_press)
	(gimp_iscissors_tool_motion): changed accordingly, also rint() the
	passed mouse coords when assigning them to iscissors->x and ->y.

	Unrelated cleanup:

	(iscissors_free_buffers): removed, folded into reset()
	(precalculate_arrays): removed, folded into class_init()
parent 179f0cc4
2006-08-14 Michael Natterer <mitch@gimp.org>
Fixed rounding and double vs. integer inconsistency when dealing
with mouse coordinates. Fixes bug #350694.
* app/tools/gimpiscissorstool.c
(clicked_on_vertex)
(clicked_on_curve): added double x and y parameters and use them
instead of the integer iscissors->x and ->y. Cleaned up the
functions a bit.
(gimp_iscissors_tool_button_press)
(gimp_iscissors_tool_motion): changed accordingly, also rint() the
passed mouse coords when assigning them to iscissors->x and ->y.
Unrelated cleanup:
(iscissors_free_buffers): removed, folded into reset()
(precalculate_arrays): removed, folded into class_init()
2006-08-14 Sven Neumann <sven@gimp.org>
* tools/gimp-remote.c
......
......@@ -175,18 +175,20 @@ static void calculate_curve (GimpTool *tool,
static void iscissors_draw_curve (GimpDrawTool *draw_tool,
ICurve *curve);
static void iscissors_free_icurves (GSList *list);
static void iscissors_free_buffers (GimpIscissorsTool *iscissors);
static gint mouse_over_vertex (GimpIscissorsTool *iscissors,
gdouble x,
gdouble y);
static gboolean clicked_on_vertex (GimpTool *tool);
static gboolean clicked_on_vertex (GimpIscissorsTool *iscissors,
gdouble x,
gdouble y);
static GSList * mouse_over_curve (GimpIscissorsTool *iscissors,
gdouble x,
gdouble y);
static gboolean clicked_on_curve (GimpTool *tool);
static gboolean clicked_on_curve (GimpIscissorsTool *iscissors,
gdouble x,
gdouble y);
static void precalculate_arrays (void);
static GPtrArray * plot_pixels (GimpIscissorsTool *iscissors,
TempBuf *dp_buf,
gint x1,
......@@ -256,12 +258,11 @@ static const gfloat blur_32[9] =
1, 1, 1,
};
static gfloat distance_weights[GRADIENT_SEARCH * GRADIENT_SEARCH];
static gfloat distance_weights[GRADIENT_SEARCH * GRADIENT_SEARCH];
static gint diagonal_weight[256];
static gint direction_value[256][4];
static gboolean initialized = FALSE;
static Tile *cur_tile = NULL;
static gint diagonal_weight[256];
static gint direction_value[256][4];
static Tile *cur_tile = NULL;
void
......@@ -288,6 +289,7 @@ gimp_iscissors_tool_class_init (GimpIscissorsToolClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
gint i;
object_class->finalize = gimp_iscissors_tool_finalize;
......@@ -299,6 +301,24 @@ gimp_iscissors_tool_class_init (GimpIscissorsToolClass *klass)
tool_class->cursor_update = gimp_iscissors_tool_cursor_update;
draw_tool_class->draw = gimp_iscissors_tool_draw;
for (i = 0; i < 256; i++)
{
/* The diagonal weight array */
diagonal_weight[i] = (int) (i * G_SQRT2);
/* The direction value array */
direction_value[i][0] = (127 - abs (127 - i)) * 2;
direction_value[i][1] = abs (127 - i) * 2;
direction_value[i][2] = abs (191 - i) * 2;
direction_value[i][3] = abs (63 - i) * 2;
}
/* set the 256th index of the direction_values to the hightest cost */
direction_value[255][0] = 255;
direction_value[255][1] = 255;
direction_value[255][2] = 255;
direction_value[255][3] = 255;
}
static void
......@@ -385,8 +405,8 @@ gimp_iscissors_tool_button_press (GimpTool *tool,
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
iscissors->x = coords->x;
iscissors->y = coords->y;
iscissors->x = rint (coords->x);
iscissors->y = rint (coords->y);
/* If the tool was being used in another image...reset it */
......@@ -430,7 +450,7 @@ gimp_iscissors_tool_button_press (GimpTool *tool,
default:
/* Check if the mouse click occurred on a vertex or the curve itself */
if (clicked_on_vertex (tool))
if (clicked_on_vertex (iscissors, coords->x, coords->y))
{
iscissors->nx = iscissors->x;
iscissors->ny = iscissors->y;
......@@ -685,8 +705,8 @@ gimp_iscissors_tool_motion (GimpTool *tool,
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
iscissors->x = coords->x;
iscissors->y = coords->y;
iscissors->x = rint (coords->x);
iscissors->y = rint (coords->y);
switch (iscissors->state)
{
......@@ -929,7 +949,8 @@ gimp_iscissors_tool_oper_update (GimpTool *tool,
else if (iscissors->connected && iscissors->mask)
{
if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (iscissors->mask),
coords->x, coords->y))
rint (coords->x),
rint (coords->y)))
{
iscissors->op = ISCISSORS_OP_SELECT;
}
......@@ -1034,15 +1055,10 @@ gimp_iscissors_tool_reset (GimpIscissorsTool *iscissors)
iscissors->state = NO_ACTION;
/* Reset the dp buffers */
iscissors_free_buffers (iscissors);
/* If they haven't already been initialized, precalculate the diagonal
* weight and direction value arrays
*/
if (!initialized)
if (iscissors->dp_buf)
{
precalculate_arrays ();
initialized = TRUE;
temp_buf_free (iscissors->dp_buf);
iscissors->dp_buf = NULL;
}
}
......@@ -1064,16 +1080,6 @@ iscissors_free_icurves (GSList *list)
}
static void
iscissors_free_buffers (GimpIscissorsTool *iscissors)
{
if (iscissors->dp_buf)
temp_buf_free (iscissors->dp_buf);
iscissors->dp_buf = NULL;
}
/* XXX need some scan-conversion routines from somewhere. maybe. ? */
static gint
......@@ -1082,7 +1088,6 @@ mouse_over_vertex (GimpIscissorsTool *iscissors,
gdouble y)
{
GSList *list;
ICurve *curve;
gint curves_found = 0;
/* traverse through the list, returning non-zero if the current cursor
......@@ -1096,7 +1101,7 @@ mouse_over_vertex (GimpIscissorsTool *iscissors,
while (list && curves_found < 2)
{
curve = (ICurve *) list->data;
ICurve *curve = list->data;
if (gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (iscissors),
GIMP_TOOL (iscissors)->display,
......@@ -1134,18 +1139,19 @@ mouse_over_vertex (GimpIscissorsTool *iscissors,
}
static gboolean
clicked_on_vertex (GimpTool *tool)
clicked_on_vertex (GimpIscissorsTool *iscissors,
gdouble x,
gdouble y)
{
GimpIscissorsTool *iscissors = GIMP_ISCISSORS_TOOL (tool);
gint curves_found = 0;
gint curves_found = 0;
curves_found = mouse_over_vertex (iscissors, iscissors->x, iscissors->y);
curves_found = mouse_over_vertex (iscissors, x, y);
if (curves_found > 1)
{
/* undraw the curve */
iscissors->draw = DRAW_CURVE;
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
gimp_draw_tool_pause (GIMP_DRAW_TOOL (iscissors));
return TRUE;
}
......@@ -1157,7 +1163,7 @@ clicked_on_vertex (GimpTool *tool)
if (curves_found == 1)
return FALSE;
return clicked_on_curve (tool);
return clicked_on_curve (iscissors, x, y);
}
......@@ -1166,26 +1172,25 @@ mouse_over_curve (GimpIscissorsTool *iscissors,
gdouble x,
gdouble y)
{
GSList *list;
gpointer *pt;
gint len;
ICurve *curve;
guint32 coords;
gint tx, ty;
GSList *list;
/* traverse through the list, returning the curve segment's list element
* if the current cursor position is on a curve...
*/
for (list = iscissors->curves; list; list = g_slist_next (list))
{
curve = (ICurve *) list->data;
ICurve *curve = list->data;
gpointer *pt;
gint len;
pt = curve->points->pdata;
len = curve->points->len;
while (len--)
{
coords = GPOINTER_TO_INT (*pt);
guint32 coords = GPOINTER_TO_INT (*pt);
gint tx, ty;
pt++;
tx = coords & 0x0000ffff;
ty = coords >> 16;
......@@ -1206,30 +1211,28 @@ mouse_over_curve (GimpIscissorsTool *iscissors,
}
static gboolean
clicked_on_curve (GimpTool *tool)
clicked_on_curve (GimpIscissorsTool *iscissors,
gdouble x,
gdouble y)
{
GimpIscissorsTool *iscissors;
GimpSelectionOptions *options;
GSList *list, *new_link;
ICurve *curve, *new_curve;
iscissors = GIMP_ISCISSORS_TOOL (tool);
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
GSList *list;
/* traverse through the list, getting back the curve segment's list
* element if the current cursor position is on a curve...
* If this occurs, replace the curve with two new curves,
* separated by a new vertex.
*/
list = mouse_over_curve (iscissors, iscissors->x, iscissors->y);
list = mouse_over_curve (iscissors, x, y);
if (list)
{
curve = (ICurve *) list->data;
ICurve *curve = list->data;
ICurve *new_curve;
GSList *new_link;
/* undraw the curve */
iscissors->draw = DRAW_CURVE;
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
gimp_draw_tool_pause (GIMP_DRAW_TOOL (iscissors));
/* Create the new curve */
new_curve = g_new (ICurve, 1);
......@@ -1258,31 +1261,6 @@ clicked_on_curve (GimpTool *tool)
}
static void
precalculate_arrays (void)
{
gint i;
for (i = 0; i < 256; i++)
{
/* The diagonal weight array */
diagonal_weight[i] = (int) (i * G_SQRT2);
/* The direction value array */
direction_value[i][0] = (127 - abs (127 - i)) * 2;
direction_value[i][1] = abs (127 - i) * 2;
direction_value[i][2] = abs (191 - i) * 2;
direction_value[i][3] = abs (63 - i) * 2;
}
/* set the 256th index of the direction_values to the hightest cost */
direction_value[255][0] = 255;
direction_value[255][1] = 255;
direction_value[255][2] = 255;
direction_value[255][3] = 255;
}
static void
calculate_curve (GimpTool *tool,
ICurve *curve)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment