1999-05-09 00:34:29 +08:00
|
|
|
/* Watercolor color_select_module, Raph Levien <raph@acm.org>, February 1998
|
|
|
|
*
|
1999-09-05 20:45:17 +08:00
|
|
|
* Ported to loadable color-selector, Sven Neumann <sven@gimp.org>, May 1999
|
1999-05-09 00:34:29 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2000-01-15 03:57:42 +08:00
|
|
|
#include "config.h"
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2000-01-26 01:46:56 +08:00
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
#include "libgimp/gimpuitypes.h"
|
|
|
|
|
|
|
|
#include "libgimp/gimpcolor.h"
|
|
|
|
#include "libgimp/gimpcolorspace.h"
|
|
|
|
#include "libgimp/gimpcolorselector.h"
|
|
|
|
#include "libgimp/gimpmodule.h"
|
|
|
|
#include "libgimp/gimpmath.h"
|
|
|
|
#include "libgimp/gimphelpui.h"
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2000-05-27 09:30:21 +08:00
|
|
|
#include "gimpmodregister.h"
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* definitions and variables */
|
|
|
|
|
|
|
|
#define IMAGE_SIZE 200
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpRGB rgb;
|
|
|
|
gdouble last_x;
|
|
|
|
gdouble last_y;
|
|
|
|
gdouble last_pressure;
|
|
|
|
|
|
|
|
gfloat pressure_adjust;
|
|
|
|
guint32 motion_time;
|
|
|
|
gint button_state;
|
|
|
|
|
|
|
|
GimpColorSelectorCallback callback;
|
|
|
|
gpointer data;
|
|
|
|
} ColorselWater;
|
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
/* prototypes */
|
2001-01-15 20:20:38 +08:00
|
|
|
static GtkWidget * colorsel_water_new (const GimpHSV *hsv,
|
|
|
|
const GimpRGB *rgb,
|
2001-01-08 05:07:14 +08:00
|
|
|
gboolean show_alpha,
|
|
|
|
GimpColorSelectorCallback,
|
2001-01-15 20:20:38 +08:00
|
|
|
gpointer ,
|
|
|
|
gpointer *);
|
|
|
|
static void colorsel_water_free (gpointer data);
|
|
|
|
static void colorsel_water_set_color (gpointer data,
|
|
|
|
const GimpHSV *hsv,
|
|
|
|
const GimpRGB *rgb);
|
2001-01-16 00:52:22 +08:00
|
|
|
static void colorsel_water_update (ColorselWater *colorsel);
|
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
/* local methods */
|
|
|
|
static GimpColorSelectorMethods methods =
|
|
|
|
{
|
|
|
|
colorsel_water_new,
|
|
|
|
colorsel_water_free,
|
2001-01-09 09:23:54 +08:00
|
|
|
colorsel_water_set_color,
|
2001-01-17 03:42:37 +08:00
|
|
|
NULL /* set_channel */
|
1999-05-09 00:34:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-01-08 05:07:14 +08:00
|
|
|
static GimpModuleInfo info =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
N_("Watercolor style color selector as a pluggable module"),
|
|
|
|
"Raph Levien <raph@acm.org>, Sven Neumann <sven@gimp.org>",
|
|
|
|
"v0.3",
|
|
|
|
"(c) 1998-1999, released under the GPL",
|
|
|
|
"May, 10 1999"
|
1999-05-09 00:34:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-01-08 05:07:14 +08:00
|
|
|
static const GtkTargetEntry targets[] =
|
|
|
|
{
|
1999-09-05 20:45:17 +08:00
|
|
|
{ "application/x-color", 0 }
|
|
|
|
};
|
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
/* globaly exported init function */
|
|
|
|
G_MODULE_EXPORT GimpModuleStatus
|
|
|
|
module_init (GimpModuleInfo **inforet)
|
|
|
|
{
|
|
|
|
GimpColorSelectorID id;
|
|
|
|
|
2000-01-07 23:27:10 +08:00
|
|
|
#ifndef __EMX__
|
2000-01-15 03:57:42 +08:00
|
|
|
id = gimp_color_selector_register (_("Watercolor"), "watercolor.html",
|
1999-10-03 21:50:19 +08:00
|
|
|
&methods);
|
2000-01-07 23:27:10 +08:00
|
|
|
#else
|
2001-01-08 05:07:14 +08:00
|
|
|
id = mod_color_selector_register (_("Watercolor"), "watercolor.html",
|
|
|
|
&methods);
|
2000-01-07 23:27:10 +08:00
|
|
|
#endif
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
if (id)
|
2001-01-08 05:07:14 +08:00
|
|
|
{
|
|
|
|
info.shutdown_data = id;
|
|
|
|
*inforet = &info;
|
|
|
|
return GIMP_MODULE_OK;
|
|
|
|
}
|
1999-05-09 00:34:29 +08:00
|
|
|
else
|
2001-01-08 05:07:14 +08:00
|
|
|
{
|
|
|
|
return GIMP_MODULE_UNLOAD;
|
|
|
|
}
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
G_MODULE_EXPORT void
|
2001-01-08 05:07:14 +08:00
|
|
|
module_unload (gpointer shutdown_data,
|
|
|
|
GimpColorSelectorFinishedCB completed_cb,
|
|
|
|
gpointer completed_data)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2000-01-07 23:27:10 +08:00
|
|
|
#ifndef __EMX__
|
1999-05-09 00:34:29 +08:00
|
|
|
gimp_color_selector_unregister (shutdown_data, completed_cb, completed_data);
|
2000-01-07 23:27:10 +08:00
|
|
|
#else
|
|
|
|
mod_color_selector_unregister (shutdown_data, completed_cb, completed_data);
|
|
|
|
#endif
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gdouble
|
2001-01-08 05:07:14 +08:00
|
|
|
calc (gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble angle)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
|
|
|
gdouble s, c;
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
s = 1.6 * sin (angle * G_PI / 180) * 256.0 / IMAGE_SIZE;
|
|
|
|
c = 1.6 * cos (angle * G_PI / 180) * 256.0 / IMAGE_SIZE;
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
return 128 + (x - (IMAGE_SIZE >> 1)) * c - (y - (IMAGE_SIZE >> 1)) * s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the preview */
|
|
|
|
static void
|
|
|
|
select_area_draw (GtkWidget *preview)
|
|
|
|
{
|
2001-01-08 05:07:14 +08:00
|
|
|
guchar buf[3 * IMAGE_SIZE];
|
|
|
|
gint x, y;
|
1999-05-09 00:34:29 +08:00
|
|
|
gdouble r, g, b;
|
|
|
|
gdouble dr, dg, db;
|
|
|
|
|
|
|
|
for (y = 0; y < IMAGE_SIZE; y++)
|
|
|
|
{
|
|
|
|
r = calc (0, y, 0);
|
|
|
|
g = calc (0, y, 120);
|
|
|
|
b = calc (0, y, 240);
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
2001-01-08 05:07:14 +08:00
|
|
|
buf[x * 3] = CLAMP ((gint) r, 0, 255);
|
|
|
|
buf[x * 3 + 1] = CLAMP ((gint) g, 0, 255);
|
|
|
|
buf[x * 3 + 2] = CLAMP ((gint) b, 0, 255);
|
1999-05-09 00:34:29 +08:00
|
|
|
r += dr;
|
|
|
|
g += dg;
|
|
|
|
b += db;
|
|
|
|
}
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, y, IMAGE_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-15 20:20:38 +08:00
|
|
|
static void
|
2001-01-16 00:52:22 +08:00
|
|
|
add_pigment (ColorselWater *colorsel,
|
|
|
|
gboolean erase,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble much)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
|
|
|
gdouble r, g, b;
|
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
much *= (gdouble) colorsel->pressure_adjust;
|
1999-05-10 05:50:33 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
if (erase)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
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);
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = calc (x, y, 0) / 255.0;
|
|
|
|
if (r < 0) r = 0;
|
|
|
|
if (r > 1) r = 1;
|
|
|
|
|
|
|
|
g = calc (x, y, 120) / 255.0;
|
|
|
|
if (g < 0) g = 0;
|
|
|
|
if (g > 1) g = 1;
|
|
|
|
|
|
|
|
b = calc (x, y, 240) / 255.0;
|
|
|
|
if (b < 0) b = 0;
|
|
|
|
if (b > 1) b = 1;
|
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel->rgb.r *= (1 - (1 - r) * much);
|
|
|
|
colorsel->rgb.g *= (1 - (1 - g) * much);
|
|
|
|
colorsel->rgb.b *= (1 - (1 - b) * much);
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel_water_update (colorsel);
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-16 00:52:22 +08:00
|
|
|
draw_brush (ColorselWater *colorsel,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gboolean erase,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble pressure)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
|
|
|
gdouble much; /* how much pigment to mix in */
|
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
if (pressure < colorsel->last_pressure)
|
|
|
|
colorsel->last_pressure = pressure;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
much = sqrt ((x - colorsel->last_x) * (x - colorsel->last_x) +
|
|
|
|
(y - colorsel->last_y) * (y - colorsel->last_y) +
|
|
|
|
1000 *
|
|
|
|
(pressure - colorsel->last_pressure) *
|
|
|
|
(pressure - colorsel->last_pressure));
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
much *= pressure * 0.05;
|
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
add_pigment (colorsel, erase, x, y, much);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel->last_x = x;
|
|
|
|
colorsel->last_y = y;
|
|
|
|
colorsel->last_pressure = pressure;
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2001-01-08 05:07:14 +08:00
|
|
|
button_press_event (GtkWidget *widget,
|
2001-01-16 00:52:22 +08:00
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
ColorselWater *colorsel;
|
|
|
|
gboolean erase;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel = (ColorselWater *) data;
|
|
|
|
|
|
|
|
colorsel->last_x = event->x;
|
|
|
|
colorsel->last_y = event->y;
|
|
|
|
colorsel->last_pressure = event->pressure;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel->button_state |= 1 << event->button;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
erase = (event->button != 1) ||
|
|
|
|
(event->source == GDK_SOURCE_ERASER);
|
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
add_pigment (colorsel, erase, event->x, event->y, 0.05);
|
|
|
|
colorsel->motion_time = event->time;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2001-01-08 05:07:14 +08:00
|
|
|
button_release_event (GtkWidget *widget,
|
2001-01-16 00:52:22 +08:00
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
ColorselWater *colorsel;
|
|
|
|
|
|
|
|
colorsel = (ColorselWater *) data;
|
|
|
|
|
|
|
|
colorsel->button_state &= ~(1 << event->button);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2001-01-08 05:07:14 +08:00
|
|
|
motion_notify_event (GtkWidget *widget,
|
2001-01-16 00:52:22 +08:00
|
|
|
GdkEventMotion *event,
|
|
|
|
gpointer data)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
ColorselWater *colorsel;
|
|
|
|
GdkTimeCoord *coords;
|
|
|
|
gint nevents;
|
|
|
|
gint i;
|
|
|
|
gboolean erase;
|
|
|
|
|
|
|
|
colorsel = (ColorselWater *) data;
|
2001-01-08 05:07:14 +08:00
|
|
|
|
|
|
|
if (event->state & (GDK_BUTTON1_MASK |
|
|
|
|
GDK_BUTTON2_MASK |
|
|
|
|
GDK_BUTTON3_MASK |
|
|
|
|
GDK_BUTTON4_MASK))
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
|
|
|
coords = gdk_input_motion_events (event->window, event->deviceid,
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel->motion_time, event->time,
|
1999-05-09 00:34:29 +08:00
|
|
|
&nevents);
|
1999-05-10 05:50:33 +08:00
|
|
|
erase = (event->state &
|
|
|
|
(GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK)) ||
|
1999-05-09 00:34:29 +08:00
|
|
|
(event->source == GDK_SOURCE_ERASER);
|
2001-01-16 00:52:22 +08:00
|
|
|
|
|
|
|
colorsel->motion_time = event->time;
|
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
if (coords)
|
|
|
|
{
|
|
|
|
for (i=0; i<nevents; i++)
|
2001-01-16 00:52:22 +08:00
|
|
|
draw_brush (colorsel, widget,
|
|
|
|
erase,
|
|
|
|
coords[i].x,
|
|
|
|
coords[i].y,
|
1999-05-09 00:34:29 +08:00
|
|
|
coords[i].pressure);
|
2001-01-16 00:52:22 +08:00
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
g_free (coords);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (event->is_hint)
|
|
|
|
gdk_input_window_get_pointer (event->window, event->deviceid,
|
1999-09-04 22:42:43 +08:00
|
|
|
#ifdef GTK_HAVE_SIX_VALUATORS
|
2001-01-16 00:52:22 +08:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
1999-09-04 22:42:43 +08:00
|
|
|
#else /* !GTK_HAVE_SIX_VALUATORS */
|
2001-01-16 00:52:22 +08:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL
|
1999-09-04 22:42:43 +08:00
|
|
|
#endif /* GTK_HAVE_SIX_VALUATORS */
|
2001-01-16 00:52:22 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
draw_brush (colorsel, widget,
|
|
|
|
erase,
|
|
|
|
event->x,
|
|
|
|
event->y,
|
1999-05-09 00:34:29 +08:00
|
|
|
event->pressure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_input_window_get_pointer (event->window, event->deviceid,
|
|
|
|
&event->x, &event->y,
|
1999-09-04 22:42:43 +08:00
|
|
|
#ifdef GTK_HAVE_SIX_VALUATORS
|
2001-01-16 00:52:22 +08:00
|
|
|
NULL, NULL, NULL, NULL, NULL
|
1999-09-04 22:42:43 +08:00
|
|
|
#else /* !GTK_HAVE_SIX_VALUATORS */
|
2001-01-16 00:52:22 +08:00
|
|
|
NULL, NULL, NULL, NULL
|
1999-09-04 22:42:43 +08:00
|
|
|
#endif /* GTK_HAVE_SIX_VALUATORS */
|
2001-01-16 00:52:22 +08:00
|
|
|
);
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2001-01-08 05:07:14 +08:00
|
|
|
proximity_out_event (GtkWidget *widget,
|
2001-01-16 00:52:22 +08:00
|
|
|
GdkEventProximity *event,
|
|
|
|
gpointer data)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
ColorselWater *colorsel;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel = (ColorselWater *) data;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
return TRUE;
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
1999-05-10 05:50:33 +08:00
|
|
|
static void
|
2001-01-08 05:07:14 +08:00
|
|
|
pressure_adjust_update (GtkAdjustment *adj,
|
|
|
|
gpointer data)
|
1999-05-10 05:50:33 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
ColorselWater *colorsel;
|
|
|
|
|
|
|
|
colorsel = (ColorselWater *) data;
|
|
|
|
|
2001-01-16 02:23:52 +08:00
|
|
|
colorsel->pressure_adjust = (adj->upper - adj->value) / 100.0;
|
1999-05-10 05:50:33 +08:00
|
|
|
}
|
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-09 09:23:54 +08:00
|
|
|
/***********/
|
1999-05-09 00:34:29 +08:00
|
|
|
/* methods */
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget*
|
2001-01-15 20:20:38 +08:00
|
|
|
colorsel_water_new (const GimpHSV *hsv,
|
|
|
|
const GimpRGB *rgb,
|
2001-01-08 05:07:14 +08:00
|
|
|
gboolean show_alpha,
|
|
|
|
GimpColorSelectorCallback callback,
|
|
|
|
gpointer callback_data,
|
1999-05-09 00:34:29 +08:00
|
|
|
/* RETURNS: */
|
2001-01-08 05:07:14 +08:00
|
|
|
gpointer *selector_data)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
ColorselWater *coldata;
|
|
|
|
GtkWidget *preview;
|
|
|
|
GtkWidget *event_box;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkObject *adj;
|
|
|
|
GtkWidget *scale;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-08 05:07:14 +08:00
|
|
|
coldata = g_new (ColorselWater, 1);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
coldata->pressure_adjust = 1.0;
|
|
|
|
|
|
|
|
coldata->callback = callback;
|
|
|
|
coldata->data = callback_data;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
*selector_data = coldata;
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
2001-01-16 00:52:22 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
|
|
|
|
|
1999-05-09 00:34:29 +08:00
|
|
|
/* the event box */
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2001-01-16 00:52:22 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
event_box = gtk_event_box_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), event_box);
|
|
|
|
|
|
|
|
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
|
|
gtk_preview_size (GTK_PREVIEW (preview), IMAGE_SIZE, IMAGE_SIZE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (event_box), preview);
|
|
|
|
select_area_draw (preview);
|
|
|
|
|
|
|
|
/* Event signals */
|
|
|
|
gtk_signal_connect (GTK_OBJECT (event_box), "motion_notify_event",
|
2001-01-08 05:07:14 +08:00
|
|
|
GTK_SIGNAL_FUNC (motion_notify_event),
|
2001-01-16 00:52:22 +08:00
|
|
|
coldata);
|
1999-05-09 00:34:29 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (event_box), "button_press_event",
|
2001-01-08 05:07:14 +08:00
|
|
|
GTK_SIGNAL_FUNC (button_press_event),
|
2001-01-16 00:52:22 +08:00
|
|
|
coldata);
|
1999-05-09 00:34:29 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (event_box), "button_release_event",
|
2001-01-08 05:07:14 +08:00
|
|
|
GTK_SIGNAL_FUNC (button_release_event),
|
2001-01-16 00:52:22 +08:00
|
|
|
coldata);
|
1999-05-09 00:34:29 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (event_box), "proximity_out_event",
|
2001-01-08 05:07:14 +08:00
|
|
|
GTK_SIGNAL_FUNC (proximity_out_event),
|
2001-01-16 00:52:22 +08:00
|
|
|
coldata);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2001-01-08 05:07:14 +08:00
|
|
|
gtk_widget_set_events (event_box,
|
|
|
|
GDK_EXPOSURE_MASK |
|
|
|
|
GDK_LEAVE_NOTIFY_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_KEY_PRESS_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_PROXIMITY_OUT_MASK);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
/* The following call enables tracking and processing of extension
|
2001-01-08 05:07:14 +08:00
|
|
|
* events for the drawing area
|
|
|
|
*/
|
1999-05-09 00:34:29 +08:00
|
|
|
gtk_widget_set_extension_events (event_box, GDK_EXTENSION_EVENTS_ALL);
|
|
|
|
gtk_widget_grab_focus (event_box);
|
1999-05-10 05:50:33 +08:00
|
|
|
|
2001-01-16 02:23:52 +08:00
|
|
|
adj = gtk_adjustment_new (200.0 - coldata->pressure_adjust * 100.0,
|
|
|
|
0.0, 200.0, 1.0, 1.0, 0.0);
|
1999-05-10 05:50:33 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
|
2001-01-16 00:52:22 +08:00
|
|
|
GTK_SIGNAL_FUNC (pressure_adjust_update),
|
|
|
|
coldata);
|
|
|
|
scale = gtk_vscale_new (GTK_ADJUSTMENT (adj));
|
1999-05-10 05:50:33 +08:00
|
|
|
gtk_scale_set_digits (GTK_SCALE (scale), 0);
|
2001-01-16 02:23:52 +08:00
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
|
2001-01-16 00:52:22 +08:00
|
|
|
gimp_help_set_help_data (scale, _("Pressure"), NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), scale, FALSE, FALSE, 0);
|
1999-05-10 05:50:33 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
gtk_widget_show_all (vbox);
|
2001-01-09 09:23:54 +08:00
|
|
|
|
2001-01-15 20:20:38 +08:00
|
|
|
colorsel_water_set_color (coldata, hsv, rgb);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
|
|
|
return vbox;
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-01-08 05:07:14 +08:00
|
|
|
colorsel_water_free (gpointer selector_data)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
|
|
|
g_free (selector_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-15 20:20:38 +08:00
|
|
|
colorsel_water_set_color (gpointer data,
|
|
|
|
const GimpHSV *hsv,
|
|
|
|
const GimpRGB *rgb)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-16 00:52:22 +08:00
|
|
|
ColorselWater *colorsel;
|
|
|
|
|
|
|
|
colorsel = (ColorselWater *) data;
|
2001-01-08 05:07:14 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel->rgb = *rgb;
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel_water_update (ColorselWater *colorsel)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2001-01-15 20:20:38 +08:00
|
|
|
GimpHSV hsv;
|
2001-01-09 09:23:54 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
gimp_rgb_to_hsv (&colorsel->rgb, &hsv);
|
1999-09-05 20:45:17 +08:00
|
|
|
|
2001-01-16 00:52:22 +08:00
|
|
|
colorsel->callback (colorsel->data, &hsv, &colorsel->rgb);
|
1999-09-05 20:45:17 +08:00
|
|
|
}
|