1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <glib-object.h>
23
#include "libgimpmath/gimpmath.h"
25
#include "core-types.h"
28
#include "gimpimage.h"
29
#include "gimpimage-sample-points.h"
30
#include "gimpimage-undo-push.h"
31
#include "gimpsamplepoint.h"
33
#include "gimp-intl.h"
36
/* public functions */
39
gimp_image_add_sample_point_at_pos (GimpImage *image,
44
GimpSamplePoint *sample_point;
46
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
47
g_return_val_if_fail (x >= 0 && x < image->width, NULL);
48
g_return_val_if_fail (y >= 0 && y < image->height, NULL);
50
sample_point = gimp_sample_point_new (image->gimp->next_sample_point_ID++);
53
gimp_image_undo_push_sample_point (image, _("Add Sample_Point"),
56
gimp_image_add_sample_point (image, sample_point, x, y);
57
gimp_sample_point_unref (sample_point);
63
gimp_image_add_sample_point (GimpImage *image,
64
GimpSamplePoint *sample_point,
68
g_return_if_fail (GIMP_IS_IMAGE (image));
69
g_return_if_fail (sample_point != NULL);
70
g_return_if_fail (x >= 0);
71
g_return_if_fail (y >= 0);
72
g_return_if_fail (x < image->width);
73
g_return_if_fail (y < image->height);
75
image->sample_points = g_list_append (image->sample_points, sample_point);
79
gimp_sample_point_ref (sample_point);
81
gimp_image_sample_point_added (image, sample_point);
82
gimp_image_update_sample_point (image, sample_point);
86
gimp_image_remove_sample_point (GimpImage *image,
87
GimpSamplePoint *sample_point,
92
g_return_if_fail (GIMP_IS_IMAGE (image));
93
g_return_if_fail (sample_point != NULL);
95
gimp_image_update_sample_point (image, sample_point);
98
gimp_image_undo_push_sample_point (image, _("Remove Sample Point"),
101
list = g_list_find (image->sample_points, sample_point);
103
list = g_list_next (list);
105
image->sample_points = g_list_remove (image->sample_points, sample_point);
107
gimp_image_sample_point_removed (image, sample_point);
109
sample_point->x = -1;
110
sample_point->y = -1;
111
gimp_sample_point_unref (sample_point);
115
gimp_image_update_sample_point (image, list->data);
116
list = g_list_next (list);
121
gimp_image_move_sample_point (GimpImage *image,
122
GimpSamplePoint *sample_point,
127
g_return_if_fail (GIMP_IS_IMAGE (image));
128
g_return_if_fail (sample_point != NULL);
129
g_return_if_fail (x >= 0);
130
g_return_if_fail (y >= 0);
131
g_return_if_fail (x < image->width);
132
g_return_if_fail (y < image->height);
135
gimp_image_undo_push_sample_point (image, _("Move Sample Point"),
138
gimp_image_update_sample_point (image, sample_point);
141
gimp_image_update_sample_point (image, sample_point);
145
gimp_image_find_sample_point (GimpImage *image,
152
GimpSamplePoint *ret = NULL;
153
gdouble mindist = G_MAXDOUBLE;
155
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
156
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
158
if (x < 0 || x >= image->width ||
159
y < 0 || y >= image->height)
164
for (list = image->sample_points; list; list = g_list_next (list))
166
GimpSamplePoint *sample_point = list->data;
169
if (sample_point->x < 0 || sample_point->y < 0)
172
dist = hypot ((sample_point->x + 0.5) - x,
173
(sample_point->y + 0.5) - y);
174
if (dist < MIN (epsilon_y, mindist))