18
18
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
27
my ($op, $morehelp, @args) = @_;
29
$blurb = "\u$op the layer to the specified extents.";
31
my $ops = $op =~ /e$/ ? "${op}s" : "${op}es";
33
This procedure $ops the layer so that it's new width and height are equal to
34
the supplied parameters. $morehelp This operation only works if the layer has
35
been added to an image.
42
{ name => 'new_width', type => '0 < int32',
43
desc => 'New layer width: (%%desc%%)' },
44
{ name => 'new_height', type => '0 < int32',
45
desc => 'New layer height: (%%desc%%)' },
52
$args .= ', ' if $args;
57
$call = "gimp_item_scale_by_origin (GIMP_ITEM (layer), new_width, new_height, gimp->config->interpolation_type, NULL, $args);";
59
$call = "gimp_item_resize (GIMP_ITEM (layer), context, new_width, new_height, $args);";
62
$invoke{code} = <<"CODE";
64
success = gimp_item_is_attached (GIMP_ITEM (layer));
72
sub layer_get_prop_proc {
73
my ($prop, $type, $desc, $undo, $core_type, $core_var) = @_;
75
$core_type = 'layer' unless $core_type;
76
$core_var = 'layer' unless $core_var;
78
$blurb = "Get the $desc of the specified layer.";
80
$help = "This procedure returns the specified layer's $desc. ";
84
@inargs = ( &layer_arg );
87
{ name => $prop, type => $type,
88
desc => "The layer $desc", no_declare => 1 }
91
my $alias = "gimp_${core_type}_get_$prop ($core_var)";
92
$alias = "g_strdup ($alias)" if $type eq 'string';
93
$outargs[0]->{alias} .= "$alias";
96
sub layer_set_prop_proc {
97
my ($prop, $type, $desc, $undo, $core_type, $core_var) = @_;
99
$core_type = 'layer' unless $core_type;
100
$core_var = 'layer' unless $core_var;
102
$blurb = "Set the $desc of the specified layer.";
104
$help = "This procedure sets the specified layer's $desc. ";
110
{ name => $prop, type => $type,
111
desc => "The new layer $desc" }
114
if ($type =~ /float/) {
115
$inargs[1]->{desc} .= ' (%%desc%%)';
118
$invoke{code} = $undo ? "gimp_${core_type}_set_$prop ($core_var, $prop, TRUE);"
119
: "gimp_${core_type}_set_$prop ($core_var, $prop);";
122
sub layer_accessors {
123
my ($prop, $type, $desc, $setting, $undo, $extra, $core_type, $core_var) = @_;
125
$core_type = 'layer' unless $core_type;
126
$core_var = 'layer' unless $core_var;
128
my (@extra, %extra); my $once = 0;
130
my $change = "s/ ($desc)/'s \$1 setting/";
131
(my $common = "\n; foreach (\$blurb, \$help) { $change }") =~ s/'s//;
134
get => "$common \$outargs[0]->{desc} =~ $change;",
135
set => "$common \$inargs[1]->{desc} =~ $change;",
138
ref($extra) ? (@extra = @$extra) : (@extra = ($extra, $extra));
139
%extra = map { $once++ ? 'set' : 'get', $_ ? $_ : "" } @extra;
141
foreach (sort keys %extra) {
142
my $proc = "layer_${_}_$prop";
147
sub @{[ scalar caller ]}::$proc {
148
\&layer_${_}_prop_proc('$prop', '$type', '$desc', $undo,
149
'$core_type', '$core_var');
151
@{[ $setting ? $modify{$_} : "" ]}
158
21
$blurb = 'Create a new layer.';
161
24
This procedure creates a new layer with the specified width, height, and type.
162
25
Name, opacity, and mode are also supplied parameters. The new layer still needs
163
26
to be added to the image, as this is not automatic. Add the new layer with the
164
'gimp_image_add_layer' command. Other attributes such as layer mask modes, and
27
gimp_image_add_layer() command. Other attributes such as layer mask modes, and
165
28
offsets should be set with explicit procedure calls.
172
{ name => 'width', type => '0 < int32',
173
desc => 'The layer width: (%%desc%%)' },
174
{ name => 'height', type => '0 < int32',
175
desc => 'The layer height: (%%desc%%)' },
34
{ name => 'image', type => 'image',
35
desc => 'The image to which to add the layer' },
36
{ name => 'width', type => '1 <= int32',
37
desc => 'The layer width' },
38
{ name => 'height', type => '1 <= int32',
39
desc => 'The layer height' },
176
40
{ name => 'type', type => 'enum GimpImageType',
177
desc => 'The layer type: { %%desc%% }' },
41
desc => 'The layer type' },
178
42
{ name => 'name', type => 'string',
179
43
desc => 'The layer name', null_ok => 1 },
180
44
{ name => 'opacity', type => '0 <= float <= 100',
181
desc => 'The layer opacity: (%%desc%%)' },
45
desc => 'The layer opacity' },
182
46
{ name => 'mode', type => 'enum GimpLayerModeEffects',
183
desc => 'The layer combination mode: { %%desc%% }' }
47
desc => 'The layer combination mode' }
185
$inargs[0]->{desc} .= ' to which to add the layer';
188
51
{ name => 'layer', type => 'layer', wrap => 1,
189
desc => 'The newly created layer', init => 1 }
52
desc => 'The newly created layer' }
195
layer = gimp_layer_new (gimage,
58
layer = gimp_layer_new (image, width, height, type, name,
199
59
opacity / 100.0, mode);
200
success = (layer != NULL);
202
{ name => 'layer', type => 'layer',
203
desc => 'The layer from which to remove mask' },
316
204
{ name => 'mode', type => 'enum GimpMaskApplyMode',
317
desc => 'Removal mode: { %%desc%% }' }
205
desc => 'Removal mode' }
319
$inargs[0]->{desc} .= ' from which to remove mask';
321
%invoke = ( code => <<'CODE'
323
success = gimp_item_is_attached (GIMP_ITEM (layer));
211
if (gimp_item_is_attached (GIMP_ITEM (layer)))
326
212
gimp_layer_apply_mask (layer, mode, TRUE);
332
220
sub layer_scale {
333
my $arg = { name => 'local_origin', type => 'boolean',
334
desc => 'Use a local origin (as opposed to the image origin)' };
221
$blurb = 'Scale the layer to the specified extents.';
336
&layer_dim_proc('scale', <<'HELP', $arg);
337
The "local_origin" parameter specifies whether to scale from the center of the
338
layer, or from the image origin.
224
This procedure scales the layer so that its new width and height are
225
equal to the supplied parameters. The 'local-origin' parameter
226
specifies whether to scale from the center of the layer, or from the
227
image origin. This operation only works if the layer has been added to
234
{ name => 'layer', type => 'layer',
235
desc => 'The layer' },
236
{ name => 'new_width', type => '1 <= int32',
237
desc => 'New layer width' },
238
{ name => 'new_height', type => '1 <= int32',
239
desc => 'New layer height' },
240
{ name => 'local_origin', type => 'boolean',
241
desc => 'Use a local origin (as opposed to the image origin)' }
247
if (gimp_item_is_attached (GIMP_ITEM (layer)))
248
gimp_item_scale_by_origin (GIMP_ITEM (layer), new_width, new_height,
249
gimp->config->interpolation_type, NULL,
342
258
sub layer_resize {
345
push @args, { name => "off$_", type => 'int32',
346
desc => "$_ offset between upper left corner of old and
347
new layers: (old - new)" }
259
$blurb = 'Resize the layer to the specified extents.';
350
&layer_dim_proc('resize', <<'HELP', @args);
351
Offsets are also provided which describe the position of the previous layer's
262
This procedure resizes the layer so that its new width and height are
263
equal to the supplied parameters. Offsets are also provided which
264
describe the position of the previous layer's content. This operation
265
only works if the layer has been added to an image.
271
{ name => 'layer', type => 'layer',
272
desc => 'The layer' },
273
{ name => 'new_width', type => '1 <= int32',
274
desc => 'New layer width' },
275
{ name => 'new_height', type => '1 <= int32',
276
desc => 'New layer height' },
277
{ name => 'offx', type => 'int32',
278
desc => 'x offset between upper left corner of old and
279
new layers: (old - new)' },
280
{ name => 'offy', type => 'int32',
281
desc => 'y offset between upper left corner of old and
282
new layers: (old - new)' }
288
if (gimp_item_is_attached (GIMP_ITEM (layer)))
289
gimp_item_resize (GIMP_ITEM (layer), context,
290
new_width, new_height, offx, offy);
356
298
sub layer_resize_to_image_size {
573
&layer_accessors('preserve_trans', 'boolean', 'preserve transperancy', 1, 1);
575
&layer_accessors('apply_mask', 'boolean', 'apply mask', 0, 0,
576
[ <<'CODE1', <<'CODE2' ]);
578
If the value is non-zero, then the layer mask for this layer is currently being
579
composited with the layer's alpha channel.
583
This controls whether the layer's mask is currently affecting the alpha
584
channel. If there is no layer mask, this function will return an error.
588
&layer_accessors('show_mask', 'boolean', 'show mask', 0, 0,
589
[ <<'CODE1', <<'CODE2' ]);
591
If the value is non-zero, then the layer mask for this layer is currently being
592
shown instead of the layer.
596
This controls whether the layer or it's mask is visible. Non-zero values
597
indicate that the mask should be visible. If the layer has no mask, then this
598
function returns an error.
602
&layer_accessors('edit_mask', 'boolean', 'show mask', 0, 0,
603
[ <<'CODE1', <<'CODE2' ]);
605
If the value is non-zero, then the layer mask for this layer is currently
576
sub layer_get_lock_alpha {
577
$blurb = 'Get the lock alpha channel setting of the specified layer.';
580
This procedure returns the specified layer's lock alpha channel setting.
586
{ name => 'layer', type => 'layer',
587
desc => 'The layer' }
591
{ name => 'lock_alpha', type => 'boolean',
592
desc => 'The layer\'s lock alpha channel setting' }
598
lock_alpha = gimp_layer_get_lock_alpha (layer);
604
sub layer_set_lock_alpha {
605
$blurb = 'Set the lock alpha channel setting of the specified layer.';
608
This procedure sets the specified layer's lock alpha channel setting.
614
{ name => 'layer', type => 'layer',
615
desc => 'The layer' },
616
{ name => 'lock_alpha', type => 'boolean',
617
desc => 'The new layer\'s lock alpha channel setting' }
623
gimp_layer_set_lock_alpha (layer, lock_alpha, TRUE);
629
sub layer_get_apply_mask {
630
$blurb = 'Get the apply mask setting of the specified layer.';
633
This procedure returns the specified layer's apply mask setting. If
634
the value is TRUE, then the layer mask for this layer is currently
635
being composited with the layer's alpha channel.
641
{ name => 'layer', type => 'layer',
642
desc => 'The layer' }
646
{ name => 'apply_mask', type => 'boolean',
647
desc => 'The layer\'s apply mask setting' }
654
apply_mask = gimp_layer_mask_get_apply (layer->mask);
662
sub layer_set_apply_mask {
663
$blurb = 'Set the apply mask setting of the specified layer.';
666
This procedure sets the specified layer's apply mask setting. This
667
controls whether the layer's mask is currently affecting the alpha
668
channel. If there is no layer mask, this function will return an
675
{ name => 'layer', type => 'layer',
676
desc => 'The layer' },
677
{ name => 'apply_mask', type => 'boolean',
678
desc => 'The new layer\'s apply mask setting' }
685
gimp_layer_mask_set_apply (layer->mask, apply_mask, TRUE);
693
sub layer_get_show_mask {
694
$blurb = 'Get the show mask setting of the specified layer.';
697
This procedure returns the specified layer's show mask setting. This
698
controls whether the layer or its mask is visible. TRUE indicates
699
that the mask should be visible. If the layer has no mask,
700
then this function returns an error.
706
{ name => 'layer', type => 'layer',
707
desc => 'The layer' }
711
{ name => 'show_mask', type => 'boolean',
712
desc => 'The layer\'s show mask setting' }
719
show_mask = gimp_layer_mask_get_show (layer->mask);
727
sub layer_set_show_mask {
728
$blurb = 'Set the show mask setting of the specified layer.';
731
This procedure sets the specified layer's show mask setting. This
732
controls whether the layer's mask is currently affecting the alpha
733
channel. If there is no layer mask, this function will return an
740
{ name => 'layer', type => 'layer',
741
desc => 'The layer' },
742
{ name => 'show_mask', type => 'boolean',
743
desc => 'The new layer\'s show mask setting' }
750
gimp_layer_mask_set_show (layer->mask, show_mask, TRUE);
758
sub layer_get_edit_mask {
759
$blurb = 'Get the edit mask setting of the specified layer.';
762
This procedure returns the specified layer's edit mask setting. If
763
the value is TRUE, then the layer mask for this layer is currently
606
764
active, and not the layer.
610
This controls whether the layer or it's mask is currently active for editing.
611
If the specified layer has no layer mask, then this procedure will return an
770
{ name => 'layer', type => 'layer',
771
desc => 'The layer' }
775
{ name => 'edit_mask', type => 'boolean',
776
desc => 'The layer\'s edit mask setting' }
783
edit_mask = gimp_layer_mask_get_edit (layer->mask);
791
sub layer_set_edit_mask {
792
$blurb = 'Set the edit mask setting of the specified layer.';
795
This procedure sets the specified layer's edit mask setting. This
796
controls whether the layer or it's mask is currently active for
797
editing. If the specified layer has no layer mask, then this
798
procedure will return an error.
616
&layer_accessors('opacity', '0 <= float <= 100', 'opacity', 0, 1,
617
[ '$outargs[0]->{alias} =
618
"gimp_layer_get_opacity (layer) * 100.0"',
620
s%opacity, %opacity / 100.0, %' ]);
622
&layer_accessors('mode', 'enum GimpLayerModeEffects', 'combination mode', 0, 1);
624
@headers = qw("config/gimpcoreconfig.h" "core/gimp.h" "core/gimpimage-undo.h"
625
"core/gimpitem-linked.h" "pdb_glue.h" "gimp-intl.h");
627
unshift @procs, qw(layer_new layer_new_from_drawable layer_copy
629
layer_scale layer_resize layer_resize_to_image_size
630
layer_translate layer_set_offsets
631
layer_create_mask layer_get_mask layer_from_mask
632
layer_add_mask layer_remove_mask
633
layer_is_floating_sel);
804
{ name => 'layer', type => 'layer',
805
desc => 'The layer' },
806
{ name => 'edit_mask', type => 'boolean',
807
desc => 'The new layer\'s edit mask setting' }
814
gimp_layer_mask_set_edit (layer->mask, edit_mask);
822
sub layer_get_opacity {
823
$blurb = 'Get the opacity of the specified layer.';
824
$help = "This procedure returns the specified layer's opacity.";
829
{ name => 'layer', type => 'layer',
830
desc => 'The layer' }
834
{ name => 'opacity', type => '0 <= float <= 100',
835
desc => 'The layer opacity' }
841
opacity = gimp_layer_get_opacity (layer) * 100.0;
847
sub layer_set_opacity {
848
$blurb = 'Set the opacity of the specified layer.';
849
$help = "This procedure sets the specified layer's opacity.";
854
{ name => 'layer', type => 'layer',
855
desc => 'The layer' },
856
{ name => 'opacity', type => '0 <= float <= 100',
857
desc => 'The new layer opacity' }
863
gimp_layer_set_opacity (layer, opacity / 100.0, TRUE);
870
$blurb = 'Get the combination mode of the specified layer.';
871
$help = "This procedure returns the specified layer's combination mode.";
876
{ name => 'layer', type => 'layer',
877
desc => 'The layer' }
881
{ name => 'mode', type => 'enum GimpLayerModeEffects',
882
desc => 'The layer combination mode' }
888
mode = gimp_layer_get_mode (layer);
895
$blurb = 'Set the combination mode of the specified layer.';
896
$help = "This procedure sets the specified layer's combination mode.";
901
{ name => 'layer', type => 'layer',
902
desc => 'The layer' },
903
{ name => 'mode', type => 'enum GimpLayerModeEffects',
904
desc => 'The new layer combination mode' }
910
gimp_layer_set_mode (layer, mode, TRUE);
917
@headers = qw("config/gimpcoreconfig.h"
919
"core/gimpimage-undo.h"
920
"core/gimpitem-linked.h"
923
@procs = qw(layer_new layer_new_from_drawable layer_copy
925
layer_scale layer_resize layer_resize_to_image_size
926
layer_translate layer_set_offsets
927
layer_create_mask layer_get_mask layer_from_mask
928
layer_add_mask layer_remove_mask
929
layer_is_floating_sel
930
layer_get_lock_alpha layer_set_lock_alpha
931
layer_get_apply_mask layer_set_apply_mask
932
layer_get_show_mask layer_set_show_mask
933
layer_get_edit_mask layer_set_edit_mask
934
layer_get_opacity layer_set_opacity
935
layer_get_mode layer_set_mode);
634
937
%exports = (app => [@procs], lib => [@procs]);