~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/core/gimpimage-sample-points.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <glib-object.h>
 
22
 
 
23
#include "libgimpmath/gimpmath.h"
 
24
 
 
25
#include "core-types.h"
 
26
 
 
27
#include "gimp.h"
 
28
#include "gimpimage.h"
 
29
#include "gimpimage-sample-points.h"
 
30
#include "gimpimage-undo-push.h"
 
31
#include "gimpsamplepoint.h"
 
32
 
 
33
#include "gimp-intl.h"
 
34
 
 
35
 
 
36
/*  public functions  */
 
37
 
 
38
GimpSamplePoint *
 
39
gimp_image_add_sample_point_at_pos (GimpImage *image,
 
40
                                    gint       x,
 
41
                                    gint       y,
 
42
                                    gboolean   push_undo)
 
43
{
 
44
  GimpSamplePoint *sample_point;
 
45
 
 
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);
 
49
 
 
50
  sample_point = gimp_sample_point_new (image->gimp->next_sample_point_ID++);
 
51
 
 
52
  if (push_undo)
 
53
    gimp_image_undo_push_sample_point (image, _("Add Sample_Point"),
 
54
                                       sample_point);
 
55
 
 
56
  gimp_image_add_sample_point (image, sample_point, x, y);
 
57
  gimp_sample_point_unref (sample_point);
 
58
 
 
59
  return sample_point;
 
60
}
 
61
 
 
62
void
 
63
gimp_image_add_sample_point (GimpImage       *image,
 
64
                             GimpSamplePoint *sample_point,
 
65
                             gint             x,
 
66
                             gint             y)
 
67
{
 
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);
 
74
 
 
75
  image->sample_points = g_list_append (image->sample_points, sample_point);
 
76
 
 
77
  sample_point->x = x;
 
78
  sample_point->y = y;
 
79
  gimp_sample_point_ref (sample_point);
 
80
 
 
81
  gimp_image_sample_point_added (image, sample_point);
 
82
  gimp_image_update_sample_point (image, sample_point);
 
83
}
 
84
 
 
85
void
 
86
gimp_image_remove_sample_point (GimpImage       *image,
 
87
                                GimpSamplePoint *sample_point,
 
88
                                gboolean         push_undo)
 
89
{
 
90
  GList *list;
 
91
 
 
92
  g_return_if_fail (GIMP_IS_IMAGE (image));
 
93
  g_return_if_fail (sample_point != NULL);
 
94
 
 
95
  gimp_image_update_sample_point (image, sample_point);
 
96
 
 
97
  if (push_undo)
 
98
    gimp_image_undo_push_sample_point (image, _("Remove Sample Point"),
 
99
                                       sample_point);
 
100
 
 
101
  list = g_list_find (image->sample_points, sample_point);
 
102
  if (list)
 
103
    list = g_list_next (list);
 
104
 
 
105
  image->sample_points = g_list_remove (image->sample_points, sample_point);
 
106
 
 
107
  gimp_image_sample_point_removed (image, sample_point);
 
108
 
 
109
  sample_point->x = -1;
 
110
  sample_point->y = -1;
 
111
  gimp_sample_point_unref (sample_point);
 
112
 
 
113
  while (list)
 
114
    {
 
115
      gimp_image_update_sample_point (image, list->data);
 
116
      list = g_list_next (list);
 
117
    }
 
118
}
 
119
 
 
120
void
 
121
gimp_image_move_sample_point (GimpImage       *image,
 
122
                              GimpSamplePoint *sample_point,
 
123
                              gint             x,
 
124
                              gint             y,
 
125
                              gboolean         push_undo)
 
126
{
 
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);
 
133
 
 
134
  if (push_undo)
 
135
    gimp_image_undo_push_sample_point (image, _("Move Sample Point"),
 
136
                                       sample_point);
 
137
 
 
138
  gimp_image_update_sample_point (image, sample_point);
 
139
  sample_point->x = x;
 
140
  sample_point->y = y;
 
141
  gimp_image_update_sample_point (image, sample_point);
 
142
}
 
143
 
 
144
GimpSamplePoint *
 
145
gimp_image_find_sample_point (GimpImage *image,
 
146
                              gdouble    x,
 
147
                              gdouble    y,
 
148
                              gdouble    epsilon_x,
 
149
                              gdouble    epsilon_y)
 
150
{
 
151
  GList           *list;
 
152
  GimpSamplePoint *ret     = NULL;
 
153
  gdouble          mindist = G_MAXDOUBLE;
 
154
 
 
155
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
156
  g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
 
157
 
 
158
  if (x < 0 || x >= image->width ||
 
159
      y < 0 || y >= image->height)
 
160
    {
 
161
      return NULL;
 
162
    }
 
163
 
 
164
  for (list = image->sample_points; list; list = g_list_next (list))
 
165
    {
 
166
      GimpSamplePoint *sample_point = list->data;
 
167
      gdouble          dist;
 
168
 
 
169
      if (sample_point->x < 0 || sample_point->y < 0)
 
170
        continue;
 
171
 
 
172
      dist = hypot ((sample_point->x + 0.5) - x,
 
173
                    (sample_point->y + 0.5) - y);
 
174
      if (dist < MIN (epsilon_y, mindist))
 
175
        {
 
176
          mindist = dist;
 
177
          ret = sample_point;
 
178
        }
 
179
    }
 
180
 
 
181
  return ret;
 
182
}