1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995-2003 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 3 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, see <https://www.gnu.org/licenses/>.
16  */
17 
18 /* NOTE: This file is auto-generated by pdbgen.pl. */
19 
20 #include "config.h"
21 
22 #include <gegl.h>
23 
24 #include <gdk-pixbuf/gdk-pixbuf.h>
25 
26 #include "libgimpbase/gimpbase.h"
27 
28 #include "pdb-types.h"
29 
30 #include "cairo.h"
31 #include "core/gimpguide.h"
32 #include "core/gimpimage-guides.h"
33 #include "core/gimpimage-undo-push.h"
34 #include "core/gimpimage.h"
35 #include "core/gimpparamspecs.h"
36 
37 #include "gimppdb.h"
38 #include "gimppdberror.h"
39 #include "gimppdb-utils.h"
40 #include "gimpprocedure.h"
41 #include "internal-procs.h"
42 
43 #include "gimp-intl.h"
44 
45 
46 static GimpValueArray *
image_add_hguide_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)47 image_add_hguide_invoker (GimpProcedure         *procedure,
48                           Gimp                  *gimp,
49                           GimpContext           *context,
50                           GimpProgress          *progress,
51                           const GimpValueArray  *args,
52                           GError               **error)
53 {
54   gboolean success = TRUE;
55   GimpValueArray *return_vals;
56   GimpImage *image;
57   gint32 yposition;
58   gint32 guide = 0;
59 
60   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
61   yposition = g_value_get_int (gimp_value_array_index (args, 1));
62 
63   if (success)
64     {
65       if (yposition <= gimp_image_get_height (image))
66         {
67           GimpGuide *g;
68 
69           g = gimp_image_add_hguide (image, yposition, TRUE);
70           guide = gimp_aux_item_get_ID (GIMP_AUX_ITEM (g));
71         }
72       else
73         success = FALSE;
74     }
75 
76   return_vals = gimp_procedure_get_return_values (procedure, success,
77                                                   error ? *error : NULL);
78 
79   if (success)
80     g_value_set_uint (gimp_value_array_index (return_vals, 1), guide);
81 
82   return return_vals;
83 }
84 
85 static GimpValueArray *
image_add_vguide_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)86 image_add_vguide_invoker (GimpProcedure         *procedure,
87                           Gimp                  *gimp,
88                           GimpContext           *context,
89                           GimpProgress          *progress,
90                           const GimpValueArray  *args,
91                           GError               **error)
92 {
93   gboolean success = TRUE;
94   GimpValueArray *return_vals;
95   GimpImage *image;
96   gint32 xposition;
97   gint32 guide = 0;
98 
99   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
100   xposition = g_value_get_int (gimp_value_array_index (args, 1));
101 
102   if (success)
103     {
104       if (xposition <= gimp_image_get_width (image))
105         {
106           GimpGuide *g;
107 
108           g = gimp_image_add_vguide (image, xposition, TRUE);
109           guide = gimp_aux_item_get_ID (GIMP_AUX_ITEM (g));
110         }
111       else
112         success = FALSE;
113     }
114 
115   return_vals = gimp_procedure_get_return_values (procedure, success,
116                                                   error ? *error : NULL);
117 
118   if (success)
119     g_value_set_uint (gimp_value_array_index (return_vals, 1), guide);
120 
121   return return_vals;
122 }
123 
124 static GimpValueArray *
image_delete_guide_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)125 image_delete_guide_invoker (GimpProcedure         *procedure,
126                             Gimp                  *gimp,
127                             GimpContext           *context,
128                             GimpProgress          *progress,
129                             const GimpValueArray  *args,
130                             GError               **error)
131 {
132   gboolean success = TRUE;
133   GimpImage *image;
134   gint32 guide;
135 
136   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
137   guide = g_value_get_uint (gimp_value_array_index (args, 1));
138 
139   if (success)
140     {
141       GimpGuide *g = gimp_pdb_image_get_guide (image, guide, error);
142 
143       if (g)
144         gimp_image_remove_guide (image, g, TRUE);
145       else
146         success = FALSE;
147     }
148 
149   return gimp_procedure_get_return_values (procedure, success,
150                                            error ? *error : NULL);
151 }
152 
153 static GimpValueArray *
image_find_next_guide_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)154 image_find_next_guide_invoker (GimpProcedure         *procedure,
155                                Gimp                  *gimp,
156                                GimpContext           *context,
157                                GimpProgress          *progress,
158                                const GimpValueArray  *args,
159                                GError               **error)
160 {
161   gboolean success = TRUE;
162   GimpValueArray *return_vals;
163   GimpImage *image;
164   gint32 guide;
165   gint32 next_guide = 0;
166 
167   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
168   guide = g_value_get_uint (gimp_value_array_index (args, 1));
169 
170   if (success)
171     {
172       GimpGuide *g = gimp_image_get_next_guide (image, guide, &success);
173 
174       if (g)
175         next_guide = gimp_aux_item_get_ID (GIMP_AUX_ITEM (g));
176 
177       if (! success)
178         g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
179                      _("Image '%s' (%d) does not contain guide with ID %d"),
180                      gimp_image_get_display_name (image),
181                      gimp_image_get_ID (image),
182                      guide);
183     }
184 
185   return_vals = gimp_procedure_get_return_values (procedure, success,
186                                                   error ? *error : NULL);
187 
188   if (success)
189     g_value_set_uint (gimp_value_array_index (return_vals, 1), next_guide);
190 
191   return return_vals;
192 }
193 
194 static GimpValueArray *
image_get_guide_orientation_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)195 image_get_guide_orientation_invoker (GimpProcedure         *procedure,
196                                      Gimp                  *gimp,
197                                      GimpContext           *context,
198                                      GimpProgress          *progress,
199                                      const GimpValueArray  *args,
200                                      GError               **error)
201 {
202   gboolean success = TRUE;
203   GimpValueArray *return_vals;
204   GimpImage *image;
205   gint32 guide;
206   gint32 orientation = 0;
207 
208   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
209   guide = g_value_get_uint (gimp_value_array_index (args, 1));
210 
211   if (success)
212     {
213       GimpGuide *g = gimp_pdb_image_get_guide (image, guide, error);
214 
215       if (g)
216         orientation = gimp_guide_get_orientation (g);
217       else
218         success = FALSE;
219     }
220 
221   return_vals = gimp_procedure_get_return_values (procedure, success,
222                                                   error ? *error : NULL);
223 
224   if (success)
225     g_value_set_enum (gimp_value_array_index (return_vals, 1), orientation);
226 
227   return return_vals;
228 }
229 
230 static GimpValueArray *
image_get_guide_position_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)231 image_get_guide_position_invoker (GimpProcedure         *procedure,
232                                   Gimp                  *gimp,
233                                   GimpContext           *context,
234                                   GimpProgress          *progress,
235                                   const GimpValueArray  *args,
236                                   GError               **error)
237 {
238   gboolean success = TRUE;
239   GimpValueArray *return_vals;
240   GimpImage *image;
241   gint32 guide;
242   gint32 position = 0;
243 
244   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
245   guide = g_value_get_uint (gimp_value_array_index (args, 1));
246 
247   if (success)
248     {
249       GimpGuide *g = gimp_pdb_image_get_guide (image, guide, error);
250 
251       if (g)
252         position = gimp_guide_get_position (g);
253       else
254         success = FALSE;
255     }
256 
257   return_vals = gimp_procedure_get_return_values (procedure, success,
258                                                   error ? *error : NULL);
259 
260   if (success)
261     g_value_set_int (gimp_value_array_index (return_vals, 1), position);
262 
263   return return_vals;
264 }
265 
266 void
register_image_guides_procs(GimpPDB * pdb)267 register_image_guides_procs (GimpPDB *pdb)
268 {
269   GimpProcedure *procedure;
270 
271   /*
272    * gimp-image-add-hguide
273    */
274   procedure = gimp_procedure_new (image_add_hguide_invoker);
275   gimp_object_set_static_name (GIMP_OBJECT (procedure),
276                                "gimp-image-add-hguide");
277   gimp_procedure_set_static_strings (procedure,
278                                      "gimp-image-add-hguide",
279                                      "Add a horizontal guide to an image.",
280                                      "This procedure adds a horizontal guide to an image. It takes the input image and the y-position of the new guide as parameters. It returns the guide ID of the new guide.",
281                                      "Adam D. Moss",
282                                      "Adam D. Moss",
283                                      "1998",
284                                      NULL);
285   gimp_procedure_add_argument (procedure,
286                                gimp_param_spec_image_id ("image",
287                                                          "image",
288                                                          "The image",
289                                                          pdb->gimp, FALSE,
290                                                          GIMP_PARAM_READWRITE));
291   gimp_procedure_add_argument (procedure,
292                                gimp_param_spec_int32 ("yposition",
293                                                       "yposition",
294                                                       "The guide's y-offset from top of image",
295                                                       0, G_MAXINT32, 0,
296                                                       GIMP_PARAM_READWRITE));
297   gimp_procedure_add_return_value (procedure,
298                                    g_param_spec_uint ("guide",
299                                                       "guide",
300                                                       "The new guide",
301                                                       1, G_MAXUINT32, 1,
302                                                       GIMP_PARAM_READWRITE));
303   gimp_pdb_register_procedure (pdb, procedure);
304   g_object_unref (procedure);
305 
306   /*
307    * gimp-image-add-vguide
308    */
309   procedure = gimp_procedure_new (image_add_vguide_invoker);
310   gimp_object_set_static_name (GIMP_OBJECT (procedure),
311                                "gimp-image-add-vguide");
312   gimp_procedure_set_static_strings (procedure,
313                                      "gimp-image-add-vguide",
314                                      "Add a vertical guide to an image.",
315                                      "This procedure adds a vertical guide to an image. It takes the input image and the x-position of the new guide as parameters. It returns the guide ID of the new guide.",
316                                      "Adam D. Moss",
317                                      "Adam D. Moss",
318                                      "1998",
319                                      NULL);
320   gimp_procedure_add_argument (procedure,
321                                gimp_param_spec_image_id ("image",
322                                                          "image",
323                                                          "The image",
324                                                          pdb->gimp, FALSE,
325                                                          GIMP_PARAM_READWRITE));
326   gimp_procedure_add_argument (procedure,
327                                gimp_param_spec_int32 ("xposition",
328                                                       "xposition",
329                                                       "The guide's x-offset from left of image",
330                                                       0, G_MAXINT32, 0,
331                                                       GIMP_PARAM_READWRITE));
332   gimp_procedure_add_return_value (procedure,
333                                    g_param_spec_uint ("guide",
334                                                       "guide",
335                                                       "The new guide",
336                                                       1, G_MAXUINT32, 1,
337                                                       GIMP_PARAM_READWRITE));
338   gimp_pdb_register_procedure (pdb, procedure);
339   g_object_unref (procedure);
340 
341   /*
342    * gimp-image-delete-guide
343    */
344   procedure = gimp_procedure_new (image_delete_guide_invoker);
345   gimp_object_set_static_name (GIMP_OBJECT (procedure),
346                                "gimp-image-delete-guide");
347   gimp_procedure_set_static_strings (procedure,
348                                      "gimp-image-delete-guide",
349                                      "Deletes a guide from an image.",
350                                      "This procedure takes an image and a guide ID as input and removes the specified guide from the specified image.",
351                                      "Adam D. Moss",
352                                      "Adam D. Moss",
353                                      "1998",
354                                      NULL);
355   gimp_procedure_add_argument (procedure,
356                                gimp_param_spec_image_id ("image",
357                                                          "image",
358                                                          "The image",
359                                                          pdb->gimp, FALSE,
360                                                          GIMP_PARAM_READWRITE));
361   gimp_procedure_add_argument (procedure,
362                                g_param_spec_uint ("guide",
363                                                   "guide",
364                                                   "The ID of the guide to be removed",
365                                                   1, G_MAXUINT32, 1,
366                                                   GIMP_PARAM_READWRITE));
367   gimp_pdb_register_procedure (pdb, procedure);
368   g_object_unref (procedure);
369 
370   /*
371    * gimp-image-find-next-guide
372    */
373   procedure = gimp_procedure_new (image_find_next_guide_invoker);
374   gimp_object_set_static_name (GIMP_OBJECT (procedure),
375                                "gimp-image-find-next-guide");
376   gimp_procedure_set_static_strings (procedure,
377                                      "gimp-image-find-next-guide",
378                                      "Find next guide on an image.",
379                                      "This procedure takes an image and a guide ID as input and finds the guide ID of the successor of the given guide ID in the image's guide list. If the supplied guide ID is 0, the procedure will return the first Guide. The procedure will return 0 if given the final guide ID as an argument or the image has no guides.",
380                                      "Adam D. Moss",
381                                      "Adam D. Moss",
382                                      "1998",
383                                      NULL);
384   gimp_procedure_add_argument (procedure,
385                                gimp_param_spec_image_id ("image",
386                                                          "image",
387                                                          "The image",
388                                                          pdb->gimp, FALSE,
389                                                          GIMP_PARAM_READWRITE));
390   gimp_procedure_add_argument (procedure,
391                                g_param_spec_uint ("guide",
392                                                   "guide",
393                                                   "The ID of the current guide (0 if first invocation)",
394                                                   1, G_MAXUINT32, 1,
395                                                   GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
396   gimp_procedure_add_return_value (procedure,
397                                    g_param_spec_uint ("next-guide",
398                                                       "next guide",
399                                                       "The next guide's ID",
400                                                       1, G_MAXUINT32, 1,
401                                                       GIMP_PARAM_READWRITE));
402   gimp_pdb_register_procedure (pdb, procedure);
403   g_object_unref (procedure);
404 
405   /*
406    * gimp-image-get-guide-orientation
407    */
408   procedure = gimp_procedure_new (image_get_guide_orientation_invoker);
409   gimp_object_set_static_name (GIMP_OBJECT (procedure),
410                                "gimp-image-get-guide-orientation");
411   gimp_procedure_set_static_strings (procedure,
412                                      "gimp-image-get-guide-orientation",
413                                      "Get orientation of a guide on an image.",
414                                      "This procedure takes an image and a guide ID as input and returns the orientations of the guide.",
415                                      "Adam D. Moss",
416                                      "Adam D. Moss",
417                                      "1998",
418                                      NULL);
419   gimp_procedure_add_argument (procedure,
420                                gimp_param_spec_image_id ("image",
421                                                          "image",
422                                                          "The image",
423                                                          pdb->gimp, FALSE,
424                                                          GIMP_PARAM_READWRITE));
425   gimp_procedure_add_argument (procedure,
426                                g_param_spec_uint ("guide",
427                                                   "guide",
428                                                   "The guide",
429                                                   1, G_MAXUINT32, 1,
430                                                   GIMP_PARAM_READWRITE));
431   gimp_procedure_add_return_value (procedure,
432                                    gimp_param_spec_enum ("orientation",
433                                                          "orientation",
434                                                          "The guide's orientation",
435                                                          GIMP_TYPE_ORIENTATION_TYPE,
436                                                          GIMP_ORIENTATION_HORIZONTAL,
437                                                          GIMP_PARAM_READWRITE));
438   gimp_param_spec_enum_exclude_value (GIMP_PARAM_SPEC_ENUM (procedure->values[0]),
439                                       GIMP_ORIENTATION_UNKNOWN);
440   gimp_pdb_register_procedure (pdb, procedure);
441   g_object_unref (procedure);
442 
443   /*
444    * gimp-image-get-guide-position
445    */
446   procedure = gimp_procedure_new (image_get_guide_position_invoker);
447   gimp_object_set_static_name (GIMP_OBJECT (procedure),
448                                "gimp-image-get-guide-position");
449   gimp_procedure_set_static_strings (procedure,
450                                      "gimp-image-get-guide-position",
451                                      "Get position of a guide on an image.",
452                                      "This procedure takes an image and a guide ID as input and returns the position of the guide relative to the top or left of the image.",
453                                      "Adam D. Moss",
454                                      "Adam D. Moss",
455                                      "1998",
456                                      NULL);
457   gimp_procedure_add_argument (procedure,
458                                gimp_param_spec_image_id ("image",
459                                                          "image",
460                                                          "The image",
461                                                          pdb->gimp, FALSE,
462                                                          GIMP_PARAM_READWRITE));
463   gimp_procedure_add_argument (procedure,
464                                g_param_spec_uint ("guide",
465                                                   "guide",
466                                                   "The guide",
467                                                   1, G_MAXUINT32, 1,
468                                                   GIMP_PARAM_READWRITE));
469   gimp_procedure_add_return_value (procedure,
470                                    gimp_param_spec_int32 ("position",
471                                                           "position",
472                                                           "The guide's position relative to top or left of image",
473                                                           G_MININT32, G_MAXINT32, 0,
474                                                           GIMP_PARAM_READWRITE));
475   gimp_pdb_register_procedure (pdb, procedure);
476   g_object_unref (procedure);
477 }
478