paint_tools.pdb 27.1 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
# 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>

Manish Singh's avatar
Manish Singh committed
20 21
sub stroke_arg () {
    { name => 'strokes', type => 'floatarray',
Manish Singh's avatar
Manish Singh committed
22
      desc => 'Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ...,
Manish Singh's avatar
Manish Singh committed
23
	       sn.x, sn.y }',
24
      array => { type => '2 <= int32',
Manish Singh's avatar
Manish Singh committed
25
		 desc => 'Number of stroke control points (count each
Manish Singh's avatar
Manish Singh committed
26
			  coordinate as 2 points)' } }
Manish Singh's avatar
Manish Singh committed
27 28 29 30 31
}

# The defs

sub airbrush {
32
    $blurb = <<'BLURB';
Manish Singh's avatar
Manish Singh committed
33 34 35 36 37 38 39 40
Paint in the current brush with varying pressure. Paint application is
time-dependent.
BLURB

    $help = <<'HELP';
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.
Manish Singh's avatar
Manish Singh committed
41
HELP
Manish Singh's avatar
Manish Singh committed
42 43 44

    &std_pdb_misc;

Manish Singh's avatar
Manish Singh committed
45
    @inargs = (
46 47 48
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
	{ name => 'pressure', type => '0 <= float <= 100',
49
	  desc => 'The pressure of the airbrush strokes' },
Manish Singh's avatar
Manish Singh committed
50
	&stroke_arg
Manish Singh's avatar
Manish Singh committed
51 52
    );

Manish Singh's avatar
Manish Singh committed
53
    %invoke = (
Manish Singh's avatar
Manish Singh committed
54
	code => <<'CODE'
55
{
56
  GimpPaintInfo *info = (GimpPaintInfo *)
57
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-airbrush");
58

59
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
60

61 62 63
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
64

65 66 67 68 69
      g_object_set (options,
                    "pressure", pressure,
                    NULL);

      success = paint_tools_stroke (gimp, context, options, drawable,
70 71 72
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
73
    }
74
}
Manish Singh's avatar
Manish Singh committed
75
CODE
Manish Singh's avatar
Manish Singh committed
76 77 78
    );
}

79
sub airbrush_default {
80
    $blurb = <<'BLURB';
81 82 83 84 85
Paint in the current brush with varying pressure. Paint application is
time-dependent.
BLURB

    $help = <<'HELP';
86
This tool simulates the use of an airbrush. It is similar to gimp_airbrush()
87
except that the pressure is derived from the airbrush tools options box.
88 89 90
It the option has not been set the default for the option will be used.
HELP

91
    &andy_pdb_misc('1999');
92 93

    @inargs = (
94 95
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
96 97 98 99 100
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
101
{
102
  GimpPaintInfo *info = (GimpPaintInfo *)
103
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-airbrush");
104

105 106 107 108 109
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
110

111
      success = paint_tools_stroke (gimp, context, options, drawable,
112 113 114
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
115
    }
116
}
117 118 119 120 121
CODE
    );
}


Manish Singh's avatar
Manish Singh committed
122
sub clone {
Manish Singh's avatar
Manish Singh committed
123
    $blurb = <<'BLURB';
Manish Singh's avatar
Manish Singh committed
124 125 126
Clone from the source to the dest drawable using the current brush
BLURB

Manish Singh's avatar
Manish Singh committed
127
    $help = <<'HELP';
128 129
This tool clones (copies) from the source drawable starting at the specified
source coordinates to the dest drawable. If the "clone_type" argument is set
Manish Singh's avatar
Manish Singh committed
130
to PATTERN-CLONE, then the current pattern is used as the source and the
Manish Singh's avatar
Manish Singh committed
131
"src_drawable" argument is ignored. Pattern cloning assumes a tileable
Manish Singh's avatar
Manish Singh committed
132 133 134 135 136 137 138 139 140 141
pattern and mods the sum of the src coordinates and subsequent stroke offsets
with the width and height of the pattern. For image cloning, if the sum of the
src coordinates and subsequent stroke offsets exceeds the extents of the src
drawable, then no paint is transferred. The clone tool is capable of
transforming between any image types including RGB->Indexed--although
converting from any type to indexed is significantly slower.
HELP

    &std_pdb_misc;

Manish Singh's avatar
Manish Singh committed
142
    @inargs = (
143 144
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
Manish Singh's avatar
Manish Singh committed
145 146
	{ name => 'src_drawable', type => 'drawable',
	  desc => 'The source drawable' },
147
	{ name => 'clone_type', type => 'enum GimpCloneType',
148
	  desc => 'The type of clone' },
Manish Singh's avatar
Manish Singh committed
149 150 151 152 153
	{ name => 'src_x', type => 'float',
	  desc => 'The x coordinate in the source image' },
	{ name => 'src_y', type => 'float',
	  desc => 'The y coordinate in the source image' },
	&stroke_arg
Manish Singh's avatar
Manish Singh committed
154 155
    );

Manish Singh's avatar
Manish Singh committed
156 157
    %invoke = (
	code => <<'CODE'
158
{
159
  GimpPaintInfo *info = (GimpPaintInfo *)
160
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-clone");
161

162
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
163

164 165 166 167 168 169 170
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);

      g_object_set (options,
                    "clone-type", clone_type,
                    NULL);
171

172
      success = paint_tools_stroke (gimp, context, options, drawable,
173
                                    num_strokes, strokes,
174
				    "undo-desc",    info->blurb,
175 176 177 178
                                    "src-drawable", src_drawable,
                                    "src-x",        src_x,
                                    "src-y",        src_y,
                                    NULL);
179
    }
180
}
Manish Singh's avatar
Manish Singh committed
181
CODE
Manish Singh's avatar
Manish Singh committed
182 183 184
    );
}

185 186 187 188 189 190
sub clone_default {
    $blurb = <<'BLURB';
Clone from the source to the dest drawable using the current brush
BLURB

    $help = <<'HELP';
191
This tool clones (copies) from the source drawable starting at the specified
192
source coordinates to the dest drawable. This function performs exactly
193
the same as the gimp_clone() function except that the tools arguments are
194 195 196 197
obtained from the clones option dialog. It this dialog has not been activated
then the dialogs default values will be used.
HELP

198
    &andy_pdb_misc('1999');
199 200

    @inargs = (
201 202
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
203 204 205 206 207
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
208
{
209
  GimpPaintInfo *info = (GimpPaintInfo *)
210
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-clone");
211

212 213 214 215 216
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
217

218
      success = paint_tools_stroke (gimp, context, options, drawable,
219 220 221
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
222
    }
223
}
224 225 226 227
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
228

229 230 231 232 233
sub convolve_default {
    $blurb = 'Convolve (Blur, Sharpen) using the current brush.';

    $help = <<'HELP';
This tool convolves the specified drawable with either a sharpening or blurring
234
kernel. This function performs exactly the same as the gimp_convolve()
235 236
function except that the tools arguments are obtained from the convolve
option dialog. It this dialog has not been activated then the dialogs
237 238 239
default values will be used.
HELP

240
    &andy_pdb_misc('1999');
241 242

    @inargs = (
243 244
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
245 246 247 248 249
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
250
{
251
  GimpPaintInfo *info = (GimpPaintInfo *)
252
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-convolve");
253

254
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
255

256 257 258 259 260
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);

      success = paint_tools_stroke (gimp, context, options, drawable,
261 262 263
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
264
    }
265
}
266 267 268 269
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
270 271 272 273 274 275 276 277 278 279 280 281 282
sub convolve {
    $blurb = 'Convolve (Blur, Sharpen) using the current brush.';

    $help = <<'HELP';
This tool convolves the specified drawable with either a sharpening or blurring
kernel. The pressure parameter controls the magnitude of the operation. Like
the paintbrush, this tool linearly interpolates between the specified stroke
coordinates.
HELP

    &std_pdb_misc;

    @inargs = (
283 284
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
Manish Singh's avatar
Manish Singh committed
285
	{ name => 'pressure', type => '0 <= float <= 100',
286
	  desc => 'The pressure' },
287
	{ name => 'convolve_type', type => 'enum GimpConvolveType',
288
	  desc => 'Convolve type' },
Manish Singh's avatar
Manish Singh committed
289 290 291 292
	&stroke_arg
    );

    %invoke = (
Manish Singh's avatar
Manish Singh committed
293
	code => <<'CODE'
294
{
295
  GimpPaintInfo *info = (GimpPaintInfo *)
296
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-convolve");
297

298 299 300 301 302
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
303

304 305 306 307
      g_object_set (options,
                    "type", convolve_type,
                    "rate", pressure,
                    NULL);
308

309
      success = paint_tools_stroke (gimp, context, options, drawable,
310 311 312
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
313
    }
314
}
Manish Singh's avatar
Manish Singh committed
315
CODE
Manish Singh's avatar
Manish Singh committed
316 317 318
    );
}

319 320 321 322 323
sub eraser_default {
    $blurb = 'Erase using the current brush.';

    $help = <<'HELP';
This tool erases using the current brush mask. This function performs exactly
324
the same as the gimp_eraser() function except that the tools arguments are
325 326 327 328
obtained from the eraser option dialog. It this dialog has not been activated
then the dialogs default values will be used.
HELP

329
    &andy_pdb_misc('1999');
330 331

    @inargs = (
332 333
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
334 335 336 337 338
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
339
{
340
  GimpPaintInfo *info = (GimpPaintInfo *)
341
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-eraser");
342

343
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
344

345 346 347 348 349
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);

      success = paint_tools_stroke (gimp, context, options, drawable,
350 351 352
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
353
    }
354
}
355 356 357 358
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372
sub eraser {
    $blurb = 'Erase using the current brush.';

    $help = <<'HELP';
This tool erases using the current brush mask. If the specified drawable
contains an alpha channel, then the erased pixels will become transparent.
Otherwise, the eraser tool replaces the contents of the drawable with the
background color. Like paintbrush, this tool linearly interpolates between the
specified stroke coordinates.
HELP

    &std_pdb_misc;

    @inargs = (
373 374
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
Manish Singh's avatar
Manish Singh committed
375
	&stroke_arg,
376
	{ name => 'hardness', type => 'enum GimpBrushApplicationMode',
377
	  desc => 'How to apply the brush' },
378
	{ name => 'method', type => 'enum GimpPaintApplicationMode',
379
	  desc => 'The paint method to use' }
Manish Singh's avatar
Manish Singh committed
380 381 382 383
    );

    %invoke = (
	code => <<'CODE'
384
{
385
  GimpPaintInfo *info = (GimpPaintInfo *)
386
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-eraser");
387

388 389 390 391 392
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
393

394 395 396 397
      g_object_set (options,
                    "application-mode", method,
                    "hard",             hardness,
                    NULL);
398

399
      success = paint_tools_stroke (gimp, context, options, drawable,
400 401 402
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
403
    }
404
}
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
CODE
    );
}

sub anti_eraser {
    $blurb = 'Anti-erase using the current brush.';

    $help = <<'HELP';
This tool anti-erases using the current brush mask. If the specified drawable
contains an alpha channel, then the erased pixels will become opaque.
Otherwise, the eraser tool replaces the contents of the drawable with the
background color. Like paintbrush, this tool linearly interpolates between the
specified stroke coordinates.
HELP

    &std_pdb_misc;

    @inargs = (
423 424
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
425
	&stroke_arg,
426
	{ name => 'hardness', type => 'enum GimpBrushApplicationMode',
427
	  desc => 'How to apply the brush' },
428
	{ name => 'method', type => 'enum GimpPaintApplicationMode',
429
	  desc => 'The paint method to use' }
430 431 432 433
    );

    %invoke = (
	code => <<'CODE'
434
{
435
  GimpPaintInfo *info = (GimpPaintInfo *)
436
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-eraser");
437

438
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
439

440 441 442
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
443

444 445 446 447 448 449 450
      g_object_set (options,
                    "application-mode", method,
                    "hard",             hardness,
                    "anti-erase",       TRUE,
                    NULL);

      success = paint_tools_stroke (gimp, context, options, drawable,
451 452 453
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
454
    }
455
}
Manish Singh's avatar
Manish Singh committed
456 457 458 459
CODE
    );
}

460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
sub heal {
    $blurb = <<'BLURB';
Heal from the source to the dest drawable using the current brush
BLURB

    $help = <<'HELP';
This tool heals the source drawable starting at the specified
source coordinates to the dest drawable. For image healing, if the sum of the
src coordinates and subsequent stroke offsets exceeds the extents of the src
drawable, then no paint is transferred. The healing tool is capable of
transforming between any image types except RGB->Indexed.
HELP

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

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
	{ name => 'src_drawable', type => 'drawable',
	  desc => 'The source drawable' },
	{ name => 'src_x', type => 'float',
	  desc => 'The x coordinate in the source image' },
	{ name => 'src_y', type => 'float',
	  desc => 'The y coordinate in the source image' },
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
{
  GimpPaintInfo *info = (GimpPaintInfo *)
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-heal");

  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);

      success = paint_tools_stroke (gimp, context, options, drawable,
                                    num_strokes, strokes,
501
				    "undo-desc",    info->blurb,
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
                                    "src-drawable", src_drawable,
                                    "src-x",        src_x,
                                    "src-y",        src_y,
                                    NULL);
    }
}
CODE
    );
}

sub heal_default {
    $blurb = <<'BLURB';
Heal from the source to the dest drawable using the current brush
BLURB

    $help = <<'HELP';
This tool heals from the source drawable starting at the specified
source coordinates to the dest drawable. This function performs exactly
the same as the gimp_heal() function except that the tools arguments are
obtained from the healing option dialog. It this dialog has not been activated
then the dialogs default values will be used.
HELP

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

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
{
  GimpPaintInfo *info = (GimpPaintInfo *)
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-heal");

  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);

      success = paint_tools_stroke (gimp, context, options, drawable,
546 547 548
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
549 550 551 552 553 554
    }
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
555
sub paintbrush {
Manish Singh's avatar
Manish Singh committed
556 557 558 559
    $blurb = <<'BLURB';
Paint in the current brush with optional fade out parameter and pull colors
from a gradient.
BLURB
Manish Singh's avatar
Manish Singh committed
560 561 562 563

    $help = <<'HELP';
This tool is the standard paintbrush. It draws linearly interpolated lines
through the specified stroke coordinates. It operates on the specified drawable
564
in the foreground color with the active brush. The 'fade-out' parameter is
Manish Singh's avatar
Manish Singh committed
565 566
measured in pixels and allows the brush stroke to linearly fall off. The
pressure is set to the maximum at the beginning of the stroke. As the distance
567 568 569
of the stroke nears the fade-out value, the pressure will approach zero. The
gradient-length is the distance to spread the gradient over. It is measured in
pixels. If the gradient-length is 0, no gradient is used.
Manish Singh's avatar
Manish Singh committed
570 571 572 573 574
HELP

    &std_pdb_misc;

    @inargs = (
575 576
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
577
	{ name => 'fade_out', type => '0 <= float',
578 579
	  desc => 'Fade out parameter' },
	  &stroke_arg,
580
	{ name => 'method', type => 'enum GimpPaintApplicationMode',
581
	  desc => 'The paint method to use' },
Manish Singh's avatar
Manish Singh committed
582
	{ name => 'gradient_length', type => '0 <= float',
583
	  desc => 'Length of gradient to draw' }
Manish Singh's avatar
Manish Singh committed
584 585 586 587
    );

    %invoke = (
	code => <<'CODE'
588
{
589
  GimpPaintInfo *info = (GimpPaintInfo *)
590
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-paintbrush");
591

592 593 594 595 596
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
597

598 599 600 601 602 603 604
      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);
605

606
      success = paint_tools_stroke (gimp, context, options, drawable,
607 608 609
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
610
    }
611
}
Manish Singh's avatar
Manish Singh committed
612 613 614 615
CODE
    );
}

616 617 618 619 620 621 622 623 624 625
sub paintbrush_default {
    $blurb = <<'BLURB';
Paint in the current brush. The fade out parameter and pull colors
from a gradient parameter are set from the paintbrush options dialog. If this
dialog has not been activated then the dialog defaults will be used.
BLURB

    $help = <<'HELP';
This tool is similar to the standard paintbrush. It draws linearly interpolated lines
through the specified stroke coordinates. It operates on the specified drawable
626
in the foreground color with the active brush. The 'fade-out' parameter is
627 628
measured in pixels and allows the brush stroke to linearly fall
off (value obtained from the option dialog). The pressure is set
629
to the maximum at the beginning of the stroke. As the distance
630 631
of the stroke nears the fade-out value, the pressure will approach zero. The
gradient-length (value obtained from the option dialog) is the
632
distance to spread the gradient over. It is measured in pixels. If
633
the gradient-length is 0, no gradient is used.
634 635
HELP

636
    &andy_pdb_misc('1999');
637 638

    @inargs = (
639 640
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
641 642 643 644 645
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
646
{
647
  GimpPaintInfo *info = (GimpPaintInfo *)
648
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-paintbrush");
649

650
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
651

652 653 654 655 656
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);

      success = paint_tools_stroke (gimp, context, options, drawable,
657 658 659
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
660
    }
661
}
662 663 664 665
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
666 667 668 669 670 671 672 673 674 675 676 677 678 679
sub pencil {
    $blurb = 'Paint in the current brush without sub-pixel sampling.';

    $help = <<'HELP';
This tool is the standard pencil. It draws linearly interpolated lines through
the specified stroke coordinates. It operates on the specified drawable in the
foreground color with the active brush. The brush mask is treated as though it
contains only black and white values. Any value below half is treated as black;
any above half, as white.
HELP

    &std_pdb_misc;

    @inargs = (
680 681
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
Manish Singh's avatar
Manish Singh committed
682 683 684 685
	&stroke_arg
    );

    %invoke = (
686
	code => <<'CODE'
687
{
688
  GimpPaintInfo *info = (GimpPaintInfo *)
689
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-pencil");
690

691 692 693 694 695
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
696

697
      success = paint_tools_stroke (gimp, context, options, drawable,
698 699 700
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
701
    }
702
}
703
CODE
Manish Singh's avatar
Manish Singh committed
704 705 706
    );
}

707
sub smudge {
708
    $blurb  = 'Smudge image with varying pressure.';
709 710

    $help = <<'HELP';
711
This tool simulates a smudge using the current brush. High pressure results
712 713 714 715 716 717
in a greater smudge of paint while low pressure results in a lesser smudge.
HELP

    &std_pdb_misc;

    @inargs = (
718 719
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
720
	 { name => 'pressure', type => '0 <= float <= 100',
721 722
	   desc => 'The pressure of the smudge strokes' },
	   &stroke_arg
723 724 725 726
    );

    %invoke = (
	code => <<'CODE'
727
{
728
  GimpPaintInfo *info = (GimpPaintInfo *)
729
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-smudge");
730

731
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
732

733 734 735
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
736

737 738 739 740 741
      g_object_set (options,
                    "rate", pressure,
                    NULL);

      success = paint_tools_stroke (gimp, context, options, drawable,
742 743 744
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
745
    }
746
}
747 748 749 750 751 752 753 754 755 756
CODE
    );
}

sub smudge_default {
    $blurb  = <<'BLURB';
Smudge image with varying pressure.
BLURB

    $help = <<'HELP';
757
This tool simulates a smudge using the current brush. It behaves exactly
758
the same as gimp_smudge() except that the pressure value is taken from the
759 760 761 762
smudge tool options or the options default if the tools option dialog has
not been activated.
HELP

763
    &andy_pdb_misc('1999');
764 765

    @inargs = (
766 767
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
768 769 770 771 772
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
773
{
774
  GimpPaintInfo *info = (GimpPaintInfo *)
775
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-smudge");
776

777 778 779 780 781
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
782

783
      success = paint_tools_stroke (gimp, context, options, drawable,
784 785 786
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
787
    }
788
}
789 790 791 792 793 794 795 796 797 798
CODE
    );
}

sub dodgeburn {
    $blurb  = <<'BLURB';
Dodgeburn image with varying exposure.
BLURB

    $help = <<'HELP';
799
Dodgeburn. More details here later.
800 801
HELP

802
    &andy_pdb_misc('1999');
803 804

    @inargs = (
805 806
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
807
	 { name => 'exposure', type => '0 <= float <= 100',
808
	   desc => 'The exposure of the  strokes' },
809
        { name => 'dodgeburn_type', type => 'enum GimpDodgeBurnType',
810
	  desc => 'The type either dodge or burn' },
811
        { name => 'dodgeburn_mode', type => 'enum GimpTransferMode',
812
	  desc => 'The mode' },
813 814 815 816 817
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
818
{
819
  GimpPaintInfo *info = (GimpPaintInfo *)
820
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-dodge-burn");
821

822
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));
823

824 825 826
  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
827

828 829 830 831 832 833 834
      g_object_set (options,
                    "type",     dodgeburn_type,
                    "mode",     dodgeburn_mode,
                    "exposure", exposure,
                    NULL);

      success = paint_tools_stroke (gimp, context, options, drawable,
835 836 837
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
838
    }
839
}
840 841 842 843 844 845
CODE
    );
}

sub dodgeburn_default {
    $blurb  = <<'BLURB';
846 847 848 849
Dodgeburn image with varying exposure. This is the same as the
gimp_dodgeburn() function except that the exposure, type and mode are
taken from the tools option dialog. If the dialog has not been
activated then the defaults as used by the dialog will be used.
850 851 852
BLURB

    $help = <<'HELP';
853
Dodgeburn. More details here later.
854 855 856 857 858
HELP

    &std_pdb_misc;

    @inargs = (
859 860
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
861 862 863 864 865
	&stroke_arg
    );

    %invoke = (
	code => <<'CODE'
866
{
867
  GimpPaintInfo *info = (GimpPaintInfo *)
868
    gimp_container_get_child_by_name (gimp->paint_info_list, "gimp-dodge-burn");
869

870 871 872 873 874
  success = (info && gimp_item_is_attached (GIMP_ITEM (drawable)));

  if (success)
    {
      GimpPaintOptions *options = gimp_paint_options_new (info);
875

876
      success = paint_tools_stroke (gimp, context, options, drawable,
877 878 879
                                    num_strokes, strokes,
				    "undo-desc", info->blurb,
				    NULL);
880
    }
881
}
882 883 884 885 886
CODE
    );
}


887 888 889 890 891 892 893 894 895 896
# Incomplete

sub ink {
    $blurb = 'Paint in the current brush without sub-pixel sampling.';

    $help = 'fixme fixme';

    &std_pdb_misc;

    @inargs = (
897 898
	{ name => 'drawable', type => 'drawable',
	  desc => 'The affected drawable' },
899 900 901 902
	&stroke_arg
    );
}

903 904

$extra{app}->{code} = <<'CODE';
905 906
static const GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;

907 908
static gboolean
paint_tools_stroke (Gimp             *gimp,
909
                    GimpContext      *context,
910
                    GimpPaintOptions *options,
911 912
                    GimpDrawable     *drawable,
                    gint              n_strokes,
913
                    const gdouble    *strokes,
914 915
                    const gchar      *first_property_name,
                    ...)
916 917
{
  GimpPaintCore *core;
918
  GimpCoords    *coords;
919
  gboolean       retval;
920
  gint           i;
921
  va_list        args;
922

923 924
  n_strokes /= 2;  /* #doubles -> #points */

925 926 927 928 929 930
  /*  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);
931
  gimp_context_set_parent (GIMP_CONTEXT (options), context);
932

933 934 935 936
  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);
937

938 939 940 941
  coords = g_new (GimpCoords, n_strokes);

  for (i = 0; i < n_strokes; i++)
    {
942 943 944
      coords[i]   = default_coords;
      coords[i].x = strokes[2 * i];
      coords[i].y = strokes[2 * i + 1];
945 946
    }

947
  retval = gimp_paint_core_stroke (core, drawable, options,
948 949 950
                                   coords, n_strokes);

  g_free (coords);
951

952
  g_object_unref (core);
953
  g_object_unref (options);
954 955 956 957

  return retval;
}
CODE
958

959 960

@headers = qw("libgimpmath/gimpmath.h"
961 962 963 964 965 966
              "core/gimp.h"
              "core/gimpcontainer.h"
              "core/gimppaintinfo.h"
              "paint/gimppaintcore.h"
              "paint/gimppaintcore-stroke.h"
              "paint/gimppaintoptions.h");
967

Michael Natterer's avatar
Michael Natterer committed
968 969 970 971 972
@procs = qw(airbrush airbrush_default
            clone clone_default
            convolve convolve_default
            dodgeburn dodgeburn_default
	    eraser eraser_default
973
            heal heal_default
Michael Natterer's avatar
Michael Natterer committed
974 975 976
            paintbrush paintbrush_default
	    pencil
            smudge smudge_default);
977

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

Michael Natterer's avatar
Michael Natterer committed
980
$desc = 'Paint Tool procedures';
Manish Singh's avatar
Manish Singh committed
981

Manish Singh's avatar
Manish Singh committed
982
1;