edit.pdb 32.3 KB
Newer Older
1
# GIMP - The GNU Image Manipulation Program
Manish Singh's avatar
Manish Singh committed
2
3
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

4
# This program is free software: you can redistribute it and/or modify
Manish Singh's avatar
Manish Singh committed
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
Manish Singh's avatar
Manish Singh committed
7
8
9
10
11
12
13
14
# (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
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Manish Singh's avatar
Manish Singh committed
16
17
18
19
20
21
22

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

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

    $help = <<'HELP';
23
24
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
25
GIMP edit buffer. It can subsequently be retrieved using the
26
gimp_edit_paste() command. If there is no selection, then the
27
specified drawable will be removed and its contents stored in the
28
29
30
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
31
32
33
HELP

    &std_pdb_misc;
34
35
36
37
38
39
40

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

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

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

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

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

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

    $help = <<'HELP';
77
78
79
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
80
gimp_edit_paste() command.  If there is no selection, then the
81
specified drawable's contents will be stored in the internal GIMP edit
82
83
84
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
85
86
87
HELP

    &std_pdb_misc;
88
89
90
91
92
93
94

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

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

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

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

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

125
126
127
128
129
130
131
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
132
gimp_edit_paste() command. If there is no selection, then the
133
134
135
projection's contents will be stored in the internal GIMP edit buffer.
HELP

136
    &mitch_pdb_misc('2004', '2.2');
137
138
139
140
141

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

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

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

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

  if (! non_empty)
    {
157
158
159
      gimp_message_literal (gimp,
                            G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                            my_error->message);
160
161
      g_clear_error (&my_error);
    }
162
163
164
165
166
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
167
168
169
170
sub edit_paste {
    $blurb = 'Paste buffer to the specified drawable.';

    $help = <<'HELP';
171
172
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
173
was previously made to either gimp_edit_cut() or gimp_edit_copy(). The
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
181
will be anchored to its drawable before the new floating selection is
182
183
184
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
185
186
187
188
HELP

    &std_pdb_misc;

189
190
191
192
193
194
    @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
195
196
197

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

201
202
203
    %invoke = (
	code => <<CODE
{
204
  GimpObject *paste = gimp_get_clipboard_object (gimp);
205

206
  if (paste &&
207
208
      gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
209
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
210
    {
211
      floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
212
                                      drawable, paste,
213
214
215
216
                                      paste_into ?
                                      GIMP_PASTE_TYPE_FLOATING_INTO :
                                      GIMP_PASTE_TYPE_FLOATING,
                                      -1, -1, -1, -1);
217

218
      if (! floating_sel)
219
220
        success = FALSE;
    }
221
222
  else
    success = FALSE;
223
}
224
225
226
227
CODE
    );
}

228
sub edit_paste_as_new_image {
229
230
231
232
233
    $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
234
previously made to either gimp_edit_cut() or gimp_edit_copy(). This
235
procedure returns the new image or -1 if the edit buffer was empty.
236
237
HELP

238
    &mitch_pdb_misc('2005', '2.10');
239
240

    @outargs = (
241
	{ name => 'image', type => 'image',
242
243
244
245
246
	  desc => 'The new image' }
    );
    %invoke = (
	code => <<CODE
{
247
  GimpObject *paste = gimp_get_clipboard_object (gimp);
248

249
  if (paste)
250
    {
251
      image = gimp_edit_paste_as_new_image (gimp, paste);
252

253
254
255
256
257
258
259
260
261
262
263
264
      if (! image)
        success = FALSE;
    }
}
CODE
    );
}

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

    $help = <<'HELP';
265
This procedure works like gimp_edit_cut(), but additionally stores the
266
267
cut buffer into a named buffer that will stay available for later
pasting, regardless of any intermediate copy or cut operations.
268
269
HELP

270
    &mitch_pdb_misc('2005', '2.4');
271
272
273
274

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => "The drawable to cut from" },
275
        { name => 'buffer_name', type => 'string', non_empty => 1,
276
277
          desc => 'The name of the buffer to create' }
    );
278

279
    @outargs = (
280
	{ name => 'real_name', type => 'string',
281
	  desc => 'The real name given to the buffer, or NULL if the
282
                   cut failed' }
283
284
285
286
287
    );

    %invoke = (
	code => <<CODE
{
288
289
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
290
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
291
    {
292
293
294
295
296
297
298
299
300
301
302
303
      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
        {
304
305
306
          gimp_message_literal (gimp,
                                G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                                my_error->message);
307
308
          g_clear_error (&my_error);
        }
309
310
311
    }
  else
    success = FALSE;
312
313
314
315
316
317
318
319
320
}
CODE
    );
}

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

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

326
    &mitch_pdb_misc('2005', '2.4');
327
328
329
330

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => "The drawable to copy from" },
331
        { name => 'buffer_name', type => 'string', non_empty => 1,
332
333
          desc => 'The name of the buffer to create' }
    );
334

335
    @outargs = (
336
	{ name => 'real_name', type => 'string',
337
	  desc => 'The real name given to the buffer, or NULL if the
338
                   copy failed' }
339
340
341
342
343
    );

    %invoke = (
	code => <<CODE
{
344
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, 0, error))
345
    {
346
347
348
349
350
351
352
353
354
355
356
357
      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
        {
358
359
360
          gimp_message_literal (gimp,
                                G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                                my_error->message);
361
362
          g_clear_error (&my_error);
        }
363
364
365
    }
  else
    success = FALSE;
366
367
368
369
370
371
372
373
374
}
CODE
    );
}

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

    $help = <<'HELP';
375
This procedure works like gimp_edit_copy_visible(), but additionally
376
377
378
stores the copied buffer into a named buffer that will stay available
for later pasting, regardless of any intermediate copy or cut
operations.
379
380
HELP

381
    &mitch_pdb_misc('2005', '2.4');
382
383
384
385

    @inargs = (
	{ name => 'image', type => 'image',
	  desc => "The image to copy from" },
386
        { name => 'buffer_name', type => 'string', non_empty => 1,
387
388
          desc => 'The name of the buffer to create' }
    );
389

390
    @outargs = (
391
	{ name => 'real_name', type => 'string',
392
	  desc => 'The real name given to the buffer, or NULL if the
393
                   copy failed' }
394
395
396
397
398
    );

    %invoke = (
	code => <<CODE
{
399
400
  GError *my_error = NULL;

401
  real_name = (gchar *) gimp_edit_named_copy_visible (image, buffer_name,
402
                                                      context, &my_error);
403

404
  if (real_name)
405
406
407
    {
      real_name = g_strdup (real_name);
    }
408
  else
409
    {
410
411
412
      gimp_message_literal (gimp,
                            G_OBJECT (progress), GIMP_MESSAGE_WARNING,
                            my_error->message);
413
414
      g_clear_error (&my_error);
    }
415
416
417
418
419
420
421
422
423
}
CODE
    );
}

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

    $help = <<'HELP';
424
This procedure works like gimp_edit_paste() but pastes a named buffer
425
instead of the global buffer.
426
427
HELP

428
    &mitch_pdb_misc('2005', '2.4');
429
430
431
432
433
434
435
436
437
438
439
440

    @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',
441
	  desc  => 'The new floating selection' }
442
443
444
445
446
    );

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

449
  if (buffer &&
450
451
      gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
452
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
453
    {
454
      floating_sel = gimp_edit_paste (gimp_item_get_image (GIMP_ITEM (drawable)),
455
456
457
458
459
                                      drawable, GIMP_OBJECT (buffer),
                                      paste_into ?
                                      GIMP_PASTE_TYPE_FLOATING_INTO :
                                      GIMP_PASTE_TYPE_FLOATING,
                                      -1, -1, -1, -1);
460
      if (! floating_sel)
461
462
        success = FALSE;
    }
463
464
  else
    success = FALSE;
465
}
466
467
CODE
    )
Manish Singh's avatar
Manish Singh committed
468
469
}

470
sub edit_named_paste_as_new_image {
471
472
473
    $blurb = 'Paste named buffer to a new image.';

    $help = <<'HELP';
474
475
This procedure works like gimp_edit_paste_as_new_image() but pastes a
named buffer instead of the global buffer.
476
477
HELP

478
    &mitch_pdb_misc('2005', '2.10');
479
480
481
482
483
484
485

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

    @outargs = (
486
	{ name => 'image', type => 'image',
487
488
489
490
491
492
	  desc => 'The new image' }
    );

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

495
  if (buffer)
496
    {
497
      image = gimp_edit_paste_as_new_image (gimp, GIMP_OBJECT (buffer));
498

499
500
501
      if (! image)
        success = FALSE;
    }
502
503
  else
    success = FALSE;
504
505
506
507
508
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
509
510
511
512
sub edit_clear {
    $blurb = 'Clear selected area of drawable.';

    $help = <<'HELP';
513
514
515
516
517
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
518
519
520
HELP

    &std_pdb_misc;
521

522
523
524
525
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to clear from' }
    );
526
527
528
529

    %invoke = (
	code => <<CODE
{
530
531
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
532
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
533
534
535
    {
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));

536
      gimp_edit_clear (image, drawable, context);
537
    }
538
539
  else
    success = FALSE;
540
541
542
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
543
544
545
546
547
548
}

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

    $help = <<'HELP';
549
550
551
552
553
554
555
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
556
557
558
HELP

    &std_pdb_misc;
559
560
    $author .= ' & Raphael Quinet';
    $date = '1995-2000';
561

562
563
564
565
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => "The drawable to fill to" },
	{ name => 'fill_type', type => 'enum GimpFillType',
566
	  desc => 'The type of fill' }
567
    );
568
569
570
571

    %invoke = (
	code => <<CODE
{
572
573
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
574
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
575
    {
576
      GimpImage       *image   = gimp_item_get_image (GIMP_ITEM (drawable));
577
      GimpFillOptions *options = gimp_fill_options_new (gimp, NULL, FALSE);
578

579
580
581
582
583
584
585
      if (gimp_fill_options_set_by_fill_type (options, context,
                                              fill_type, error))
        {
          gimp_edit_fill (image, drawable, options, NULL);
        }
      else
        success = FALSE;
586
587

      g_object_unref (options);
588
    }
589
590
  else
    success = FALSE;
591
592
593
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
594
595
}

596
597
598
599
600
601
602
603
604
605
606
607
608
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
609
the sample_merged parameter is TRUE, the data of the composite
610
611
612
613
614
615
616
617
618
619
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 = (
620
621
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
622
	{ name => 'fill_mode', type => 'enum GimpBucketFillMode',
623
	  desc => 'The type of fill' },
624
	{ name => paint_mode, type => 'enum GimpLayerMode',
625
          default => 'GIMP_LAYER_MODE_NORMAL',
626
	  desc => 'The paint application mode' },
627
	{ name => 'opacity', type => '0 <= float <= 100',
628
	  desc => 'The opacity of the final bucket fill' },
629
630
	{ name => 'threshold', type => '0 <= float <= 255',
	  desc => "The threshold determines how extensive the seed fill will
631
632
633
		   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." },
634
	{ name => 'sample_merged', type => 'boolean',
635
636
637
638
639
640
641
642
643
	  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." }
644
645
646
647
648
649
650
    );

    %invoke = (
        headers => [ qw ("core/gimpdrawable-bucket-fill.h"
	                 "core/gimpchannel.h") ],
	code => <<'CODE'
{
651
652
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
653
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
654
    {
655
      GimpImage       *image   = gimp_item_get_image (GIMP_ITEM (drawable));
656
      GimpFillOptions *options = gimp_fill_options_new (gimp, NULL, FALSE);
657

658
659
      if (gimp_fill_options_set_by_fill_mode (options, context,
                                              fill_mode, error))
660
        {
661
662
          if (paint_mode == GIMP_LAYER_MODE_OVERLAY_LEGACY)
            paint_mode = GIMP_LAYER_MODE_SOFTLIGHT_LEGACY;
663

664
665
          gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
          gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
666

667
          if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
668
            {
669
              gimp_edit_fill (image, drawable, options, NULL);
670
            }
671
672
673
674
675
676
677
678
679
680
          else
            {
              gimp_drawable_bucket_fill (drawable, options,
                                         FALSE /* don't fill transparent */,
                                         GIMP_SELECT_CRITERION_COMPOSITE,
                                         threshold / 255.0,
                                         sample_merged,
                                         FALSE /* no diagonal neighbors */,
                                         x, y);
           }
681
682
        }
      else
683
        success = FALSE;
684

685
      g_object_unref (options);
686
    }
687
688
  else
    success = FALSE;
689
690
691
692
693
}
CODE
    );
}

694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
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' },
722
	{ name => paint_mode, type => 'enum GimpLayerMode',
723
          default => 'GIMP_LAYER_MODE_NORMAL',
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
	  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'
{
757
758
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
759
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
760
    {
761
      GimpImage       *image   = gimp_item_get_image (GIMP_ITEM (drawable));
762
      GimpFillOptions *options = gimp_fill_options_new (gimp, NULL, FALSE);
763

764
765
      if (gimp_fill_options_set_by_fill_mode (options, context,
                                              fill_mode, error))
766
        {
767
768
          if (paint_mode == GIMP_LAYER_MODE_OVERLAY_LEGACY)
            paint_mode = GIMP_LAYER_MODE_SOFTLIGHT_LEGACY;
769

770
771
          gimp_context_set_opacity (GIMP_CONTEXT (options), opacity / 100.0);
          gimp_context_set_paint_mode (GIMP_CONTEXT (options), paint_mode);
772

773
          if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
774
            {
775
              gimp_edit_fill (image, drawable, options, NULL);
776
            }
777
778
779
780
781
782
783
784
785
786
          else
            {
              gimp_drawable_bucket_fill (drawable, options,
                                         fill_transparent,
                                         select_criterion,
                                         threshold / 255.0,
                                         sample_merged,
                                         FALSE /* no diagonal neighbors */,
                                         x, y);
           }
787
788
        }
      else
789
        success = FALSE;
790

791
      g_object_unref (options);
792
793
794
795
796
797
798
799
    }
  else
    success = FALSE;
}
CODE
    );
}

800
801
sub edit_blend {
    $blurb = <<'BLURB';
802
803
Blend between the starting and ending coordinates with the specified
blend mode and gradient type.
804
805
806
BLURB

    $help = <<'HELP';
807
808
809
810
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.
811
812
813
814
815
HELP

    &std_pdb_misc;

    @inargs = (
816
817
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
818
        { name => 'blend_mode', type => 'enum GimpBlendMode',
819
	  desc => 'The type of blend' },
820
	{ name => 'paint_mode', type => 'enum GimpLayerMode',
821
          default => 'GIMP_LAYER_MODE_NORMAL',
822
	  desc => 'The paint application mode' },
823
	{ name => 'gradient_type',  type => 'enum GimpGradientType',
824
	  desc => 'The type of gradient' },
825
	{ name => 'opacity', type => '0 <= float <= 100',
826
	  desc => 'The opacity of the final blend' },
827
828
	{ name => 'offset', type => '0 <= float',
	  desc => 'Offset relates to the starting and ending coordinates
829
		   specified for the blend. This parameter is mode dependent.' },
830
	{ name => 'repeat', type => 'enum GimpRepeatMode',
831
	  desc => 'Repeat mode' },
832
	{ name => 'reverse', type => 'boolean',
833
	  desc => 'Use the reverse gradient' },
834
	{ name => 'supersample', type => 'boolean',
835
	  desc => 'Do adaptive supersampling' },
836
	{ name => 'max_depth', type => '1 <= int32 <= 9', no_validate => 1,
837
	  desc => 'Maximum recursion levels for supersampling' },
838
	{ name => 'threshold', type => '0 <= float <= 4', no_validate => 1,
839
	  desc => 'Supersampling threshold' },
840
	{ name => 'dither', type => 'boolean',
841
	  desc => 'Use dithering to reduce banding' },
842
843
844
845
846
847
848
849
850
851
852
	{ 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 = (
853
        headers => [ qw("core/gimp-gradients.h" "core/gimpdrawable-blend.h") ],
854
855
	code => <<'CODE'
{
856
857
  success = (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                        GIMP_PDB_ITEM_CONTENT, error) &&
858
             gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error));
859

860
861
862
863
864
865
866
867
868
  if (success && supersample)
    {
      if (max_depth < 1 || max_depth > 9)
        success = FALSE;

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

869
  if (success)
870
    {
871
872
      GimpGradient *gradient;

873
874
      if (paint_mode == GIMP_LAYER_MODE_OVERLAY_LEGACY)
        paint_mode = GIMP_LAYER_MODE_SOFTLIGHT_LEGACY;
875

876
      if (progress)
877
        gimp_progress_start (progress, FALSE, _("Blending"));
878

879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
      switch (blend_mode)
        {
        case GIMP_BLEND_FG_BG_RGB:
          gradient = gimp_gradients_get_fg_bg_rgb (context->gimp);
          break;

        case GIMP_BLEND_FG_BG_HSV:
          gradient = gimp_gradients_get_fg_bg_hsv_cw (context->gimp);
          break;

        case GIMP_BLEND_FG_TRANSPARENT:
          gradient = gimp_gradients_get_fg_transparent (context->gimp);
          break;

        case GIMP_BLEND_CUSTOM:
	default:
          gradient = gimp_context_get_gradient (context);
          break;
        }

899
      gimp_drawable_blend (drawable,
900
                           context,
901
                           gradient,
902
                           GIMP_PDB_CONTEXT (context)->distance_metric,
903
904
905
906
907
908
909
                           paint_mode,
                           gradient_type,
                           opacity / 100.0,
	                   offset, repeat, reverse,
                           supersample, max_depth,
                           threshold, dither,
                           x1, y1, x2, y2,
910
911
912
913
	                   progress);

      if (progress)
        gimp_progress_end (progress);
914
915
916
917
918
919
    }
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
920
921
922
923
924
925
926
927
928
929
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;
930

931
932
933
934
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to stroke to' }
    );
935
936

    %invoke = (
937
	headers => [ qw("core/gimpstrokeoptions.h") ],
938
939
	code => <<'CODE'
{
940
941
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
942
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
943
    {
944
      GimpImage         *image = gimp_item_get_image (GIMP_ITEM (drawable));
945
      GimpStrokeOptions *options;
946
      GimpPaintOptions  *paint_options;
947

948
      options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
949

950
951
952
953
      paint_options =
        gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
      paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));

954
      success = gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
955
956
                                  drawable, context, options, paint_options,
                                  TRUE, progress, error);
957

958
      g_object_unref (paint_options);
959
    }
960
961
  else
    success = FALSE;
962
963
964
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
965
966
}

967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
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 = (
985
	headers => [ qw("core/gimpstrokeoptions.h") ],
986
987
	code => <<'CODE'
{
988
989
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
990
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
991
      gimp_pdb_item_is_attached (GIMP_ITEM (vectors),
992
993
                                 gimp_item_get_image (GIMP_ITEM (drawable)),
                                 0, error))
994
    {
995
996
      GimpStrokeOptions *options;
      GimpPaintOptions  *paint_options;
997

998
      options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
999

1000
1001
1002
1003
      paint_options =
        gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
      paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));

1004
      success = gimp_item_stroke (GIMP_ITEM (vectors),
1005
1006
                                  drawable, context, options, paint_options,
                                  TRUE, progress, error);
1007

1008
      g_object_unref (paint_options);
1009
1010
1011
1012
1013
1014
1015
1016
    }
  else
    success = FALSE;
}
CODE
    );
}

1017

1018
@headers = qw("libgimpconfig/gimpconfig.h"
1019
1020
              "core/gimp.h"
              "core/gimp-edit.h"
1021
              "core/gimpbuffer.h"
1022
1023
              "core/gimpimage.h"
              "core/gimpprogress.h"
1024
              "gimppdb-utils.h"
1025
              "gimppdbcontext.h"
1026
              "gimp-intl.h");
Michael Natterer's avatar
Michael Natterer committed
1027

1028
@procs = qw(edit_cut
1029
1030
1031
1032
            edit_copy
            edit_copy_visible
            edit_paste
            edit_paste_as_new_image
1033
            edit_named_cut
1034
1035
1036
1037
            edit_named_copy
            edit_named_copy_visible
            edit_named_paste
            edit_named_paste_as_new_image
1038
1039
1040
1041
1042
1043
1044
            edit_clear
            edit_fill
            edit_bucket_fill
            edit_bucket_fill_full
	    edit_blend
            edit_stroke
            edit_stroke_vectors);
1045

1046
%exports = (app => [@procs], lib => [@procs]);
Manish Singh's avatar
Manish Singh committed
1047
1048

$desc = 'Edit procedures';
1049
1050
1051
$doc_title = 'gimpedit';
$doc_short_desc = 'Edit menu functions (cut, copy, paste, clear, etc.)';
$doc_long_desc = 'Edit menu functions (cut, copy, paste, clear, etc.)';
Manish Singh's avatar
Manish Singh committed
1052
1053

1;