gimptransformoptions.c 15.2 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

#include <gtk/gtk.h>

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

Michael Natterer's avatar
Michael Natterer committed
26 27
#include "tools-types.h"

28 29
#include "config/gimpcoreconfig.h"

30
#include "core/gimp.h"
Michael Natterer's avatar
Michael Natterer committed
31
#include "core/gimptoolinfo.h"
32

33
#include "widgets/gimpwidgets-utils.h"
34

35 36
#include "gimprotatetool.h"
#include "gimpscaletool.h"
37
#include "gimptooloptions-gui.h"
38
#include "gimptransformoptions.h"
39

40
#include "gimp-intl.h"
41 42


43 44 45
enum
{
  PROP_0,
46
  PROP_TYPE,
47 48
  PROP_DIRECTION,
  PROP_INTERPOLATION,
49
  PROP_CLIP,
50
  PROP_PREVIEW_TYPE,
51
  PROP_PREVIEW_OPACITY,
52 53
  PROP_GRID_TYPE,
  PROP_GRID_SIZE,
54
  PROP_CONSTRAIN,
55 56
};

57

58 59 60 61 62 63 64 65
static void   gimp_transform_options_set_property   (GObject         *object,
                                                     guint            property_id,
                                                     const GValue    *value,
                                                     GParamSpec      *pspec);
static void   gimp_transform_options_get_property   (GObject         *object,
                                                     guint            property_id,
                                                     GValue          *value,
                                                     GParamSpec      *pspec);
66

67
static void   gimp_transform_options_reset          (GimpToolOptions *tool_options);
68

69 70
static void   gimp_transform_options_preview_notify (GimpTransformOptions *options,
                                                     GParamSpec           *pspec,
71 72 73 74 75
                                                     GtkWidget            *box);

static void   gimp_transform_options_preview_opacity_notify (GimpTransformOptions *options,
                                                     GParamSpec           *pspec,
                                                     GtkWidget            *table);
76 77


78
G_DEFINE_TYPE (GimpTransformOptions, gimp_transform_options,
79
               GIMP_TYPE_TOOL_OPTIONS)
80

81
#define parent_class gimp_transform_options_parent_class
82 83


84
static void
85
gimp_transform_options_class_init (GimpTransformOptionsClass *klass)
86
{
87 88
  GObjectClass         *object_class  = G_OBJECT_CLASS (klass);
  GimpToolOptionsClass *options_class = GIMP_TOOL_OPTIONS_CLASS (klass);
89 90 91 92 93 94

  object_class->set_property = gimp_transform_options_set_property;
  object_class->get_property = gimp_transform_options_get_property;

  options_class->reset       = gimp_transform_options_reset;

95 96 97 98
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_TYPE,
                                 "type", NULL,
                                 GIMP_TYPE_TRANSFORM_TYPE,
                                 GIMP_TRANSFORM_TYPE_LAYER,
99
                                 GIMP_PARAM_STATIC_STRINGS);
100 101 102 103
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_DIRECTION,
                                 "direction", NULL,
                                 GIMP_TYPE_TRANSFORM_DIRECTION,
                                 GIMP_TRANSFORM_FORWARD,
104
                                 GIMP_PARAM_STATIC_STRINGS);
105 106 107
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_INTERPOLATION,
                                 "interpolation", NULL,
                                 GIMP_TYPE_INTERPOLATION_TYPE,
108
                                 GIMP_INTERPOLATION_LINEAR,
109
                                 GIMP_PARAM_STATIC_STRINGS);
110 111 112 113 114
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_CLIP,
                                 "clip", NULL,
                                 GIMP_TYPE_TRANSFORM_RESIZE,
                                 GIMP_TRANSFORM_RESIZE_ADJUST,
                                 GIMP_PARAM_STATIC_STRINGS);
115 116 117 118
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_PREVIEW_TYPE,
                                 "preview-type", NULL,
                                 GIMP_TYPE_TRANSFORM_PREVIEW_TYPE,
                                 GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE,
119
                                 GIMP_PARAM_STATIC_STRINGS);
120 121 122 123
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_PREVIEW_OPACITY,
                                   "preview-opacity", NULL,
                                   0.0, 1.0, 1.0,
                                GIMP_PARAM_STATIC_STRINGS);
124 125 126 127
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_GRID_TYPE,
                                 "grid-type", NULL,
                                 GIMP_TYPE_TRANSFORM_GRID_TYPE,
                                 GIMP_TRANSFORM_GRID_TYPE_N_LINES,
128
                                 GIMP_PARAM_STATIC_STRINGS);
129 130 131
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_GRID_SIZE,
                                "grid-size", NULL,
                                1, 128, 15,
132
                                GIMP_PARAM_STATIC_STRINGS);
133 134
  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_CONSTRAIN,
                                    "constrain", NULL,
135
                                    FALSE,
136
                                    GIMP_PARAM_STATIC_STRINGS);
137
}
138

139 140 141
static void
gimp_transform_options_init (GimpTransformOptions *options)
{
142
  options->recursion_level = 3;
143 144
}

145 146 147 148 149 150
static void
gimp_transform_options_set_property (GObject      *object,
                                     guint         property_id,
                                     const GValue *value,
                                     GParamSpec   *pspec)
{
151
  GimpTransformOptions *options = GIMP_TRANSFORM_OPTIONS (object);
152 153 154

  switch (property_id)
    {
155 156 157
    case PROP_TYPE:
      options->type = g_value_get_enum (value);
      break;
158 159 160 161 162 163
    case PROP_DIRECTION:
      options->direction = g_value_get_enum (value);
      break;
    case PROP_INTERPOLATION:
      options->interpolation = g_value_get_enum (value);
      break;
164
    case PROP_CLIP:
165
      options->clip = g_value_get_enum (value);
166
      break;
167 168
    case PROP_PREVIEW_TYPE:
      options->preview_type = g_value_get_enum (value);
169
      break;
170 171 172
    case PROP_PREVIEW_OPACITY:
      options->preview_opacity = g_value_get_double (value);
      break;
173 174 175 176 177 178
    case PROP_GRID_TYPE:
      options->grid_type = g_value_get_enum (value);
      break;
    case PROP_GRID_SIZE:
      options->grid_size = g_value_get_int (value);
      break;
179 180
    case PROP_CONSTRAIN:
      options->constrain = g_value_get_boolean (value);
181 182 183 184 185 186 187 188 189 190 191 192 193
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_transform_options_get_property (GObject    *object,
                                     guint       property_id,
                                     GValue     *value,
                                     GParamSpec *pspec)
{
194
  GimpTransformOptions *options = GIMP_TRANSFORM_OPTIONS (object);
195 196 197

  switch (property_id)
    {
198 199 200
    case PROP_TYPE:
      g_value_set_enum (value, options->type);
      break;
201 202 203 204 205 206
    case PROP_DIRECTION:
      g_value_set_enum (value, options->direction);
      break;
    case PROP_INTERPOLATION:
      g_value_set_enum (value, options->interpolation);
      break;
207
    case PROP_CLIP:
208
      g_value_set_enum (value, options->clip);
209
      break;
210 211
    case PROP_PREVIEW_TYPE:
      g_value_set_enum (value, options->preview_type);
212
      break;
213 214 215
    case PROP_PREVIEW_OPACITY:
      g_value_set_double (value, options->preview_opacity);
      break;
216 217 218 219 220 221
    case PROP_GRID_TYPE:
      g_value_set_enum (value, options->grid_type);
      break;
    case PROP_GRID_SIZE:
      g_value_set_int (value, options->grid_size);
      break;
222 223
    case PROP_CONSTRAIN:
      g_value_set_boolean (value, options->constrain);
224 225 226 227 228 229 230 231 232
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_transform_options_reset (GimpToolOptions *tool_options)
233 234
{
  GParamSpec *pspec;
235 236 237 238 239

  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (tool_options),
                                        "interpolation");

  if (pspec)
240 241
    G_PARAM_SPEC_ENUM (pspec)->default_value =
      tool_options->tool_info->gimp->config->interpolation_type;
242 243

  GIMP_TOOL_OPTIONS_CLASS (parent_class)->reset (tool_options);
244 245
}

246 247 248 249 250 251 252 253
/**
 * gimp_transform_options_gui:
 * @tool_options: a #GimpToolOptions
 *
 * Build the Transform Tool Options.
 *
 * Return value: a container holding the transform tool options
 **/
254
GtkWidget *
255 256
gimp_transform_options_gui (GimpToolOptions *tool_options)
{
257 258
  GObject              *config  = G_OBJECT (tool_options);
  GimpTransformOptions *options = GIMP_TRANSFORM_OPTIONS (tool_options);
259
  GtkWidget            *vbox    = gimp_tool_options_gui (tool_options);
260 261 262 263
  GtkWidget            *hbox;
  GtkWidget            *label;
  GtkWidget            *frame;
  GtkWidget            *table;
264
  GtkWidget            *combo;
265
  GtkWidget            *preview_box;
266
  const gchar          *constrain = NULL;
267

268 269 270 271
  hbox = gimp_prop_enum_stock_box_new (config, "type", "gimp", 0, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

272
  label = gtk_label_new (_("Transform:"));
273 274 275 276
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_box_reorder_child (GTK_BOX (hbox), label, 0);
  gtk_widget_show (label);

277
  frame = gimp_prop_enum_radio_frame_new (config, "direction",
278
                                          _("Direction"), 0, 0);
279 280
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
281

282
  /*  the interpolation menu  */
Sven Neumann's avatar
Sven Neumann committed
283 284 285
  frame = gimp_frame_new (_("Interpolation:"));
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
286

287
  combo = gimp_prop_enum_combo_box_new (config, "interpolation", 0, 0);
Sven Neumann's avatar
Sven Neumann committed
288
  gtk_container_add (GTK_CONTAINER (frame), combo);
289
  gtk_widget_show (combo);
290

291
  /*  the clipping menu  */
Sven Neumann's avatar
Sven Neumann committed
292
  hbox = gtk_hbox_new (FALSE, 2);
293 294 295
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

Sven Neumann's avatar
Sven Neumann committed
296 297 298
  frame = gimp_frame_new (_("Clipping:"));
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
299 300

  combo = gimp_prop_enum_combo_box_new (config, "clip", 0, 0);
Sven Neumann's avatar
Sven Neumann committed
301
  gtk_container_add (GTK_CONTAINER (frame), combo);
302
  gtk_widget_show (combo);
303 304

  /*  the preview frame  */
305
  frame = gimp_frame_new (NULL);
306 307
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
308

309
  /*  the preview type menu  */
Sven Neumann's avatar
Sven Neumann committed
310
  hbox = gtk_hbox_new (FALSE, 2);
311 312 313 314 315 316 317 318
  gtk_frame_set_label_widget (GTK_FRAME (frame), hbox);
  gtk_widget_show (hbox);

  label = gtk_label_new (_("Preview:"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  combo = gimp_prop_enum_combo_box_new (config, "preview-type", 0, 0);
319
  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
320 321
  gtk_widget_show (combo);

322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
  preview_box = gtk_vbox_new (FALSE, 6);
  gtk_container_add (GTK_CONTAINER (frame), preview_box);
  gtk_widget_show (preview_box);

  /*  the preview opacity scale  */
  table = gtk_table_new (1, 3, FALSE);
  gtk_table_set_col_spacing (GTK_TABLE (table), 1, 2);
  gtk_box_pack_start (GTK_BOX (preview_box), table, FALSE, FALSE, 0);
  gtk_widget_show (table);

  gtk_widget_set_sensitive (table,
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE ||
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID);

  g_signal_connect (config, "notify::preview-type",
                    G_CALLBACK (gimp_transform_options_preview_opacity_notify),
                    table);

  gimp_prop_opacity_entry_new (config, "preview-opacity",
                               GTK_TABLE (table), 0, 0,
                               _("Opacity:"));
345

346
  /*  the grid type menu  */
347
  combo = gimp_prop_enum_combo_box_new (config, "grid-type", 0, 0);
348
  gtk_box_pack_start (GTK_BOX (preview_box), combo, FALSE, FALSE, 0);
349
  gtk_widget_show (combo);
350

351 352
  /*  the grid density scale  */
  table = gtk_table_new (1, 3, FALSE);
353
  gtk_table_set_col_spacing (GTK_TABLE (table), 1, 2);
354
  gtk_box_pack_start (GTK_BOX (preview_box), table, FALSE, FALSE, 0);
355 356
  gtk_widget_show (table);

357 358 359 360 361 362 363 364 365 366 367
  gtk_widget_set_sensitive (combo,
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_GRID ||
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID);

  g_signal_connect (config, "notify::preview-type",
                    G_CALLBACK (gimp_transform_options_preview_notify),
                    combo);

  gtk_widget_set_sensitive (table,
368 369 370 371 372 373 374
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_GRID ||
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID);

  g_signal_connect (config, "notify::preview-type",
                    G_CALLBACK (gimp_transform_options_preview_notify),
375
                    table);
376

377 378
  gimp_prop_scale_entry_new (config, "grid-size",
                             GTK_TABLE (table), 0, 0,
379
                             NULL,
380 381
                             1.0, 8.0, 0,
                             FALSE, 0.0, 0.0);
382

383 384 385 386 387 388 389 390 391 392
  if (tool_options->tool_info->tool_type == GIMP_TYPE_ROTATE_TOOL)
    {
      constrain = (_("15 degrees  (%s)"));
    }
  else if (tool_options->tool_info->tool_type == GIMP_TYPE_SCALE_TOOL)
    {
      constrain = (_("Keep aspect  (%s)"));
    }

  if (constrain)
393
    {
394 395 396 397 398
      GtkWidget *button;
      gchar     *label;

      label = g_strdup_printf (constrain,
                               gimp_get_mod_string (GDK_CONTROL_MASK));
399 400 401 402 403 404

      button = gimp_prop_check_button_new (config, "constrain", label);
      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
      gtk_widget_show (button);

      g_free (label);
405
    }
406

407
  return vbox;
408 409 410
}


Michael Natterer's avatar
Michael Natterer committed
411 412 413
/*  private functions  */

static void
414 415
gimp_transform_options_preview_notify (GimpTransformOptions *options,
                                       GParamSpec           *pspec,
416
                                       GtkWidget            *box)
Michael Natterer's avatar
Michael Natterer committed
417
{
418
  gtk_widget_set_sensitive (box,
419 420 421 422
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_GRID ||
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID);
Michael Natterer's avatar
Michael Natterer committed
423
}
424 425 426 427 428 429 430 431 432 433 434 435 436

static void
gimp_transform_options_preview_opacity_notify (GimpTransformOptions *options,
                                               GParamSpec           *pspec,
                                               GtkWidget            *table)
{
  gtk_widget_set_sensitive (table,
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE ||
                            options->preview_type ==
                            GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID);
}