the color scales from the main color selection as GimpColorSelector

2002-10-28  Michael Natterer  <mitch@gimp.org>

	* libgimpwidgets/gimpcolorscales.[ch]: the color scales from
	the main color selection as GimpColorSelector subclass.

	* libgimpwidgets/Makefile.am
	* libgimpwidgets/gimpwidgets.h
	* libgimpwidgets/gimpwidgetsmarshal.list
	* libgimpwidgets/gimpwidgetstypes.h: changed accordingly.

	* libgimpwidgets/gimpcolornotebook.c: skip it when iterating the
	GimpColorSelector subclasses.

	* libgimpwidgets/gimpcolorselector.[ch]: added virtual function
	set_has_alpha() amd signal "channel_changed". Put RGB, HSV and
	channel values into to the GimpColorSelector struct where they are
	available for subclasses.

	* libgimpwidgets/gimpcolorselect.[ch]
	* modules/colorsel_triangle.c
	* modules/colorsel_water.c: changed accordingly, cleanup.

	* app/gui/color-notebook.[ch]: use the new GimpColorScales widget,
	lots of cleanup.

2002-10-28  Michael Natterer  <mitch@gimp.org>

	* libgimpwidgets/tmpl/gimpcolorscales.sgml: added GimpColorScales.

	* libgimpwidgets/libgimpwidgets-docs.sgml
	* libgimpwidgets/libgimpwidgets-sections.txt
	* libgimpwidgets/libgimpwidgets.types
	* libgimpwidgets/tmpl/gimpcolorselect.sgml
	* libgimpwidgets/tmpl/gimpcolorselector.sgml; updated.
This commit is contained in:
Michael Natterer
2002-10-28 20:13:17 +00:00
committed by Michael Natterer
parent dcb5f7b2da
commit 8945226142
27 changed files with 1776 additions and 1884 deletions

View File

@ -61,9 +61,6 @@ struct _ColorselTriangle
{
GimpColorSelector parent_instance;
GimpHSV hsv;
GimpRGB rgb;
gdouble oldsat;
gdouble oldval;
gint mode;
@ -190,9 +187,6 @@ colorsel_triangle_init (ColorselTriangle *triangle)
GtkWidget *frame;
GtkWidget *hbox;
gimp_rgba_set (&triangle->rgb, 1.0, 1.0, 1.0, 1.0);
gimp_rgb_to_hsv (&triangle->rgb, &triangle->hsv);
triangle->oldsat = 0;
triangle->oldval = 0;
triangle->mode = 0;
@ -232,9 +226,6 @@ colorsel_triangle_set_color (GimpColorSelector *selector,
triangle = COLORSEL_TRIANGLE (selector);
triangle->rgb = *rgb;
triangle->hsv = *hsv;
colorsel_triangle_update_previews (triangle, TRUE);
}
@ -272,13 +263,16 @@ static void
colorsel_triangle_update_previews (ColorselTriangle *triangle,
gboolean hue_changed)
{
guchar buf[3 * PREVIEWSIZE];
gint x, y, k, r2, dx, col;
gint x0, y0;
gdouble hue, sat, val, atn;
gint hx,hy, sx,sy, vx,vy;
GimpColorSelector *selector;
guchar buf[3 * PREVIEWSIZE];
gint x, y, k, r2, dx, col;
gint x0, y0;
gdouble hue, sat, val, atn;
gint hx,hy, sx,sy, vx,vy;
hue = (gdouble) triangle->hsv.h * 2 * G_PI;
selector = GIMP_COLOR_SELECTOR (triangle);
hue = (gdouble) selector->hsv.h * 2 * G_PI;
/* Colored point (value = 1, saturation = 1) */
hx = RINT (sin (hue) * COLORTRIANGLERADIUS);
@ -292,7 +286,7 @@ colorsel_triangle_update_previews (ColorselTriangle *triangle,
vx = RINT (sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS);
vy = RINT (cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS);
hue = triangle->hsv.h * 360.0;
hue = selector->hsv.h * 360.0;
if (hue_changed)
{
@ -408,10 +402,10 @@ colorsel_triangle_update_previews (ColorselTriangle *triangle,
/* marker in triangle */
col = gimp_rgb_intensity (&triangle->rgb) > 0.5 ? 0 : 255;
col = gimp_rgb_intensity (&selector->rgb) > 0.5 ? 0 : 255;
sat = triangle->oldsat = triangle->hsv.s;
val = triangle->oldval = triangle->hsv.v;
sat = triangle->oldsat = selector->hsv.s;
val = triangle->oldval = selector->hsv.v;
x0 = RINT (sx + (vx - sx) * val + (hx - vx) * sat * val);
y0 = RINT (sy + (vy - sy) * val + (hy - vy) * sat * val);
@ -498,10 +492,13 @@ colorsel_triangle_event (GtkWidget *widget,
GdkEvent *event,
ColorselTriangle *triangle)
{
gint x,y, angle, mousex, mousey;
gdouble r;
gdouble hue, sat, val;
gint hx,hy, sx,sy, vx,vy;
GimpColorSelector *selector;
gint x,y, angle, mousex, mousey;
gdouble r;
gdouble hue, sat, val;
gint hx,hy, sx,sy, vx,vy;
selector = GIMP_COLOR_SELECTOR (triangle);
switch (event->type)
{
@ -529,9 +526,7 @@ colorsel_triangle_event (GtkWidget *widget,
gtk_grab_remove (widget);
/* callback the user */
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle),
&triangle->rgb,
&triangle->hsv);
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle));
return FALSE;
break;
@ -552,23 +547,23 @@ colorsel_triangle_event (GtkWidget *widget,
if (triangle->mode == 1 ||
(r > COLORWHEELRADIUS &&
(abs (angle - triangle->hsv.h * 360.0) < 30 ||
abs (abs (angle - triangle->hsv.h * 360.0) - 360) < 30)))
(abs (angle - selector->hsv.h * 360.0) < 30 ||
abs (abs (angle - selector->hsv.h * 360.0) - 360) < 30)))
{
triangle->hsv.h = angle / 360.0;
gimp_hsv_to_rgb (&triangle->hsv, &triangle->rgb);
selector->hsv.h = angle / 360.0;
gimp_hsv_to_rgb (&selector->hsv, &selector->rgb);
colorsel_triangle_update_previews (triangle, TRUE);
}
else
{
hue = triangle->hsv.h * 2 * G_PI;
hue = selector->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 = triangle->hsv.h * 360.0;
hue = selector->hsv.h * 360.0;
if ((x - sx) * vx + (y - sy) * vy < 0)
{
@ -617,6 +612,7 @@ colorsel_triangle_event (GtkWidget *widget,
sat = (gdouble) (x - sx - val * (vx - sx)) / (val * (gdouble) (hx - vx));
else
sat = (gdouble) (y - sy - val * (vy - sy)) / (val * (gdouble) (hy - vy));
if (sat < 0)
sat = 0;
else if (sat > 1)
@ -624,16 +620,14 @@ colorsel_triangle_event (GtkWidget *widget,
}
}
triangle->hsv.s = sat;
triangle->hsv.v = val;
gimp_hsv_to_rgb (&triangle->hsv, &triangle->rgb);
colorsel_triangle_update_previews (triangle, FALSE);
}
selector->hsv.s = sat;
selector->hsv.v = val;
gimp_hsv_to_rgb (&selector->hsv, &selector->rgb);
colorsel_triangle_update_previews (triangle, FALSE);
}
/* callback the user */
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle),
&triangle->rgb,
&triangle->hsv);
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle));
return FALSE;
}

View File

@ -56,8 +56,6 @@ struct _ColorselWater
{
GimpColorSelector parent_instance;
GimpRGB rgb;
gdouble last_x;
gdouble last_y;
gdouble last_pressure;
@ -83,8 +81,6 @@ static void colorsel_water_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
static void colorsel_water_update (ColorselWater *water);
static void select_area_draw (GtkWidget *preview);
static gboolean button_press_event (GtkWidget *widget,
GdkEventButton *event,
@ -274,19 +270,6 @@ colorsel_water_set_color (GimpColorSelector *selector,
ColorselWater *water;
water = COLORSEL_WATER (selector);
water->rgb = *rgb;
}
static void
colorsel_water_update (ColorselWater *water)
{
GimpHSV hsv;
gimp_rgb_to_hsv (&water->rgb, &hsv);
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (water),
&water->rgb, &hsv);
}
static gdouble
@ -336,21 +319,24 @@ select_area_draw (GtkWidget *preview)
}
static void
add_pigment (ColorselWater *colorsel,
add_pigment (ColorselWater *water,
gboolean erase,
gdouble x,
gdouble y,
gdouble much)
{
gdouble r, g, b;
GimpColorSelector *selector;
gdouble r, g, b;
much *= (gdouble) colorsel->pressure_adjust;
selector = GIMP_COLOR_SELECTOR (water);
much *= (gdouble) water->pressure_adjust;
if (erase)
{
colorsel->rgb.r = 1 - (1 - colorsel->rgb.r) * (1 - much);
colorsel->rgb.g = 1 - (1 - colorsel->rgb.g) * (1 - much);
colorsel->rgb.b = 1 - (1 - colorsel->rgb.b) * (1 - much);
selector->rgb.r = 1 - (1 - selector->rgb.r) * (1 - much);
selector->rgb.g = 1 - (1 - selector->rgb.g) * (1 - much);
selector->rgb.b = 1 - (1 - selector->rgb.b) * (1 - much);
}
else
{
@ -366,16 +352,18 @@ add_pigment (ColorselWater *colorsel,
if (b < 0) b = 0;
if (b > 1) b = 1;
colorsel->rgb.r *= (1 - (1 - r) * much);
colorsel->rgb.g *= (1 - (1 - g) * much);
colorsel->rgb.b *= (1 - (1 - b) * much);
selector->rgb.r *= (1 - (1 - r) * much);
selector->rgb.g *= (1 - (1 - g) * much);
selector->rgb.b *= (1 - (1 - b) * much);
}
colorsel_water_update (colorsel);
gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
gimp_color_selector_color_changed (selector);
}
static void
draw_brush (ColorselWater *colorsel,
draw_brush (ColorselWater *water,
GtkWidget *widget,
gboolean erase,
gdouble x,
@ -384,22 +372,22 @@ draw_brush (ColorselWater *colorsel,
{
gdouble much; /* how much pigment to mix in */
if (pressure < colorsel->last_pressure)
colorsel->last_pressure = pressure;
if (pressure < water->last_pressure)
water->last_pressure = pressure;
much = sqrt ((x - colorsel->last_x) * (x - colorsel->last_x) +
(y - colorsel->last_y) * (y - colorsel->last_y) +
much = sqrt ((x - water->last_x) * (x - water->last_x) +
(y - water->last_y) * (y - water->last_y) +
1000 *
(pressure - colorsel->last_pressure) *
(pressure - colorsel->last_pressure));
(pressure - water->last_pressure) *
(pressure - water->last_pressure));
much *= pressure * 0.05;
add_pigment (colorsel, erase, x, y, much);
add_pigment (water, erase, x, y, much);
colorsel->last_x = x;
colorsel->last_y = y;
colorsel->last_pressure = pressure;
water->last_x = x;
water->last_y = y;
water->last_pressure = pressure;
}
static gboolean