1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 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 275 276 277 278 279 280
|
/* GIMP CMYK ColorSelector
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmodule/gimpmodule.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimp/libgimp-intl.h"
/* definitions and variables */
#define COLORSEL_TYPE_CMYK (colorsel_cmyk_type)
#define COLORSEL_CMYK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLORSEL_TYPE_CMYK, ColorselCmyk))
#define COLORSEL_CMYK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COLORSEL_TYPE_CMYK, ColorselCmykClass))
#define COLORSEL_IS_CMYK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLORSEL_TYPE_CMYK))
#define COLORSEL_IS_CMYK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COLORSEL_TYPE_CMYK))
typedef struct _ColorselCmyk ColorselCmyk;
typedef struct _ColorselCmykClass ColorselCmykClass;
struct _ColorselCmyk
{
GimpColorSelector parent_instance;
GimpCMYK cmyk;
gdouble pullout;
GtkAdjustment *adj[5];
};
struct _ColorselCmykClass
{
GimpColorSelectorClass parent_class;
};
static GType colorsel_cmyk_get_type (GTypeModule *module);
static void colorsel_cmyk_class_init (ColorselCmykClass *klass);
static void colorsel_cmyk_init (ColorselCmyk *cmyk);
static void colorsel_cmyk_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
static void colorsel_cmyk_adj_update (GtkAdjustment *adj,
ColorselCmyk *module);
static void colorsel_cmyk_pullout_update (GtkAdjustment *adj,
ColorselCmyk *module);
static const GimpModuleInfo colorsel_cmyk_info =
{
GIMP_MODULE_ABI_VERSION,
N_("CMYK color selector"),
"Sven Neumann <sven@gimp.org>",
"v0.2",
"(c) 2003, released under the GPL",
"July 2003"
};
static GType colorsel_cmyk_type = 0;
G_MODULE_EXPORT const GimpModuleInfo *
gimp_module_query (GTypeModule *module)
{
return &colorsel_cmyk_info;
}
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module)
{
colorsel_cmyk_get_type (module);
return TRUE;
}
static GType
colorsel_cmyk_get_type (GTypeModule *module)
{
if (! colorsel_cmyk_type)
{
static const GTypeInfo select_info =
{
sizeof (ColorselCmykClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) colorsel_cmyk_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (ColorselCmyk),
0, /* n_preallocs */
(GInstanceInitFunc) colorsel_cmyk_init,
};
colorsel_cmyk_type =
g_type_module_register_type (module,
GIMP_TYPE_COLOR_SELECTOR,
"ColorselCmyk",
&select_info, 0);
}
return colorsel_cmyk_type;
}
static void
colorsel_cmyk_class_init (ColorselCmykClass *klass)
{
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
selector_class->name = _("CMYK");
selector_class->help_id = "gimp-colorselector-cmyk";
selector_class->stock_id = GTK_STOCK_PRINT; /* FIXME */
selector_class->set_color = colorsel_cmyk_set_color;
}
static void
colorsel_cmyk_init (ColorselCmyk *module)
{
GtkWidget *table;
GtkWidget *label;
GtkWidget *spinbutton;
GtkObject *adj;
gint i;
static const gchar *cmyk_labels[] =
{
N_("_C"),
N_("_M"),
N_("_Y"),
N_("_K")
};
static const gchar *cmyk_tips[] =
{
N_("Cyan"),
N_("Magenta"),
N_("Yellow"),
N_("Black")
};
module->pullout = 1.0;
table = gtk_table_new (5, 4, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 0);
gtk_table_set_row_spacing (GTK_TABLE (table), 3, 4);
gtk_box_pack_start (GTK_BOX (module), table, TRUE, TRUE, 0);
for (i = 0; i < 4; i++)
{
adj = gimp_scale_entry_new (GTK_TABLE (table), 1, i,
gettext (cmyk_labels[i]),
-1, -1,
0.0,
0.0, 100.0,
1.0, 10.0,
0,
TRUE, 0.0, 0.0,
gettext (cmyk_tips[i]),
NULL);
g_signal_connect (adj, "value_changed",
G_CALLBACK (colorsel_cmyk_adj_update),
module);
module->adj[i] = GTK_ADJUSTMENT (adj);
}
label = gtk_label_new_with_mnemonic (_("Black _Pullout:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
1, 3, i, i + 1,
GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (label);
spinbutton = gimp_spin_button_new (&adj, module->pullout * 100.0,
0.0, 100.0, 1.0, 10.0, 0.0,
1.0, 0);
gtk_table_attach (GTK_TABLE (table), spinbutton,
3, 4, i, i + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (spinbutton);
gimp_help_set_help_data (spinbutton,
_("The percentage of black to pull out "
"of the colored inks."), NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
g_signal_connect (adj, "value_changed",
G_CALLBACK (colorsel_cmyk_pullout_update),
module);
module->adj[i] = GTK_ADJUSTMENT (adj);
gtk_widget_show (table);
}
static void
colorsel_cmyk_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
ColorselCmyk *module = COLORSEL_CMYK (selector);
gimp_rgb_to_cmyk (rgb, module->pullout, &module->cmyk);
gtk_adjustment_set_value (module->adj[0], module->cmyk.c * 100.0);
gtk_adjustment_set_value (module->adj[1], module->cmyk.m * 100.0);
gtk_adjustment_set_value (module->adj[2], module->cmyk.y * 100.0);
gtk_adjustment_set_value (module->adj[3], module->cmyk.k * 100.0);
}
static void
colorsel_cmyk_adj_update (GtkAdjustment *adj,
ColorselCmyk *module)
{
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
gint i;
for (i = 0; i < 4; i++)
if (module->adj[i] == adj)
break;
switch (i)
{
case 0:
module->cmyk.c = adj->value / 100.0;
break;
case 1:
module->cmyk.m = adj->value / 100.0;
break;
case 2:
module->cmyk.y = adj->value / 100.0;
break;
case 3:
module->cmyk.k = adj->value / 100.0;
break;
default:
return;
}
gimp_cmyk_to_rgb (&module->cmyk, &selector->rgb);
gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
gimp_color_selector_color_changed (selector);
}
static void
colorsel_cmyk_pullout_update (GtkAdjustment *adj,
ColorselCmyk *module)
{
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
module->pullout = adj->value / 100.0;
gimp_color_selector_set_color (selector, &selector->rgb, &selector->hsv);
}
|