app/color_notebook.[ch] app/color_select.c libgimp/gimpcolorselector.h

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

	* app/color_notebook.[ch]
	* app/color_select.c
	* libgimp/gimpcolorselector.h
	* modules/colorsel_gtk.c
	* modules/colorsel_triangle.c
	* modules/colorsel_water.c: use GimpRGB and GimpHSV.

	* libgimp/gimpcolor.c
	* libgimp/gimpcolorspace.[ch]: All rgb_to_hsv functions:

	if r == g == b the difference between the max and min value
	is 0 and we should avoid to divide by it ;-)
This commit is contained in:
Michael Natterer 2001-01-15 12:20:38 +00:00 committed by Michael Natterer
parent 4c1f53a979
commit 368d0efe9b
19 changed files with 1309 additions and 2088 deletions

View File

@ -1,3 +1,18 @@
2001-01-15 Michael Natterer <mitch@gimp.org>
* app/color_notebook.[ch]
* app/color_select.c
* libgimp/gimpcolorselector.h
* modules/colorsel_gtk.c
* modules/colorsel_triangle.c
* modules/colorsel_water.c: use GimpRGB and GimpHSV.
* libgimp/gimpcolor.c
* libgimp/gimpcolorspace.[ch]: All rgb_to_hsv functions:
if r == g == b the difference between the max and min value
is 0 and we should avoid to divide by it ;-)
2001-01-15 Sven Neumann <sven@gimp.org>
* plug-ins/gdyntext/gdyntext.[ch]

View File

@ -72,9 +72,10 @@ struct _ColorNotebook
GdkGC *gc;
gint values[7];
GimpHSV hsv;
GimpRGB rgb;
gint orig_values[4];
GimpRGB orig_rgb;
GimpColorSelectorChannelType active_channel;
@ -121,13 +122,8 @@ 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,
gint alpha);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
@ -203,8 +199,6 @@ color_notebook_new (GimpRGB *color,
ColorSelectorInstance *csel;
gint i;
guchar red, green, blue, alpha;
static gchar *toggle_titles[] =
{
N_("H"),
@ -225,14 +219,13 @@ color_notebook_new (GimpRGB *color,
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 };
static gdouble slider_initial_vals[] = { 0, 0, 0, 0, 0, 0, 0 };
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
g_return_val_if_fail (selector_info != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &alpha);
cnp = g_new0 (ColorNotebook, 1);
cnp->gc = NULL;
@ -244,10 +237,8 @@ color_notebook_new (GimpRGB *color,
cnp->selectors = NULL;
cnp->cur_page = NULL;
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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
@ -295,13 +286,8 @@ color_notebook_new (GimpRGB *color,
csel->info = info;
info->refs++;
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],
info->methods.new (&cnp->hsv,
&cnp->rgb,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
@ -418,6 +404,7 @@ color_notebook_new (GimpRGB *color,
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_widget_show (label);
}
else
{
@ -438,7 +425,7 @@ color_notebook_new (GimpRGB *color,
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
slider_initial_vals[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
@ -455,7 +442,10 @@ color_notebook_new (GimpRGB *color,
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
(gint) (color->r * 255.999),
(gint) (color->g * 255.999),
(gint) (color->b * 255.999));
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);
@ -471,6 +461,8 @@ color_notebook_new (GimpRGB *color,
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
color_notebook_update_scales (cnp, -1);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -537,19 +529,14 @@ void
color_notebook_set_color (ColorNotebook *cnp,
GimpRGB *color)
{
guchar red, green, blue, alpha;
g_return_if_fail (cnp != NULL);
g_return_if_fail (color != NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -561,30 +548,22 @@ color_notebook_set_color (ColorNotebook *cnp,
* Called by a color selector on user selection of a color
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha)
color_notebook_update_callback (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelectorInstance *csel;
ColorNotebook *cnp;
g_return_if_fail (data != NULL);
g_return_if_fail (hsv != NULL);
g_return_if_fail (rgb != NULL);
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
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;
cnp->hsv = *hsv;
cnp->rgb = *rgb;
color_notebook_update_scales (cnp, -1);
@ -598,19 +577,12 @@ color_notebook_ok_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -621,19 +593,12 @@ color_notebook_cancel_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->orig_rgb,
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -800,13 +765,8 @@ color_notebook_update_notebook (ColorNotebook *cnp)
csel = cnp->cur_page;
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]);
&cnp->hsv,
&cnp->rgb);
}
static void
@ -824,17 +784,9 @@ color_notebook_update_channel (ColorNotebook *cnp)
static void
color_notebook_update_caller (ColorNotebook *cnp)
{
GimpRGB color;
gimp_rgba_set (&color,
cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] / 255.0);
if (cnp && cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -846,7 +798,7 @@ color_notebook_update_colors (ColorNotebook *cnp,
{
GdkWindow *window;
GdkColor color;
gint red, green, blue;
guchar red, green, blue;
gint width, height;
if (!cnp)
@ -855,16 +807,14 @@ color_notebook_update_colors (ColorNotebook *cnp,
if (which == UPDATE_ORIG_COLOR)
{
window = cnp->orig_color->window;
red = cnp->orig_values[0];
green = cnp->orig_values[1];
blue = cnp->orig_values[2];
gimp_rgb_get_uchar (&cnp->orig_rgb, &red, &green, &blue);
}
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
gimp_rgb_get_uchar (&cnp->rgb, &red, &green, &blue);
}
else
{
@ -892,64 +842,55 @@ color_notebook_update_colors (ColorNotebook *cnp,
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
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;
gimp_hsv_to_rgb (&cnp->hsv, &cnp->rgb);
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
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;
gimp_rgb_to_hsv (&cnp->rgb, &cnp->hsv);
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gint values[7];
gchar buffer[16];
gint i;
if (!cnp)
if (! cnp)
return;
values[GIMP_COLOR_SELECTOR_HUE] = (gint) (cnp->hsv.h * 360.999);
values[GIMP_COLOR_SELECTOR_SATURATION] = (gint) (cnp->hsv.s * 100.999);
values[GIMP_COLOR_SELECTOR_VALUE] = (gint) (cnp->hsv.v * 100.999);
values[GIMP_COLOR_SELECTOR_RED] = (gint) (cnp->rgb.r * 255.999);
values[GIMP_COLOR_SELECTOR_GREEN] = (gint) (cnp->rgb.g * 255.999);
values[GIMP_COLOR_SELECTOR_BLUE] = (gint) (cnp->rgb.b * 255.999);
values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) (cnp->rgb.a * 100.999);
for (i = 0; i < (cnp->show_alpha ? 7 : 6); i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
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);
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]);
values[GIMP_COLOR_SELECTOR_RED],
values[GIMP_COLOR_SELECTOR_GREEN],
values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
@ -964,7 +905,7 @@ color_notebook_color_events (GtkWidget *widget,
cnp = (ColorNotebook *) data;
if (!cnp)
if (! cnp)
return FALSE;
switch (event->type)
@ -1024,7 +965,36 @@ color_notebook_scale_update (GtkAdjustment *adjustment,
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
switch (i)
{
case GIMP_COLOR_SELECTOR_HUE:
cnp->hsv.h = GTK_ADJUSTMENT (adjustment)->value / 360.0;
break;
case GIMP_COLOR_SELECTOR_SATURATION:
cnp->hsv.s = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_VALUE:
cnp->hsv.v = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_RED:
cnp->rgb.r = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_GREEN:
cnp->rgb.g = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_BLUE:
cnp->rgb.b = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_ALPHA:
cnp->hsv.a = cnp->rgb.a = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
}
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
@ -1069,9 +1039,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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]);
(gint) (cnp->rgb.r * 255.999),
(gint) (cnp->rgb.g * 255.999),
(gint) (cnp->rgb.b * 255.999));
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
@ -1079,9 +1049,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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);
cnp->rgb.r = ((hex_rgb & 0xff0000) >> 16) / 255.0;
cnp->rgb.g = ((hex_rgb & 0x00ff00) >> 8) / 255.0;
cnp->rgb.b = ((hex_rgb & 0x0000ff)) / 255.0;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1114,11 +1084,7 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
*color = cnp->rgb;
}
static void
@ -1127,16 +1093,10 @@ color_notebook_drop_new_color (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
guchar r, g, b, a;
cnp = (ColorNotebook *) data;
gimp_rgba_get_uchar (color, &r, &g, &b, &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;
cnp->rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1156,9 +1116,5 @@ color_notebook_drag_old_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
*color = cnp->orig_rgb;
}

View File

@ -33,6 +33,7 @@ typedef void (* ColorNotebookCallback) (GimpRGB *color,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
ColorNotebook * color_notebook_new (GimpRGB *color,
ColorNotebookCallback callback,
gpointer data,

View File

@ -36,6 +36,7 @@
#include "session.h"
#include "color_area.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimphelpui.h"
@ -82,14 +83,9 @@ typedef enum
UPDATE_CALLER = 1 << 6
} ColorSelectUpdateType;
typedef void (* ColorSelectCallback) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gpointer data);
typedef void (* ColorSelectCallback) (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer data);
typedef struct _ColorSelect ColorSelect;
@ -98,11 +94,14 @@ struct _ColorSelect
GtkWidget *xy_color;
GtkWidget *z_color;
gint pos[3];
gint values[7];
gint z_color_fill;
gint xy_color_fill;
GdkGC *gc;
gint pos[3];
GimpHSV hsv;
GimpRGB rgb;
gint z_color_fill;
gint xy_color_fill;
GdkGC *gc;
ColorSelectCallback callback;
gpointer client_data;
@ -114,32 +113,30 @@ typedef void (* ColorSelectFillUpdateProc) (ColorSelectFill *color_select_fill);
struct _ColorSelectFill
{
guchar *buffer;
gint y;
gint width;
gint height;
gint *values;
guchar *buffer;
gint y;
gint width;
gint height;
GimpHSV hsv;
GimpRGB rgb;
ColorSelectFillUpdateProc update;
};
static GtkWidget * color_select_widget_new (ColorSelect *,
gint ,
gint ,
gint ,
gint );
static GtkWidget * color_select_widget_new (ColorSelect *csp,
const GimpRGB *color);
static void color_select_drop_color (GtkWidget *widget,
GimpRGB *color,
gpointer data);
static void color_select_update (ColorSelect *,
static void color_select_drop_color (GtkWidget *widget,
GimpRGB *color,
gpointer data);
static void color_select_update (ColorSelect *csp,
ColorSelectUpdateType);
static void color_select_update_caller (ColorSelect *);
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_caller (ColorSelect *csp);
static void color_select_update_values (ColorSelect *csp);
static void color_select_update_rgb_values (ColorSelect *csp);
static void color_select_update_hsv_values (ColorSelect *csp);
static void color_select_update_pos (ColorSelect *csp);
static gint color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *eevent,
@ -156,56 +153,42 @@ static gint color_select_z_events (GtkWidget *widet,
static void color_select_image_fill (GtkWidget *,
ColorSelectFillType,
gint *);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_select_draw_z_marker (ColorSelect *,
static void color_select_draw_z_marker (ColorSelect *csp,
GdkRectangle *);
static void color_select_draw_xy_marker (ColorSelect *,
static void color_select_draw_xy_marker (ColorSelect *csp,
GdkRectangle *);
static void color_select_update_red (ColorSelectFill *);
static void color_select_update_green (ColorSelectFill *);
static void color_select_update_blue (ColorSelectFill *);
static void color_select_update_hue (ColorSelectFill *);
static void color_select_update_saturation (ColorSelectFill *);
static void color_select_update_value (ColorSelectFill *);
static void color_select_update_red_green (ColorSelectFill *);
static void color_select_update_red_blue (ColorSelectFill *);
static void color_select_update_green_blue (ColorSelectFill *);
static void color_select_update_hue_saturation (ColorSelectFill *);
static void color_select_update_hue_value (ColorSelectFill *);
static void color_select_update_saturation_value (ColorSelectFill *);
static void color_select_update_red (ColorSelectFill *csf);
static void color_select_update_green (ColorSelectFill *csf);
static void color_select_update_blue (ColorSelectFill *csf);
static void color_select_update_hue (ColorSelectFill *csf);
static void color_select_update_saturation (ColorSelectFill *csf);
static void color_select_update_value (ColorSelectFill *csf);
static void color_select_update_red_green (ColorSelectFill *csf);
static void color_select_update_red_blue (ColorSelectFill *csf);
static void color_select_update_green_blue (ColorSelectFill *csf);
static void color_select_update_hue_saturation (ColorSelectFill *csf);
static void color_select_update_hue_value (ColorSelectFill *csf);
static void color_select_update_saturation_value (ColorSelectFill *csf);
static GtkWidget * color_select_notebook_new (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gboolean ,
static GtkWidget * color_select_notebook_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback,
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_set_color (gpointer ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint );
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_set_color (gpointer ,
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_select_notebook_set_channel (gpointer ,
GimpColorSelectorChannelType channel);
static void color_select_notebook_update_callback (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gpointer );
static void color_select_notebook_update_callback (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer );
/* Static variables */
static ColorSelectFillUpdateProc update_procs[] =
@ -251,11 +234,8 @@ color_select_init (void)
static GtkWidget *
color_select_widget_new (ColorSelect *csp,
gint r,
gint g,
gint b,
gint a)
color_select_widget_new (ColorSelect *csp,
const GimpRGB *color)
{
GtkWidget *main_vbox;
GtkWidget *main_hbox;
@ -330,16 +310,10 @@ color_select_drop_color (GtkWidget *widget,
gpointer data)
{
ColorSelect *csp;
guchar r, g, b, a;
csp = (ColorSelect *) data;
gimp_rgba_get_uchar (color, &r, &g, &b, &a);
csp->values[COLOR_SELECT_RED] = (gint) r;
csp->values[COLOR_SELECT_GREEN] = (gint) g;
csp->values[COLOR_SELECT_BLUE] = (gint) b;
csp->values[COLOR_SELECT_ALPHA] = (gint) a;
csp->rgb = *color;
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
@ -351,25 +325,15 @@ color_select_drop_color (GtkWidget *widget,
}
static void
color_select_set_color (ColorSelect *csp,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
color_select_set_color (ColorSelect *csp,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
if (!csp)
if (! csp)
return;
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;
csp->hsv = *hsv;
csp->rgb = *rgb;
color_select_update_pos (csp);
@ -394,13 +358,15 @@ color_select_update (ColorSelect *csp,
if (update & UPDATE_XY_COLOR)
{
color_select_image_fill (csp->xy_color, csp->xy_color_fill, csp->values);
color_select_image_fill (csp->xy_color, csp->xy_color_fill,
&csp->hsv, &csp->rgb);
gtk_widget_draw (csp->xy_color, NULL);
}
if (update & UPDATE_Z_COLOR)
{
color_select_image_fill (csp->z_color, csp->z_color_fill, csp->values);
color_select_image_fill (csp->z_color, csp->z_color_fill,
&csp->hsv, &csp->rgb);
gtk_widget_draw (csp->z_color, NULL);
}
@ -413,13 +379,8 @@ color_select_update_caller (ColorSelect *csp)
{
if (csp && csp->callback)
{
(* 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],
(* csp->callback) (&csp->hsv,
&csp->rgb,
csp->client_data);
}
}
@ -433,34 +394,35 @@ color_select_update_values (ColorSelect *csp)
switch (csp->z_color_fill)
{
case COLOR_SELECT_RED:
csp->values[COLOR_SELECT_BLUE] = csp->pos[0];
csp->values[COLOR_SELECT_GREEN] = csp->pos[1];
csp->values[COLOR_SELECT_RED] = csp->pos[2];
csp->rgb.b = csp->pos[0] / 255.0;
csp->rgb.g = csp->pos[1] / 255.0;
csp->rgb.r = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_GREEN:
csp->values[COLOR_SELECT_BLUE] = csp->pos[0];
csp->values[COLOR_SELECT_RED] = csp->pos[1];
csp->values[COLOR_SELECT_GREEN] = csp->pos[2];
csp->rgb.b = csp->pos[0] / 255.0;
csp->rgb.r = csp->pos[1] / 255.0;
csp->rgb.g = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_BLUE:
csp->values[COLOR_SELECT_GREEN] = csp->pos[0];
csp->values[COLOR_SELECT_RED] = csp->pos[1];
csp->values[COLOR_SELECT_BLUE] = csp->pos[2];
csp->rgb.g = csp->pos[0] / 255.0;
csp->rgb.r = csp->pos[1] / 255.0;
csp->rgb.b = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_HUE:
csp->values[COLOR_SELECT_VALUE] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_SATURATION] = csp->pos[1] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[2] * 360 / 255;
csp->hsv.v = csp->pos[0] / 255.0;
csp->hsv.s = csp->pos[1] / 255.0;
csp->hsv.h = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_SATURATION:
csp->values[COLOR_SELECT_VALUE] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[1] * 360 / 255;
csp->values[COLOR_SELECT_SATURATION] = csp->pos[2] * 100 / 255;
csp->hsv.v = csp->pos[0] / 255.0;
csp->hsv.h = csp->pos[1] / 255.0;
csp->hsv.s = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_VALUE:
csp->values[COLOR_SELECT_SATURATION] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[1] * 360 / 255;
csp->values[COLOR_SELECT_VALUE] = csp->pos[2] * 100 / 255;
csp->hsv.s = csp->pos[0] / 255.0;
csp->hsv.h = csp->pos[1] / 255.0;
csp->hsv.v = csp->pos[2] / 255.0;
break;
}
@ -471,6 +433,7 @@ color_select_update_values (ColorSelect *csp)
case COLOR_SELECT_BLUE:
color_select_update_hsv_values (csp);
break;
case COLOR_SELECT_HUE:
case COLOR_SELECT_SATURATION:
case COLOR_SELECT_VALUE:
@ -482,178 +445,59 @@ color_select_update_values (ColorSelect *csp)
static void
color_select_update_rgb_values (ColorSelect *csp)
{
gfloat h, s, v;
gfloat f, p, q, t;
if (!csp)
if (! csp)
return;
h = csp->values[COLOR_SELECT_HUE];
s = csp->values[COLOR_SELECT_SATURATION] / 100.0;
v = csp->values[COLOR_SELECT_VALUE] / 100.0;
if (s == 0)
{
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
}
else
{
if (h == 360)
h = 0;
h /= 60;
f = h - (int) h;
p = v * (1 - s);
q = v * (1 - (s * f));
t = v * (1 - (s * (1 - f)));
switch ((gint) h)
{
case 0:
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = t * 255;
csp->values[COLOR_SELECT_BLUE] = p * 255;
break;
case 1:
csp->values[COLOR_SELECT_RED] = q * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = p * 255;
break;
case 2:
csp->values[COLOR_SELECT_RED] = p * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = t * 255;
break;
case 3:
csp->values[COLOR_SELECT_RED] = p * 255;
csp->values[COLOR_SELECT_GREEN] = q * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
break;
case 4:
csp->values[COLOR_SELECT_RED] = t * 255;
csp->values[COLOR_SELECT_GREEN] = p * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
break;
case 5:
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = p * 255;
csp->values[COLOR_SELECT_BLUE] = q * 255;
break;
}
}
gimp_hsv_to_rgb (&csp->hsv, &csp->rgb);
}
static void
color_select_update_hsv_values (ColorSelect *csp)
{
gint r, g, b;
gfloat h, s, v;
gint min, max;
gint delta;
if (!csp)
if (! csp)
return;
r = csp->values[COLOR_SELECT_RED];
g = csp->values[COLOR_SELECT_GREEN];
b = csp->values[COLOR_SELECT_BLUE];
if (r > g)
{
if (r > b)
max = r;
else
max = b;
if (g < b)
min = g;
else
min = b;
}
else
{
if (g > b)
max = g;
else
max = b;
if (r < b)
min = r;
else
min = b;
}
v = max;
if (max != 0)
s = (max - min) / (float) max;
else
s = 0;
if (s == 0)
{
h = 0;
}
else
{
h = 0;
delta = max - min;
if (r == max)
h = (g - b) / (float) delta;
else if (g == max)
h = 2 + (b - r) / (float) delta;
else if (b == max)
h = 4 + (r - g) / (float) delta;
h *= 60;
if (h < 0)
h += 360;
}
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s * 100;
csp->values[COLOR_SELECT_VALUE] = v * 100 / 255;
gimp_rgb_to_hsv (&csp->rgb, &csp->hsv);
}
static void
color_select_update_pos (ColorSelect *csp)
{
if (!csp)
if (! csp)
return;
switch (csp->z_color_fill)
{
case COLOR_SELECT_RED:
csp->pos[0] = csp->values[COLOR_SELECT_BLUE];
csp->pos[1] = csp->values[COLOR_SELECT_GREEN];
csp->pos[2] = csp->values[COLOR_SELECT_RED];
csp->pos[0] = (gint) (csp->rgb.b * 255.999);
csp->pos[1] = (gint) (csp->rgb.g * 255.999);
csp->pos[2] = (gint) (csp->rgb.r * 255.999);
break;
case COLOR_SELECT_GREEN:
csp->pos[0] = csp->values[COLOR_SELECT_BLUE];
csp->pos[1] = csp->values[COLOR_SELECT_RED];
csp->pos[2] = csp->values[COLOR_SELECT_GREEN];
csp->pos[0] = (gint) (csp->rgb.b * 255.999);
csp->pos[1] = (gint) (csp->rgb.r * 255.999);
csp->pos[2] = (gint) (csp->rgb.g * 255.999);
break;
case COLOR_SELECT_BLUE:
csp->pos[0] = csp->values[COLOR_SELECT_GREEN];
csp->pos[1] = csp->values[COLOR_SELECT_RED];
csp->pos[2] = csp->values[COLOR_SELECT_BLUE];
csp->pos[0] = (gint) (csp->rgb.g * 255.999);
csp->pos[1] = (gint) (csp->rgb.r * 255.999);
csp->pos[2] = (gint) (csp->rgb.b * 255.999);
break;
case COLOR_SELECT_HUE:
csp->pos[0] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[2] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[0] = (gint) (csp->hsv.v * 255.999);
csp->pos[1] = (gint) (csp->hsv.s * 255.999);
csp->pos[2] = (gint) (csp->hsv.h * 255.999);
break;
case COLOR_SELECT_SATURATION:
csp->pos[0] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[2] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[0] = (gint) (csp->hsv.v * 255.999);
csp->pos[1] = (gint) (csp->hsv.h * 255.999);
csp->pos[2] = (gint) (csp->hsv.s * 255.999);
break;
case COLOR_SELECT_VALUE:
csp->pos[0] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[2] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[0] = (gint) (csp->hsv.s * 255.999);
csp->pos[1] = (gint) (csp->hsv.h * 255.999);
csp->pos[2] = (gint) (csp->hsv.v * 255.999);
break;
}
}
@ -663,7 +507,7 @@ color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *event,
ColorSelect *csp)
{
if (!csp->gc)
if (! csp->gc)
csp->gc = gdk_gc_new (widget->window);
color_select_draw_xy_marker (csp, &event->area);
@ -701,7 +545,7 @@ color_select_xy_events (GtkWidget *widget,
gdk_pointer_grab (csp->xy_color->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
color_select_draw_xy_marker (csp, NULL);
@ -795,10 +639,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (bevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
gdk_pointer_grab (csp->z_color->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
@ -815,10 +657,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (bevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
gdk_pointer_ungrab (bevent->time);
color_select_draw_z_marker (csp, NULL);
@ -837,10 +677,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (mevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
@ -857,7 +695,7 @@ static void
color_select_set_channel (ColorSelect *csp,
GimpColorSelectorChannelType type)
{
if (!csp)
if (! csp)
return;
switch ((ColorSelectFillType) type)
@ -897,7 +735,8 @@ color_select_set_channel (ColorSelect *csp,
static void
color_select_image_fill (GtkWidget *preview,
ColorSelectFillType type,
gint *values)
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelectFill csf;
gint height;
@ -909,7 +748,8 @@ color_select_image_fill (GtkWidget *preview,
csf.y = -1;
csf.width = preview->requisition.width;
csf.height = preview->requisition.height;
csf.values = values;
csf.hsv = *hsv;
csf.rgb = *rgb;
height = csf.height;
if (height > 0)
@ -1085,14 +925,9 @@ color_select_update_hue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
h = csf->y * 360 / csf->height;
h = csf->y * 360.0 / csf->height;
h = 360 - h;
if (h < 0)
h = 0;
if (h >= 360)
h = 0;
h = CLAMP (360 - h, 0, 360);
h /= 60;
f = (h - (int) h) * 255;
@ -1205,7 +1040,7 @@ color_select_update_red_green (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
b = csf->values[COLOR_SELECT_BLUE];
b = (gint) (csf->rgb.b * 255.999);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0)
@ -1236,7 +1071,7 @@ color_select_update_red_blue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
g = csf->values[COLOR_SELECT_GREEN];
g = (gint) (csf->rgb.g * 255.999);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0)
@ -1267,7 +1102,7 @@ color_select_update_green_blue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
r = csf->values[COLOR_SELECT_RED];
r = (gint) (csf->rgb.r * 255.999);
g = (csf->height - csf->y + 1) * 255 / csf->height;
if (g < 0)
@ -1312,7 +1147,7 @@ color_select_update_hue_saturation (ColorSelectFill *csf)
s = 0;
ds = 1.0 / csf->width;
v = csf->values[COLOR_SELECT_VALUE] / 100.0;
v = csf->hsv.v;
switch ((int) h)
{
@ -1403,7 +1238,7 @@ color_select_update_hue_value (ColorSelectFill *csf)
v = 0;
dv = 1.0 / csf->width;
s = csf->values[COLOR_SELECT_SATURATION] / 100.0;
s = csf->hsv.s;
switch ((int) h)
{
@ -1490,7 +1325,7 @@ color_select_update_saturation_value (ColorSelectFill *csf)
s = 1 - s;
h = (gfloat) csf->values[COLOR_SELECT_HUE];
h = (gfloat) csf->hsv.h * 360.0;
if (h >= 360)
h -= 360;
h /= 60;
@ -1577,13 +1412,8 @@ typedef struct
} notebook_glue;
static GtkWidget *
color_select_notebook_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
color_select_notebook_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer data,
@ -1607,20 +1437,14 @@ color_select_notebook_new (gint h,
csp->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
csp->gc = NULL;
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;
csp->hsv = *hsv;
csp->rgb = *rgb;
color_select_update_pos (csp);
glue->main_vbox = color_select_widget_new (csp, r, g, b, a);
glue->main_vbox = color_select_widget_new (csp, rgb);
color_select_image_fill (csp->z_color, csp->z_color_fill, csp->values);
color_select_image_fill (csp->xy_color, csp->xy_color_fill, csp->values);
color_select_update (csp, UPDATE_XY_COLOR | UPDATE_Z_COLOR);
*selector_data = glue;
@ -1642,20 +1466,14 @@ color_select_notebook_free (gpointer data)
g_free (glue);
}
static void
color_select_notebook_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
color_select_notebook_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
notebook_glue *glue = data;
color_select_set_color (glue->csp, h, s, v, r, g, b, a);
color_select_set_color (glue->csp, hsv, rgb);
}
static void
@ -1668,16 +1486,11 @@ color_select_notebook_set_channel (gpointer data,
}
static void
color_select_notebook_update_callback (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gpointer data)
color_select_notebook_update_callback (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer data)
{
notebook_glue *glue = data;
glue->callback (glue->client_data, h, s, v, r, g, b, a);
glue->callback (glue->client_data, hsv, rgb);
}

View File

@ -72,9 +72,10 @@ struct _ColorNotebook
GdkGC *gc;
gint values[7];
GimpHSV hsv;
GimpRGB rgb;
gint orig_values[4];
GimpRGB orig_rgb;
GimpColorSelectorChannelType active_channel;
@ -121,13 +122,8 @@ 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,
gint alpha);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
@ -203,8 +199,6 @@ color_notebook_new (GimpRGB *color,
ColorSelectorInstance *csel;
gint i;
guchar red, green, blue, alpha;
static gchar *toggle_titles[] =
{
N_("H"),
@ -225,14 +219,13 @@ color_notebook_new (GimpRGB *color,
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 };
static gdouble slider_initial_vals[] = { 0, 0, 0, 0, 0, 0, 0 };
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
g_return_val_if_fail (selector_info != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &alpha);
cnp = g_new0 (ColorNotebook, 1);
cnp->gc = NULL;
@ -244,10 +237,8 @@ color_notebook_new (GimpRGB *color,
cnp->selectors = NULL;
cnp->cur_page = NULL;
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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
@ -295,13 +286,8 @@ color_notebook_new (GimpRGB *color,
csel->info = info;
info->refs++;
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],
info->methods.new (&cnp->hsv,
&cnp->rgb,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
@ -418,6 +404,7 @@ color_notebook_new (GimpRGB *color,
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_widget_show (label);
}
else
{
@ -438,7 +425,7 @@ color_notebook_new (GimpRGB *color,
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
slider_initial_vals[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
@ -455,7 +442,10 @@ color_notebook_new (GimpRGB *color,
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
(gint) (color->r * 255.999),
(gint) (color->g * 255.999),
(gint) (color->b * 255.999));
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);
@ -471,6 +461,8 @@ color_notebook_new (GimpRGB *color,
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
color_notebook_update_scales (cnp, -1);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -537,19 +529,14 @@ void
color_notebook_set_color (ColorNotebook *cnp,
GimpRGB *color)
{
guchar red, green, blue, alpha;
g_return_if_fail (cnp != NULL);
g_return_if_fail (color != NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -561,30 +548,22 @@ color_notebook_set_color (ColorNotebook *cnp,
* Called by a color selector on user selection of a color
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha)
color_notebook_update_callback (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelectorInstance *csel;
ColorNotebook *cnp;
g_return_if_fail (data != NULL);
g_return_if_fail (hsv != NULL);
g_return_if_fail (rgb != NULL);
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
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;
cnp->hsv = *hsv;
cnp->rgb = *rgb;
color_notebook_update_scales (cnp, -1);
@ -598,19 +577,12 @@ color_notebook_ok_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -621,19 +593,12 @@ color_notebook_cancel_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->orig_rgb,
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -800,13 +765,8 @@ color_notebook_update_notebook (ColorNotebook *cnp)
csel = cnp->cur_page;
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]);
&cnp->hsv,
&cnp->rgb);
}
static void
@ -824,17 +784,9 @@ color_notebook_update_channel (ColorNotebook *cnp)
static void
color_notebook_update_caller (ColorNotebook *cnp)
{
GimpRGB color;
gimp_rgba_set (&color,
cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] / 255.0);
if (cnp && cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -846,7 +798,7 @@ color_notebook_update_colors (ColorNotebook *cnp,
{
GdkWindow *window;
GdkColor color;
gint red, green, blue;
guchar red, green, blue;
gint width, height;
if (!cnp)
@ -855,16 +807,14 @@ color_notebook_update_colors (ColorNotebook *cnp,
if (which == UPDATE_ORIG_COLOR)
{
window = cnp->orig_color->window;
red = cnp->orig_values[0];
green = cnp->orig_values[1];
blue = cnp->orig_values[2];
gimp_rgb_get_uchar (&cnp->orig_rgb, &red, &green, &blue);
}
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
gimp_rgb_get_uchar (&cnp->rgb, &red, &green, &blue);
}
else
{
@ -892,64 +842,55 @@ color_notebook_update_colors (ColorNotebook *cnp,
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
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;
gimp_hsv_to_rgb (&cnp->hsv, &cnp->rgb);
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
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;
gimp_rgb_to_hsv (&cnp->rgb, &cnp->hsv);
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gint values[7];
gchar buffer[16];
gint i;
if (!cnp)
if (! cnp)
return;
values[GIMP_COLOR_SELECTOR_HUE] = (gint) (cnp->hsv.h * 360.999);
values[GIMP_COLOR_SELECTOR_SATURATION] = (gint) (cnp->hsv.s * 100.999);
values[GIMP_COLOR_SELECTOR_VALUE] = (gint) (cnp->hsv.v * 100.999);
values[GIMP_COLOR_SELECTOR_RED] = (gint) (cnp->rgb.r * 255.999);
values[GIMP_COLOR_SELECTOR_GREEN] = (gint) (cnp->rgb.g * 255.999);
values[GIMP_COLOR_SELECTOR_BLUE] = (gint) (cnp->rgb.b * 255.999);
values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) (cnp->rgb.a * 100.999);
for (i = 0; i < (cnp->show_alpha ? 7 : 6); i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
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);
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]);
values[GIMP_COLOR_SELECTOR_RED],
values[GIMP_COLOR_SELECTOR_GREEN],
values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
@ -964,7 +905,7 @@ color_notebook_color_events (GtkWidget *widget,
cnp = (ColorNotebook *) data;
if (!cnp)
if (! cnp)
return FALSE;
switch (event->type)
@ -1024,7 +965,36 @@ color_notebook_scale_update (GtkAdjustment *adjustment,
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
switch (i)
{
case GIMP_COLOR_SELECTOR_HUE:
cnp->hsv.h = GTK_ADJUSTMENT (adjustment)->value / 360.0;
break;
case GIMP_COLOR_SELECTOR_SATURATION:
cnp->hsv.s = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_VALUE:
cnp->hsv.v = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_RED:
cnp->rgb.r = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_GREEN:
cnp->rgb.g = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_BLUE:
cnp->rgb.b = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_ALPHA:
cnp->hsv.a = cnp->rgb.a = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
}
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
@ -1069,9 +1039,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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]);
(gint) (cnp->rgb.r * 255.999),
(gint) (cnp->rgb.g * 255.999),
(gint) (cnp->rgb.b * 255.999));
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
@ -1079,9 +1049,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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);
cnp->rgb.r = ((hex_rgb & 0xff0000) >> 16) / 255.0;
cnp->rgb.g = ((hex_rgb & 0x00ff00) >> 8) / 255.0;
cnp->rgb.b = ((hex_rgb & 0x0000ff)) / 255.0;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1114,11 +1084,7 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
*color = cnp->rgb;
}
static void
@ -1127,16 +1093,10 @@ color_notebook_drop_new_color (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
guchar r, g, b, a;
cnp = (ColorNotebook *) data;
gimp_rgba_get_uchar (color, &r, &g, &b, &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;
cnp->rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1156,9 +1116,5 @@ color_notebook_drag_old_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
*color = cnp->orig_rgb;
}

View File

@ -33,6 +33,7 @@ typedef void (* ColorNotebookCallback) (GimpRGB *color,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
ColorNotebook * color_notebook_new (GimpRGB *color,
ColorNotebookCallback callback,
gpointer data,

View File

@ -72,9 +72,10 @@ struct _ColorNotebook
GdkGC *gc;
gint values[7];
GimpHSV hsv;
GimpRGB rgb;
gint orig_values[4];
GimpRGB orig_rgb;
GimpColorSelectorChannelType active_channel;
@ -121,13 +122,8 @@ 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,
gint alpha);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
@ -203,8 +199,6 @@ color_notebook_new (GimpRGB *color,
ColorSelectorInstance *csel;
gint i;
guchar red, green, blue, alpha;
static gchar *toggle_titles[] =
{
N_("H"),
@ -225,14 +219,13 @@ color_notebook_new (GimpRGB *color,
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 };
static gdouble slider_initial_vals[] = { 0, 0, 0, 0, 0, 0, 0 };
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
g_return_val_if_fail (selector_info != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &alpha);
cnp = g_new0 (ColorNotebook, 1);
cnp->gc = NULL;
@ -244,10 +237,8 @@ color_notebook_new (GimpRGB *color,
cnp->selectors = NULL;
cnp->cur_page = NULL;
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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
@ -295,13 +286,8 @@ color_notebook_new (GimpRGB *color,
csel->info = info;
info->refs++;
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],
info->methods.new (&cnp->hsv,
&cnp->rgb,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
@ -418,6 +404,7 @@ color_notebook_new (GimpRGB *color,
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_widget_show (label);
}
else
{
@ -438,7 +425,7 @@ color_notebook_new (GimpRGB *color,
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
slider_initial_vals[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
@ -455,7 +442,10 @@ color_notebook_new (GimpRGB *color,
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
(gint) (color->r * 255.999),
(gint) (color->g * 255.999),
(gint) (color->b * 255.999));
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);
@ -471,6 +461,8 @@ color_notebook_new (GimpRGB *color,
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
color_notebook_update_scales (cnp, -1);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -537,19 +529,14 @@ void
color_notebook_set_color (ColorNotebook *cnp,
GimpRGB *color)
{
guchar red, green, blue, alpha;
g_return_if_fail (cnp != NULL);
g_return_if_fail (color != NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -561,30 +548,22 @@ color_notebook_set_color (ColorNotebook *cnp,
* Called by a color selector on user selection of a color
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha)
color_notebook_update_callback (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelectorInstance *csel;
ColorNotebook *cnp;
g_return_if_fail (data != NULL);
g_return_if_fail (hsv != NULL);
g_return_if_fail (rgb != NULL);
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
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;
cnp->hsv = *hsv;
cnp->rgb = *rgb;
color_notebook_update_scales (cnp, -1);
@ -598,19 +577,12 @@ color_notebook_ok_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -621,19 +593,12 @@ color_notebook_cancel_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->orig_rgb,
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -800,13 +765,8 @@ color_notebook_update_notebook (ColorNotebook *cnp)
csel = cnp->cur_page;
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]);
&cnp->hsv,
&cnp->rgb);
}
static void
@ -824,17 +784,9 @@ color_notebook_update_channel (ColorNotebook *cnp)
static void
color_notebook_update_caller (ColorNotebook *cnp)
{
GimpRGB color;
gimp_rgba_set (&color,
cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] / 255.0);
if (cnp && cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -846,7 +798,7 @@ color_notebook_update_colors (ColorNotebook *cnp,
{
GdkWindow *window;
GdkColor color;
gint red, green, blue;
guchar red, green, blue;
gint width, height;
if (!cnp)
@ -855,16 +807,14 @@ color_notebook_update_colors (ColorNotebook *cnp,
if (which == UPDATE_ORIG_COLOR)
{
window = cnp->orig_color->window;
red = cnp->orig_values[0];
green = cnp->orig_values[1];
blue = cnp->orig_values[2];
gimp_rgb_get_uchar (&cnp->orig_rgb, &red, &green, &blue);
}
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
gimp_rgb_get_uchar (&cnp->rgb, &red, &green, &blue);
}
else
{
@ -892,64 +842,55 @@ color_notebook_update_colors (ColorNotebook *cnp,
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
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;
gimp_hsv_to_rgb (&cnp->hsv, &cnp->rgb);
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
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;
gimp_rgb_to_hsv (&cnp->rgb, &cnp->hsv);
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gint values[7];
gchar buffer[16];
gint i;
if (!cnp)
if (! cnp)
return;
values[GIMP_COLOR_SELECTOR_HUE] = (gint) (cnp->hsv.h * 360.999);
values[GIMP_COLOR_SELECTOR_SATURATION] = (gint) (cnp->hsv.s * 100.999);
values[GIMP_COLOR_SELECTOR_VALUE] = (gint) (cnp->hsv.v * 100.999);
values[GIMP_COLOR_SELECTOR_RED] = (gint) (cnp->rgb.r * 255.999);
values[GIMP_COLOR_SELECTOR_GREEN] = (gint) (cnp->rgb.g * 255.999);
values[GIMP_COLOR_SELECTOR_BLUE] = (gint) (cnp->rgb.b * 255.999);
values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) (cnp->rgb.a * 100.999);
for (i = 0; i < (cnp->show_alpha ? 7 : 6); i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
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);
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]);
values[GIMP_COLOR_SELECTOR_RED],
values[GIMP_COLOR_SELECTOR_GREEN],
values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
@ -964,7 +905,7 @@ color_notebook_color_events (GtkWidget *widget,
cnp = (ColorNotebook *) data;
if (!cnp)
if (! cnp)
return FALSE;
switch (event->type)
@ -1024,7 +965,36 @@ color_notebook_scale_update (GtkAdjustment *adjustment,
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
switch (i)
{
case GIMP_COLOR_SELECTOR_HUE:
cnp->hsv.h = GTK_ADJUSTMENT (adjustment)->value / 360.0;
break;
case GIMP_COLOR_SELECTOR_SATURATION:
cnp->hsv.s = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_VALUE:
cnp->hsv.v = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_RED:
cnp->rgb.r = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_GREEN:
cnp->rgb.g = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_BLUE:
cnp->rgb.b = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_ALPHA:
cnp->hsv.a = cnp->rgb.a = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
}
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
@ -1069,9 +1039,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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]);
(gint) (cnp->rgb.r * 255.999),
(gint) (cnp->rgb.g * 255.999),
(gint) (cnp->rgb.b * 255.999));
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
@ -1079,9 +1049,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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);
cnp->rgb.r = ((hex_rgb & 0xff0000) >> 16) / 255.0;
cnp->rgb.g = ((hex_rgb & 0x00ff00) >> 8) / 255.0;
cnp->rgb.b = ((hex_rgb & 0x0000ff)) / 255.0;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1114,11 +1084,7 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
*color = cnp->rgb;
}
static void
@ -1127,16 +1093,10 @@ color_notebook_drop_new_color (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
guchar r, g, b, a;
cnp = (ColorNotebook *) data;
gimp_rgba_get_uchar (color, &r, &g, &b, &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;
cnp->rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1156,9 +1116,5 @@ color_notebook_drag_old_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
*color = cnp->orig_rgb;
}

View File

@ -33,6 +33,7 @@ typedef void (* ColorNotebookCallback) (GimpRGB *color,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
ColorNotebook * color_notebook_new (GimpRGB *color,
ColorNotebookCallback callback,
gpointer data,

View File

@ -36,6 +36,7 @@
#include "session.h"
#include "color_area.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimphelpui.h"
@ -82,14 +83,9 @@ typedef enum
UPDATE_CALLER = 1 << 6
} ColorSelectUpdateType;
typedef void (* ColorSelectCallback) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gpointer data);
typedef void (* ColorSelectCallback) (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer data);
typedef struct _ColorSelect ColorSelect;
@ -98,11 +94,14 @@ struct _ColorSelect
GtkWidget *xy_color;
GtkWidget *z_color;
gint pos[3];
gint values[7];
gint z_color_fill;
gint xy_color_fill;
GdkGC *gc;
gint pos[3];
GimpHSV hsv;
GimpRGB rgb;
gint z_color_fill;
gint xy_color_fill;
GdkGC *gc;
ColorSelectCallback callback;
gpointer client_data;
@ -114,32 +113,30 @@ typedef void (* ColorSelectFillUpdateProc) (ColorSelectFill *color_select_fill);
struct _ColorSelectFill
{
guchar *buffer;
gint y;
gint width;
gint height;
gint *values;
guchar *buffer;
gint y;
gint width;
gint height;
GimpHSV hsv;
GimpRGB rgb;
ColorSelectFillUpdateProc update;
};
static GtkWidget * color_select_widget_new (ColorSelect *,
gint ,
gint ,
gint ,
gint );
static GtkWidget * color_select_widget_new (ColorSelect *csp,
const GimpRGB *color);
static void color_select_drop_color (GtkWidget *widget,
GimpRGB *color,
gpointer data);
static void color_select_update (ColorSelect *,
static void color_select_drop_color (GtkWidget *widget,
GimpRGB *color,
gpointer data);
static void color_select_update (ColorSelect *csp,
ColorSelectUpdateType);
static void color_select_update_caller (ColorSelect *);
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_caller (ColorSelect *csp);
static void color_select_update_values (ColorSelect *csp);
static void color_select_update_rgb_values (ColorSelect *csp);
static void color_select_update_hsv_values (ColorSelect *csp);
static void color_select_update_pos (ColorSelect *csp);
static gint color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *eevent,
@ -156,56 +153,42 @@ static gint color_select_z_events (GtkWidget *widet,
static void color_select_image_fill (GtkWidget *,
ColorSelectFillType,
gint *);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_select_draw_z_marker (ColorSelect *,
static void color_select_draw_z_marker (ColorSelect *csp,
GdkRectangle *);
static void color_select_draw_xy_marker (ColorSelect *,
static void color_select_draw_xy_marker (ColorSelect *csp,
GdkRectangle *);
static void color_select_update_red (ColorSelectFill *);
static void color_select_update_green (ColorSelectFill *);
static void color_select_update_blue (ColorSelectFill *);
static void color_select_update_hue (ColorSelectFill *);
static void color_select_update_saturation (ColorSelectFill *);
static void color_select_update_value (ColorSelectFill *);
static void color_select_update_red_green (ColorSelectFill *);
static void color_select_update_red_blue (ColorSelectFill *);
static void color_select_update_green_blue (ColorSelectFill *);
static void color_select_update_hue_saturation (ColorSelectFill *);
static void color_select_update_hue_value (ColorSelectFill *);
static void color_select_update_saturation_value (ColorSelectFill *);
static void color_select_update_red (ColorSelectFill *csf);
static void color_select_update_green (ColorSelectFill *csf);
static void color_select_update_blue (ColorSelectFill *csf);
static void color_select_update_hue (ColorSelectFill *csf);
static void color_select_update_saturation (ColorSelectFill *csf);
static void color_select_update_value (ColorSelectFill *csf);
static void color_select_update_red_green (ColorSelectFill *csf);
static void color_select_update_red_blue (ColorSelectFill *csf);
static void color_select_update_green_blue (ColorSelectFill *csf);
static void color_select_update_hue_saturation (ColorSelectFill *csf);
static void color_select_update_hue_value (ColorSelectFill *csf);
static void color_select_update_saturation_value (ColorSelectFill *csf);
static GtkWidget * color_select_notebook_new (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gboolean ,
static GtkWidget * color_select_notebook_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback,
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_set_color (gpointer ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint );
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_set_color (gpointer ,
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_select_notebook_set_channel (gpointer ,
GimpColorSelectorChannelType channel);
static void color_select_notebook_update_callback (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gpointer );
static void color_select_notebook_update_callback (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer );
/* Static variables */
static ColorSelectFillUpdateProc update_procs[] =
@ -251,11 +234,8 @@ color_select_init (void)
static GtkWidget *
color_select_widget_new (ColorSelect *csp,
gint r,
gint g,
gint b,
gint a)
color_select_widget_new (ColorSelect *csp,
const GimpRGB *color)
{
GtkWidget *main_vbox;
GtkWidget *main_hbox;
@ -330,16 +310,10 @@ color_select_drop_color (GtkWidget *widget,
gpointer data)
{
ColorSelect *csp;
guchar r, g, b, a;
csp = (ColorSelect *) data;
gimp_rgba_get_uchar (color, &r, &g, &b, &a);
csp->values[COLOR_SELECT_RED] = (gint) r;
csp->values[COLOR_SELECT_GREEN] = (gint) g;
csp->values[COLOR_SELECT_BLUE] = (gint) b;
csp->values[COLOR_SELECT_ALPHA] = (gint) a;
csp->rgb = *color;
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
@ -351,25 +325,15 @@ color_select_drop_color (GtkWidget *widget,
}
static void
color_select_set_color (ColorSelect *csp,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
color_select_set_color (ColorSelect *csp,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
if (!csp)
if (! csp)
return;
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;
csp->hsv = *hsv;
csp->rgb = *rgb;
color_select_update_pos (csp);
@ -394,13 +358,15 @@ color_select_update (ColorSelect *csp,
if (update & UPDATE_XY_COLOR)
{
color_select_image_fill (csp->xy_color, csp->xy_color_fill, csp->values);
color_select_image_fill (csp->xy_color, csp->xy_color_fill,
&csp->hsv, &csp->rgb);
gtk_widget_draw (csp->xy_color, NULL);
}
if (update & UPDATE_Z_COLOR)
{
color_select_image_fill (csp->z_color, csp->z_color_fill, csp->values);
color_select_image_fill (csp->z_color, csp->z_color_fill,
&csp->hsv, &csp->rgb);
gtk_widget_draw (csp->z_color, NULL);
}
@ -413,13 +379,8 @@ color_select_update_caller (ColorSelect *csp)
{
if (csp && csp->callback)
{
(* 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],
(* csp->callback) (&csp->hsv,
&csp->rgb,
csp->client_data);
}
}
@ -433,34 +394,35 @@ color_select_update_values (ColorSelect *csp)
switch (csp->z_color_fill)
{
case COLOR_SELECT_RED:
csp->values[COLOR_SELECT_BLUE] = csp->pos[0];
csp->values[COLOR_SELECT_GREEN] = csp->pos[1];
csp->values[COLOR_SELECT_RED] = csp->pos[2];
csp->rgb.b = csp->pos[0] / 255.0;
csp->rgb.g = csp->pos[1] / 255.0;
csp->rgb.r = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_GREEN:
csp->values[COLOR_SELECT_BLUE] = csp->pos[0];
csp->values[COLOR_SELECT_RED] = csp->pos[1];
csp->values[COLOR_SELECT_GREEN] = csp->pos[2];
csp->rgb.b = csp->pos[0] / 255.0;
csp->rgb.r = csp->pos[1] / 255.0;
csp->rgb.g = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_BLUE:
csp->values[COLOR_SELECT_GREEN] = csp->pos[0];
csp->values[COLOR_SELECT_RED] = csp->pos[1];
csp->values[COLOR_SELECT_BLUE] = csp->pos[2];
csp->rgb.g = csp->pos[0] / 255.0;
csp->rgb.r = csp->pos[1] / 255.0;
csp->rgb.b = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_HUE:
csp->values[COLOR_SELECT_VALUE] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_SATURATION] = csp->pos[1] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[2] * 360 / 255;
csp->hsv.v = csp->pos[0] / 255.0;
csp->hsv.s = csp->pos[1] / 255.0;
csp->hsv.h = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_SATURATION:
csp->values[COLOR_SELECT_VALUE] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[1] * 360 / 255;
csp->values[COLOR_SELECT_SATURATION] = csp->pos[2] * 100 / 255;
csp->hsv.v = csp->pos[0] / 255.0;
csp->hsv.h = csp->pos[1] / 255.0;
csp->hsv.s = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_VALUE:
csp->values[COLOR_SELECT_SATURATION] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[1] * 360 / 255;
csp->values[COLOR_SELECT_VALUE] = csp->pos[2] * 100 / 255;
csp->hsv.s = csp->pos[0] / 255.0;
csp->hsv.h = csp->pos[1] / 255.0;
csp->hsv.v = csp->pos[2] / 255.0;
break;
}
@ -471,6 +433,7 @@ color_select_update_values (ColorSelect *csp)
case COLOR_SELECT_BLUE:
color_select_update_hsv_values (csp);
break;
case COLOR_SELECT_HUE:
case COLOR_SELECT_SATURATION:
case COLOR_SELECT_VALUE:
@ -482,178 +445,59 @@ color_select_update_values (ColorSelect *csp)
static void
color_select_update_rgb_values (ColorSelect *csp)
{
gfloat h, s, v;
gfloat f, p, q, t;
if (!csp)
if (! csp)
return;
h = csp->values[COLOR_SELECT_HUE];
s = csp->values[COLOR_SELECT_SATURATION] / 100.0;
v = csp->values[COLOR_SELECT_VALUE] / 100.0;
if (s == 0)
{
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
}
else
{
if (h == 360)
h = 0;
h /= 60;
f = h - (int) h;
p = v * (1 - s);
q = v * (1 - (s * f));
t = v * (1 - (s * (1 - f)));
switch ((gint) h)
{
case 0:
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = t * 255;
csp->values[COLOR_SELECT_BLUE] = p * 255;
break;
case 1:
csp->values[COLOR_SELECT_RED] = q * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = p * 255;
break;
case 2:
csp->values[COLOR_SELECT_RED] = p * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = t * 255;
break;
case 3:
csp->values[COLOR_SELECT_RED] = p * 255;
csp->values[COLOR_SELECT_GREEN] = q * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
break;
case 4:
csp->values[COLOR_SELECT_RED] = t * 255;
csp->values[COLOR_SELECT_GREEN] = p * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
break;
case 5:
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = p * 255;
csp->values[COLOR_SELECT_BLUE] = q * 255;
break;
}
}
gimp_hsv_to_rgb (&csp->hsv, &csp->rgb);
}
static void
color_select_update_hsv_values (ColorSelect *csp)
{
gint r, g, b;
gfloat h, s, v;
gint min, max;
gint delta;
if (!csp)
if (! csp)
return;
r = csp->values[COLOR_SELECT_RED];
g = csp->values[COLOR_SELECT_GREEN];
b = csp->values[COLOR_SELECT_BLUE];
if (r > g)
{
if (r > b)
max = r;
else
max = b;
if (g < b)
min = g;
else
min = b;
}
else
{
if (g > b)
max = g;
else
max = b;
if (r < b)
min = r;
else
min = b;
}
v = max;
if (max != 0)
s = (max - min) / (float) max;
else
s = 0;
if (s == 0)
{
h = 0;
}
else
{
h = 0;
delta = max - min;
if (r == max)
h = (g - b) / (float) delta;
else if (g == max)
h = 2 + (b - r) / (float) delta;
else if (b == max)
h = 4 + (r - g) / (float) delta;
h *= 60;
if (h < 0)
h += 360;
}
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s * 100;
csp->values[COLOR_SELECT_VALUE] = v * 100 / 255;
gimp_rgb_to_hsv (&csp->rgb, &csp->hsv);
}
static void
color_select_update_pos (ColorSelect *csp)
{
if (!csp)
if (! csp)
return;
switch (csp->z_color_fill)
{
case COLOR_SELECT_RED:
csp->pos[0] = csp->values[COLOR_SELECT_BLUE];
csp->pos[1] = csp->values[COLOR_SELECT_GREEN];
csp->pos[2] = csp->values[COLOR_SELECT_RED];
csp->pos[0] = (gint) (csp->rgb.b * 255.999);
csp->pos[1] = (gint) (csp->rgb.g * 255.999);
csp->pos[2] = (gint) (csp->rgb.r * 255.999);
break;
case COLOR_SELECT_GREEN:
csp->pos[0] = csp->values[COLOR_SELECT_BLUE];
csp->pos[1] = csp->values[COLOR_SELECT_RED];
csp->pos[2] = csp->values[COLOR_SELECT_GREEN];
csp->pos[0] = (gint) (csp->rgb.b * 255.999);
csp->pos[1] = (gint) (csp->rgb.r * 255.999);
csp->pos[2] = (gint) (csp->rgb.g * 255.999);
break;
case COLOR_SELECT_BLUE:
csp->pos[0] = csp->values[COLOR_SELECT_GREEN];
csp->pos[1] = csp->values[COLOR_SELECT_RED];
csp->pos[2] = csp->values[COLOR_SELECT_BLUE];
csp->pos[0] = (gint) (csp->rgb.g * 255.999);
csp->pos[1] = (gint) (csp->rgb.r * 255.999);
csp->pos[2] = (gint) (csp->rgb.b * 255.999);
break;
case COLOR_SELECT_HUE:
csp->pos[0] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[2] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[0] = (gint) (csp->hsv.v * 255.999);
csp->pos[1] = (gint) (csp->hsv.s * 255.999);
csp->pos[2] = (gint) (csp->hsv.h * 255.999);
break;
case COLOR_SELECT_SATURATION:
csp->pos[0] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[2] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[0] = (gint) (csp->hsv.v * 255.999);
csp->pos[1] = (gint) (csp->hsv.h * 255.999);
csp->pos[2] = (gint) (csp->hsv.s * 255.999);
break;
case COLOR_SELECT_VALUE:
csp->pos[0] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[2] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[0] = (gint) (csp->hsv.s * 255.999);
csp->pos[1] = (gint) (csp->hsv.h * 255.999);
csp->pos[2] = (gint) (csp->hsv.v * 255.999);
break;
}
}
@ -663,7 +507,7 @@ color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *event,
ColorSelect *csp)
{
if (!csp->gc)
if (! csp->gc)
csp->gc = gdk_gc_new (widget->window);
color_select_draw_xy_marker (csp, &event->area);
@ -701,7 +545,7 @@ color_select_xy_events (GtkWidget *widget,
gdk_pointer_grab (csp->xy_color->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
color_select_draw_xy_marker (csp, NULL);
@ -795,10 +639,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (bevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
gdk_pointer_grab (csp->z_color->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
@ -815,10 +657,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (bevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
gdk_pointer_ungrab (bevent->time);
color_select_draw_z_marker (csp, NULL);
@ -837,10 +677,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (mevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
@ -857,7 +695,7 @@ static void
color_select_set_channel (ColorSelect *csp,
GimpColorSelectorChannelType type)
{
if (!csp)
if (! csp)
return;
switch ((ColorSelectFillType) type)
@ -897,7 +735,8 @@ color_select_set_channel (ColorSelect *csp,
static void
color_select_image_fill (GtkWidget *preview,
ColorSelectFillType type,
gint *values)
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelectFill csf;
gint height;
@ -909,7 +748,8 @@ color_select_image_fill (GtkWidget *preview,
csf.y = -1;
csf.width = preview->requisition.width;
csf.height = preview->requisition.height;
csf.values = values;
csf.hsv = *hsv;
csf.rgb = *rgb;
height = csf.height;
if (height > 0)
@ -1085,14 +925,9 @@ color_select_update_hue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
h = csf->y * 360 / csf->height;
h = csf->y * 360.0 / csf->height;
h = 360 - h;
if (h < 0)
h = 0;
if (h >= 360)
h = 0;
h = CLAMP (360 - h, 0, 360);
h /= 60;
f = (h - (int) h) * 255;
@ -1205,7 +1040,7 @@ color_select_update_red_green (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
b = csf->values[COLOR_SELECT_BLUE];
b = (gint) (csf->rgb.b * 255.999);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0)
@ -1236,7 +1071,7 @@ color_select_update_red_blue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
g = csf->values[COLOR_SELECT_GREEN];
g = (gint) (csf->rgb.g * 255.999);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0)
@ -1267,7 +1102,7 @@ color_select_update_green_blue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
r = csf->values[COLOR_SELECT_RED];
r = (gint) (csf->rgb.r * 255.999);
g = (csf->height - csf->y + 1) * 255 / csf->height;
if (g < 0)
@ -1312,7 +1147,7 @@ color_select_update_hue_saturation (ColorSelectFill *csf)
s = 0;
ds = 1.0 / csf->width;
v = csf->values[COLOR_SELECT_VALUE] / 100.0;
v = csf->hsv.v;
switch ((int) h)
{
@ -1403,7 +1238,7 @@ color_select_update_hue_value (ColorSelectFill *csf)
v = 0;
dv = 1.0 / csf->width;
s = csf->values[COLOR_SELECT_SATURATION] / 100.0;
s = csf->hsv.s;
switch ((int) h)
{
@ -1490,7 +1325,7 @@ color_select_update_saturation_value (ColorSelectFill *csf)
s = 1 - s;
h = (gfloat) csf->values[COLOR_SELECT_HUE];
h = (gfloat) csf->hsv.h * 360.0;
if (h >= 360)
h -= 360;
h /= 60;
@ -1577,13 +1412,8 @@ typedef struct
} notebook_glue;
static GtkWidget *
color_select_notebook_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
color_select_notebook_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer data,
@ -1607,20 +1437,14 @@ color_select_notebook_new (gint h,
csp->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
csp->gc = NULL;
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;
csp->hsv = *hsv;
csp->rgb = *rgb;
color_select_update_pos (csp);
glue->main_vbox = color_select_widget_new (csp, r, g, b, a);
glue->main_vbox = color_select_widget_new (csp, rgb);
color_select_image_fill (csp->z_color, csp->z_color_fill, csp->values);
color_select_image_fill (csp->xy_color, csp->xy_color_fill, csp->values);
color_select_update (csp, UPDATE_XY_COLOR | UPDATE_Z_COLOR);
*selector_data = glue;
@ -1642,20 +1466,14 @@ color_select_notebook_free (gpointer data)
g_free (glue);
}
static void
color_select_notebook_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
color_select_notebook_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
notebook_glue *glue = data;
color_select_set_color (glue->csp, h, s, v, r, g, b, a);
color_select_set_color (glue->csp, hsv, rgb);
}
static void
@ -1668,16 +1486,11 @@ color_select_notebook_set_channel (gpointer data,
}
static void
color_select_notebook_update_callback (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gpointer data)
color_select_notebook_update_callback (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer data)
{
notebook_glue *glue = data;
glue->callback (glue->client_data, h, s, v, r, g, b, a);
glue->callback (glue->client_data, hsv, rgb);
}

View File

@ -72,9 +72,10 @@ struct _ColorNotebook
GdkGC *gc;
gint values[7];
GimpHSV hsv;
GimpRGB rgb;
gint orig_values[4];
GimpRGB orig_rgb;
GimpColorSelectorChannelType active_channel;
@ -121,13 +122,8 @@ 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,
gint alpha);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
@ -203,8 +199,6 @@ color_notebook_new (GimpRGB *color,
ColorSelectorInstance *csel;
gint i;
guchar red, green, blue, alpha;
static gchar *toggle_titles[] =
{
N_("H"),
@ -225,14 +219,13 @@ color_notebook_new (GimpRGB *color,
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 };
static gdouble slider_initial_vals[] = { 0, 0, 0, 0, 0, 0, 0 };
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
g_return_val_if_fail (selector_info != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &alpha);
cnp = g_new0 (ColorNotebook, 1);
cnp->gc = NULL;
@ -244,10 +237,8 @@ color_notebook_new (GimpRGB *color,
cnp->selectors = NULL;
cnp->cur_page = NULL;
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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
@ -295,13 +286,8 @@ color_notebook_new (GimpRGB *color,
csel->info = info;
info->refs++;
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],
info->methods.new (&cnp->hsv,
&cnp->rgb,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
@ -418,6 +404,7 @@ color_notebook_new (GimpRGB *color,
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
gtk_widget_show (label);
}
else
{
@ -438,7 +425,7 @@ color_notebook_new (GimpRGB *color,
cnp->slider_data[i] = gimp_scale_entry_new (GTK_TABLE (table), 0, i,
NULL,
80, 55,
cnp->values[i],
slider_initial_vals[i],
0.0, slider_max_vals[i],
1.0, slider_incs[i],
0, TRUE, 0.0, 0.0,
@ -455,7 +442,10 @@ color_notebook_new (GimpRGB *color,
gtk_widget_show (hbox);
cnp->hex_entry = gtk_entry_new ();
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x", red, green, blue);
g_snprintf (buffer, sizeof (buffer), "#%.2x%.2x%.2x",
(gint) (color->r * 255.999),
(gint) (color->g * 255.999),
(gint) (color->b * 255.999));
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);
@ -471,6 +461,8 @@ color_notebook_new (GimpRGB *color,
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
color_notebook_update_scales (cnp, -1);
gtk_widget_show (cnp->shell);
/* this must come after showing the widget, otherwise we get a
@ -537,19 +529,14 @@ void
color_notebook_set_color (ColorNotebook *cnp,
GimpRGB *color)
{
guchar red, green, blue, alpha;
g_return_if_fail (cnp != NULL);
g_return_if_fail (color != NULL);
gimp_rgba_get_uchar (color, &red, &green, &blue, &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;
cnp->rgb = *color;
cnp->orig_rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
color_notebook_update (cnp,
UPDATE_NOTEBOOK |
@ -561,30 +548,22 @@ color_notebook_set_color (ColorNotebook *cnp,
* Called by a color selector on user selection of a color
*/
static void
color_notebook_update_callback (gpointer data,
gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha)
color_notebook_update_callback (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelectorInstance *csel;
ColorNotebook *cnp;
g_return_if_fail (data != NULL);
g_return_if_fail (hsv != NULL);
g_return_if_fail (rgb != NULL);
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
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;
cnp->hsv = *hsv;
cnp->rgb = *rgb;
color_notebook_update_scales (cnp, -1);
@ -598,19 +577,12 @@ color_notebook_ok_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_OK,
cnp->client_data);
}
@ -621,19 +593,12 @@ color_notebook_cancel_callback (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
GimpRGB color;
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (&color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
if (cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->orig_rgb,
COLOR_NOTEBOOK_CANCEL,
cnp->client_data);
}
@ -800,13 +765,8 @@ color_notebook_update_notebook (ColorNotebook *cnp)
csel = cnp->cur_page;
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]);
&cnp->hsv,
&cnp->rgb);
}
static void
@ -824,17 +784,9 @@ color_notebook_update_channel (ColorNotebook *cnp)
static void
color_notebook_update_caller (ColorNotebook *cnp)
{
GimpRGB color;
gimp_rgba_set (&color,
cnp->values[GIMP_COLOR_SELECTOR_RED] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_GREEN] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_BLUE] / 255.0,
cnp->values[GIMP_COLOR_SELECTOR_ALPHA] / 255.0);
if (cnp && cnp->callback)
{
(* cnp->callback) (&color,
(* cnp->callback) (&cnp->rgb,
COLOR_NOTEBOOK_UPDATE,
cnp->client_data);
}
@ -846,7 +798,7 @@ color_notebook_update_colors (ColorNotebook *cnp,
{
GdkWindow *window;
GdkColor color;
gint red, green, blue;
guchar red, green, blue;
gint width, height;
if (!cnp)
@ -855,16 +807,14 @@ color_notebook_update_colors (ColorNotebook *cnp,
if (which == UPDATE_ORIG_COLOR)
{
window = cnp->orig_color->window;
red = cnp->orig_values[0];
green = cnp->orig_values[1];
blue = cnp->orig_values[2];
gimp_rgb_get_uchar (&cnp->orig_rgb, &red, &green, &blue);
}
else if (which == UPDATE_NEW_COLOR)
{
window = cnp->new_color->window;
red = cnp->values[GIMP_COLOR_SELECTOR_RED];
green = cnp->values[GIMP_COLOR_SELECTOR_GREEN];
blue = cnp->values[GIMP_COLOR_SELECTOR_BLUE];
gimp_rgb_get_uchar (&cnp->rgb, &red, &green, &blue);
}
else
{
@ -892,64 +842,55 @@ color_notebook_update_colors (ColorNotebook *cnp,
static void
color_notebook_update_rgb_values (ColorNotebook *cnp)
{
gdouble h, s, v;
if (!cnp)
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;
gimp_hsv_to_rgb (&cnp->hsv, &cnp->rgb);
}
static void
color_notebook_update_hsv_values (ColorNotebook *cnp)
{
gdouble r, g, b;
if (!cnp)
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;
gimp_rgb_to_hsv (&cnp->rgb, &cnp->hsv);
}
static void
color_notebook_update_scales (ColorNotebook *cnp,
gint skip)
{
gint values[7];
gchar buffer[16];
gint i;
if (!cnp)
if (! cnp)
return;
values[GIMP_COLOR_SELECTOR_HUE] = (gint) (cnp->hsv.h * 360.999);
values[GIMP_COLOR_SELECTOR_SATURATION] = (gint) (cnp->hsv.s * 100.999);
values[GIMP_COLOR_SELECTOR_VALUE] = (gint) (cnp->hsv.v * 100.999);
values[GIMP_COLOR_SELECTOR_RED] = (gint) (cnp->rgb.r * 255.999);
values[GIMP_COLOR_SELECTOR_GREEN] = (gint) (cnp->rgb.g * 255.999);
values[GIMP_COLOR_SELECTOR_BLUE] = (gint) (cnp->rgb.b * 255.999);
values[GIMP_COLOR_SELECTOR_ALPHA] = (gint) (cnp->rgb.a * 100.999);
for (i = 0; i < (cnp->show_alpha ? 7 : 6); i++)
if (i != skip)
{
gtk_signal_handler_block_by_data (GTK_OBJECT (cnp->slider_data[i]), cnp);
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);
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]);
values[GIMP_COLOR_SELECTOR_RED],
values[GIMP_COLOR_SELECTOR_GREEN],
values[GIMP_COLOR_SELECTOR_BLUE]);
gtk_entry_set_text (GTK_ENTRY (cnp->hex_entry), buffer);
}
@ -964,7 +905,7 @@ color_notebook_color_events (GtkWidget *widget,
cnp = (ColorNotebook *) data;
if (!cnp)
if (! cnp)
return FALSE;
switch (event->type)
@ -1024,7 +965,36 @@ color_notebook_scale_update (GtkAdjustment *adjustment,
if (cnp->slider_data[i] == GTK_OBJECT (adjustment))
break;
cnp->values[i] = (gint) (GTK_ADJUSTMENT (adjustment)->value);
switch (i)
{
case GIMP_COLOR_SELECTOR_HUE:
cnp->hsv.h = GTK_ADJUSTMENT (adjustment)->value / 360.0;
break;
case GIMP_COLOR_SELECTOR_SATURATION:
cnp->hsv.s = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_VALUE:
cnp->hsv.v = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
case GIMP_COLOR_SELECTOR_RED:
cnp->rgb.r = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_GREEN:
cnp->rgb.g = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_BLUE:
cnp->rgb.b = GTK_ADJUSTMENT (adjustment)->value / 255.0;
break;
case GIMP_COLOR_SELECTOR_ALPHA:
cnp->hsv.a = cnp->rgb.a = GTK_ADJUSTMENT (adjustment)->value / 100.0;
break;
}
if ((i >= GIMP_COLOR_SELECTOR_HUE) && (i <= GIMP_COLOR_SELECTOR_VALUE))
{
@ -1069,9 +1039,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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]);
(gint) (cnp->rgb.r * 255.999),
(gint) (cnp->rgb.g * 255.999),
(gint) (cnp->rgb.b * 255.999));
if ((strlen (hex_color) == 7) &&
(g_strcasecmp (buffer, hex_color) != 0))
@ -1079,9 +1049,9 @@ color_notebook_hex_entry_events (GtkWidget *widget,
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);
cnp->rgb.r = ((hex_rgb & 0xff0000) >> 16) / 255.0;
cnp->rgb.g = ((hex_rgb & 0x00ff00) >> 8) / 255.0;
cnp->rgb.b = ((hex_rgb & 0x0000ff)) / 255.0;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1114,11 +1084,7 @@ color_notebook_drag_new_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->values[GIMP_COLOR_SELECTOR_RED],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_GREEN],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_BLUE],
(guchar) cnp->values[GIMP_COLOR_SELECTOR_ALPHA]);
*color = cnp->rgb;
}
static void
@ -1127,16 +1093,10 @@ color_notebook_drop_new_color (GtkWidget *widget,
gpointer data)
{
ColorNotebook *cnp;
guchar r, g, b, a;
cnp = (ColorNotebook *) data;
gimp_rgba_get_uchar (color, &r, &g, &b, &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;
cnp->rgb = *color;
color_notebook_update_hsv_values (cnp);
color_notebook_update_scales (cnp, -1);
@ -1156,9 +1116,5 @@ color_notebook_drag_old_color (GtkWidget *widget,
cnp = (ColorNotebook *) data;
gimp_rgba_set_uchar (color,
(guchar) cnp->orig_values[0],
(guchar) cnp->orig_values[1],
(guchar) cnp->orig_values[2],
(guchar) cnp->orig_values[3]);
*color = cnp->orig_rgb;
}

View File

@ -33,6 +33,7 @@ typedef void (* ColorNotebookCallback) (GimpRGB *color,
typedef struct _ColorSelectorInstance ColorSelectorInstance;
ColorNotebook * color_notebook_new (GimpRGB *color,
ColorNotebookCallback callback,
gpointer data,

View File

@ -343,11 +343,11 @@ gimp_hsv_clamp (GimpHSV *hsv)
{
g_return_if_fail (hsv != NULL);
if (hsv->h < 0.0)
hsv->h = GIMP_HSV_UNDEFINED;
hsv->h -= (gint) hsv->h;
if (hsv->h < 0)
hsv->h += 1.0;
hsv->s = CLAMP (hsv->s, 0.0, 1.0);
hsv->v = CLAMP (hsv->v, 0.0, 1.0);
hsv->a = CLAMP (hsv->a, 0.0, 1.0);

View File

@ -40,43 +40,28 @@ typedef enum
} GimpColorSelectorChannelType;
typedef void (* GimpColorSelectorCallback) (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a);
typedef void (* GimpColorSelectorCallback) (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb);
typedef GtkWidget * (* GimpColorSelectorNewFunc) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gboolean show_alpha,
typedef GtkWidget * (* GimpColorSelectorNewFunc) (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback cb,
gpointer data,
gpointer *selector_data);
gpointer data,
gpointer *selector_data);
typedef void (* GimpColorSelectorFreeFunc) (gpointer selector_data);
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 (* GimpColorSelectorSetColorFunc) (gpointer selector_data,
const GimpHSV *hsv,
const GimpRGB *rgb);
typedef void (* GimpColorSelectorSetChannelFunc) (gpointer selector_data,
typedef void (* GimpColorSelectorSetChannelFunc) (gpointer selector_data,
GimpColorSelectorChannelType type);
typedef void (* GimpColorSelectorFinishedCB) (gpointer finished_data);
typedef void (* GimpColorSelectorFinishedCB) (gpointer finished_data);
typedef struct _GimpColorSelectorMethods GimpColorSelectorMethods;

View File

@ -24,6 +24,9 @@
#include "gimpmath.h"
#define GIMP_HSV_UNDEFINED -1.0
#define GIMP_HSL_UNDEFINED -1.0
/*********************************
* color conversion routines *
*********************************/
@ -32,8 +35,8 @@
/* GimpRGB functions */
void
gimp_rgb_to_hsv (GimpRGB *rgb,
GimpHSV *hsv)
gimp_rgb_to_hsv (const GimpRGB *rgb,
GimpHSV *hsv)
{
gdouble max, min, delta;
@ -51,6 +54,9 @@ gimp_rgb_to_hsv (GimpRGB *rgb,
hsv->s = delta / max;
if (delta == 0.0)
delta = 1.0;
if (rgb->r == max)
{
hsv->h = (rgb->g - rgb->b) / delta;
@ -74,23 +80,25 @@ gimp_rgb_to_hsv (GimpRGB *rgb,
else
{
hsv->s = 0.0;
hsv->h = GIMP_HSV_UNDEFINED;
hsv->h = 0.0;
}
hsv->a = rgb->a;
}
void
gimp_hsv_to_rgb (GimpHSV *hsv,
GimpRGB *rgb)
gimp_hsv_to_rgb (const GimpHSV *hsv,
GimpRGB *rgb)
{
gint i;
gdouble f, w, q, t;
gdouble hue;
g_return_if_fail (rgb != NULL);
g_return_if_fail (hsv != NULL);
if (hsv->s == 0.0 || hsv->h == GIMP_HSV_UNDEFINED)
if (hsv->s == 0.0)
{
rgb->r = hsv->v;
rgb->g = hsv->v;
@ -98,13 +106,15 @@ gimp_hsv_to_rgb (GimpHSV *hsv,
}
else
{
if (hsv->h == 1.0)
hsv->h = 0.0;
hue = hsv->h;
hsv->h *= 6.0;
if (hue == 1.0)
hue = 0.0;
i = (gint) hsv->h;
f = hsv->h - i;
hue *= 6.0;
i = (gint) hue;
f = hue - i;
w = hsv->v * (1.0 - hsv->s);
q = hsv->v * (1.0 - (hsv->s * f));
t = hsv->v * (1.0 - (hsv->s * (1.0 - f)));
@ -148,10 +158,10 @@ gimp_hsv_to_rgb (GimpHSV *hsv,
}
void
gimp_rgb_to_hsl (GimpRGB *rgb,
gdouble *hue,
gdouble *saturation,
gdouble *lightness)
gimp_rgb_to_hsl (const GimpRGB *rgb,
gdouble *hue,
gdouble *saturation,
gdouble *lightness)
{
gdouble max, min, delta;
@ -179,6 +189,9 @@ gimp_rgb_to_hsl (GimpRGB *rgb,
delta = max - min;
if (delta == 0.0)
delta = 1.0;
if (rgb->r == max)
{
*hue = (rgb->g - rgb->b) / delta;
@ -260,10 +273,10 @@ gimp_hsl_to_rgb (gdouble hue,
*****************************************************************************/
void
gimp_rgb_to_hwb (GimpRGB *rgb,
gdouble *hue,
gdouble *whiteness,
gdouble *blackness)
gimp_rgb_to_hwb (const GimpRGB *rgb,
gdouble *hue,
gdouble *whiteness,
gdouble *blackness)
{
/* RGB are each on [0, 1]. W and B are returned on [0, 1] and H is */
/* returned on [0, 6]. Exception: H is returned UNDEFINED if W == 1 - B. */
@ -655,6 +668,9 @@ gimp_rgb_to_hsv_double (gdouble *red,
{
delta = max - min;
if (delta == 0.0)
delta = 1.0;
if (r == max)
h = (g - b) / delta;
else if (g == max)
@ -785,6 +801,9 @@ gimp_rgb_to_hsv4 (guchar *rgb,
{
delta = max - min;
if (delta == 0.0)
delta = 1.0;
if (red == max)
h = (green - blue) / delta;
else if (green == max)

View File

@ -32,33 +32,30 @@ extern "C" {
/* GimpRGB function */
#define GIMP_HSV_UNDEFINED -1.0
#define GIMP_HSL_UNDEFINED -1.0
void gimp_rgb_to_hsv (const GimpRGB *rgb,
GimpHSV *hsv);
void gimp_rgb_to_hsv (GimpRGB *rgb,
GimpHSV *hsv);
void gimp_rgb_to_hsl (const GimpRGB *rgb,
gdouble *hue,
gdouble *saturation,
gdouble *lightness);
void gimp_rgb_to_hsl (GimpRGB *rgb,
gdouble *hue,
gdouble *saturation,
gdouble *lightness);
void gimp_hsv_to_rgb (const GimpHSV *hsv,
GimpRGB *rgb);
void gimp_hsv_to_rgb (GimpHSV *hsv,
GimpRGB *rgb);
void gimp_hsl_to_rgb (gdouble hue,
gdouble saturation,
gdouble lightness,
GimpRGB *rgb);
void gimp_hsl_to_rgb (gdouble hue,
gdouble saturation,
gdouble lightness,
GimpRGB *rgb);
void gimp_rgb_to_hwb (GimpRGB *rgb,
gdouble *hue,
gdouble *whiteness,
gdouble *blackness);
void gimp_hwb_to_rgb (gdouble hue,
gdouble whiteness,
gdouble blackness,
GimpRGB *rgb);
void gimp_rgb_to_hwb (const GimpRGB *rgb,
gdouble *hue,
gdouble *whiteness,
gdouble *blackness);
void gimp_hwb_to_rgb (gdouble hue,
gdouble whiteness,
gdouble blackness,
GimpRGB *rgb);
/* gint functions */

View File

@ -36,6 +36,7 @@
#include "session.h"
#include "color_area.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimphelpui.h"
@ -82,14 +83,9 @@ typedef enum
UPDATE_CALLER = 1 << 6
} ColorSelectUpdateType;
typedef void (* ColorSelectCallback) (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gpointer data);
typedef void (* ColorSelectCallback) (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer data);
typedef struct _ColorSelect ColorSelect;
@ -98,11 +94,14 @@ struct _ColorSelect
GtkWidget *xy_color;
GtkWidget *z_color;
gint pos[3];
gint values[7];
gint z_color_fill;
gint xy_color_fill;
GdkGC *gc;
gint pos[3];
GimpHSV hsv;
GimpRGB rgb;
gint z_color_fill;
gint xy_color_fill;
GdkGC *gc;
ColorSelectCallback callback;
gpointer client_data;
@ -114,32 +113,30 @@ typedef void (* ColorSelectFillUpdateProc) (ColorSelectFill *color_select_fill);
struct _ColorSelectFill
{
guchar *buffer;
gint y;
gint width;
gint height;
gint *values;
guchar *buffer;
gint y;
gint width;
gint height;
GimpHSV hsv;
GimpRGB rgb;
ColorSelectFillUpdateProc update;
};
static GtkWidget * color_select_widget_new (ColorSelect *,
gint ,
gint ,
gint ,
gint );
static GtkWidget * color_select_widget_new (ColorSelect *csp,
const GimpRGB *color);
static void color_select_drop_color (GtkWidget *widget,
GimpRGB *color,
gpointer data);
static void color_select_update (ColorSelect *,
static void color_select_drop_color (GtkWidget *widget,
GimpRGB *color,
gpointer data);
static void color_select_update (ColorSelect *csp,
ColorSelectUpdateType);
static void color_select_update_caller (ColorSelect *);
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_caller (ColorSelect *csp);
static void color_select_update_values (ColorSelect *csp);
static void color_select_update_rgb_values (ColorSelect *csp);
static void color_select_update_hsv_values (ColorSelect *csp);
static void color_select_update_pos (ColorSelect *csp);
static gint color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *eevent,
@ -156,56 +153,42 @@ static gint color_select_z_events (GtkWidget *widet,
static void color_select_image_fill (GtkWidget *,
ColorSelectFillType,
gint *);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_select_draw_z_marker (ColorSelect *,
static void color_select_draw_z_marker (ColorSelect *csp,
GdkRectangle *);
static void color_select_draw_xy_marker (ColorSelect *,
static void color_select_draw_xy_marker (ColorSelect *csp,
GdkRectangle *);
static void color_select_update_red (ColorSelectFill *);
static void color_select_update_green (ColorSelectFill *);
static void color_select_update_blue (ColorSelectFill *);
static void color_select_update_hue (ColorSelectFill *);
static void color_select_update_saturation (ColorSelectFill *);
static void color_select_update_value (ColorSelectFill *);
static void color_select_update_red_green (ColorSelectFill *);
static void color_select_update_red_blue (ColorSelectFill *);
static void color_select_update_green_blue (ColorSelectFill *);
static void color_select_update_hue_saturation (ColorSelectFill *);
static void color_select_update_hue_value (ColorSelectFill *);
static void color_select_update_saturation_value (ColorSelectFill *);
static void color_select_update_red (ColorSelectFill *csf);
static void color_select_update_green (ColorSelectFill *csf);
static void color_select_update_blue (ColorSelectFill *csf);
static void color_select_update_hue (ColorSelectFill *csf);
static void color_select_update_saturation (ColorSelectFill *csf);
static void color_select_update_value (ColorSelectFill *csf);
static void color_select_update_red_green (ColorSelectFill *csf);
static void color_select_update_red_blue (ColorSelectFill *csf);
static void color_select_update_green_blue (ColorSelectFill *csf);
static void color_select_update_hue_saturation (ColorSelectFill *csf);
static void color_select_update_hue_value (ColorSelectFill *csf);
static void color_select_update_saturation_value (ColorSelectFill *csf);
static GtkWidget * color_select_notebook_new (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gboolean ,
static GtkWidget * color_select_notebook_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback,
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_set_color (gpointer ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint );
gpointer ,
gpointer *);
static void color_select_notebook_free (gpointer );
static void color_select_notebook_set_color (gpointer ,
const GimpHSV *hsv,
const GimpRGB *rgb);
static void color_select_notebook_set_channel (gpointer ,
GimpColorSelectorChannelType channel);
static void color_select_notebook_update_callback (gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gint ,
gpointer );
static void color_select_notebook_update_callback (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer );
/* Static variables */
static ColorSelectFillUpdateProc update_procs[] =
@ -251,11 +234,8 @@ color_select_init (void)
static GtkWidget *
color_select_widget_new (ColorSelect *csp,
gint r,
gint g,
gint b,
gint a)
color_select_widget_new (ColorSelect *csp,
const GimpRGB *color)
{
GtkWidget *main_vbox;
GtkWidget *main_hbox;
@ -330,16 +310,10 @@ color_select_drop_color (GtkWidget *widget,
gpointer data)
{
ColorSelect *csp;
guchar r, g, b, a;
csp = (ColorSelect *) data;
gimp_rgba_get_uchar (color, &r, &g, &b, &a);
csp->values[COLOR_SELECT_RED] = (gint) r;
csp->values[COLOR_SELECT_GREEN] = (gint) g;
csp->values[COLOR_SELECT_BLUE] = (gint) b;
csp->values[COLOR_SELECT_ALPHA] = (gint) a;
csp->rgb = *color;
color_select_update_hsv_values (csp);
color_select_update_pos (csp);
@ -351,25 +325,15 @@ color_select_drop_color (GtkWidget *widget,
}
static void
color_select_set_color (ColorSelect *csp,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
color_select_set_color (ColorSelect *csp,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
if (!csp)
if (! csp)
return;
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;
csp->hsv = *hsv;
csp->rgb = *rgb;
color_select_update_pos (csp);
@ -394,13 +358,15 @@ color_select_update (ColorSelect *csp,
if (update & UPDATE_XY_COLOR)
{
color_select_image_fill (csp->xy_color, csp->xy_color_fill, csp->values);
color_select_image_fill (csp->xy_color, csp->xy_color_fill,
&csp->hsv, &csp->rgb);
gtk_widget_draw (csp->xy_color, NULL);
}
if (update & UPDATE_Z_COLOR)
{
color_select_image_fill (csp->z_color, csp->z_color_fill, csp->values);
color_select_image_fill (csp->z_color, csp->z_color_fill,
&csp->hsv, &csp->rgb);
gtk_widget_draw (csp->z_color, NULL);
}
@ -413,13 +379,8 @@ color_select_update_caller (ColorSelect *csp)
{
if (csp && csp->callback)
{
(* 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],
(* csp->callback) (&csp->hsv,
&csp->rgb,
csp->client_data);
}
}
@ -433,34 +394,35 @@ color_select_update_values (ColorSelect *csp)
switch (csp->z_color_fill)
{
case COLOR_SELECT_RED:
csp->values[COLOR_SELECT_BLUE] = csp->pos[0];
csp->values[COLOR_SELECT_GREEN] = csp->pos[1];
csp->values[COLOR_SELECT_RED] = csp->pos[2];
csp->rgb.b = csp->pos[0] / 255.0;
csp->rgb.g = csp->pos[1] / 255.0;
csp->rgb.r = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_GREEN:
csp->values[COLOR_SELECT_BLUE] = csp->pos[0];
csp->values[COLOR_SELECT_RED] = csp->pos[1];
csp->values[COLOR_SELECT_GREEN] = csp->pos[2];
csp->rgb.b = csp->pos[0] / 255.0;
csp->rgb.r = csp->pos[1] / 255.0;
csp->rgb.g = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_BLUE:
csp->values[COLOR_SELECT_GREEN] = csp->pos[0];
csp->values[COLOR_SELECT_RED] = csp->pos[1];
csp->values[COLOR_SELECT_BLUE] = csp->pos[2];
csp->rgb.g = csp->pos[0] / 255.0;
csp->rgb.r = csp->pos[1] / 255.0;
csp->rgb.b = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_HUE:
csp->values[COLOR_SELECT_VALUE] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_SATURATION] = csp->pos[1] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[2] * 360 / 255;
csp->hsv.v = csp->pos[0] / 255.0;
csp->hsv.s = csp->pos[1] / 255.0;
csp->hsv.h = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_SATURATION:
csp->values[COLOR_SELECT_VALUE] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[1] * 360 / 255;
csp->values[COLOR_SELECT_SATURATION] = csp->pos[2] * 100 / 255;
csp->hsv.v = csp->pos[0] / 255.0;
csp->hsv.h = csp->pos[1] / 255.0;
csp->hsv.s = csp->pos[2] / 255.0;
break;
case COLOR_SELECT_VALUE:
csp->values[COLOR_SELECT_SATURATION] = csp->pos[0] * 100 / 255;
csp->values[COLOR_SELECT_HUE] = csp->pos[1] * 360 / 255;
csp->values[COLOR_SELECT_VALUE] = csp->pos[2] * 100 / 255;
csp->hsv.s = csp->pos[0] / 255.0;
csp->hsv.h = csp->pos[1] / 255.0;
csp->hsv.v = csp->pos[2] / 255.0;
break;
}
@ -471,6 +433,7 @@ color_select_update_values (ColorSelect *csp)
case COLOR_SELECT_BLUE:
color_select_update_hsv_values (csp);
break;
case COLOR_SELECT_HUE:
case COLOR_SELECT_SATURATION:
case COLOR_SELECT_VALUE:
@ -482,178 +445,59 @@ color_select_update_values (ColorSelect *csp)
static void
color_select_update_rgb_values (ColorSelect *csp)
{
gfloat h, s, v;
gfloat f, p, q, t;
if (!csp)
if (! csp)
return;
h = csp->values[COLOR_SELECT_HUE];
s = csp->values[COLOR_SELECT_SATURATION] / 100.0;
v = csp->values[COLOR_SELECT_VALUE] / 100.0;
if (s == 0)
{
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
}
else
{
if (h == 360)
h = 0;
h /= 60;
f = h - (int) h;
p = v * (1 - s);
q = v * (1 - (s * f));
t = v * (1 - (s * (1 - f)));
switch ((gint) h)
{
case 0:
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = t * 255;
csp->values[COLOR_SELECT_BLUE] = p * 255;
break;
case 1:
csp->values[COLOR_SELECT_RED] = q * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = p * 255;
break;
case 2:
csp->values[COLOR_SELECT_RED] = p * 255;
csp->values[COLOR_SELECT_GREEN] = v * 255;
csp->values[COLOR_SELECT_BLUE] = t * 255;
break;
case 3:
csp->values[COLOR_SELECT_RED] = p * 255;
csp->values[COLOR_SELECT_GREEN] = q * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
break;
case 4:
csp->values[COLOR_SELECT_RED] = t * 255;
csp->values[COLOR_SELECT_GREEN] = p * 255;
csp->values[COLOR_SELECT_BLUE] = v * 255;
break;
case 5:
csp->values[COLOR_SELECT_RED] = v * 255;
csp->values[COLOR_SELECT_GREEN] = p * 255;
csp->values[COLOR_SELECT_BLUE] = q * 255;
break;
}
}
gimp_hsv_to_rgb (&csp->hsv, &csp->rgb);
}
static void
color_select_update_hsv_values (ColorSelect *csp)
{
gint r, g, b;
gfloat h, s, v;
gint min, max;
gint delta;
if (!csp)
if (! csp)
return;
r = csp->values[COLOR_SELECT_RED];
g = csp->values[COLOR_SELECT_GREEN];
b = csp->values[COLOR_SELECT_BLUE];
if (r > g)
{
if (r > b)
max = r;
else
max = b;
if (g < b)
min = g;
else
min = b;
}
else
{
if (g > b)
max = g;
else
max = b;
if (r < b)
min = r;
else
min = b;
}
v = max;
if (max != 0)
s = (max - min) / (float) max;
else
s = 0;
if (s == 0)
{
h = 0;
}
else
{
h = 0;
delta = max - min;
if (r == max)
h = (g - b) / (float) delta;
else if (g == max)
h = 2 + (b - r) / (float) delta;
else if (b == max)
h = 4 + (r - g) / (float) delta;
h *= 60;
if (h < 0)
h += 360;
}
csp->values[COLOR_SELECT_HUE] = h;
csp->values[COLOR_SELECT_SATURATION] = s * 100;
csp->values[COLOR_SELECT_VALUE] = v * 100 / 255;
gimp_rgb_to_hsv (&csp->rgb, &csp->hsv);
}
static void
color_select_update_pos (ColorSelect *csp)
{
if (!csp)
if (! csp)
return;
switch (csp->z_color_fill)
{
case COLOR_SELECT_RED:
csp->pos[0] = csp->values[COLOR_SELECT_BLUE];
csp->pos[1] = csp->values[COLOR_SELECT_GREEN];
csp->pos[2] = csp->values[COLOR_SELECT_RED];
csp->pos[0] = (gint) (csp->rgb.b * 255.999);
csp->pos[1] = (gint) (csp->rgb.g * 255.999);
csp->pos[2] = (gint) (csp->rgb.r * 255.999);
break;
case COLOR_SELECT_GREEN:
csp->pos[0] = csp->values[COLOR_SELECT_BLUE];
csp->pos[1] = csp->values[COLOR_SELECT_RED];
csp->pos[2] = csp->values[COLOR_SELECT_GREEN];
csp->pos[0] = (gint) (csp->rgb.b * 255.999);
csp->pos[1] = (gint) (csp->rgb.r * 255.999);
csp->pos[2] = (gint) (csp->rgb.g * 255.999);
break;
case COLOR_SELECT_BLUE:
csp->pos[0] = csp->values[COLOR_SELECT_GREEN];
csp->pos[1] = csp->values[COLOR_SELECT_RED];
csp->pos[2] = csp->values[COLOR_SELECT_BLUE];
csp->pos[0] = (gint) (csp->rgb.g * 255.999);
csp->pos[1] = (gint) (csp->rgb.r * 255.999);
csp->pos[2] = (gint) (csp->rgb.b * 255.999);
break;
case COLOR_SELECT_HUE:
csp->pos[0] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[2] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[0] = (gint) (csp->hsv.v * 255.999);
csp->pos[1] = (gint) (csp->hsv.s * 255.999);
csp->pos[2] = (gint) (csp->hsv.h * 255.999);
break;
case COLOR_SELECT_SATURATION:
csp->pos[0] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[2] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[0] = (gint) (csp->hsv.v * 255.999);
csp->pos[1] = (gint) (csp->hsv.h * 255.999);
csp->pos[2] = (gint) (csp->hsv.s * 255.999);
break;
case COLOR_SELECT_VALUE:
csp->pos[0] = csp->values[COLOR_SELECT_SATURATION] * 255 / 100;
csp->pos[1] = csp->values[COLOR_SELECT_HUE] * 255 / 360;
csp->pos[2] = csp->values[COLOR_SELECT_VALUE] * 255 / 100;
csp->pos[0] = (gint) (csp->hsv.s * 255.999);
csp->pos[1] = (gint) (csp->hsv.h * 255.999);
csp->pos[2] = (gint) (csp->hsv.v * 255.999);
break;
}
}
@ -663,7 +507,7 @@ color_select_xy_expose (GtkWidget *widget,
GdkEventExpose *event,
ColorSelect *csp)
{
if (!csp->gc)
if (! csp->gc)
csp->gc = gdk_gc_new (widget->window);
color_select_draw_xy_marker (csp, &event->area);
@ -701,7 +545,7 @@ color_select_xy_events (GtkWidget *widget,
gdk_pointer_grab (csp->xy_color->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
color_select_draw_xy_marker (csp, NULL);
@ -795,10 +639,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (bevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
gdk_pointer_grab (csp->z_color->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
@ -815,10 +657,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (bevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
gdk_pointer_ungrab (bevent->time);
color_select_draw_z_marker (csp, NULL);
@ -837,10 +677,8 @@ color_select_z_events (GtkWidget *widget,
color_select_draw_z_marker (csp, NULL);
csp->pos[2] = 255 - (mevent->y * 255) / (Z_DEF_HEIGHT - 1);
if (csp->pos[2] < 0)
csp->pos[2] = 0;
if (csp->pos[2] > 255)
csp->pos[2] = 255;
csp->pos[2] = CLAMP (csp->pos[2], 0, 255);
color_select_draw_z_marker (csp, NULL);
color_select_update (csp, UPDATE_VALUES | UPDATE_CALLER);
@ -857,7 +695,7 @@ static void
color_select_set_channel (ColorSelect *csp,
GimpColorSelectorChannelType type)
{
if (!csp)
if (! csp)
return;
switch ((ColorSelectFillType) type)
@ -897,7 +735,8 @@ color_select_set_channel (ColorSelect *csp,
static void
color_select_image_fill (GtkWidget *preview,
ColorSelectFillType type,
gint *values)
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelectFill csf;
gint height;
@ -909,7 +748,8 @@ color_select_image_fill (GtkWidget *preview,
csf.y = -1;
csf.width = preview->requisition.width;
csf.height = preview->requisition.height;
csf.values = values;
csf.hsv = *hsv;
csf.rgb = *rgb;
height = csf.height;
if (height > 0)
@ -1085,14 +925,9 @@ color_select_update_hue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
h = csf->y * 360 / csf->height;
h = csf->y * 360.0 / csf->height;
h = 360 - h;
if (h < 0)
h = 0;
if (h >= 360)
h = 0;
h = CLAMP (360 - h, 0, 360);
h /= 60;
f = (h - (int) h) * 255;
@ -1205,7 +1040,7 @@ color_select_update_red_green (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
b = csf->values[COLOR_SELECT_BLUE];
b = (gint) (csf->rgb.b * 255.999);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0)
@ -1236,7 +1071,7 @@ color_select_update_red_blue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
g = csf->values[COLOR_SELECT_GREEN];
g = (gint) (csf->rgb.g * 255.999);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0)
@ -1267,7 +1102,7 @@ color_select_update_green_blue (ColorSelectFill *csf)
p = csf->buffer;
csf->y += 1;
r = csf->values[COLOR_SELECT_RED];
r = (gint) (csf->rgb.r * 255.999);
g = (csf->height - csf->y + 1) * 255 / csf->height;
if (g < 0)
@ -1312,7 +1147,7 @@ color_select_update_hue_saturation (ColorSelectFill *csf)
s = 0;
ds = 1.0 / csf->width;
v = csf->values[COLOR_SELECT_VALUE] / 100.0;
v = csf->hsv.v;
switch ((int) h)
{
@ -1403,7 +1238,7 @@ color_select_update_hue_value (ColorSelectFill *csf)
v = 0;
dv = 1.0 / csf->width;
s = csf->values[COLOR_SELECT_SATURATION] / 100.0;
s = csf->hsv.s;
switch ((int) h)
{
@ -1490,7 +1325,7 @@ color_select_update_saturation_value (ColorSelectFill *csf)
s = 1 - s;
h = (gfloat) csf->values[COLOR_SELECT_HUE];
h = (gfloat) csf->hsv.h * 360.0;
if (h >= 360)
h -= 360;
h /= 60;
@ -1577,13 +1412,8 @@ typedef struct
} notebook_glue;
static GtkWidget *
color_select_notebook_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
color_select_notebook_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer data,
@ -1607,20 +1437,14 @@ color_select_notebook_new (gint h,
csp->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
csp->gc = NULL;
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;
csp->hsv = *hsv;
csp->rgb = *rgb;
color_select_update_pos (csp);
glue->main_vbox = color_select_widget_new (csp, r, g, b, a);
glue->main_vbox = color_select_widget_new (csp, rgb);
color_select_image_fill (csp->z_color, csp->z_color_fill, csp->values);
color_select_image_fill (csp->xy_color, csp->xy_color_fill, csp->values);
color_select_update (csp, UPDATE_XY_COLOR | UPDATE_Z_COLOR);
*selector_data = glue;
@ -1642,20 +1466,14 @@ color_select_notebook_free (gpointer data)
g_free (glue);
}
static void
color_select_notebook_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
color_select_notebook_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
notebook_glue *glue = data;
color_select_set_color (glue->csp, h, s, v, r, g, b, a);
color_select_set_color (glue->csp, hsv, rgb);
}
static void
@ -1668,16 +1486,11 @@ color_select_notebook_set_channel (gpointer data,
}
static void
color_select_notebook_update_callback (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
gpointer data)
color_select_notebook_update_callback (const GimpHSV *hsv,
const GimpRGB *rgb,
gpointer data)
{
notebook_glue *glue = data;
glue->callback (glue->client_data, h, s, v, r, g, b, a);
glue->callback (glue->client_data, hsv, rgb);
}

View File

@ -26,35 +26,25 @@
#include "gimpmodregister.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpcolor.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpintl.h"
/* prototypes */
static GtkWidget * colorsel_gtk_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
static GtkWidget * colorsel_gtk_new (const GimpHSV *hsv,
const GimpRGB *rgb,
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);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void colorsel_gtk_set_channel (gpointer data,
GimpColorSelectorChannelType channel);
static void colorsel_gtk_update (GtkWidget *widget,
@ -136,13 +126,8 @@ typedef struct
static GtkWidget *
colorsel_gtk_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
colorsel_gtk_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer data,
@ -164,7 +149,7 @@ colorsel_gtk_new (gint h,
gtk_widget_hide (GTK_COLOR_SELECTION (p->selector)->scales[0]->parent);
colorsel_gtk_set_color (p, h, s, v, r, g, b, a);
colorsel_gtk_set_color (p, hsv, rgb);
/* EEK: to be removed */
gtk_signal_connect_object_after
@ -202,23 +187,18 @@ 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)
colorsel_gtk_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorselGtk *p = data;
gdouble color[4];
color[0] = ((gdouble) r) / 255.999;
color[1] = ((gdouble) g) / 255.999;
color[2] = ((gdouble) b) / 255.999;
color[3] = ((gdouble) a) / 255.999;
color[0] = rgb->r;
color[1] = rgb->g;
color[2] = rgb->b;
color[3] = rgb->a;
gtk_color_selection_set_color (GTK_COLOR_SELECTION (p->selector), color);
}
@ -234,29 +214,20 @@ colorsel_gtk_update (GtkWidget *widget,
gpointer data)
{
ColorselGtk *p = data;
gint h;
gint s;
gint v;
gint r;
gint g;
gint b;
gint a;
GimpHSV hsv;
GimpRGB rgb;
gdouble color[4];
gtk_color_selection_get_color (GTK_COLOR_SELECTION (p->selector), color);
r = (gint) (color[0] * 255.999);
g = (gint) (color[1] * 255.999);
b = (gint) (color[2] * 255.999);
a = (gint) (color[3] * 255.999);
rgb.r = color[0];
rgb.g = color[1];
rgb.b = color[2];
rgb.a = color[3];
gimp_rgb_to_hsv_double (&color[0], &color[1], &color[2]);
gimp_rgb_to_hsv (&rgb, &hsv);
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);
p->callback (p->client_data, &hsv, &rgb);
}
/* EEK */

View File

@ -27,23 +27,18 @@
#include "gimpmodregister.h"
#include <libgimp/gimpcolorselector.h>
#include <libgimp/gimpcolor.h>
#include <libgimp/gimpcolorspace.h>
#include <libgimp/gimpmodule.h>
#include <libgimp/gimpmath.h>
#include "libgimp/gimpcolor.h"
#include "libgimp/gimpcolorspace.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpmath.h"
#include "libgimp/gimpintl.h"
/* prototypes */
static GtkWidget * colorsel_triangle_new (gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha,
static GtkWidget * colorsel_triangle_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer callback_data,
@ -52,13 +47,8 @@ static GtkWidget * colorsel_triangle_new (gint hue,
static void colorsel_triangle_free (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);
const GimpHSV *hsv,
const GimpRGB *rgb);
static void colorsel_triangle_set_channel (gpointer selector_data,
GimpColorSelectorChannelType channel);
@ -113,7 +103,9 @@ typedef enum
struct _ColorSelect
{
gint values[7];
GimpHSV hsv;
GimpRGB rgb;
gdouble oldsat;
gdouble oldval;
gint mode;
@ -132,10 +124,6 @@ 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);
*/
/*************************************************************/
@ -179,13 +167,8 @@ module_unload (gpointer shutdown_data,
/* methods */
static GtkWidget *
colorsel_triangle_new (gint hue,
gint saturation,
gint value,
gint red,
gint green,
gint blue,
gint alpha,
colorsel_triangle_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer callback_data,
@ -199,13 +182,9 @@ colorsel_triangle_new (gint hue,
GtkWidget *vbox;
coldata = g_new (ColorSelect, 1);
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->hsv = *hsv;
coldata->rgb = *rgb;
coldata->oldsat = 0;
coldata->oldval = 0;
@ -242,26 +221,16 @@ colorsel_triangle_free (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)
colorsel_triangle_set_color (gpointer selector_data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorSelect *coldata;
coldata = selector_data;
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->hsv = *hsv;
coldata->rgb = *rgb;
update_previews (coldata, TRUE);
}
@ -278,201 +247,240 @@ colorsel_triangle_set_channel (gpointer selector_data,
static void
color_select_update_rgb_values (ColorSelect *csp)
{
csp->values[RED] = RINT (((gdouble) csp->values[HUE]) / 360.0 * 255);
csp->values[GREEN] = RINT (((gdouble) csp->values[SATURATION]) / 100.0 * 255);
csp->values[BLUE] = RINT (((gdouble) csp->values[VALUE]) / 100.0 * 255);
gimp_hsv_to_rgb_int (&(csp->values[RED]),
&(csp->values[GREEN]),
&(csp->values[BLUE]));
gimp_hsv_to_rgb (&csp->hsv, &csp->rgb);
}
/*
static void
color_select_update_hsv_values (ColorSelect *csp)
{
gdouble hue, sat, val;
hue = (gdouble) csp->values[RED] / 255;
sat = (gdouble) csp->values[GREEN] / 255;
val = (gdouble) csp->values[BLUE] / 255;
gimp_rgb_to_hsv_double (&hue, &sat, &val);
csp->values[HUE] = RINT (hue * 360);
csp->values[SATURATION] = RINT (sat * 100);
csp->values[VALUE] = RINT (val * 100);
}
*/
static void
update_previews (ColorSelect *coldata,
gint hue_changed)
{
GtkWidget *preview;
guchar buf[3*PREVIEWSIZE];
guchar buf[3 * PREVIEWSIZE];
gint x, y, k, r2, dx, col;
gint x0, y0;
gdouble hue, sat, val, s, v, atn;
gint hx,hy, sx,sy, vx,vy;
hue = (gdouble) coldata->values[HUE] * G_PI / 180;
hue = (gdouble) coldata->hsv.h * 2 * G_PI;
hx = sin (hue) * COLORTRIANGLERADIUS;
hy = cos (hue) * COLORTRIANGLERADIUS;
sx = sin (hue - 2 * G_PI/3) * COLORTRIANGLERADIUS;
sy = cos (hue - 2 * G_PI/3) * COLORTRIANGLERADIUS;
sx = sin (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
sy = cos (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vx = sin (hue + 2 * G_PI/3) * COLORTRIANGLERADIUS;
vy = cos (hue + 2 * G_PI/3) * COLORTRIANGLERADIUS;
vx = sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vy = cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
hue = (gdouble) coldata->values[HUE];
hue = coldata->hsv.h * 360.0;
preview = coldata->preview;
if (hue_changed) {
for (y = COLORWHEELRADIUS; y > -COLORWHEELRADIUS; y--) {
dx = RINT (sqrt (fabs ((COLORWHEELRADIUS) * (COLORWHEELRADIUS) - y * y)));
for (x = -dx, k = 0; x <= dx; x++) {
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
r2 = (x * x) + (y * y);
if ( r2 <= COLORWHEELRADIUS * COLORWHEELRADIUS) {
if (r2 > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS) {
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
} else {
val = (gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
(gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (hue_changed)
{
for (y = COLORWHEELRADIUS; y > -COLORWHEELRADIUS; y--)
{
dx = RINT (sqrt (fabs ((COLORWHEELRADIUS) * (COLORWHEELRADIUS) - y * y)));
for (x = -dx, k = 0; x <= dx; x++)
{
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
r2 = (x * x) + (y * y);
if ( r2 <= COLORWHEELRADIUS * COLORWHEELRADIUS)
{
if (r2 > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS)
{
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
}
else
{
val =
(gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
(gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (val >= 0 && val<= 1) { /* normally val>=0, but this results in
graphics errors... */
sat = (val == 0 ? 0: ((gdouble) (y - sy - val * (vy - sy)) /
(val * (gdouble) (hy - vy))));
if (sat >= 0 && sat <= 1)
gimp_hsv_to_rgb4 (buf + k, hue / 360, sat, val);
}
}
}
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, COLORWHEELRADIUS - dx,
COLORWHEELRADIUS - y - 1, 2 * dx + 1);
}
if (val >= 0 && val<= 1)
{
/* normally val>=0, but this results in
graphics errors... */
sat =
(val == 0 ? 0: ((gdouble) (y - sy - val * (vy - sy)) /
(val * (gdouble) (hy - vy))));
if (sat >= 0 && sat <= 1)
gimp_hsv_to_rgb4 (buf + k, hue / 360, sat, val);
}
}
}
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
COLORWHEELRADIUS - dx,
COLORWHEELRADIUS - y - 1, 2 * dx + 1);
}
/* marker in outer ring */
/* marker in outer ring */
x0 = RINT (sin (hue * G_PI/180) *
((gdouble) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1) / 2 +
COLORTRIANGLERADIUS) + 0.5);
y0 = RINT (cos (hue * G_PI/180) *
((gdouble) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1) / 2 +
x0 = RINT (sin (hue * G_PI / 180) *
((gdouble) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1) / 2 +
COLORTRIANGLERADIUS) + 0.5);
y0 = RINT (cos (hue * G_PI / 180) *
((gdouble) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1) / 2 +
COLORTRIANGLERADIUS) + 0.5);
atn = atan2 (x0, y0);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf, atn / (2 * G_PI), 1, 1);
atn = atan2 (x0, y0);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf, atn / (2 * G_PI), 1, 1);
col = INTENSITY (buf[0], buf[1], buf[2]) > 127 ? 0 : 255 ;
col = INTENSITY (buf[0], buf[1], buf[2]) > 127 ? 0 : 255;
for (y = y0 - 4 ; y <= y0 + 4 ; y++) {
for (x = x0 - 4, k=0 ; x <= x0 + 4 ; x++) {
r2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
if (r2 <= 20 && r2 >= 6) {
buf[k] = buf[k+1] = buf[k+2] = col;
} else {
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
for (y = y0 - 4 ; y <= y0 + 4 ; y++)
{
for (x = x0 - 4, k=0 ; x <= x0 + 4 ; x++)
{
r2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
if (r2 <= 20 && r2 >= 6)
{
buf[k] = buf[k+1] = buf[k+2] = col;
}
else
{
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
}
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
COLORWHEELRADIUS + x0-4,
COLORWHEELRADIUS - 1 - y, 9);
}
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
COLORWHEELRADIUS + x0-4,
COLORWHEELRADIUS - 1 - y, 9);
}
else
{
/* delete marker in triangle */
} else {
/* delete marker in triangle */
s = coldata->oldsat;
v = coldata->oldval;
x0 = RINT (sx + (vx - sx) * v + (hx - vx) * s * v);
y0 = RINT (sy + (vy - sy) * v + (hy - vy) * s * v);
for (y = y0 - 4 ; y <= y0 + 4 ; y++) {
for (x = x0 - 4, k=0 ; x <= x0 + 4 ; x++) {
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
r2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
if (x * x + y * y > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS) {
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
} else {
val = (gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
(gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (val > 0 && val <= 1) { /* eigentlich val>=0, aber dann Grafikfehler... */
sat = (val == 0 ? 0 : ((gdouble) (y - sy - val * (vy - sy)) /
(val * (gdouble) (hy - vy))));
if (sat >= 0 && sat <= 1)
gimp_hsv_to_rgb4 (buf + k, hue / 360, sat, val);
}
}
k += 3;
}
s = coldata->oldsat;
v = coldata->oldval;
x0 = RINT (sx + (vx - sx) * v + (hx - vx) * s * v);
y0 = RINT (sy + (vy - sy) * v + (hy - vy) * s * v);
for (y = y0 - 4 ; y <= y0 + 4 ; y++)
{
for (x = x0 - 4, k=0 ; x <= x0 + 4 ; x++)
{
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
r2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
if (x * x + y * y > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS)
{
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
}
else
{
val =
(gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
(gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (val > 0 && val <= 1)
{
/* eigentlich val>=0, aber dann Grafikfehler... */
sat =
(val == 0 ? 0 : ((gdouble) (y - sy - val * (vy - sy)) /
(val * (gdouble) (hy - vy))));
if (sat >= 0 && sat <= 1)
gimp_hsv_to_rgb4 (buf + k, hue / 360, sat, val);
}
}
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
COLORWHEELRADIUS + x0 - 4,
COLORWHEELRADIUS - 1 - y, 9);
}
coldata->oldsat = coldata->hsv.s;
coldata->oldval = coldata->hsv.v;
}
/* marker in triangle */
col = gimp_rgb_intensity (&coldata->rgb) > 0.5 ? 0 : 255;
s = coldata->hsv.s;
v = coldata->hsv.v;
coldata->oldsat = s;
coldata->oldval = v;
x0 = RINT (sx + (vx - sx) * v + (hx - vx) * s * v);
y0 = RINT (sy + (vy - sy) * v + (hy - vy) * s * v);
for (y = y0 - 4 ; y <= y0 + 4 ; y++)
{
for (x = x0 - 4, k=0 ; x <= x0 + 4 ; x++)
{
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
r2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
if (r2 <= 20 && r2 >= 6)
{
buf[k] = buf[k+1] = buf[k+2] = col;
}
else
{
if (x * x + y * y > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS)
{
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
}
else
{
val =
(gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
(gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (val > 0 && val <= 1)
{
/* eigentlich val>=0, aber dann Grafikfehler... */
sat =
(val == 0 ? 0 : ((gdouble) (y - sy - val * (vy - sy)) /
(val * (gdouble) (hy - vy))));
if (sat >= 0 && sat <= 1)
gimp_hsv_to_rgb4 (buf + k, hue / 360, sat, val);
}
}
}
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
COLORWHEELRADIUS + x0 - 4,
COLORWHEELRADIUS - 1 - y, 9);
}
coldata->oldsat = coldata->values[SATURATION] / 100.0;
coldata->oldval = coldata->values[VALUE] / 100.0;
}
/* marker in triangle */
col = INTENSITY (coldata->values[RED], coldata->values[GREEN],
coldata->values[BLUE]) > 127 ? 0 : 255 ;
s = coldata->values[SATURATION] / 100.0;
v = coldata->values[VALUE] / 100.0;
coldata->oldsat = s;
coldata->oldval = v;
x0 = RINT (sx + (vx - sx) * v + (hx - vx) * s * v);
y0 = RINT (sy + (vy - sy) * v + (hy - vy) * s * v);
for (y = y0 - 4 ; y <= y0 + 4 ; y++) {
for (x = x0 - 4, k=0 ; x <= x0 + 4 ; x++) {
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
r2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
if (r2 <= 20 && r2 >= 6) {
buf[k] = buf[k+1] = buf[k+2] = col;
} else {
if (x * x + y * y > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS) {
atn = atan2 (x, y);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf + k, atn / (2 * G_PI), 1, 1);
} else {
val = (gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
(gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (val > 0 && val <= 1) { /* eigentlich val>=0, aber dann Grafikfehler... */
sat = (val == 0 ? 0 : ((gdouble) (y - sy - val * (vy - sy)) /
(val * (gdouble) (hy - vy))));
if (sat >= 0 && sat <= 1)
gimp_hsv_to_rgb4 (buf + k, hue / 360, sat, val);
}
}
}
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
COLORWHEELRADIUS + x0 - 4,
COLORWHEELRADIUS - 1 - y, 9);
}
gtk_widget_draw (preview, NULL);
}
@ -493,7 +501,8 @@ color_selection_callback (GtkWidget *widget,
coldata = gtk_object_get_user_data (GTK_OBJECT (widget));
switch (event->type) {
switch (event->type)
{
case GDK_BUTTON_PRESS:
gtk_grab_add (widget);
x = event->button.x - COLORWHEELRADIUS - 1;
@ -519,13 +528,8 @@ color_selection_callback (GtkWidget *widget,
/* callback the user */
(* 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]);
&coldata->hsv,
&coldata->rgb);
return FALSE;
break;
@ -537,7 +541,7 @@ color_selection_callback (GtkWidget *widget,
r = sqrt ((gdouble) (x * x + y * y));
angle = ((gint) RINT (atan2 (x, y) / G_PI * 180) + 360 ) % 360;
break;
}
}
gtk_widget_get_pointer (widget, &mousex, &mousey);
if ((event->type == GDK_MOTION_NOTIFY &&
@ -546,77 +550,85 @@ color_selection_callback (GtkWidget *widget,
if (coldata->mode == 1 ||
(r > COLORWHEELRADIUS &&
(abs (angle - coldata->values[HUE]) < 30 ||
abs (abs (angle - coldata->values[HUE]) - 360) < 30))) {
coldata->values[HUE] = angle;
color_select_update_rgb_values (coldata);
update_previews (coldata, TRUE);
} else {
hue = (gdouble) coldata->values[HUE] * G_PI / 180;
hx = sin (hue) * COLORTRIANGLERADIUS;
hy = cos (hue) * COLORTRIANGLERADIUS;
sx = sin (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
sy = cos (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vx = sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vy = cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
hue = (gdouble) coldata->values[HUE];
if ((x - sx) * vx + (y - sy) * vy < 0) {
sat = 1;
val = ((gdouble) ( (x - sx) * (hx - sx) + (y - sy) * (hy - sy)))
/ ((hx - sx) * (hx - sx) + (hy - sy) * (hy - sy));
if (val < 0)
val = 0;
else if (val > 1)
val = 1;
} else
if ((x - sx) * hx + (y - sy) * hy < 0) {
sat = 0;
val = ((gdouble) ( (x - sx) * (vx - sx) + (y - sy) * (vy - sy)))
/ ((vx - sx) * (vx - sx) + (vy - sy) * (vy - sy));
if (val < 0)
val = 0;
else if (val > 1)
val = 1;
} else if ((x - hx) * sx + (y - hy) * sy < 0) {
val = 1;
sat = ((gdouble) ( (x - vx) * (hx - vx) + (y - vy) * (hy - vy)))
/ ((hx - vx) * (hx - vx) + (hy - vy) * (hy - vy));
if (sat < 0)
sat = 0;
else if (sat > 1)
sat = 1;
} else {
val = (gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx))
/ (gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (val <= 0) {
val = 0;
sat = 0;
} else {
if (val > 1)
val = 1;
sat = (gdouble) (y - sy - val * (vy - sy)) / (val * (gdouble) (hy - vy));
if (sat < 0)
sat = 0;
else if (sat > 1)
sat = 1;
}
(abs (angle - coldata->hsv.h * 260.0) < 30 ||
abs (abs (angle - coldata->hsv.h * 360.0) - 360) < 30)))
{
coldata->hsv.h = angle / 360.0;
color_select_update_rgb_values (coldata);
update_previews (coldata, TRUE);
}
else
{
hue = coldata->hsv.h * 2 * G_PI;
hx = sin (hue) * COLORTRIANGLERADIUS;
hy = cos (hue) * COLORTRIANGLERADIUS;
sx = sin (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
sy = cos (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vx = sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vy = cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
hue = coldata->hsv.h * 360.0;
coldata->values[SATURATION] = 100 * sat + 0.5;
coldata->values[VALUE] = 100 * val + 0.5;
if ((x - sx) * vx + (y - sy) * vy < 0)
{
sat = 1;
val = ((gdouble) ( (x - sx) * (hx - sx) + (y - sy) * (hy - sy)))
/ ((hx - sx) * (hx - sx) + (hy - sy) * (hy - sy));
if (val < 0)
val = 0;
else if (val > 1)
val = 1;
}
else if ((x - sx) * hx + (y - sy) * hy < 0)
{
sat = 0;
val = ((gdouble) ( (x - sx) * (vx - sx) + (y - sy) * (vy - sy)))
/ ((vx - sx) * (vx - sx) + (vy - sy) * (vy - sy));
if (val < 0)
val = 0;
else if (val > 1)
val = 1;
}
else if ((x - hx) * sx + (y - hy) * sy < 0)
{
val = 1;
sat = ((gdouble) ( (x - vx) * (hx - vx) + (y - vy) * (hy - vy)))
/ ((hx - vx) * (hx - vx) + (hy - vy) * (hy - vy));
if (sat < 0)
sat = 0;
else if (sat > 1)
sat = 1;
}
else
{
val = (gdouble) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx))
/ (gdouble) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
if (val <= 0)
{
val = 0;
sat = 0;
}
else
{
if (val > 1)
val = 1;
sat = (gdouble) (y - sy - val * (vy - sy)) / (val * (gdouble) (hy - vy));
if (sat < 0)
sat = 0;
else if (sat > 1)
sat = 1;
}
}
coldata->hsv.s = sat;
coldata->hsv.v = val;
color_select_update_rgb_values (coldata);
update_previews (coldata, FALSE);
}
/* callback the user */
(* 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]);
&coldata->hsv,
&coldata->rgb);
return FALSE;
}

View File

@ -25,9 +25,9 @@
#include <gtk/gtk.h>
#include <libgimp/gimpcolorselector.h>
#include <libgimp/gimpcolor.h>
#include <libgimp/gimpcolorspace.h>
#include <libgimp/gimpcolorselector.h>
#include <libgimp/gimpmodule.h>
#include <libgimp/gimpmath.h>
@ -36,27 +36,17 @@
#include <libgimp/gimpintl.h>
/* prototypes */
static GtkWidget * colorsel_water_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
static GtkWidget * colorsel_water_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback,
gpointer,
gpointer *);
static void colorsel_water_free (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,
gpointer ,
gpointer *);
static void colorsel_water_free (gpointer data);
static void colorsel_water_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb);
static void colorsel_water_set_channel (gpointer data,
GimpColorSelectorChannelType channel);
static void colorsel_water_update (void);
static void colorsel_water_drag_begin (GtkWidget *widget,
@ -345,7 +335,7 @@ select_area_draw (GtkWidget *preview)
}
static void
static void
add_pigment (gboolean erase,
gdouble x,
gdouble y,
@ -412,7 +402,6 @@ draw_brush (GtkWidget *widget,
last_pressure = pressure;
}
static gint
button_press_event (GtkWidget *widget,
GdkEventButton *event)
@ -564,13 +553,8 @@ pressure_adjust_update (GtkAdjustment *adj,
static GtkWidget*
colorsel_water_new (gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a,
colorsel_water_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer callback_data,
@ -760,7 +744,7 @@ colorsel_water_new (gint h,
gtk_widget_show_all (hbox);
colorsel_water_set_color (coldata, h, s, v, r, g, b, a);
colorsel_water_set_color (coldata, hsv, rgb);
draw_all_buckets ();
return vbox;
@ -774,20 +758,15 @@ colorsel_water_free (gpointer selector_data)
}
static void
colorsel_water_set_color (gpointer data,
gint h,
gint s,
gint v,
gint r,
gint g,
gint b,
gint a)
colorsel_water_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
set_bucket (0,
((gdouble) r) / 255.999,
((gdouble) g) / 255.999,
((gdouble) b) / 255.999,
((gdouble) a) / 255.999);
rgb->r,
rgb->g,
rgb->b,
rgb->a);
draw_bucket (0);
}
@ -801,36 +780,19 @@ colorsel_water_set_channel (gpointer data,
static void
colorsel_water_update (void)
{
gdouble rr;
gdouble gg;
gdouble bb;
GimpRGB rgb;
GimpHSV hsv;
gint h;
gint s;
gint v;
gint r;
gint g;
gint b;
gint a;
rgb.r = bucket[0][0];
rgb.g = bucket[0][1];
rgb.b = bucket[0][2];
rgb.a = bucket[0][3];
r = (gint) (bucket[0][0] * 255.999);
g = (gint) (bucket[0][1] * 255.999);
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);
gimp_rgb_to_hsv (&rgb, &hsv);
draw_bucket (0);
coldata->callback (coldata->data, h, s, v, r, g, b, a);
coldata->callback (coldata->data, &hsv, &rgb);
}
static void
@ -900,10 +862,10 @@ colorsel_water_drop_handle (GtkWidget *widget,
vals = (guint16 *) selection_data->data;
colors[0] = (gdouble)vals[0] / 0xffff;
colors[1] = (gdouble)vals[1] / 0xffff;
colors[2] = (gdouble)vals[2] / 0xffff;
colors[3] = (gdouble)vals[3] / 0xffff;
colors[0] = (gdouble) vals[0] / 0xffff;
colors[1] = (gdouble) vals[1] / 0xffff;
colors[2] = (gdouble) vals[2] / 0xffff;
colors[3] = (gdouble) vals[3] / 0xffff;
draw_all_buckets ();
colorsel_water_update ();
@ -931,10 +893,3 @@ colorsel_water_drag_handle (GtkWidget *widget,
gdk_atom_intern ("application/x-color", FALSE),
16, (guchar *)vals, 8);
}