gimpblendoptions.c 9.94 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 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 <gtk/gtk.h>

23
#include "libgimpconfig/gimpconfig.h"
24 25 26 27
#include "libgimpwidgets/gimpwidgets.h"

#include "tools-types.h"

28
#include "core/gimpdatafactory.h"
29

30
#include "widgets/gimppropwidgets.h"
31
#include "widgets/gimpviewablebox.h"
32 33

#include "gimpblendoptions.h"
34
#include "gimppaintoptions-gui.h"
35

36
#include "gimp-intl.h"
37 38


39 40 41 42 43
enum
{
  PROP_0,
  PROP_OFFSET,
  PROP_GRADIENT_TYPE,
44
  PROP_GRADIENT_REPEAT,  /*  overrides a GimpPaintOptions property  */
45 46
  PROP_SUPERSAMPLE,
  PROP_SUPERSAMPLE_DEPTH,
47 48
  PROP_SUPERSAMPLE_THRESHOLD,
  PROP_DITHER
49 50 51
};


52 53 54 55 56 57 58 59
static void   gimp_blend_options_set_property    (GObject          *object,
                                                  guint             property_id,
                                                  const GValue     *value,
                                                  GParamSpec       *pspec);
static void   gimp_blend_options_get_property    (GObject          *object,
                                                  guint             property_id,
                                                  GValue           *value,
                                                  GParamSpec       *pspec);
60

61 62
static void   blend_options_gradient_type_notify (GimpBlendOptions *options,
                                                  GParamSpec       *pspec,
63
                                                  GtkWidget        *repeat_combo);
64 65


66
G_DEFINE_TYPE (GimpBlendOptions, gimp_blend_options, GIMP_TYPE_PAINT_OPTIONS)
67 68


69
static void
70 71
gimp_blend_options_class_init (GimpBlendOptionsClass *klass)
{
72
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
73 74 75 76 77 78 79

  object_class->set_property = gimp_blend_options_set_property;
  object_class->get_property = gimp_blend_options_get_property;

  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_OFFSET,
                                   "offset", NULL,
                                   0.0, 100.0, 0.0,
80
                                   GIMP_PARAM_STATIC_STRINGS);
81 82 83
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_GRADIENT_TYPE,
                                 "gradient-type", NULL,
                                 GIMP_TYPE_GRADIENT_TYPE,
84
                                 GIMP_GRADIENT_LINEAR,
85
                                 GIMP_PARAM_STATIC_STRINGS);
86 87 88 89
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_GRADIENT_REPEAT,
                                 "gradient-repeat", NULL,
                                 GIMP_TYPE_REPEAT_MODE,
                                 GIMP_REPEAT_NONE,
90
                                 GIMP_PARAM_STATIC_STRINGS);
91 92 93 94

  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_SUPERSAMPLE,
                                    "supersample", NULL,
                                    FALSE,
95
                                    GIMP_PARAM_STATIC_STRINGS);
96 97
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_SUPERSAMPLE_DEPTH,
                                "supersample-depth", NULL,
98
                                0, 6, 3,
99
                                GIMP_PARAM_STATIC_STRINGS);
100 101 102
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_SUPERSAMPLE_THRESHOLD,
                                   "supersample-threshold", NULL,
                                   0.0, 4.0, 0.2,
103
                                   GIMP_PARAM_STATIC_STRINGS);
104 105 106 107

  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_DITHER,
                                    "dither", NULL,
                                    TRUE,
108
                                    GIMP_PARAM_STATIC_STRINGS);
109 110
}

111 112 113 114 115
static void
gimp_blend_options_init (GimpBlendOptions *options)
{
}

116 117 118 119 120 121
static void
gimp_blend_options_set_property (GObject      *object,
                                 guint         property_id,
                                 const GValue *value,
                                 GParamSpec   *pspec)
{
122
  GimpBlendOptions *options = GIMP_BLEND_OPTIONS (object);
123 124 125 126 127 128 129 130 131

  switch (property_id)
    {
    case PROP_OFFSET:
      options->offset = g_value_get_double (value);
      break;
    case PROP_GRADIENT_TYPE:
      options->gradient_type = g_value_get_enum (value);
      break;
132 133 134 135
    case PROP_GRADIENT_REPEAT:
      GIMP_PAINT_OPTIONS (options)->gradient_options->gradient_repeat =
        g_value_get_enum (value);
      break;
136 137 138 139 140 141 142 143 144 145 146

    case PROP_SUPERSAMPLE:
      options->supersample = g_value_get_boolean (value);
      break;
    case PROP_SUPERSAMPLE_DEPTH:
      options->supersample_depth = g_value_get_int (value);
      break;
    case PROP_SUPERSAMPLE_THRESHOLD:
      options->supersample_threshold = g_value_get_double (value);
      break;

147 148 149
    case PROP_DITHER:
      options->dither = g_value_get_boolean (value);
      break;
150

151 152 153 154 155 156 157 158 159 160 161 162
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_blend_options_get_property (GObject    *object,
                                 guint       property_id,
                                 GValue     *value,
                                 GParamSpec *pspec)
{
163
  GimpBlendOptions *options = GIMP_BLEND_OPTIONS (object);
164 165 166 167 168 169 170 171 172

  switch (property_id)
    {
    case PROP_OFFSET:
      g_value_set_double (value, options->offset);
      break;
    case PROP_GRADIENT_TYPE:
      g_value_set_enum (value, options->gradient_type);
      break;
173 174 175 176
    case PROP_GRADIENT_REPEAT:
      g_value_set_enum (value,
                        GIMP_PAINT_OPTIONS (options)->gradient_options->gradient_repeat);
      break;
177 178 179 180 181 182 183 184 185 186 187

    case PROP_SUPERSAMPLE:
      g_value_set_boolean (value, options->supersample);
      break;
    case PROP_SUPERSAMPLE_DEPTH:
      g_value_set_int (value, options->supersample_depth);
      break;
    case PROP_SUPERSAMPLE_THRESHOLD:
      g_value_set_double (value, options->supersample_threshold);
      break;

188 189 190
    case PROP_DITHER:
      g_value_set_boolean (value, options->dither);
      break;
191

192 193 194 195
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
196 197
}

198
GtkWidget *
199 200
gimp_blend_options_gui (GimpToolOptions *tool_options)
{
201
  GObject   *config = G_OBJECT (tool_options);
202
  GtkWidget *vbox   = gimp_paint_options_gui (tool_options);
203
  GtkWidget *vbox2;
204
  GtkWidget *frame;
205
  GtkWidget *scale;
206
  GtkWidget *combo;
207
  GtkWidget *button;
208

209
  /*  the gradient  */
210 211
  button = gimp_prop_gradient_box_new (NULL, GIMP_CONTEXT (tool_options),
                                       _("Gradient"), 2,
212 213
                                       "gradient-view-type",
                                       "gradient-view-size",
214 215
                                       "gradient-reverse",
                                       "gimp-gradient-editor");
216
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
217
  gtk_widget_show (button);
218

219
  /*  the gradient type menu  */
220
  combo = gimp_prop_enum_combo_box_new (config, "gradient-type", 0, 0);
221
  gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (combo), _("Shape"));
222
  g_object_set (combo, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
223 224
  gimp_enum_combo_box_set_icon_prefix (GIMP_ENUM_COMBO_BOX (combo),
                                       "gimp-gradient");
225 226
  gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
  gtk_widget_show (combo);
227 228

  /*  the repeat option  */
229
  combo = gimp_prop_enum_combo_box_new (config, "gradient-repeat", 0, 0);
230
  gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (combo), _("Repeat"));
231
  g_object_set (combo, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
232 233
  gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
  gtk_widget_show (combo);
234

235
  g_signal_connect (config, "notify::gradient-type",
236
                    G_CALLBACK (blend_options_gradient_type_notify),
237
                    combo);
238

239 240 241 242
  /*  the offset scale  */
  scale = gimp_prop_spin_scale_new (config, "offset",
                                    _("Offset"),
                                    1.0, 10.0, 1);
243
  gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
244 245 246
  gtk_widget_show (scale);

  /*  the dither toggle  */
247 248 249 250
  button = gimp_prop_check_button_new (config, "dither",
                                       _("Dithering"));
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_widget_show (button);
251

252
  /*  supersampling options  */
Michael Natterer's avatar
Michael Natterer committed
253
  vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
254 255
  frame = gimp_prop_expanding_frame_new (config, "supersample",
                                         _("Adaptive supersampling"),
256
                                         vbox2, NULL);
257 258
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
259

260
  /*  max depth scale  */
261 262 263 264 265
  scale = gimp_prop_spin_scale_new (config, "supersample-depth",
                                    _("Max depth"),
                                    1.0, 1.0, 0);
  gtk_box_pack_start (GTK_BOX (vbox2), scale, FALSE, FALSE, 0);
  gtk_widget_show (scale);
266

267
  /*  threshold scale  */
268 269 270 271 272
  scale = gimp_prop_spin_scale_new (config, "supersample-threshold",
                                    _("Threshold"),
                                    0.01, 0.1, 2);
  gtk_box_pack_start (GTK_BOX (vbox2), scale, FALSE, FALSE, 0);
  gtk_widget_show (scale);
273 274

  return vbox;
275 276 277
}

static void
278 279
blend_options_gradient_type_notify (GimpBlendOptions *options,
                                    GParamSpec       *pspec,
280
                                    GtkWidget        *repeat_combo)
281
{
282
  gtk_widget_set_sensitive (repeat_combo, options->gradient_type < 6);
283
}