Commit 1be91fc2 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

minor cleanups.

2004-08-15  Sven Neumann  <sven@gimp.org>

	* modules/colorsel_triangle.c: minor cleanups.

	* modules/colorsel_water.c: GimpPreviewArea seems like overkill
	here, use a GtkDrawingArea instead.
parent 7ef3447a
2004-08-15 Sven Neumann <sven@gimp.org>
* modules/colorsel_triangle.c: minor cleanups.
* modules/colorsel_water.c: GimpPreviewArea seems like overkill
here, use a GtkDrawingArea instead.
2004-08-15 DindinX <david@dindinx.org>
* modules/colorsel_triangle.c
......
......@@ -39,8 +39,7 @@
#define COLORTRIANGLERADIUS (COLORWHEELRADIUS - GIMP_COLOR_SELECTOR_BAR_SIZE)
#define PREVIEWSIZE (2 * COLORWHEELRADIUS + 1)
#define BGCOLOR 180
#define PREVIEW_MASK (GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
#define PREVIEW_MASK (GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON_MOTION_MASK )
......@@ -75,8 +74,6 @@ static GType colorsel_triangle_get_type (GTypeModule *module);
static void colorsel_triangle_class_init (ColorselTriangleClass *klass);
static void colorsel_triangle_init (ColorselTriangle *triangle);
static void colorsel_triangle_finalize (GObject *object);
static void colorsel_triangle_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
......@@ -93,7 +90,7 @@ static void colorsel_xy_to_triangle_buf (gint x,
gint hy);
static GtkWidget *colorsel_triangle_create_preview (ColorselTriangle *triangle);
static void colorsel_triangle_update_previews (ColorselTriangle *triangle);
static void colorsel_triangle_update_preview (ColorselTriangle *triangle);
static gboolean colorsel_triangle_event (GtkWidget *widget,
GdkEvent *event,
ColorselTriangle *triangle);
......@@ -164,16 +161,10 @@ colorsel_triangle_get_type (GTypeModule *module)
static void
colorsel_triangle_class_init (ColorselTriangleClass *klass)
{
GObjectClass *object_class;
GimpColorSelectorClass *selector_class;
object_class = G_OBJECT_CLASS (klass);
selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = colorsel_triangle_finalize;
selector_class->name = _("Triangle");
selector_class->help_id = "gimp-colorselector-triangle";
selector_class->stock_id = GIMP_STOCK_COLOR_TRIANGLE;
......@@ -203,17 +194,7 @@ colorsel_triangle_init (ColorselTriangle *triangle)
gtk_container_add (GTK_CONTAINER (frame), triangle->preview);
gtk_widget_show (triangle->preview);
colorsel_triangle_update_previews (triangle);
}
static void
colorsel_triangle_finalize (GObject *object)
{
ColorselTriangle *triangle;
triangle = COLORSEL_TRIANGLE (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
colorsel_triangle_update_preview (triangle);
}
static void
......@@ -221,20 +202,17 @@ colorsel_triangle_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
ColorselTriangle *triangle;
triangle = COLORSEL_TRIANGLE (selector);
ColorselTriangle *triangle = COLORSEL_TRIANGLE (selector);
colorsel_triangle_update_previews (triangle);
colorsel_triangle_update_preview (triangle);
}
static GtkWidget *
colorsel_triangle_create_preview (ColorselTriangle *triangle)
{
GtkWidget *preview;
GtkWidget *preview = gimp_preview_area_new ();
preview = gimp_preview_area_new ();
gtk_widget_set_events (GTK_WIDGET (preview), PREVIEW_MASK );
gtk_widget_add_events (GTK_WIDGET (preview), PREVIEW_MASK);
gtk_widget_set_size_request (preview, PREVIEWSIZE, PREVIEWSIZE);
g_signal_connect (preview, "motion_notify_event",
......@@ -247,16 +225,16 @@ colorsel_triangle_create_preview (ColorselTriangle *triangle)
G_CALLBACK (colorsel_triangle_event),
triangle);
g_signal_connect_swapped (preview, "size_allocate",
G_CALLBACK (colorsel_triangle_update_previews),
G_CALLBACK (colorsel_triangle_update_preview),
triangle);
return preview;
}
static void
colorsel_triangle_update_previews (ColorselTriangle *triangle)
colorsel_triangle_update_preview (ColorselTriangle *triangle)
{
GimpColorSelector *selector;
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (triangle);
guchar buf[3 * PREVIEWSIZE];
guchar *preview_buf;
gint x, y, k, r2, dx, col;
......@@ -265,9 +243,7 @@ colorsel_triangle_update_previews (ColorselTriangle *triangle)
gint hx,hy, sx,sy, vx,vy;
preview_buf = g_new (guchar, 3 * PREVIEWSIZE * PREVIEWSIZE);
memset (preview_buf, BGCOLOR, 3 * PREVIEWSIZE * PREVIEWSIZE);
selector = GIMP_COLOR_SELECTOR (triangle);
memset (preview_buf, BGCOLOR, 3 * PREVIEWSIZE * PREVIEWSIZE);
hue = (gdouble) selector->hsv.h * 2 * G_PI;
......@@ -300,19 +276,20 @@ colorsel_triangle_update_previews (ColorselTriangle *triangle)
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
{
colorsel_xy_to_triangle_buf (x, y, hue, buf + k, hx, hy, sx, sy, vx, vy);
colorsel_xy_to_triangle_buf (x, y, hue, buf + k,
hx, hy, sx, sy, vx, vy);
}
}
k += 3;
}
memcpy (preview_buf +
( (COLORWHEELRADIUS - y) * PREVIEWSIZE +
COLORWHEELRADIUS - dx ) * 3,
memcpy (preview_buf + ((COLORWHEELRADIUS - y) * PREVIEWSIZE +
COLORWHEELRADIUS - dx ) * 3,
buf,
3 * (2 * dx + 1));
}
......@@ -329,6 +306,7 @@ colorsel_triangle_update_previews (ColorselTriangle *triangle)
atn = atan2 (x0, y0);
if (atn < 0)
atn = atn + 2 * G_PI;
gimp_hsv_to_rgb4 (buf, atn / (2 * G_PI), 1, 1);
col = GIMP_RGB_INTENSITY (buf[0], buf[1], buf[2]) > 127 ? 0 : 255;
......@@ -354,9 +332,8 @@ colorsel_triangle_update_previews (ColorselTriangle *triangle)
k += 3;
}
memcpy (preview_buf +
( (COLORWHEELRADIUS - y) * PREVIEWSIZE +
COLORWHEELRADIUS + x0 - 4) * 3,
memcpy (preview_buf + ((COLORWHEELRADIUS - y) * PREVIEWSIZE +
COLORWHEELRADIUS + x0 - 4) * 3,
buf,
27);
}
......@@ -399,9 +376,9 @@ colorsel_triangle_update_previews (ColorselTriangle *triangle)
k += 3;
}
memcpy (preview_buf +
( (COLORWHEELRADIUS - y) * PREVIEWSIZE +
COLORWHEELRADIUS + x0 - 4) * 3,
memcpy (preview_buf + ((COLORWHEELRADIUS - y) * PREVIEWSIZE +
COLORWHEELRADIUS + x0 - 4) * 3,
buf,
27);
}
......@@ -459,14 +436,12 @@ colorsel_triangle_event (GtkWidget *widget,
GdkEvent *event,
ColorselTriangle *triangle)
{
GimpColorSelector *selector;
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (triangle);
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)
{
case GDK_BUTTON_PRESS:
......@@ -519,7 +494,7 @@ colorsel_triangle_event (GtkWidget *widget,
{
selector->hsv.h = angle / 360.0;
gimp_hsv_to_rgb (&selector->hsv, &selector->rgb);
colorsel_triangle_update_previews (triangle);
colorsel_triangle_update_preview (triangle);
}
else
{
......@@ -590,7 +565,7 @@ colorsel_triangle_event (GtkWidget *widget,
selector->hsv.s = sat;
selector->hsv.v = val;
gimp_hsv_to_rgb (&selector->hsv, &selector->rgb);
colorsel_triangle_update_previews (triangle);
colorsel_triangle_update_preview (triangle);
}
/* callback the user */
......
......@@ -66,31 +66,26 @@ struct _ColorselWaterClass
};
static GType colorsel_water_get_type (GTypeModule *module);
static GType colorsel_water_get_type (GTypeModule *module);
static void colorsel_water_class_init (ColorselWaterClass *klass);
static void colorsel_water_init (ColorselWater *water);
static void colorsel_water_finalize (GObject *object);
static void colorsel_water_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
static void select_area_draw (GtkWidget *preview);
static gboolean button_press_event (GtkWidget *widget,
GdkEventButton *event,
ColorselWater *water);
static gboolean button_release_event (GtkWidget *widget,
GdkEventButton *event,
ColorselWater *water);
static gboolean motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
ColorselWater *water);
static gboolean proximity_out_event (GtkWidget *widget,
GdkEventProximity *event,
ColorselWater *water);
static void pressure_adjust_update (GtkAdjustment *adj,
ColorselWater *water);
static void select_area_expose (GtkWidget *widget,
GdkEventExpose *event);
static gboolean button_press_event (GtkWidget *widget,
GdkEventButton *event,
ColorselWater *water);
static gboolean button_release_event (GtkWidget *widget,
GdkEventButton *event,
ColorselWater *water);
static gboolean motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
ColorselWater *water);
static gboolean proximity_out_event (GtkWidget *widget,
GdkEventProximity *event,
ColorselWater *water);
static void pressure_adjust_update (GtkAdjustment *adj,
ColorselWater *water);
static const GimpModuleInfo colorsel_water_info =
......@@ -158,27 +153,19 @@ colorsel_water_get_type (GTypeModule *module)
static void
colorsel_water_class_init (ColorselWaterClass *klass)
{
GObjectClass *object_class;
GimpColorSelectorClass *selector_class;
object_class = G_OBJECT_CLASS (klass);
selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = colorsel_water_finalize;
selector_class->name = _("Watercolor");
selector_class->help_id = "gimp-colorselector-watercolor";
selector_class->stock_id = GIMP_STOCK_TOOL_PAINTBRUSH;
selector_class->set_color = colorsel_water_set_color;
}
static void
colorsel_water_init (ColorselWater *water)
{
GtkWidget *preview;
GtkWidget *event_box;
GtkWidget *area;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *hbox2;
......@@ -190,39 +177,35 @@ colorsel_water_init (ColorselWater *water)
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (water), hbox, TRUE, FALSE, 0);
hbox2 = gtk_hbox_new (FALSE, 4);
hbox2 = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, FALSE, 0);
/* the event box */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, FALSE, 0);
event_box = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (frame), event_box);
gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, FALSE, 0);
preview = gimp_preview_area_new ();
gtk_widget_set_size_request (preview, IMAGE_SIZE, IMAGE_SIZE);
gtk_container_add (GTK_CONTAINER (event_box), preview);
g_signal_connect (preview, "size-allocate",
G_CALLBACK (select_area_draw), NULL);
area = gtk_drawing_area_new ();
gtk_widget_set_size_request (area, IMAGE_SIZE, IMAGE_SIZE);
gtk_container_add (GTK_CONTAINER (frame), area);
g_signal_connect (area, "expose_event",
G_CALLBACK (select_area_expose),
NULL);
/* Event signals */
g_signal_connect (event_box, "motion_notify_event",
g_signal_connect (area, "motion_notify_event",
G_CALLBACK (motion_notify_event),
water);
g_signal_connect (event_box, "button_press_event",
g_signal_connect (area, "button_press_event",
G_CALLBACK (button_press_event),
water);
g_signal_connect (event_box, "button_release_event",
g_signal_connect (area, "button_release_event",
G_CALLBACK (button_release_event),
water);
g_signal_connect (event_box, "proximity_out_event",
g_signal_connect (area, "proximity_out_event",
G_CALLBACK (proximity_out_event),
water);
gtk_widget_set_events (event_box,
GDK_EXPOSURE_MASK |
gtk_widget_add_events (area,
GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_KEY_PRESS_MASK |
......@@ -233,8 +216,8 @@ colorsel_water_init (ColorselWater *water)
/* The following call enables tracking and processing of extension
* events for the drawing area
*/
gtk_widget_set_extension_events (event_box, GDK_EXTENSION_EVENTS_ALL);
gtk_widget_grab_focus (event_box);
gtk_widget_set_extension_events (area, GDK_EXTENSION_EVENTS_ALL);
gtk_widget_grab_focus (area);
adj = gtk_adjustment_new (200.0 - water->pressure_adjust * 100.0,
0.0, 200.0, 1.0, 1.0, 0.0);
......@@ -250,26 +233,6 @@ colorsel_water_init (ColorselWater *water)
gtk_widget_show_all (hbox);
}
static void
colorsel_water_finalize (GObject *object)
{
ColorselWater *water;
water = COLORSEL_WATER (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
colorsel_water_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
ColorselWater *water;
water = COLORSEL_WATER (selector);
}
static gdouble
calc (gdouble x,
gdouble y,
......@@ -285,38 +248,55 @@ calc (gdouble x,
/* Initialize the preview */
static void
select_area_draw (GtkWidget *preview)
select_area_expose (GtkWidget *widget,
GdkEventExpose *event)
{
guchar buf[3 * IMAGE_SIZE * IMAGE_SIZE];
gint width = event->area.width;
gint height = event->area.height;
guchar *buf = g_alloca (3 * width * height);
gint x, y;
gdouble r, g, b;
gdouble dr, dg, db;
gint i, j;
for (y = 0; y < IMAGE_SIZE; y++)
for (j = 0, y = event->area.y; j < height; j++, y++)
{
gdouble r, g, b;
gdouble dr, dg, db;
r = calc (0, y, 0);
g = calc (0, y, 120);
b = calc (0, y, 240);
dr = calc (1, y, 0) - r;
dr = calc (1, y, 0) - r;
dg = calc (1, y, 120) - g;
db = calc (1, y, 240) - b;
for (x = 0; x < IMAGE_SIZE; x++)
x = event->area.x;
r += x * dr;
g += x * dg;
b += x * db;
for (i = 0; i < width; i++)
{
buf[(x + IMAGE_SIZE * y) * 3] = CLAMP ((gint) r, 0, 255);
buf[(x + IMAGE_SIZE * y) * 3 + 1] = CLAMP ((gint) g, 0, 255);
buf[(x + IMAGE_SIZE * y) * 3 + 2] = CLAMP ((gint) b, 0, 255);
buf[(i + width * j) * 3] = CLAMP ((gint) r, 0, 255);
buf[(i + width * j) * 3 + 1] = CLAMP ((gint) g, 0, 255);
buf[(i + width * j) * 3 + 2] = CLAMP ((gint) b, 0, 255);
r += dr;
g += dg;
b += db;
}
}
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, IMAGE_SIZE, IMAGE_SIZE,
GIMP_RGB_IMAGE,
buf,
3 * IMAGE_SIZE);
x = event->area.x;
y = event->area.y;
gdk_draw_rgb_image_dithalign (widget->window,
widget->style->fg_gc[widget->state],
x, y, width, height,
GDK_RGB_DITHER_MAX,
buf, 3 * width,
-x, -y);
}
static void
......@@ -326,12 +306,10 @@ add_pigment (ColorselWater *water,
gdouble y,
gdouble much)
{
GimpColorSelector *selector;
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (water);
gdouble r, g, b;
selector = GIMP_COLOR_SELECTOR (water);
much *= (gdouble) water->pressure_adjust;
much *= (gdouble) water->pressure_adjust;
if (erase)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment