edit.pdb 27.2 KB
Newer Older
1
# GIMP - The GNU Image Manipulation Program
Manish Singh's avatar
Manish Singh committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

# 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.

# "Perlized" from C source by Manish Singh <yosh@gimp.org>

sub edit_cut {
    $blurb = 'Cut from the specified drawable.';

    $help = <<'HELP';
24 25
If there is a selection in the image, then the area specified by the
selection is cut from the specified drawable and placed in an internal
26
GIMP edit buffer. It can subsequently be retrieved using the
27
gimp_edit_paste() command. If there is no selection, then the
28
specified drawable will be removed and its contents stored in the
29 30 31
internal GIMP edit buffer. This procedure will fail if the selected area
lies completely outside the bounds of the current drawable and there is
nothing to copy from.
Manish Singh's avatar
Manish Singh committed
32 33 34
HELP

    &std_pdb_misc;
35 36 37 38 39 40 41

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to cut from' }
    );

    @outargs = (
42
	{ name => 'non_empty', type => 'boolean',
43 44
	  desc => 'TRUE if the cut was successful,
                   FALSE if there was nothing to copy from' }
45 46
    );

47 48 49
    %invoke = (
	code => <<CODE
{
50
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
51
    {
52 53
      GimpImage *image    = gimp_item_get_image (GIMP_ITEM (drawable));
      GError    *my_error = NULL;
54

55 56 57 58 59 60 61 62
      non_empty = gimp_edit_cut (image, drawable, context, &my_error) != NULL;

      if (! non_empty)
        {
          gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                        "%s", my_error->message);
          g_clear_error (&my_error);
        }
63
    }
64 65
  else
    success = FALSE;
66 67 68
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
69 70 71 72 73 74
}

sub edit_copy {
    $blurb = 'Copy from the specified drawable.';

    $help = <<'HELP';
75 76 77
If there is a selection in the image, then the area specified by the
selection is copied from the specified drawable and placed in an
internal GIMP edit buffer. It can subsequently be retrieved using the
78
gimp_edit_paste() command.  If there is no selection, then the
79
specified drawable's contents will be stored in the internal GIMP edit
80 81 82
buffer. This procedure will fail if the selected area lies completely
outside the bounds of the current drawable and there is nothing to
copy from.
Manish Singh's avatar
Manish Singh committed
83 84 85
HELP

    &std_pdb_misc;
86 87 88 89 90 91 92

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to copy from' }
    );

    @outargs = (
93
	{ name => 'non_empty', type => 'boolean',
94 95
	  desc => 'TRUE if the cut was successful,
                   FALSE if there was nothing to copy from' }
96 97
    );

98 99 100
    %invoke = (
	code => <<CODE
{
101
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
102
    {
103 104 105 106
      GimpImage *image    = gimp_item_get_image (GIMP_ITEM (drawable));
      GError    *my_error = NULL;

      non_empty = gimp_edit_copy (image, drawable, context, &my_error) != NULL;
107

108 109 110 111 112 113
      if (! non_empty)
        {
          gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                        "%s", my_error->message);
          g_clear_error (&my_error);
        }
114
    }
115 116
  else
    success = FALSE;
117 118 119
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
120 121
}

122 123 124 125 126 127 128
sub edit_copy_visible {
    $blurb = 'Copy from the projection.';

    $help = <<'HELP';
If there is a selection in the image, then the area specified by the
selection is copied from the projection and placed in an internal GIMP
edit buffer. It can subsequently be retrieved using the
129
gimp_edit_paste() command. If there is no selection, then the
130 131 132
projection's contents will be stored in the internal GIMP edit buffer.
HELP

133
    &mitch_pdb_misc('2004', '2.2');
134 135 136 137 138

    @inargs = (
	{ name => 'image', type => 'image',
	  desc => "The image to copy from" }
    );
139 140

    @outargs = (
141
	{ name => 'non_empty', type => 'boolean',
142
	  desc => 'TRUE if the copy was successful' }
143
    );
144 145 146 147

    %invoke = (
	code => <<CODE
{
148 149 150 151 152 153 154 155 156 157
  GError *my_error = NULL;

  non_empty = gimp_edit_copy_visible (image, context, &my_error) != NULL;

  if (! non_empty)
    {
      gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                    "%s", my_error->message);
      g_clear_error (&my_error);
    }
158 159 160 161 162
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
163 164 165 166
sub edit_paste {
    $blurb = 'Paste buffer to the specified drawable.';

    $help = <<'HELP';
167 168
This procedure pastes a copy of the internal GIMP edit buffer to the
specified drawable. The GIMP edit buffer will be empty unless a call
169
was previously made to either gimp_edit_cut() or gimp_edit_copy(). The
170 171 172 173 174 175 176 177 178 179 180
"paste_into" option specifies whether to clear the current image
selection, or to paste the buffer "behind" the selection. This allows
the selection to act as a mask for the pasted buffer. Anywhere that
the selection mask is non-zero, the pasted buffer will show
through. The pasted buffer will be a new layer in the image which is
designated as the image floating selection. If the image has a
floating selection at the time of pasting, the old floating selection
will be anchored to it's drawable before the new floating selection is
added. This procedure returns the new floating layer. The resulting
floating selection will already be attached to the specified drawable,
and a subsequent call to floating_sel_attach is not needed.
Manish Singh's avatar
Manish Singh committed
181 182 183 184
HELP

    &std_pdb_misc;

185 186 187 188 189 190
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to paste to' },
        { name => 'paste_into', type => 'boolean',
	  desc => 'Clear selection, or paste behind it?' }
    );
Manish Singh's avatar
Manish Singh committed
191 192 193

    @outargs = (
	{ name  => 'floating_sel', type  => 'layer',
194
	  desc  => 'The new floating selection' }
Manish Singh's avatar
Manish Singh committed
195 196
    );

197 198 199
    %invoke = (
	code => <<CODE
{
200 201
  if (gimp->global_buffer &&
      gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
202
    {
203 204 205
      floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
                                      drawable, gimp->global_buffer,
                                      paste_into, -1, -1, -1, -1);
206

207
      if (! floating_sel)
208 209
        success = FALSE;
    }
210 211
  else
    success = FALSE;
212
}
213 214 215 216 217 218 219 220 221 222
CODE
    );
}

sub edit_paste_as_new {
    $blurb = 'Paste buffer to a new image.';

    $help = <<'HELP';
This procedure pastes a copy of the internal GIMP edit buffer to a new
image.  The GIMP edit buffer will be empty unless a call was
223
previously made to either gimp_edit_cut() or gimp_edit_copy(). This
224
procedure returns the new image or -1 if the edit buffer was empty.
225 226
HELP

227
    &mitch_pdb_misc('2005', '2.4');
228 229

    @outargs = (
230
	{ name => 'image', type => 'image',
231 232 233 234 235
	  desc => 'The new image' }
    );
    %invoke = (
	code => <<CODE
{
236
  if (gimp->global_buffer)
237 238
    {
      image = gimp_edit_paste_as_new (gimp, NULL, gimp->global_buffer);
239

240 241 242
      if (! image)
        success = FALSE;
    }
243
  else
244 245 246
    {
      image = NULL;
    }
247 248 249 250 251 252 253 254 255
}
CODE
    );
}

sub edit_named_cut {
    $blurb = 'Cut into a named buffer.';

    $help = <<'HELP';
256
This procedure works like gimp_edit_cut(), but additionally stores the
257 258
cut buffer into a named buffer that will stay available for later
pasting, regardless of any intermediate copy or cut operations.
259 260
HELP

261
    &mitch_pdb_misc('2005', '2.4');
262 263 264 265

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => "The drawable to cut from" },
266
        { name => 'buffer_name', type => 'string', non_empty => 1,
267 268 269
          desc => 'The name of the buffer to create' }
    );
    @outargs = (
270
	{ name => 'real_name', type => 'string',
271
	  desc => 'The real name given to the buffer, or NULL if the
272
                   cut failed' }
273 274 275 276 277
    );

    %invoke = (
	code => <<CODE
{
278
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
279
    {
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
      GimpImage *image    = gimp_item_get_image (GIMP_ITEM (drawable));
      GError    *my_error = NULL;

      real_name = (gchar *) gimp_edit_named_cut (image, buffer_name,
                                                 drawable, context, &my_error);

      if (real_name)
        {
          real_name = g_strdup (real_name);
        }
      else
        {
          gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                        "%s", my_error->message);
          g_clear_error (&my_error);
        }
296 297 298
    }
  else
    success = FALSE;
299 300 301 302 303 304 305 306 307
}
CODE
    );
}

sub edit_named_copy {
    $blurb = 'Copy into a named buffer.';

    $help = <<'HELP';
308
This procedure works like gimp_edit_copy(), but additionally stores the
309 310
copied buffer into a named buffer that will stay available for later
pasting, regardless of any intermediate copy or cut operations.
311 312
HELP

313
    &mitch_pdb_misc('2005', '2.4');
314 315 316 317

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => "The drawable to copy from" },
318
        { name => 'buffer_name', type => 'string', non_empty => 1,
319 320 321
          desc => 'The name of the buffer to create' }
    );
    @outargs = (
322
	{ name => 'real_name', type => 'string',
323
	  desc => 'The real name given to the buffer, or NULL if the
324
                   copy failed' }
325 326 327 328 329
    );

    %invoke = (
	code => <<CODE
{
330
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
331
    {
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
      GimpImage *image    = gimp_item_get_image (GIMP_ITEM (drawable));
      GError    *my_error = NULL;

      real_name = (gchar *) gimp_edit_named_copy (image, buffer_name,
                                                  drawable, context, &my_error);

      if (real_name)
        {
          real_name = g_strdup (real_name);
        }
      else
        {
          gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                        "%s", my_error->message);
          g_clear_error (&my_error);
        }
348 349 350
    }
  else
    success = FALSE;
351 352 353 354 355 356 357 358 359
}
CODE
    );
}

sub edit_named_copy_visible {
    $blurb = 'Copy from the projection into a named buffer.';

    $help = <<'HELP';
360
This procedure works like gimp_edit_copy_visible(), but additionally
361 362 363
stores the copied buffer into a named buffer that will stay available
for later pasting, regardless of any intermediate copy or cut
operations.
364 365
HELP

366
    &mitch_pdb_misc('2005', '2.4');
367 368 369 370

    @inargs = (
	{ name => 'image', type => 'image',
	  desc => "The image to copy from" },
371
        { name => 'buffer_name', type => 'string', non_empty => 1,
372 373
          desc => 'The name of the buffer to create' }
    );
374

375
    @outargs = (
376
	{ name => 'real_name', type => 'string',
377
	  desc => 'The real name given to the buffer, or NULL if the
378
                   copy failed' }
379 380 381 382 383
    );

    %invoke = (
	code => <<CODE
{
384 385
  GError *my_error = NULL;

386
  real_name = (gchar *) gimp_edit_named_copy_visible (image, buffer_name,
387
                                                      context, &my_error);
388

389
  if (real_name)
390 391 392
    {
      real_name = g_strdup (real_name);
    }
393
  else
394 395 396 397 398
    {
      gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                    "%s", my_error->message);
      g_clear_error (&my_error);
    }
399 400 401 402 403 404 405 406 407
}
CODE
    );
}

sub edit_named_paste {
    $blurb = 'Paste named buffer to the specified drawable.';

    $help = <<'HELP';
408
This procedure works like gimp_edit_paste() but pastes a named buffer
409
instead of the global buffer.
410 411
HELP

412
    &mitch_pdb_misc('2005', '2.4');
413 414 415 416 417 418 419 420 421 422 423 424

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to paste to' },
        { name => 'buffer_name', type => 'string',
          desc => 'The name of the buffer to paste' },
        { name => 'paste_into', type => 'boolean',
	  desc => 'Clear selection, or paste behind it?' }
    );

    @outargs = (
	{ name  => 'floating_sel', type  => 'layer',
425
	  desc  => 'The new floating selection' }
426 427 428 429 430
    );

    %invoke = (
	code => <<CODE
{
431
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
432

433
  if (buffer && gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
434
    {
435 436 437 438
      floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
                                      drawable, buffer,
                                      paste_into, -1, -1, -1, -1);
      if (! floating_sel)
439 440
        success = FALSE;
    }
441 442
  else
    success = FALSE;
443
}
444 445
CODE
    )
Manish Singh's avatar
Manish Singh committed
446 447
}

448 449 450 451
sub edit_named_paste_as_new {
    $blurb = 'Paste named buffer to a new image.';

    $help = <<'HELP';
452
This procedure works like gimp_edit_paste_as_new() but pastes a named buffer
453 454 455
instead of the global buffer.
HELP

456
    &mitch_pdb_misc('2005', '2.4');
457 458 459 460 461 462 463

    @inargs = (
        { name => 'buffer_name', type => 'string',
          desc => 'The name of the buffer to paste' }
    );

    @outargs = (
464
	{ name => 'image', type => 'image',
465 466 467 468 469 470
	  desc => 'The new image' }
    );

    %invoke = (
	code => <<CODE
{
471
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
472

473
  if (buffer)
474 475
    {
      image = gimp_edit_paste_as_new (gimp, NULL, buffer);
476

477 478 479
      if (! image)
        success = FALSE;
    }
480 481
  else
    success = FALSE;
482 483 484 485 486
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
487 488 489 490
sub edit_clear {
    $blurb = 'Clear selected area of drawable.';

    $help = <<'HELP';
491 492 493 494 495
This procedure clears the specified drawable. If the drawable has an
alpha channel, the cleared pixels will become transparent. If the
drawable does not have an alpha channel, cleared pixels will be set to
the background color. This procedure only affects regions within a
selection if there is a selection active.
Manish Singh's avatar
Manish Singh committed
496 497 498
HELP

    &std_pdb_misc;
499

500 501 502 503
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to clear from' }
    );
504 505 506 507

    %invoke = (
	code => <<CODE
{
508
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
509 510 511 512 513
    {
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));

      success = gimp_edit_clear (image, drawable, context);
    }
514 515
  else
    success = FALSE;
516 517 518
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
519 520 521 522 523 524
}

sub edit_fill {
    $blurb = 'Fill selected area of drawable.';

    $help = <<'HELP';
525 526 527 528 529 530 531
This procedure fills the specified drawable with the fill mode. If the
fill mode is foreground, the current foreground color is used. If the
fill mode is background, the current background color is used. Other
fill modes should not be used. This procedure only affects regions
within a selection if there is a selection active. If you want to fill
the whole drawable, regardless of the selection, use
gimp_drawable_fill().
Manish Singh's avatar
Manish Singh committed
532 533 534
HELP

    &std_pdb_misc;
535 536
    $author .= ' & Raphael Quinet';
    $date = '1995-2000';
537

538 539 540 541
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => "The drawable to fill to" },
	{ name => 'fill_type', type => 'enum GimpFillType',
542
	  desc => 'The type of fill' }
543
    );
544 545 546 547

    %invoke = (
	code => <<CODE
{
548
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
549 550 551 552 553 554
    {
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));

      success = gimp_edit_fill (image, drawable, context,
                                (GimpFillType) fill_type);
    }
555 556
  else
    success = FALSE;
557 558 559
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
560 561
}

562 563 564 565 566 567 568 569 570 571 572 573 574
sub edit_bucket_fill {
    $blurb = <<'BLURB';
Fill the area specified either by the current selection if there is one, or by
a seed fill starting at the specified coordinates.
BLURB

    $help = <<'HELP';
This tool requires information on the paint application mode, and the
fill mode, which can either be in the foreground color, or in the
currently active pattern. If there is no selection, a seed fill is
executed at the specified coordinates and extends outward in keeping
with the threshold parameter. If there is a selection in the target
image, the threshold, sample merged, x, and y arguments are unused. If
575
the sample_merged parameter is TRUE, the data of the composite
576 577 578 579 580 581 582 583 584 585
image will be used instead of that for the specified drawable.  This
is equivalent to sampling for colors after merging all visible
layers. In the case of merged sampling, the x and y coordinates are
relative to the image's origin; otherwise, they are relative to the
drawable's origin.
HELP

    &std_pdb_misc;

    @inargs = (
586 587
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
588
	{ name => 'fill_mode', type => 'enum GimpBucketFillMode',
589
	  desc => 'The type of fill' },
590
	{ name => paint_mode, type => 'enum GimpLayerModeEffects',
591
	  desc => 'The paint application mode' },
592
	{ name => 'opacity', type => '0 <= float <= 100',
593
	  desc => 'The opacity of the final bucket fill' },
594 595
	{ name => 'threshold', type => '0 <= float <= 255',
	  desc => "The threshold determines how extensive the seed fill will
596 597 598
		   be. It's value is specified in terms of intensity levels.
                   This parameter is only valid when there is no selection in
		   the specified image." },
599
	{ name => 'sample_merged', type => 'boolean',
600 601 602 603 604 605 606 607 608
	  desc => 'Use the composite image, not the drawable' },
	{ name => 'x', type => 'float',
	  desc => "The x coordinate of this bucket fill's application.
		   This parameter is only valid when there is no selection
		   in the specified image." },
	{ name => 'y', type => 'float',
	  desc => "The y coordinate of this bucket fill's application.
		   This parameter is only valid when there is no selection
		   in the specified image." }
609 610 611 612 613 614 615
    );

    %invoke = (
        headers => [ qw ("core/gimpdrawable-bucket-fill.h"
	                 "core/gimpchannel.h") ],
	code => <<'CODE'
{
616
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
617
    {
618
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
619
      gboolean   do_seed_fill;
620

621
      do_seed_fill = gimp_channel_is_empty (gimp_image_get_mask (image));
622

Michael Natterer's avatar
Michael Natterer committed
623 624 625 626 627 628 629
      success = gimp_drawable_bucket_fill (drawable, context, fill_mode,
                                           paint_mode, opacity / 100.0,
                                           do_seed_fill,
                                           FALSE /* don't fill transparent */,
                                           GIMP_SELECT_CRITERION_COMPOSITE,
	                                   threshold, sample_merged, x, y,
                                           error);
630
    }
631 632
  else
    success = FALSE;
633 634 635 636 637
}
CODE
    );
}

638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
sub edit_bucket_fill_full {
    $blurb = <<'BLURB';
Fill the area specified either by the current selection if there is one, or by
a seed fill starting at the specified coordinates.
BLURB

    $help = <<'HELP';
This tool requires information on the paint application mode, and the
fill mode, which can either be in the foreground color, or in the
currently active pattern. If there is no selection, a seed fill is
executed at the specified coordinates and extends outward in keeping
with the threshold parameter. If there is a selection in the target
image, the threshold, sample merged, x, and y arguments are unused. If
the sample_merged parameter is TRUE, the data of the composite
image will be used instead of that for the specified drawable.  This
is equivalent to sampling for colors after merging all visible
layers. In the case of merged sampling, the x and y coordinates are
relative to the image's origin; otherwise, they are relative to the
drawable's origin.
HELP

    &david_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
	{ name => 'fill_mode', type => 'enum GimpBucketFillMode',
	  desc => 'The type of fill' },
	{ name => paint_mode, type => 'enum GimpLayerModeEffects',
	  desc => 'The paint application mode' },
	{ name => 'opacity', type => '0 <= float <= 100',
	  desc => 'The opacity of the final bucket fill' },
	{ name => 'threshold', type => '0 <= float <= 255',
	  desc => "The threshold determines how extensive the seed fill will
		   be. It's value is specified in terms of intensity levels.
                   This parameter is only valid when there is no selection in
		   the specified image." },
	{ name => 'sample_merged', type => 'boolean',
	  desc => 'Use the composite image, not the drawable' },
	{ name => 'fill_transparent', type => 'boolean',
	  desc => "Whether to consider transparent pixels for filling.
	           If TRUE, transparency is considered as a unique fillable
		   color." },
	{ name => 'select_criterion', type => 'enum GimpSelectCriterion',
	  desc => "The criterion used to determine color similarity.
	           SELECT_CRITERION_COMPOSITE is the standard choice.
		   " },
	{ name => 'x', type => 'float',
	  desc => "The x coordinate of this bucket fill's application.
		   This parameter is only valid when there is no selection
		   in the specified image." },
	{ name => 'y', type => 'float',
	  desc => "The y coordinate of this bucket fill's application.
		   This parameter is only valid when there is no selection
		   in the specified image." }
    );

    %invoke = (
        headers => [ qw ("core/gimpdrawable-bucket-fill.h"
	                 "core/gimpchannel.h") ],
	code => <<'CODE'
{
700
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
701 702 703 704 705 706
    {
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
      gboolean   do_seed_fill;

      do_seed_fill = gimp_channel_is_empty (gimp_image_get_mask (image));

Michael Natterer's avatar
Michael Natterer committed
707 708 709 710 711 712 713
      success = gimp_drawable_bucket_fill (drawable, context, fill_mode,
                                           paint_mode, opacity / 100.0,
                                           do_seed_fill,
                                           fill_transparent,
                                           select_criterion,
                                           threshold, sample_merged, x, y,
                                           error);
714 715 716 717 718 719 720 721
    }
  else
    success = FALSE;
}
CODE
    );
}

722 723
sub edit_blend {
    $blurb = <<'BLURB';
724 725
Blend between the starting and ending coordinates with the specified
blend mode and gradient type.
726 727 728
BLURB

    $help = <<'HELP';
729 730 731 732
This tool requires information on the paint application mode, the
blend mode, and the gradient type. It creates the specified variety of
blend using the starting and ending coordinates as defined for each
gradient type.
733 734 735 736 737
HELP

    &std_pdb_misc;

    @inargs = (
738 739
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
740
        { name => 'blend_mode', type => 'enum GimpBlendMode',
741
	  desc => 'The type of blend' },
742
	{ name => 'paint_mode', type => 'enum GimpLayerModeEffects',
743
	  desc => 'The paint application mode' },
744
	{ name => 'gradient_type',  type => 'enum GimpGradientType',
745
	  desc => 'The type of gradient' },
746
	{ name => 'opacity', type => '0 <= float <= 100',
747
	  desc => 'The opacity of the final blend' },
748 749
	{ name => 'offset', type => '0 <= float',
	  desc => 'Offset relates to the starting and ending coordinates
750
		   specified for the blend. This parameter is mode dependent.' },
751
	{ name => 'repeat', type => 'enum GimpRepeatMode',
752
	  desc => 'Repeat mode' },
753
	{ name => 'reverse', type => 'boolean',
754
	  desc => 'Use the reverse gradient' },
755
	{ name => 'supersample', type => 'boolean',
756
	  desc => 'Do adaptive supersampling' },
757
	{ name => 'max_depth', type => '1 <= int32 <= 9', no_validate => 1,
758
	  desc => 'Maximum recursion levels for supersampling' },
759
	{ name => 'threshold', type => '0 <= float <= 4', no_validate => 1,
760
	  desc => 'Supersampling threshold' },
761
	{ name => 'dither', type => 'boolean',
762
	  desc => 'Use dithering to reduce banding' },
763 764 765 766 767 768 769 770 771 772 773 774 775 776
	{ name => 'x1', type => 'float',
	  desc => "The x coordinate of this blend's starting point" },
	{ name => 'y1', type => 'float',
	  desc => "The y coordinate of this blend's starting point" },
	{ name => 'x2', type => 'float',
	  desc => "The x coordinate of this blend's ending point" },
	{ name => 'y2', type => 'float',
	  desc => "The y coordinate of this blend's ending point" }
    );

    %invoke = (
        headers => [ qw("core/gimpdrawable-blend.h") ],
	code => <<'CODE'
{
777
  success = gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error);
778

779 780 781 782 783 784 785 786 787
  if (success && supersample)
    {
      if (max_depth < 1 || max_depth > 9)
        success = FALSE;

      if (threshold < 0.0 || threshold > 4.0)
        success = FALSE;
    }

788
  if (success)
789
    {
790
      if (progress)
791
        gimp_progress_start (progress, _("Blending"), FALSE);
792

793
      gimp_drawable_blend (drawable,
794
                           context,
795 796 797 798 799 800 801 802
                           blend_mode,
                           paint_mode,
                           gradient_type,
                           opacity / 100.0,
	                   offset, repeat, reverse,
                           supersample, max_depth,
                           threshold, dither,
                           x1, y1, x2, y2,
803 804 805 806
	                   progress);

      if (progress)
        gimp_progress_end (progress);
807 808 809 810 811 812
    }
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
813 814 815 816 817 818 819 820 821 822
sub edit_stroke {
    $blurb = 'Stroke the current selection';

    $help = <<'HELP';
This procedure strokes the current selection, painting along the selection
boundary with the active brush and foreground color. The paint is applied to
the specified drawable regardless of the active selection.
HELP

    &std_pdb_misc;
823

824 825 826 827
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to stroke to' }
    );
828 829

    %invoke = (
830
	headers => [ qw("core/gimpstrokeoptions.h") ],
831 832
	code => <<'CODE'
{
833
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error))
834
    {
835
      GimpImage         *image   = gimp_item_get_image (GIMP_ITEM (drawable));
836
      GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
837

838 839 840
      g_object_set (options,
                    "method", GIMP_STROKE_METHOD_PAINT_CORE,
                    NULL);
841

842
      success = gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
843 844
                                  drawable, context, options, TRUE, TRUE,
                                  progress, error);
845

846
      g_object_unref (options);
847
    }
848 849
  else
    success = FALSE;
850 851 852
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
853 854
}

855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
sub edit_stroke_vectors {
    $blurb = 'Stroke the specified vectors object';

    $help = <<'HELP';
This procedure strokes the specified vectors object, painting along the
path with the active brush and foreground color.
HELP

    &simon_pdb_misc('2006', '2.4');

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to stroke to' },
	{ name => 'vectors', type => 'vectors',
          desc => 'The vectors object' }
    );

    %invoke = (
873
	headers => [ qw("core/gimpstrokeoptions.h") ],
874 875
	code => <<'CODE'
{
876 877
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), error) &&
      gimp_pdb_item_is_attached (GIMP_ITEM (vectors), error))
878
    {
879
      GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
880

881 882 883
      g_object_set (options,
                    "method", GIMP_STROKE_METHOD_PAINT_CORE,
                    NULL);
884 885

      success = gimp_item_stroke (GIMP_ITEM (vectors),
886 887
                                  drawable, context, options, TRUE, TRUE,
                                  progress, error);
888

889
      g_object_unref (options);
890 891 892 893 894 895 896 897
    }
  else
    success = FALSE;
}
CODE
    );
}

898

899 900 901 902 903
@headers = qw(<string.h>
              "core/gimp.h"
              "core/gimp-edit.h"
              "core/gimpimage.h"
              "core/gimpprogress.h"
904
              "gimppdb-utils.h"
905
              "gimp-intl.h");
Michael Natterer's avatar
Michael Natterer committed
906

907 908
@procs = qw(edit_cut
            edit_copy edit_copy_visible
909
            edit_paste edit_paste_as_new
910 911
            edit_named_cut
            edit_named_copy edit_named_copy_visible
912
            edit_named_paste edit_named_paste_as_new
913 914 915 916 917 918 919
            edit_clear
            edit_fill
            edit_bucket_fill
            edit_bucket_fill_full
	    edit_blend
            edit_stroke
            edit_stroke_vectors);
920

921
%exports = (app => [@procs], lib => [@procs]);
Manish Singh's avatar
Manish Singh committed
922 923 924 925

$desc = 'Edit procedures';

1;