gimppaintoptions.c 23.3 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gegl.h>
21

22
#include "libgimpbase/gimpbase.h"
23
#include "libgimpmath/gimpmath.h"
24
#include "libgimpconfig/gimpconfig.h"
25

26 27
#include "paint-types.h"

28
#include "core/gimp.h"
29
#include "core/gimpimage.h"
Michael Natterer's avatar
Michael Natterer committed
30
#include "core/gimpdynamics.h"
31
#include "core/gimpdynamicsoutput.h"
32
#include "core/gimpgradient.h"
33
#include "core/gimppaintinfo.h"
34

35 36
#include "gimppaintoptions.h"

37 38
#include "gimp-intl.h"

39

40
#define DEFAULT_BRUSH_SIZE             20.0
41
#define DEFAULT_BRUSH_ASPECT_RATIO     1.0
42 43 44 45 46
#define DEFAULT_BRUSH_ANGLE            0.0

#define DEFAULT_APPLICATION_MODE       GIMP_PAINT_CONSTANT
#define DEFAULT_HARD                   FALSE

47 48 49 50 51
#define DEFAULT_USE_JITTER             FALSE
#define DEFAULT_JITTER_AMOUNT          0.2

#define DEFAULT_DYNAMICS_EXPANDED      FALSE

52
#define DEFAULT_FADE_LENGTH            100.0
Alexia Death's avatar
Alexia Death committed
53 54
#define DEFAULT_FADE_REVERSE           FALSE
#define DEFAULT_FADE_REPEAT            GIMP_REPEAT_NONE
55 56 57 58 59 60
#define DEFAULT_FADE_UNIT              GIMP_UNIT_PIXEL

#define DEFAULT_GRADIENT_REVERSE       FALSE
#define DEFAULT_GRADIENT_REPEAT        GIMP_REPEAT_TRIANGULAR
#define DEFAULT_GRADIENT_LENGTH        100.0
#define DEFAULT_GRADIENT_UNIT          GIMP_UNIT_PIXEL
61

Alexia Death's avatar
Alexia Death committed
62 63
#define DYNAMIC_MAX_VALUE              1.0
#define DYNAMIC_MIN_VALUE              0.0
64

65
#define DEFAULT_SMOOTHING_QUALITY      20
66
#define DEFAULT_SMOOTHING_FACTOR       50
67

68

69 70 71
enum
{
  PROP_0,
72

73
  PROP_PAINT_INFO,
Sven Neumann's avatar
Sven Neumann committed
74

75
  PROP_BRUSH_SIZE,
76
  PROP_BRUSH_ASPECT_RATIO,
Sven Neumann's avatar
Sven Neumann committed
77 78
  PROP_BRUSH_ANGLE,

79
  PROP_APPLICATION_MODE,
80
  PROP_HARD,
81

82 83 84 85 86
  PROP_USE_JITTER,
  PROP_JITTER_AMOUNT,

  PROP_DYNAMICS_EXPANDED,

87
  PROP_FADE_LENGTH,
Alexia Death's avatar
Alexia Death committed
88 89
  PROP_FADE_REVERSE,
  PROP_FADE_REPEAT,
90
  PROP_FADE_UNIT,
91

92
  PROP_GRADIENT_REVERSE,
93 94 95

  PROP_BRUSH_VIEW_TYPE,
  PROP_BRUSH_VIEW_SIZE,
96 97
  PROP_DYNAMICS_VIEW_TYPE,
  PROP_DYNAMICS_VIEW_SIZE,
98 99 100
  PROP_PATTERN_VIEW_TYPE,
  PROP_PATTERN_VIEW_SIZE,
  PROP_GRADIENT_VIEW_TYPE,
101 102 103
  PROP_GRADIENT_VIEW_SIZE,

  PROP_USE_SMOOTHING,
104
  PROP_SMOOTHING_QUALITY,
105
  PROP_SMOOTHING_FACTOR
106
};
107 108


109
static void    gimp_paint_options_dispose          (GObject      *object);
110 111 112 113 114 115 116 117 118 119
static void    gimp_paint_options_finalize         (GObject      *object);
static void    gimp_paint_options_set_property     (GObject      *object,
                                                    guint         property_id,
                                                    const GValue *value,
                                                    GParamSpec   *pspec);
static void    gimp_paint_options_get_property     (GObject      *object,
                                                    guint         property_id,
                                                    GValue       *value,
                                                    GParamSpec   *pspec);

120

121

122
G_DEFINE_TYPE (GimpPaintOptions, gimp_paint_options, GIMP_TYPE_TOOL_OPTIONS)
123

Michael Natterer's avatar
Michael Natterer committed
124
#define parent_class gimp_paint_options_parent_class
125 126


127
static void
128
gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
129
{
130
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
131

132
  object_class->dispose      = gimp_paint_options_dispose;
133
  object_class->finalize     = gimp_paint_options_finalize;
134 135 136
  object_class->set_property = gimp_paint_options_set_property;
  object_class->get_property = gimp_paint_options_get_property;

137 138 139 140
  g_object_class_install_property (object_class, PROP_PAINT_INFO,
                                   g_param_spec_object ("paint-info",
                                                        NULL, NULL,
                                                        GIMP_TYPE_PAINT_INFO,
141
                                                        GIMP_PARAM_READWRITE |
142 143
                                                        G_PARAM_CONSTRUCT_ONLY));

144 145
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_SIZE,
                                   "brush-size", _("Brush Size"),
146
                                   1.0, 1000.0, DEFAULT_BRUSH_SIZE,
147
                                   GIMP_PARAM_STATIC_STRINGS);
148 149

  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_ASPECT_RATIO,
150
                                   "brush-aspect-ratio", _("Brush Aspect Ratio"),
151 152
                                   0.01, 10.0, DEFAULT_BRUSH_ASPECT_RATIO,
                                   GIMP_PARAM_STATIC_STRINGS);
Sven Neumann's avatar
Sven Neumann committed
153
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_ANGLE,
154
                                   "brush-angle", _("Brush Angle"),
Sven Neumann's avatar
Sven Neumann committed
155 156 157
                                   -180.0, 180.0, DEFAULT_BRUSH_ANGLE,
                                   GIMP_PARAM_STATIC_STRINGS);

158 159 160 161
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_APPLICATION_MODE,
                                 "application-mode", NULL,
                                 GIMP_TYPE_PAINT_APPLICATION_MODE,
                                 DEFAULT_APPLICATION_MODE,
162
                                 GIMP_PARAM_STATIC_STRINGS);
163

164 165 166
  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_HARD,
                                    "hard", NULL,
                                    DEFAULT_HARD,
167
                                    GIMP_PARAM_STATIC_STRINGS);
168

169 170 171 172 173 174 175 176 177 178 179 180
  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_JITTER,
                                    "use-jitter", NULL,
                                    DEFAULT_USE_JITTER,
                                    GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_JITTER_AMOUNT,
                                   "jitter-amount", NULL,
                                   0.0, 50.0, DEFAULT_JITTER_AMOUNT,
                                   GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_DYNAMICS_EXPANDED,
                                     "dynamics-expanded", NULL,
                                    DEFAULT_DYNAMICS_EXPANDED,
181
                                    GIMP_PARAM_STATIC_STRINGS);
182

183 184
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_FADE_LENGTH,
                                   "fade-length", NULL,
185
                                   0.0, 32767.0, DEFAULT_FADE_LENGTH,
186
                                   GIMP_PARAM_STATIC_STRINGS);
187 188
  GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_FADE_UNIT,
                                 "fade-unit", NULL,
189
                                 TRUE, TRUE, DEFAULT_FADE_UNIT,
190
                                 GIMP_PARAM_STATIC_STRINGS);
Alexia Death's avatar
Alexia Death committed
191 192 193 194 195 196 197 198 199
  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADE_REVERSE,
                                    "fade-reverse", NULL,
                                    DEFAULT_FADE_REVERSE,
                                    GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_FADE_REPEAT,
                                 "fade-repeat", NULL,
                                 GIMP_TYPE_REPEAT_MODE,
                                 DEFAULT_FADE_REPEAT,
                                 GIMP_PARAM_STATIC_STRINGS);
200

201 202
  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_GRADIENT_REVERSE,
                                    "gradient-reverse", NULL,
203 204
                                    DEFAULT_GRADIENT_REVERSE,
                                    GIMP_PARAM_STATIC_STRINGS);
205 206 207 208 209

  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_BRUSH_VIEW_TYPE,
                                 "brush-view-type", NULL,
                                 GIMP_TYPE_VIEW_TYPE,
                                 GIMP_VIEW_TYPE_GRID,
210
                                 GIMP_PARAM_STATIC_STRINGS);
211 212 213 214 215
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_BRUSH_VIEW_SIZE,
                                "brush-view-size", NULL,
                                GIMP_VIEW_SIZE_TINY,
                                GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                                GIMP_VIEW_SIZE_SMALL,
216
                                GIMP_PARAM_STATIC_STRINGS);
217

218 219 220 221 222 223 224 225 226 227 228 229
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_DYNAMICS_VIEW_TYPE,
                                  "dynamics-view-type", NULL,
                                 GIMP_TYPE_VIEW_TYPE,
                                 GIMP_VIEW_TYPE_LIST,
                                 GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_DYNAMICS_VIEW_SIZE,
                                "dynamics-view-size", NULL,
                                GIMP_VIEW_SIZE_TINY,
                                GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                                GIMP_VIEW_SIZE_SMALL,
                                GIMP_PARAM_STATIC_STRINGS);

230 231 232 233
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_PATTERN_VIEW_TYPE,
                                 "pattern-view-type", NULL,
                                 GIMP_TYPE_VIEW_TYPE,
                                 GIMP_VIEW_TYPE_GRID,
234
                                 GIMP_PARAM_STATIC_STRINGS);
235 236 237 238 239
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_PATTERN_VIEW_SIZE,
                                "pattern-view-size", NULL,
                                GIMP_VIEW_SIZE_TINY,
                                GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                                GIMP_VIEW_SIZE_SMALL,
240
                                GIMP_PARAM_STATIC_STRINGS);
241 242 243 244 245

  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_GRADIENT_VIEW_TYPE,
                                 "gradient-view-type", NULL,
                                 GIMP_TYPE_VIEW_TYPE,
                                 GIMP_VIEW_TYPE_LIST,
246
                                 GIMP_PARAM_STATIC_STRINGS);
247 248 249 250 251
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_GRADIENT_VIEW_SIZE,
                                "gradient-view-size", NULL,
                                GIMP_VIEW_SIZE_TINY,
                                GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                                GIMP_VIEW_SIZE_LARGE,
252
                                GIMP_PARAM_STATIC_STRINGS);
253 254 255 256 257

  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_SMOOTHING,
                                    "use-smoothing", NULL,
                                    FALSE,
                                    GIMP_PARAM_STATIC_STRINGS);
258 259
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_SMOOTHING_QUALITY,
                                "smoothing-quality", NULL,
260
                                1, 100, DEFAULT_SMOOTHING_QUALITY,
261
                                GIMP_PARAM_STATIC_STRINGS);
262 263
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_SMOOTHING_FACTOR,
                                   "smoothing-factor", NULL,
264 265 266 267 268
                                   3.0, 1000.0, DEFAULT_SMOOTHING_FACTOR,
                                   /* Max velocity is set at 3.
                                    * Allowing for smoothing factor to be
                                    * less than velcoty results in numeric
                                    * instablility */
269
                                   GIMP_PARAM_STATIC_STRINGS);
270
}
271

272 273 274
static void
gimp_paint_options_init (GimpPaintOptions *options)
{
275
  options->application_mode_save = DEFAULT_APPLICATION_MODE;
276

277
  options->jitter_options    = g_slice_new0 (GimpJitterOptions);
278
  options->fade_options      = g_slice_new0 (GimpFadeOptions);
279
  options->gradient_options  = g_slice_new0 (GimpGradientOptions);
280
  options->smoothing_options = g_slice_new0 (GimpSmoothingOptions);
281 282
}

283
static void
284
gimp_paint_options_dispose (GObject *object)
285 286 287
{
  GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);

288
  if (options->paint_info)
289 290 291 292 293 294 295 296 297 298 299 300
    {
      g_object_unref (options->paint_info);
      options->paint_info = NULL;
    }

  G_OBJECT_CLASS (parent_class)->dispose (object);
}

static void
gimp_paint_options_finalize (GObject *object)
{
  GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);
301

302 303 304
  g_slice_free (GimpJitterOptions,    options->jitter_options);
  g_slice_free (GimpFadeOptions,      options->fade_options);
  g_slice_free (GimpGradientOptions,  options->gradient_options);
305
  g_slice_free (GimpSmoothingOptions, options->smoothing_options);
306 307 308 309

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

310 311 312 313 314
static void
gimp_paint_options_set_property (GObject      *object,
                                 guint         property_id,
                                 const GValue *value,
                                 GParamSpec   *pspec)
315
{
316 317 318 319 320
  GimpPaintOptions    *options            = GIMP_PAINT_OPTIONS (object);
  GimpFadeOptions     *fade_options       = options->fade_options;
  GimpJitterOptions   *jitter_options     = options->jitter_options;
  GimpGradientOptions *gradient_options   = options->gradient_options;
  GimpSmoothingOptions *smoothing_options = options->smoothing_options;
321

322 323
  switch (property_id)
    {
324
    case PROP_PAINT_INFO:
325
      options->paint_info = g_value_dup_object (value);
326 327
      break;

328 329
    case PROP_BRUSH_SIZE:
      options->brush_size = g_value_get_double (value);
330
      break;
331

332 333 334 335
    case PROP_BRUSH_ASPECT_RATIO:
      options->brush_aspect_ratio = g_value_get_double (value);
      break;

Sven Neumann's avatar
Sven Neumann committed
336
    case PROP_BRUSH_ANGLE:
337
      options->brush_angle = - 1.0 * g_value_get_double (value) / 360.0; /* let's make the angle mathematically correct */
Sven Neumann's avatar
Sven Neumann committed
338 339
      break;

340 341
    case PROP_APPLICATION_MODE:
      options->application_mode = g_value_get_enum (value);
342
      break;
343

344 345 346
    case PROP_HARD:
      options->hard = g_value_get_boolean (value);
      break;
347

348 349 350 351 352 353 354 355 356 357
    case PROP_USE_JITTER:
      jitter_options->use_jitter = g_value_get_boolean (value);
      break;

    case PROP_JITTER_AMOUNT:
      jitter_options->jitter_amount = g_value_get_double (value);
      break;

    case PROP_DYNAMICS_EXPANDED:
      options->dynamics_expanded = g_value_get_boolean (value);
358 359
      break;

360
    case PROP_FADE_LENGTH:
361
      fade_options->fade_length = g_value_get_double (value);
362
      break;
363

Alexia Death's avatar
Alexia Death committed
364 365 366 367 368 369 370 371
    case PROP_FADE_REVERSE:
      fade_options->fade_reverse = g_value_get_boolean (value);
      break;

    case PROP_FADE_REPEAT:
      fade_options->fade_repeat = g_value_get_enum (value);
      break;

372
    case PROP_FADE_UNIT:
373
      fade_options->fade_unit = g_value_get_int (value);
374 375
      break;

376 377 378
    case PROP_GRADIENT_REVERSE:
      gradient_options->gradient_reverse = g_value_get_boolean (value);
      break;
379

380 381 382
    case PROP_BRUSH_VIEW_TYPE:
      options->brush_view_type = g_value_get_enum (value);
      break;
383

384 385 386 387
    case PROP_BRUSH_VIEW_SIZE:
      options->brush_view_size = g_value_get_int (value);
      break;

388 389 390 391 392 393 394 395
    case PROP_DYNAMICS_VIEW_TYPE:
      options->dynamics_view_type = g_value_get_enum (value);
      break;

    case PROP_DYNAMICS_VIEW_SIZE:
      options->dynamics_view_size = g_value_get_int (value);
      break;

396 397 398
    case PROP_PATTERN_VIEW_TYPE:
      options->pattern_view_type = g_value_get_enum (value);
      break;
399

400 401 402 403 404 405 406
    case PROP_PATTERN_VIEW_SIZE:
      options->pattern_view_size = g_value_get_int (value);
      break;

    case PROP_GRADIENT_VIEW_TYPE:
      options->gradient_view_type = g_value_get_enum (value);
      break;
407

408 409 410 411
    case PROP_GRADIENT_VIEW_SIZE:
      options->gradient_view_size = g_value_get_int (value);
      break;

412 413 414 415
    case PROP_USE_SMOOTHING:
      smoothing_options->use_smoothing = g_value_get_boolean (value);
      break;

416 417
    case PROP_SMOOTHING_QUALITY:
      smoothing_options->smoothing_quality = g_value_get_int (value);
418 419 420 421 422 423
      break;

    case PROP_SMOOTHING_FACTOR:
      smoothing_options->smoothing_factor = g_value_get_double (value);
      break;

424 425 426 427
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
428 429
}

430 431 432 433 434 435
static void
gimp_paint_options_get_property (GObject    *object,
                                 guint       property_id,
                                 GValue     *value,
                                 GParamSpec *pspec)
{
436 437 438 439
  GimpPaintOptions     *options           = GIMP_PAINT_OPTIONS (object);
  GimpFadeOptions      *fade_options      = options->fade_options;
  GimpJitterOptions    *jitter_options    = options->jitter_options;
  GimpGradientOptions  *gradient_options  = options->gradient_options;
440
  GimpSmoothingOptions *smoothing_options = options->smoothing_options;
441

442 443
  switch (property_id)
    {
444 445 446 447
    case PROP_PAINT_INFO:
      g_value_set_object (value, options->paint_info);
      break;

448 449
    case PROP_BRUSH_SIZE:
      g_value_set_double (value, options->brush_size);
450
      break;
451

452 453 454 455
    case PROP_BRUSH_ASPECT_RATIO:
      g_value_set_double (value, options->brush_aspect_ratio);
      break;

Sven Neumann's avatar
Sven Neumann committed
456
    case PROP_BRUSH_ANGLE:
457
      g_value_set_double (value, - 1.0 * options->brush_angle * 360.0); /* mathematically correct -> intuitively correct */
Sven Neumann's avatar
Sven Neumann committed
458 459
      break;

460 461
    case PROP_APPLICATION_MODE:
      g_value_set_enum (value, options->application_mode);
462
      break;
463

464 465 466
    case PROP_HARD:
      g_value_set_boolean (value, options->hard);
      break;
467

468 469 470 471 472 473 474 475 476 477
    case PROP_USE_JITTER:
      g_value_set_boolean (value, jitter_options->use_jitter);
      break;

    case PROP_JITTER_AMOUNT:
      g_value_set_double (value, jitter_options->jitter_amount);
      break;

    case PROP_DYNAMICS_EXPANDED:
      g_value_set_boolean (value, options->dynamics_expanded);
478 479
      break;

480 481 482 483
    case PROP_FADE_LENGTH:
      g_value_set_double (value, fade_options->fade_length);
      break;

Alexia Death's avatar
Alexia Death committed
484 485 486 487 488 489 490 491
    case PROP_FADE_REVERSE:
      g_value_set_boolean (value, fade_options->fade_reverse);
      break;

    case PROP_FADE_REPEAT:
      g_value_set_enum (value, fade_options->fade_repeat);
      break;

492 493 494 495
    case PROP_FADE_UNIT:
      g_value_set_int (value, fade_options->fade_unit);
      break;

496
    case PROP_GRADIENT_REVERSE:
497
      g_value_set_boolean (value, gradient_options->gradient_reverse);
498 499 500
      break;

    case PROP_BRUSH_VIEW_TYPE:
501
      g_value_set_enum (value, options->brush_view_type);
502 503 504
      break;

    case PROP_BRUSH_VIEW_SIZE:
505
      g_value_set_int (value, options->brush_view_size);
506 507
      break;

508 509 510 511 512 513 514 515
    case PROP_DYNAMICS_VIEW_TYPE:
      g_value_set_enum (value, options->dynamics_view_type);
      break;

    case PROP_DYNAMICS_VIEW_SIZE:
      g_value_set_int (value, options->dynamics_view_size);
      break;

516
    case PROP_PATTERN_VIEW_TYPE:
517
      g_value_set_enum (value, options->pattern_view_type);
518 519 520
      break;

    case PROP_PATTERN_VIEW_SIZE:
521
      g_value_set_int (value, options->pattern_view_size);
522 523 524
      break;

    case PROP_GRADIENT_VIEW_TYPE:
525
      g_value_set_enum (value, options->gradient_view_type);
526 527 528
      break;

    case PROP_GRADIENT_VIEW_SIZE:
529
      g_value_set_int (value, options->gradient_view_size);
530
      break;
531

532
    case PROP_USE_SMOOTHING:
533
      g_value_set_boolean (value, smoothing_options->use_smoothing);
534 535
      break;

536 537
    case PROP_SMOOTHING_QUALITY:
      g_value_set_int (value, smoothing_options->smoothing_quality);
538 539 540 541 542
      break;

    case PROP_SMOOTHING_FACTOR:
      g_value_set_double (value, smoothing_options->smoothing_factor);
      break;
543 544 545 546 547 548 549

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

550

551
GimpPaintOptions *
552
gimp_paint_options_new (GimpPaintInfo *paint_info)
553
{
554 555
  GimpPaintOptions *options;

556
  g_return_val_if_fail (GIMP_IS_PAINT_INFO (paint_info), NULL);
557

558 559
  options = g_object_new (paint_info->paint_options_type,
                          "gimp",       paint_info->gimp,
560
                          "name",       gimp_object_get_name (paint_info),
561
                          "paint-info", paint_info,
562 563 564
                          NULL);

  return options;
565
}
566

567 568
gdouble
gimp_paint_options_get_fade (GimpPaintOptions *paint_options,
569
                             GimpImage        *image,
570 571 572
                             gdouble           pixel_dist)
{
  GimpFadeOptions *fade_options;
573 574 575 576
  gdouble          z        = -1.0;
  gdouble          fade_out =  0.0;
  gdouble          unit_factor;
  gdouble          pos;
577

578
  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options),
Alexia Death's avatar
Alexia Death committed
579 580
                        DYNAMIC_MAX_VALUE);
  g_return_val_if_fail (GIMP_IS_IMAGE (image), DYNAMIC_MAX_VALUE);
581 582 583

  fade_options = paint_options->fade_options;

584
  switch (fade_options->fade_unit)
585
    {
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
    case GIMP_UNIT_PIXEL:
      fade_out = fade_options->fade_length;
      break;

    case GIMP_UNIT_PERCENT:
      fade_out = (MAX (gimp_image_get_width  (image),
                       gimp_image_get_height (image)) *
                  fade_options->fade_length / 100);
      break;

    default:
      {
        gdouble xres;
        gdouble yres;

        gimp_image_get_resolution (image, &xres, &yres);

        unit_factor = gimp_unit_get_factor (fade_options->fade_unit);
        fade_out    = (fade_options->fade_length *
                       MAX (xres, yres) / unit_factor);
      }
      break;
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
  /*  factor in the fade out value  */
  if (fade_out > 0.0)
    {
      pos = pixel_dist / fade_out;
    }
  else
    pos = DYNAMIC_MAX_VALUE;

  /*  for no repeat, set pos close to 1.0 after the first chunk  */
  if (fade_options->fade_repeat == GIMP_REPEAT_NONE && pos >= DYNAMIC_MAX_VALUE)
    pos = DYNAMIC_MAX_VALUE - 0.0000001;

  if (((gint) pos & 1) &&
      fade_options->fade_repeat != GIMP_REPEAT_SAWTOOTH)
    pos = DYNAMIC_MAX_VALUE - (pos - (gint) pos);
  else
    pos = pos - (gint) pos;

  z = pos;

  if (fade_options->fade_reverse)
    z = 1.0 - z;

  return z;    /*  ln (1/255)  */
634 635
}

636 637
gdouble
gimp_paint_options_get_jitter (GimpPaintOptions *paint_options,
638
                               GimpImage        *image)
639 640 641
{
  GimpJitterOptions *jitter_options;

Michael Natterer's avatar
Michael Natterer committed
642 643
  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), 0.0);

644 645 646
  jitter_options = paint_options->jitter_options;

  if (jitter_options->use_jitter)
Alexia Death's avatar
Alexia Death committed
647 648 649 650
    {
      return jitter_options->jitter_amount;
    }

651 652 653
  return 0.0;
}

654 655
gboolean
gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
656
                                       GimpImage        *image,
657
                                       gdouble           grad_point,
658 659 660 661 662
                                       gdouble           pixel_dist,
                                       GimpRGB          *color)
{
  GimpGradientOptions *gradient_options;
  GimpGradient        *gradient;
Alexia Death's avatar
Alexia Death committed
663
  GimpDynamics        *dynamics;
664 665

  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
666
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
667 668 669 670 671
  g_return_val_if_fail (color != NULL, FALSE);

  gradient_options = paint_options->gradient_options;

  gradient = gimp_context_get_gradient (GIMP_CONTEXT (paint_options));
Alexia Death's avatar
Alexia Death committed
672 673 674

  dynamics = gimp_context_get_dynamics (GIMP_CONTEXT (paint_options));

675
  if (gimp_dynamics_output_is_enabled (dynamics->color_output))
676
    {
677
      gimp_gradient_get_color_at (gradient, GIMP_CONTEXT (paint_options),
678
                                  NULL, grad_point,
679 680 681 682 683 684 685 686 687
                                  gradient_options->gradient_reverse,
                                  color);

      return TRUE;
    }

  return FALSE;
}

688 689 690
GimpBrushApplicationMode
gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options)
{
691 692
  GimpDynamics *dynamics;

693 694 695 696 697
  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), GIMP_BRUSH_SOFT);

  if (paint_options->hard)
    return GIMP_BRUSH_HARD;

698 699
  dynamics = gimp_context_get_dynamics (GIMP_CONTEXT (paint_options));

700 701 702

   if (gimp_dynamics_output_is_enabled(dynamics->force_output))
     return GIMP_BRUSH_PRESSURE;
703

704 705
  return GIMP_BRUSH_SOFT;
}