tool_options.c 30.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995-1999 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.
 */
Sven Neumann's avatar
Sven Neumann committed
18

Tomas Ogren's avatar
Tomas Ogren committed
19
#include "config.h"
Michael Natterer's avatar
Michael Natterer committed
20

21
#include <gtk/gtk.h>
Sven Neumann's avatar
Sven Neumann committed
22 23 24

#include "apptypes.h"

25
#include "brush_select.h"
26
#include "gimpcontext.h"
27
#include "gimprc.h"
28
#include "gimpui.h"
29 30
#include "paint_funcs.h"
#include "paint_options.h"
31
#include "selection_options.h"
32
#include "gtkhwrapbox.h"
33 34

#include "libgimp/gimpunitmenu.h"
35

36 37 38
#include "libgimp/gimpintl.h"


39 40 41 42 43 44 45 46 47 48 49 50
/*  declared extern in paint_options.h  */
PaintPressureOptions non_gui_pressure_options = 
{
  NULL,
  FALSE, FALSE, NULL,
  FALSE, FALSE, NULL,
  FALSE, FALSE, NULL,
  FALSE, FALSE, NULL,
  FALSE, FALSE, NULL
};


51 52
/*  a list of all PaintOptions  */
static GSList  *paint_options_list = NULL;
53

54 55 56
static PaintPressureOptions * paint_pressure_options_new   (ToolType);
static void                   paint_pressure_options_reset (PaintPressureOptions *);

57

58
/*  ui helper functions  ******************************************************/
59

Michael Natterer's avatar
Michael Natterer committed
60
static void
61 62
tool_options_opacity_adjustment_update (GtkAdjustment *adjustment,
					gpointer       data)
63
{
64
  gtk_signal_handler_block_by_data (GTK_OBJECT (data), adjustment);
65
  gimp_context_set_opacity (GIMP_CONTEXT (data),
66
			    adjustment->value / 100);
67
  gtk_signal_handler_unblock_by_data (GTK_OBJECT (data), adjustment);
68 69 70 71 72 73 74 75 76 77
}

static void
tool_options_opacity_changed (GimpContext *context,
			      gdouble      opacity,
			      gpointer     data)
{
  gtk_signal_handler_block_by_data (GTK_OBJECT (data), context);
  gtk_adjustment_set_value (GTK_ADJUSTMENT (data), opacity * 100);
  gtk_signal_handler_unblock_by_data (GTK_OBJECT (data), context);
78
}
79

80 81 82 83
static void
tool_options_paint_mode_update (GtkWidget *widget,
				gpointer   data)
{
84 85
  LayerModeEffects  paint_mode;
  PaintOptions     *options;
86

87
  paint_mode = (LayerModeEffects) gtk_object_get_user_data (GTK_OBJECT (widget));
88 89
  options    = (PaintOptions *) data;

90
  gtk_signal_handler_block_by_data (GTK_OBJECT (options->context),
91
				    options->paint_mode_w);
92 93
  gimp_context_set_paint_mode (GIMP_CONTEXT (options->context), paint_mode);
  gtk_signal_handler_unblock_by_data (GTK_OBJECT (options->context),
94
				      options->paint_mode_w);
95 96 97 98 99 100 101
}

static void
tool_options_paint_mode_changed (GimpContext      *context,
				 LayerModeEffects  paint_mode,
				 gpointer          data)
{
102
  gimp_option_menu_set_history (GTK_OPTION_MENU (data), (gpointer) paint_mode);
103 104 105
}

/*  tool options functions  ***************************************************/
106 107 108 109 110 111 112

void
tool_options_init (ToolOptions          *options,
		   gchar                *title,
		   ToolOptionsResetFunc  reset_func)
{
  options->main_vbox  = gtk_vbox_new (FALSE, 2);
113
  options->title      = title;
114 115 116 117 118 119 120 121 122 123
  options->reset_func = reset_func;
}

ToolOptions *
tool_options_new (gchar *title)
{
  ToolOptions *options;

  GtkWidget *label;

124
  options = g_new (ToolOptions, 1);
125 126 127 128 129 130 131 132 133
  tool_options_init (options, title, NULL);

  label = gtk_label_new (_("This tool has no options."));
  gtk_box_pack_start (GTK_BOX (options->main_vbox), label, FALSE, FALSE, 6);
  gtk_widget_show (label);

  return options;
}

134
/*  selection tool options functions  *****************************************/
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

void
selection_options_init (SelectionOptions     *options,
			ToolType              tool_type,
			ToolOptionsResetFunc  reset_func)
{
  GtkWidget *vbox;
  GtkWidget *abox;
  GtkWidget *table;
  GtkWidget *label;
  GtkWidget *scale;
  GtkWidget *separator;

  /*  initialize the tool options structure  */
  tool_options_init ((ToolOptions *) options,
		     ((tool_type == RECT_SELECT) ?
151
		      _("Rectangular Selection") :
152
		      ((tool_type == ELLIPSE_SELECT) ?
153
		       _("Elliptical Selection") :
154
		       ((tool_type == FREE_SELECT) ?
155
			_("Free-Hand Selection") :
156
			((tool_type == FUZZY_SELECT) ?
157
			 _("Fuzzy Selection") :
158
			 ((tool_type == BEZIER_SELECT) ?
159
			  _("Bezier Selection") :
160
			  ((tool_type == ISCISSORS) ?
161
			   _("Intelligent Scissors") :
162
			   ((tool_type == BY_COLOR_SELECT) ?
163 164
			    _("By-Color Selection") :
			    "ERROR: Unknown Select Tool Type"))))))),
165 166 167 168 169 170 171 172 173 174
		     reset_func);

  /*  the main vbox  */
  vbox = options->tool_options.main_vbox;

  /*  initialize the selection options structure  */
  options->feather        = options->feather_d        = FALSE;
  options->feather_radius = options->feather_radius_d = 10.0;
  options->antialias      = options->antialias_d      = TRUE;
  options->sample_merged  = options->sample_merged_d  = FALSE;
175
  options->threshold                                  = default_threshold;
176 177 178
  options->fixed_size     = options->fixed_size_d     = FALSE;
  options->fixed_height   = options->fixed_height_d   = 1;
  options->fixed_width    = options->fixed_width_d    = 1;
179
  options->fixed_unit     = options->fixed_unit_d     = GIMP_UNIT_PIXEL;
180
  options->interactive    = options->interactive_d    = FALSE;
181 182 183 184 185

  options->feather_w        = NULL;
  options->feather_radius_w = NULL;
  options->antialias_w      = NULL;
  options->sample_merged_w  = NULL;
186
  options->threshold_w      = NULL;
187 188 189 190
  options->fixed_size_w     = NULL;
  options->fixed_height_w   = NULL;
  options->fixed_width_w    = NULL;
  options->fixed_unit_w     = NULL;
191
  options->interactive_w    = NULL;
192

193 194
  /*  the feather toggle button  */
  table = gtk_table_new (2, 2, FALSE);
195
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
196 197 198 199 200 201 202 203
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);

  options->feather_w = gtk_check_button_new_with_label (_("Feather"));
  gtk_table_attach (GTK_TABLE (table), options->feather_w, 0, 1, 0, 1,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->feather_w),
				options->feather_d);
  gtk_signal_connect (GTK_OBJECT (options->feather_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
204
		      GTK_SIGNAL_FUNC (gimp_toggle_button_update),
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
		      &options->feather);
  gtk_widget_show (options->feather_w);

  /*  the feather radius scale  */
  label = gtk_label_new (_("Radius:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  abox = gtk_alignment_new (0.5, 1.0, 1.0, 0.0);
  gtk_table_attach (GTK_TABLE (table), abox, 1, 2, 0, 2,
		    GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (abox);

  options->feather_radius_w =
221
    gtk_adjustment_new (options->feather_radius_d, 0.0, 100.0, 1.0, 1.0, 1.0);
222 223 224 225 226
  scale = gtk_hscale_new (GTK_ADJUSTMENT (options->feather_radius_w));
  gtk_container_add (GTK_CONTAINER (abox), scale);
  gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
  gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
  gtk_signal_connect (GTK_OBJECT (options->feather_radius_w), "value_changed",
Michael Natterer's avatar
Michael Natterer committed
227
		      GTK_SIGNAL_FUNC (gimp_double_adjustment_update),
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
		      &options->feather_radius);
  gtk_widget_show (scale);

  /*  grey out label & scale if feather is off  */
  gtk_widget_set_sensitive (scale, options->feather_d);
  gtk_widget_set_sensitive (label, options->feather_d);
  gtk_object_set_data (GTK_OBJECT (options->feather_w), "set_sensitive", scale);
  gtk_object_set_data (GTK_OBJECT (scale), "set_sensitive", label);

  gtk_widget_show (table);

  /*  the antialias toggle button  */
  if (tool_type != RECT_SELECT)
    {
      options->antialias_w = gtk_check_button_new_with_label (_("Antialiasing"));
      gtk_box_pack_start (GTK_BOX (vbox), options->antialias_w, FALSE, FALSE, 0);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->antialias_w),
				    options->antialias_d);
      gtk_signal_connect (GTK_OBJECT (options->antialias_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
247
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
248 249 250 251 252 253 254 255 256 257
			  &options->antialias);
      gtk_widget_show (options->antialias_w);
    }

  /*  a separator between the common and tool-specific selection options  */
  switch (tool_type)
    {
    case FREE_SELECT:
    case BEZIER_SELECT:
      break;
258

259
    case ISCISSORS:
260 261 262 263 264 265 266 267 268 269 270 271
    case RECT_SELECT:
    case ELLIPSE_SELECT:
    case FUZZY_SELECT:
    case BY_COLOR_SELECT:
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
      gtk_widget_show (separator);
      break;
    default:
      break;
    }

272 273 274 275 276 277 278 279
  /* selection tool with an interactive boundary that can be toggled */
  if (tool_type == ISCISSORS)
    {
      options->interactive_w =
	gtk_check_button_new_with_label (_("Show Interactive Boundary"));

      gtk_box_pack_start (GTK_BOX (vbox), options->interactive_w,
			  FALSE, FALSE, 0);
280 281
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->interactive_w),
				    options->interactive_d);
282 283 284 285 286 287
      gtk_signal_connect (GTK_OBJECT (options->interactive_w), "toggled",
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
			  &options->interactive);
      gtk_widget_show (options->interactive_w);
    }

288 289
  /*  selection tools which operate on contiguous regions  */
  if (tool_type == FUZZY_SELECT)
290
    {
291 292 293
      GtkWidget *hbox;

      /*  the sample merged toggle  */
294 295 296 297 298
      options->sample_merged_w =
	gtk_check_button_new_with_label (_("Sample Merged"));
      gtk_box_pack_start (GTK_BOX (vbox), options->sample_merged_w,
			  FALSE, FALSE, 0);
      gtk_signal_connect (GTK_OBJECT (options->sample_merged_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
299
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
300 301 302 303
			  &options->sample_merged);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_merged_w),
				    options->sample_merged_d);
      gtk_widget_show (options->sample_merged_w);
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

      /*  the threshold scale  */
      hbox = gtk_hbox_new (FALSE, 1);
      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
      gtk_widget_show (hbox);
  
      label = gtk_label_new (_("Threshold:"));
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
      gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 1);
      gtk_widget_show (label);

      options->threshold_w = 
	gtk_adjustment_new (default_threshold, 0.0, 255.0, 1.0, 1.0, 0.0);
      scale = gtk_hscale_new (GTK_ADJUSTMENT (options->threshold_w));
      gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
      gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
      gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
      gtk_signal_connect (GTK_OBJECT (options->threshold_w), "value_changed",
			  GTK_SIGNAL_FUNC (gimp_double_adjustment_update),
			  &options->threshold);
      gtk_widget_show (scale);
325 326 327
    }

  /*  widgets for fixed size select  */
328
  if (tool_type == RECT_SELECT || tool_type == ELLIPSE_SELECT)
329 330 331 332 333 334 335
    {
      GtkWidget *alignment;
      GtkWidget *table;
      GtkWidget *width_spinbutton;
      GtkWidget *height_spinbutton;

      options->fixed_size_w =
Sven Neumann's avatar
Sven Neumann committed
336
	gtk_check_button_new_with_label (_("Fixed Size / Aspect Ratio"));
337 338 339
      gtk_box_pack_start (GTK_BOX (vbox), options->fixed_size_w,
			  FALSE, FALSE, 0);
      gtk_signal_connect (GTK_OBJECT (options->fixed_size_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
340
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
341
			  &options->fixed_size);
342 343 344
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->fixed_size_w),
				    options->fixed_size_d);
      gtk_widget_show (options->fixed_size_w);
345 346 347 348 349 350

      alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
      gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
      gtk_widget_show (alignment);

      table = gtk_table_new (3, 2, FALSE);
351
      gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
      gtk_table_set_row_spacings (GTK_TABLE (table), 1);
      gtk_container_add (GTK_CONTAINER (alignment), table);

      /*  grey out the table if fixed size is off  */
      gtk_widget_set_sensitive (table, options->fixed_size_d);
      gtk_object_set_data (GTK_OBJECT (options->fixed_size_w), "set_sensitive",
			   table);

      options->fixed_width_w =
	gtk_adjustment_new (options->fixed_width_d, 1e-5, 32767.0,
			    1.0, 50.0, 0.0);
      width_spinbutton =
	gtk_spin_button_new (GTK_ADJUSTMENT (options->fixed_width_w), 1.0, 0.0);
      gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(width_spinbutton),
				       GTK_SHADOW_NONE);
      gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (width_spinbutton), TRUE);
      gtk_widget_set_usize (width_spinbutton, 75, 0);
      gtk_signal_connect (GTK_OBJECT (options->fixed_width_w), "value_changed",
Michael Natterer's avatar
Michael Natterer committed
370
                          GTK_SIGNAL_FUNC (gimp_double_adjustment_update),
371
                          &options->fixed_width);
372
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
373
				 _("Width:"), 1.0, 0.5,
374
				 width_spinbutton, 1, FALSE);
375 376 377 378 379 380 381 382 383 384 385

      options->fixed_height_w =
	gtk_adjustment_new (options->fixed_height_d, 1e-5, 32767.0,
			    1.0, 50.0, 0.0);
      height_spinbutton =
	gtk_spin_button_new (GTK_ADJUSTMENT (options->fixed_height_w), 1.0, 0.0);
      gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON(height_spinbutton),
				       GTK_SHADOW_NONE);
      gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(height_spinbutton), TRUE);
      gtk_widget_set_usize (height_spinbutton, 75, 0);
      gtk_signal_connect (GTK_OBJECT (options->fixed_height_w), "value_changed",
Michael Natterer's avatar
Michael Natterer committed
386
                          GTK_SIGNAL_FUNC (gimp_double_adjustment_update),
387
                          &options->fixed_height);
388
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
389
				 _("Height:"), 1.0, 0.5,
390
				 height_spinbutton, 1, FALSE);
391

392 393 394
      options->fixed_unit_w =
	gimp_unit_menu_new ("%a", options->fixed_unit_d, TRUE, TRUE, TRUE);
      gtk_signal_connect (GTK_OBJECT (options->fixed_unit_w), "unit_changed",
Michael Natterer's avatar
Michael Natterer committed
395
                          GTK_SIGNAL_FUNC (gimp_unit_menu_update),
396 397 398 399 400
                          &options->fixed_unit);
      gtk_object_set_data (GTK_OBJECT (options->fixed_unit_w), "set_digits",
			   width_spinbutton);
      gtk_object_set_data (GTK_OBJECT (width_spinbutton), "set_digits",
			   height_spinbutton);
401
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
402
				 _("Unit:"), 1.0, 0.5,
403
				 options->fixed_unit_w, 1, FALSE);
404 405 406 407 408 409 410 411 412 413 414

      gtk_widget_show (table);
    }
}

SelectionOptions *
selection_options_new (ToolType              tool_type,
		       ToolOptionsResetFunc  reset_func)
{
  SelectionOptions *options;

415
  options = g_new (SelectionOptions, 1);
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
  selection_options_init (options, tool_type, reset_func);

  return options;
}

void
selection_options_reset (SelectionOptions *options)
{
  if (options->feather_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->feather_w),
				    options->feather_d);
      gtk_adjustment_set_value (GTK_ADJUSTMENT (options->feather_radius_w),
				options->feather_radius_d);
    }
431

432 433 434
  if (options->antialias_w)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->antialias_w),
				  options->antialias_d);
435

436
  if (options->sample_merged_w)
437 438 439 440 441 442 443
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_merged_w),
				    options->sample_merged_d);
      gtk_adjustment_set_value (GTK_ADJUSTMENT (options->threshold_w),
				default_threshold);
    }

444 445 446
  if (options->fixed_size_w)
    {
      GtkWidget *spinbutton;
447
      gint       digits;
448 449 450 451 452 453 454 455 456 457 458 459 460

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(options->fixed_size_w),
				    options->fixed_size_d);
      gtk_adjustment_set_value (GTK_ADJUSTMENT (options->fixed_width_w),
				options->fixed_width_d);
      gtk_adjustment_set_value (GTK_ADJUSTMENT (options->fixed_height_w),
				options->fixed_height_d);

      options->fixed_unit = options->fixed_unit_d;
      gimp_unit_menu_set_unit (GIMP_UNIT_MENU (options->fixed_unit_w),
			       options->fixed_unit_d);

      digits =
461 462
	((options->fixed_unit_d == GIMP_UNIT_PIXEL) ? 0 :
	 ((options->fixed_unit_d == GIMP_UNIT_PERCENT) ? 2 :
463 464 465 466 467 468 469 470 471 472 473
	  (MIN (6, MAX (3, gimp_unit_get_digits (options->fixed_unit_d))))));

      spinbutton =
	gtk_object_get_data (GTK_OBJECT (options->fixed_unit_w), "set_digits");
      while (spinbutton)
	{
	  gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), digits);
	  spinbutton =
	    gtk_object_get_data (GTK_OBJECT (spinbutton), "set_digits");
	}
    }
474 475 476 477 478 479

  if (options->interactive_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->interactive_w),
				    options->interactive_d);
    }
480
}
481 482 483 484 485 486 487 488 489 490 491 492 493 494


/*  paint tool options functions  *********************************************/

void
paint_options_init (PaintOptions         *options,
		    ToolType              tool_type,
		    ToolOptionsResetFunc  reset_func)
{
  GtkWidget *vbox;
  GtkWidget *table;
  GtkWidget *scale;
  GtkWidget *separator;

495 496
  GimpContext *tool_context = tool_info[tool_type].tool_context;

497 498 499
  /*  initialize the tool options structure  */
  tool_options_init ((ToolOptions *) options,
		     ((tool_type == BUCKET_FILL) ?
500
		      _("Bucket Fill") :
501
		      ((tool_type == BLEND) ?
502
		       _("Blend Tool") :
503
		       ((tool_type == PENCIL) ?
504
			_("Pencil") :
505
			((tool_type == PAINTBRUSH) ?
506
			 _("Paintbrush") :
507
			 ((tool_type == ERASER) ?
508
			  _("Eraser") :
509
			  ((tool_type == AIRBRUSH) ?
510
			   _("Airbrush") :
511
			   ((tool_type == CLONE) ?
512
			    _("Clone Tool") :
513
			    ((tool_type == CONVOLVE) ?
514
			     _("Convolver") :
515
			     ((tool_type == INK) ?
516
			      _("Ink Tool") :
517
			      ((tool_type == DODGEBURN) ?
518
			       _("Dodge or Burn") :
519
			       ((tool_type == SMUDGE) ?
520
				_("Smudge Tool") :
521 522 523
/*  				((tool_type == XINPUT_AIRBRUSH) ? */
/*  				 _("Xinput Airbrush") : */
				 "ERROR: Unknown Paint Tool Type"))))))))))),
524 525 526
		     reset_func);

  /*  initialize the paint options structure  */
Michael Natterer's avatar
Michael Natterer committed
527 528 529 530 531
  options->global           = NULL;
  options->opacity_w        = NULL;
  options->paint_mode_w     = NULL;
  options->context          = tool_context;
  options->incremental_w    = NULL;
532
  options->incremental = options->incremental_d = FALSE;
Michael Natterer's avatar
Michael Natterer committed
533
  options->pressure_options = NULL;
534 535 536 537 538 539 540 541 542 543 544 545 546 547

  /*  the main vbox  */
  vbox = gtk_vbox_new (FALSE, 2);
  gtk_box_pack_start (GTK_BOX (options->tool_options.main_vbox), vbox,
		      FALSE, FALSE, 0);
  options->paint_vbox = vbox;

  /*  the main table  */
  table = gtk_table_new (2, 2, FALSE);
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);

  /*  the opacity scale  */
  options->opacity_w =
548 549
    gtk_adjustment_new (gimp_context_get_opacity (tool_context) * 100,
			0.0, 100.0, 1.0, 1.0, 0.0);
550 551 552
  scale = gtk_hscale_new (GTK_ADJUSTMENT (options->opacity_w));
  gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
  gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
553
  gtk_signal_connect (GTK_OBJECT (options->opacity_w), "value_changed",
554
		      GTK_SIGNAL_FUNC (tool_options_opacity_adjustment_update),
555
		      tool_context);
556
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
557
			     _("Opacity:"), 1.0, 1.0,
558
			     scale, 1, FALSE);
559

560 561 562 563
  gtk_signal_connect (GTK_OBJECT (tool_context), "opacity_changed",
		      GTK_SIGNAL_FUNC (tool_options_opacity_changed),
		      options->opacity_w);

564 565 566 567 568 569 570 571 572 573
  /*  the paint mode menu  */
  switch (tool_type)
    {
    case BUCKET_FILL:
    case BLEND:
    case PENCIL:
    case PAINTBRUSH:
    case AIRBRUSH:
    case CLONE:
    case INK:
574
/*      case XINPUT_AIRBRUSH: */
575 576
      gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);

577
      options->paint_mode_w =
578
	paint_mode_menu_new (tool_options_paint_mode_update, options,
579
			     gimp_context_get_paint_mode (tool_context));
580
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
581
				 _("Mode:"), 1.0, 0.5,
582
				 options->paint_mode_w, 1, TRUE);
583

584 585 586
      gtk_signal_connect (GTK_OBJECT (tool_context), "paint_mode_changed",
			  GTK_SIGNAL_FUNC (tool_options_paint_mode_changed),
			  options->paint_mode_w);
587 588 589
      break;
    case CONVOLVE:
    case ERASER:
590 591
    case DODGEBURN:
    case SMUDGE:
592 593 594 595 596 597 598 599
      break;
    default:
      break;
    }

  /*  show the main table  */
  gtk_widget_show (table);

600 601
  /*  a separator after the common paint options which can be global  */
  switch (tool_type)
602
    {
603 604 605
    case BUCKET_FILL:
    case BLEND:
    case INK:
Michael Natterer's avatar
Michael Natterer committed
606
      /* case XINPUT_AIRBRUSH: */
607 608 609
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
      gtk_widget_show (separator);
610 611
      break;
    case PENCIL:
Michael Natterer's avatar
Michael Natterer committed
612 613 614 615 616 617 618
    case PAINTBRUSH:
    case ERASER:
    case AIRBRUSH:
    case CLONE:
    case CONVOLVE:
    case DODGEBURN:
    case SMUDGE:
619 620 621
      break;
    default:
      break;
622 623 624 625 626
    }

  if (! global_paint_options)
    gtk_widget_show (vbox);

627 628 629 630 631 632 633 634 635 636 637 638
  /*  the "incremental" toggle  */
  switch (tool_type)
    {
    case AIRBRUSH:
    case ERASER:
    case PAINTBRUSH:
    case PENCIL:
      options->incremental_w =
	gtk_check_button_new_with_label (_("Incremental"));
      gtk_box_pack_start (GTK_BOX (options->tool_options.main_vbox),
			  options->incremental_w, FALSE, FALSE, 0);
      gtk_signal_connect (GTK_OBJECT (options->incremental_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
639
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
			  &options->incremental);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->incremental_w),
				    options->incremental_d);
      gtk_widget_show (options->incremental_w);

    case BUCKET_FILL:
    case BLEND:
    case CLONE:
    case CONVOLVE:
    case DODGEBURN:
    case SMUDGE:
      break;
    default:
      break;
    }

Michael Natterer's avatar
Michael Natterer committed
656 657
  options->pressure_options = paint_pressure_options_new (tool_type);

658 659 660 661 662 663 664
  if (options->pressure_options->frame)
    {
      gtk_box_pack_start (GTK_BOX (options->tool_options.main_vbox),
			  options->pressure_options->frame, FALSE, FALSE, 0);
      gtk_widget_show (options->pressure_options->frame);
    }

665 666 667 668 669 670 671 672 673 674
  /*  register this Paintoptions structure  */
  paint_options_list = g_slist_prepend (paint_options_list, options);
}

PaintOptions *
paint_options_new (ToolType              tool_type,
		   ToolOptionsResetFunc  reset_func)
{
  PaintOptions *options;

675
  options = g_new (PaintOptions, 1);
676 677 678 679 680 681 682 683 684 685 686
  paint_options_init (options, tool_type, reset_func);

  if (global_paint_options && options->global)
    gtk_widget_show (options->global);

  return options;
}

void
paint_options_reset (PaintOptions *options)
{
687 688 689 690
  GimpContext *default_context;

  default_context = gimp_context_get_default ();

691 692
  if (options->opacity_w)
    {
693
      gimp_context_set_opacity (GIMP_CONTEXT (options->context),
694
				gimp_context_get_opacity (default_context));
695 696 697
    }
  if (options->paint_mode_w)
    {
698
      gimp_context_set_paint_mode (GIMP_CONTEXT (options->context),
699
				   gimp_context_get_paint_mode (default_context));
700
    }
701 702
  if (options->incremental_w)
    {
703
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->incremental_w),
704 705
				    options->incremental_d);
    }
706 707

  paint_pressure_options_reset (options->pressure_options);
708 709
}

710 711 712
static PaintPressureOptions *
paint_pressure_options_new (ToolType tool_type)
{
713
  PaintPressureOptions *pressure = NULL;
714
  GtkWidget *frame = NULL;
715
  GtkWidget *wbox = NULL;
716 717

  pressure = g_new (PaintPressureOptions, 1);
Michael Natterer's avatar
Michael Natterer committed
718

719
  pressure->opacity  = pressure->opacity_d  = TRUE;
720
  pressure->pressure = pressure->pressure_d = TRUE;
721 722 723 724 725 726 727 728 729
  pressure->rate     = pressure->rate_d     = FALSE;
  pressure->size     = pressure->size_d     = FALSE;
  pressure->color    = pressure->color_d    = FALSE;

  pressure->opacity_w  = NULL;
  pressure->pressure_w = NULL;
  pressure->rate_w     = NULL;
  pressure->size_w     = NULL;
  pressure->color_w    = NULL;
730 731 732

  switch (tool_type)
    {
733
    case AIRBRUSH:
734 735 736 737 738 739
    case CLONE:
    case CONVOLVE:
    case DODGEBURN:
    case ERASER:
    case PAINTBRUSH:
    case PENCIL:
740
    case SMUDGE:
Sven Neumann's avatar
Sven Neumann committed
741
      frame = gtk_frame_new (_("Pressure Sensitivity"));
742 743 744 745
      wbox = gtk_hwrap_box_new (FALSE);
      gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (wbox), 6);
      gtk_container_add (GTK_CONTAINER (frame), wbox);
      gtk_widget_show (wbox);
746 747 748 749 750 751 752 753 754
      break;
    default:
      break;
    }

  /*  the opacity toggle  */
  switch (tool_type)
    {
    case CLONE:
755
    case DODGEBURN:
756 757 758 759 760
    case ERASER:
    case PAINTBRUSH:
    case PENCIL:
      pressure->opacity_w =
	gtk_check_button_new_with_label (_("Opacity"));
761
      gtk_container_add (GTK_CONTAINER (wbox), pressure->opacity_w);
762
      gtk_signal_connect (GTK_OBJECT (pressure->opacity_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
763
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
764 765 766 767 768 769 770 771 772
			  &pressure->opacity);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->opacity_w),
				    pressure->opacity_d);
      gtk_widget_show (pressure->opacity_w);
      break;
    default:
      break;
    }

773
 /*  the pressure toggle  */
774 775
  switch (tool_type)
    {
776
    case AIRBRUSH:
777
    case CLONE:
778
    case CONVOLVE:
779 780
    case DODGEBURN:
    case ERASER:
Sven Neumann's avatar
Sven Neumann committed
781
    case PAINTBRUSH:
782
    case SMUDGE:
jtl's avatar
jtl committed
783
      pressure->pressure_w = gtk_check_button_new_with_label (_("Hardness"));
784
      gtk_container_add (GTK_CONTAINER (wbox), pressure->pressure_w);
785
      gtk_signal_connect (GTK_OBJECT (pressure->pressure_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
786
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
787 788 789 790 791 792 793 794 795
			  &pressure->pressure);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->pressure_w),
				    pressure->pressure_d);
      gtk_widget_show (pressure->pressure_w);
      break;
    default:
      break;
    }

796 797 798 799 800 801 802 803
  /*  the rate toggle */
  switch (tool_type)
    {
    case AIRBRUSH:
    case CONVOLVE:
    case SMUDGE:
      pressure->rate_w =
	gtk_check_button_new_with_label (_("Rate"));
804
      gtk_container_add (GTK_CONTAINER (wbox), pressure->rate_w);
805
      gtk_signal_connect (GTK_OBJECT (pressure->rate_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
806
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
807 808 809 810 811 812 813 814 815
			  &pressure->rate);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->rate_w),
				    pressure->rate_d);
      gtk_widget_show (pressure->rate_w);
      break;
    default:
      break;
    }

816 817 818 819 820 821 822 823 824 825 826 827
  /*  the size toggle  */
  switch (tool_type)
    {
    case AIRBRUSH:
    case CLONE:
    case CONVOLVE:
    case DODGEBURN:
    case ERASER:
    case PAINTBRUSH:
    case PENCIL:
      pressure->size_w =
	gtk_check_button_new_with_label (_("Size"));
828
      gtk_container_add (GTK_CONTAINER (wbox), pressure->size_w);
829
      gtk_signal_connect (GTK_OBJECT (pressure->size_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
830
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
			  &pressure->size);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->size_w),
				    pressure->size_d);
      gtk_widget_show (pressure->size_w);
      break;
    default:
      break;
    }

  /*  the color toggle  */
  switch (tool_type)
    {
    case AIRBRUSH:
    case PAINTBRUSH:
    case PENCIL:
      pressure->color_w =
	gtk_check_button_new_with_label (_("Color"));
848
      gtk_container_add (GTK_CONTAINER (wbox), pressure->color_w);
849
      gtk_signal_connect (GTK_OBJECT (pressure->color_w), "toggled",
Michael Natterer's avatar
Michael Natterer committed
850
			  GTK_SIGNAL_FUNC (gimp_toggle_button_update),
851 852 853 854 855 856 857 858
			  &pressure->color);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->color_w),
				    pressure->color_d);
      gtk_widget_show (pressure->color_w);
      break;
    default:
      break;
    }
859

860 861
  pressure->frame = frame;

862
  return pressure;
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
}

static void
paint_pressure_options_reset (PaintPressureOptions *pressure)
{
  if (pressure->opacity_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->opacity_w),
				    pressure->opacity_d);
    }
  if (pressure->pressure_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->pressure_w),
				    pressure->pressure_d);
    }
878 879 880 881 882
  if (pressure->rate_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->rate_w),
				    pressure->rate_d);
    }
883 884 885 886 887 888 889 890 891 892 893 894 895
  if (pressure->size_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->size_w),
				    pressure->size_d);
    }
  if (pressure->color_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->color_w),
				    pressure->color_d);
    }
}


896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
/*  global paint options functions  *******************************************/

void
paint_options_set_global (gboolean global)
{
  PaintOptions *options;
  GSList *list;

  global = global ? TRUE : FALSE;

  if (global_paint_options == global)
    return;

  global_paint_options = global;

  for (list = paint_options_list; list; list = list->next)
    {
      options = (PaintOptions *) list->data;

      if (global)
	{
	  if (options->paint_vbox && GTK_WIDGET_VISIBLE (options->paint_vbox))
	    gtk_widget_hide (options->paint_vbox);
	  if (options->global && ! GTK_WIDGET_VISIBLE (options->global))
	    gtk_widget_show (options->global);
	}
      else
	{
	  if (options->paint_vbox && ! GTK_WIDGET_VISIBLE (options->paint_vbox))
	    gtk_widget_show (options->paint_vbox);
	  if (options->global && GTK_WIDGET_VISIBLE (options->global))
	    gtk_widget_hide (options->global);
	}
    }

  /*  NULL means the main brush selection  */
  brush_select_show_paint_options (NULL, global);
}


/*  create a paint mode menu  *************************************************/

GtkWidget *
939
paint_mode_menu_new (GtkSignalFunc    callback,
940 941
		     gpointer         data,
		     LayerModeEffects initial)
942 943
{
  GtkWidget *menu;
944 945 946 947 948 949 950

  menu = gimp_option_menu_new2
    (FALSE, callback, data, (gpointer) initial,

     _("Normal"),          (gpointer) NORMAL_MODE, NULL,
     _("Dissolve"),        (gpointer) DISSOLVE_MODE, NULL,
     _("Behind"),          (gpointer) BEHIND_MODE, NULL,
951 952
     _("Multiply"),        (gpointer) MULTIPLY_MODE, NULL,
     _("Divide"),          (gpointer) DIVIDE_MODE, NULL,
953 954
     _("Screen"),          (gpointer) SCREEN_MODE, NULL,
     _("Overlay"),         (gpointer) OVERLAY_MODE, NULL,
955 956 957
     _("Dodge"),           (gpointer) DODGE_MODE, NULL,
     _("Burn"),            (gpointer) BURN_MODE, NULL,
     _("Hard Light"),      (gpointer) HARDLIGHT_MODE, NULL,
958 959 960 961 962 963 964 965 966 967 968
     _("Difference"),      (gpointer) DIFFERENCE_MODE, NULL,
     _("Addition"),        (gpointer) ADDITION_MODE, NULL,
     _("Subtract"),        (gpointer) SUBTRACT_MODE, NULL,
     _("Darken Only"),     (gpointer) DARKEN_ONLY_MODE, NULL,
     _("Lighten Only"),    (gpointer) LIGHTEN_ONLY_MODE, NULL,
     _("Hue"),             (gpointer) HUE_MODE, NULL,
     _("Saturation"),      (gpointer) SATURATION_MODE, NULL,
     _("Color"),           (gpointer) COLOR_MODE, NULL,
     _("Value"),           (gpointer) VALUE_MODE, NULL,

     NULL);
969 970 971

  return menu;
}