color-rotate-dialog.c 22.5 KB
Newer Older
Sven Neumann's avatar
Sven Neumann committed
1 2 3
/*
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This is a plug-in for GIMP.
Sven Neumann's avatar
Sven Neumann committed
5 6 7 8 9 10 11
 *
 * Colormap-Rotation plug-in. Exchanges two color ranges.
 *
 * Copyright (C) 1999 Sven Anders (anderss@fmi.uni-passau.de)
 *                    Based on code from Pavel Grinfeld (pavel@ml.com)
 *
 *
12
 * This program is free software: you can redistribute it and/or modify
Sven Neumann's avatar
Sven Neumann committed
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 3 of the License, or
Sven Neumann's avatar
Sven Neumann committed
15 16 17 18 19 20 21 22
 * (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
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Sven Neumann's avatar
Sven Neumann committed
24 25
 */

26
/*---------------------------------------------------------------------------
Sven Neumann's avatar
Sven Neumann committed
27
 * Change log:
28
 *
Sven Neumann's avatar
Sven Neumann committed
29 30 31 32 33 34 35
 * Version 2.0, 04 April 1999.
 *  Nearly complete rewrite, made plug-in stable.
 *  (Works with GIMP 1.1 and GTK+ 1.2)
 *
 * Version 1.0, 27 March 1997.
 *  Initial (unstable) release by Pavel Grinfeld
 *
36 37 38
 *---------------------------------------------------------------------------*/

#include "config.h"
Sven Neumann's avatar
Sven Neumann committed
39

40 41 42
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>

43 44 45 46 47 48
#include "color-rotate.h"
#include "color-rotate-utils.h"
#include "color-rotate-draw.h"
#include "color-rotate-callbacks.h"
#include "color-rotate-dialog.h"
#include "color-rotate-stock.h"
Sven Neumann's avatar
Sven Neumann committed
49

50
#include "images/color-rotate-stock-pixbufs.h"
Michael Natterer's avatar
Michael Natterer committed
51

Michael Natterer's avatar
Michael Natterer committed
52 53
#include "libgimp/stdplugins-intl.h"

Michael Natterer's avatar
Michael Natterer committed
54

Sven Neumann's avatar
Sven Neumann committed
55 56 57
/* Defines */

#define INITIAL_ALPHA      0
58
#define INITIAL_BETA       G_PI_2
Sven Neumann's avatar
Sven Neumann committed
59 60 61 62 63 64 65 66 67 68 69
#define INITIAL_GRAY_SAT   0.0
#define INITIAL_GRAY_RSAT  0.0
#define INITIAL_GRAY_HUE   0.0

#define RANGE_ADJUST_MASK GDK_EXPOSURE_MASK | \
                          GDK_ENTER_NOTIFY_MASK | \
                          GDK_BUTTON_PRESS_MASK | \
                          GDK_BUTTON_RELEASE_MASK | \
                          GDK_BUTTON1_MOTION_MASK | \
                          GDK_POINTER_MOTION_HINT_MASK

Michael Natterer's avatar
Michael Natterer committed
70

Sven Neumann's avatar
Sven Neumann committed
71 72
/* Previews: create one preview */

73
static GtkWidget *
74
rcm_create_one_preview (GtkWidget **preview,
75
                        gint        mode,
76 77
			gint        width,
			gint        height)
Sven Neumann's avatar
Sven Neumann committed
78
{
79 80 81 82 83 84 85
  GtkWidget *align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
  GtkWidget *frame;

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  gtk_container_add (GTK_CONTAINER (align), frame);
  gtk_widget_show (frame);
86

87
  *preview = gimp_preview_area_new ();
Sven Neumann's avatar
Sven Neumann committed
88

89 90
  gtk_widget_set_size_request (*preview, width, height);
  gtk_container_add (GTK_CONTAINER (frame), *preview);
Michael Natterer's avatar
Michael Natterer committed
91
  gtk_widget_show (*preview);
92

93 94
  g_object_set_data (G_OBJECT (*preview), "mode", GINT_TO_POINTER (mode));

95
  return align;
Sven Neumann's avatar
Sven Neumann committed
96 97
}

Michael Natterer's avatar
Michael Natterer committed
98

Sven Neumann's avatar
Sven Neumann committed
99 100
/* Previews */

101
static GtkWidget *
Sven Neumann's avatar
Sven Neumann committed
102
rcm_create_previews (void)
Sven Neumann's avatar
Sven Neumann committed
103
{
104 105 106 107 108 109 110
  GtkWidget *top_vbox;
  GtkWidget *vbox;
  GtkWidget *frame;
  GtkWidget *hbox;
  GtkWidget *label;
  GtkWidget *button;
  GtkWidget *combo;
Sven Neumann's avatar
Sven Neumann committed
111

Michael Natterer's avatar
Michael Natterer committed
112
  top_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
113

Michael Natterer's avatar
Michael Natterer committed
114
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
115 116 117 118 119 120
  gtk_box_pack_start (GTK_BOX (top_vbox), vbox, TRUE, TRUE, 0);
  gtk_widget_show (vbox);

  label = gtk_label_new (_("Original"));
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
121

122
  frame = rcm_create_one_preview (&Current.Bna->before, ORIGINAL,
123 124
                                  Current.reduced->width,
                                  Current.reduced->height);
125 126
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
Sven Neumann's avatar
Sven Neumann committed
127

128 129 130 131
  g_signal_connect_after (Current.Bna->before, "size-allocate",
                          G_CALLBACK (rcm_render_preview),
                          NULL);

Michael Natterer's avatar
Michael Natterer committed
132
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
133 134
  gtk_box_pack_start (GTK_BOX (top_vbox), vbox, TRUE, TRUE, 0);
  gtk_widget_show (vbox);
Sven Neumann's avatar
Sven Neumann committed
135

136 137 138
  label = gtk_label_new (_("Rotated"));
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);
139

140
  frame = rcm_create_one_preview (&Current.Bna->after, CURRENT,
141 142
                                  Current.reduced->width,
                                  Current.reduced->height);
143 144
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
Sven Neumann's avatar
Sven Neumann committed
145

146 147 148 149
  g_signal_connect_after (Current.Bna->after, "size-allocate",
                          G_CALLBACK (rcm_render_preview),
                          NULL);

Michael Natterer's avatar
Michael Natterer committed
150
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
151 152
  gtk_box_pack_start (GTK_BOX (top_vbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);
153

154 155 156 157
  button = gtk_check_button_new_with_label (_("Continuous update"));
  gtk_box_pack_start(GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), Current.RealTime);
  gtk_widget_show (button);
158

159 160 161
  g_signal_connect (button, "clicked",
                    G_CALLBACK (rcm_preview_as_you_drag),
                    &(Current.RealTime));
Sven Neumann's avatar
Sven Neumann committed
162

Michael Natterer's avatar
Michael Natterer committed
163
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
164 165
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);
Sven Neumann's avatar
Sven Neumann committed
166

167 168 169
  label = gtk_label_new (_("Area:"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
170

171 172 173 174 175
  combo = gimp_int_combo_box_new (_("Entire Layer"), ENTIRE_IMAGE,
                                  _("Selection"),    SELECTION,
                                  _("Context"),      SELECTION_IN_CONTEXT,
                                  NULL);
  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), Current.Slctn);
Sven Neumann's avatar
Sven Neumann committed
176

177 178
  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
  gtk_widget_show (combo);
Sven Neumann's avatar
Sven Neumann committed
179

180 181 182 183 184 185 186
  g_signal_connect (combo, "changed",
                    G_CALLBACK (rcm_combo_callback),
                    NULL);

  gtk_widget_show (top_vbox);

  return top_vbox;
Sven Neumann's avatar
Sven Neumann committed
187 188
}

Michael Natterer's avatar
Michael Natterer committed
189

Sven Neumann's avatar
Sven Neumann committed
190 191
/* Main: One circles with values and buttons */

192
static RcmCircle*
193 194
rcm_create_one_circle (gint         height,
		       const gchar *label_content)
Sven Neumann's avatar
Sven Neumann committed
195
{
Michael Natterer's avatar
Michael Natterer committed
196
  GtkWidget     *frame, *button_table, *legend_table;
197
  GtkWidget     *label, *button, *entry;
Sven Neumann's avatar
Sven Neumann committed
198
  GtkAdjustment *adj;
Michael Natterer's avatar
Michael Natterer committed
199
  RcmCircle     *st;
Sven Neumann's avatar
Sven Neumann committed
200

Michael Natterer's avatar
Michael Natterer committed
201
  st = g_new (RcmCircle, 1);
Sven Neumann's avatar
Sven Neumann committed
202

Michael Natterer's avatar
Michael Natterer committed
203 204 205
  st->angle         = g_new (RcmAngle, 1);
  st->angle->alpha  = INITIAL_ALPHA;
  st->angle->beta   = INITIAL_BETA;
Sven Neumann's avatar
Sven Neumann committed
206 207 208
  st->angle->cw_ccw = 1;

  /** Main: Circle: create (main) frame **/
209
  st->frame = gimp_frame_new (label_content);
Michael Natterer's avatar
Michael Natterer committed
210
  gtk_widget_show (st->frame);
Sven Neumann's avatar
Sven Neumann committed
211 212 213 214

  /** Main: Circle: create frame & preview **/

  /* create frame */
Michael Natterer's avatar
Michael Natterer committed
215 216 217
  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  gtk_widget_show (frame);
218

Sven Neumann's avatar
Sven Neumann committed
219
  /* create preview */
220 221
  st->preview = gimp_preview_area_new ();
  gtk_widget_set_size_request (st->preview, height, height);
Michael Natterer's avatar
Michael Natterer committed
222 223
  gtk_container_add (GTK_CONTAINER (frame), st->preview);
  gtk_widget_show (st->preview);
Sven Neumann's avatar
Sven Neumann committed
224 225

  /* set signals */
Michael Natterer's avatar
Michael Natterer committed
226
  gtk_widget_set_events (st->preview, RANGE_ADJUST_MASK);
Sven Neumann's avatar
Sven Neumann committed
227

228
  g_signal_connect_after (st->preview, "expose-event",
229 230
                          G_CALLBACK (rcm_expose_event),
                          st);
231

232
  g_signal_connect (st->preview, "button-press-event",
233 234
                    G_CALLBACK (rcm_button_press_event),
                    st);
Sven Neumann's avatar
Sven Neumann committed
235

236
  g_signal_connect (st->preview, "button-release-event",
237 238
                    G_CALLBACK (rcm_release_event),
                    st);
239

240
  g_signal_connect (st->preview, "motion-notify-event",
241 242
                    G_CALLBACK (rcm_motion_notify_event),
                    st);
243 244

  /** Main: Circle: create table for buttons **/
Michael Natterer's avatar
Michael Natterer committed
245 246
  button_table = gtk_table_new (3, 1, FALSE);
  gtk_widget_show (button_table);
Sven Neumann's avatar
Sven Neumann committed
247 248

  /** Main: Circle: Buttons **/
249 250

  button = gtk_button_new_from_stock (st->angle->cw_ccw > 0 ?
251 252
                                      STOCK_COLOR_ROTATE_SWITCH_CLOCKWISE :
                                      STOCK_COLOR_ROTATE_SWITCH_COUNTERCLOCKWISE);
253 254 255 256 257 258 259
  g_signal_connect (button, "clicked",
                    G_CALLBACK (rcm_cw_ccw),
                    st);
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (button_table), button,
                    0, 1, 0, 1,
                    GTK_EXPAND | GTK_FILL, GTK_FILL, 4, 2);
Michael Natterer's avatar
Michael Natterer committed
260

Sven Neumann's avatar
Sven Neumann committed
261
  st->cw_ccw_pixmap = NULL;
262
  st->cw_ccw_button = button;
263 264 265
  st->cw_ccw_box    = NULL;
  st->cw_ccw_label  = NULL;

266
  button = gtk_button_new_from_stock (STOCK_COLOR_ROTATE_CHANGE_ORDER);
267 268 269 270 271 272 273
  g_signal_connect (button, "clicked",
                    G_CALLBACK (rcm_a_to_b),
                    st);
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (button_table), button,
                    0, 1, 1, 2,
                    GTK_EXPAND | GTK_FILL, GTK_FILL, 4, 2);
Sven Neumann's avatar
Sven Neumann committed
274 275

  st->a_b_pixmap = NULL;
276
  st->a_b_box    = NULL;
277
  st->a_b_button = button;
Sven Neumann's avatar
Sven Neumann committed
278

279
  button = gtk_button_new_from_stock (STOCK_COLOR_ROTATE_SELECT_ALL);
280 281 282 283 284 285 286
  g_signal_connect (button, "clicked",
                    G_CALLBACK (rcm_360_degrees),
                    st);
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (button_table), button,
                    0, 1, 2, 3,
                    GTK_EXPAND | GTK_FILL, GTK_FILL, 4, 2);
Michael Natterer's avatar
Michael Natterer committed
287

Sven Neumann's avatar
Sven Neumann committed
288
  st->f360_pixmap = NULL;
289
  st->f360_box    = NULL;
290
  st->f360_button = button;
Sven Neumann's avatar
Sven Neumann committed
291 292

  /** Main: Circle: Legend **/
Michael Natterer's avatar
Michael Natterer committed
293 294
  legend_table = gtk_table_new (1, 6, FALSE);
  gtk_widget_show (legend_table);
Sven Neumann's avatar
Sven Neumann committed
295 296

  /* spinbutton 1 */
297
  label = gtk_label_new (C_("color-range", "From:"));
Michael Natterer's avatar
Michael Natterer committed
298 299 300
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (legend_table), label, 0, 1, 0, 1,
                    0, GTK_EXPAND, 5, 5);
Sven Neumann's avatar
Sven Neumann committed
301 302 303 304 305 306

  st->angle->alpha = INITIAL_ALPHA;
  adj = (GtkAdjustment *) gtk_adjustment_new(st->angle->alpha, 0.0, 2.0, 0.0001, 0.001, 0.0);
  st->alpha_entry = entry = gtk_spin_button_new(adj, 0.01, 4);
  gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(entry), TRUE);
  gtk_table_attach(GTK_TABLE(legend_table), entry, 1,2, 0,1,
Sven Neumann's avatar
Sven Neumann committed
307
		   GTK_EXPAND|GTK_FILL, GTK_EXPAND, 2, 4);
308 309
  gtk_widget_show(entry);

310
  g_signal_connect (entry, "changed",
311 312
                    G_CALLBACK (rcm_set_alpha),
                    st);
Sven Neumann's avatar
Sven Neumann committed
313 314

  /* label */
315
  st->alpha_units_label = gtk_label_new (rcm_units_string (Current.Units));
Michael Natterer's avatar
Michael Natterer committed
316
  gtk_widget_show (st->alpha_units_label);
Sven Neumann's avatar
Sven Neumann committed
317

318 319
  gtk_table_attach (GTK_TABLE (legend_table),
                    st->alpha_units_label, 2, 3, 0, 1,
Michael Natterer's avatar
Michael Natterer committed
320
                    0, GTK_EXPAND, 4, 4);
Sven Neumann's avatar
Sven Neumann committed
321 322

  /* spinbutton 2 */
323
  label = gtk_label_new (C_("color-range", "To:"));
Michael Natterer's avatar
Michael Natterer committed
324 325 326
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (legend_table), label, 3,4, 0,1,
                    0, GTK_EXPAND, 4, 4);
Sven Neumann's avatar
Sven Neumann committed
327 328

  st->angle->beta = INITIAL_BETA;
329 330
  adj = (GtkAdjustment *) gtk_adjustment_new (st->angle->beta,
                                              0.0, 2.0, 0.0001, 0.001, 0.0);
Michael Natterer's avatar
Michael Natterer committed
331 332 333 334 335
  st->beta_entry = entry = gtk_spin_button_new (adj, 0.01, 4);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (entry), TRUE);
  gtk_table_attach (GTK_TABLE (legend_table), entry, 4,5, 0,1,
                    GTK_EXPAND|GTK_FILL, GTK_EXPAND, 2, 4);
  gtk_widget_show (entry);
336

337
  g_signal_connect (entry, "changed",
338 339
                    G_CALLBACK (rcm_set_beta),
                    st);
Sven Neumann's avatar
Sven Neumann committed
340 341

  /* label */
Michael Natterer's avatar
Michael Natterer committed
342 343
  st->beta_units_label = gtk_label_new (rcm_units_string (Current.Units));
  gtk_widget_show (st->beta_units_label);
Sven Neumann's avatar
Sven Neumann committed
344

Michael Natterer's avatar
Michael Natterer committed
345 346
  gtk_table_attach (GTK_TABLE (legend_table), st->beta_units_label, 5,6, 0,1,
                    0, GTK_EXPAND, 4, 4);
Sven Neumann's avatar
Sven Neumann committed
347 348

  /* Main: Circle: create table for Preview / Buttons / Legend */
Michael Natterer's avatar
Michael Natterer committed
349 350
  st->table= gtk_table_new (2, 2, FALSE);
  gtk_widget_show (st->table);
351

Michael Natterer's avatar
Michael Natterer committed
352 353
  gtk_table_attach (GTK_TABLE (st->table), frame, 0, 1, 0, 1,
                    0, GTK_EXPAND, 4, 0);
354

Michael Natterer's avatar
Michael Natterer committed
355 356
  gtk_table_attach (GTK_TABLE (st->table), button_table, 1, 2, 0, 1,
                    0, GTK_EXPAND, 2, 0);
357

Michael Natterer's avatar
Michael Natterer committed
358 359
  gtk_table_attach (GTK_TABLE (st->table), legend_table, 0, 2, 1, 2,
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 2);
Sven Neumann's avatar
Sven Neumann committed
360 361

  /* add table to (main) frame */
Michael Natterer's avatar
Michael Natterer committed
362
  gtk_container_add (GTK_CONTAINER (st->frame), st->table);
363

Sven Neumann's avatar
Sven Neumann committed
364 365 366
  return st;
}

Michael Natterer's avatar
Michael Natterer committed
367

Sven Neumann's avatar
Sven Neumann committed
368 369
/* Main */

370
static GtkWidget *
Sven Neumann's avatar
Sven Neumann committed
371
rcm_create_main (void)
Sven Neumann's avatar
Sven Neumann committed
372
{
373
  GtkWidget *vbox;
Sven Neumann's avatar
Sven Neumann committed
374

375 376
  Current.From = rcm_create_one_circle (SUM, C_("color-rotate", "From:"));
  Current.To   = rcm_create_one_circle (SUM, C_("color-rotate", "To:"));
Sven Neumann's avatar
Sven Neumann committed
377

Michael Natterer's avatar
Michael Natterer committed
378
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
379 380
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
  gtk_widget_show (vbox);
Sven Neumann's avatar
Sven Neumann committed
381

382 383 384 385
  gtk_box_pack_start (GTK_BOX (vbox), Current.From->frame,
		      FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), Current.To->frame,
		      FALSE, FALSE, 0);
Sven Neumann's avatar
Sven Neumann committed
386

387
  return vbox;
Sven Neumann's avatar
Sven Neumann committed
388 389
}

Michael Natterer's avatar
Michael Natterer committed
390

Sven Neumann's avatar
Sven Neumann committed
391 392
/* Misc: Gray */

393
static GtkWidget *
Sven Neumann's avatar
Sven Neumann committed
394
rcm_create_gray (void)
Sven Neumann's avatar
Sven Neumann committed
395
{
396 397 398 399 400 401 402 403
  GtkWidget *top_vbox, *vbox;
  GtkWidget *frame, *preview;
  GtkWidget *table;
  GtkWidget *entry;
  GtkWidget *radio_box;
  GtkWidget *hbox;
  GtkWidget *label;
  GtkWidget *button;
Michael Natterer's avatar
Michael Natterer committed
404 405
  GSList    *group = NULL;
  RcmGray   *st;
Sven Neumann's avatar
Sven Neumann committed
406 407
  GtkAdjustment *adj;

408
  Current.Gray = st = g_new (RcmGray, 1);
409 410
  st->hue   = 0;
  st->satur = 0;
Sven Neumann's avatar
Sven Neumann committed
411

Michael Natterer's avatar
Michael Natterer committed
412
  top_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
413 414 415 416 417
  gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 12);
  gtk_widget_show (top_vbox);

  frame = gimp_frame_new (_("Gray"));
  gtk_box_pack_start (GTK_BOX (top_vbox), frame, FALSE, FALSE, 0);
418
  gtk_widget_show (frame);
Sven Neumann's avatar
Sven Neumann committed
419

Michael Natterer's avatar
Michael Natterer committed
420
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
421 422 423
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

Michael Natterer's avatar
Michael Natterer committed
424
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
425 426 427 428 429 430 431
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
432

433 434
  st->preview = preview = gimp_preview_area_new ();
  gtk_widget_set_size_request (preview, GRAY_SUM, GRAY_SUM);
435
  gtk_container_add (GTK_CONTAINER (frame), preview);
436
  gtk_widget_show (preview);
Sven Neumann's avatar
Sven Neumann committed
437

438
  gtk_widget_add_events (preview, RANGE_ADJUST_MASK);
Sven Neumann's avatar
Sven Neumann committed
439

440
  g_signal_connect_after (preview, "expose-event",
441 442
                          G_CALLBACK (rcm_gray_expose_event),
                          st);
Sven Neumann's avatar
Sven Neumann committed
443

444
  g_signal_connect (preview, "button-press-event",
445 446
                    G_CALLBACK (rcm_gray_button_press_event),
                    st);
Sven Neumann's avatar
Sven Neumann committed
447

448
  g_signal_connect (preview, "button-release-event",
449 450
                    G_CALLBACK (rcm_gray_release_event),
                    st);
Sven Neumann's avatar
Sven Neumann committed
451

452
  g_signal_connect (preview, "motion-notify-event",
453 454
                    G_CALLBACK (rcm_gray_motion_notify_event),
                    st);
455

456
  /* Gray: Circle: Legend */
457 458 459 460 461
  table = gtk_table_new (2, 3, FALSE);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  gtk_widget_show (table);
462 463 464

  /* Gray: Circle: Spinbutton 1 */
  label = gtk_label_new(_("Hue:"));
465 466
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
467 468
		    GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
469 470

  st->hue = INITIAL_GRAY_HUE;
471 472
  adj = (GtkAdjustment *) gtk_adjustment_new (st->hue,
                                              0.0, 2.0, 0.0001, 0.001, 0.0);
473 474
  st->hue_entry = entry = gtk_spin_button_new (adj, 0.01, 4);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON(entry), TRUE);
475 476
  gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
                    GTK_FILL, GTK_FILL, 0, 0);
477
  gtk_widget_show (entry);
Sven Neumann's avatar
Sven Neumann committed
478

479
  g_signal_connect (entry, "changed",
480 481 482
                    G_CALLBACK (rcm_set_hue),
                    st);

Sven Neumann's avatar
Sven Neumann committed
483
  /* Gray: Circle: units label */
484 485
  st->hue_units_label = gtk_label_new (rcm_units_string (Current.Units));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
486 487
  gtk_table_attach (GTK_TABLE (table), st->hue_units_label, 2, 3, 0, 1,
		    GTK_FILL, GTK_FILL, 0, 0);
488
  gtk_widget_show (st->hue_units_label);
Sven Neumann's avatar
Sven Neumann committed
489 490

  /* Gray: Circle: Spinbutton 2 */
491 492
  label = gtk_label_new (_("Saturation:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
493
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
494 495
		    GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
496 497

  st->satur = INITIAL_GRAY_SAT;
498 499
  adj = (GtkAdjustment *) gtk_adjustment_new (st->satur,
                                              0.0, 1.0, 0.0001, 0.001, 0.0);
500 501
  st->satur_entry = entry = gtk_spin_button_new (adj, 0.01, 4);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (entry), TRUE);
502 503
  gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2,
                    GTK_FILL, GTK_FILL, 0, 2);
504
  gtk_widget_show (entry);
Sven Neumann's avatar
Sven Neumann committed
505

506
  g_signal_connect (entry, "changed",
507 508 509
                    G_CALLBACK (rcm_set_satur),
                    st);

Sven Neumann's avatar
Sven Neumann committed
510
  /** Gray: Operation-Mode **/
511 512 513
  frame = gimp_frame_new (_("Gray Mode"));
  gtk_box_pack_start (GTK_BOX (top_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
Sven Neumann's avatar
Sven Neumann committed
514

Michael Natterer's avatar
Michael Natterer committed
515
  radio_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
516
  gtk_container_add (GTK_CONTAINER (frame), radio_box);
517
  gtk_widget_show (radio_box);
Sven Neumann's avatar
Sven Neumann committed
518 519 520

  /* Gray: Operation-Mode: two radio buttons */
  button = gtk_radio_button_new_with_label(group, _("Treat as this"));
521
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
522
  gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, FALSE, 0);
523 524
  gtk_widget_show (button);

525 526
  if (Current.Gray_to_from == GRAY_FROM)
    gtk_button_clicked (GTK_BUTTON (button));
527

528
  g_signal_connect (button, "clicked",
529 530
                    G_CALLBACK (rcm_switch_to_gray_from),
                    &(Current.Gray_to_from));
Sven Neumann's avatar
Sven Neumann committed
531

532
  button = gtk_radio_button_new_with_label (group, _("Change to this"));
533
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
534
  gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, FALSE, 0);
535 536
  gtk_widget_show (button);

537 538
  if (Current.Gray_to_from == GRAY_TO)
    gtk_button_clicked (GTK_BUTTON (button));
539

540
  g_signal_connect (button, "clicked",
541 542
                    G_CALLBACK (rcm_switch_to_gray_to),
                    &(Current.Gray_to_from));
Sven Neumann's avatar
Sven Neumann committed
543

544
  /** Gray: What is gray? **/
545 546 547
  frame = gimp_frame_new (_("Gray Threshold"));
  gtk_box_pack_start (GTK_BOX (top_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
548

Michael Natterer's avatar
Michael Natterer committed
549
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
550 551
  gtk_container_add (GTK_CONTAINER (frame), hbox);
  gtk_widget_show (hbox);
552

553
  label = gtk_label_new (_("Saturation:"));
554
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
555
  gtk_widget_show (label);
Sven Neumann's avatar
Sven Neumann committed
556 557

  st->gray_sat = INITIAL_GRAY_RSAT;
558 559
  adj = (GtkAdjustment *) gtk_adjustment_new (st->gray_sat,
                                              0.0, 1.0, 0.0001, 0.001, 0.0);
Sven Neumann's avatar
Sven Neumann committed
560

561
  entry = gtk_spin_button_new (adj, 0.01, 4);
562
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (entry), TRUE);
563
  gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
564 565
  gtk_widget_show (entry);

566
  g_signal_connect (entry, "changed",
567 568
                    G_CALLBACK (rcm_set_gray_sat),
                    st);
Sven Neumann's avatar
Sven Neumann committed
569

570
  return top_vbox;
Sven Neumann's avatar
Sven Neumann committed
571 572
}

Michael Natterer's avatar
Michael Natterer committed
573

Sven Neumann's avatar
Sven Neumann committed
574 575
/* Misc */

576
static GtkWidget *
577
rcm_create_units (void)
Sven Neumann's avatar
Sven Neumann committed
578
{
579 580
  GtkWidget *frame;
  GtkWidget *vbox;
Sven Neumann's avatar
Sven Neumann committed
581
  GtkWidget *button;
582
  GSList    *group = NULL;
Sven Neumann's avatar
Sven Neumann committed
583 584

  /** Misc: Used unit selection **/
585 586 587
  frame = gimp_frame_new (_("Units"));
  gtk_container_set_border_width (GTK_CONTAINER (frame), 12);
  gtk_widget_show (frame);
Sven Neumann's avatar
Sven Neumann committed
588

Michael Natterer's avatar
Michael Natterer committed
589
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
590 591
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);
Sven Neumann's avatar
Sven Neumann committed
592 593

  /* Misc: Used unit selection: 3 radio buttons */
594 595 596
  button = gtk_radio_button_new_with_label (group, _("Radians"));
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
597 598
  gtk_widget_show (button);

599 600
  if (Current.Units == RADIANS)
    gtk_button_clicked (GTK_BUTTON (button));
601

602
  g_signal_connect (button, "clicked",
603 604
                    G_CALLBACK (rcm_switch_to_radians),
                    NULL);
605

606 607 608
  button = gtk_radio_button_new_with_label (group, _("Radians/Pi"));
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
609 610
  gtk_widget_show (button);

611 612
  if (Current.Units == RADIANS_OVER_PI)
    gtk_button_clicked (GTK_BUTTON (button));
613

614
  g_signal_connect (button, "clicked",
615 616
                    G_CALLBACK (rcm_switch_to_radians_over_PI),
                    NULL);
Sven Neumann's avatar
Sven Neumann committed
617

618 619
  button = gtk_radio_button_new_with_label (group, _("Degrees"));
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
620 621
  gtk_widget_show (button);

622 623
  if (Current.Units == DEGREES)
    gtk_button_clicked (GTK_BUTTON (button));
624

625
  g_signal_connect (button, "clicked",
626 627
                    G_CALLBACK (rcm_switch_to_degrees),
                    NULL);
Sven Neumann's avatar
Sven Neumann committed
628

629
  return frame;
Sven Neumann's avatar
Sven Neumann committed
630 631
}

Michael Natterer's avatar
Michael Natterer committed
632

Sven Neumann's avatar
Sven Neumann committed
633 634
/* create and call main dialog */

635
gboolean
636
color_rotate_dialog (void)
Sven Neumann's avatar
Sven Neumann committed
637
{
638 639 640
  GtkWidget *dialog;
  GtkWidget *hbox;
  GtkWidget *notebook;
641
  GtkWidget *previews;
642
  gboolean   run;
Sven Neumann's avatar
Sven Neumann committed
643

644
  Current.Bna = g_new (RcmBna, 1);
Sven Neumann's avatar
Sven Neumann committed
645

646
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
647
  color_rotate_stock_init ();
648

649
  dialog = gimp_dialog_new (_("Rotate Colors"), PLUG_IN_ROLE,
650 651
                            NULL, 0,
                            gimp_standard_help_func, PLUG_IN_PROC,
Sven Neumann's avatar
Sven Neumann committed
652

653 654
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
655

656
                            NULL);
Sven Neumann's avatar
Sven Neumann committed
657

658
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
659 660 661
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);
662

663
  gimp_window_set_transient (GTK_WINDOW (dialog));
664

665
  Current.Bna->dlg = dialog;
Sven Neumann's avatar
Sven Neumann committed
666

667 668
  /* Create sub-dialogs */
  Current.reduced = rcm_reduce_image (Current.drawable, Current.mask,
669 670
                                      MAX_PREVIEW_SIZE, Current.Slctn);

671
  Current.Bna->bna_frame = previews = rcm_create_previews ();
Sven Neumann's avatar
Sven Neumann committed
672 673

  /* H-Box */
Michael Natterer's avatar
Michael Natterer committed
674
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
675
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
676 677
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                      hbox, TRUE, TRUE, 0);
678
  gtk_widget_show (hbox);
Sven Neumann's avatar
Sven Neumann committed
679

680
  gtk_box_pack_start (GTK_BOX (hbox), previews, TRUE, TRUE, 0);
Sven Neumann's avatar
Sven Neumann committed
681 682

  /* Notebook */
683
  notebook = gtk_notebook_new ();
684
  gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
685 686
  gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0);
  gtk_widget_show (notebook);
Sven Neumann's avatar
Sven Neumann committed
687

688 689
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), rcm_create_main (),
			    gtk_label_new (_("Main Options")));
Sven Neumann's avatar
Sven Neumann committed
690

691 692
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), rcm_create_gray (),
			    gtk_label_new (_("Gray Options")));
Sven Neumann's avatar
Sven Neumann committed
693

694 695
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), rcm_create_units (),
			    gtk_label_new (_("Units")));
Sven Neumann's avatar
Sven Neumann committed
696

697
  gtk_widget_show (dialog);
Sven Neumann's avatar
Sven Neumann committed
698

699 700 701
  rcm_render_circle (Current.From->preview, SUM, MARGIN);
  rcm_render_circle (Current.To->preview, SUM, MARGIN);
  rcm_render_circle (Current.Gray->preview, GRAY_SUM, GRAY_MARGIN);
702

703
  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
704

705
  gtk_widget_destroy (dialog);
Sven Neumann's avatar
Sven Neumann committed
706

707
  return run;
Sven Neumann's avatar
Sven Neumann committed
708
}