app/color_notebook.[ch] moved the scales and the toggle butttons out of

2001-01-09  Michael Natterer  <mitch@gimp.org>

	* app/color_notebook.[ch]
	* app/color_select.c: moved the scales and the toggle butttons out
	of the notebook. Added an "Aplha" scale (the opacity is not yet
	shown in the color area). Removed the ColorNotebook structure from
	the header.

	* app/color_area.c: the ColorNotebook struct is no longer public.

	* libgimp/gimpcolorselector.h
	* modules/colorsel_gtk.c
	* modules/colorsel_triangle.c
	* modules/colorsel_water.c: changed the ColorSelector module
	interface again: Pass H, S, V, R, G, B and A in all functions
	and callbacks. Added a "set_channel" method because the channel
	toggles are outside the notebook now. This needs more work...
This commit is contained in:
Michael Natterer 2001-01-09 01:23:54 +00:00 committed by Michael Natterer
parent bd96765ded
commit 37fe1a885d
19 changed files with 2276 additions and 1496 deletions

View File

@ -1,3 +1,21 @@
2001-01-09 Michael Natterer <mitch@gimp.org>
* app/color_notebook.[ch]
* app/color_select.c: moved the scales and the toggle butttons out
of the notebook. Added an "Aplha" scale (the opacity is not yet
shown in the color area). Removed the ColorNotebook structure from
the header.
* app/color_area.c: the ColorNotebook struct is no longer public.
* libgimp/gimpcolorselector.h
* modules/colorsel_gtk.c
* modules/colorsel_triangle.c
* modules/colorsel_water.c: changed the ColorSelector module
interface again: Pass H, S, V, R, G, B and A in all functions
and callbacks. Added a "set_channel" method because the channel
toggles are outside the notebook now. This needs more work...
2001-01-08 Michael Natterer <mitch@gimp.org>
* app/color_notebook.[ch]

View File

@ -313,7 +313,7 @@ static void
color_area_edit (void)
{
GimpContext *user_context;
guchar r, g, b;
guchar r, g, b;
user_context = gimp_context_get_user ();
@ -346,8 +346,10 @@ color_area_edit (void)
color_notebook_show (color_notebook);
color_notebook_active = TRUE;
}
else
gdk_window_raise (color_notebook->shell->window);
else
{
color_notebook_show (color_notebook);
}
color_notebook_set_color (color_notebook, r, g, b, 255);
}

View File

@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define __COLOR_NOTEBOOK_C__ 1
#include "config.h"
@ -27,6 +28,7 @@
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "apptypes.h"
@ -38,6 +40,7 @@
#include "libgimp/gimphelpui.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpintl.h"
@ -46,23 +49,44 @@
#define COLOR_AREA_HEIGHT 20
enum
{
RED,
GREEN,
BLUE,
ALPHA
};
typedef enum
{
UPDATE_NOTEBOOK = 1 << 0,
UPDATE_NEW_COLOR = 1 << 1,
UPDATE_ORIG_COLOR = 1 << 2,
UPDATE_CALLER = 1 << 3
UPDATE_CHANNEL = 1 << 1,
UPDATE_NEW_COLOR = 1 << 2,
UPDATE_ORIG_COLOR = 1 << 3,
UPDATE_CALLER = 1 << 4
} ColorNotebookUpdateType;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GtkWidget *toggles[7];
GtkObject *slider_data[7];
GtkWidget *hex_entry;
GdkGC *gc;
gint values[7];
gint orig_values[4];
GimpColorSelectorChannelType active_channel;
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
/* information we keep on each registered colour selector */
typedef struct _ColorSelectorInfo ColorSelectorInfo;
@ -95,6 +119,9 @@ static void color_notebook_ok_callback (GtkWidget *widget,
static void color_notebook_cancel_callback (GtkWidget *widget,
gpointer data);
static void color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -110,14 +137,27 @@ static void color_notebook_selector_death (ColorSelectorInfo *info);
static void color_notebook_update (ColorNotebook *cnp,
ColorNotebookUpdateType update);
static void color_notebook_update_notebook (ColorNotebook *cnp);
static void color_notebook_update_channel (ColorNotebook *cnp);
static void color_notebook_update_caller (ColorNotebook *cnp);
static void color_notebook_update_colors (ColorNotebook *cnp,
ColorNotebookUpdateType which);
static void color_notebook_update_rgb_values (ColorNotebook *cnp);
static void color_notebook_update_hsv_values (ColorNotebook *cnp);
static void color_notebook_update_scales (ColorNotebook *cnp,
gint skip);
static gboolean color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_toggle_update (GtkWidget *widget,
gpointer data);
static void color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data);
static gint color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
guchar *g,
@ -162,12 +202,39 @@ color_notebook_new (gint red,
{
ColorNotebook *cnp;
GtkWidget *main_hbox;
/*GtkWidget *right_vbox;*/
GtkWidget *right_vbox;
GtkWidget *colors_frame;
GtkWidget *colors_hbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *label;
GSList *group;
gchar buffer[16];
ColorSelectorInfo *info;
ColorSelectorInstance *csel;
gint i;
static gchar *toggle_titles[] =
{
N_("H"),
N_("S"),
N_("V"),
N_("R"),
N_("G"),
N_("B"),
N_("A")
};
static gchar *slider_tips[7] =
{
N_("Hue"),
N_("Saturation"),
N_("Value"),
N_("Red"),
N_("Green"),
N_("Blue"),
N_("Alpha")
};
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 255 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 16 };
g_return_val_if_fail (selector_info != NULL, NULL);
@ -181,10 +248,12 @@ color_notebook_new (gint red,
cnp->selectors = NULL;
cnp->cur_page = NULL;
cnp->values[RED] = cnp->orig_values[RED] = red & 0xff;
cnp->values[GREEN] = cnp->orig_values[GREEN] = green & 0xff;
cnp->values[BLUE] = cnp->orig_values[BLUE] = blue & 0xff;
cnp->values[ALPHA] = cnp->orig_values[ALPHA] = alpha & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha & 0xff;
color_notebook_update_hsv_values (cnp);
cnp->shell =
gimp_dialog_new (_("Color Selection"), "color_selection",
@ -202,7 +271,7 @@ color_notebook_new (gint red,
NULL);
main_hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 1);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (cnp->shell)->vbox), main_hbox);
gtk_widget_show (main_hbox);
@ -229,10 +298,17 @@ color_notebook_new (gint red,
csel->color_notebook = cnp;
csel->info = info;
info->refs++;
csel->frame = info->methods.new (red, green, blue, alpha,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
csel->frame =
info->methods.new (cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
gtk_object_set_data (GTK_OBJECT (csel->frame), "gimp_color_notebook",
csel);
@ -266,27 +342,19 @@ color_notebook_new (gint red,
}
/* The right vertical box with old/new color area and color space sliders */
/*
right_vbox = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
*/
/* The old/new color area frame and hbox */
colors_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (colors_frame), GTK_SHADOW_IN);
/* gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0); */
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (cnp->shell)->action_area),
colors_frame,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0);
gtk_widget_show (colors_frame);
colors_hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), colors_hbox);
gtk_widget_show (colors_hbox);
hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), hbox);
gtk_widget_show (hbox);
/* The new color area */
cnp->new_color = gtk_drawing_area_new ();
@ -298,7 +366,7 @@ color_notebook_new (gint red,
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->new_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->new_color);
/* dnd stuff */
@ -325,7 +393,7 @@ color_notebook_new (gint red,
GTK_SIGNAL_FUNC (color_notebook_color_events),
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->orig_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->orig_color);
/* dnd stuff */
@ -336,6 +404,63 @@ color_notebook_new (gint red,
gimp_dnd_color_source_set (cnp->orig_color, color_notebook_drag_old_color,
cnp);
/* The color space sliders, toggle buttons and entries */
table = gtk_table_new (7, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (right_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
group = NULL;
for (i = 0; i < 7; i++)
{
cnp->toggles[i] =
gtk_radio_button_new_with_label (group, gettext (toggle_titles[i]));
gimp_help_set_help_data (cnp->toggles[i], gettext (slider_tips[i]), NULL);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (cnp->toggles[i]));
gtk_table_attach (GTK_TABLE (table), cnp->toggles[i],
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (cnp->toggles[i]), "toggled",
GTK_SIGNAL_FUNC (color_notebook_toggle_update),
cnp);
gtk_widget_show (cnp->toggles[i]);
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
gettext (slider_tips[i]),
NULL);
gtk_signal_connect (GTK_OBJECT (cnp->slider_data[i]), "value_changed",
GTK_SIGNAL_FUNC (color_notebook_scale_update),
cnp);
}
/* The hex triplet entry */
hbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (right_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
gtk_widget_set_usize (GTK_WIDGET (cnp->hex_entry), 75, 0);
gtk_box_pack_end (GTK_BOX (hbox), cnp->hex_entry, FALSE, FALSE, 2);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "focus_out_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "key_press_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_widget_show (cnp->hex_entry);
label = gtk_label_new (_("Hex Triplet:"));
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -356,7 +481,11 @@ void
color_notebook_show (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
gtk_widget_show (cnp->shell);
if (! GTK_WIDGET_VISIBLE (cnp->shell))
gtk_widget_show (cnp->shell);
else
gdk_window_raise (cnp->shell->window);
}
void
@ -403,15 +532,10 @@ color_notebook_set_color (ColorNotebook *cnp,
{
g_return_if_fail (cnp != NULL);
cnp->orig_values[RED] = red;
cnp->orig_values[GREEN] = green;
cnp->orig_values[BLUE] = blue;
cnp->orig_values[ALPHA] = alpha;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha;
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -424,6 +548,9 @@ color_notebook_set_color (ColorNotebook *cnp,
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -437,12 +564,19 @@ color_notebook_update_callback (gpointer data,
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_HUE] = hue;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = saturation;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = value;
cnp->values[GIMP_COLOR_SELECTOR_RED] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = alpha;
color_notebook_update (cnp, UPDATE_NEW_COLOR | UPDATE_CALLER);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static void
@ -455,10 +589,10 @@ color_notebook_ok_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -474,10 +608,10 @@ color_notebook_cancel_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->orig_values[RED],
cnp->orig_values[GREEN],
cnp->orig_values[BLUE],
cnp->orig_values[ALPHA],
(* cnp->callback) (cnp->orig_values[0],
cnp->orig_values[1],
cnp->orig_values[2],
cnp->orig_values[3],
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -500,7 +634,7 @@ color_notebook_page_switch (GtkWidget *widget,
cnp->cur_page = csel;
color_notebook_update (cnp, UPDATE_NOTEBOOK);
color_notebook_update (cnp, UPDATE_CHANNEL | UPDATE_NOTEBOOK);
}
static void
@ -622,6 +756,9 @@ color_notebook_update (ColorNotebook *cnp,
if (update & UPDATE_NOTEBOOK)
color_notebook_update_notebook (cnp);
if (update & UPDATE_CHANNEL)
color_notebook_update_channel (cnp);
if (update & UPDATE_NEW_COLOR)
color_notebook_update_colors (cnp, UPDATE_NEW_COLOR);
@ -640,11 +777,26 @@ color_notebook_update_notebook (ColorNotebook *cnp)
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.setcolor (csel->selector_data,
cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA]);
csel->info->methods.set_color (csel->selector_data,
cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
}
static void
color_notebook_update_channel (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.set_channel (csel->selector_data,
cnp->active_channel);
}
static void
@ -652,10 +804,10 @@ color_notebook_update_caller (ColorNotebook *cnp)
{
if (cnp && cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -683,9 +835,9 @@ color_notebook_update_colors (ColorNotebook *cnp,
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[RED];
green = cnp->values[GREEN];
blue = cnp->values[BLUE];
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
}
else
{
@ -710,6 +862,72 @@ color_notebook_update_colors (ColorNotebook *cnp,
}
}
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
return;
h = cnp->values[GIMP_COLOR_SELECTOR_HUE] / 360.0;
s = cnp->values[GIMP_COLOR_SELECTOR_SATURATION] / 100.0;
v = cnp->values[GIMP_COLOR_SELECTOR_VALUE] / 100.0;
gimp_hsv_to_rgb_double (&h, &s, &v);
cnp->values[GIMP_COLOR_SELECTOR_RED] = h * 255;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = s * 255;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = v * 255;
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
return;
r = cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0;
g = cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0;
b = cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0;
gimp_rgb_to_hsv_double (&r, &g, &b);
cnp->values[GIMP_COLOR_SELECTOR_HUE] = r * 360.0;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = g * 100.0;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = b * 100.0;
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gchar buffer[16];
gint i;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (cnp->slider_data[i]),
cnp->values[i]);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
}
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
static gboolean
color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
@ -741,6 +959,129 @@ color_notebook_color_events (GtkWidget *widget,
return FALSE;
}
static void
color_notebook_toggle_update (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
gint i;
if (! GTK_TOGGLE_BUTTON (widget)->active)
return;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (widget == cnp->toggles[i])
cnp->active_channel = (GimpColorSelectorChannelType) i;
color_notebook_update (cnp, UPDATE_CHANNEL);
}
static void
color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data)
{
ColorNotebook *cnp;
gint old_values[7];
gint i, j;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
for (j = 0; j < 7; j++)
old_values[j] = cnp->values[j];
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
color_notebook_update_rgb_values (cnp);
}
else if ((i >= GIMP_COLOR_SELECTOR_RED) && (i <= GIMP_COLOR_SELECTOR_BLUE))
{
color_notebook_update_hsv_values (cnp);
}
color_notebook_update_scales (cnp, i);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static gint
color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
ColorNotebook *cnp;
gchar buffer[8];
gchar *hex_color;
guint hex_rgb;
cnp = (ColorNotebook *) data;
if (!cnp)
return FALSE;
switch (event->type)
{
case GDK_KEY_PRESS:
if (((GdkEventKey *) event)->keyval != GDK_Return)
break;
/* else fall through */
case GDK_FOCUS_CHANGE:
hex_color = g_strdup (gtk_entry_get_text (GTK_ENTRY (cnp->hex_entry)));
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
{
if ((sscanf (hex_color, "#%x", &hex_rgb) == 1) &&
(hex_rgb < (1 << 24)))
{
cnp->values[GIMP_COLOR_SELECTOR_RED] = (hex_rgb & 0xff0000) >> 16;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (hex_rgb & 0x00ff00) >> 8;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (hex_rgb & 0x0000ff);
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
}
g_free (hex_color);
break;
default:
/* do nothing */
break;
}
return FALSE;
}
static void
color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
@ -753,10 +1094,10 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
*r = (guchar) cnp->values[RED];
*g = (guchar) cnp->values[GREEN];
*b = (guchar) cnp->values[BLUE];
*a = (guchar) cnp->values[ALPHA];
*r = (guchar) cnp->values[GIMP_COLOR_SELECTOR_RED];
*g = (guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN];
*b = (guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE];
*a = (guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA];
}
static void
@ -771,10 +1112,13 @@ color_notebook_drop_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
cnp->values[RED] = (gint) r;
cnp->values[GREEN] = (gint) g;
cnp->values[BLUE] = (gint) b;
cnp->values[ALPHA] = (gint) a;
cnp->values[GIMP_COLOR_SELECTOR_RED] = (gint) r;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (gint) g;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (gint) b;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) a;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |

View File

@ -36,28 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GdkGC *gc;
gint values[4];
gint orig_values[4];
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
ColorNotebook * color_notebook_new (gint red,
gint green,
gint blue,

View File

@ -42,10 +42,10 @@
#include "libgimp/gimpintl.h"
#define XY_DEF_WIDTH 240
#define XY_DEF_HEIGHT 240
#define XY_DEF_WIDTH 200
#define XY_DEF_HEIGHT 200
#define Z_DEF_WIDTH 15
#define Z_DEF_HEIGHT 240
#define Z_DEF_HEIGHT 200
#define COLOR_AREA_WIDTH 74
#define COLOR_AREA_HEIGHT 20
@ -82,7 +82,10 @@ typedef enum
UPDATE_CALLER = 1 << 6
} ColorSelectUpdateType;
typedef void (* ColorSelectCallback) (gint r,
typedef void (* ColorSelectCallback) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -94,15 +97,11 @@ struct _ColorSelect
{
GtkWidget *xy_color;
GtkWidget *z_color;
GtkWidget *toggles[6];
GtkObject *slider_data[6];
GtkWidget *hex_entry;
gint pos[3];
gint values[7];
gint z_color_fill;
gint xy_color_fill;
gboolean wants_updates;
GdkGC *gc;
ColorSelectCallback callback;
@ -144,28 +143,19 @@ static void color_select_update_values (ColorSelect *);
static void color_select_update_rgb_values (ColorSelect *);
static void color_select_update_hsv_values (ColorSelect *);
static void color_select_update_pos (ColorSelect *);
static void color_select_update_scales (ColorSelect *,
gint );
static gint color_select_xy_expose (GtkWidget *,
GdkEventExpose *,
ColorSelect *);
static gint color_select_xy_events (GtkWidget *,
GdkEvent *,
ColorSelect *);
static gint color_select_z_expose (GtkWidget *,
GdkEventExpose *,
ColorSelect *);
static gint color_select_z_events (GtkWidget *,
GdkEvent *,
ColorSelect *);
static void color_select_scale_update (GtkObject *,
gpointer );
static void color_select_toggle_update (GtkWidget *,
gpointer );
static gint color_select_hex_entry_events (GtkWidget *,
GdkEvent *,
gpointer );
static gint color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *eevent,
ColorSelect *color_select);
static gint color_select_xy_events (GtkWidget *widget,
GdkEvent *event,
ColorSelect *color_select);
static gint color_select_z_expose (GtkWidget *widget,
GdkEventExpose *eevent,
ColorSelect *color_select);
static gint color_select_z_events (GtkWidget *widet,
GdkEvent *event,
ColorSelect *color_select);
static void color_select_image_fill (GtkWidget *,
ColorSelectFillType,
@ -190,6 +180,9 @@ static void color_select_update_hue_value (ColorSelectFill *);
static void color_select_update_saturation_value (ColorSelectFill *);
static GtkWidget * color_select_notebook_new (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
@ -198,12 +191,20 @@ static GtkWidget * color_select_notebook_new (gint ,
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_setcolor (gpointer ,
static void color_select_notebook_set_color (gpointer ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint );
static void color_select_notebook_set_channel (gpointer ,
GimpColorSelectorChannelType channel);
static void color_select_notebook_update_callback (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
@ -244,7 +245,8 @@ color_select_init (void)
{
color_select_notebook_new,
color_select_notebook_free,
color_select_notebook_setcolor
color_select_notebook_set_color,
color_select_notebook_set_channel
};
gimp_color_selector_register ("GIMP", "built_in.html", &methods);
@ -260,49 +262,25 @@ color_select_widget_new (ColorSelect *csp,
{
GtkWidget *main_vbox;
GtkWidget *main_hbox;
GtkWidget *hbox;
GtkWidget *xy_frame;
GtkWidget *z_frame;
GtkWidget *right_vbox;
GtkWidget *table;
GtkWidget *hex_hbox;
GtkWidget *label;
GSList *group;
gchar buffer[16];
gint i;
static gchar *toggle_titles[6] =
{
N_("H"),
N_("S"),
N_("V"),
N_("R"),
N_("G"),
N_("B")
};
static gchar *slider_tips[6] =
{
N_("Hue"),
N_("Saturation"),
N_("Value"),
N_("Red"),
N_("Green"),
N_("Blue")
};
static gdouble slider_max_vals[6] = { 360, 100, 100, 255, 255, 255 };
static gdouble slider_incs[6] = { 30, 10, 10, 16, 16, 16 };
main_vbox = gtk_vbox_new (FALSE, 2);
main_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 2);
main_hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 0);
gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, TRUE, 2);
main_hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, FALSE, 0);
gtk_widget_show (main_hbox);
hbox = gtk_hbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (main_hbox), hbox, TRUE, FALSE, 0);
gtk_widget_show (hbox);
/* The x/y component preview */
xy_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (xy_frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (main_hbox), xy_frame, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), xy_frame, FALSE, FALSE, 2);
gtk_widget_show (xy_frame);
csp->xy_color = gtk_preview_new (GTK_PREVIEW_COLOR);
@ -330,7 +308,7 @@ color_select_widget_new (ColorSelect *csp,
/* The z component preview */
z_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (z_frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (main_hbox), z_frame, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), z_frame, FALSE, FALSE, 2);
gtk_widget_show (z_frame);
csp->z_color = gtk_preview_new (GTK_PREVIEW_COLOR);
@ -346,70 +324,6 @@ color_select_widget_new (ColorSelect *csp,
gtk_container_add (GTK_CONTAINER (z_frame), csp->z_color);
gtk_widget_show (csp->z_color);
/* The right vertical box with old/new color area and color space sliders */
right_vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (right_vbox), 0);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
/* The color space sliders, toggle buttons and entries */
table = gtk_table_new (6, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_box_pack_start (GTK_BOX (right_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
group = NULL;
for (i = 0; i < 6; i++)
{
csp->toggles[i] =
gtk_radio_button_new_with_label (group, gettext (toggle_titles[i]));
gimp_help_set_help_data (csp->toggles[i], gettext (slider_tips[i]), NULL);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (csp->toggles[i]));
gtk_table_attach (GTK_TABLE (table), csp->toggles[i],
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (csp->toggles[i]), "toggled",
GTK_SIGNAL_FUNC (color_select_toggle_update),
csp);
gtk_widget_show (csp->toggles[i]);
csp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
csp->values[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
gettext (slider_tips[i]),
NULL);
gtk_signal_connect (GTK_OBJECT (csp->slider_data[i]), "value_changed",
GTK_SIGNAL_FUNC (color_select_scale_update),
csp);
}
/* The hex triplet entry */
hex_hbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (right_vbox), hex_hbox, FALSE, FALSE, 0);
gtk_widget_show (hex_hbox);
csp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", r, g, b);
gtk_entry_set_text (GTK_ENTRY (csp->hex_entry), buffer);
gtk_widget_set_usize (GTK_WIDGET (csp->hex_entry), 75, 0);
gtk_box_pack_end (GTK_BOX (hex_hbox), csp->hex_entry, FALSE, FALSE, 2);
gtk_signal_connect (GTK_OBJECT (csp->hex_entry), "focus_out_event",
GTK_SIGNAL_FUNC (color_select_hex_entry_events),
csp);
gtk_signal_connect (GTK_OBJECT (csp->hex_entry), "key_press_event",
GTK_SIGNAL_FUNC (color_select_hex_entry_events),
csp);
gtk_widget_show (csp->hex_entry);
label = gtk_label_new (_("Hex Triplet:"));
gtk_box_pack_end (GTK_BOX (hex_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
return main_vbox;
}
@ -432,14 +346,18 @@ color_select_drop_color (GtkWidget *widget,
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
color_select_update_scales (csp, -1);
color_select_update (csp, UPDATE_Z_COLOR);
color_select_update (csp, UPDATE_XY_COLOR);
color_select_update (csp, UPDATE_CALLER);
}
static void
color_select_set_color (ColorSelect *csp,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
@ -448,14 +366,15 @@ color_select_set_color (ColorSelect *csp,
if (!csp)
return;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s;
csp->values[COLOR_SELECT_VALUE] = v;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
color_select_update_scales (csp, -1);
color_select_update (csp, UPDATE_Z_COLOR);
color_select_update (csp, UPDATE_XY_COLOR);
@ -474,7 +393,6 @@ color_select_update (ColorSelect *csp,
if (update & UPDATE_VALUES)
{
color_select_update_values (csp);
color_select_update_scales (csp, -1);
}
if (update & UPDATE_XY_COLOR)
@ -489,16 +407,19 @@ color_select_update (ColorSelect *csp,
gtk_widget_draw (csp->z_color, NULL);
}
/*if (update & UPDATE_CALLER)*/
color_select_update_caller (csp);
if (update & UPDATE_CALLER)
color_select_update_caller (csp);
}
static void
color_select_update_caller (ColorSelect *csp)
{
if (csp && csp->wants_updates && csp->callback)
if (csp && csp->callback)
{
(* csp->callback) (csp->values[COLOR_SELECT_RED],
(* csp->callback) (csp->values[COLOR_SELECT_HUE],
csp->values[COLOR_SELECT_SATURATION],
csp->values[COLOR_SELECT_VALUE],
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE],
csp->values[COLOR_SELECT_ALPHA],
@ -740,32 +661,6 @@ color_select_update_pos (ColorSelect *csp)
}
}
static void
color_select_update_scales (ColorSelect *csp,
gint skip)
{
gchar buffer[16];
gint i;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (csp->slider_data[i]), csp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (csp->slider_data[i]),
csp->values[i]);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (csp->slider_data[i]), csp);
}
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE]);
gtk_entry_set_text (GTK_ENTRY (csp->hex_entry), buffer);
}
static gint
color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *event,
@ -814,7 +709,7 @@ color_select_xy_events (GtkWidget *widget,
NULL, NULL, bevent->time);
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_BUTTON_RELEASE:
@ -836,7 +731,7 @@ color_select_xy_events (GtkWidget *widget,
gdk_pointer_ungrab (bevent->time);
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_MOTION_NOTIFY:
@ -863,7 +758,7 @@ color_select_xy_events (GtkWidget *widget,
csp->pos[1] = 255;
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
default:
@ -914,7 +809,7 @@ color_select_z_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_BUTTON_RELEASE:
@ -930,7 +825,7 @@ color_select_z_events (GtkWidget *widget,
gdk_pointer_ungrab (bevent->time);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES | UPDATE_XY_COLOR);
color_select_update (csp, UPDATE_VALUES | UPDATE_XY_COLOR | UPDATE_CALLER);
break;
case GDK_MOTION_NOTIFY:
@ -951,7 +846,7 @@ color_select_z_events (GtkWidget *widget,
csp->pos[2] = 255;
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
default:
@ -962,94 +857,13 @@ color_select_z_events (GtkWidget *widget,
}
static void
color_select_scale_update (GtkObject *adjustment,
gpointer data)
color_select_set_channel (ColorSelect *csp,
GimpColorSelectorChannelType type)
{
ColorSelect *csp;
gint old_values[6];
gint update_z_marker;
gint update_xy_marker;
gint i, j;
csp = (ColorSelect *) data;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (csp->slider_data[i] == adjustment)
break;
for (j = 0; j < 6; j++)
old_values[j] = csp->values[j];
csp->values[i] = (int) (GTK_ADJUSTMENT (adjustment)->value);
if ((i >= COLOR_SELECT_HUE) && (i <= COLOR_SELECT_VALUE))
color_select_update_rgb_values (csp);
else if ((i >= COLOR_SELECT_RED) && (i <= COLOR_SELECT_BLUE))
color_select_update_hsv_values (csp);
color_select_update_scales (csp, i);
update_z_marker = 0;
update_xy_marker = 0;
for (j = 0; j < 6; j++)
{
if (j == csp->z_color_fill)
{
if (old_values[j] != csp->values[j])
update_z_marker = 1;
}
else
{
if (old_values[j] != csp->values[j])
update_xy_marker = 1;
}
}
if (update_z_marker)
{
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_POS | UPDATE_XY_COLOR);
color_select_draw_z_marker (csp, NULL);
}
else
{
if (update_z_marker)
color_select_draw_z_marker (csp, NULL);
if (update_xy_marker)
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_POS);
if (update_z_marker)
color_select_draw_z_marker (csp, NULL);
if (update_xy_marker)
color_select_draw_xy_marker (csp, NULL);
}
}
static void
color_select_toggle_update (GtkWidget *widget,
gpointer data)
{
ColorSelect *csp;
ColorSelectFillType type = COLOR_SELECT_HUE;
gint i;
if (!GTK_TOGGLE_BUTTON (widget)->active)
return;
csp = (ColorSelect *) data;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (widget == csp->toggles[i])
type = (ColorSelectFillType) i;
switch (type)
switch ((ColorSelectFillType) type)
{
case COLOR_SELECT_HUE:
csp->z_color_fill = COLOR_SELECT_HUE;
@ -1083,60 +897,6 @@ color_select_toggle_update (GtkWidget *widget,
color_select_update (csp, UPDATE_Z_COLOR | UPDATE_XY_COLOR);
}
static gint
color_select_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
ColorSelect *csp;
gchar buffer[8];
gchar *hex_color;
guint hex_rgb;
csp = (ColorSelect *) data;
if (!csp)
return FALSE;
switch (event->type)
{
case GDK_KEY_PRESS:
if (((GdkEventKey *) event)->keyval != GDK_Return)
break;
/* else fall through */
case GDK_FOCUS_CHANGE:
hex_color = g_strdup (gtk_entry_get_text (GTK_ENTRY (csp->hex_entry)));
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE]);
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
{
if ((sscanf (hex_color, "#%x", &hex_rgb) == 1) &&
(hex_rgb < (1 << 24)))
color_select_set_color (csp,
(hex_rgb & 0xff0000) >> 16,
(hex_rgb & 0x00ff00) >> 8,
(hex_rgb & 0x0000ff),
255);
}
g_free (hex_color);
break;
default:
/* do nothing */
break;
}
return FALSE;
}
static void
color_select_image_fill (GtkWidget *preview,
ColorSelectFillType type,
@ -1149,8 +909,8 @@ color_select_image_fill (GtkWidget *preview,
csf.update = update_procs[type];
csf.y = -1;
csf.width = preview->requisition.width;
csf.y = -1;
csf.width = preview->requisition.width;
csf.height = preview->requisition.height;
csf.values = values;
@ -1182,7 +942,7 @@ color_select_draw_z_marker (ColorSelect *csp,
return;
y = (Z_DEF_HEIGHT - 1) - ((Z_DEF_HEIGHT - 1) * csp->pos[2]) / 255;
width = csp->z_color->requisition.width;
width = csp->z_color->requisition.width;
height = csp->z_color->requisition.height;
minx = 0;
miny = 0;
@ -1724,7 +1484,7 @@ color_select_update_saturation_value (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
s = (float) csf->y / csf->height;
s = (gfloat) csf->y / csf->height;
if (s < 0)
s = 0;
@ -1733,16 +1493,16 @@ color_select_update_saturation_value (ColorSelectFill *csf)
s = 1 - s;
h = (float) csf->values[COLOR_SELECT_HUE];
h = (gfloat) csf->values[COLOR_SELECT_HUE];
if (h >= 360)
h -= 360;
h /= 60;
f = (h - (int) h) * 255;
f = (h - (gint) h) * 255;
v = 0;
dv = 1.0 / csf->width;
switch ((int) h)
switch ((gint) h)
{
case 0:
for (i = 0; i < csf->width; i++)
@ -1820,7 +1580,10 @@ typedef struct
} notebook_glue;
static GtkWidget *
color_select_notebook_new (gint r,
color_select_notebook_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -1846,13 +1609,15 @@ color_select_notebook_new (gint r,
csp->z_color_fill = COLOR_SELECT_HUE;
csp->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
csp->gc = NULL;
csp->wants_updates = TRUE;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_hsv_values (csp);
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s;
csp->values[COLOR_SELECT_VALUE] = v;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_pos (csp);
glue->main_vbox = color_select_widget_new (csp, r, g, b, a);
@ -1882,19 +1647,34 @@ color_select_notebook_free (gpointer data)
static void
color_select_notebook_setcolor (gpointer data,
gint r,
gint g,
gint b,
gint a)
color_select_notebook_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
{
notebook_glue *glue = data;
color_select_set_color (glue->csp, r, g, b, a);
color_select_set_color (glue->csp, h, s, v, r, g, b, a);
}
static void
color_select_notebook_update_callback (gint r,
color_select_notebook_set_channel (gpointer data,
GimpColorSelectorChannelType channel)
{
notebook_glue *glue = data;
color_select_set_channel (glue->csp, channel);
}
static void
color_select_notebook_update_callback (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -1902,5 +1682,5 @@ color_select_notebook_update_callback (gint r,
{
notebook_glue *glue = data;
glue->callback (glue->client_data, r, g, b, a);
glue->callback (glue->client_data, h, s, v, r, g, b, a);
}

View File

@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define __COLOR_NOTEBOOK_C__ 1
#include "config.h"
@ -27,6 +28,7 @@
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "apptypes.h"
@ -38,6 +40,7 @@
#include "libgimp/gimphelpui.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpintl.h"
@ -46,23 +49,44 @@
#define COLOR_AREA_HEIGHT 20
enum
{
RED,
GREEN,
BLUE,
ALPHA
};
typedef enum
{
UPDATE_NOTEBOOK = 1 << 0,
UPDATE_NEW_COLOR = 1 << 1,
UPDATE_ORIG_COLOR = 1 << 2,
UPDATE_CALLER = 1 << 3
UPDATE_CHANNEL = 1 << 1,
UPDATE_NEW_COLOR = 1 << 2,
UPDATE_ORIG_COLOR = 1 << 3,
UPDATE_CALLER = 1 << 4
} ColorNotebookUpdateType;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GtkWidget *toggles[7];
GtkObject *slider_data[7];
GtkWidget *hex_entry;
GdkGC *gc;
gint values[7];
gint orig_values[4];
GimpColorSelectorChannelType active_channel;
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
/* information we keep on each registered colour selector */
typedef struct _ColorSelectorInfo ColorSelectorInfo;
@ -95,6 +119,9 @@ static void color_notebook_ok_callback (GtkWidget *widget,
static void color_notebook_cancel_callback (GtkWidget *widget,
gpointer data);
static void color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -110,14 +137,27 @@ static void color_notebook_selector_death (ColorSelectorInfo *info);
static void color_notebook_update (ColorNotebook *cnp,
ColorNotebookUpdateType update);
static void color_notebook_update_notebook (ColorNotebook *cnp);
static void color_notebook_update_channel (ColorNotebook *cnp);
static void color_notebook_update_caller (ColorNotebook *cnp);
static void color_notebook_update_colors (ColorNotebook *cnp,
ColorNotebookUpdateType which);
static void color_notebook_update_rgb_values (ColorNotebook *cnp);
static void color_notebook_update_hsv_values (ColorNotebook *cnp);
static void color_notebook_update_scales (ColorNotebook *cnp,
gint skip);
static gboolean color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_toggle_update (GtkWidget *widget,
gpointer data);
static void color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data);
static gint color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
guchar *g,
@ -162,12 +202,39 @@ color_notebook_new (gint red,
{
ColorNotebook *cnp;
GtkWidget *main_hbox;
/*GtkWidget *right_vbox;*/
GtkWidget *right_vbox;
GtkWidget *colors_frame;
GtkWidget *colors_hbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *label;
GSList *group;
gchar buffer[16];
ColorSelectorInfo *info;
ColorSelectorInstance *csel;
gint i;
static gchar *toggle_titles[] =
{
N_("H"),
N_("S"),
N_("V"),
N_("R"),
N_("G"),
N_("B"),
N_("A")
};
static gchar *slider_tips[7] =
{
N_("Hue"),
N_("Saturation"),
N_("Value"),
N_("Red"),
N_("Green"),
N_("Blue"),
N_("Alpha")
};
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 255 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 16 };
g_return_val_if_fail (selector_info != NULL, NULL);
@ -181,10 +248,12 @@ color_notebook_new (gint red,
cnp->selectors = NULL;
cnp->cur_page = NULL;
cnp->values[RED] = cnp->orig_values[RED] = red & 0xff;
cnp->values[GREEN] = cnp->orig_values[GREEN] = green & 0xff;
cnp->values[BLUE] = cnp->orig_values[BLUE] = blue & 0xff;
cnp->values[ALPHA] = cnp->orig_values[ALPHA] = alpha & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha & 0xff;
color_notebook_update_hsv_values (cnp);
cnp->shell =
gimp_dialog_new (_("Color Selection"), "color_selection",
@ -202,7 +271,7 @@ color_notebook_new (gint red,
NULL);
main_hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 1);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (cnp->shell)->vbox), main_hbox);
gtk_widget_show (main_hbox);
@ -229,10 +298,17 @@ color_notebook_new (gint red,
csel->color_notebook = cnp;
csel->info = info;
info->refs++;
csel->frame = info->methods.new (red, green, blue, alpha,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
csel->frame =
info->methods.new (cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
gtk_object_set_data (GTK_OBJECT (csel->frame), "gimp_color_notebook",
csel);
@ -266,27 +342,19 @@ color_notebook_new (gint red,
}
/* The right vertical box with old/new color area and color space sliders */
/*
right_vbox = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
*/
/* The old/new color area frame and hbox */
colors_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (colors_frame), GTK_SHADOW_IN);
/* gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0); */
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (cnp->shell)->action_area),
colors_frame,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0);
gtk_widget_show (colors_frame);
colors_hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), colors_hbox);
gtk_widget_show (colors_hbox);
hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), hbox);
gtk_widget_show (hbox);
/* The new color area */
cnp->new_color = gtk_drawing_area_new ();
@ -298,7 +366,7 @@ color_notebook_new (gint red,
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->new_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->new_color);
/* dnd stuff */
@ -325,7 +393,7 @@ color_notebook_new (gint red,
GTK_SIGNAL_FUNC (color_notebook_color_events),
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->orig_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->orig_color);
/* dnd stuff */
@ -336,6 +404,63 @@ color_notebook_new (gint red,
gimp_dnd_color_source_set (cnp->orig_color, color_notebook_drag_old_color,
cnp);
/* The color space sliders, toggle buttons and entries */
table = gtk_table_new (7, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (right_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
group = NULL;
for (i = 0; i < 7; i++)
{
cnp->toggles[i] =
gtk_radio_button_new_with_label (group, gettext (toggle_titles[i]));
gimp_help_set_help_data (cnp->toggles[i], gettext (slider_tips[i]), NULL);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (cnp->toggles[i]));
gtk_table_attach (GTK_TABLE (table), cnp->toggles[i],
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (cnp->toggles[i]), "toggled",
GTK_SIGNAL_FUNC (color_notebook_toggle_update),
cnp);
gtk_widget_show (cnp->toggles[i]);
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
gettext (slider_tips[i]),
NULL);
gtk_signal_connect (GTK_OBJECT (cnp->slider_data[i]), "value_changed",
GTK_SIGNAL_FUNC (color_notebook_scale_update),
cnp);
}
/* The hex triplet entry */
hbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (right_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
gtk_widget_set_usize (GTK_WIDGET (cnp->hex_entry), 75, 0);
gtk_box_pack_end (GTK_BOX (hbox), cnp->hex_entry, FALSE, FALSE, 2);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "focus_out_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "key_press_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_widget_show (cnp->hex_entry);
label = gtk_label_new (_("Hex Triplet:"));
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -356,7 +481,11 @@ void
color_notebook_show (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
gtk_widget_show (cnp->shell);
if (! GTK_WIDGET_VISIBLE (cnp->shell))
gtk_widget_show (cnp->shell);
else
gdk_window_raise (cnp->shell->window);
}
void
@ -403,15 +532,10 @@ color_notebook_set_color (ColorNotebook *cnp,
{
g_return_if_fail (cnp != NULL);
cnp->orig_values[RED] = red;
cnp->orig_values[GREEN] = green;
cnp->orig_values[BLUE] = blue;
cnp->orig_values[ALPHA] = alpha;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha;
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -424,6 +548,9 @@ color_notebook_set_color (ColorNotebook *cnp,
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -437,12 +564,19 @@ color_notebook_update_callback (gpointer data,
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_HUE] = hue;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = saturation;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = value;
cnp->values[GIMP_COLOR_SELECTOR_RED] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = alpha;
color_notebook_update (cnp, UPDATE_NEW_COLOR | UPDATE_CALLER);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static void
@ -455,10 +589,10 @@ color_notebook_ok_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -474,10 +608,10 @@ color_notebook_cancel_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->orig_values[RED],
cnp->orig_values[GREEN],
cnp->orig_values[BLUE],
cnp->orig_values[ALPHA],
(* cnp->callback) (cnp->orig_values[0],
cnp->orig_values[1],
cnp->orig_values[2],
cnp->orig_values[3],
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -500,7 +634,7 @@ color_notebook_page_switch (GtkWidget *widget,
cnp->cur_page = csel;
color_notebook_update (cnp, UPDATE_NOTEBOOK);
color_notebook_update (cnp, UPDATE_CHANNEL | UPDATE_NOTEBOOK);
}
static void
@ -622,6 +756,9 @@ color_notebook_update (ColorNotebook *cnp,
if (update & UPDATE_NOTEBOOK)
color_notebook_update_notebook (cnp);
if (update & UPDATE_CHANNEL)
color_notebook_update_channel (cnp);
if (update & UPDATE_NEW_COLOR)
color_notebook_update_colors (cnp, UPDATE_NEW_COLOR);
@ -640,11 +777,26 @@ color_notebook_update_notebook (ColorNotebook *cnp)
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.setcolor (csel->selector_data,
cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA]);
csel->info->methods.set_color (csel->selector_data,
cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
}
static void
color_notebook_update_channel (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.set_channel (csel->selector_data,
cnp->active_channel);
}
static void
@ -652,10 +804,10 @@ color_notebook_update_caller (ColorNotebook *cnp)
{
if (cnp && cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -683,9 +835,9 @@ color_notebook_update_colors (ColorNotebook *cnp,
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[RED];
green = cnp->values[GREEN];
blue = cnp->values[BLUE];
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
}
else
{
@ -710,6 +862,72 @@ color_notebook_update_colors (ColorNotebook *cnp,
}
}
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
return;
h = cnp->values[GIMP_COLOR_SELECTOR_HUE] / 360.0;
s = cnp->values[GIMP_COLOR_SELECTOR_SATURATION] / 100.0;
v = cnp->values[GIMP_COLOR_SELECTOR_VALUE] / 100.0;
gimp_hsv_to_rgb_double (&h, &s, &v);
cnp->values[GIMP_COLOR_SELECTOR_RED] = h * 255;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = s * 255;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = v * 255;
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
return;
r = cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0;
g = cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0;
b = cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0;
gimp_rgb_to_hsv_double (&r, &g, &b);
cnp->values[GIMP_COLOR_SELECTOR_HUE] = r * 360.0;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = g * 100.0;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = b * 100.0;
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gchar buffer[16];
gint i;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (cnp->slider_data[i]),
cnp->values[i]);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
}
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
static gboolean
color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
@ -741,6 +959,129 @@ color_notebook_color_events (GtkWidget *widget,
return FALSE;
}
static void
color_notebook_toggle_update (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
gint i;
if (! GTK_TOGGLE_BUTTON (widget)->active)
return;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (widget == cnp->toggles[i])
cnp->active_channel = (GimpColorSelectorChannelType) i;
color_notebook_update (cnp, UPDATE_CHANNEL);
}
static void
color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data)
{
ColorNotebook *cnp;
gint old_values[7];
gint i, j;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
for (j = 0; j < 7; j++)
old_values[j] = cnp->values[j];
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
color_notebook_update_rgb_values (cnp);
}
else if ((i >= GIMP_COLOR_SELECTOR_RED) && (i <= GIMP_COLOR_SELECTOR_BLUE))
{
color_notebook_update_hsv_values (cnp);
}
color_notebook_update_scales (cnp, i);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static gint
color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
ColorNotebook *cnp;
gchar buffer[8];
gchar *hex_color;
guint hex_rgb;
cnp = (ColorNotebook *) data;
if (!cnp)
return FALSE;
switch (event->type)
{
case GDK_KEY_PRESS:
if (((GdkEventKey *) event)->keyval != GDK_Return)
break;
/* else fall through */
case GDK_FOCUS_CHANGE:
hex_color = g_strdup (gtk_entry_get_text (GTK_ENTRY (cnp->hex_entry)));
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
{
if ((sscanf (hex_color, "#%x", &hex_rgb) == 1) &&
(hex_rgb < (1 << 24)))
{
cnp->values[GIMP_COLOR_SELECTOR_RED] = (hex_rgb & 0xff0000) >> 16;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (hex_rgb & 0x00ff00) >> 8;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (hex_rgb & 0x0000ff);
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
}
g_free (hex_color);
break;
default:
/* do nothing */
break;
}
return FALSE;
}
static void
color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
@ -753,10 +1094,10 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
*r = (guchar) cnp->values[RED];
*g = (guchar) cnp->values[GREEN];
*b = (guchar) cnp->values[BLUE];
*a = (guchar) cnp->values[ALPHA];
*r = (guchar) cnp->values[GIMP_COLOR_SELECTOR_RED];
*g = (guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN];
*b = (guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE];
*a = (guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA];
}
static void
@ -771,10 +1112,13 @@ color_notebook_drop_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
cnp->values[RED] = (gint) r;
cnp->values[GREEN] = (gint) g;
cnp->values[BLUE] = (gint) b;
cnp->values[ALPHA] = (gint) a;
cnp->values[GIMP_COLOR_SELECTOR_RED] = (gint) r;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (gint) g;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (gint) b;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) a;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |

View File

@ -36,28 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GdkGC *gc;
gint values[4];
gint orig_values[4];
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
ColorNotebook * color_notebook_new (gint red,
gint green,
gint blue,

View File

@ -313,7 +313,7 @@ static void
color_area_edit (void)
{
GimpContext *user_context;
guchar r, g, b;
guchar r, g, b;
user_context = gimp_context_get_user ();
@ -346,8 +346,10 @@ color_area_edit (void)
color_notebook_show (color_notebook);
color_notebook_active = TRUE;
}
else
gdk_window_raise (color_notebook->shell->window);
else
{
color_notebook_show (color_notebook);
}
color_notebook_set_color (color_notebook, r, g, b, 255);
}

View File

@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define __COLOR_NOTEBOOK_C__ 1
#include "config.h"
@ -27,6 +28,7 @@
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "apptypes.h"
@ -38,6 +40,7 @@
#include "libgimp/gimphelpui.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpintl.h"
@ -46,23 +49,44 @@
#define COLOR_AREA_HEIGHT 20
enum
{
RED,
GREEN,
BLUE,
ALPHA
};
typedef enum
{
UPDATE_NOTEBOOK = 1 << 0,
UPDATE_NEW_COLOR = 1 << 1,
UPDATE_ORIG_COLOR = 1 << 2,
UPDATE_CALLER = 1 << 3
UPDATE_CHANNEL = 1 << 1,
UPDATE_NEW_COLOR = 1 << 2,
UPDATE_ORIG_COLOR = 1 << 3,
UPDATE_CALLER = 1 << 4
} ColorNotebookUpdateType;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GtkWidget *toggles[7];
GtkObject *slider_data[7];
GtkWidget *hex_entry;
GdkGC *gc;
gint values[7];
gint orig_values[4];
GimpColorSelectorChannelType active_channel;
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
/* information we keep on each registered colour selector */
typedef struct _ColorSelectorInfo ColorSelectorInfo;
@ -95,6 +119,9 @@ static void color_notebook_ok_callback (GtkWidget *widget,
static void color_notebook_cancel_callback (GtkWidget *widget,
gpointer data);
static void color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -110,14 +137,27 @@ static void color_notebook_selector_death (ColorSelectorInfo *info);
static void color_notebook_update (ColorNotebook *cnp,
ColorNotebookUpdateType update);
static void color_notebook_update_notebook (ColorNotebook *cnp);
static void color_notebook_update_channel (ColorNotebook *cnp);
static void color_notebook_update_caller (ColorNotebook *cnp);
static void color_notebook_update_colors (ColorNotebook *cnp,
ColorNotebookUpdateType which);
static void color_notebook_update_rgb_values (ColorNotebook *cnp);
static void color_notebook_update_hsv_values (ColorNotebook *cnp);
static void color_notebook_update_scales (ColorNotebook *cnp,
gint skip);
static gboolean color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_toggle_update (GtkWidget *widget,
gpointer data);
static void color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data);
static gint color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
guchar *g,
@ -162,12 +202,39 @@ color_notebook_new (gint red,
{
ColorNotebook *cnp;
GtkWidget *main_hbox;
/*GtkWidget *right_vbox;*/
GtkWidget *right_vbox;
GtkWidget *colors_frame;
GtkWidget *colors_hbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *label;
GSList *group;
gchar buffer[16];
ColorSelectorInfo *info;
ColorSelectorInstance *csel;
gint i;
static gchar *toggle_titles[] =
{
N_("H"),
N_("S"),
N_("V"),
N_("R"),
N_("G"),
N_("B"),
N_("A")
};
static gchar *slider_tips[7] =
{
N_("Hue"),
N_("Saturation"),
N_("Value"),
N_("Red"),
N_("Green"),
N_("Blue"),
N_("Alpha")
};
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 255 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 16 };
g_return_val_if_fail (selector_info != NULL, NULL);
@ -181,10 +248,12 @@ color_notebook_new (gint red,
cnp->selectors = NULL;
cnp->cur_page = NULL;
cnp->values[RED] = cnp->orig_values[RED] = red & 0xff;
cnp->values[GREEN] = cnp->orig_values[GREEN] = green & 0xff;
cnp->values[BLUE] = cnp->orig_values[BLUE] = blue & 0xff;
cnp->values[ALPHA] = cnp->orig_values[ALPHA] = alpha & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha & 0xff;
color_notebook_update_hsv_values (cnp);
cnp->shell =
gimp_dialog_new (_("Color Selection"), "color_selection",
@ -202,7 +271,7 @@ color_notebook_new (gint red,
NULL);
main_hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 1);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (cnp->shell)->vbox), main_hbox);
gtk_widget_show (main_hbox);
@ -229,10 +298,17 @@ color_notebook_new (gint red,
csel->color_notebook = cnp;
csel->info = info;
info->refs++;
csel->frame = info->methods.new (red, green, blue, alpha,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
csel->frame =
info->methods.new (cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
gtk_object_set_data (GTK_OBJECT (csel->frame), "gimp_color_notebook",
csel);
@ -266,27 +342,19 @@ color_notebook_new (gint red,
}
/* The right vertical box with old/new color area and color space sliders */
/*
right_vbox = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
*/
/* The old/new color area frame and hbox */
colors_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (colors_frame), GTK_SHADOW_IN);
/* gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0); */
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (cnp->shell)->action_area),
colors_frame,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0);
gtk_widget_show (colors_frame);
colors_hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), colors_hbox);
gtk_widget_show (colors_hbox);
hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), hbox);
gtk_widget_show (hbox);
/* The new color area */
cnp->new_color = gtk_drawing_area_new ();
@ -298,7 +366,7 @@ color_notebook_new (gint red,
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->new_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->new_color);
/* dnd stuff */
@ -325,7 +393,7 @@ color_notebook_new (gint red,
GTK_SIGNAL_FUNC (color_notebook_color_events),
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->orig_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->orig_color);
/* dnd stuff */
@ -336,6 +404,63 @@ color_notebook_new (gint red,
gimp_dnd_color_source_set (cnp->orig_color, color_notebook_drag_old_color,
cnp);
/* The color space sliders, toggle buttons and entries */
table = gtk_table_new (7, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (right_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
group = NULL;
for (i = 0; i < 7; i++)
{
cnp->toggles[i] =
gtk_radio_button_new_with_label (group, gettext (toggle_titles[i]));
gimp_help_set_help_data (cnp->toggles[i], gettext (slider_tips[i]), NULL);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (cnp->toggles[i]));
gtk_table_attach (GTK_TABLE (table), cnp->toggles[i],
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (cnp->toggles[i]), "toggled",
GTK_SIGNAL_FUNC (color_notebook_toggle_update),
cnp);
gtk_widget_show (cnp->toggles[i]);
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
gettext (slider_tips[i]),
NULL);
gtk_signal_connect (GTK_OBJECT (cnp->slider_data[i]), "value_changed",
GTK_SIGNAL_FUNC (color_notebook_scale_update),
cnp);
}
/* The hex triplet entry */
hbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (right_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
gtk_widget_set_usize (GTK_WIDGET (cnp->hex_entry), 75, 0);
gtk_box_pack_end (GTK_BOX (hbox), cnp->hex_entry, FALSE, FALSE, 2);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "focus_out_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "key_press_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_widget_show (cnp->hex_entry);
label = gtk_label_new (_("Hex Triplet:"));
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -356,7 +481,11 @@ void
color_notebook_show (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
gtk_widget_show (cnp->shell);
if (! GTK_WIDGET_VISIBLE (cnp->shell))
gtk_widget_show (cnp->shell);
else
gdk_window_raise (cnp->shell->window);
}
void
@ -403,15 +532,10 @@ color_notebook_set_color (ColorNotebook *cnp,
{
g_return_if_fail (cnp != NULL);
cnp->orig_values[RED] = red;
cnp->orig_values[GREEN] = green;
cnp->orig_values[BLUE] = blue;
cnp->orig_values[ALPHA] = alpha;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha;
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -424,6 +548,9 @@ color_notebook_set_color (ColorNotebook *cnp,
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -437,12 +564,19 @@ color_notebook_update_callback (gpointer data,
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_HUE] = hue;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = saturation;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = value;
cnp->values[GIMP_COLOR_SELECTOR_RED] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = alpha;
color_notebook_update (cnp, UPDATE_NEW_COLOR | UPDATE_CALLER);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static void
@ -455,10 +589,10 @@ color_notebook_ok_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -474,10 +608,10 @@ color_notebook_cancel_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->orig_values[RED],
cnp->orig_values[GREEN],
cnp->orig_values[BLUE],
cnp->orig_values[ALPHA],
(* cnp->callback) (cnp->orig_values[0],
cnp->orig_values[1],
cnp->orig_values[2],
cnp->orig_values[3],
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -500,7 +634,7 @@ color_notebook_page_switch (GtkWidget *widget,
cnp->cur_page = csel;
color_notebook_update (cnp, UPDATE_NOTEBOOK);
color_notebook_update (cnp, UPDATE_CHANNEL | UPDATE_NOTEBOOK);
}
static void
@ -622,6 +756,9 @@ color_notebook_update (ColorNotebook *cnp,
if (update & UPDATE_NOTEBOOK)
color_notebook_update_notebook (cnp);
if (update & UPDATE_CHANNEL)
color_notebook_update_channel (cnp);
if (update & UPDATE_NEW_COLOR)
color_notebook_update_colors (cnp, UPDATE_NEW_COLOR);
@ -640,11 +777,26 @@ color_notebook_update_notebook (ColorNotebook *cnp)
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.setcolor (csel->selector_data,
cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA]);
csel->info->methods.set_color (csel->selector_data,
cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
}
static void
color_notebook_update_channel (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.set_channel (csel->selector_data,
cnp->active_channel);
}
static void
@ -652,10 +804,10 @@ color_notebook_update_caller (ColorNotebook *cnp)
{
if (cnp && cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -683,9 +835,9 @@ color_notebook_update_colors (ColorNotebook *cnp,
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[RED];
green = cnp->values[GREEN];
blue = cnp->values[BLUE];
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
}
else
{
@ -710,6 +862,72 @@ color_notebook_update_colors (ColorNotebook *cnp,
}
}
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
return;
h = cnp->values[GIMP_COLOR_SELECTOR_HUE] / 360.0;
s = cnp->values[GIMP_COLOR_SELECTOR_SATURATION] / 100.0;
v = cnp->values[GIMP_COLOR_SELECTOR_VALUE] / 100.0;
gimp_hsv_to_rgb_double (&h, &s, &v);
cnp->values[GIMP_COLOR_SELECTOR_RED] = h * 255;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = s * 255;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = v * 255;
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
return;
r = cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0;
g = cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0;
b = cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0;
gimp_rgb_to_hsv_double (&r, &g, &b);
cnp->values[GIMP_COLOR_SELECTOR_HUE] = r * 360.0;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = g * 100.0;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = b * 100.0;
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gchar buffer[16];
gint i;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (cnp->slider_data[i]),
cnp->values[i]);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
}
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
static gboolean
color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
@ -741,6 +959,129 @@ color_notebook_color_events (GtkWidget *widget,
return FALSE;
}
static void
color_notebook_toggle_update (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
gint i;
if (! GTK_TOGGLE_BUTTON (widget)->active)
return;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (widget == cnp->toggles[i])
cnp->active_channel = (GimpColorSelectorChannelType) i;
color_notebook_update (cnp, UPDATE_CHANNEL);
}
static void
color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data)
{
ColorNotebook *cnp;
gint old_values[7];
gint i, j;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
for (j = 0; j < 7; j++)
old_values[j] = cnp->values[j];
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
color_notebook_update_rgb_values (cnp);
}
else if ((i >= GIMP_COLOR_SELECTOR_RED) && (i <= GIMP_COLOR_SELECTOR_BLUE))
{
color_notebook_update_hsv_values (cnp);
}
color_notebook_update_scales (cnp, i);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static gint
color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
ColorNotebook *cnp;
gchar buffer[8];
gchar *hex_color;
guint hex_rgb;
cnp = (ColorNotebook *) data;
if (!cnp)
return FALSE;
switch (event->type)
{
case GDK_KEY_PRESS:
if (((GdkEventKey *) event)->keyval != GDK_Return)
break;
/* else fall through */
case GDK_FOCUS_CHANGE:
hex_color = g_strdup (gtk_entry_get_text (GTK_ENTRY (cnp->hex_entry)));
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
{
if ((sscanf (hex_color, "#%x", &hex_rgb) == 1) &&
(hex_rgb < (1 << 24)))
{
cnp->values[GIMP_COLOR_SELECTOR_RED] = (hex_rgb & 0xff0000) >> 16;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (hex_rgb & 0x00ff00) >> 8;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (hex_rgb & 0x0000ff);
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
}
g_free (hex_color);
break;
default:
/* do nothing */
break;
}
return FALSE;
}
static void
color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
@ -753,10 +1094,10 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
*r = (guchar) cnp->values[RED];
*g = (guchar) cnp->values[GREEN];
*b = (guchar) cnp->values[BLUE];
*a = (guchar) cnp->values[ALPHA];
*r = (guchar) cnp->values[GIMP_COLOR_SELECTOR_RED];
*g = (guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN];
*b = (guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE];
*a = (guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA];
}
static void
@ -771,10 +1112,13 @@ color_notebook_drop_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
cnp->values[RED] = (gint) r;
cnp->values[GREEN] = (gint) g;
cnp->values[BLUE] = (gint) b;
cnp->values[ALPHA] = (gint) a;
cnp->values[GIMP_COLOR_SELECTOR_RED] = (gint) r;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (gint) g;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (gint) b;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) a;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |

View File

@ -36,28 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GdkGC *gc;
gint values[4];
gint orig_values[4];
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
ColorNotebook * color_notebook_new (gint red,
gint green,
gint blue,

View File

@ -42,10 +42,10 @@
#include "libgimp/gimpintl.h"
#define XY_DEF_WIDTH 240
#define XY_DEF_HEIGHT 240
#define XY_DEF_WIDTH 200
#define XY_DEF_HEIGHT 200
#define Z_DEF_WIDTH 15
#define Z_DEF_HEIGHT 240
#define Z_DEF_HEIGHT 200
#define COLOR_AREA_WIDTH 74
#define COLOR_AREA_HEIGHT 20
@ -82,7 +82,10 @@ typedef enum
UPDATE_CALLER = 1 << 6
} ColorSelectUpdateType;
typedef void (* ColorSelectCallback) (gint r,
typedef void (* ColorSelectCallback) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -94,15 +97,11 @@ struct _ColorSelect
{
GtkWidget *xy_color;
GtkWidget *z_color;
GtkWidget *toggles[6];
GtkObject *slider_data[6];
GtkWidget *hex_entry;
gint pos[3];
gint values[7];
gint z_color_fill;
gint xy_color_fill;
gboolean wants_updates;
GdkGC *gc;
ColorSelectCallback callback;
@ -144,28 +143,19 @@ static void color_select_update_values (ColorSelect *);
static void color_select_update_rgb_values (ColorSelect *);
static void color_select_update_hsv_values (ColorSelect *);
static void color_select_update_pos (ColorSelect *);
static void color_select_update_scales (ColorSelect *,
gint );
static gint color_select_xy_expose (GtkWidget *,
GdkEventExpose *,
ColorSelect *);
static gint color_select_xy_events (GtkWidget *,
GdkEvent *,
ColorSelect *);
static gint color_select_z_expose (GtkWidget *,
GdkEventExpose *,
ColorSelect *);
static gint color_select_z_events (GtkWidget *,
GdkEvent *,
ColorSelect *);
static void color_select_scale_update (GtkObject *,
gpointer );
static void color_select_toggle_update (GtkWidget *,
gpointer );
static gint color_select_hex_entry_events (GtkWidget *,
GdkEvent *,
gpointer );
static gint color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *eevent,
ColorSelect *color_select);
static gint color_select_xy_events (GtkWidget *widget,
GdkEvent *event,
ColorSelect *color_select);
static gint color_select_z_expose (GtkWidget *widget,
GdkEventExpose *eevent,
ColorSelect *color_select);
static gint color_select_z_events (GtkWidget *widet,
GdkEvent *event,
ColorSelect *color_select);
static void color_select_image_fill (GtkWidget *,
ColorSelectFillType,
@ -190,6 +180,9 @@ static void color_select_update_hue_value (ColorSelectFill *);
static void color_select_update_saturation_value (ColorSelectFill *);
static GtkWidget * color_select_notebook_new (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
@ -198,12 +191,20 @@ static GtkWidget * color_select_notebook_new (gint ,
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_setcolor (gpointer ,
static void color_select_notebook_set_color (gpointer ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint );
static void color_select_notebook_set_channel (gpointer ,
GimpColorSelectorChannelType channel);
static void color_select_notebook_update_callback (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
@ -244,7 +245,8 @@ color_select_init (void)
{
color_select_notebook_new,
color_select_notebook_free,
color_select_notebook_setcolor
color_select_notebook_set_color,
color_select_notebook_set_channel
};
gimp_color_selector_register ("GIMP", "built_in.html", &methods);
@ -260,49 +262,25 @@ color_select_widget_new (ColorSelect *csp,
{
GtkWidget *main_vbox;
GtkWidget *main_hbox;
GtkWidget *hbox;
GtkWidget *xy_frame;
GtkWidget *z_frame;
GtkWidget *right_vbox;
GtkWidget *table;
GtkWidget *hex_hbox;
GtkWidget *label;
GSList *group;
gchar buffer[16];
gint i;
static gchar *toggle_titles[6] =
{
N_("H"),
N_("S"),
N_("V"),
N_("R"),
N_("G"),
N_("B")
};
static gchar *slider_tips[6] =
{
N_("Hue"),
N_("Saturation"),
N_("Value"),
N_("Red"),
N_("Green"),
N_("Blue")
};
static gdouble slider_max_vals[6] = { 360, 100, 100, 255, 255, 255 };
static gdouble slider_incs[6] = { 30, 10, 10, 16, 16, 16 };
main_vbox = gtk_vbox_new (FALSE, 2);
main_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 2);
main_hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 0);
gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, TRUE, 2);
main_hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, FALSE, 0);
gtk_widget_show (main_hbox);
hbox = gtk_hbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (main_hbox), hbox, TRUE, FALSE, 0);
gtk_widget_show (hbox);
/* The x/y component preview */
xy_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (xy_frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (main_hbox), xy_frame, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), xy_frame, FALSE, FALSE, 2);
gtk_widget_show (xy_frame);
csp->xy_color = gtk_preview_new (GTK_PREVIEW_COLOR);
@ -330,7 +308,7 @@ color_select_widget_new (ColorSelect *csp,
/* The z component preview */
z_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (z_frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (main_hbox), z_frame, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), z_frame, FALSE, FALSE, 2);
gtk_widget_show (z_frame);
csp->z_color = gtk_preview_new (GTK_PREVIEW_COLOR);
@ -346,70 +324,6 @@ color_select_widget_new (ColorSelect *csp,
gtk_container_add (GTK_CONTAINER (z_frame), csp->z_color);
gtk_widget_show (csp->z_color);
/* The right vertical box with old/new color area and color space sliders */
right_vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (right_vbox), 0);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
/* The color space sliders, toggle buttons and entries */
table = gtk_table_new (6, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_box_pack_start (GTK_BOX (right_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
group = NULL;
for (i = 0; i < 6; i++)
{
csp->toggles[i] =
gtk_radio_button_new_with_label (group, gettext (toggle_titles[i]));
gimp_help_set_help_data (csp->toggles[i], gettext (slider_tips[i]), NULL);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (csp->toggles[i]));
gtk_table_attach (GTK_TABLE (table), csp->toggles[i],
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (csp->toggles[i]), "toggled",
GTK_SIGNAL_FUNC (color_select_toggle_update),
csp);
gtk_widget_show (csp->toggles[i]);
csp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
csp->values[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
gettext (slider_tips[i]),
NULL);
gtk_signal_connect (GTK_OBJECT (csp->slider_data[i]), "value_changed",
GTK_SIGNAL_FUNC (color_select_scale_update),
csp);
}
/* The hex triplet entry */
hex_hbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (right_vbox), hex_hbox, FALSE, FALSE, 0);
gtk_widget_show (hex_hbox);
csp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", r, g, b);
gtk_entry_set_text (GTK_ENTRY (csp->hex_entry), buffer);
gtk_widget_set_usize (GTK_WIDGET (csp->hex_entry), 75, 0);
gtk_box_pack_end (GTK_BOX (hex_hbox), csp->hex_entry, FALSE, FALSE, 2);
gtk_signal_connect (GTK_OBJECT (csp->hex_entry), "focus_out_event",
GTK_SIGNAL_FUNC (color_select_hex_entry_events),
csp);
gtk_signal_connect (GTK_OBJECT (csp->hex_entry), "key_press_event",
GTK_SIGNAL_FUNC (color_select_hex_entry_events),
csp);
gtk_widget_show (csp->hex_entry);
label = gtk_label_new (_("Hex Triplet:"));
gtk_box_pack_end (GTK_BOX (hex_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
return main_vbox;
}
@ -432,14 +346,18 @@ color_select_drop_color (GtkWidget *widget,
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
color_select_update_scales (csp, -1);
color_select_update (csp, UPDATE_Z_COLOR);
color_select_update (csp, UPDATE_XY_COLOR);
color_select_update (csp, UPDATE_CALLER);
}
static void
color_select_set_color (ColorSelect *csp,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
@ -448,14 +366,15 @@ color_select_set_color (ColorSelect *csp,
if (!csp)
return;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s;
csp->values[COLOR_SELECT_VALUE] = v;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
color_select_update_scales (csp, -1);
color_select_update (csp, UPDATE_Z_COLOR);
color_select_update (csp, UPDATE_XY_COLOR);
@ -474,7 +393,6 @@ color_select_update (ColorSelect *csp,
if (update & UPDATE_VALUES)
{
color_select_update_values (csp);
color_select_update_scales (csp, -1);
}
if (update & UPDATE_XY_COLOR)
@ -489,16 +407,19 @@ color_select_update (ColorSelect *csp,
gtk_widget_draw (csp->z_color, NULL);
}
/*if (update & UPDATE_CALLER)*/
color_select_update_caller (csp);
if (update & UPDATE_CALLER)
color_select_update_caller (csp);
}
static void
color_select_update_caller (ColorSelect *csp)
{
if (csp && csp->wants_updates && csp->callback)
if (csp && csp->callback)
{
(* csp->callback) (csp->values[COLOR_SELECT_RED],
(* csp->callback) (csp->values[COLOR_SELECT_HUE],
csp->values[COLOR_SELECT_SATURATION],
csp->values[COLOR_SELECT_VALUE],
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE],
csp->values[COLOR_SELECT_ALPHA],
@ -740,32 +661,6 @@ color_select_update_pos (ColorSelect *csp)
}
}
static void
color_select_update_scales (ColorSelect *csp,
gint skip)
{
gchar buffer[16];
gint i;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (csp->slider_data[i]), csp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (csp->slider_data[i]),
csp->values[i]);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (csp->slider_data[i]), csp);
}
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE]);
gtk_entry_set_text (GTK_ENTRY (csp->hex_entry), buffer);
}
static gint
color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *event,
@ -814,7 +709,7 @@ color_select_xy_events (GtkWidget *widget,
NULL, NULL, bevent->time);
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_BUTTON_RELEASE:
@ -836,7 +731,7 @@ color_select_xy_events (GtkWidget *widget,
gdk_pointer_ungrab (bevent->time);
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_MOTION_NOTIFY:
@ -863,7 +758,7 @@ color_select_xy_events (GtkWidget *widget,
csp->pos[1] = 255;
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
default:
@ -914,7 +809,7 @@ color_select_z_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_BUTTON_RELEASE:
@ -930,7 +825,7 @@ color_select_z_events (GtkWidget *widget,
gdk_pointer_ungrab (bevent->time);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES | UPDATE_XY_COLOR);
color_select_update (csp, UPDATE_VALUES | UPDATE_XY_COLOR | UPDATE_CALLER);
break;
case GDK_MOTION_NOTIFY:
@ -951,7 +846,7 @@ color_select_z_events (GtkWidget *widget,
csp->pos[2] = 255;
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
default:
@ -962,94 +857,13 @@ color_select_z_events (GtkWidget *widget,
}
static void
color_select_scale_update (GtkObject *adjustment,
gpointer data)
color_select_set_channel (ColorSelect *csp,
GimpColorSelectorChannelType type)
{
ColorSelect *csp;
gint old_values[6];
gint update_z_marker;
gint update_xy_marker;
gint i, j;
csp = (ColorSelect *) data;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (csp->slider_data[i] == adjustment)
break;
for (j = 0; j < 6; j++)
old_values[j] = csp->values[j];
csp->values[i] = (int) (GTK_ADJUSTMENT (adjustment)->value);
if ((i >= COLOR_SELECT_HUE) && (i <= COLOR_SELECT_VALUE))
color_select_update_rgb_values (csp);
else if ((i >= COLOR_SELECT_RED) && (i <= COLOR_SELECT_BLUE))
color_select_update_hsv_values (csp);
color_select_update_scales (csp, i);
update_z_marker = 0;
update_xy_marker = 0;
for (j = 0; j < 6; j++)
{
if (j == csp->z_color_fill)
{
if (old_values[j] != csp->values[j])
update_z_marker = 1;
}
else
{
if (old_values[j] != csp->values[j])
update_xy_marker = 1;
}
}
if (update_z_marker)
{
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_POS | UPDATE_XY_COLOR);
color_select_draw_z_marker (csp, NULL);
}
else
{
if (update_z_marker)
color_select_draw_z_marker (csp, NULL);
if (update_xy_marker)
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_POS);
if (update_z_marker)
color_select_draw_z_marker (csp, NULL);
if (update_xy_marker)
color_select_draw_xy_marker (csp, NULL);
}
}
static void
color_select_toggle_update (GtkWidget *widget,
gpointer data)
{
ColorSelect *csp;
ColorSelectFillType type = COLOR_SELECT_HUE;
gint i;
if (!GTK_TOGGLE_BUTTON (widget)->active)
return;
csp = (ColorSelect *) data;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (widget == csp->toggles[i])
type = (ColorSelectFillType) i;
switch (type)
switch ((ColorSelectFillType) type)
{
case COLOR_SELECT_HUE:
csp->z_color_fill = COLOR_SELECT_HUE;
@ -1083,60 +897,6 @@ color_select_toggle_update (GtkWidget *widget,
color_select_update (csp, UPDATE_Z_COLOR | UPDATE_XY_COLOR);
}
static gint
color_select_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
ColorSelect *csp;
gchar buffer[8];
gchar *hex_color;
guint hex_rgb;
csp = (ColorSelect *) data;
if (!csp)
return FALSE;
switch (event->type)
{
case GDK_KEY_PRESS:
if (((GdkEventKey *) event)->keyval != GDK_Return)
break;
/* else fall through */
case GDK_FOCUS_CHANGE:
hex_color = g_strdup (gtk_entry_get_text (GTK_ENTRY (csp->hex_entry)));
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE]);
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
{
if ((sscanf (hex_color, "#%x", &hex_rgb) == 1) &&
(hex_rgb < (1 << 24)))
color_select_set_color (csp,
(hex_rgb & 0xff0000) >> 16,
(hex_rgb & 0x00ff00) >> 8,
(hex_rgb & 0x0000ff),
255);
}
g_free (hex_color);
break;
default:
/* do nothing */
break;
}
return FALSE;
}
static void
color_select_image_fill (GtkWidget *preview,
ColorSelectFillType type,
@ -1149,8 +909,8 @@ color_select_image_fill (GtkWidget *preview,
csf.update = update_procs[type];
csf.y = -1;
csf.width = preview->requisition.width;
csf.y = -1;
csf.width = preview->requisition.width;
csf.height = preview->requisition.height;
csf.values = values;
@ -1182,7 +942,7 @@ color_select_draw_z_marker (ColorSelect *csp,
return;
y = (Z_DEF_HEIGHT - 1) - ((Z_DEF_HEIGHT - 1) * csp->pos[2]) / 255;
width = csp->z_color->requisition.width;
width = csp->z_color->requisition.width;
height = csp->z_color->requisition.height;
minx = 0;
miny = 0;
@ -1724,7 +1484,7 @@ color_select_update_saturation_value (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
s = (float) csf->y / csf->height;
s = (gfloat) csf->y / csf->height;
if (s < 0)
s = 0;
@ -1733,16 +1493,16 @@ color_select_update_saturation_value (ColorSelectFill *csf)
s = 1 - s;
h = (float) csf->values[COLOR_SELECT_HUE];
h = (gfloat) csf->values[COLOR_SELECT_HUE];
if (h >= 360)
h -= 360;
h /= 60;
f = (h - (int) h) * 255;
f = (h - (gint) h) * 255;
v = 0;
dv = 1.0 / csf->width;
switch ((int) h)
switch ((gint) h)
{
case 0:
for (i = 0; i < csf->width; i++)
@ -1820,7 +1580,10 @@ typedef struct
} notebook_glue;
static GtkWidget *
color_select_notebook_new (gint r,
color_select_notebook_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -1846,13 +1609,15 @@ color_select_notebook_new (gint r,
csp->z_color_fill = COLOR_SELECT_HUE;
csp->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
csp->gc = NULL;
csp->wants_updates = TRUE;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_hsv_values (csp);
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s;
csp->values[COLOR_SELECT_VALUE] = v;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_pos (csp);
glue->main_vbox = color_select_widget_new (csp, r, g, b, a);
@ -1882,19 +1647,34 @@ color_select_notebook_free (gpointer data)
static void
color_select_notebook_setcolor (gpointer data,
gint r,
gint g,
gint b,
gint a)
color_select_notebook_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
{
notebook_glue *glue = data;
color_select_set_color (glue->csp, r, g, b, a);
color_select_set_color (glue->csp, h, s, v, r, g, b, a);
}
static void
color_select_notebook_update_callback (gint r,
color_select_notebook_set_channel (gpointer data,
GimpColorSelectorChannelType channel)
{
notebook_glue *glue = data;
color_select_set_channel (glue->csp, channel);
}
static void
color_select_notebook_update_callback (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -1902,5 +1682,5 @@ color_select_notebook_update_callback (gint r,
{
notebook_glue *glue = data;
glue->callback (glue->client_data, r, g, b, a);
glue->callback (glue->client_data, h, s, v, r, g, b, a);
}

View File

@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define __COLOR_NOTEBOOK_C__ 1
#include "config.h"
@ -27,6 +28,7 @@
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "apptypes.h"
@ -38,6 +40,7 @@
#include "libgimp/gimphelpui.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpintl.h"
@ -46,23 +49,44 @@
#define COLOR_AREA_HEIGHT 20
enum
{
RED,
GREEN,
BLUE,
ALPHA
};
typedef enum
{
UPDATE_NOTEBOOK = 1 << 0,
UPDATE_NEW_COLOR = 1 << 1,
UPDATE_ORIG_COLOR = 1 << 2,
UPDATE_CALLER = 1 << 3
UPDATE_CHANNEL = 1 << 1,
UPDATE_NEW_COLOR = 1 << 2,
UPDATE_ORIG_COLOR = 1 << 3,
UPDATE_CALLER = 1 << 4
} ColorNotebookUpdateType;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GtkWidget *toggles[7];
GtkObject *slider_data[7];
GtkWidget *hex_entry;
GdkGC *gc;
gint values[7];
gint orig_values[4];
GimpColorSelectorChannelType active_channel;
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
/* information we keep on each registered colour selector */
typedef struct _ColorSelectorInfo ColorSelectorInfo;
@ -95,6 +119,9 @@ static void color_notebook_ok_callback (GtkWidget *widget,
static void color_notebook_cancel_callback (GtkWidget *widget,
gpointer data);
static void color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -110,14 +137,27 @@ static void color_notebook_selector_death (ColorSelectorInfo *info);
static void color_notebook_update (ColorNotebook *cnp,
ColorNotebookUpdateType update);
static void color_notebook_update_notebook (ColorNotebook *cnp);
static void color_notebook_update_channel (ColorNotebook *cnp);
static void color_notebook_update_caller (ColorNotebook *cnp);
static void color_notebook_update_colors (ColorNotebook *cnp,
ColorNotebookUpdateType which);
static void color_notebook_update_rgb_values (ColorNotebook *cnp);
static void color_notebook_update_hsv_values (ColorNotebook *cnp);
static void color_notebook_update_scales (ColorNotebook *cnp,
gint skip);
static gboolean color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_toggle_update (GtkWidget *widget,
gpointer data);
static void color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data);
static gint color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
guchar *g,
@ -162,12 +202,39 @@ color_notebook_new (gint red,
{
ColorNotebook *cnp;
GtkWidget *main_hbox;
/*GtkWidget *right_vbox;*/
GtkWidget *right_vbox;
GtkWidget *colors_frame;
GtkWidget *colors_hbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *label;
GSList *group;
gchar buffer[16];
ColorSelectorInfo *info;
ColorSelectorInstance *csel;
gint i;
static gchar *toggle_titles[] =
{
N_("H"),
N_("S"),
N_("V"),
N_("R"),
N_("G"),
N_("B"),
N_("A")
};
static gchar *slider_tips[7] =
{
N_("Hue"),
N_("Saturation"),
N_("Value"),
N_("Red"),
N_("Green"),
N_("Blue"),
N_("Alpha")
};
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 255 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 16 };
g_return_val_if_fail (selector_info != NULL, NULL);
@ -181,10 +248,12 @@ color_notebook_new (gint red,
cnp->selectors = NULL;
cnp->cur_page = NULL;
cnp->values[RED] = cnp->orig_values[RED] = red & 0xff;
cnp->values[GREEN] = cnp->orig_values[GREEN] = green & 0xff;
cnp->values[BLUE] = cnp->orig_values[BLUE] = blue & 0xff;
cnp->values[ALPHA] = cnp->orig_values[ALPHA] = alpha & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue & 0xff;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha & 0xff;
color_notebook_update_hsv_values (cnp);
cnp->shell =
gimp_dialog_new (_("Color Selection"), "color_selection",
@ -202,7 +271,7 @@ color_notebook_new (gint red,
NULL);
main_hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 1);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (cnp->shell)->vbox), main_hbox);
gtk_widget_show (main_hbox);
@ -229,10 +298,17 @@ color_notebook_new (gint red,
csel->color_notebook = cnp;
csel->info = info;
info->refs++;
csel->frame = info->methods.new (red, green, blue, alpha,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
csel->frame =
info->methods.new (cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
gtk_object_set_data (GTK_OBJECT (csel->frame), "gimp_color_notebook",
csel);
@ -266,27 +342,19 @@ color_notebook_new (gint red,
}
/* The right vertical box with old/new color area and color space sliders */
/*
right_vbox = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
*/
/* The old/new color area frame and hbox */
colors_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (colors_frame), GTK_SHADOW_IN);
/* gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0); */
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (cnp->shell)->action_area),
colors_frame,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), colors_frame, FALSE, FALSE, 0);
gtk_widget_show (colors_frame);
colors_hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), colors_hbox);
gtk_widget_show (colors_hbox);
hbox = gtk_hbox_new (TRUE, 2);
gtk_container_add (GTK_CONTAINER (colors_frame), hbox);
gtk_widget_show (hbox);
/* The new color area */
cnp->new_color = gtk_drawing_area_new ();
@ -298,7 +366,7 @@ color_notebook_new (gint red,
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->new_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->new_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->new_color);
/* dnd stuff */
@ -325,7 +393,7 @@ color_notebook_new (gint red,
GTK_SIGNAL_FUNC (color_notebook_color_events),
cnp);
gtk_object_set_user_data (GTK_OBJECT (cnp->orig_color), cnp);
gtk_box_pack_start (GTK_BOX (colors_hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cnp->orig_color, TRUE, TRUE, 0);
gtk_widget_show (cnp->orig_color);
/* dnd stuff */
@ -336,6 +404,63 @@ color_notebook_new (gint red,
gimp_dnd_color_source_set (cnp->orig_color, color_notebook_drag_old_color,
cnp);
/* The color space sliders, toggle buttons and entries */
table = gtk_table_new (7, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (right_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
group = NULL;
for (i = 0; i < 7; i++)
{
cnp->toggles[i] =
gtk_radio_button_new_with_label (group, gettext (toggle_titles[i]));
gimp_help_set_help_data (cnp->toggles[i], gettext (slider_tips[i]), NULL);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (cnp->toggles[i]));
gtk_table_attach (GTK_TABLE (table), cnp->toggles[i],
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (cnp->toggles[i]), "toggled",
GTK_SIGNAL_FUNC (color_notebook_toggle_update),
cnp);
gtk_widget_show (cnp->toggles[i]);
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
gettext (slider_tips[i]),
NULL);
gtk_signal_connect (GTK_OBJECT (cnp->slider_data[i]), "value_changed",
GTK_SIGNAL_FUNC (color_notebook_scale_update),
cnp);
}
/* The hex triplet entry */
hbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (right_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
gtk_widget_set_usize (GTK_WIDGET (cnp->hex_entry), 75, 0);
gtk_box_pack_end (GTK_BOX (hbox), cnp->hex_entry, FALSE, FALSE, 2);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "focus_out_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_signal_connect (GTK_OBJECT (cnp->hex_entry), "key_press_event",
GTK_SIGNAL_FUNC (color_notebook_hex_entry_events),
cnp);
gtk_widget_show (cnp->hex_entry);
label = gtk_label_new (_("Hex Triplet:"));
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -356,7 +481,11 @@ void
color_notebook_show (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
gtk_widget_show (cnp->shell);
if (! GTK_WIDGET_VISIBLE (cnp->shell))
gtk_widget_show (cnp->shell);
else
gdk_window_raise (cnp->shell->window);
}
void
@ -403,15 +532,10 @@ color_notebook_set_color (ColorNotebook *cnp,
{
g_return_if_fail (cnp != NULL);
cnp->orig_values[RED] = red;
cnp->orig_values[GREEN] = green;
cnp->orig_values[BLUE] = blue;
cnp->orig_values[ALPHA] = alpha;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_RED] = cnp->orig_values[0] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = cnp->orig_values[1] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = cnp->orig_values[2] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = cnp->orig_values[3] = alpha;
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -424,6 +548,9 @@ color_notebook_set_color (ColorNotebook *cnp,
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
@ -437,12 +564,19 @@ color_notebook_update_callback (gpointer data,
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
cnp->values[RED] = red;
cnp->values[GREEN] = green;
cnp->values[BLUE] = blue;
cnp->values[ALPHA] = alpha;
cnp->values[GIMP_COLOR_SELECTOR_HUE] = hue;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = saturation;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = value;
cnp->values[GIMP_COLOR_SELECTOR_RED] = red;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = green;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = blue;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = alpha;
color_notebook_update (cnp, UPDATE_NEW_COLOR | UPDATE_CALLER);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static void
@ -455,10 +589,10 @@ color_notebook_ok_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -474,10 +608,10 @@ color_notebook_cancel_callback (GtkWidget *widget,
if (cnp->callback)
{
(* cnp->callback) (cnp->orig_values[RED],
cnp->orig_values[GREEN],
cnp->orig_values[BLUE],
cnp->orig_values[ALPHA],
(* cnp->callback) (cnp->orig_values[0],
cnp->orig_values[1],
cnp->orig_values[2],
cnp->orig_values[3],
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -500,7 +634,7 @@ color_notebook_page_switch (GtkWidget *widget,
cnp->cur_page = csel;
color_notebook_update (cnp, UPDATE_NOTEBOOK);
color_notebook_update (cnp, UPDATE_CHANNEL | UPDATE_NOTEBOOK);
}
static void
@ -622,6 +756,9 @@ color_notebook_update (ColorNotebook *cnp,
if (update & UPDATE_NOTEBOOK)
color_notebook_update_notebook (cnp);
if (update & UPDATE_CHANNEL)
color_notebook_update_channel (cnp);
if (update & UPDATE_NEW_COLOR)
color_notebook_update_colors (cnp, UPDATE_NEW_COLOR);
@ -640,11 +777,26 @@ color_notebook_update_notebook (ColorNotebook *cnp)
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.setcolor (csel->selector_data,
cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA]);
csel->info->methods.set_color (csel->selector_data,
cnp->values[GIMP_COLOR_SELECTOR_HUE],
cnp->values[GIMP_COLOR_SELECTOR_SATURATION],
cnp->values[GIMP_COLOR_SELECTOR_VALUE],
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
}
static void
color_notebook_update_channel (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
csel->info->methods.set_channel (csel->selector_data,
cnp->active_channel);
}
static void
@ -652,10 +804,10 @@ color_notebook_update_caller (ColorNotebook *cnp)
{
if (cnp && cnp->callback)
{
(* cnp->callback) (cnp->values[RED],
cnp->values[GREEN],
cnp->values[BLUE],
cnp->values[ALPHA],
(* cnp->callback) (cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE],
cnp->values[GIMP_COLOR_SELECTOR_ALPHA],
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -683,9 +835,9 @@ color_notebook_update_colors (ColorNotebook *cnp,
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[RED];
green = cnp->values[GREEN];
blue = cnp->values[BLUE];
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
}
else
{
@ -710,6 +862,72 @@ color_notebook_update_colors (ColorNotebook *cnp,
}
}
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
return;
h = cnp->values[GIMP_COLOR_SELECTOR_HUE] / 360.0;
s = cnp->values[GIMP_COLOR_SELECTOR_SATURATION] / 100.0;
v = cnp->values[GIMP_COLOR_SELECTOR_VALUE] / 100.0;
gimp_hsv_to_rgb_double (&h, &s, &v);
cnp->values[GIMP_COLOR_SELECTOR_RED] = h * 255;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = s * 255;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = v * 255;
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
return;
r = cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0;
g = cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0;
b = cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0;
gimp_rgb_to_hsv_double (&r, &g, &b);
cnp->values[GIMP_COLOR_SELECTOR_HUE] = r * 360.0;
cnp->values[GIMP_COLOR_SELECTOR_SATURATION] = g * 100.0;
cnp->values[GIMP_COLOR_SELECTOR_VALUE] = b * 100.0;
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gchar buffer[16];
gint i;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (cnp->slider_data[i]),
cnp->values[i]);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
}
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
static gboolean
color_notebook_color_events (GtkWidget *widget,
GdkEvent *event,
@ -741,6 +959,129 @@ color_notebook_color_events (GtkWidget *widget,
return FALSE;
}
static void
color_notebook_toggle_update (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
gint i;
if (! GTK_TOGGLE_BUTTON (widget)->active)
return;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (widget == cnp->toggles[i])
cnp->active_channel = (GimpColorSelectorChannelType) i;
color_notebook_update (cnp, UPDATE_CHANNEL);
}
static void
color_notebook_scale_update (GtkAdjustment *adjustment,
gpointer data)
{
ColorNotebook *cnp;
gint old_values[7];
gint i, j;
cnp = (ColorNotebook *) data;
if (!cnp)
return;
for (i = 0; i < 7; i++)
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
for (j = 0; j < 7; j++)
old_values[j] = cnp->values[j];
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
color_notebook_update_rgb_values (cnp);
}
else if ((i >= GIMP_COLOR_SELECTOR_RED) && (i <= GIMP_COLOR_SELECTOR_BLUE))
{
color_notebook_update_hsv_values (cnp);
}
color_notebook_update_scales (cnp, i);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
static gint
color_notebook_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
ColorNotebook *cnp;
gchar buffer[8];
gchar *hex_color;
guint hex_rgb;
cnp = (ColorNotebook *) data;
if (!cnp)
return FALSE;
switch (event->type)
{
case GDK_KEY_PRESS:
if (((GdkEventKey *) event)->keyval != GDK_Return)
break;
/* else fall through */
case GDK_FOCUS_CHANGE:
hex_color = g_strdup (gtk_entry_get_text (GTK_ENTRY (cnp->hex_entry)));
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
cnp->values[GIMP_COLOR_SELECTOR_RED],
cnp->values[GIMP_COLOR_SELECTOR_GREEN],
cnp->values[GIMP_COLOR_SELECTOR_BLUE]);
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
{
if ((sscanf (hex_color, "#%x", &hex_rgb) == 1) &&
(hex_rgb < (1 << 24)))
{
cnp->values[GIMP_COLOR_SELECTOR_RED] = (hex_rgb & 0xff0000) >> 16;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (hex_rgb & 0x00ff00) >> 8;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (hex_rgb & 0x0000ff);
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
UPDATE_NEW_COLOR |
UPDATE_CALLER);
}
}
g_free (hex_color);
break;
default:
/* do nothing */
break;
}
return FALSE;
}
static void
color_notebook_drag_new_color (GtkWidget *widget,
guchar *r,
@ -753,10 +1094,10 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
*r = (guchar) cnp->values[RED];
*g = (guchar) cnp->values[GREEN];
*b = (guchar) cnp->values[BLUE];
*a = (guchar) cnp->values[ALPHA];
*r = (guchar) cnp->values[GIMP_COLOR_SELECTOR_RED];
*g = (guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN];
*b = (guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE];
*a = (guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA];
}
static void
@ -771,10 +1112,13 @@ color_notebook_drop_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
cnp->values[RED] = (gint) r;
cnp->values[GREEN] = (gint) g;
cnp->values[BLUE] = (gint) b;
cnp->values[ALPHA] = (gint) a;
cnp->values[GIMP_COLOR_SELECTOR_RED] = (gint) r;
cnp->values[GIMP_COLOR_SELECTOR_GREEN] = (gint) g;
cnp->values[GIMP_COLOR_SELECTOR_BLUE] = (gint) b;
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) a;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |

View File

@ -36,28 +36,6 @@ typedef void (* ColorNotebookCallback) (gint red,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
struct _ColorNotebook
{
GtkWidget *shell;
GtkWidget *notebook;
GtkWidget *new_color;
GtkWidget *orig_color;
GdkGC *gc;
gint values[4];
gint orig_values[4];
ColorNotebookCallback callback;
gpointer client_data;
gint wants_updates;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
};
ColorNotebook * color_notebook_new (gint red,
gint green,
gint blue,

View File

@ -313,7 +313,7 @@ static void
color_area_edit (void)
{
GimpContext *user_context;
guchar r, g, b;
guchar r, g, b;
user_context = gimp_context_get_user ();
@ -346,8 +346,10 @@ color_area_edit (void)
color_notebook_show (color_notebook);
color_notebook_active = TRUE;
}
else
gdk_window_raise (color_notebook->shell->window);
else
{
color_notebook_show (color_notebook);
}
color_notebook_set_color (color_notebook, r, g, b, 255);
}

View File

@ -28,13 +28,31 @@ extern "C" {
/* For information look at the html documentation */
typedef enum
{
GIMP_COLOR_SELECTOR_HUE,
GIMP_COLOR_SELECTOR_SATURATION,
GIMP_COLOR_SELECTOR_VALUE,
GIMP_COLOR_SELECTOR_RED,
GIMP_COLOR_SELECTOR_GREEN,
GIMP_COLOR_SELECTOR_BLUE,
GIMP_COLOR_SELECTOR_ALPHA
} GimpColorSelectorChannelType;
typedef void (* GimpColorSelectorCallback) (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a);
typedef GtkWidget * (* GimpColorSelectorNewFunc) (gint r,
typedef GtkWidget * (* GimpColorSelectorNewFunc) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -47,11 +65,17 @@ typedef void (* GimpColorSelectorFreeFunc) (gpointer selector_data);
typedef void (* GimpColorSelectorSetColorFunc) (gpointer selector_data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a);
typedef void (* GimpColorSelectorSetChannelFunc) (gpointer selector_data,
GimpColorSelectorChannelType type);
typedef void (* GimpColorSelectorFinishedCB) (gpointer finished_data);
@ -59,9 +83,11 @@ typedef struct _GimpColorSelectorMethods GimpColorSelectorMethods;
struct _GimpColorSelectorMethods
{
GimpColorSelectorNewFunc new;
GimpColorSelectorFreeFunc free;
GimpColorSelectorSetColorFunc setcolor;
GimpColorSelectorNewFunc new;
GimpColorSelectorFreeFunc free;
GimpColorSelectorSetColorFunc set_color;
GimpColorSelectorSetChannelFunc set_channel;
};
typedef gpointer GimpColorSelectorID;

View File

@ -42,10 +42,10 @@
#include "libgimp/gimpintl.h"
#define XY_DEF_WIDTH 240
#define XY_DEF_HEIGHT 240
#define XY_DEF_WIDTH 200
#define XY_DEF_HEIGHT 200
#define Z_DEF_WIDTH 15
#define Z_DEF_HEIGHT 240
#define Z_DEF_HEIGHT 200
#define COLOR_AREA_WIDTH 74
#define COLOR_AREA_HEIGHT 20
@ -82,7 +82,10 @@ typedef enum
UPDATE_CALLER = 1 << 6
} ColorSelectUpdateType;
typedef void (* ColorSelectCallback) (gint r,
typedef void (* ColorSelectCallback) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -94,15 +97,11 @@ struct _ColorSelect
{
GtkWidget *xy_color;
GtkWidget *z_color;
GtkWidget *toggles[6];
GtkObject *slider_data[6];
GtkWidget *hex_entry;
gint pos[3];
gint values[7];
gint z_color_fill;
gint xy_color_fill;
gboolean wants_updates;
GdkGC *gc;
ColorSelectCallback callback;
@ -144,28 +143,19 @@ static void color_select_update_values (ColorSelect *);
static void color_select_update_rgb_values (ColorSelect *);
static void color_select_update_hsv_values (ColorSelect *);
static void color_select_update_pos (ColorSelect *);
static void color_select_update_scales (ColorSelect *,
gint );
static gint color_select_xy_expose (GtkWidget *,
GdkEventExpose *,
ColorSelect *);
static gint color_select_xy_events (GtkWidget *,
GdkEvent *,
ColorSelect *);
static gint color_select_z_expose (GtkWidget *,
GdkEventExpose *,
ColorSelect *);
static gint color_select_z_events (GtkWidget *,
GdkEvent *,
ColorSelect *);
static void color_select_scale_update (GtkObject *,
gpointer );
static void color_select_toggle_update (GtkWidget *,
gpointer );
static gint color_select_hex_entry_events (GtkWidget *,
GdkEvent *,
gpointer );
static gint color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *eevent,
ColorSelect *color_select);
static gint color_select_xy_events (GtkWidget *widget,
GdkEvent *event,
ColorSelect *color_select);
static gint color_select_z_expose (GtkWidget *widget,
GdkEventExpose *eevent,
ColorSelect *color_select);
static gint color_select_z_events (GtkWidget *widet,
GdkEvent *event,
ColorSelect *color_select);
static void color_select_image_fill (GtkWidget *,
ColorSelectFillType,
@ -190,6 +180,9 @@ static void color_select_update_hue_value (ColorSelectFill *);
static void color_select_update_saturation_value (ColorSelectFill *);
static GtkWidget * color_select_notebook_new (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
@ -198,12 +191,20 @@ static GtkWidget * color_select_notebook_new (gint ,
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_setcolor (gpointer ,
static void color_select_notebook_set_color (gpointer ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint );
static void color_select_notebook_set_channel (gpointer ,
GimpColorSelectorChannelType channel);
static void color_select_notebook_update_callback (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
@ -244,7 +245,8 @@ color_select_init (void)
{
color_select_notebook_new,
color_select_notebook_free,
color_select_notebook_setcolor
color_select_notebook_set_color,
color_select_notebook_set_channel
};
gimp_color_selector_register ("GIMP", "built_in.html", &methods);
@ -260,49 +262,25 @@ color_select_widget_new (ColorSelect *csp,
{
GtkWidget *main_vbox;
GtkWidget *main_hbox;
GtkWidget *hbox;
GtkWidget *xy_frame;
GtkWidget *z_frame;
GtkWidget *right_vbox;
GtkWidget *table;
GtkWidget *hex_hbox;
GtkWidget *label;
GSList *group;
gchar buffer[16];
gint i;
static gchar *toggle_titles[6] =
{
N_("H"),
N_("S"),
N_("V"),
N_("R"),
N_("G"),
N_("B")
};
static gchar *slider_tips[6] =
{
N_("Hue"),
N_("Saturation"),
N_("Value"),
N_("Red"),
N_("Green"),
N_("Blue")
};
static gdouble slider_max_vals[6] = { 360, 100, 100, 255, 255, 255 };
static gdouble slider_incs[6] = { 30, 10, 10, 16, 16, 16 };
main_vbox = gtk_vbox_new (FALSE, 2);
main_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 2);
main_hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 0);
gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, TRUE, 2);
main_hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (main_vbox), main_hbox, TRUE, FALSE, 0);
gtk_widget_show (main_hbox);
hbox = gtk_hbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (main_hbox), hbox, TRUE, FALSE, 0);
gtk_widget_show (hbox);
/* The x/y component preview */
xy_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (xy_frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (main_hbox), xy_frame, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), xy_frame, FALSE, FALSE, 2);
gtk_widget_show (xy_frame);
csp->xy_color = gtk_preview_new (GTK_PREVIEW_COLOR);
@ -330,7 +308,7 @@ color_select_widget_new (ColorSelect *csp,
/* The z component preview */
z_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (z_frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (main_hbox), z_frame, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), z_frame, FALSE, FALSE, 2);
gtk_widget_show (z_frame);
csp->z_color = gtk_preview_new (GTK_PREVIEW_COLOR);
@ -346,70 +324,6 @@ color_select_widget_new (ColorSelect *csp,
gtk_container_add (GTK_CONTAINER (z_frame), csp->z_color);
gtk_widget_show (csp->z_color);
/* The right vertical box with old/new color area and color space sliders */
right_vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (right_vbox), 0);
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
/* The color space sliders, toggle buttons and entries */
table = gtk_table_new (6, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_box_pack_start (GTK_BOX (right_vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
group = NULL;
for (i = 0; i < 6; i++)
{
csp->toggles[i] =
gtk_radio_button_new_with_label (group, gettext (toggle_titles[i]));
gimp_help_set_help_data (csp->toggles[i], gettext (slider_tips[i]), NULL);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (csp->toggles[i]));
gtk_table_attach (GTK_TABLE (table), csp->toggles[i],
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (csp->toggles[i]), "toggled",
GTK_SIGNAL_FUNC (color_select_toggle_update),
csp);
gtk_widget_show (csp->toggles[i]);
csp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
csp->values[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
gettext (slider_tips[i]),
NULL);
gtk_signal_connect (GTK_OBJECT (csp->slider_data[i]), "value_changed",
GTK_SIGNAL_FUNC (color_select_scale_update),
csp);
}
/* The hex triplet entry */
hex_hbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (right_vbox), hex_hbox, FALSE, FALSE, 0);
gtk_widget_show (hex_hbox);
csp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", r, g, b);
gtk_entry_set_text (GTK_ENTRY (csp->hex_entry), buffer);
gtk_widget_set_usize (GTK_WIDGET (csp->hex_entry), 75, 0);
gtk_box_pack_end (GTK_BOX (hex_hbox), csp->hex_entry, FALSE, FALSE, 2);
gtk_signal_connect (GTK_OBJECT (csp->hex_entry), "focus_out_event",
GTK_SIGNAL_FUNC (color_select_hex_entry_events),
csp);
gtk_signal_connect (GTK_OBJECT (csp->hex_entry), "key_press_event",
GTK_SIGNAL_FUNC (color_select_hex_entry_events),
csp);
gtk_widget_show (csp->hex_entry);
label = gtk_label_new (_("Hex Triplet:"));
gtk_box_pack_end (GTK_BOX (hex_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
return main_vbox;
}
@ -432,14 +346,18 @@ color_select_drop_color (GtkWidget *widget,
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
color_select_update_scales (csp, -1);
color_select_update (csp, UPDATE_Z_COLOR);
color_select_update (csp, UPDATE_XY_COLOR);
color_select_update (csp, UPDATE_CALLER);
}
static void
color_select_set_color (ColorSelect *csp,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
@ -448,14 +366,15 @@ color_select_set_color (ColorSelect *csp,
if (!csp)
return;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s;
csp->values[COLOR_SELECT_VALUE] = v;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
color_select_update_scales (csp, -1);
color_select_update (csp, UPDATE_Z_COLOR);
color_select_update (csp, UPDATE_XY_COLOR);
@ -474,7 +393,6 @@ color_select_update (ColorSelect *csp,
if (update & UPDATE_VALUES)
{
color_select_update_values (csp);
color_select_update_scales (csp, -1);
}
if (update & UPDATE_XY_COLOR)
@ -489,16 +407,19 @@ color_select_update (ColorSelect *csp,
gtk_widget_draw (csp->z_color, NULL);
}
/*if (update & UPDATE_CALLER)*/
color_select_update_caller (csp);
if (update & UPDATE_CALLER)
color_select_update_caller (csp);
}
static void
color_select_update_caller (ColorSelect *csp)
{
if (csp && csp->wants_updates && csp->callback)
if (csp && csp->callback)
{
(* csp->callback) (csp->values[COLOR_SELECT_RED],
(* csp->callback) (csp->values[COLOR_SELECT_HUE],
csp->values[COLOR_SELECT_SATURATION],
csp->values[COLOR_SELECT_VALUE],
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE],
csp->values[COLOR_SELECT_ALPHA],
@ -740,32 +661,6 @@ color_select_update_pos (ColorSelect *csp)
}
}
static void
color_select_update_scales (ColorSelect *csp,
gint skip)
{
gchar buffer[16];
gint i;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (csp->slider_data[i]), csp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (csp->slider_data[i]),
csp->values[i]);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (csp->slider_data[i]), csp);
}
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE]);
gtk_entry_set_text (GTK_ENTRY (csp->hex_entry), buffer);
}
static gint
color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *event,
@ -814,7 +709,7 @@ color_select_xy_events (GtkWidget *widget,
NULL, NULL, bevent->time);
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_BUTTON_RELEASE:
@ -836,7 +731,7 @@ color_select_xy_events (GtkWidget *widget,
gdk_pointer_ungrab (bevent->time);
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_MOTION_NOTIFY:
@ -863,7 +758,7 @@ color_select_xy_events (GtkWidget *widget,
csp->pos[1] = 255;
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
default:
@ -914,7 +809,7 @@ color_select_z_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
case GDK_BUTTON_RELEASE:
@ -930,7 +825,7 @@ color_select_z_events (GtkWidget *widget,
gdk_pointer_ungrab (bevent->time);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES | UPDATE_XY_COLOR);
color_select_update (csp, UPDATE_VALUES | UPDATE_XY_COLOR | UPDATE_CALLER);
break;
case GDK_MOTION_NOTIFY:
@ -951,7 +846,7 @@ color_select_z_events (GtkWidget *widget,
csp->pos[2] = 255;
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
break;
default:
@ -962,94 +857,13 @@ color_select_z_events (GtkWidget *widget,
}
static void
color_select_scale_update (GtkObject *adjustment,
gpointer data)
color_select_set_channel (ColorSelect *csp,
GimpColorSelectorChannelType type)
{
ColorSelect *csp;
gint old_values[6];
gint update_z_marker;
gint update_xy_marker;
gint i, j;
csp = (ColorSelect *) data;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (csp->slider_data[i] == adjustment)
break;
for (j = 0; j < 6; j++)
old_values[j] = csp->values[j];
csp->values[i] = (int) (GTK_ADJUSTMENT (adjustment)->value);
if ((i >= COLOR_SELECT_HUE) && (i <= COLOR_SELECT_VALUE))
color_select_update_rgb_values (csp);
else if ((i >= COLOR_SELECT_RED) && (i <= COLOR_SELECT_BLUE))
color_select_update_hsv_values (csp);
color_select_update_scales (csp, i);
update_z_marker = 0;
update_xy_marker = 0;
for (j = 0; j < 6; j++)
{
if (j == csp->z_color_fill)
{
if (old_values[j] != csp->values[j])
update_z_marker = 1;
}
else
{
if (old_values[j] != csp->values[j])
update_xy_marker = 1;
}
}
if (update_z_marker)
{
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_POS | UPDATE_XY_COLOR);
color_select_draw_z_marker (csp, NULL);
}
else
{
if (update_z_marker)
color_select_draw_z_marker (csp, NULL);
if (update_xy_marker)
color_select_draw_xy_marker (csp, NULL);
color_select_update (csp, UPDATE_POS);
if (update_z_marker)
color_select_draw_z_marker (csp, NULL);
if (update_xy_marker)
color_select_draw_xy_marker (csp, NULL);
}
}
static void
color_select_toggle_update (GtkWidget *widget,
gpointer data)
{
ColorSelect *csp;
ColorSelectFillType type = COLOR_SELECT_HUE;
gint i;
if (!GTK_TOGGLE_BUTTON (widget)->active)
return;
csp = (ColorSelect *) data;
if (!csp)
return;
for (i = 0; i < 6; i++)
if (widget == csp->toggles[i])
type = (ColorSelectFillType) i;
switch (type)
switch ((ColorSelectFillType) type)
{
case COLOR_SELECT_HUE:
csp->z_color_fill = COLOR_SELECT_HUE;
@ -1083,60 +897,6 @@ color_select_toggle_update (GtkWidget *widget,
color_select_update (csp, UPDATE_Z_COLOR | UPDATE_XY_COLOR);
}
static gint
color_select_hex_entry_events (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
ColorSelect *csp;
gchar buffer[8];
gchar *hex_color;
guint hex_rgb;
csp = (ColorSelect *) data;
if (!csp)
return FALSE;
switch (event->type)
{
case GDK_KEY_PRESS:
if (((GdkEventKey *) event)->keyval != GDK_Return)
break;
/* else fall through */
case GDK_FOCUS_CHANGE:
hex_color = g_strdup (gtk_entry_get_text (GTK_ENTRY (csp->hex_entry)));
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
csp->values[COLOR_SELECT_RED],
csp->values[COLOR_SELECT_GREEN],
csp->values[COLOR_SELECT_BLUE]);
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
{
if ((sscanf (hex_color, "#%x", &hex_rgb) == 1) &&
(hex_rgb < (1 << 24)))
color_select_set_color (csp,
(hex_rgb & 0xff0000) >> 16,
(hex_rgb & 0x00ff00) >> 8,
(hex_rgb & 0x0000ff),
255);
}
g_free (hex_color);
break;
default:
/* do nothing */
break;
}
return FALSE;
}
static void
color_select_image_fill (GtkWidget *preview,
ColorSelectFillType type,
@ -1149,8 +909,8 @@ color_select_image_fill (GtkWidget *preview,
csf.update = update_procs[type];
csf.y = -1;
csf.width = preview->requisition.width;
csf.y = -1;
csf.width = preview->requisition.width;
csf.height = preview->requisition.height;
csf.values = values;
@ -1182,7 +942,7 @@ color_select_draw_z_marker (ColorSelect *csp,
return;
y = (Z_DEF_HEIGHT - 1) - ((Z_DEF_HEIGHT - 1) * csp->pos[2]) / 255;
width = csp->z_color->requisition.width;
width = csp->z_color->requisition.width;
height = csp->z_color->requisition.height;
minx = 0;
miny = 0;
@ -1724,7 +1484,7 @@ color_select_update_saturation_value (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
s = (float) csf->y / csf->height;
s = (gfloat) csf->y / csf->height;
if (s < 0)
s = 0;
@ -1733,16 +1493,16 @@ color_select_update_saturation_value (ColorSelectFill *csf)
s = 1 - s;
h = (float) csf->values[COLOR_SELECT_HUE];
h = (gfloat) csf->values[COLOR_SELECT_HUE];
if (h >= 360)
h -= 360;
h /= 60;
f = (h - (int) h) * 255;
f = (h - (gint) h) * 255;
v = 0;
dv = 1.0 / csf->width;
switch ((int) h)
switch ((gint) h)
{
case 0:
for (i = 0; i < csf->width; i++)
@ -1820,7 +1580,10 @@ typedef struct
} notebook_glue;
static GtkWidget *
color_select_notebook_new (gint r,
color_select_notebook_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -1846,13 +1609,15 @@ color_select_notebook_new (gint r,
csp->z_color_fill = COLOR_SELECT_HUE;
csp->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
csp->gc = NULL;
csp->wants_updates = TRUE;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_hsv_values (csp);
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s;
csp->values[COLOR_SELECT_VALUE] = v;
csp->values[COLOR_SELECT_RED] = r;
csp->values[COLOR_SELECT_GREEN] = g;
csp->values[COLOR_SELECT_BLUE] = b;
csp->values[COLOR_SELECT_ALPHA] = a;
color_select_update_pos (csp);
glue->main_vbox = color_select_widget_new (csp, r, g, b, a);
@ -1882,19 +1647,34 @@ color_select_notebook_free (gpointer data)
static void
color_select_notebook_setcolor (gpointer data,
gint r,
gint g,
gint b,
gint a)
color_select_notebook_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
{
notebook_glue *glue = data;
color_select_set_color (glue->csp, r, g, b, a);
color_select_set_color (glue->csp, h, s, v, r, g, b, a);
}
static void
color_select_notebook_update_callback (gint r,
color_select_notebook_set_channel (gpointer data,
GimpColorSelectorChannelType channel)
{
notebook_glue *glue = data;
color_select_set_channel (glue->csp, channel);
}
static void
color_select_notebook_update_callback (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -1902,5 +1682,5 @@ color_select_notebook_update_callback (gint r,
{
notebook_glue *glue = data;
glue->callback (glue->client_data, r, g, b, a);
glue->callback (glue->client_data, h, s, v, r, g, b, a);
}

View File

@ -27,28 +27,38 @@
#include "gimpmodregister.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpcolor.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpintl.h"
/* prototypes */
static GtkWidget * colorsel_gtk_new (gint r,
gint g,
gint b,
gint a,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer data,
gpointer *selector_data);
static void colorsel_gtk_free (gpointer data);
static void colorsel_gtk_setcolor (gpointer data,
gint r,
gint g,
gint b,
gint a);
static void colorsel_gtk_update (GtkWidget *widget,
gpointer data);
static GtkWidget * colorsel_gtk_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer data,
gpointer *selector_data);
static void colorsel_gtk_free (gpointer data);
static void colorsel_gtk_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a);
static void colorsel_gtk_set_channel (gpointer data,
GimpColorSelectorChannelType channel);
static void colorsel_gtk_update (GtkWidget *widget,
gpointer data);
/* EEK */
static gboolean colorsel_gtk_widget_idle_hide (gpointer data);
@ -61,7 +71,8 @@ static GimpColorSelectorMethods methods =
{
colorsel_gtk_new,
colorsel_gtk_free,
colorsel_gtk_setcolor
colorsel_gtk_set_color,
colorsel_gtk_set_channel
};
static GimpModuleInfo info =
@ -125,7 +136,10 @@ typedef struct
static GtkWidget *
colorsel_gtk_new (gint r,
colorsel_gtk_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -148,11 +162,9 @@ colorsel_gtk_new (gint r,
gtk_color_selection_set_opacity (GTK_COLOR_SELECTION (p->selector),
show_alpha);
/*
gtk_widget_hide (GTK_COLOR_SELECTION (p->selector)->sample_area->parent);
*/
gtk_widget_hide (GTK_COLOR_SELECTION (p->selector)->scales[0]->parent);
colorsel_gtk_setcolor (p, r, g, b, a);
colorsel_gtk_set_color (p, h, s, v, r, g, b, a);
/* EEK: to be removed */
gtk_signal_connect_object_after
@ -190,11 +202,14 @@ colorsel_gtk_free (gpointer data)
}
static void
colorsel_gtk_setcolor (gpointer data,
gint r,
gint g,
gint b,
gint a)
colorsel_gtk_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
{
ColorselGtk *p = data;
@ -208,11 +223,20 @@ colorsel_gtk_setcolor (gpointer data,
gtk_color_selection_set_color (GTK_COLOR_SELECTION (p->selector), color);
}
static void
colorsel_gtk_set_channel (gpointer data,
GimpColorSelectorChannelType channel)
{
}
static void
colorsel_gtk_update (GtkWidget *widget,
gpointer data)
{
ColorselGtk *p = data;
gint h;
gint s;
gint v;
gint r;
gint g;
gint b;
@ -226,7 +250,13 @@ colorsel_gtk_update (GtkWidget *widget,
b = (gint) (color[2] * 255.999);
a = (gint) (color[3] * 255.999);
p->callback (p->client_data, r, g, b, a);
gimp_rgb_to_hsv_double (&color[0], &color[1], &color[2]);
h = (gint) (color[0] * 360.999);
s = (gint) (color[1] * 255.999);
v = (gint) (color[2] * 255.999);
p->callback (p->client_data, h, v, s, r, g, b, a);
}
/* EEK */

View File

@ -37,7 +37,10 @@
/* prototypes */
static GtkWidget * colorsel_triangle_new (gint red,
static GtkWidget * colorsel_triangle_new (gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha,
@ -48,11 +51,16 @@ static GtkWidget * colorsel_triangle_new (gint red,
static void colorsel_triangle_free (gpointer selector_data);
static void colorsel_triangle_setcolor (gpointer selector_data,
static void colorsel_triangle_set_color (gpointer selector_data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha);
static void colorsel_triangle_set_channel (gpointer selector_data,
GimpColorSelectorChannelType channel);
/* local methods */
@ -60,7 +68,8 @@ static GimpColorSelectorMethods methods =
{
colorsel_triangle_new,
colorsel_triangle_free,
colorsel_triangle_setcolor
colorsel_triangle_set_color,
colorsel_triangle_set_channel
};
@ -123,7 +132,9 @@ static void color_select_update_rgb_values (ColorSelect *coldata);
static void update_previews (ColorSelect *coldata,
gboolean hue_changed);
/*
static void color_select_update_hsv_values (ColorSelect *coldata);
*/
/*************************************************************/
@ -168,7 +179,10 @@ module_unload (gpointer shutdown_data,
/* methods */
static GtkWidget *
colorsel_triangle_new (gint red,
colorsel_triangle_new (gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha,
@ -185,12 +199,13 @@ colorsel_triangle_new (gint red,
GtkWidget *vbox;
coldata = g_new (ColorSelect, 1);
coldata->values[RED] = red;
coldata->values[GREEN] = green;
coldata->values[BLUE] = blue;
coldata->values[ALPHA] = alpha;
color_select_update_hsv_values (coldata);
coldata->values[HUE] = hue;
coldata->values[SATURATION] = saturation;
coldata->values[VALUE] = value;
coldata->values[RED] = red;
coldata->values[GREEN] = green;
coldata->values[BLUE] = blue;
coldata->values[ALPHA] = alpha;
coldata->oldsat = 0;
coldata->oldval = 0;
@ -227,26 +242,36 @@ colorsel_triangle_free (gpointer selector_data)
}
static void
colorsel_triangle_setcolor (gpointer selector_data,
gint red,
gint green,
gint blue,
gint alpha)
colorsel_triangle_set_color (gpointer selector_data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha)
{
ColorSelect *coldata;
coldata = selector_data;
coldata->values[RED] = red;
coldata->values[GREEN] = green;
coldata->values[BLUE] = blue;
coldata->values[ALPHA] = alpha;
color_select_update_hsv_values (coldata);
coldata->values[HUE] = hue;
coldata->values[SATURATION] = saturation;
coldata->values[VALUE] = value;
coldata->values[RED] = red;
coldata->values[GREEN] = green;
coldata->values[BLUE] = blue;
coldata->values[ALPHA] = alpha;
update_previews (coldata, TRUE);
}
static void
colorsel_triangle_set_channel (gpointer selector_data,
GimpColorSelectorChannelType channel)
{
}
/*************************************************************/
/* helper functions */
@ -262,14 +287,15 @@ color_select_update_rgb_values (ColorSelect *csp)
&(csp->values[BLUE]));
}
/*
static void
color_select_update_hsv_values (ColorSelect *csp)
{
gdouble hue, sat, val;
hue = (gdouble) csp->values[RED] / 255;
hue = (gdouble) csp->values[RED] / 255;
sat = (gdouble) csp->values[GREEN] / 255;
val = (gdouble) csp->values[BLUE] / 255;
val = (gdouble) csp->values[BLUE] / 255;
gimp_rgb_to_hsv_double (&hue, &sat, &val);
@ -277,7 +303,7 @@ color_select_update_hsv_values (ColorSelect *csp)
csp->values[SATURATION] = RINT (sat * 100);
csp->values[VALUE] = RINT (val * 100);
}
*/
static void
update_previews (ColorSelect *coldata,
@ -492,11 +518,14 @@ color_selection_callback (GtkWidget *widget,
gtk_grab_remove (widget);
/* callback the user */
(*coldata->callback) (coldata->data,
coldata->values[RED],
coldata->values[GREEN],
coldata->values[BLUE],
coldata->values[ALPHA]);
(* coldata->callback) (coldata->data,
coldata->values[HUE],
coldata->values[SATURATION],
coldata->values[VALUE],
coldata->values[RED],
coldata->values[GREEN],
coldata->values[BLUE],
coldata->values[ALPHA]);
return FALSE;
break;
@ -580,11 +609,14 @@ color_selection_callback (GtkWidget *widget,
}
/* callback the user */
(*coldata->callback) (coldata->data,
coldata->values[RED],
coldata->values[GREEN],
coldata->values[BLUE],
coldata->values[ALPHA]);
(* coldata->callback) (coldata->data,
coldata->values[HUE],
coldata->values[SATURATION],
coldata->values[VALUE],
coldata->values[RED],
coldata->values[GREEN],
coldata->values[BLUE],
coldata->values[ALPHA]);
return FALSE;
}

View File

@ -26,6 +26,8 @@
#include <gtk/gtk.h>
#include <libgimp/gimpcolorselector.h>
#include <libgimp/gimpcolor.h>
#include <libgimp/gimpcolorspace.h>
#include <libgimp/gimpmodule.h>
#include <libgimp/gimpmath.h>
@ -34,7 +36,10 @@
#include <libgimp/gimpintl.h>
/* prototypes */
static GtkWidget * colorsel_water_new (gint r,
static GtkWidget * colorsel_water_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -43,11 +48,16 @@ static GtkWidget * colorsel_water_new (gint r,
gpointer,
gpointer *);
static void colorsel_water_free (gpointer data);
static void colorsel_water_setcolor (gpointer data,
static void colorsel_water_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a);
static void colorsel_water_set_channel (gpointer data,
GimpColorSelectorChannelType channel);
static void colorsel_water_update (void);
static void colorsel_water_drag_begin (GtkWidget *widget,
GdkDragContext *context,
@ -75,7 +85,8 @@ static GimpColorSelectorMethods methods =
{
colorsel_water_new,
colorsel_water_free,
colorsel_water_setcolor
colorsel_water_set_color,
colorsel_water_set_channel
};
@ -548,12 +559,15 @@ pressure_adjust_update (GtkAdjustment *adj,
}
/*************************************************************/
/***********/
/* methods */
static GtkWidget*
colorsel_water_new (gint r,
colorsel_water_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
@ -729,7 +743,7 @@ colorsel_water_new (gint r,
gtk_preview_size (GTK_PREVIEW (color_preview[i+1]),
BUCKET_SIZE, BUCKET_SIZE);
gtk_container_add (GTK_CONTAINER (button), color_preview[i+1]);
set_bucket (i+1, 1.0, 1.0, 1.0, 1.0);
set_bucket (i + 1, 1.0, 1.0, 1.0, 1.0);
}
hbox2 = gtk_hbox_new (FALSE, 0);
@ -745,8 +759,8 @@ colorsel_water_new (gint r,
gtk_box_pack_start (GTK_BOX (vbox2), scale, TRUE, TRUE, 0);
gtk_widget_show_all (hbox);
colorsel_water_setcolor (coldata, r, g, b, a);
colorsel_water_set_color (coldata, h, s, v, r, g, b, a);
draw_all_buckets ();
return vbox;
@ -760,11 +774,14 @@ colorsel_water_free (gpointer selector_data)
}
static void
colorsel_water_setcolor (gpointer data,
gint r,
gint g,
gint b,
gint a)
colorsel_water_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
{
set_bucket (0,
((gdouble) r) / 255.999,
@ -775,9 +792,22 @@ colorsel_water_setcolor (gpointer data,
draw_bucket (0);
}
static void
colorsel_water_set_channel (gpointer data,
GimpColorSelectorChannelType channel)
{
}
static void
colorsel_water_update (void)
{
gdouble rr;
gdouble gg;
gdouble bb;
gint h;
gint s;
gint v;
gint r;
gint g;
gint b;
@ -788,9 +818,19 @@ colorsel_water_update (void)
b = (gint) (bucket[0][2] * 255.999);
a = (gint) (bucket[0][3] * 255.999);
rr = bucket[0][0];
gg = bucket[0][1];
bb = bucket[0][2];
gimp_rgb_to_hsv_double (&rr, &gg, &bb);
h = (gint) (rr * 360.99);
s = (gint) (gg * 255.99);
v = (gint) (bb * 255.99);
draw_bucket (0);
coldata->callback (coldata->data, r, g, b, a);
coldata->callback (coldata->data, h, s, v, r, g, b, a);
}
static void