gimptooloptions.c 30.9 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.
 */
Tomas Ogren's avatar
Tomas Ogren committed
18
#include "config.h"
19
20
#include "brush_select.h"
#include "gimprc.h"
21
#include "gimpui.h"
22
23
#include "paint_funcs.h"
#include "paint_options.h"
24
25
26
27
#include "selection_options.h"
#include "tool_options_ui.h"

#include "libgimp/gimpunitmenu.h"
28
29
30
31
32
#include "libgimp/gimpintl.h"


/*  a list of all PaintOptions  */
static GSList  *paint_options_list = NULL;
33

34
35
36
static PaintPressureOptions * paint_pressure_options_new   (ToolType);
static void                   paint_pressure_options_reset (PaintPressureOptions *);

37

38
/*  ui helper functions  ******************************************************/
39
40
41
42
43
44

void
tool_options_toggle_update (GtkWidget *widget,
			    gpointer   data)
{
  GtkWidget *set_sensitive;
45
  gboolean  *toggle_val;
46

47
  toggle_val = (gboolean *) data;
48
49
50
51
52
  *toggle_val = (GTK_TOGGLE_BUTTON (widget)->active) ? TRUE : FALSE;

  /*  a tool options toggle button can set the sensitive state of
   *  an arbitrary list of widgets
   */
53

54
55
56
57
58
59
60
61
  set_sensitive =
    gtk_object_get_data (GTK_OBJECT (widget), "set_sensitive");
  while (set_sensitive)
    {
      gtk_widget_set_sensitive (GTK_WIDGET (set_sensitive), *toggle_val);
      set_sensitive =
	gtk_object_get_data (GTK_OBJECT (set_sensitive), "set_sensitive");
    }
62
63
64
65
66
67
68
69
70

  set_sensitive =
    gtk_object_get_data (GTK_OBJECT (widget), "inverse_sensitive");
  while (set_sensitive)
    {
      gtk_widget_set_sensitive (GTK_WIDGET (set_sensitive), ! *toggle_val);
      set_sensitive =
	gtk_object_get_data (GTK_OBJECT (set_sensitive), "inverse_sensitive");
    }
71
72
73
74
75
76
}

void
tool_options_int_adjustment_update (GtkWidget *widget,
				    gpointer   data)
{
77
  gint *val;
78

79
  val = (gint *) data;
80
81
82
83
84
85
86
  *val = GTK_ADJUSTMENT (widget)->value;
}

void
tool_options_double_adjustment_update (GtkWidget *widget,
				       gpointer   data)
{
87
  gdouble *val;
88

89
  val = (gdouble *) data;
90
91
92
  *val = GTK_ADJUSTMENT (widget)->value;
}

93
94
95
96
void
tool_options_opacity_adjustment_update (GtkWidget *widget,
					gpointer   data)
{
97
98
99
  gimp_context_set_opacity (GIMP_CONTEXT (data),
			    GTK_ADJUSTMENT (widget)->value / 100);
}
100

101
102
103
104
105
106
107
108
109
static void
tool_options_paint_mode_update (GtkWidget *widget,
				gpointer   data)
{
  GimpContext *context;

  context = (GimpContext *) gtk_object_get_user_data (GTK_OBJECT (widget));

  gimp_context_set_paint_mode (GIMP_CONTEXT (context),
110
			       (LayerModeEffects) data);
111
112
}

113
114
115
116
117
118
void
tool_options_unitmenu_update (GtkWidget *widget,
			      gpointer   data)
{
  GUnit     *val;
  GtkWidget *spinbutton;
119
  gint       digits;
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

  val = (GUnit *) data;
  *val = gimp_unit_menu_get_unit (GIMP_UNIT_MENU (widget));

  digits = ((*val == UNIT_PIXEL) ? 0 :
	    ((*val == UNIT_PERCENT) ? 2 :
	     (MIN (6, MAX (3, gimp_unit_get_digits (*val))))));

  spinbutton =
    gtk_object_get_data (GTK_OBJECT (widget), "set_digits");
  while (spinbutton)
    {
      gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), digits);
      spinbutton = gtk_object_get_data (GTK_OBJECT (spinbutton), "set_digits");
    }
}

Sven Neumann's avatar
Sven Neumann committed
137
138
139
140
static void
tool_options_radio_buttons_update (GtkWidget *widget,
				   gpointer   data)
{
141
  gint *toggle_val;
Sven Neumann's avatar
Sven Neumann committed
142

143
  toggle_val = (gint *) data;
Sven Neumann's avatar
Sven Neumann committed
144
  if (GTK_TOGGLE_BUTTON (widget)->active)
145
146
    *toggle_val = (gint) gtk_object_get_data (GTK_OBJECT (widget),
					      "toggle_value");
Sven Neumann's avatar
Sven Neumann committed
147
148
}

149
GtkWidget *
150
151
152
153
154
155
tool_options_radio_buttons_new (gchar*      label,
				gpointer    toggle_val,
				GtkWidget*  button_widget[],
				gchar*      button_label[],
				gint        button_value[],
				gint        num)
Sven Neumann's avatar
Sven Neumann committed
156
157
158
159
{
  GtkWidget *frame;
  GtkWidget *vbox;
  GSList *group = NULL;
160
  gint i;
Sven Neumann's avatar
Sven Neumann committed
161

162
  frame = gtk_frame_new (label);
Sven Neumann's avatar
Sven Neumann committed
163
164
165
166
167
168
169

  g_return_val_if_fail (toggle_val != NULL, frame);

  vbox = gtk_vbox_new (FALSE, 1);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
  gtk_container_add (GTK_CONTAINER (frame), vbox);

170
  for (i=0; i<num; i++)
Sven Neumann's avatar
Sven Neumann committed
171
    {
172
173
      button_widget[i] =
	gtk_radio_button_new_with_label (group, gettext (button_label[i]));
174
175
176
      group = gtk_radio_button_group (GTK_RADIO_BUTTON (button_widget[i]));
      gtk_box_pack_start (GTK_BOX (vbox), button_widget[i], FALSE, FALSE, 0);
      gtk_signal_connect (GTK_OBJECT (button_widget[i]), "toggled",
177
			  GTK_SIGNAL_FUNC (tool_options_radio_buttons_update),
Sven Neumann's avatar
Sven Neumann committed
178
			  toggle_val);
179
180
181
      gtk_object_set_data (GTK_OBJECT (button_widget[i]), "toggle_value",
			   (gpointer)button_value[i]);
      gtk_widget_show (button_widget[i]);
Sven Neumann's avatar
Sven Neumann committed
182
183
184
185
186
187
    }
  gtk_widget_show (vbox);

  return (frame);
}

188

189
/*  tool options functions  ***************************************************/
190
191
192
193
194
195
196

void
tool_options_init (ToolOptions          *options,
		   gchar                *title,
		   ToolOptionsResetFunc  reset_func)
{
  options->main_vbox  = gtk_vbox_new (FALSE, 2);
197
  options->title      = title;
198
199
200
201
202
203
204
205
206
207
  options->reset_func = reset_func;
}

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

  GtkWidget *label;

208
  options = g_new (ToolOptions, 1);
209
210
211
212
213
214
215
216
217
  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;
}

218
/*  selection tool options functions  *****************************************/
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

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) ?
235
		      _("Rectangular Select Options") :
236
		      ((tool_type == ELLIPSE_SELECT) ?
237
		       _("Elliptical Selection Options") :
238
		       ((tool_type == FREE_SELECT) ?
239
			_("Free-hand Selection Options") :
240
			((tool_type == FUZZY_SELECT) ?
241
			 _("Fuzzy Selection Options") :
242
			 ((tool_type == BEZIER_SELECT) ?
243
			  _("Bezier Selection Options") :
244
			  ((tool_type == ISCISSORS) ?
245
			   _("Intelligent Scissors Options") :
246
			   ((tool_type == BY_COLOR_SELECT) ?
247
			    _("By-Color Select Options") :
248
			    "ERROR: Unknown Selection Type"))))))),
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
		     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;
  options->fixed_size     = options->fixed_size_d     = FALSE;
  options->fixed_height   = options->fixed_height_d   = 1;
  options->fixed_width    = options->fixed_width_d    = 1;
  options->fixed_unit     = options->fixed_unit_d     = UNIT_PIXEL;

  options->feather_w        = NULL;
  options->feather_radius_w = NULL;
  options->antialias_w      = NULL;
  options->sample_merged_w  = NULL;
  options->fixed_size_w     = NULL;
  options->fixed_height_w   = NULL;
  options->fixed_width_w    = NULL;
  options->fixed_unit_w     = NULL;

  /*  the feather toggle button  */
  table = gtk_table_new (2, 2, FALSE);
275
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
276
277
278
279
280
281
282
283
  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",
284
		      GTK_SIGNAL_FUNC (tool_options_toggle_update),
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
		      &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 =
301
    gtk_adjustment_new (options->feather_radius_d, 0.0, 100.0, 1.0, 1.0, 1.0);
302
303
304
305
306
  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",
307
		      GTK_SIGNAL_FUNC (tool_options_double_adjustment_update),
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
		      &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",
327
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
328
329
330
331
332
333
334
335
336
			  &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:
337
    case ISCISSORS:
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
      break;
    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;
    }

  /*  the sample merged option  */
  switch (tool_type)
    {
    case RECT_SELECT:
    case ELLIPSE_SELECT:
    case FREE_SELECT:
    case BEZIER_SELECT:
    case ISCISSORS:
      break;
    case FUZZY_SELECT:
    case BY_COLOR_SELECT:
      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",
367
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
368
369
370
371
372
373
374
375
376
377
			  &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);
      break;
    default:
      break;
    }

  /*  widgets for fixed size select  */
378
  if (tool_type == RECT_SELECT || tool_type == ELLIPSE_SELECT)
379
380
381
382
383
384
385
386
387
388
389
    {
      GtkWidget *alignment;
      GtkWidget *table;
      GtkWidget *width_spinbutton;
      GtkWidget *height_spinbutton;

      options->fixed_size_w =
	gtk_check_button_new_with_label (_("Fixed size / aspect ratio"));
      gtk_box_pack_start (GTK_BOX (vbox), options->fixed_size_w,
			  FALSE, FALSE, 0);
      gtk_signal_connect (GTK_OBJECT (options->fixed_size_w), "toggled",
390
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
391
			  &options->fixed_size);
392
393
394
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->fixed_size_w),
				    options->fixed_size_d);
      gtk_widget_show (options->fixed_size_w);
395
396
397
398
399
400

      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);
401
      gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
      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",
420
                          GTK_SIGNAL_FUNC (tool_options_double_adjustment_update),
421
                          &options->fixed_width);
422
423
424
      gimp_table_attach_aligned (GTK_TABLE (table), 0,
				 _("Width:"), 1.0, 0.5,
				 width_spinbutton, FALSE);
425
426
427
428
429
430
431
432
433
434
435

      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",
436
                          GTK_SIGNAL_FUNC (tool_options_double_adjustment_update),
437
                          &options->fixed_height);
438
439
440
441
      gimp_table_attach_aligned (GTK_TABLE (table), 1,
				 _("Height:"), 1.0, 0.5,
				 height_spinbutton, FALSE);

442
443
444
      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",
445
                          GTK_SIGNAL_FUNC (tool_options_unitmenu_update),
446
447
448
449
450
                          &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);
451
452
453
      gimp_table_attach_aligned (GTK_TABLE (table), 2,
				 _("Unit:"), 1.0, 0.5,
				 options->fixed_unit_w, FALSE);
454
455
456
457
458
459
460
461
462
463
464

      gtk_widget_show (table);
    }
}

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

465
  options = g_new (SelectionOptions, 1);
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
  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);
    }
  if (options->antialias_w)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->antialias_w),
				  options->antialias_d);
  if (options->sample_merged_w)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_merged_w),
				  options->sample_merged_d);
  if (options->fixed_size_w)
    {
      GtkWidget *spinbutton;
490
      gint       digits;
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

      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 =
	((options->fixed_unit_d == UNIT_PIXEL) ? 0 :
	 ((options->fixed_unit_d == UNIT_PERCENT) ? 2 :
	  (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");
	}
    }
}
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532


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

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

533
534
  GimpContext *tool_context = tool_info[tool_type].tool_context;

535
536
537
  /*  initialize the tool options structure  */
  tool_options_init ((ToolOptions *) options,
		     ((tool_type == BUCKET_FILL) ?
538
		      _("Bucket Fill Options") :
539
		      ((tool_type == BLEND) ?
540
		       _("Blend Options") :
541
		       ((tool_type == PENCIL) ?
542
			_("Pencil Options") :
543
			((tool_type == PAINTBRUSH) ?
544
			 _("Paintbrush Options") :
545
			 ((tool_type == ERASER) ?
Sven Neumann's avatar
Sven Neumann committed
546
			  _("Eraser Options") :
547
			  ((tool_type == AIRBRUSH) ?
548
			   _("Airbrush Options") :
549
			   ((tool_type == CLONE) ?
550
			    _("Clone Tool Options") :
551
			    ((tool_type == CONVOLVE) ?
552
			     _("Convolver Options") :
553
			     ((tool_type == INK) ?
554
555
556
557
558
			      _("Ink Options") :
			      ((tool_type == DODGEBURN) ?
			       _("Dodge or Burn Options") :
			       ((tool_type == SMUDGE) ?
				_("Smudge Options") :
559
560
				((tool_type == XINPUT_AIRBRUSH) ?
				 _("Xinput Airbrush Options") :
561
				 "ERROR: Unknown Paint Type")))))))))))),
562
563
564
		     reset_func);

  /*  initialize the paint options structure  */
565
566
567
568
  options->global        = NULL;
  options->opacity_w     = NULL;
  options->paint_mode_w  = NULL;
  options->incremental_w = NULL;
569
570
571
  options->incremental = options->incremental_d = FALSE;

  options->pressure_options = paint_pressure_options_new (tool_type);
572
573
574
575
576
577
578
579
580
581
582
583
584
585

  /*  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 =
586
587
    gtk_adjustment_new (gimp_context_get_opacity (tool_context) * 100,
			0.0, 100.0, 1.0, 1.0, 0.0);
588
589
590
  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);
591
  gtk_signal_connect (GTK_OBJECT (options->opacity_w), "value_changed",
592
		      GTK_SIGNAL_FUNC (tool_options_opacity_adjustment_update),
593
594
595
596
		      tool_context);
  gimp_table_attach_aligned (GTK_TABLE (table), 0,
			     _("Opacity:"), 1.0, 1.0,
			     scale, FALSE);
597
598
599
600
601
602
603
604
605
606
607

  /*  the paint mode menu  */
  switch (tool_type)
    {
    case BUCKET_FILL:
    case BLEND:
    case PENCIL:
    case PAINTBRUSH:
    case AIRBRUSH:
    case CLONE:
    case INK:
608
    case XINPUT_AIRBRUSH:
609
610
611
612
      gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);

      options->paint_mode_w = gtk_option_menu_new ();
      menu =
613
	paint_mode_menu_new (tool_options_paint_mode_update, tool_context);
614
      gtk_option_menu_set_menu (GTK_OPTION_MENU (options->paint_mode_w), menu);
615
616
      gtk_option_menu_set_history (GTK_OPTION_MENU (options->paint_mode_w),
				   gimp_context_get_paint_mode (tool_context));
617
618
619
620
621
622
623
      gimp_table_attach_aligned (GTK_TABLE (table), 1,
				 _("Mode:"), 1.0, 0.5,
				 options->paint_mode_w, TRUE);

      /* eek */
      gtk_object_set_data (GTK_OBJECT (options->paint_mode_w), "tool_context",
			   tool_info[tool_type].tool_context);
624
625
626
      break;
    case CONVOLVE:
    case ERASER:
627
628
    case DODGEBURN:
    case SMUDGE:
629
630
631
632
633
634
635
636
      break;
    default:
      break;
    }

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

637
638
  /*  a separator after the common paint options which can be global  */
  switch (tool_type)
639
    {
640
641
642
643
644
645
646
    case BUCKET_FILL:
    case BLEND:
    case CLONE:
    case CONVOLVE:
    case INK:
    case DODGEBURN:
    case SMUDGE:
647
    case XINPUT_AIRBRUSH:
648
649
650
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
      gtk_widget_show (separator);
651
652
653
654
655
656
657
658
      break;
    case AIRBRUSH:
    case ERASER:
    case PAINTBRUSH:
    case PENCIL:
      break;
    default:
      break;
659
660
661
662
663
    }

  if (! global_paint_options)
    gtk_widget_show (vbox);

664
665
666
667
668
669
670
671
672
673
674
675
  /*  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",
676
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
			  &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;
    }

693
694
695
696
697
698
699
700
  options->pressure_options = paint_pressure_options_new (tool_type);
  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);
    }

701
702
703
704
705
706
707
708
709
710
  /*  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;

711
  options = g_new (PaintOptions, 1);
712
713
714
715
716
717
718
719
720
721
722
  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)
{
723
724
725
726
  GimpContext *default_context;

  default_context = gimp_context_get_default ();

727
728
729
  if (options->opacity_w)
    {
      gtk_adjustment_set_value (GTK_ADJUSTMENT (options->opacity_w),
730
				gimp_context_get_opacity (default_context) * 100);
731
732
733
    }
  if (options->paint_mode_w)
    {
734
735
736
737
738
739
      GimpContext *context;

      context = (GimpContext *) gtk_object_get_data (GTK_OBJECT (options->paint_mode_w), "tool_context");

      gimp_context_set_paint_mode (GIMP_CONTEXT (context),
				   gimp_context_get_paint_mode (default_context));
740
      gtk_option_menu_set_history (GTK_OPTION_MENU (options->paint_mode_w),
741
				   gimp_context_get_paint_mode (default_context));
742
    }
743
744
745
746
747
  if (options->incremental_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(options->incremental_w),
				    options->incremental_d);
    }
748
749

  paint_pressure_options_reset (options->pressure_options);
750
751
}

752
753
754
755
756
757
758
759
760
static PaintPressureOptions *
paint_pressure_options_new (ToolType tool_type)
{
  PaintPressureOptions *pressure;
  GtkWidget *frame = NULL;
  GtkWidget *hbox = NULL;

  pressure = g_new (PaintPressureOptions, 1);
    
761
  pressure->opacity  = pressure->opacity_d  = TRUE;
762
  pressure->pressure = pressure->pressure_d = TRUE;
763
764
765
766
767
768
769
770
771
  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;
772
773
774

  switch (tool_type)
    {
775
    case AIRBRUSH:
776
777
778
779
780
781
    case CLONE:
    case CONVOLVE:
    case DODGEBURN:
    case ERASER:
    case PAINTBRUSH:
    case PENCIL:
782
    case SMUDGE:
783
784
785
786
787
788
789
790
791
792
793
794
795
      frame = gtk_frame_new (_("Pressure sensitivity"));
      hbox = gtk_hbox_new (FALSE, 2);
      gtk_container_add (GTK_CONTAINER (frame), hbox);
      gtk_widget_show (hbox);
      break;
    default:
      break;
    }

  /*  the opacity toggle  */
  switch (tool_type)
    {
    case CLONE:
796
    case DODGEBURN:
797
798
799
800
801
802
803
    case ERASER:
    case PAINTBRUSH:
    case PENCIL:
      pressure->opacity_w =
	gtk_check_button_new_with_label (_("Opacity"));
      gtk_container_add (GTK_CONTAINER (hbox), pressure->opacity_w);
      gtk_signal_connect (GTK_OBJECT (pressure->opacity_w), "toggled",
804
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
805
806
807
808
809
810
811
812
813
			  &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;
    }

814
 /*  the pressure toggle  */
815
816
  switch (tool_type)
    {
817
    case AIRBRUSH:
818
    case CLONE:
819
    case CONVOLVE:
820
821
    case DODGEBURN:
    case ERASER:
Sven Neumann's avatar
Sven Neumann committed
822
    case PAINTBRUSH:
823
824
    case SMUDGE:
      pressure->pressure_w = gtk_check_button_new_with_label (_("Pressure"));
825
826
      gtk_container_add (GTK_CONTAINER (hbox), pressure->pressure_w);
      gtk_signal_connect (GTK_OBJECT (pressure->pressure_w), "toggled",
827
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
828
829
830
831
832
833
834
835
836
			  &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;
    }

837
838
839
840
841
842
843
844
845
846
  /*  the rate toggle */
  switch (tool_type)
    {
    case AIRBRUSH:
    case CONVOLVE:
    case SMUDGE:
      pressure->rate_w =
	gtk_check_button_new_with_label (_("Rate"));
      gtk_container_add (GTK_CONTAINER (hbox), pressure->rate_w);
      gtk_signal_connect (GTK_OBJECT (pressure->rate_w), "toggled",
847
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
848
849
850
851
852
853
854
855
856
			  &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;
    }

857
858
859
860
861
862
863
864
865
866
867
868
869
870
  /*  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"));
      gtk_container_add (GTK_CONTAINER (hbox), pressure->size_w);
      gtk_signal_connect (GTK_OBJECT (pressure->size_w), "toggled",
871
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
			  &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"));
      gtk_container_add (GTK_CONTAINER (hbox), pressure->color_w);
      gtk_signal_connect (GTK_OBJECT (pressure->color_w), "toggled",
891
			  GTK_SIGNAL_FUNC (tool_options_toggle_update),
892
893
894
895
896
897
898
899
			  &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;
    }
900

901
902
  pressure->frame = frame;

903
  return pressure;
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
}

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);
    }
919
920
921
922
923
  if (pressure->rate_w)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->rate_w),
				    pressure->rate_d);
    }
924
925
926
927
928
929
930
931
932
933
934
935
936
  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);
    }
}


937
938
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
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
/*  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 *
paint_mode_menu_new (MenuItemCallback callback,
		     gpointer         user_data)
{
  GtkWidget *menu;
984
  gint i;
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016

  static MenuItem option_items[] =
  {
    { N_("Normal"), 0, 0, NULL, (gpointer) NORMAL_MODE, NULL, NULL },
    { N_("Dissolve"), 0, 0, NULL, (gpointer) DISSOLVE_MODE, NULL, NULL },
    { N_("Behind"), 0, 0, NULL, (gpointer) BEHIND_MODE, NULL, NULL },
    { N_("Multiply (Burn)"), 0, 0, NULL, (gpointer) MULTIPLY_MODE, NULL, NULL },
    { N_("Divide (Dodge)"), 0, 0, NULL, (gpointer) DIVIDE_MODE, NULL, NULL },
    { N_("Screen"), 0, 0, NULL, (gpointer) SCREEN_MODE, NULL, NULL },
    { N_("Overlay"), 0, 0, NULL, (gpointer) OVERLAY_MODE, NULL, NULL },
    { N_("Difference"), 0, 0, NULL, (gpointer) DIFFERENCE_MODE, NULL, NULL },
    { N_("Addition"), 0, 0, NULL, (gpointer) ADDITION_MODE, NULL, NULL },
    { N_("Subtract"), 0, 0, NULL, (gpointer) SUBTRACT_MODE, NULL, NULL },
    { N_("Darken Only"), 0, 0, NULL, (gpointer) DARKEN_ONLY_MODE, NULL, NULL },
    { N_("Lighten Only"), 0, 0, NULL, (gpointer) LIGHTEN_ONLY_MODE, NULL, NULL },
    { N_("Hue"), 0, 0, NULL, (gpointer) HUE_MODE, NULL, NULL },
    { N_("Saturation"), 0, 0, NULL, (gpointer) SATURATION_MODE, NULL, NULL },
    { N_("Color"), 0, 0, NULL, (gpointer) COLOR_MODE, NULL, NULL },
    { N_("Value"), 0, 0, NULL, (gpointer) VALUE_MODE, NULL, NULL },
    { NULL, 0, 0, NULL, NULL, NULL, NULL }
  };

  for (i = 0; i <= VALUE_MODE; i++)
    option_items[i].callback = callback;

  menu = build_menu (option_items, NULL);

  for (i = 0; i <= VALUE_MODE; i++)
    gtk_object_set_user_data (GTK_OBJECT (option_items[i].widget), user_data);

  return menu;
}