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

« back to all changes in this revision

Viewing changes to app/core/gimpimage-guides.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
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
24
24
 
25
25
#include "gimp.h"
26
26
#include "gimpimage.h"
 
27
#include "gimpguide.h"
27
28
#include "gimpimage-guides.h"
28
29
#include "gimpimage-undo-push.h"
29
30
 
33
34
/*  public functions  */
34
35
 
35
36
GimpGuide *
36
 
gimp_image_add_hguide (GimpImage *gimage,
37
 
                       gint       position,
38
 
                       gboolean   push_undo)
39
 
{
40
 
  GimpGuide *guide;
41
 
 
42
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
43
 
  g_return_val_if_fail (position >= 0 && position <= gimage->height, NULL);
44
 
 
45
 
  guide = g_new0 (GimpGuide, 1);
46
 
 
47
 
  guide->ref_count   = 1;
48
 
  guide->position    = -1;
49
 
  guide->orientation = GIMP_ORIENTATION_HORIZONTAL;
50
 
  guide->guide_ID    = gimage->gimp->next_guide_ID++;
51
 
 
52
 
  if (push_undo)
53
 
    gimp_image_undo_push_image_guide (gimage, _("Add Horizontal Guide"),
54
 
                                      guide);
55
 
 
56
 
  gimp_image_add_guide (gimage, guide, position);
57
 
  gimp_image_guide_unref (guide);
58
 
 
59
 
  return guide;
60
 
}
61
 
 
62
 
GimpGuide *
63
 
gimp_image_add_vguide (GimpImage *gimage,
64
 
                       gint       position,
65
 
                       gboolean   push_undo)
66
 
{
67
 
  GimpGuide *guide;
68
 
 
69
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
70
 
  g_return_val_if_fail (position >= 0 && position <= gimage->width, NULL);
71
 
 
72
 
  guide = g_new0 (GimpGuide, 1);
73
 
 
74
 
  guide->ref_count   = 1;
75
 
  guide->position    = -1;
76
 
  guide->orientation = GIMP_ORIENTATION_VERTICAL;
77
 
  guide->guide_ID    = gimage->gimp->next_guide_ID++;
78
 
 
79
 
  if (push_undo)
80
 
    gimp_image_undo_push_image_guide (gimage, _("Add Vertical Guide"),
81
 
                                      guide);
82
 
 
83
 
  gimp_image_add_guide (gimage, guide, position);
84
 
  gimp_image_guide_unref (guide);
85
 
 
86
 
  return guide;
87
 
}
88
 
 
89
 
GimpGuide *
90
 
gimp_image_guide_ref (GimpGuide *guide)
91
 
{
92
 
  g_return_val_if_fail (guide != NULL, NULL);
93
 
 
94
 
  guide->ref_count++;
95
 
 
96
 
  return guide;
97
 
}
98
 
 
99
 
void
100
 
gimp_image_guide_unref (GimpGuide *guide)
101
 
{
102
 
  g_return_if_fail (guide != NULL);
103
 
 
104
 
  guide->ref_count--;
105
 
 
106
 
  if (guide->ref_count < 1)
107
 
    g_free (guide);
108
 
}
109
 
 
110
 
void
111
 
gimp_image_add_guide (GimpImage *gimage,
112
 
                      GimpGuide *guide,
 
37
gimp_image_add_hguide (GimpImage *image,
 
38
                       gint       position,
 
39
                       gboolean   push_undo)
 
40
{
 
41
  GimpGuide *guide;
 
42
 
 
43
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
44
  g_return_val_if_fail (position >= 0 && position <= image->height, NULL);
 
45
 
 
46
  guide = gimp_guide_new (GIMP_ORIENTATION_HORIZONTAL,
 
47
                          image->gimp->next_guide_ID++);
 
48
 
 
49
  if (push_undo)
 
50
    gimp_image_undo_push_guide (image, _("Add Horizontal Guide"), guide);
 
51
 
 
52
  gimp_image_add_guide (image, guide, position);
 
53
  g_object_unref (G_OBJECT (guide));
 
54
 
 
55
  return guide;
 
56
}
 
57
 
 
58
GimpGuide *
 
59
gimp_image_add_vguide (GimpImage *image,
 
60
                       gint       position,
 
61
                       gboolean   push_undo)
 
62
{
 
63
  GimpGuide *guide;
 
64
 
 
65
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
66
  g_return_val_if_fail (position >= 0 && position <= image->width, NULL);
 
67
 
 
68
  guide = gimp_guide_new (GIMP_ORIENTATION_VERTICAL,
 
69
                          image->gimp->next_guide_ID++);
 
70
 
 
71
  if (push_undo)
 
72
    gimp_image_undo_push_guide (image, _("Add Vertical Guide"), guide);
 
73
 
 
74
  gimp_image_add_guide (image, guide, position);
 
75
  g_object_unref (G_OBJECT (guide));
 
76
 
 
77
  return guide;
 
78
}
 
79
 
 
80
void
 
81
gimp_image_add_guide (GimpImage *image,
 
82
                      GimpGuide *guide,
113
83
                      gint       position)
114
84
{
115
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
116
 
  g_return_if_fail (guide != NULL);
 
85
  g_return_if_fail (GIMP_IS_IMAGE (image));
 
86
  g_return_if_fail (GIMP_IS_GUIDE (guide));
117
87
  g_return_if_fail (position >= 0);
118
88
 
119
 
  if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL)
120
 
    g_return_if_fail (position <= gimage->height);
 
89
  if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_HORIZONTAL)
 
90
    g_return_if_fail (position <= image->height);
121
91
  else
122
 
    g_return_if_fail (position <= gimage->width);
123
 
 
124
 
  gimage->guides = g_list_prepend (gimage->guides, guide);
125
 
 
126
 
  guide->position = position;
127
 
  gimp_image_guide_ref (guide);
128
 
 
129
 
  gimp_image_update_guide (gimage, guide);
 
92
    g_return_if_fail (position <= image->width);
 
93
 
 
94
  image->guides = g_list_prepend (image->guides, guide);
 
95
 
 
96
  gimp_guide_set_position (guide, position);
 
97
  g_object_ref (G_OBJECT (guide));
 
98
 
 
99
  gimp_image_update_guide (image, guide);
130
100
}
131
101
 
132
102
void
133
 
gimp_image_remove_guide (GimpImage *gimage,
134
 
                         GimpGuide *guide,
 
103
gimp_image_remove_guide (GimpImage *image,
 
104
                         GimpGuide *guide,
135
105
                         gboolean   push_undo)
136
106
{
137
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
138
 
  g_return_if_fail (guide != NULL);
 
107
  g_return_if_fail (GIMP_IS_IMAGE (image));
 
108
  g_return_if_fail (GIMP_IS_GUIDE (guide));
139
109
 
140
 
  gimp_image_update_guide (gimage, guide);
 
110
  gimp_image_update_guide (image, guide);
141
111
 
142
112
  if (push_undo)
143
 
    gimp_image_undo_push_image_guide (gimage, _("Remove Guide"), guide);
144
 
 
145
 
  gimage->guides = g_list_remove (gimage->guides, guide);
146
 
 
147
 
  guide->position = -1;
148
 
  gimp_image_guide_unref (guide);
 
113
    gimp_image_undo_push_guide (image, _("Remove Guide"), guide);
 
114
 
 
115
  image->guides = g_list_remove (image->guides, guide);
 
116
  gimp_guide_removed (guide);
 
117
 
 
118
  gimp_guide_set_position (guide, -1);
 
119
  g_object_unref (G_OBJECT (guide));
149
120
}
150
121
 
151
122
void
152
 
gimp_image_move_guide (GimpImage *gimage,
 
123
gimp_image_move_guide (GimpImage *image,
153
124
                       GimpGuide *guide,
154
125
                       gint       position,
155
126
                       gboolean   push_undo)
156
127
{
157
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
158
 
  g_return_if_fail (guide != NULL);
 
128
  g_return_if_fail (GIMP_IS_IMAGE (image));
 
129
  g_return_if_fail (GIMP_IS_GUIDE (guide));
159
130
  g_return_if_fail (position >= 0);
160
131
 
161
 
  if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL)
162
 
    g_return_if_fail (position <= gimage->height);
 
132
  if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_HORIZONTAL)
 
133
    g_return_if_fail (position <= image->height);
163
134
  else
164
 
    g_return_if_fail (position <= gimage->width);
 
135
    g_return_if_fail (position <= image->width);
165
136
 
166
137
  if (push_undo)
167
 
    gimp_image_undo_push_image_guide (gimage, _("Move Guide"), guide);
168
 
 
169
 
  gimp_image_update_guide (gimage, guide);
170
 
  guide->position = position;
171
 
  gimp_image_update_guide (gimage, guide);
172
 
}
173
 
 
174
 
GimpGuide *
175
 
gimp_image_find_guide (GimpImage *gimage,
 
138
    gimp_image_undo_push_guide (image, _("Move Guide"), guide);
 
139
 
 
140
  gimp_image_update_guide (image, guide);
 
141
  gimp_guide_set_position (guide, position);
 
142
  gimp_image_update_guide (image, guide);
 
143
}
 
144
 
 
145
GimpGuide *
 
146
gimp_image_get_guide (GimpImage *image,
 
147
                      guint32    id)
 
148
{
 
149
  GList *guides;
 
150
 
 
151
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
152
 
 
153
  for (guides = image->guides; guides; guides = g_list_next (guides))
 
154
    {
 
155
      GimpGuide *guide = guides->data;
 
156
 
 
157
      if (gimp_guide_get_ID (guide) == id &&
 
158
          gimp_guide_get_position (guide) >= 0)
 
159
        return guide;
 
160
    }
 
161
 
 
162
  return NULL;
 
163
}
 
164
 
 
165
GimpGuide *
 
166
gimp_image_get_next_guide (GimpImage *image,
 
167
                           guint32    id,
 
168
                           gboolean  *guide_found)
 
169
{
 
170
  GList *guides;
 
171
 
 
172
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
173
  g_return_val_if_fail (guide_found != NULL, NULL);
 
174
 
 
175
  if (id == 0)
 
176
    *guide_found = TRUE;
 
177
  else
 
178
    *guide_found = FALSE;
 
179
 
 
180
  for (guides = image->guides; guides; guides = g_list_next (guides))
 
181
    {
 
182
      GimpGuide *guide = guides->data;
 
183
 
 
184
      if (gimp_guide_get_position (guide) < 0)
 
185
        continue;
 
186
 
 
187
      if (*guide_found) /* this is the first guide after the found one */
 
188
        return guide;
 
189
 
 
190
      if (gimp_guide_get_ID (guide) == id) /* found it, next one will be returned */
 
191
        *guide_found = TRUE;
 
192
    }
 
193
 
 
194
  return NULL;
 
195
}
 
196
 
 
197
GimpGuide *
 
198
gimp_image_find_guide (GimpImage *image,
176
199
                       gdouble    x,
177
200
                       gdouble    y,
178
201
                       gdouble    epsilon_x,
184
207
  gdouble    dist;
185
208
  gdouble    mindist = G_MAXDOUBLE;
186
209
 
187
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
 
210
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
188
211
  g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
189
212
 
190
 
  if (x < 0 || x >= gimage->width ||
191
 
      y < 0 || y >= gimage->height)
 
213
  if (x < 0 || x >= image->width ||
 
214
      y < 0 || y >= image->height)
192
215
    {
193
216
      return NULL;
194
217
    }
195
218
 
196
 
  for (list = gimage->guides; list; list = g_list_next (list))
 
219
  for (list = image->guides; list; list = g_list_next (list))
197
220
    {
198
 
      guide = (GimpGuide *) list->data;
199
 
 
200
 
      if (guide->position < 0)
 
221
      gint position;
 
222
 
 
223
      guide = list->data;
 
224
      position = gimp_guide_get_position (guide);
 
225
 
 
226
      if (position < 0)
201
227
        continue;
202
228
 
203
 
      switch (guide->orientation)
 
229
      switch (gimp_guide_get_orientation (guide))
204
230
        {
205
231
        case GIMP_ORIENTATION_HORIZONTAL:
206
 
          dist = ABS (guide->position - y);
 
232
          dist = ABS (position - y);
207
233
          if (dist < MIN (epsilon_y, mindist))
208
234
            {
209
235
              mindist = dist;
213
239
 
214
240
        /* mindist always is in vertical resolution to make it comparable */
215
241
        case GIMP_ORIENTATION_VERTICAL:
216
 
          dist = ABS (guide->position - x);
 
242
          dist = ABS (position - x);
217
243
          if (dist < MIN (epsilon_x, mindist / epsilon_y * epsilon_x))
218
244
            {
219
245
              mindist = dist * epsilon_y / epsilon_x;