Commit 7cbe447c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/core/gimpimage-sample-points.c app/display/gimpdisplayshell-draw.c

2005-03-19  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimage-sample-points.c
	* app/display/gimpdisplayshell-draw.c
	* app/display/gimpdisplayshell.c
	* app/tools/gimpcolortool.c: make sure sample points always have
	coordinates in the range [0..width/height-1], also added lots of
	+0.5 because they live at the pixels' centers, not at their
	borders. Fixed drawing of sample points at the display borders.
parent 339ef0f0
2005-03-19 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-sample-points.c
* app/display/gimpdisplayshell-draw.c
* app/display/gimpdisplayshell.c
* app/tools/gimpcolortool.c: make sure sample points always have
coordinates in the range [0..width/height-1], also added lots of
+0.5 because they live at the pixels' centers, not at their
borders. Fixed drawing of sample points at the display borders.
2005-03-19 Manish Singh <yosh@gimp.org>
* app/config/Makefile.am: actually link test program with
......
......@@ -41,8 +41,8 @@ gimp_image_add_sample_point_at_pos (GimpImage *gimage,
GimpSamplePoint *sample_point;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (x >= 0 && x <= gimage->width, NULL);
g_return_val_if_fail (y >= 0 && y <= gimage->height, NULL);
g_return_val_if_fail (x >= 0 && x < gimage->width, NULL);
g_return_val_if_fail (y >= 0 && y < gimage->height, NULL);
sample_point = g_new0 (GimpSamplePoint, 1);
......@@ -92,8 +92,8 @@ gimp_image_add_sample_point (GimpImage *gimage,
g_return_if_fail (sample_point != NULL);
g_return_if_fail (x >= 0);
g_return_if_fail (y >= 0);
g_return_if_fail (x <= gimage->width);
g_return_if_fail (y <= gimage->height);
g_return_if_fail (x < gimage->width);
g_return_if_fail (y < gimage->height);
gimage->sample_points = g_list_append (gimage->sample_points, sample_point);
......@@ -148,8 +148,8 @@ gimp_image_move_sample_point (GimpImage *gimage,
g_return_if_fail (sample_point != NULL);
g_return_if_fail (x >= 0);
g_return_if_fail (y >= 0);
g_return_if_fail (x <= gimage->width);
g_return_if_fail (y <= gimage->height);
g_return_if_fail (x < gimage->width);
g_return_if_fail (y < gimage->height);
if (push_undo)
gimp_image_undo_push_image_sample_point (gimage, _("Move Sample Point"),
......@@ -169,10 +169,8 @@ gimp_image_find_sample_point (GimpImage *gimage,
gdouble epsilon_y)
{
GList *list;
GimpSamplePoint *sample_point;
GimpSamplePoint *ret = NULL;
gdouble dist;
gdouble mindist = G_MAXDOUBLE;
GimpSamplePoint *ret = NULL;
gdouble mindist = G_MAXDOUBLE;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
......@@ -185,12 +183,14 @@ gimp_image_find_sample_point (GimpImage *gimage,
for (list = gimage->sample_points; list; list = g_list_next (list))
{
sample_point = (GimpSamplePoint *) list->data;
GimpSamplePoint *sample_point = list->data;
gdouble dist;
if (sample_point->x < 0 || sample_point->y < 0)
continue;
dist = hypot ( sample_point->x - x, sample_point->y - y);
dist = hypot ((sample_point->x + 0.5) - x,
(sample_point->y + 0.5) - y);
if (dist < MIN (epsilon_y, mindist))
{
mindist = dist;
......
......@@ -298,9 +298,9 @@ gimp_display_shell_draw_sample_point (GimpDisplayShell *shell,
gboolean active)
{
GimpCanvasStyle style;
gdouble x, y;
gint x1, x2;
gint y1, y2;
gint x, y;
gint w, h;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
......@@ -309,26 +309,24 @@ gimp_display_shell_draw_sample_point (GimpDisplayShell *shell,
if (sample_point->x < 0)
return;
gimp_display_shell_transform_xy (shell,
sample_point->x,
sample_point->y,
&x, &y, FALSE);
gimp_display_shell_transform_xy_f (shell,
sample_point->x + 0.5,
sample_point->y + 0.5,
&x, &y, FALSE);
x1 = x - GIMP_SAMPLE_POINT_DRAW_SIZE;
x2 = x + GIMP_SAMPLE_POINT_DRAW_SIZE;
y1 = y - GIMP_SAMPLE_POINT_DRAW_SIZE;
y2 = y + GIMP_SAMPLE_POINT_DRAW_SIZE;
x1 = floor (x - GIMP_SAMPLE_POINT_DRAW_SIZE);
x2 = ceil (x + GIMP_SAMPLE_POINT_DRAW_SIZE);
y1 = floor (y - GIMP_SAMPLE_POINT_DRAW_SIZE);
y2 = ceil (y + GIMP_SAMPLE_POINT_DRAW_SIZE);
gdk_drawable_get_size (shell->canvas->window, &w, &h);
if (x < 0 || y < 0 || x >= w || y >= h)
if (x < - GIMP_SAMPLE_POINT_DRAW_SIZE ||
y < - GIMP_SAMPLE_POINT_DRAW_SIZE ||
x > w + GIMP_SAMPLE_POINT_DRAW_SIZE ||
y > h + GIMP_SAMPLE_POINT_DRAW_SIZE)
return;
if (x1 < 0) x1 = 0;
if (y1 < 0) y1 = 0;
if (x2 > w) x2 = w;
if (y2 > h) y2 = h;
if (active)
style = GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE;
else
......@@ -373,9 +371,7 @@ gimp_display_shell_draw_sample_points (GimpDisplayShell *shell)
list;
list = g_list_next (list))
{
gimp_display_shell_draw_sample_point(shell,
(GimpSamplePoint *) list->data,
FALSE);
gimp_display_shell_draw_sample_point (shell, list->data, FALSE);
}
}
}
......
......@@ -1276,8 +1276,8 @@ void
gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
GimpSamplePoint *sample_point)
{
gint x, y;
gint xmin, xmax, ymin, ymax;
gdouble x, y;
gint x1, y1, x2, y2;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (sample_point != NULL);
......@@ -1285,18 +1285,19 @@ gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
if (sample_point->x < 0)
return;
gimp_display_shell_transform_xy (shell,
sample_point->x,
sample_point->y,
&x, &y,
FALSE);
gimp_display_shell_transform_xy_f (shell,
sample_point->x + 0.5,
sample_point->y + 0.5,
&x, &y,
FALSE);
xmin = MAX (0, x - GIMP_SAMPLE_POINT_DRAW_SIZE);
xmax = MIN (shell->disp_width, x + GIMP_SAMPLE_POINT_DRAW_SIZE);
ymin = MAX (0, y - GIMP_SAMPLE_POINT_DRAW_SIZE);
ymax = MIN (shell->disp_height, y + GIMP_SAMPLE_POINT_DRAW_SIZE);
x1 = MAX (0, floor (x - GIMP_SAMPLE_POINT_DRAW_SIZE));
y1 = MAX (0, floor (y - GIMP_SAMPLE_POINT_DRAW_SIZE));
x2 = MIN (shell->disp_width, ceil (x + GIMP_SAMPLE_POINT_DRAW_SIZE));
y2 = MIN (shell->disp_height, ceil (y + GIMP_SAMPLE_POINT_DRAW_SIZE));
gimp_display_shell_expose_area (shell, xmin, ymin, xmax, ymax);
/* HACK: add 3 instead of 1 so the number gets cleared too */
gimp_display_shell_expose_area (shell, x1, y1, x2 - x1 + 3, y2 - y1 + 3);
}
void
......
......@@ -326,10 +326,10 @@ gimp_color_tool_button_release (GimpTool *tool,
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
if ((color_tool->sample_point_x < x ||
color_tool->sample_point_x > (x + width) ||
color_tool->sample_point_y < y ||
color_tool->sample_point_y > (y + height)))
if ((color_tool->sample_point_x < x ||
color_tool->sample_point_x > (x + width - 1) ||
color_tool->sample_point_y < y ||
color_tool->sample_point_y > (y + height - 1)))
{
if (color_tool->sample_point)
{
......@@ -400,8 +400,8 @@ gimp_color_tool_motion (GimpTool *tool,
&tx, &ty,
FALSE);
if (tx < 0 || tx >= shell->disp_width ||
ty < 0 || ty >= shell->disp_height)
if (tx < 0 || tx > shell->disp_width ||
ty < 0 || ty > shell->disp_height)
{
color_tool->sample_point_x = -1;
color_tool->sample_point_y = -1;
......@@ -412,16 +412,16 @@ gimp_color_tool_motion (GimpTool *tool,
{
gint x, y, width, height;
color_tool->sample_point_x = RINT (coords->x);
color_tool->sample_point_y = RINT (coords->y);
color_tool->sample_point_x = floor (coords->x);
color_tool->sample_point_y = floor (coords->y);
gimp_display_shell_untransform_viewport (shell, &x, &y,
&width, &height);
if ((color_tool->sample_point_x < x ||
color_tool->sample_point_x > (x + width) ||
color_tool->sample_point_y < y ||
color_tool->sample_point_y > (y + height)))
if ((color_tool->sample_point_x < x ||
color_tool->sample_point_x > (x + width - 1) ||
color_tool->sample_point_y < y ||
color_tool->sample_point_y > (y + height - 1)))
{
delete_point = TRUE;
}
......@@ -571,13 +571,13 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
color_tool->sample_point_y != -1)
{
gimp_draw_tool_draw_line (draw_tool,
0, color_tool->sample_point_y,
0, color_tool->sample_point_y + 0.5,
draw_tool->gdisp->gimage->width,
color_tool->sample_point_y,
color_tool->sample_point_y + 0.5,
FALSE);
gimp_draw_tool_draw_line (draw_tool,
color_tool->sample_point_x, 0,
color_tool->sample_point_x,
color_tool->sample_point_x + 0.5, 0,
color_tool->sample_point_x + 0.5,
draw_tool->gdisp->gimage->height,
FALSE);
}
......
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