1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
5
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
7
* based on color_notebook module
8
* Copyright (C) 1998 Austin Donnelly <austin@greenend.org.uk>
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Library General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the
22
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23
* Boston, MA 02111-1307, USA.
32
#include "libgimpcolor/gimpcolor.h"
33
#include "libgimpmath/gimpmath.h"
35
#include "gimpwidgetstypes.h"
37
#include "gimpcolorscale.h"
38
#include "gimpcolorscales.h"
39
#include "gimpcolorhexentry.h"
40
#include "gimpwidgets.h"
42
#include "libgimp/libgimp-intl.h"
45
#define GIMP_COLOR_SCALES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_SCALES, GimpColorScalesClass))
46
#define GIMP_IS_COLOR_SCALES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_SCALES))
47
#define GIMP_COLOR_SCALES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_SCALES, GimpColorScalesClass))
50
typedef struct _GimpColorScalesClass GimpColorScalesClass;
52
struct _GimpColorScales
54
GimpColorSelector parent_instance;
56
GtkWidget *toggles[7];
57
GtkWidget *sliders[7];
58
GtkObject *slider_data[7];
62
struct _GimpColorScalesClass
64
GimpColorSelectorClass parent_class;
68
static void gimp_color_scales_class_init (GimpColorScalesClass *klass);
69
static void gimp_color_scales_init (GimpColorScales *scales);
71
static void gimp_color_scales_togg_sensitive (GimpColorSelector *selector,
73
static void gimp_color_scales_togg_visible (GimpColorSelector *selector,
76
static void gimp_color_scales_set_show_alpha (GimpColorSelector *selector,
78
static void gimp_color_scales_set_color (GimpColorSelector *selector,
81
static void gimp_color_scales_set_channel (GimpColorSelector *selector,
82
GimpColorSelectorChannel channel);
84
static void gimp_color_scales_update_scales (GimpColorScales *scales,
86
static void gimp_color_scales_toggle_update (GtkWidget *widget,
87
GimpColorScales *scales);
88
static void gimp_color_scales_scale_update (GtkAdjustment *adjustment,
89
GimpColorScales *scales);
91
static void gimp_color_scales_entry_changed (GimpColorHexEntry *entry,
92
GimpColorScales *scales);
95
static GimpColorSelectorClass *parent_class = NULL;
99
gimp_color_scales_get_type (void)
101
static GType scales_type = 0;
105
static const GTypeInfo scales_info =
107
sizeof (GimpColorScalesClass),
108
(GBaseInitFunc) NULL,
109
(GBaseFinalizeFunc) NULL,
110
(GClassInitFunc) gimp_color_scales_class_init,
111
NULL, /* class_finalize */
112
NULL, /* class_data */
113
sizeof (GimpColorScales),
115
(GInstanceInitFunc) gimp_color_scales_init,
118
scales_type = g_type_register_static (GIMP_TYPE_COLOR_SELECTOR,
127
gimp_color_scales_class_init (GimpColorScalesClass *klass)
129
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
131
parent_class = g_type_class_peek_parent (klass);
133
selector_class->name = _("Scales");
134
selector_class->help_id = "gimp-colorselector-scales";
135
selector_class->stock_id = GIMP_STOCK_TOOL_OPTIONS;
136
selector_class->set_toggles_visible = gimp_color_scales_togg_visible;
137
selector_class->set_toggles_sensitive = gimp_color_scales_togg_sensitive;
138
selector_class->set_show_alpha = gimp_color_scales_set_show_alpha;
139
selector_class->set_color = gimp_color_scales_set_color;
140
selector_class->set_channel = gimp_color_scales_set_channel;
144
gimp_color_scales_init (GimpColorScales *scales)
146
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
153
static const gchar *toggle_titles[] =
163
static const gchar *slider_tips[7] =
173
static gdouble slider_initial_vals[] = { 0, 0, 0, 0, 0, 0, 0 };
174
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
175
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
177
/* don't needs the toggles for our own operation */
178
selector->toggles_visible = FALSE;
180
table = gtk_table_new (7, 4, FALSE);
181
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
182
gtk_table_set_row_spacing (GTK_TABLE (table), 2, 3); /* hsv <-> rgb */
183
gtk_table_set_row_spacing (GTK_TABLE (table), 5, 3); /* rgb <-> alpha */
184
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
185
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 0);
186
gtk_box_pack_start (GTK_BOX (scales), table, FALSE, FALSE, 0);
187
gtk_widget_show (table);
191
for (i = 0; i < 7; i++)
195
scales->toggles[i] = NULL;
199
scales->toggles[i] = gtk_radio_button_new (group);
200
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (scales->toggles[i]));
201
gtk_table_attach (GTK_TABLE (table), scales->toggles[i],
203
GTK_SHRINK, GTK_EXPAND, 0, 0);
205
if (selector->toggles_visible)
206
gtk_widget_show (scales->toggles[i]);
208
gimp_help_set_help_data (scales->toggles[i],
209
gettext (slider_tips[i]), NULL);
211
g_signal_connect (scales->toggles[i], "toggled",
212
G_CALLBACK (gimp_color_scales_toggle_update),
216
scales->slider_data[i] =
217
gimp_color_scale_entry_new (GTK_TABLE (table), 1, i,
218
gettext (toggle_titles[i]),
220
slider_initial_vals[i],
221
0.0, slider_max_vals[i],
224
gettext (slider_tips[i]),
227
scales->sliders[i] = GIMP_SCALE_ENTRY_SCALE (scales->slider_data[i]);
229
gimp_color_scale_set_channel (GIMP_COLOR_SCALE (scales->sliders[i]), i);
231
g_signal_connect (scales->slider_data[i], "value_changed",
232
G_CALLBACK (gimp_color_scales_scale_update),
236
/* The hex triplet entry */
237
hbox = gtk_hbox_new (FALSE, 6);
238
gtk_box_pack_end (GTK_BOX (scales), hbox, FALSE, FALSE, 0);
239
gtk_widget_show (hbox);
241
scales->hex_entry = gimp_color_hex_entry_new ();
242
gimp_help_set_help_data (scales->hex_entry,
243
_("Hexadecimal color notation "
244
"as used in HTML and CSS"), NULL);
245
gtk_box_pack_end (GTK_BOX (hbox), scales->hex_entry, TRUE, TRUE, 0);
246
gtk_widget_show (scales->hex_entry);
248
label = gtk_label_new_with_mnemonic (_("HTML _Notation:"));
249
gtk_label_set_mnemonic_widget (GTK_LABEL (label), scales->hex_entry);
250
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
251
gtk_widget_show (label);
253
g_signal_connect (scales->hex_entry, "color_changed",
254
G_CALLBACK (gimp_color_scales_entry_changed),
259
gimp_color_scales_togg_sensitive (GimpColorSelector *selector,
262
GimpColorScales *scales = GIMP_COLOR_SCALES (selector);
265
for (i = 0; i < 6; i++)
266
gtk_widget_set_sensitive (scales->toggles[i], sensitive);
270
gimp_color_scales_togg_visible (GimpColorSelector *selector,
273
GimpColorScales *scales = GIMP_COLOR_SCALES (selector);
276
for (i = 0; i < 6; i++)
279
gtk_widget_show (scales->toggles[i]);
281
gtk_widget_hide (scales->toggles[i]);
286
gimp_color_scales_set_show_alpha (GimpColorSelector *selector,
289
GimpColorScales *scales = GIMP_COLOR_SCALES (selector);
294
label = GIMP_SCALE_ENTRY_LABEL (scales->slider_data[6]);
295
scale = GIMP_SCALE_ENTRY_SCALE (scales->slider_data[6]);
296
spin = GIMP_SCALE_ENTRY_SPINBUTTON (scales->slider_data[6]);
300
gtk_widget_show (label);
301
gtk_widget_show (scale);
302
gtk_widget_show (spin);
306
gtk_widget_hide (label);
307
gtk_widget_hide (scale);
308
gtk_widget_hide (spin);
313
gimp_color_scales_set_color (GimpColorSelector *selector,
317
GimpColorScales *scales = GIMP_COLOR_SCALES (selector);
319
gimp_color_scales_update_scales (scales, -1);
323
gimp_color_scales_set_channel (GimpColorSelector *selector,
324
GimpColorSelectorChannel channel)
326
GimpColorScales *scales = GIMP_COLOR_SCALES (selector);
328
if (channel >= 0 && channel <= 7)
330
g_signal_handlers_block_by_func (scales->toggles[channel],
331
gimp_color_scales_toggle_update,
334
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scales->toggles[channel]),
337
g_signal_handlers_unblock_by_func (scales->toggles[channel],
338
gimp_color_scales_toggle_update,
344
gimp_color_scales_update_scales (GimpColorScales *scales,
347
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
351
values[GIMP_COLOR_SELECTOR_HUE] = ROUND (selector->hsv.h * 360.0);
352
values[GIMP_COLOR_SELECTOR_SATURATION] = ROUND (selector->hsv.s * 100.0);
353
values[GIMP_COLOR_SELECTOR_VALUE] = ROUND (selector->hsv.v * 100.0);
354
values[GIMP_COLOR_SELECTOR_RED] = ROUND (selector->rgb.r * 255.0);
355
values[GIMP_COLOR_SELECTOR_GREEN] = ROUND (selector->rgb.g * 255.0);
356
values[GIMP_COLOR_SELECTOR_BLUE] = ROUND (selector->rgb.b * 255.0);
357
values[GIMP_COLOR_SELECTOR_ALPHA] = ROUND (selector->rgb.a * 100.0);
359
for (i = 0; i < 7; i++)
363
g_signal_handlers_block_by_func (scales->slider_data[i],
364
gimp_color_scales_scale_update,
367
gtk_adjustment_set_value (GTK_ADJUSTMENT (scales->slider_data[i]),
370
g_signal_handlers_unblock_by_func (scales->slider_data[i],
371
gimp_color_scales_scale_update,
375
gimp_color_scale_set_color (GIMP_COLOR_SCALE (scales->sliders[i]),
376
&selector->rgb, &selector->hsv);
379
g_signal_handlers_block_by_func (scales->hex_entry,
380
gimp_color_scales_entry_changed,
383
gimp_color_hex_entry_set_color (GIMP_COLOR_HEX_ENTRY (scales->hex_entry),
386
g_signal_handlers_unblock_by_func (scales->hex_entry,
387
gimp_color_scales_entry_changed,
392
gimp_color_scales_toggle_update (GtkWidget *widget,
393
GimpColorScales *scales)
395
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
397
if (GTK_TOGGLE_BUTTON (widget)->active)
401
for (i = 0; i < 6; i++)
402
if (widget == scales->toggles[i])
404
selector->channel = (GimpColorSelectorChannel) i;
408
gimp_color_selector_channel_changed (selector);
413
gimp_color_scales_scale_update (GtkAdjustment *adjustment,
414
GimpColorScales *scales)
416
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
419
for (i = 0; i < 7; i++)
420
if (scales->slider_data[i] == GTK_OBJECT (adjustment))
425
case GIMP_COLOR_SELECTOR_HUE:
426
selector->hsv.h = GTK_ADJUSTMENT (adjustment)->value / 360.0;
429
case GIMP_COLOR_SELECTOR_SATURATION:
430
selector->hsv.s = GTK_ADJUSTMENT (adjustment)->value / 100.0;
433
case GIMP_COLOR_SELECTOR_VALUE:
434
selector->hsv.v = GTK_ADJUSTMENT (adjustment)->value / 100.0;
437
case GIMP_COLOR_SELECTOR_RED:
438
selector->rgb.r = GTK_ADJUSTMENT (adjustment)->value / 255.0;
441
case GIMP_COLOR_SELECTOR_GREEN:
442
selector->rgb.g = GTK_ADJUSTMENT (adjustment)->value / 255.0;
445
case GIMP_COLOR_SELECTOR_BLUE:
446
selector->rgb.b = GTK_ADJUSTMENT (adjustment)->value / 255.0;
449
case GIMP_COLOR_SELECTOR_ALPHA:
450
selector->hsv.a = selector->rgb.a =
451
GTK_ADJUSTMENT (adjustment)->value / 100.0;
455
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
457
gimp_hsv_to_rgb (&selector->hsv, &selector->rgb);
459
else if ((i >= GIMP_COLOR_SELECTOR_RED) && (i <= GIMP_COLOR_SELECTOR_BLUE))
461
gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
464
gimp_color_scales_update_scales (scales, i);
466
gimp_color_selector_color_changed (selector);
470
gimp_color_scales_entry_changed (GimpColorHexEntry *entry,
471
GimpColorScales *scales)
473
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
475
gimp_color_hex_entry_get_color (entry, &selector->rgb);
477
gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
478
gimp_color_scales_update_scales (scales, -1);
480
gimp_color_selector_color_changed (selector);