paint-tools-cmds.c 74.7 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

19
/* NOTE: This file is auto-generated by pdbgen.pl. */
20

21 22
#include "config.h"

23
#include <gegl.h>
24

25 26
#include "libgimpmath/gimpmath.h"

27
#include "pdb-types.h"
28

29
#include "core/gimpdrawable.h"
30
#include "core/gimppaintinfo.h"
31
#include "core/gimpparamspecs.h"
32
#include "paint/gimppaintcore-stroke.h"
33
#include "paint/gimppaintcore.h"
34
#include "paint/gimppaintoptions.h"
35

36 37 38
#include "gimppdb.h"
#include "gimppdb-utils.h"
#include "gimpprocedure.h"
39
#include "internal-procs.h"
40

41

42 43
static const GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;

44
static gboolean
45 46 47 48 49 50 51 52
paint_tools_stroke (Gimp              *gimp,
                    GimpContext       *context,
                    GimpPaintOptions  *options,
                    GimpDrawable      *drawable,
                    gint               n_strokes,
                    const gdouble     *strokes,
                    GError           **error,
                    const gchar       *first_property_name,
53
                    ...)
54 55
{
  GimpPaintCore *core;
56
  GimpCoords    *coords;
57
  gboolean       retval;
58
  gint           i;
59
  va_list        args;
60

61 62
  n_strokes /= 2;  /* #doubles -> #points */

63 64 65 66 67 68
  /*  undefine the paint-relevant context properties and get them
   *  from the current context
   */
  gimp_context_define_properties (GIMP_CONTEXT (options),
                                  GIMP_CONTEXT_PAINT_PROPS_MASK,
                                  FALSE);
69
  gimp_context_set_parent (GIMP_CONTEXT (options), context);
70

71 72 73 74
  va_start (args, first_property_name);
  core = GIMP_PAINT_CORE (g_object_new_valist (options->paint_info->paint_type,
                                               first_property_name, args));
  va_end (args);
75

76 77 78 79
  coords = g_new (GimpCoords, n_strokes);

  for (i = 0; i < n_strokes; i++)
    {
80 81 82
      coords[i]   = default_coords;
      coords[i].x = strokes[2 * i];
      coords[i].y = strokes[2 * i + 1];
83 84
    }

85
  retval = gimp_paint_core_stroke (core, drawable, options,
86
                                   coords, n_strokes, TRUE,
87
                                   error);
88 89

  g_free (coords);
90

91
  g_object_unref (core);
92
  g_object_unref (options);
93 94 95 96

  return retval;
}

97
static GValueArray *
98 99 100 101 102 103
airbrush_invoker (GimpProcedure      *procedure,
                  Gimp               *gimp,
                  GimpContext        *context,
                  GimpProgress       *progress,
                  const GValueArray  *args,
                  GError            **error)
104 105 106 107 108
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gdouble pressure;
  gint32 num_strokes;
109
  const gdouble *strokes;
110

111 112 113 114
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  pressure = g_value_get_double (&args->values[1]);
  num_strokes = g_value_get_int (&args->values[2]);
  strokes = gimp_value_get_floatarray (&args->values[3]);
115 116

  if (success)
117
    {
118
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-airbrush", error);
Manish Singh's avatar
Manish Singh committed
119

120
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
121 122
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
123

124 125 126 127 128
          g_object_set (options,
                        "pressure", pressure,
                        NULL);

          success = paint_tools_stroke (gimp, context, options, drawable,
129
                                        num_strokes, strokes, error,
130 131
                                        "undo-desc", info->blurb,
                                        NULL);
132
        }
133 134
      else
        success = FALSE;
135
    }
136

137 138
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
139 140
}

141
static GValueArray *
142 143 144 145 146 147
airbrush_default_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
148 149 150 151
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
152
  const gdouble *strokes;
153

154 155 156
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);
157 158

  if (success)
159
    {
160
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-airbrush", error);
161

162
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
163 164
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
165

166
          success = paint_tools_stroke (gimp, context, options, drawable,
167
                                        num_strokes, strokes, error,
168 169
                                        "undo-desc", info->blurb,
                                        NULL);
170
        }
171 172
      else
        success = FALSE;
173
    }
174

175 176
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
177 178
}

179
static GValueArray *
180 181 182 183 184 185
clone_invoker (GimpProcedure      *procedure,
               Gimp               *gimp,
               GimpContext        *context,
               GimpProgress       *progress,
               const GValueArray  *args,
               GError            **error)
186 187 188 189 190 191 192 193
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  GimpDrawable *src_drawable;
  gint32 clone_type;
  gdouble src_x;
  gdouble src_y;
  gint32 num_strokes;
194
  const gdouble *strokes;
195

196 197 198 199 200 201 202
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  src_drawable = gimp_value_get_drawable (&args->values[1], gimp);
  clone_type = g_value_get_enum (&args->values[2]);
  src_x = g_value_get_double (&args->values[3]);
  src_y = g_value_get_double (&args->values[4]);
  num_strokes = g_value_get_int (&args->values[5]);
  strokes = gimp_value_get_floatarray (&args->values[6]);
203 204

  if (success)
205
    {
206
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-clone", error);
Manish Singh's avatar
Manish Singh committed
207

208
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
209 210 211 212 213 214
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);

          g_object_set (options,
                        "clone-type", clone_type,
                        NULL);
Manish Singh's avatar
Manish Singh committed
215

216
          success = paint_tools_stroke (gimp, context, options, drawable,
217
                                        num_strokes, strokes, error,
218
                                        "undo-desc",    info->blurb,
219 220 221 222
                                        "src-drawable", src_drawable,
                                        "src-x",        src_x,
                                        "src-y",        src_y,
                                        NULL);
223
        }
224 225
      else
        success = FALSE;
226
    }
227

228 229
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
230 231
}

232
static GValueArray *
233 234 235 236 237 238
clone_default_invoker (GimpProcedure      *procedure,
                       Gimp               *gimp,
                       GimpContext        *context,
                       GimpProgress       *progress,
                       const GValueArray  *args,
                       GError            **error)
239 240 241 242
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
243
  const gdouble *strokes;
244

245 246 247
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);
248 249

  if (success)
250
    {
251
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-clone", error);
252

253
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
254 255
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
Manish Singh's avatar
Manish Singh committed
256

257
          success = paint_tools_stroke (gimp, context, options, drawable,
258
                                        num_strokes, strokes, error,
259 260
                                        "undo-desc", info->blurb,
                                        NULL);
261
        }
262 263
      else
        success = FALSE;
264
    }
265

266 267
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
268 269
}

270
static GValueArray *
271 272 273 274 275 276
convolve_invoker (GimpProcedure      *procedure,
                  Gimp               *gimp,
                  GimpContext        *context,
                  GimpProgress       *progress,
                  const GValueArray  *args,
                  GError            **error)
277 278 279 280 281 282
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gdouble pressure;
  gint32 convolve_type;
  gint32 num_strokes;
283
  const gdouble *strokes;
284

285 286 287 288 289
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  pressure = g_value_get_double (&args->values[1]);
  convolve_type = g_value_get_enum (&args->values[2]);
  num_strokes = g_value_get_int (&args->values[3]);
  strokes = gimp_value_get_floatarray (&args->values[4]);
290 291

  if (success)
292
    {
293
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-convolve", error);
Manish Singh's avatar
Manish Singh committed
294

295
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
296 297
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
Manish Singh's avatar
Manish Singh committed
298

299 300 301 302 303 304
          g_object_set (options,
                        "type", convolve_type,
                        "rate", pressure,
                        NULL);

          success = paint_tools_stroke (gimp, context, options, drawable,
305
                                        num_strokes, strokes, error,
306 307
                                        "undo-desc", info->blurb,
                                        NULL);
308
        }
309 310
      else
        success = FALSE;
311
    }
312

313 314
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
315 316
}

317
static GValueArray *
318 319 320 321 322 323
convolve_default_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
324 325 326 327
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
328
  const gdouble *strokes;
329

330 331 332
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);
333 334

  if (success)
335
    {
336
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-convolve", error);
337

338
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
339 340
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
Manish Singh's avatar
Manish Singh committed
341

342
          success = paint_tools_stroke (gimp, context, options, drawable,
343
                                        num_strokes, strokes, error,
344 345
                                        "undo-desc", info->blurb,
                                        NULL);
346
        }
347 348
      else
        success = FALSE;
349
    }
350

351 352
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
353 354
}

355
static GValueArray *
356 357 358 359 360 361
dodgeburn_invoker (GimpProcedure      *procedure,
                   Gimp               *gimp,
                   GimpContext        *context,
                   GimpProgress       *progress,
                   const GValueArray  *args,
                   GError            **error)
362 363 364 365 366 367 368
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gdouble exposure;
  gint32 dodgeburn_type;
  gint32 dodgeburn_mode;
  gint32 num_strokes;
369
  const gdouble *strokes;
370

371 372 373 374 375 376
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  exposure = g_value_get_double (&args->values[1]);
  dodgeburn_type = g_value_get_enum (&args->values[2]);
  dodgeburn_mode = g_value_get_enum (&args->values[3]);
  num_strokes = g_value_get_int (&args->values[4]);
  strokes = gimp_value_get_floatarray (&args->values[5]);
377 378

  if (success)
379
    {
380
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-dodge-burn", error);
Manish Singh's avatar
Manish Singh committed
381

382
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
383 384
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
Manish Singh's avatar
Manish Singh committed
385

386 387 388 389 390 391 392
          g_object_set (options,
                        "type",     dodgeburn_type,
                        "mode",     dodgeburn_mode,
                        "exposure", exposure,
                        NULL);

          success = paint_tools_stroke (gimp, context, options, drawable,
393
                                        num_strokes, strokes, error,
394 395
                                        "undo-desc", info->blurb,
                                        NULL);
396
        }
397 398
      else
        success = FALSE;
399
    }
400

401 402
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
403 404
}

405
static GValueArray *
406 407 408 409 410 411
dodgeburn_default_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
412 413 414 415
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
416
  const gdouble *strokes;
417

418 419 420
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);
421 422

  if (success)
423
    {
424
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-dodge-burn", error);
425

426
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
427 428
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
Manish Singh's avatar
Manish Singh committed
429

430
          success = paint_tools_stroke (gimp, context, options, drawable,
431
                                        num_strokes, strokes, error,
432 433
                                        "undo-desc", info->blurb,
                                        NULL);
434
        }
435 436
      else
        success = FALSE;
437
    }
438

439 440
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
441 442
}

443
static GValueArray *
444 445 446 447 448 449
eraser_invoker (GimpProcedure      *procedure,
                Gimp               *gimp,
                GimpContext        *context,
                GimpProgress       *progress,
                const GValueArray  *args,
                GError            **error)
450 451 452 453
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
454
  const gdouble *strokes;
455 456 457
  gint32 hardness;
  gint32 method;

458 459 460 461 462
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);
  hardness = g_value_get_enum (&args->values[3]);
  method = g_value_get_enum (&args->values[4]);
463 464

  if (success)
465
    {
466
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-eraser", error);
Manish Singh's avatar
Manish Singh committed
467

468
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
469 470
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
Manish Singh's avatar
Manish Singh committed
471

472 473 474 475 476 477
          g_object_set (options,
                        "application-mode", method,
                        "hard",             hardness,
                        NULL);

          success = paint_tools_stroke (gimp, context, options, drawable,
478
                                        num_strokes, strokes, error,
479 480
                                        "undo-desc", info->blurb,
                                        NULL);
481
        }
482 483
      else
        success = FALSE;
484
    }
485

486 487
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
488 489
}

490
static GValueArray *
491 492 493 494 495 496
eraser_default_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
497 498 499 500
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
501
  const gdouble *strokes;
502

503 504 505
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);
506 507

  if (success)
508
    {
509
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-eraser", error);
Manish Singh's avatar
Manish Singh committed
510

511
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
512 513
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
514

515
          success = paint_tools_stroke (gimp, context, options, drawable,
516
                                        num_strokes, strokes, error,
517 518
                                        "undo-desc", info->blurb,
                                        NULL);
519
        }
520 521
      else
        success = FALSE;
522
    }
523

524 525
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
526 527
}

528
static GValueArray *
529 530 531 532 533 534
heal_invoker (GimpProcedure      *procedure,
              Gimp               *gimp,
              GimpContext        *context,
              GimpProgress       *progress,
              const GValueArray  *args,
              GError            **error)
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  GimpDrawable *src_drawable;
  gdouble src_x;
  gdouble src_y;
  gint32 num_strokes;
  const gdouble *strokes;

  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  src_drawable = gimp_value_get_drawable (&args->values[1], gimp);
  src_x = g_value_get_double (&args->values[2]);
  src_y = g_value_get_double (&args->values[3]);
  num_strokes = g_value_get_int (&args->values[4]);
  strokes = gimp_value_get_floatarray (&args->values[5]);

  if (success)
    {
553
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-heal", error);
554

555
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
556 557 558 559
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);

          success = paint_tools_stroke (gimp, context, options, drawable,
560
                                        num_strokes, strokes, error,
561
                                        "undo-desc",    info->blurb,
562 563 564 565 566
                                        "src-drawable", src_drawable,
                                        "src-x",        src_x,
                                        "src-y",        src_y,
                                        NULL);
        }
567 568
      else
        success = FALSE;
569 570
    }

571 572
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
573 574 575
}

static GValueArray *
576 577 578 579 580 581
heal_default_invoker (GimpProcedure      *procedure,
                      Gimp               *gimp,
                      GimpContext        *context,
                      GimpProgress       *progress,
                      const GValueArray  *args,
                      GError            **error)
582 583 584 585 586 587 588 589 590 591 592 593
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
  const gdouble *strokes;

  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);

  if (success)
    {
594
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-heal", error);
595

596
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
597 598 599 600
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);

          success = paint_tools_stroke (gimp, context, options, drawable,
601
                                        num_strokes, strokes, error,
602 603
                                        "undo-desc", info->blurb,
                                        NULL);
604
        }
605 606
      else
        success = FALSE;
607 608
    }

609 610
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
611 612
}

613
static GValueArray *
614 615 616 617 618 619
paintbrush_invoker (GimpProcedure      *procedure,
                    Gimp               *gimp,
                    GimpContext        *context,
                    GimpProgress       *progress,
                    const GValueArray  *args,
                    GError            **error)
620 621 622 623 624
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gdouble fade_out;
  gint32 num_strokes;
625
  const gdouble *strokes;
626 627 628
  gint32 method;
  gdouble gradient_length;

629 630 631 632 633 634
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  fade_out = g_value_get_double (&args->values[1]);
  num_strokes = g_value_get_int (&args->values[2]);
  strokes = gimp_value_get_floatarray (&args->values[3]);
  method = g_value_get_enum (&args->values[4]);
  gradient_length = g_value_get_double (&args->values[5]);
635 636

  if (success)
637
    {
638
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-paintbrush", error);
Manish Singh's avatar
Manish Singh committed
639

640
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
641 642
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
Manish Singh's avatar
Manish Singh committed
643

644 645 646 647 648 649 650 651 652
          g_object_set (options,
                        "application-mode", method,
                        "use-fade",         fade_out > 0.0,
                        "fade-length",      fade_out,
                        "use-gradient",     gradient_length > 0.0,
                        "gradient-length",  gradient_length,
                        NULL);

          success = paint_tools_stroke (gimp, context, options, drawable,
653
                                        num_strokes, strokes, error,
654 655
                                        "undo-desc", info->blurb,
                                        NULL);
656
        }
657 658
      else
        success = FALSE;
659
    }
660

661 662
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
663 664
}

665
static GValueArray *
666 667 668 669 670 671
paintbrush_default_invoker (GimpProcedure      *procedure,
                            Gimp               *gimp,
                            GimpContext        *context,
                            GimpProgress       *progress,
                            const GValueArray  *args,
                            GError            **error)
672 673 674 675
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
676
  const gdouble *strokes;
677

678
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
679 680 681 682 683
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);

  if (success)
    {
684
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-paintbrush", error);
685

686
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
687 688 689 690
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);

          success = paint_tools_stroke (gimp, context, options, drawable,
691
                                        num_strokes, strokes, error,
692 693
                                        "undo-desc", info->blurb,
                                        NULL);
694
        }
695 696
      else
        success = FALSE;
697 698
    }

699 700
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
701 702 703
}

static GValueArray *
704 705 706 707 708 709
pencil_invoker (GimpProcedure      *procedure,
                Gimp               *gimp,
                GimpContext        *context,
                GimpProgress       *progress,
                const GValueArray  *args,
                GError            **error)
710 711 712 713 714 715 716 717 718 719 720 721
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
  const gdouble *strokes;

  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);

  if (success)
    {
722
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-pencil", error);
723

724
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
725 726 727 728
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);

          success = paint_tools_stroke (gimp, context, options, drawable,
729
                                        num_strokes, strokes, error,
730 731
                                        "undo-desc", info->blurb,
                                        NULL);
732
        }
733 734
      else
        success = FALSE;
735 736
    }

737 738
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
739 740 741
}

static GValueArray *
742 743 744 745 746 747
smudge_invoker (GimpProcedure      *procedure,
                Gimp               *gimp,
                GimpContext        *context,
                GimpProgress       *progress,
                const GValueArray  *args,
                GError            **error)
748 749 750 751 752 753 754 755 756 757 758
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gdouble pressure;
  gint32 num_strokes;
  const gdouble *strokes;

  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  pressure = g_value_get_double (&args->values[1]);
  num_strokes = g_value_get_int (&args->values[2]);
  strokes = gimp_value_get_floatarray (&args->values[3]);
759 760

  if (success)
761
    {
762
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-smudge", error);
Manish Singh's avatar
Manish Singh committed
763

764
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
765 766
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);
767

768 769 770 771
          g_object_set (options,
                        "rate", pressure,
                        NULL);

772
          success = paint_tools_stroke (gimp, context, options, drawable,
773
                                        num_strokes, strokes, error,
774 775
                                        "undo-desc", info->blurb,
                                        NULL);
776
        }
777 778
      else
        success = FALSE;
779
    }
780

781 782
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
783 784
}

785
static GValueArray *
786 787 788 789 790 791
smudge_default_invoker (GimpProcedure      *procedure,
                        Gimp               *gimp,
                        GimpContext        *context,
                        GimpProgress       *progress,
                        const GValueArray  *args,
                        GError            **error)
792 793 794 795
{
  gboolean success = TRUE;
  GimpDrawable *drawable;
  gint32 num_strokes;
796
  const gdouble *strokes;
797

798 799 800
  drawable = gimp_value_get_drawable (&args->values[0], gimp);
  num_strokes = g_value_get_int (&args->values[1]);
  strokes = gimp_value_get_floatarray (&args->values[2]);
801 802

  if (success)
803
    {
804
      GimpPaintInfo *info = gimp_pdb_get_paint_info (gimp, "gimp-smudge", error);
Manish Singh's avatar
Manish Singh committed
805

806
      if (info && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
807 808 809 810
        {
          GimpPaintOptions *options = gimp_paint_options_new (info);

          success = paint_tools_stroke (gimp, context, options, drawable,
811
                                        num_strokes, strokes, error,
812 813
                                        "undo-desc", info->blurb,
                                        NULL);
814
        }
815 816
      else
        success = FALSE;
817
    }
818

819 820
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
821 822
}

823
void
824
register_paint_tools_procs (GimpPDB *pdb)
825
{
826
  GimpProcedure *procedure;
827

828 829 830
  /*
   * gimp-airbrush
   */
831
  procedure = gimp_procedure_new (airbrush_invoker);
832 833
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-airbrush");
834 835 836 837 838 839 840 841 842 843 844 845
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-airbrush",
                                     "Paint in the current brush with varying pressure. Paint application is time-dependent.",
                                     "This tool simulates the use of an airbrush. Paint pressure represents the relative intensity of the paint application. High pressure results in a thicker layer of paint while low pressure results in a thinner layer.",
                                     "Spencer Kimball & Peter Mattis",
                                     "Spencer Kimball & Peter Mattis",
                                     "1995-1996",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_drawable_id ("drawable",
                                                            "drawable",
                                                            "The affected drawable",
846
                                                            pdb->gimp, FALSE,
847 848 849 850
                                                            GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               g_param_spec_double ("pressure",
                                                    "pressure",
851
                                                    "The pressure of the airbrush strokes",
852 853 854 855 856 857 858 859 860 861 862 863 864
                                                    0, 100, 0,
                                                    GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_int32 ("num-strokes",
                                                      "num strokes",
                                                      "Number of stroke control points (count each coordinate as 2 points)",
                                                      2, G_MAXINT32, 2,
                                                      GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            GIMP_PARAM_READWRITE));
865
  gimp_pdb_register_procedure (pdb, procedure);
866
  g_object_unref (procedure);
867 868 869 870

  /*
   * gimp-airbrush-default
   */
871
  procedure = gimp_procedure_new (airbrush_default_invoker);
872 873
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-airbrush-default");
874 875 876
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-airbrush-default",
                                     "Paint in the current brush with varying pressure. Paint application is time-dependent.",
877
                                     "This tool simulates the use of an airbrush. It is similar to 'gimp-airbrush' except that the pressure is derived from the airbrush tools options box. It the option has not been set the default for the option will be used.",
878 879 880 881 882 883 884 885
                                     "Andy Thomas",
                                     "Andy Thomas",
                                     "1999",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_drawable_id ("drawable",
                                                            "drawable",
                                                            "The affected drawable",
886
                                                            pdb->gimp, FALSE,
887 888 889 890 891 892 893 894 895 896 897 898
                                                            GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_int32 ("num-strokes",
                                                      "num strokes",
                                                      "Number of stroke control points (count each coordinate as 2 points)",
                                                      2, G_MAXINT32, 2,
                                                      GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_float_array ("strokes",
                                                            "strokes",
                                                            "Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }",
                                                            GIMP_PARAM_READWRITE));
899
  gimp_pdb_register_procedure (pdb, procedure);
900
  g_object_unref (procedure);
901 902 903 904

  /*
   * gimp-clone
   */