gimppaintoptions.c 43.2 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 <https://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gdk-pixbuf/gdk-pixbuf.h>
21
#include <gegl.h>
22

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

27 28
#include "paint-types.h"

29
#include "core/gimp.h"
30
#include "core/gimpbrush-header.h"
31
#include "core/gimpbrushgenerated.h"
32
#include "core/gimpimage.h"
Michael Natterer's avatar
Michael Natterer committed
33
#include "core/gimpdynamics.h"
34
#include "core/gimpdynamicsoutput.h"
35
#include "core/gimpgradient.h"
36
#include "core/gimppaintinfo.h"
37

38
#include "gimpbrushcore.h"
39 40
#include "gimppaintoptions.h"

41 42
#include "gimp-intl.h"

43

44 45 46 47 48 49
#define DEFAULT_BRUSH_SIZE              20.0
#define DEFAULT_BRUSH_ASPECT_RATIO      0.0
#define DEFAULT_BRUSH_ANGLE             0.0
#define DEFAULT_BRUSH_SPACING           0.1
#define DEFAULT_BRUSH_HARDNESS          1.0 /* Generated brushes have their own */
#define DEFAULT_BRUSH_FORCE             0.5
50

51 52 53 54 55 56 57 58
#define DEFAULT_BRUSH_LINK_SIZE         TRUE
#define DEFAULT_BRUSH_LINK_ASPECT_RATIO TRUE
#define DEFAULT_BRUSH_LINK_ANGLE        TRUE
#define DEFAULT_BRUSH_LINK_SPACING      TRUE
#define DEFAULT_BRUSH_LINK_HARDNESS     TRUE

#define DEFAULT_BRUSH_LOCK_TO_VIEW      FALSE

59 60
#define DEFAULT_APPLICATION_MODE        GIMP_PAINT_CONSTANT
#define DEFAULT_HARD                    FALSE
61

62 63
#define DEFAULT_USE_JITTER              FALSE
#define DEFAULT_JITTER_AMOUNT           0.2
64

65
#define DEFAULT_DYNAMICS_EXPANDED       FALSE
66

67 68 69 70
#define DEFAULT_FADE_LENGTH             100.0
#define DEFAULT_FADE_REVERSE            FALSE
#define DEFAULT_FADE_REPEAT             GIMP_REPEAT_NONE
#define DEFAULT_FADE_UNIT               GIMP_UNIT_PIXEL
71

72
#define DEFAULT_GRADIENT_REVERSE        FALSE
73
#define DEFAULT_GRADIENT_BLEND_SPACE    GIMP_GRADIENT_BLEND_RGB_PERCEPTUAL
74
#define DEFAULT_GRADIENT_REPEAT         GIMP_REPEAT_NONE
75

76 77
#define DYNAMIC_MAX_VALUE               1.0
#define DYNAMIC_MIN_VALUE               0.0
78

79 80
#define DEFAULT_SMOOTHING_QUALITY       20
#define DEFAULT_SMOOTHING_FACTOR        50
81

82 83 84
enum
{
  PROP_0,
85

86
  PROP_PAINT_INFO,
87

88 89
  PROP_USE_APPLICATOR, /* temp debug */

90
  PROP_BRUSH_SIZE,
91
  PROP_BRUSH_ASPECT_RATIO,
92
  PROP_BRUSH_ANGLE,
93
  PROP_BRUSH_SPACING,
94 95
  PROP_BRUSH_HARDNESS,
  PROP_BRUSH_FORCE,
96

97 98 99 100 101 102 103 104
  PROP_BRUSH_LINK_SIZE,
  PROP_BRUSH_LINK_ASPECT_RATIO,
  PROP_BRUSH_LINK_ANGLE,
  PROP_BRUSH_LINK_SPACING,
  PROP_BRUSH_LINK_HARDNESS,

  PROP_BRUSH_LOCK_TO_VIEW,

105
  PROP_APPLICATION_MODE,
106
  PROP_HARD,
107

108 109 110 111 112
  PROP_USE_JITTER,
  PROP_JITTER_AMOUNT,

  PROP_DYNAMICS_EXPANDED,

113
  PROP_FADE_LENGTH,
114 115
  PROP_FADE_REVERSE,
  PROP_FADE_REPEAT,
116
  PROP_FADE_UNIT,
117

118
  PROP_GRADIENT_REVERSE,
119
  PROP_GRADIENT_BLEND_COLOR_SPACE,
120
  PROP_GRADIENT_REPEAT,
121 122 123

  PROP_BRUSH_VIEW_TYPE,
  PROP_BRUSH_VIEW_SIZE,
124 125
  PROP_DYNAMICS_VIEW_TYPE,
  PROP_DYNAMICS_VIEW_SIZE,
126 127 128
  PROP_PATTERN_VIEW_TYPE,
  PROP_PATTERN_VIEW_SIZE,
  PROP_GRADIENT_VIEW_TYPE,
129 130 131
  PROP_GRADIENT_VIEW_SIZE,

  PROP_USE_SMOOTHING,
132
  PROP_SMOOTHING_QUALITY,
133
  PROP_SMOOTHING_FACTOR
134
};
135 136


137
static void         gimp_paint_options_config_iface_init (GimpConfigInterface *config_iface);
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
static void         gimp_paint_options_dispose           (GObject          *object);
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);

static void         gimp_paint_options_brush_changed     (GimpContext      *context,
                                                          GimpBrush        *brush);
static void         gimp_paint_options_brush_notify      (GimpBrush        *brush,
                                                          const GParamSpec *pspec,
                                                          GimpPaintOptions *options);

static GimpConfig * gimp_paint_options_duplicate         (GimpConfig       *config);
static gboolean     gimp_paint_options_copy              (GimpConfig       *src,
                                                          GimpConfig       *dest,
                                                          GParamFlags       flags);
static void         gimp_paint_options_reset             (GimpConfig       *config);
161

162

163 164 165 166
G_DEFINE_TYPE_WITH_CODE (GimpPaintOptions, gimp_paint_options,
                         GIMP_TYPE_TOOL_OPTIONS,
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
                                                gimp_paint_options_config_iface_init))
167

Michael Natterer's avatar
Michael Natterer committed
168
#define parent_class gimp_paint_options_parent_class
169

170 171
static GimpConfigInterface *parent_config_iface = NULL;

172

173
static void
174
gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
175
{
176 177 178 179 180 181 182
  GObjectClass     *object_class  = G_OBJECT_CLASS (klass);
  GimpContextClass *context_class = GIMP_CONTEXT_CLASS (klass);

  object_class->dispose         = gimp_paint_options_dispose;
  object_class->finalize        = gimp_paint_options_finalize;
  object_class->set_property    = gimp_paint_options_set_property;
  object_class->get_property    = gimp_paint_options_get_property;
183

184
  context_class->brush_changed  = gimp_paint_options_brush_changed;
185

186 187 188 189
  g_object_class_install_property (object_class, PROP_PAINT_INFO,
                                   g_param_spec_object ("paint-info",
                                                        NULL, NULL,
                                                        GIMP_TYPE_PAINT_INFO,
190
                                                        GIMP_PARAM_READWRITE |
191 192
                                                        G_PARAM_CONSTRUCT_ONLY));

193 194
  g_object_class_install_property (object_class, PROP_USE_APPLICATOR,
                                   g_param_spec_boolean ("use-applicator",
195 196
                                                         "Use GimpApplicator",
                                                         NULL,
197
                                                         FALSE,
198 199 200
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT));

201 202 203 204 205 206 207 208 209 210 211 212 213 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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BRUSH_SIZE,
                           "brush-size",
                           _("Size"),
                           _("Brush Size"),
                           1.0, GIMP_BRUSH_MAX_SIZE, DEFAULT_BRUSH_SIZE,
                           GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BRUSH_ASPECT_RATIO,
                           "brush-aspect-ratio",
                           _("Aspect Ratio"),
                           _("Brush Aspect Ratio"),
                           -20.0, 20.0, DEFAULT_BRUSH_ASPECT_RATIO,
                           GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BRUSH_ANGLE,
                           "brush-angle",
                           _("Angle"),
                           _("Brush Angle"),
                           -180.0, 180.0, DEFAULT_BRUSH_ANGLE,
                           GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BRUSH_SPACING,
                           "brush-spacing",
                           _("Spacing"),
                           _("Brush Spacing"),
                           0.01, 50.0, DEFAULT_BRUSH_SPACING,
                           GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BRUSH_HARDNESS,
                           "brush-hardness",
                           _("Hardness"),
                           _("Brush Hardness"),
                           0.0, 1.0, DEFAULT_BRUSH_HARDNESS,
                           GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BRUSH_FORCE,
                           "brush-force",
                           _("Force"),
                           _("Brush Force"),
                           0.0, 1.0, DEFAULT_BRUSH_FORCE,
                           GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_BRUSH_LINK_SIZE,
                            "brush-link-size",
                            _("Link Size"),
                            _("Link brush size to brush native"),
                            DEFAULT_BRUSH_LINK_SIZE,
                            GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_BRUSH_LINK_ASPECT_RATIO,
                            "brush-link-aspect-ratio",
                            _("Link Aspect Ratio"),
                            _("Link brush aspect ratio to brush native"),
                            DEFAULT_BRUSH_LINK_ASPECT_RATIO,
                            GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_BRUSH_LINK_ANGLE,
                            "brush-link-angle",
                            _("Link Angle"),
                            _("Link brush angle to brush native"),
                            DEFAULT_BRUSH_LINK_ANGLE,
                            GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_BRUSH_LINK_SPACING,
                            "brush-link-spacing",
                            _("Link Spacing"),
                            _("Link brush spacing to brush native"),
                            DEFAULT_BRUSH_LINK_SPACING,
                            GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_BRUSH_LINK_HARDNESS,
                            "brush-link-hardness",
                            _("Link Hardness"),
                            _("Link brush hardness to brush native"),
                            DEFAULT_BRUSH_LINK_HARDNESS,
                            GIMP_PARAM_STATIC_STRINGS);

278 279 280
  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_BRUSH_LOCK_TO_VIEW,
                            "brush-lock-to-view",
                            _("Lock brush to view"),
Piotr Drąg's avatar
Piotr Drąg committed
281
                            _("Keep brush appearance fixed relative to the view"),
282 283 284
                            DEFAULT_BRUSH_LOCK_TO_VIEW,
                            GIMP_PARAM_STATIC_STRINGS);

285 286 287 288 289 290 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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
  GIMP_CONFIG_PROP_ENUM (object_class, PROP_APPLICATION_MODE,
                         "application-mode",
                         _("Incremental"),
                         _("Every stamp has its own opacity"),
                         GIMP_TYPE_PAINT_APPLICATION_MODE,
                         DEFAULT_APPLICATION_MODE,
                         GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_HARD,
                            "hard",
                            _("Hard edge"),
                            _("Ignore fuzziness of the current brush"),
                            DEFAULT_HARD,
                            GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_USE_JITTER,
                            "use-jitter",
                            _("Apply Jitter"),
                            _("Scatter brush as you paint"),
                            DEFAULT_USE_JITTER,
                            GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_JITTER_AMOUNT,
                           "jitter-amount",
                           _("Amount"),
                           _("Distance of scattering"),
                           0.0, 50.0, DEFAULT_JITTER_AMOUNT,
                           GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_DYNAMICS_EXPANDED,
                            "dynamics-expanded",
                            _("Dynamics Options"),
                            NULL,
                            DEFAULT_DYNAMICS_EXPANDED,
                            GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_FADE_LENGTH,
                           "fade-length",
                           _("Fade length"),
                           _("Distance over which strokes fade out"),
                           0.0, 32767.0, DEFAULT_FADE_LENGTH,
                           GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_UNIT (object_class, PROP_FADE_UNIT,
                         "fade-unit",
                         NULL, NULL,
                         TRUE, TRUE, DEFAULT_FADE_UNIT,
                         GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_FADE_REVERSE,
                            "fade-reverse",
                            _("Reverse"),
                            _("Reverse direction of fading"),
                            DEFAULT_FADE_REVERSE,
                            GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_ENUM (object_class, PROP_FADE_REPEAT,
                         "fade-repeat",
                         _("Repeat"),
                         _("How fade is repeated as you paint"),
                         GIMP_TYPE_REPEAT_MODE,
                         DEFAULT_FADE_REPEAT,
                         GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_GRADIENT_REVERSE,
                            "gradient-reverse",
                            NULL, NULL,
                            DEFAULT_GRADIENT_REVERSE,
                            GIMP_PARAM_STATIC_STRINGS);
350 351 352 353 354 355 356
  GIMP_CONFIG_PROP_ENUM (object_class, PROP_GRADIENT_BLEND_COLOR_SPACE,
                         "gradient-blend-color-space",
                         _("Blend Color Space"),
                         _("Which color space to use when blending RGB gradient segments"),
                         GIMP_TYPE_GRADIENT_BLEND_COLOR_SPACE,
                         DEFAULT_GRADIENT_BLEND_SPACE,
                         GIMP_PARAM_STATIC_STRINGS);
357 358 359 360 361 362 363
  GIMP_CONFIG_PROP_ENUM (object_class, PROP_GRADIENT_REPEAT,
                         "gradient-repeat",
                         _("Repeat"),
                         NULL,
                         GIMP_TYPE_REPEAT_MODE,
                         DEFAULT_GRADIENT_REPEAT,
                         GIMP_PARAM_STATIC_STRINGS);
364 365 366 367 368 369 370 371 372 373 374 375 376 377 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 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 430 431 432 433 434 435 436 437 438 439 440 441 442

  GIMP_CONFIG_PROP_ENUM (object_class, PROP_BRUSH_VIEW_TYPE,
                         "brush-view-type",
                         NULL, NULL,
                         GIMP_TYPE_VIEW_TYPE,
                         GIMP_VIEW_TYPE_GRID,
                         GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_INT (object_class, PROP_BRUSH_VIEW_SIZE,
                        "brush-view-size",
                        NULL, NULL,
                        GIMP_VIEW_SIZE_TINY,
                        GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                        GIMP_VIEW_SIZE_SMALL,
                        GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_ENUM (object_class, PROP_DYNAMICS_VIEW_TYPE,
                         "dynamics-view-type",
                         NULL, NULL,
                         GIMP_TYPE_VIEW_TYPE,
                         GIMP_VIEW_TYPE_LIST,
                         GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_INT (object_class, PROP_DYNAMICS_VIEW_SIZE,
                        "dynamics-view-size",
                        NULL, NULL,
                        GIMP_VIEW_SIZE_TINY,
                        GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                        GIMP_VIEW_SIZE_SMALL,
                        GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_ENUM (object_class, PROP_PATTERN_VIEW_TYPE,
                         "pattern-view-type",
                         NULL, NULL,
                         GIMP_TYPE_VIEW_TYPE,
                         GIMP_VIEW_TYPE_GRID,
                         GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_INT (object_class, PROP_PATTERN_VIEW_SIZE,
                        "pattern-view-size",
                        NULL, NULL,
                        GIMP_VIEW_SIZE_TINY,
                        GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                        GIMP_VIEW_SIZE_SMALL,
                        GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_ENUM (object_class, PROP_GRADIENT_VIEW_TYPE,
                         "gradient-view-type",
                         NULL, NULL,
                         GIMP_TYPE_VIEW_TYPE,
                         GIMP_VIEW_TYPE_LIST,
                         GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_INT (object_class, PROP_GRADIENT_VIEW_SIZE,
                        "gradient-view-size",
                        NULL, NULL,
                        GIMP_VIEW_SIZE_TINY,
                        GIMP_VIEWABLE_MAX_BUTTON_SIZE,
                        GIMP_VIEW_SIZE_LARGE,
                        GIMP_PARAM_STATIC_STRINGS);

  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_USE_SMOOTHING,
                            "use-smoothing",
                            _("Smooth stroke"),
                            _("Paint smoother strokes"),
                            FALSE,
                            GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_INT (object_class, PROP_SMOOTHING_QUALITY,
                        "smoothing-quality",
                        _("Quality"),
                        _("Depth of smoothing"),
                        1, 100, DEFAULT_SMOOTHING_QUALITY,
                        GIMP_PARAM_STATIC_STRINGS);
  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_SMOOTHING_FACTOR,
                           "smoothing-factor",
                           _("Weight"),
                           _("Gravity of the pen"),
                           /* Max velocity is set to 3; allowing for
                            * smoothing factor to be less than velcoty
                            * results in numeric instablility
                            */
                           3.0, 1000.0, DEFAULT_SMOOTHING_FACTOR,
                           GIMP_PARAM_STATIC_STRINGS);
443
}
444

445 446 447 448 449 450 451 452 453
static void
gimp_paint_options_config_iface_init (GimpConfigInterface *config_iface)
{
  parent_config_iface = g_type_interface_peek_parent (config_iface);

  if (! parent_config_iface)
    parent_config_iface = g_type_default_interface_peek (GIMP_TYPE_CONFIG);

  config_iface->duplicate = gimp_paint_options_duplicate;
454
  config_iface->copy      = gimp_paint_options_copy;
455
  config_iface->reset     = gimp_paint_options_reset;
456 457
}

458 459 460
static void
gimp_paint_options_init (GimpPaintOptions *options)
{
461
  options->application_mode_save = DEFAULT_APPLICATION_MODE;
462

463
  options->jitter_options    = g_slice_new0 (GimpJitterOptions);
464
  options->fade_options      = g_slice_new0 (GimpFadeOptions);
465
  options->gradient_options  = g_slice_new0 (GimpGradientPaintOptions);
466
  options->smoothing_options = g_slice_new0 (GimpSmoothingOptions);
467 468
}

469
static void
470
gimp_paint_options_dispose (GObject *object)
471 472 473
{
  GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);

474
  g_clear_object (&options->paint_info);
475 476 477 478 479 480 481 482

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

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

484 485 486 487
  g_slice_free (GimpJitterOptions,        options->jitter_options);
  g_slice_free (GimpFadeOptions,          options->fade_options);
  g_slice_free (GimpGradientPaintOptions, options->gradient_options);
  g_slice_free (GimpSmoothingOptions,     options->smoothing_options);
488 489 490 491

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

492 493 494 495 496
static void
gimp_paint_options_set_property (GObject      *object,
                                 guint         property_id,
                                 const GValue *value,
                                 GParamSpec   *pspec)
497
{
498 499 500 501 502
  GimpPaintOptions         *options           = GIMP_PAINT_OPTIONS (object);
  GimpFadeOptions          *fade_options      = options->fade_options;
  GimpJitterOptions        *jitter_options    = options->jitter_options;
  GimpGradientPaintOptions *gradient_options  = options->gradient_options;
  GimpSmoothingOptions     *smoothing_options = options->smoothing_options;
503

504 505
  switch (property_id)
    {
506
    case PROP_PAINT_INFO:
507
      options->paint_info = g_value_dup_object (value);
508 509
      break;

510 511 512 513
    case PROP_USE_APPLICATOR:
      options->use_applicator = g_value_get_boolean (value);
      break;

514 515
    case PROP_BRUSH_SIZE:
      options->brush_size = g_value_get_double (value);
516
      break;
517 518 519
    case PROP_BRUSH_ASPECT_RATIO:
      options->brush_aspect_ratio = g_value_get_double (value);
      break;
520
    case PROP_BRUSH_ANGLE:
521
      options->brush_angle = - 1.0 * g_value_get_double (value) / 360.0; /* let's make the angle mathematically correct */
522
      break;
523 524 525
    case PROP_BRUSH_SPACING:
      options->brush_spacing = g_value_get_double (value);
      break;
526 527 528 529 530 531 532
    case PROP_BRUSH_HARDNESS:
      options->brush_hardness = g_value_get_double (value);
      break;
    case PROP_BRUSH_FORCE:
      options->brush_force = g_value_get_double (value);
      break;

533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
    case PROP_BRUSH_LINK_SIZE:
      options->brush_link_size = g_value_get_boolean (value);
      break;
    case PROP_BRUSH_LINK_ASPECT_RATIO:
      options->brush_link_aspect_ratio = g_value_get_boolean (value);
      break;
    case PROP_BRUSH_LINK_ANGLE:
      options->brush_link_angle = g_value_get_boolean (value);
      break;
    case PROP_BRUSH_LINK_SPACING:
      options->brush_link_spacing = g_value_get_boolean (value);
      break;
    case PROP_BRUSH_LINK_HARDNESS:
      options->brush_link_hardness = g_value_get_boolean (value);
      break;

549 550 551 552
    case PROP_BRUSH_LOCK_TO_VIEW:
      options->brush_lock_to_view = g_value_get_boolean (value);
      break;

553 554
    case PROP_APPLICATION_MODE:
      options->application_mode = g_value_get_enum (value);
555
      break;
556 557 558
    case PROP_HARD:
      options->hard = g_value_get_boolean (value);
      break;
559

560 561 562 563 564 565 566 567 568
    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);
569 570
      break;

571
    case PROP_FADE_LENGTH:
572
      fade_options->fade_length = g_value_get_double (value);
573
      break;
574 575 576 577 578 579
    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;
580
    case PROP_FADE_UNIT:
581
      fade_options->fade_unit = g_value_get_int (value);
582 583
      break;

584 585 586
    case PROP_GRADIENT_REVERSE:
      gradient_options->gradient_reverse = g_value_get_boolean (value);
      break;
587 588 589
    case PROP_GRADIENT_BLEND_COLOR_SPACE:
      gradient_options->gradient_blend_color_space = g_value_get_enum (value);
      break;
590 591 592
    case PROP_GRADIENT_REPEAT:
      gradient_options->gradient_repeat = g_value_get_enum (value);
      break;
593

594 595 596 597 598 599 600
    case PROP_BRUSH_VIEW_TYPE:
      options->brush_view_type = g_value_get_enum (value);
      break;
    case PROP_BRUSH_VIEW_SIZE:
      options->brush_view_size = g_value_get_int (value);
      break;

601 602 603 604 605 606 607
    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;

608 609 610 611 612 613 614 615 616 617 618 619 620 621
    case PROP_PATTERN_VIEW_TYPE:
      options->pattern_view_type = g_value_get_enum (value);
      break;
    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;
    case PROP_GRADIENT_VIEW_SIZE:
      options->gradient_view_size = g_value_get_int (value);
      break;

622 623 624
    case PROP_USE_SMOOTHING:
      smoothing_options->use_smoothing = g_value_get_boolean (value);
      break;
625 626
    case PROP_SMOOTHING_QUALITY:
      smoothing_options->smoothing_quality = g_value_get_int (value);
627 628 629 630 631
      break;
    case PROP_SMOOTHING_FACTOR:
      smoothing_options->smoothing_factor = g_value_get_double (value);
      break;

632 633 634 635
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
636 637
}

638 639 640 641 642 643
static void
gimp_paint_options_get_property (GObject    *object,
                                 guint       property_id,
                                 GValue     *value,
                                 GParamSpec *pspec)
{
644 645 646 647 648
  GimpPaintOptions         *options           = GIMP_PAINT_OPTIONS (object);
  GimpFadeOptions          *fade_options      = options->fade_options;
  GimpJitterOptions        *jitter_options    = options->jitter_options;
  GimpGradientPaintOptions *gradient_options  = options->gradient_options;
  GimpSmoothingOptions     *smoothing_options = options->smoothing_options;
649

650 651
  switch (property_id)
    {
652 653 654 655
    case PROP_PAINT_INFO:
      g_value_set_object (value, options->paint_info);
      break;

656 657 658 659
    case PROP_USE_APPLICATOR:
      g_value_set_boolean (value, options->use_applicator);
      break;

660 661
    case PROP_BRUSH_SIZE:
      g_value_set_double (value, options->brush_size);
662
      break;
663 664 665
    case PROP_BRUSH_ASPECT_RATIO:
      g_value_set_double (value, options->brush_aspect_ratio);
      break;
666
    case PROP_BRUSH_ANGLE:
667
      g_value_set_double (value, - 1.0 * options->brush_angle * 360.0); /* mathematically correct -> intuitively correct */
668
      break;
669 670 671
    case PROP_BRUSH_SPACING:
      g_value_set_double (value, options->brush_spacing);
      break;
672 673 674 675 676 677 678
    case PROP_BRUSH_HARDNESS:
      g_value_set_double (value, options->brush_hardness);
      break;
    case PROP_BRUSH_FORCE:
      g_value_set_double (value, options->brush_force);
      break;

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
    case PROP_BRUSH_LINK_SIZE:
      g_value_set_boolean (value, options->brush_link_size);
      break;
    case PROP_BRUSH_LINK_ASPECT_RATIO:
      g_value_set_boolean (value, options->brush_link_aspect_ratio);
      break;
    case PROP_BRUSH_LINK_ANGLE:
      g_value_set_boolean (value, options->brush_link_angle);
      break;
    case PROP_BRUSH_LINK_SPACING:
      g_value_set_boolean (value, options->brush_link_spacing);
      break;
    case PROP_BRUSH_LINK_HARDNESS:
      g_value_set_boolean (value, options->brush_link_hardness);
      break;

695 696 697 698
    case PROP_BRUSH_LOCK_TO_VIEW:
      g_value_set_boolean (value, options->brush_lock_to_view);
      break;

699 700
    case PROP_APPLICATION_MODE:
      g_value_set_enum (value, options->application_mode);
701
      break;
702 703 704
    case PROP_HARD:
      g_value_set_boolean (value, options->hard);
      break;
705

706 707 708 709 710 711 712 713 714
    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);
715 716
      break;

717 718 719
    case PROP_FADE_LENGTH:
      g_value_set_double (value, fade_options->fade_length);
      break;
720 721 722 723 724 725
    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;
726 727 728 729
    case PROP_FADE_UNIT:
      g_value_set_int (value, fade_options->fade_unit);
      break;

730
    case PROP_GRADIENT_REVERSE:
731
      g_value_set_boolean (value, gradient_options->gradient_reverse);
732
      break;
733 734 735
    case PROP_GRADIENT_BLEND_COLOR_SPACE:
      g_value_set_enum (value, gradient_options->gradient_blend_color_space);
      break;
736 737 738
    case PROP_GRADIENT_REPEAT:
      g_value_set_enum (value, gradient_options->gradient_repeat);
      break;
739 740

    case PROP_BRUSH_VIEW_TYPE:
741
      g_value_set_enum (value, options->brush_view_type);
742 743
      break;
    case PROP_BRUSH_VIEW_SIZE:
744
      g_value_set_int (value, options->brush_view_size);
745 746
      break;

747 748 749 750 751 752 753
    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;

754
    case PROP_PATTERN_VIEW_TYPE:
755
      g_value_set_enum (value, options->pattern_view_type);
756 757
      break;
    case PROP_PATTERN_VIEW_SIZE:
758
      g_value_set_int (value, options->pattern_view_size);
759 760 761
      break;

    case PROP_GRADIENT_VIEW_TYPE:
762
      g_value_set_enum (value, options->gradient_view_type);
763 764
      break;
    case PROP_GRADIENT_VIEW_SIZE:
765
      g_value_set_int (value, options->gradient_view_size);
766
      break;
767

768
    case PROP_USE_SMOOTHING:
769
      g_value_set_boolean (value, smoothing_options->use_smoothing);
770
      break;
771 772
    case PROP_SMOOTHING_QUALITY:
      g_value_set_int (value, smoothing_options->smoothing_quality);
773 774 775 776
      break;
    case PROP_SMOOTHING_FACTOR:
      g_value_set_double (value, smoothing_options->smoothing_factor);
      break;
777 778 779 780 781 782 783

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

784 785 786 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 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
static void
gimp_paint_options_brush_changed (GimpContext *context,
                                  GimpBrush   *brush)
{
  GimpPaintOptions *options = GIMP_PAINT_OPTIONS (context);

  if (options->paint_info &&
      g_type_is_a (options->paint_info->paint_type,
                   GIMP_TYPE_BRUSH_CORE))
    {
      if (options->brush)
        {
          g_signal_handlers_disconnect_by_func (options->brush,
                                                gimp_paint_options_brush_notify,
                                                options);
          g_object_remove_weak_pointer (G_OBJECT (options->brush),
                                        (gpointer) &options->brush);
        }

      options->brush = brush;

      if (options->brush)
        {
          g_object_add_weak_pointer (G_OBJECT (options->brush),
                                     (gpointer) &options->brush);
          g_signal_connect_object (options->brush, "notify",
                                   G_CALLBACK (gimp_paint_options_brush_notify),
                                   options, 0);

          gimp_paint_options_brush_notify (options->brush, NULL, options);
        }
    }
}

static void
gimp_paint_options_brush_notify (GimpBrush        *brush,
                                 const GParamSpec *pspec,
                                 GimpPaintOptions *options)
{
  if (gimp_tool_options_get_gui_mode (GIMP_TOOL_OPTIONS (options)))
    {
#define IS_PSPEC(p,n) (p == NULL || ! strcmp (n, p->name))

      if (options->brush_link_size && IS_PSPEC (pspec, "radius"))
        gimp_paint_options_set_default_brush_size (options, brush);

      if (options->brush_link_aspect_ratio && IS_PSPEC (pspec, "aspect-ratio"))
        gimp_paint_options_set_default_brush_aspect_ratio (options, brush);

      if (options->brush_link_angle && IS_PSPEC (pspec, "angle"))
        gimp_paint_options_set_default_brush_angle (options, brush);

      if (options->brush_link_spacing && IS_PSPEC (pspec, "spacing"))
        gimp_paint_options_set_default_brush_spacing (options, brush);

      if (options->brush_link_hardness && IS_PSPEC (pspec, "hardness"))
        gimp_paint_options_set_default_brush_hardness (options, brush);

#undef IS_SPEC
    }
}

846 847 848
static GimpConfig *
gimp_paint_options_duplicate (GimpConfig *config)
{
849
  return parent_config_iface->duplicate (config);
850 851
}

852 853 854 855 856
static gboolean
gimp_paint_options_copy (GimpConfig  *src,
                         GimpConfig  *dest,
                         GParamFlags  flags)
{
857
  return parent_config_iface->copy (src, dest, flags);
858
}
859

860 861 862 863 864 865 866 867
static void
gimp_paint_options_reset (GimpConfig *config)
{
  GimpBrush *brush = gimp_context_get_brush (GIMP_CONTEXT (config));

  parent_config_iface->reset (config);

  if (brush)
868 869 870 871 872 873 874 875 876 877 878 879
    {
      gimp_paint_options_set_default_brush_size (GIMP_PAINT_OPTIONS (config),
                                                 brush);
      gimp_paint_options_set_default_brush_hardness (GIMP_PAINT_OPTIONS (config),
                                                     brush);
      gimp_paint_options_set_default_brush_aspect_ratio (GIMP_PAINT_OPTIONS (config),
                                                         brush);
      gimp_paint_options_set_default_brush_angle (GIMP_PAINT_OPTIONS (config),
                                                  brush);
      gimp_paint_options_set_default_brush_spacing (GIMP_PAINT_OPTIONS (config),
                                                    brush);
    }
880 881
}

882
GimpPaintOptions *
883
gimp_paint_options_new (GimpPaintInfo *paint_info)
884
{
885 886
  GimpPaintOptions *options;

887
  g_return_val_if_fail (GIMP_IS_PAINT_INFO (paint_info), NULL);
888

889 890
  options = g_object_new (paint_info->paint_options_type,
                          "gimp",       paint_info->gimp,
891
                          "name",       gimp_object_get_name (paint_info),
892
                          "paint-info", paint_info,
893 894 895
                          NULL);

  return options;
896
}
897

898 899
gdouble
gimp_paint_options_get_fade (GimpPaintOptions *paint_options,
900
                             GimpImage        *image,
901 902 903
                             gdouble           pixel_dist)
{
  GimpFadeOptions *fade_options;
904 905 906 907
  gdouble          z        = -1.0;
  gdouble          fade_out =  0.0;
  gdouble          unit_factor;
  gdouble          pos;
908

909
  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options),
910 911
                        DYNAMIC_MAX_VALUE);
  g_return_val_if_fail (GIMP_IS_IMAGE (image), DYNAMIC_MAX_VALUE);
912 913 914

  fade_options = paint_options->fade_options;

915
  switch (fade_options->fade_unit)
916
    {
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
    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;
939 940
    }

941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
  /*  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)  */
965 966
}

967 968
gdouble
gimp_paint_options_get_jitter (GimpPaintOptions *paint_options,
969
                               GimpImage        *image)
970 971 972
{
  GimpJitterOptions *jitter_options;

973 974
  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), 0.0);

975 976 977
  jitter_options = paint_options->jitter_options;

  if (jitter_options->use_jitter)
Alexia Death's avatar
Alexia Death committed
978 979 980 981
    {
      return jitter_options->jitter_amount;
    }

982 983 984
  return 0.0;
}

985 986
gboolean
gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
987
                                       GimpImage        *image,
988
                                       gdouble           grad_point,
989 990 991
                                       gdouble           pixel_dist,
                                       GimpRGB          *color)
{
992
  GimpDynamics *dynamics;
993 994

  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
995
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
996 997
  g_return_val_if_fail (color != NULL, FALSE);

Alexia Death's avatar
Alexia Death committed
998 999
  dynamics = gimp_context_get_dynamics (GIMP_CONTEXT (paint_options));

1000
  if (gimp_dynamics_is_output_enabled (dynamics, GIMP_DYNAMICS_OUTPUT_COLOR))
1001
    {
1002 1003
      GimpGradientPaintOptions *gradient_options = paint_options->gradient_options;
      GimpGradient             *gradient;
1004 1005 1006

      gradient = gimp_context_get_gradient (GIMP_CONTEXT (paint_options));

1007
      gimp_gradient_get_color_at (gradient, GIMP_CONTEXT (paint_options),
1008
                                  NULL, grad_point,
1009
                                  gradient_options->gradient_reverse,
1010
                                  gradient_options->gradient_blend_color_space,
1011 1012 1013 1014 1015 1016 1017 1018
                                  color);

      return TRUE;
    }

  return FALSE;
}

1019 1020 1021
GimpBrushApplicationMode
gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options)
{
1022 1023
  GimpDynamics *dynamics;
  gboolean      dynamic_force = FALSE;
1024

1025 1026 1027 1028 1029
  g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), GIMP_BRUSH_SOFT);

  if (paint_options->hard)
    return GIMP_BRUSH_HARD;

1030 1031
  dynamics = gimp_context_get_dynamics (GIMP_CONTEXT (paint_options));

1032 1033
  dynamic_force = gimp_dynamics_is_output_enabled (dynamics,
                                                   GIMP_DYNAMICS_OUTPUT_FORCE);
1034

Ell's avatar
Ell committed
1035
  if (dynamic_force || (paint_options->brush_force != 0.5))
1036
    return GIMP_BRUSH_PRESSURE;
1037

1038 1039
  return GIMP_BRUSH_SOFT;
}
1040

1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
void
gimp_paint_options_set_default_brush_size (GimpPaintOptions *paint_options,
                                           GimpBrush        *brush)
{
  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
  g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));

  if (! brush)
    brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));

  if (brush)
    {
      gint height;
      gint width;

1056
      gimp_brush_transform_size (brush, 1.0, 0.0, 0.0, FALSE, &height, &width);
1057 1058 1059 1060 1061 1062 1063

      g_object_set (paint_options,
                    "brush-size", (gdouble) MAX (height, width),
                    NULL);
    }
}

1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
void
gimp_paint_options_set_default_brush_angle (GimpPaintOptions *paint_options,
                                            GimpBrush        *brush)
{
  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
  g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));

  if (! brush)
    brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));

  if (GIMP_IS_BRUSH_GENERATED (brush))
    {
      GimpBrushGenerated *generated_brush = GIMP_BRUSH_GENERATED (brush);

      g_object_set (paint_options,
                    "brush-angle", (gdouble) gimp_brush_generated_get_angle (generated_brush),
                    NULL);
    }
  else
    {
      g_object_set (paint_options,
                    "brush-angle", DEFAULT_BRUSH_ANGLE,
                    NULL);
    }
}

void
gimp_paint_options_set_default_brush_aspect_ratio (GimpPaintOptions *paint_options,
                                                   GimpBrush        *brush)
{
  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
  g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));

  if (! brush)
    brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));

  if (GIMP_IS_BRUSH_GENERATED (brush))
    {
      GimpBrushGenerated *generated_brush = GIMP_BRUSH_GENERATED (brush);
      gdouble             ratio;

      ratio = gimp_brush_generated_get_aspect_ratio (generated_brush);

      ratio = (ratio - 1.0) * 20.0 / 19.0;

      g_object_set (paint_options,
                    "brush-aspect-ratio", ratio,
                    NULL);
    }
  else
    {
      g_object_set (paint_options,
                    "brush-aspect-ratio", DEFAULT_BRUSH_ASPECT_RATIO,
                    NULL);
    }
}

1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
void
gimp_paint_options_set_default_brush_spacing (GimpPaintOptions *paint_options,
                                              GimpBrush        *brush)
{
  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
  g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));

  if (! brush)
    brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));

  if (brush)
    {
      g_object_set (paint_options,
1134
                    "brush-spacing", (gdouble) gimp_brush_get_spacing (brush) / 100.0,
1135 1136 1137 1138
                    NULL);
    }
}

1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
void
gimp_paint_options_set_default_brush_hardness (GimpPaintOptions *paint_options,
                                               GimpBrush        *brush)
{
  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
  g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));

  if (! brush)
    brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));

1149
  if (GIMP_IS_BRUSH_GENERATED (brush))
1150
    {
1151
      GimpBrushGenerated *generated_brush = GIMP_BRUSH_GENERATED (brush);
1152 1153

      g_object_set (paint_options,
1154
                    "brush-hardness", (gdouble) gimp_brush_generated_get_hardness (generated_brush),
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
                    NULL);
    }
  else
    {
      g_object_set (paint_options,
                    "brush-hardness", DEFAULT_BRUSH_HARDNESS,
                    NULL);
    }
}

1165
static const gchar *brush_props[] =
1166
{
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
  "brush-size",
  "brush-angle",
  "brush-aspect-ratio",
  "brush-spacing",
  "brush-hardness",
  "brush-force",
  "brush-link-size",
  "brush-link-angle",
  "brush-link-aspect-ratio",
  "brush-link-spacing",
  "brush-link-hardness",
  "brush-lock-to-view"
};
1180

1181 1182 1183 1184 1185 1186 1187 1188
static const gchar *dynamics_props[] =
{
  "dynamics-expanded",
  "fade-reverse",
  "fade-length",
  "fade-unit",
  "fade-repeat"
};
1189

1190 1191 1192
static const gchar *gradient_props[] =
{
  "gradient-reverse",
1193 1194
  "gradient-blend-color-space",
  "gradient-repeat"
1195
};
1196

1197 1198 1199
static const gint max_n_props = (G_N_ELEMENTS (brush_props) +
                                 G_N_ELEMENTS (dynamics_props) +
                                 G_N_ELEMENTS (gradient_props));
1200

1201 1202 1203
gboolean
gimp_paint_options_is_prop (const gchar         *prop_name,
                            GimpContextPropMask  prop_mask)
1204
{
1205
  gint i;
1206

1207
  g_return_val_if_fail (prop_name != NULL, FALSE);
1208

1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
  if (prop_mask & GIMP_CONTEXT_PROP_MASK_BRUSH)
    {
      for (i = 0; i < G_N_ELEMENTS (brush_props); i++)
        if (! strcmp (prop_name, brush_props[i]))
          return TRUE;
    }

  if (prop_mask & GIMP_CONTEXT_PROP_MASK_DYNAMICS)
    {
      for (i = 0; i < G_N_ELEMENTS (dynamics_props); i++)
        if (! strcmp (prop_name, dynamics_props[i]))
          return TRUE;
    }

  if (prop_mask & GIMP_CONTEXT_PROP_MASK_GRADIENT)
    {
      for (i = 0; i < G_N_ELEMENTS (gradient_props); i++)
        if (! strcmp (prop_name, gradient_props[i]))
          return TRUE;
    }

  return FALSE;
1231 1232 1233
}

void
1234 1235 1236
gimp_paint_options_copy_props (GimpPaintOptions    *src,
                               GimpPaintOptions    *dest,
                               GimpContextPropMask  prop_mask)
1237
{
1238 1239 1240 1241
  const gchar *names[max_n_props];
  GValue       values[max_n_props];
  gint         n_props = 0;
  gint         i;
1242 1243 1244 1245

  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (dest));

1246 1247 1248 1249 1250
  if (prop_mask & GIMP_CONTEXT_PROP_MASK_BRUSH)
    {
      for (i = 0; i < G_N_ELEMENTS (brush_props); i++)
        names[n_props++] = brush_props[i];
    }
1251

1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
  if (prop_mask & GIMP_CONTEXT_PROP_MASK_DYNAMICS)
    {
      for (i = 0; i < G_N_ELEMENTS (dynamics_props); i++)
        names[n_props++] = dynamics_props[i];
    }

  if (prop_mask & GIMP_CONTEXT_PROP_MASK_GRADIENT)
    {
      for (i = 0; i < G_N_ELEMENTS (gradient_props); i++)
        names[n_props++] = gradient_props[i];
    }

  if (n_props > 0)
    {
      g_object_getv (G_OBJECT (src), n_props, names, values);
      g_object_setv (G_OBJECT (dest), n_props, names, values);

      while (n_props--)
        g_value_unset (&values[n_props]);
    }
1272
}