brushes_cmds.c 16.4 KB
Newer Older
1
/* The GIMP -- an image manipulation program
Manish Singh's avatar
Manish Singh committed
2
 * Copyright (C) 1995-2000 Spencer Kimball and Peter Mattis
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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.
 */

/* NOTE: This file is autogenerated by pdbgen.pl. */

21
#include "config.h"
22 23

#include <string.h>
24

25 26
#include <gtk/gtk.h>

27
#include "apptypes.h"
28 29
#include "procedural_db.h"

30
#include "gimpbrush.h"
31
#include "gimpbrushlist.h"
32
#include "gimpcontext.h"
33
#include "gimplist.h"
34
#include "temp_buf.h"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

static ProcRecord brushes_refresh_proc;
static ProcRecord brushes_get_brush_proc;
static ProcRecord brushes_set_brush_proc;
static ProcRecord brushes_get_opacity_proc;
static ProcRecord brushes_set_opacity_proc;
static ProcRecord brushes_get_spacing_proc;
static ProcRecord brushes_set_spacing_proc;
static ProcRecord brushes_get_paint_mode_proc;
static ProcRecord brushes_set_paint_mode_proc;
static ProcRecord brushes_list_proc;
static ProcRecord brushes_get_brush_data_proc;

void
register_brushes_procs (void)
{
  procedural_db_register (&brushes_refresh_proc);
  procedural_db_register (&brushes_get_brush_proc);
  procedural_db_register (&brushes_set_brush_proc);
  procedural_db_register (&brushes_get_opacity_proc);
  procedural_db_register (&brushes_set_opacity_proc);
  procedural_db_register (&brushes_get_spacing_proc);
  procedural_db_register (&brushes_set_spacing_proc);
  procedural_db_register (&brushes_get_paint_mode_proc);
  procedural_db_register (&brushes_set_paint_mode_proc);
  procedural_db_register (&brushes_list_proc);
  procedural_db_register (&brushes_get_brush_data_proc);
}

static Argument *
brushes_refresh_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@gimp.org>
   */

  brushes_init (FALSE);

  return procedural_db_return_args (&brushes_refresh_proc, TRUE);
}

static ProcRecord brushes_refresh_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",
  "Seth Burgess",
  "1997",
  PDB_INTERNAL,
  0,
  NULL,
  0,
  NULL,
  { { brushes_refresh_invoker } }
};

static Argument *
brushes_get_brush_invoker (Argument *args)
{
  gboolean success = TRUE;
  Argument *return_args;
101
  GimpBrush *brush;
102

103
  success = (brush = gimp_context_get_brush (NULL)) != NULL;
104 105 106 107 108

  return_args = procedural_db_return_args (&brushes_get_brush_proc, success);

  if (success)
    {
109 110 111 112
      return_args[1].value.pdb_pointer = g_strdup (brush->name);
      return_args[2].value.pdb_int = brush->mask->width;
      return_args[3].value.pdb_int = brush->mask->height;
      return_args[4].value.pdb_int = brush->spacing;
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    }

  return return_args;
}

static ProcArg brushes_get_brush_outargs[] =
{
  {
    PDB_STRING,
    "name",
    "The brush name"
  },
  {
    PDB_INT32,
    "width",
    "The brush width"
  },
  {
    PDB_INT32,
    "height",
    "The brush height"
  },
  {
    PDB_INT32,
    "spacing",
    "The brush spacing: 0 <= spacing <= 1000"
  }
};

static 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,
  0,
  NULL,
  4,
  brushes_get_brush_outargs,
  { { brushes_get_brush_invoker } }
};

static Argument *
brushes_set_brush_invoker (Argument *args)
{
  gboolean success = TRUE;
  gchar *name;
163
  GimpBrush *brush;
164 165 166 167 168 169 170

  name = (gchar *) args[0].value.pdb_pointer;
  if (name == NULL)
    success = FALSE;

  if (success)
    {
171 172 173 174
      brush = gimp_brush_list_get_brush (brush_list, name);
    
      if (brush)
	gimp_context_set_brush (NULL, brush);
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
      else
	success = FALSE;
    }

  return procedural_db_return_args (&brushes_set_brush_proc, success);
}

static ProcArg brushes_set_brush_inargs[] =
{
  {
    PDB_STRING,
    "name",
    "The brush name"
  }
};

static 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,
  1,
  brushes_set_brush_inargs,
  0,
  NULL,
  { { brushes_set_brush_invoker } }
};

static Argument *
brushes_get_opacity_invoker (Argument *args)
{
  Argument *return_args;

  return_args = procedural_db_return_args (&brushes_get_opacity_proc, TRUE);
213
  return_args[1].value.pdb_float = gimp_context_get_opacity (NULL) * 100.0;
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

  return return_args;
}

static ProcArg brushes_get_opacity_outargs[] =
{
  {
    PDB_FLOAT,
    "opacity",
    "The brush opacity: 0 <= opacity <= 100"
  }
};

static 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,
  0,
  NULL,
  1,
  brushes_get_opacity_outargs,
  { { brushes_get_opacity_invoker } }
};

static Argument *
brushes_set_opacity_invoker (Argument *args)
{
  gboolean success = TRUE;
  gdouble opacity;

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

  if (success)
254
    gimp_context_set_opacity (NULL, opacity / 100.0);
255 256 257 258 259 260 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

  return procedural_db_return_args (&brushes_set_opacity_proc, success);
}

static ProcArg brushes_set_opacity_inargs[] =
{
  {
    PDB_FLOAT,
    "opacity",
    "The brush opacity: 0 <= opacity <= 100"
  }
};

static 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,
  1,
  brushes_set_opacity_inargs,
  0,
  NULL,
  { { brushes_set_opacity_invoker } }
};

static Argument *
brushes_get_spacing_invoker (Argument *args)
{
  Argument *return_args;

  return_args = procedural_db_return_args (&brushes_get_spacing_proc, TRUE);
290
  return_args[1].value.pdb_int = gimp_brush_get_spacing (gimp_context_get_brush (NULL));
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

  return return_args;
}

static ProcArg brushes_get_spacing_outargs[] =
{
  {
    PDB_INT32,
    "spacing",
    "The brush spacing: 0 <= spacing <= 1000"
  }
};

static 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,
  0,
  NULL,
  1,
  brushes_get_spacing_outargs,
  { { brushes_get_spacing_invoker } }
};

static Argument *
brushes_set_spacing_invoker (Argument *args)
{
  gboolean success = TRUE;
  gint32 spacing;

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

  if (success)
331
    gimp_brush_set_spacing (gimp_context_get_brush (NULL), spacing);
332 333 334 335 336 337 338 339 340 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

  return procedural_db_return_args (&brushes_set_spacing_proc, success);
}

static ProcArg brushes_set_spacing_inargs[] =
{
  {
    PDB_INT32,
    "spacing",
    "The brush spacing: 0 <= spacing <= 1000"
  }
};

static 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,
  1,
  brushes_set_spacing_inargs,
  0,
  NULL,
  { { brushes_set_spacing_invoker } }
};

static Argument *
brushes_get_paint_mode_invoker (Argument *args)
{
  Argument *return_args;

  return_args = procedural_db_return_args (&brushes_get_paint_mode_proc, TRUE);
367
  return_args[1].value.pdb_int = gimp_context_get_paint_mode (NULL);
368 369 370 371 372 373 374 375 376

  return return_args;
}

static ProcArg brushes_get_paint_mode_outargs[] =
{
  {
    PDB_INT32,
    "paint_mode",
377
    "The paint mode: { NORMAL_MODE (0), DISSOLVE_MODE (1), BEHIND_MODE (2), MULTIPLY_MODE (3), SCREEN_MODE (4), OVERLAY_MODE (5), DIFFERENCE_MODE (6), ADDITION_MODE (7), SUBTRACT_MODE (8), DARKEN_ONLY_MODE (9), LIGHTEN_ONLY_MODE (10), HUE_MODE (11), SATURATION_MODE (12), COLOR_MODE (13), VALUE_MODE (14), DIVIDE_MODE (15), DODGE_MODE (16), BURN_MODE (17), HARDLIGHT_MODE (18) }"
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
  }
};

static 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 which corresponds to the values listed in the argument description.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  0,
  NULL,
  1,
  brushes_get_paint_mode_outargs,
  { { brushes_get_paint_mode_invoker } }
};

static Argument *
brushes_set_paint_mode_invoker (Argument *args)
{
  gboolean success = TRUE;
  gint32 paint_mode;

  paint_mode = args[0].value.pdb_int;
404
  if (paint_mode < NORMAL_MODE || paint_mode > HARDLIGHT_MODE)
405 406 407
    success = FALSE;

  if (success)
408
    gimp_context_set_paint_mode (NULL, paint_mode);
409 410 411 412 413 414 415 416 417

  return procedural_db_return_args (&brushes_set_paint_mode_proc, success);
}

static ProcArg brushes_set_paint_mode_inargs[] =
{
  {
    PDB_INT32,
    "paint_mode",
418
    "The paint mode: { NORMAL_MODE (0), DISSOLVE_MODE (1), BEHIND_MODE (2), MULTIPLY_MODE (3), SCREEN_MODE (4), OVERLAY_MODE (5), DIFFERENCE_MODE (6), ADDITION_MODE (7), SUBTRACT_MODE (8), DARKEN_ONLY_MODE (9), LIGHTEN_ONLY_MODE (10), HUE_MODE (11), SATURATION_MODE (12), COLOR_MODE (13), VALUE_MODE (14), DIVIDE_MODE (15), DODGE_MODE (16), BURN_MODE (17), HARDLIGHT_MODE (18) }"
419 420 421 422 423 424 425 426 427 428 429 430 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 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 501 502 503 504
  }
};

static 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,
  1,
  brushes_set_paint_mode_inargs,
  0,
  NULL,
  { { brushes_set_paint_mode_invoker } }
};

static Argument *
brushes_list_invoker (Argument *args)
{
  gboolean success = TRUE;
  Argument *return_args;
  gchar **brushes;
  GSList *list = NULL;
  int i = 0;

  brushes = g_new (char *, brush_list->num_brushes);

  success = (list = GIMP_LIST (brush_list)->list) != NULL;

  while (list)
    {
      brushes[i++] = g_strdup (((GimpBrush *) list->data)->name);
      list = list->next;
    }

  return_args = procedural_db_return_args (&brushes_list_proc, success);

  if (success)
    {
      return_args[1].value.pdb_int = brush_list->num_brushes;
      return_args[2].value.pdb_pointer = brushes;
    }

  return return_args;
}

static ProcArg brushes_list_outargs[] =
{
  {
    PDB_INT32,
    "num_brushes",
    "The number of brushes in the brush list"
  },
  {
    PDB_STRINGARRAY,
    "brush_list",
    "The list of brush names"
  }
};

static 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,
  0,
  NULL,
  2,
  brushes_list_outargs,
  { { brushes_list_invoker } }
};

static Argument *
brushes_get_brush_data_invoker (Argument *args)
{
  gboolean success = TRUE;
  Argument *return_args;
  gchar *name;
  gint32 length = 0;
505
  guint8 *mask_data = NULL;
506
  GimpBrush *brush = NULL;
507 508 509 510 511 512 513 514 515

  name = (gchar *) args[0].value.pdb_pointer;
  if (name == NULL)
    success = FALSE;

  if (success)
    {
      if (strlen (name))
	{
516
	  GSList *list;
517 518 519
    
	  success = FALSE;
    
520
	  for (list = GIMP_LIST (brush_list)->list; list; list = g_slist_next (list))
521
	    {
522
	      brush = (GimpBrush *) list->data;
523
    
524
	      if (!strcmp (brush->name, name))
Manish Singh's avatar
Manish Singh committed
525 526 527 528
		{
		  success = TRUE;
		  break;
		}
529 530 531
	    }
	}
      else
532
	success = (brush = gimp_context_get_brush (NULL)) != NULL;
533 534 535
    
      if (success)
	{
536
	  length = brush->mask->height * brush->mask->width;
537
	  mask_data = g_new (guint8, length);
538
	  g_memmove (mask_data, temp_buf_data (brush->mask), length);
539 540 541 542 543 544 545
	}
    }

  return_args = procedural_db_return_args (&brushes_get_brush_data_proc, success);

  if (success)
    {
546
      return_args[1].value.pdb_pointer = g_strdup (brush->name);
547
      return_args[2].value.pdb_float = 1.0;
548
      return_args[3].value.pdb_int = brush->spacing;
549
      return_args[4].value.pdb_int = 0;
550 551
      return_args[5].value.pdb_int = brush->mask->width;
      return_args[6].value.pdb_int = brush->mask->height;
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
      return_args[7].value.pdb_int = length;
      return_args[8].value.pdb_pointer = mask_data;
    }

  return return_args;
}

static ProcArg brushes_get_brush_data_inargs[] =
{
  {
    PDB_STRING,
    "name",
    "the brush name (\"\" means current active pattern)"
  }
};

static ProcArg brushes_get_brush_data_outargs[] =
{
  {
    PDB_STRING,
    "name",
    "The brush name"
  },
  {
    PDB_FLOAT,
    "opacity",
    "The brush opacity: 0 <= opacity <= 100"
  },
  {
    PDB_INT32,
    "spacing",
    "The brush spacing: 0 <= spacing <= 1000"
  },
  {
    PDB_INT32,
    "paint_mode",
588
    "The paint mode: { NORMAL_MODE (0), DISSOLVE_MODE (1), BEHIND_MODE (2), MULTIPLY_MODE (3), SCREEN_MODE (4), OVERLAY_MODE (5), DIFFERENCE_MODE (6), ADDITION_MODE (7), SUBTRACT_MODE (8), DARKEN_ONLY_MODE (9), LIGHTEN_ONLY_MODE (10), HUE_MODE (11), SATURATION_MODE (12), COLOR_MODE (13), VALUE_MODE (14), DIVIDE_MODE (15), DODGE_MODE (16), BURN_MODE (17), HARDLIGHT_MODE (18) }"
589 590 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
  },
  {
    PDB_INT32,
    "width",
    "The brush width"
  },
  {
    PDB_INT32,
    "height",
    "The brush height"
  },
  {
    PDB_INT32,
    "length",
    "Length of brush mask data"
  },
  {
    PDB_INT8ARRAY,
    "mask_data",
    "The brush mask data"
  }
};

static ProcRecord brushes_get_brush_data_proc =
{
  "gimp_brushes_get_brush_data",
  "Retrieve information about the currently active brush (including data).",
  "This procedure retrieves information about the currently active brush. This includes the brush name, and the brush extents (width and height). It also returns the brush data.",
  "Andy Thomas",
  "Andy Thomas",
  "1998",
  PDB_INTERNAL,
  1,
  brushes_get_brush_data_inargs,
  8,
  brushes_get_brush_data_outargs,
  { { brushes_get_brush_data_invoker } }
};