gimpbrushlist.c 22.6 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* The GIMP -- an image manipulation program
 * 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
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17
18
19
20
21
22
23
24
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
25
#include <math.h>
Elliot Lee's avatar
Elliot Lee committed
26
#include "appenv.h"
27
#include "gimpbrushgenerated.h"
Elliot Lee's avatar
Elliot Lee committed
28
29
30
31
32
#include "brush_header.h"
#include "brush_select.h"
#include "buildmenu.h"
#include "colormaps.h"
#include "datafiles.h"
33
#include "devices.h"
Elliot Lee's avatar
Elliot Lee committed
34
35
36
#include "errors.h"
#include "general.h"
#include "gimprc.h"
37
#include "gimpsignal.h"
Elliot Lee's avatar
Elliot Lee committed
38
#include "menus.h"
39
#include "paint_core.h"
40
41
42
43
#include "gimplist.h"
#include "gimpbrush.h"
#include "gimplistP.h"
#include "gimpbrushlistP.h"
Elliot Lee's avatar
Elliot Lee committed
44
45
46


/*  global variables  */
47
48
GimpBrush     *active_brush = NULL;
GimpBrushList *brush_list   = NULL;
Elliot Lee's avatar
Elliot Lee committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62

double              opacity = 1.0;
int                 paint_mode = 0;


BrushSelectP        brush_select_dialog = NULL;


/*  static variables  */
static int          success;
static Argument    *return_args;
static int          have_default_brush = 0;

/*  static function prototypes  */
63
static void   create_default_brush   (void);
64
static gint   brush_compare_func     (gconstpointer, gconstpointer);
Elliot Lee's avatar
Elliot Lee committed
65

66
static void brush_load                    (char *filename);
67
68
69
70

/* class functions */
static GimpObjectClass* parent_class;

71
72
73
74
75
76
77
78
static void
gimp_brush_list_add_func(GimpList* list, gpointer val)
{
  list->list=g_slist_insert_sorted (list->list, val, brush_compare_func);
  GIMP_BRUSH_LIST(list)->num_brushes++;
}

static void
79
gimp_brush_list_remove_func(GimpList* list, gpointer val)
80
81
82
83
84
{
  list->list=g_slist_remove(list->list, val);
  GIMP_BRUSH_LIST(list)->num_brushes--;
}

85
86
static void
gimp_brush_list_class_init (GimpBrushListClass *klass)
Elliot Lee's avatar
Elliot Lee committed
87
{
88
  GimpListClass *gimp_list_class;
89
  
90
91
  gimp_list_class = GIMP_LIST_CLASS(klass);
  gimp_list_class->add = gimp_brush_list_add_func;
92
  gimp_list_class->remove = gimp_brush_list_remove_func;
93
  parent_class = gtk_type_class (gimp_list_get_type ());
94
}
Elliot Lee's avatar
Elliot Lee committed
95

96
97
98
99
100
void
gimp_brush_list_init(GimpBrushList *list)
{
  list->num_brushes = 0;
}
Elliot Lee's avatar
Elliot Lee committed
101

102
103
104
105
106
107
108
109
110
111
112
113
114
GtkType gimp_brush_list_get_type(void)
{
  static GtkType type;
  if(!type)
  {
    GtkTypeInfo info={
      "GimpBrushList",
      sizeof(GimpBrushList),
      sizeof(GimpBrushListClass),
      (GtkClassInitFunc)gimp_brush_list_class_init,
      (GtkObjectInitFunc)gimp_brush_list_init,
      NULL,
      NULL };
115
    type=gtk_type_unique(gimp_list_get_type(), &info);
116
117
118
  }
  return type;
}
Elliot Lee's avatar
Elliot Lee committed
119

120
121
122
123
GimpBrushList *
gimp_brush_list_new ()
{
  GimpBrushList *list=GIMP_BRUSH_LIST(gtk_type_new(gimp_brush_list_get_type()));
124
125
  GIMP_LIST(list)->type = GIMP_TYPE_BRUSH;
  GIMP_LIST(list)->weak = 0;
126
127
128
  
  return list;
}
Elliot Lee's avatar
Elliot Lee committed
129
130


131
132
133
134
135
136
137
/*  function declarations  */
void
brushes_init (int no_data)
{

  if (brush_list)
    brushes_free();
138
139
  else
    brush_list = gimp_brush_list_new();
140

141
  if (brush_path == NULL || (no_data))
142
    create_default_brush ();
143
  else
144
    datafiles_read_directories (brush_path,(datafile_loader_t)brush_load, 0);
145
}
Elliot Lee's avatar
Elliot Lee committed
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
static void
brush_load(char *filename)
{
  if (strcmp(&filename[strlen(filename) - 4], ".gbr") == 0)
  {
    gimp_brush_list_add(brush_list, gimp_brush_new(filename));
  }
  else if (strcmp(&filename[strlen(filename) - 4], ".vbr") == 0)
  {
    gimp_brush_list_add(brush_list,
			GIMP_BRUSH(gimp_brush_generated_load(filename)));
  }
}

161
static gint
162
brush_compare_func (gconstpointer first, gconstpointer second)
163
{
164
165
  return strcmp (((const GimpBrush *)first)->name, 
		 ((const GimpBrush *)second)->name);
166
167
}

Elliot Lee's avatar
Elliot Lee committed
168

169
170
171
void
brushes_free ()
{
172
173
174
175
176
  
  if (brush_list)
  {
    while (GIMP_LIST(brush_list)->list)
      gimp_brush_list_remove(brush_list, GIMP_LIST(brush_list)->list->data);
177
  }
Elliot Lee's avatar
Elliot Lee committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

  have_default_brush = 0;
}


void
brush_select_dialog_free ()
{
  if (brush_select_dialog)
    {
      brush_select_free (brush_select_dialog);
      brush_select_dialog = NULL;
    }
}


194
GimpBrush *
Elliot Lee's avatar
Elliot Lee committed
195
196
197
198
199
200
201
202
203
get_active_brush ()
{
  if (have_default_brush)
    {
      have_default_brush = 0;
      if (!active_brush)
	fatal_error ("Specified default brush not found!");
    }
  else if (! active_brush && brush_list)
204
    /* need a gimp_list_get_first() type function */
205
    select_brush((GimpBrush *) GIMP_LIST(brush_list)->list->data);
Elliot Lee's avatar
Elliot Lee committed
206
207
208
209
210

  return active_brush;
}


211
static GSList *
212
insert_brush_in_list (GSList *list, GimpBrush * brush)
Elliot Lee's avatar
Elliot Lee committed
213
{
214
  return g_slist_insert_sorted (list, brush, brush_compare_func);
Elliot Lee's avatar
Elliot Lee committed
215
216
217
218
219
}

static void
create_default_brush ()
{
220
221
222
  GimpBrushGenerated *brush;
  
  brush = gimp_brush_generated_new(5.0, .5, 0.0, 1.0);
Elliot Lee's avatar
Elliot Lee committed
223
224
225

  /*  Swap the brush to disk (if we're being stingy with memory) */
  if (stingy_memory_use)
226
    temp_buf_swap (GIMP_BRUSH(brush)->mask);
Elliot Lee's avatar
Elliot Lee committed
227
228

  /*  Make this the default, active brush  */
229
  select_brush(GIMP_BRUSH(brush));
Elliot Lee's avatar
Elliot Lee committed
230
231
232
233
234
  have_default_brush = 1;
}



235
236
237
238
239
int
gimp_brush_list_get_brush_index (GimpBrushList *brush_list,
				 GimpBrush *brush)
{
  /* fix me: make a gimp_list function that does this? */
240
  return g_slist_index (GIMP_LIST(brush_list)->list, brush);
241
242
}

243
GimpBrush *
244
gimp_brush_list_get_brush_by_index (GimpBrushList *brush_list, int index)
Elliot Lee's avatar
Elliot Lee committed
245
{
246
  GSList *list;
247
248
249
  GimpBrush * brush = NULL;
  /* fix me: make a gimp_list function that does this? */
  list = g_slist_nth (GIMP_LIST(brush_list)->list, index);
250
  if (list)
251
    brush = (GimpBrush *) list->data;
Elliot Lee's avatar
Elliot Lee committed
252

253
  return brush;
Elliot Lee's avatar
Elliot Lee committed
254
255
}

256
257
258
259
static void
gimp_brush_list_uniquefy_brush_name(GimpBrushList *brush_list,
				    GimpBrush *brush)
{
260
  GSList *list, *listb;
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  GimpBrush *brushb;
  int number = 1;
  char *newname;
  char *oldname;
  char *ext;
  g_return_if_fail(GIMP_IS_BRUSH_LIST(brush_list));
  g_return_if_fail(GIMP_IS_BRUSH(brush));
  list = GIMP_LIST(brush_list)->list;
  while (list)
  {
    brushb = GIMP_BRUSH(list->data);
    if (brush != brushb &&
	strcmp(gimp_brush_get_name(brush), gimp_brush_get_name(brushb)) == 0)
    { /* names conflict */
      oldname = gimp_brush_get_name(brush);
      newname = g_malloc(strlen(oldname)+10); /* if this aint enough 
						 yer screwed */
      strcpy (newname, oldname);
      if ((ext = strrchr(newname, '#')))
      {
	number = atoi(ext+1);
	if (&ext[(int)(log10(number) + 1)] != &newname[strlen(newname) - 1])
	{
	  number = 1;
	  ext = &newname[strlen(newname)];
	}
      }
      else
      {
	number = 1;
	ext = &newname[strlen(newname)];
      }
      sprintf(ext, "#%d", number+1);
294
295
296
297
298
299
300
301
302
303
304
305
306
      listb = GIMP_LIST(brush_list)->list;
      while (listb) /* make sure the new name is unique */
      {
	brushb = GIMP_BRUSH(listb->data);
	if (brush != brushb && strcmp(newname,
				      gimp_brush_get_name(brushb)) == 0)
	{
	  number++;
	  sprintf(ext, "#%d", number+1);
	  listb = GIMP_LIST(brush_list)->list;
	}
	listb = listb->next;
      }
307
308
      gimp_brush_set_name(brush, newname);
      g_free(newname);
309
310
311
312
313
314
315
      if (gimp_list_have(GIMP_LIST(brush_list), brush))
      { /* ought to have a better way than this to resort the brush */
	gtk_object_ref(GTK_OBJECT(brush));
	gimp_brush_list_remove(brush_list, brush);
	gimp_brush_list_add(brush_list, brush);
	gtk_object_unref(GTK_OBJECT(brush));
      }
316
317
318
319
320
321
322
323
324
325
326
      return;
    }
    list = list->next;
  }
}

static void brush_renamed(GimpBrush *brush, GimpBrushList *brush_list)
{
  gimp_brush_list_uniquefy_brush_name(brush_list, brush);
}

327
void
328
gimp_brush_list_add (GimpBrushList *brush_list, GimpBrush * brush)
329
{
330
  gimp_brush_list_uniquefy_brush_name(brush_list, brush);
331
  gimp_list_add(GIMP_LIST(brush_list), brush);
332
  gtk_object_sink(GTK_OBJECT(brush));
333
334
  gtk_signal_connect(GTK_OBJECT(brush), "rename",
		     (GtkSignalFunc)brush_renamed, brush_list);
335
}
Elliot Lee's avatar
Elliot Lee committed
336
337

void
338
339
gimp_brush_list_remove (GimpBrushList *brush_list, GimpBrush * brush)
{
340
  gtk_signal_disconnect_by_data(GTK_OBJECT(brush), brush_list);
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
  gimp_list_remove(GIMP_LIST(brush_list), brush);
}

int
gimp_brush_list_length (GimpBrushList *brush_list)
{
  g_return_val_if_fail(GIMP_IS_BRUSH_LIST(brush_list), 0);
  return (brush_list->num_brushes);
}

GimpBrush *
gimp_brush_list_get_brush(GimpBrushList *blist, char *name)
{
  GimpBrush *brushp;
  GSList *list;
  if (blist == NULL)
    return NULL;

  list = GIMP_LIST(brush_list)->list;

  while (list)
  {
    brushp = (GimpBrush *) list->data;

    if (!strcmp (brushp->name, name))
    {
      return brushp;
    }

    list = g_slist_next (list);
  }
  return NULL;
}

void
select_brush (GimpBrush * brush)
Elliot Lee's avatar
Elliot Lee committed
377
378
379
380
381
{
  /*  Make sure the active brush is swapped before we get a new one... */
  if (stingy_memory_use)
    temp_buf_swap (active_brush->mask);

382
383
384
  if (active_brush)
    gtk_object_unref(GTK_OBJECT(active_brush));

Elliot Lee's avatar
Elliot Lee committed
385
386
  /*  Set the active brush  */
  active_brush = brush;
387
388
  
  gtk_object_ref(GTK_OBJECT(active_brush));
Elliot Lee's avatar
Elliot Lee committed
389
390
391
392
393
394
395

  /*  Make sure the active brush is unswapped... */
  if (stingy_memory_use)
    temp_buf_unswap (brush->mask);

  /*  Keep up appearances in the brush dialog  */
  if (brush_select_dialog)
396
397
    brush_select_select (brush_select_dialog,
			 gimp_brush_list_get_brush_index(brush_list, brush));
398
399

  device_status_update (current_device);
Elliot Lee's avatar
Elliot Lee committed
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
}


void
create_brush_dialog ()
{
  if (!brush_select_dialog)
    {
      /*  Create the dialog...  */
      brush_select_dialog = brush_select_new ();
    }
  else
    {
      /*  Popup the dialog  */
      if (!GTK_WIDGET_VISIBLE (brush_select_dialog->shell))
	gtk_widget_show (brush_select_dialog->shell);
      else
	gdk_window_raise(brush_select_dialog->shell->window);
    }
  
}



/***********************/
/*  BRUSHES_GET_BRUSH  */

static Argument *
brushes_get_brush_invoker (Argument *args)
{
430
  GimpBrush * brushp;
Elliot Lee's avatar
Elliot Lee committed
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459

  success = (brushp = get_active_brush ()) != NULL;

  return_args = procedural_db_return_args (&brushes_get_brush_proc, success);

  if (success)
    {
      return_args[1].value.pdb_pointer = g_strdup (brushp->name);
      return_args[2].value.pdb_int = brushp->mask->width;
      return_args[3].value.pdb_int = brushp->mask->height;
      return_args[4].value.pdb_int = brushp->spacing;
    }

  return return_args;
}

static Argument *
brushes_refresh_brush_invoker (Argument *args)
{

  /* FIXME: I've hardcoded success to be 1, because brushes_init() is a 
   *        void function right now.  It'd be nice if it returned a value at 
   *        some future date, so we could tell if things blew up when reparsing
   *        the list (for whatever reason). 
   *                       - Seth "Yes, this is a kludge" Burgess
   *                         <sjburges@ou.edu>
   */

  success = TRUE ;
460
  brushes_init(FALSE);
Elliot Lee's avatar
Elliot Lee committed
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
501
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
  return procedural_db_return_args (&brushes_refresh_brush_proc, success);
}


/*  The procedure definition  */
ProcArg brushes_get_brush_out_args[] =
{
  { PDB_STRING,
    "name",
    "the brush name"
  },
  { PDB_INT32,
    "width",
    "the brush width"
  },
  { PDB_INT32,
    "height",
    "the brush height"
  },
  { PDB_INT32,
    "spacing",
    "the brush spacing: (% of MAX [width, height])"
  }
};

ProcRecord brushes_get_brush_proc =
{
  "gimp_brushes_get_brush",
  "Retrieve information about the currently active brush mask",
  "This procedure retrieves information about the currently active brush mask.  This includes the brush name, the width and height, and the brush spacing paramter.  All paint operations and stroke operations use this mask to control the application of paint to the image.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  0,
  NULL,

  /*  Output arguments  */
  4,
  brushes_get_brush_out_args,

  /*  Exec method  */
  { { brushes_get_brush_invoker } },
};

/* =========================================================== */
/* REFRESH BRUSHES                                             */
/* =========================================================== */

ProcRecord brushes_refresh_brush_proc =
{
  "gimp_brushes_refresh",
  "Refresh current brushes",
  "This procedure retrieves all brushes currently in the user's brush path "
  "and updates the brush dialog accordingly.", 
  "Seth Burgess<sjburges@ou.edu>",
  "Seth Burgess",
  "1997",
  PDB_INTERNAL,

  /*  Input arguments  */
  0,
  NULL,

  /*  Output arguments  */
  0,
  NULL,

  /*  Exec method  */
  { { brushes_refresh_brush_invoker } },
};

535
536
537
/* access functions */
double
gimp_brush_get_opacity ()
Elliot Lee's avatar
Elliot Lee committed
538
{
539
  return opacity;
Elliot Lee's avatar
Elliot Lee committed
540
541
}

542
543
int
gimp_brush_get_spacing ()
Elliot Lee's avatar
Elliot Lee committed
544
{
545
546
547
548
549
  if (active_brush)
    return active_brush->spacing;
  else
    return 0;
}
Elliot Lee's avatar
Elliot Lee committed
550

551
552
int
gimp_brush_get_paint_mode ()
Elliot Lee's avatar
Elliot Lee committed
553
{
554
555
  return paint_mode;
}
Elliot Lee's avatar
Elliot Lee committed
556

557
558
559
560
561
562
void
gimp_brush_set_opacity (opac)
     double opac;
{
  opacity = opac;
}
Elliot Lee's avatar
Elliot Lee committed
563

564
565
566
567
568
569
570
void
gimp_brush_set_spacing (spac)
     int spac;
{
  if (active_brush)
    active_brush->spacing = spac;
}
Elliot Lee's avatar
Elliot Lee committed
571

572
573
574
575
576
577
void
gimp_brush_set_paint_mode (pm)
     int pm;
{
  paint_mode = pm;
}
Elliot Lee's avatar
Elliot Lee committed
578

579
580
581
/****************************/
/* PDB Interface To Brushes */
/****************************/
Elliot Lee's avatar
Elliot Lee committed
582
583
584
585
586
587
588
589

/*************************/
/*  BRUSHES_GET_OPACITY  */

static Argument *
brushes_get_opacity_invoker (Argument *args)
{
  return_args = procedural_db_return_args (&brushes_get_opacity_proc, TRUE);
590
  return_args[1].value.pdb_float = gimp_brush_get_opacity () * 100.0;
Elliot Lee's avatar
Elliot Lee committed
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

  return return_args;
}

/*  The procedure definition  */
ProcArg brushes_get_opacity_out_args[] =
{
  { PDB_FLOAT,
    "opacity",
    "the brush opacity: 0 <= opacity <= 100"
  }
};

ProcRecord brushes_get_opacity_proc =
{
  "gimp_brushes_get_opacity",
  "Get the brush opacity",
  "This procedure returns the opacity setting for brushes.  This value is set globally and will remain the same even if the brush mask is changed.  The return value is a floating point number between 0 and 100.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  0,
  NULL,

  /*  Output arguments  */
  1,
  brushes_get_opacity_out_args,

  /*  Exec method  */
  { { brushes_get_opacity_invoker } },
};


/*************************/
/*  BRUSHES_SET_OPACITY  */

static Argument *
brushes_set_opacity_invoker (Argument *args)
{
  double opacity;

  opacity = args[0].value.pdb_float;
  success = (opacity >= 0.0 && opacity <= 100.0);

  if (success)
639
    gimp_brush_set_opacity (opacity / 100.0);
Elliot Lee's avatar
Elliot Lee committed
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

  return procedural_db_return_args (&brushes_set_opacity_proc, success);
}

/*  The procedure definition  */
ProcArg brushes_set_opacity_args[] =
{
  { PDB_FLOAT,
    "opacity",
    "the brush opacity: 0 <= opacity <= 100"
  }
};

ProcRecord brushes_set_opacity_proc =
{
  "gimp_brushes_set_opacity",
  "Set the brush opacity",
  "This procedure modifies the opacity setting for brushes.  This value is set globally and will remain the same even if the brush mask is changed.  The value should be a floating point number between 0 and 100.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  1,
  brushes_set_opacity_args,

  /*  Output arguments  */
  0,
  NULL,

  /*  Exec method  */
  { { brushes_set_opacity_invoker } },
};


/*************************/
/*  BRUSHES_GET_SPACING  */

static Argument *
brushes_get_spacing_invoker (Argument *args)
{
  return_args = procedural_db_return_args (&brushes_get_spacing_proc, TRUE);
683
  return_args[1].value.pdb_int = gimp_brush_get_spacing ();
Elliot Lee's avatar
Elliot Lee committed
684
685
686
687
688
689
690
691
692
693
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
722
723
724
725
726
727
728
729
730
731

  return return_args;
}

/*  The procedure definition  */
ProcArg brushes_get_spacing_out_args[] =
{
  { PDB_INT32,
    "spacing",
    "the brush spacing: 0 <= spacing <= 1000"
  }
};

ProcRecord brushes_get_spacing_proc =
{
  "gimp_brushes_get_spacing",
  "Get the brush spacing",
  "This procedure returns the spacing setting for brushes.  This value is set per brush and will change if a different brush is selected.  The return value is an integer between 0 and 1000 which represents percentage of the maximum of the width and height of the mask.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  0,
  NULL,

  /*  Output arguments  */
  1,
  brushes_get_spacing_out_args,

  /*  Exec method  */
  { { brushes_get_spacing_invoker } },
};


/*************************/
/*  BRUSHES_SET_SPACING  */

static Argument *
brushes_set_spacing_invoker (Argument *args)
{
  int spacing;

  spacing = args[0].value.pdb_int;
  success = (spacing >= 0 && spacing <= 1000);

  if (success)
732
    gimp_brush_set_spacing (spacing);
Elliot Lee's avatar
Elliot Lee committed
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775

  return procedural_db_return_args (&brushes_set_spacing_proc, success);
}

/*  The procedure definition  */
ProcArg brushes_set_spacing_args[] =
{
  { PDB_INT32,
    "spacing",
    "the brush spacing: 0 <= spacing <= 1000"
  }
};

ProcRecord brushes_set_spacing_proc =
{
  "gimp_brushes_set_spacing",
  "Set the brush spacing",
  "This procedure modifies the spacing setting for the current brush.  This value is set on a per-brush basis and will change if a different brush mask is selected.  The value should be a integer between 0 and 1000.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  1,
  brushes_set_spacing_args,

  /*  Output arguments  */
  0,
  NULL,

  /*  Exec method  */
  { { brushes_set_spacing_invoker } },
};


/****************************/
/*  BRUSHES_GET_PAINT_MODE  */

static Argument *
brushes_get_paint_mode_invoker (Argument *args)
{
  return_args = procedural_db_return_args (&brushes_get_paint_mode_proc, TRUE);
776
  return_args[1].value.pdb_int = gimp_brush_get_paint_mode ();
Elliot Lee's avatar
Elliot Lee committed
777
778
779
780
781
782
783
784
785

  return return_args;
}

/*  The procedure definition  */
ProcArg brushes_get_paint_mode_out_args[] =
{
  { PDB_INT32,
    "paint_mode",
Manish Singh's avatar
Manish Singh committed
786
    "the paint mode: { NORMAL (0), DISSOLVE (1), BEHIND (2), MULTIPLY/BURN (3), SCREEN (4), OVERLAY (5) DIFFERENCE (6), ADDITION (7), SUBTRACT (8), DARKEN-ONLY (9), LIGHTEN-ONLY (10), HUE (11), SATURATION (12), COLOR (13), VALUE (14), DIVIDE/DODGE (15) }"
Elliot Lee's avatar
Elliot Lee committed
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
  }
};

ProcRecord brushes_get_paint_mode_proc =
{
  "gimp_brushes_get_paint_mode",
  "Get the brush paint_mode",
  "This procedure returns the paint-mode setting for brushes.  This value is set globally and will not change if a different brush is selected.  The return value is an integer between 0 and 13 which corresponds to the values listed in the argument description.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  0,
  NULL,

  /*  Output arguments  */
  1,
  brushes_get_paint_mode_out_args,

  /*  Exec method  */
  { { brushes_get_paint_mode_invoker } },
};


/****************************/
/*  BRUSHES_SET_PAINT_MODE  */

static Argument *
brushes_set_paint_mode_invoker (Argument *args)
{
  int paint_mode;

  paint_mode = args[0].value.pdb_int;
  success = (paint_mode >= NORMAL_MODE && paint_mode <= VALUE_MODE);

  if (success)
825
    gimp_brush_set_paint_mode (paint_mode);
Elliot Lee's avatar
Elliot Lee committed
826
827
828
829
830
831
832
833
834

  return procedural_db_return_args (&brushes_set_paint_mode_proc, success);
}

/*  The procedure definition  */
ProcArg brushes_set_paint_mode_args[] =
{
  { PDB_INT32,
    "paint_mode",
Manish Singh's avatar
Manish Singh committed
835
    "the paint mode: { NORMAL (0), DISSOLVE (1), BEHIND (2), MULTIPLY/BURN (3), SCREEN (4), OVERLAY (5) DIFFERENCE (6), ADDITION (7), SUBTRACT (8), DARKEN-ONLY (9), LIGHTEN-ONLY (10), HUE (11), SATURATION (12), COLOR (13), VALUE (14), DIVIDE/DODGE (15) }"
Elliot Lee's avatar
Elliot Lee committed
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
  }
};

ProcRecord brushes_set_paint_mode_proc =
{
  "gimp_brushes_set_paint_mode",
  "Set the brush paint_mode",
  "This procedure modifies the paint_mode setting for the current brush.  This value is set globally and will not change if a different brush mask is selected.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  1,
  brushes_set_paint_mode_args,

  /*  Output arguments  */
  0,
  NULL,

  /*  Exec method  */
  { { brushes_set_paint_mode_invoker } },
};


862
863
864
865
866
867
868
869

/***********************/
/*  BRUSHES_SET_BRUSH  */


static Argument *
brushes_set_brush_invoker (Argument *args)
{
870
  GimpBrush * brushp;
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
  char *name;

  success = (name = (char *) args[0].value.pdb_pointer) != NULL;

  if (success)
  {
    brushp = gimp_brush_list_get_brush(brush_list, name);
    if (brushp)
      select_brush(brushp);
    else
      success = 0;
  }

  return procedural_db_return_args (&brushes_set_brush_proc, success);
}

/*  The procedure definition  */
ProcArg brushes_set_brush_args[] =
{
  { PDB_STRING,
    "name",
    "the brush name"
  }
};

ProcRecord brushes_set_brush_proc =
{
  "gimp_brushes_set_brush",
  "Set the specified brush as the active brush",
  "This procedure allows the active brush mask to be set by specifying its name.  The name is simply a string which corresponds to one of the names of the installed brushes.  If there is no matching brush found, this procedure will return an error.  Otherwise, the specified brush becomes active and will be used in all subsequent paint operations.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  1,
  brushes_set_brush_args,

  /*  Output arguments  */
  0,
  NULL,

  /*  Exec method  */
  { { brushes_set_brush_invoker } },
};




Elliot Lee's avatar
Elliot Lee committed
921
922
923
924
925
926
/******************/
/*  BRUSHES_LIST  */

static Argument *
brushes_list_invoker (Argument *args)
{
927
  GimpBrush * brushp;
928
  GSList *list;
Elliot Lee's avatar
Elliot Lee committed
929
930
931
  char **brushes;
  int i;

932
  brushes = (char **) g_malloc (sizeof (char *) * brush_list->num_brushes);
Elliot Lee's avatar
Elliot Lee committed
933

934
  success = (list = GIMP_LIST(brush_list)->list) != NULL;
Elliot Lee's avatar
Elliot Lee committed
935
936
937
938
  i = 0;

  while (list)
    {
939
      brushp = (GimpBrush *) list->data;
Elliot Lee's avatar
Elliot Lee committed
940
941

      brushes[i++] = g_strdup (brushp->name);
942
      list = g_slist_next (list);
Elliot Lee's avatar
Elliot Lee committed
943
944
945
946
947
948
    }

  return_args = procedural_db_return_args (&brushes_list_proc, success);

  if (success)
    {
949
      return_args[1].value.pdb_int = brush_list->num_brushes;
Elliot Lee's avatar
Elliot Lee committed
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
      return_args[2].value.pdb_pointer = brushes;
    }

  return return_args;
}

/*  The procedure definition  */
ProcArg brushes_list_out_args[] =
{
  { PDB_INT32,
    "num_brushes",
    "the number of brushes in the brush list"
  },
  { PDB_STRINGARRAY,
    "brush_list",
    "the list of brush names"
  }
};

ProcRecord brushes_list_proc =
{
  "gimp_brushes_list",
  "Retrieve a complete listing of the available brushes",
  "This procedure returns a complete listing of available GIMP brushes.  Each name returned can be used as input to the 'gimp_brushes_set_brush'",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,

  /*  Input arguments  */
  0,
  NULL,

  /*  Output arguments  */
  2,
  brushes_list_out_args,

  /*  Exec method  */
  { { brushes_list_invoker } },
};