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
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1999-05-09 00:34:29 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1999-05-09 00:34:29 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1999-05-09 00:34:29 +08:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gegl.h>
|
1999-05-09 00:34:29 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
2002-10-21 22:15:02 +08:00
|
|
|
#include "libgimpmodule/gimpmodule.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2002-10-30 23:12:30 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
2001-01-16 00:52:22 +08:00
|
|
|
|
|
|
|
|
2008-01-10 06:22:10 +08:00
|
|
|
#define COLORSEL_TYPE_WATER (colorsel_water_get_type ())
|
2002-10-20 18:14:17 +08:00
|
|
|
#define COLORSEL_WATER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLORSEL_TYPE_WATER, ColorselWater))
|
|
|
|
#define COLORSEL_WATER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COLORSEL_TYPE_WATER, ColorselWaterClass))
|
|
|
|
#define COLORSEL_IS_WATER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLORSEL_TYPE_WATER))
|
|
|
|
#define COLORSEL_IS_WATER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COLORSEL_TYPE_WATER))
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _ColorselWater ColorselWater;
|
|
|
|
typedef struct _ColorselWaterClass ColorselWaterClass;
|
|
|
|
|
|
|
|
struct _ColorselWater
|
2001-01-16 00:52:22 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
GimpColorSelector parent_instance;
|
|
|
|
|
|
|
|
gdouble last_x;
|
|
|
|
gdouble last_y;
|
|
|
|
|
|
|
|
gfloat pressure_adjust;
|
|
|
|
guint32 motion_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _ColorselWaterClass
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
GimpColorSelectorClass parent_class;
|
1999-05-09 00:34:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-18 03:57:50 +08:00
|
|
|
static GType colorsel_water_get_type (void);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2010-08-09 06:14:35 +08:00
|
|
|
static gboolean select_area_expose (GtkWidget *widget,
|
2008-01-10 06:22:10 +08:00
|
|
|
GdkEventExpose *event);
|
|
|
|
static gboolean button_press_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);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
|
2002-10-20 20:40:30 +08:00
|
|
|
static const GimpModuleInfo colorsel_water_info =
|
2001-01-08 05:07:14 +08:00
|
|
|
{
|
2003-01-03 01:44:28 +08:00
|
|
|
GIMP_MODULE_ABI_VERSION,
|
2002-10-23 22:55:07 +08:00
|
|
|
N_("Watercolor style color selector"),
|
2001-01-08 05:07:14 +08:00
|
|
|
"Raph Levien <raph@acm.org>, Sven Neumann <sven@gimp.org>",
|
2006-03-10 21:12:15 +08:00
|
|
|
"v0.4",
|
|
|
|
"released under the GPL",
|
|
|
|
"1998-2006"
|
1999-05-09 00:34:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-10 06:22:10 +08:00
|
|
|
G_DEFINE_DYNAMIC_TYPE (ColorselWater, colorsel_water,
|
|
|
|
GIMP_TYPE_COLOR_SELECTOR)
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
|
2002-10-20 20:40:30 +08:00
|
|
|
G_MODULE_EXPORT const GimpModuleInfo *
|
|
|
|
gimp_module_query (GTypeModule *module)
|
|
|
|
{
|
|
|
|
return &colorsel_water_info;
|
|
|
|
}
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
G_MODULE_EXPORT gboolean
|
2002-10-20 20:40:30 +08:00
|
|
|
gimp_module_register (GTypeModule *module)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2008-01-10 06:22:10 +08:00
|
|
|
colorsel_water_register_type (module);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
colorsel_water_class_init (ColorselWaterClass *klass)
|
|
|
|
{
|
2004-08-16 02:01:11 +08:00
|
|
|
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2014-05-10 14:33:29 +08:00
|
|
|
selector_class->name = _("Watercolor");
|
|
|
|
selector_class->help_id = "gimp-colorselector-watercolor";
|
|
|
|
selector_class->icon_name = GIMP_STOCK_TOOL_PAINTBRUSH;
|
2008-01-10 06:22:10 +08:00
|
|
|
}
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2008-01-10 06:22:10 +08:00
|
|
|
static void
|
|
|
|
colorsel_water_class_finalize (ColorselWaterClass *klass)
|
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
colorsel_water_init (ColorselWater *water)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2011-10-02 20:09:45 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *area;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
GtkWidget *scale;
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2013-11-05 05:09:57 +08:00
|
|
|
colorsel_water_get_type (); /* useless function call to silence compiler */
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
water->pressure_adjust = 1.0;
|
|
|
|
|
2011-09-30 16:59:40 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2004-08-17 23:07:27 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (water), hbox, TRUE, TRUE, 0);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2004-08-17 23:07:27 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2004-08-16 02:01:11 +08:00
|
|
|
area = gtk_drawing_area_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), area);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (area, "expose-event",
|
2004-08-16 02:01:11 +08:00
|
|
|
G_CALLBACK (select_area_expose),
|
|
|
|
NULL);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
/* Event signals */
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (area, "motion-notify-event",
|
2002-10-20 18:14:17 +08:00
|
|
|
G_CALLBACK (motion_notify_event),
|
|
|
|
water);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (area, "button-press-event",
|
2002-10-20 18:14:17 +08:00
|
|
|
G_CALLBACK (button_press_event),
|
|
|
|
water);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (area, "proximity-out-event",
|
2002-10-20 18:14:17 +08:00
|
|
|
G_CALLBACK (proximity_out_event),
|
|
|
|
water);
|
|
|
|
|
2004-08-16 02:01:11 +08:00
|
|
|
gtk_widget_add_events (area,
|
2004-08-15 23:31:20 +08:00
|
|
|
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);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
/* The following call enables tracking and processing of extension
|
|
|
|
* events for the drawing area
|
|
|
|
*/
|
2004-08-16 02:01:11 +08:00
|
|
|
gtk_widget_set_extension_events (area, GDK_EXTENSION_EVENTS_ALL);
|
|
|
|
gtk_widget_grab_focus (area);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2011-10-02 20:09:45 +08:00
|
|
|
adj = GTK_ADJUSTMENT (gtk_adjustment_new (200.0 - water->pressure_adjust * 100.0,
|
|
|
|
0.0, 200.0, 1.0, 1.0, 0.0));
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (adj, "value-changed",
|
2002-10-20 18:14:17 +08:00
|
|
|
G_CALLBACK (pressure_adjust_update),
|
|
|
|
water);
|
2004-08-17 23:07:27 +08:00
|
|
|
|
2011-10-02 20:09:45 +08:00
|
|
|
scale = gtk_scale_new (GTK_ORIENTATION_VERTICAL, adj);
|
2002-10-20 18:14:17 +08:00
|
|
|
gtk_scale_set_digits (GTK_SCALE (scale), 0);
|
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
|
|
|
|
gimp_help_set_help_data (scale, _("Pressure"), NULL);
|
2004-08-17 23:07:27 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), scale, FALSE, FALSE, 0);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
gtk_widget_show_all (hbox);
|
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
|
|
|
{
|
2004-08-17 23:07:27 +08:00
|
|
|
gdouble s = 2.0 * sin (angle * G_PI / 180.0) * 256.0;
|
|
|
|
gdouble c = 2.0 * cos (angle * G_PI / 180.0) * 256.0;
|
2001-01-08 05:07:14 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
return 128 + (x - 0.5) * c - (y - 0.5) * s;
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
2010-08-09 06:14:35 +08:00
|
|
|
static gboolean
|
2004-08-16 02:01:11 +08:00
|
|
|
select_area_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2010-08-09 06:14:35 +08:00
|
|
|
cairo_t *cr;
|
|
|
|
GtkAllocation allocation;
|
|
|
|
gdouble dx;
|
|
|
|
gdouble dy;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
guchar *dest;
|
|
|
|
gdouble y;
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
cr = gdk_cairo_create (event->window);
|
|
|
|
|
|
|
|
gdk_cairo_region (cr, event->region);
|
|
|
|
cairo_clip (cr);
|
2009-10-18 00:58:28 +08:00
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
|
|
|
dx = 1.0 / allocation.width;
|
|
|
|
dy = 1.0 / allocation.height;
|
|
|
|
|
2010-08-09 06:14:35 +08:00
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
|
|
|
|
event->area.width,
|
|
|
|
event->area.height);
|
|
|
|
|
|
|
|
dest = cairo_image_surface_get_data (surface);
|
|
|
|
|
2009-10-18 00:58:28 +08:00
|
|
|
for (j = 0, y = event->area.y / allocation.height;
|
|
|
|
j < event->area.height;
|
|
|
|
j++, y += dy)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2004-08-17 23:07:27 +08:00
|
|
|
guchar *d = dest;
|
2004-08-16 02:01:11 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
gdouble r = calc (0, y, 0);
|
|
|
|
gdouble g = calc (0, y, 120);
|
|
|
|
gdouble b = calc (0, y, 240);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
gdouble dr = calc (dx, y, 0) - r;
|
|
|
|
gdouble dg = calc (dx, y, 120) - g;
|
|
|
|
gdouble db = calc (dx, y, 240) - b;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2010-08-09 06:14:35 +08:00
|
|
|
gint i;
|
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
r += event->area.x * dr;
|
|
|
|
g += event->area.x * dg;
|
|
|
|
b += event->area.x * db;
|
2004-08-16 02:01:11 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
for (i = 0; i < event->area.width; i++)
|
2004-08-15 23:31:20 +08:00
|
|
|
{
|
2010-08-09 06:14:35 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
|
|
|
CLAMP ((gint) r, 0, 255),
|
|
|
|
CLAMP ((gint) g, 0, 255),
|
|
|
|
CLAMP ((gint) b, 0, 255));
|
2004-08-16 02:01:11 +08:00
|
|
|
|
2004-08-15 23:31:20 +08:00
|
|
|
r += dr;
|
|
|
|
g += dg;
|
|
|
|
b += db;
|
2004-08-17 23:07:27 +08:00
|
|
|
|
2010-08-09 06:14:35 +08:00
|
|
|
d += 4;
|
2004-08-15 23:31:20 +08:00
|
|
|
}
|
2004-08-16 02:01:11 +08:00
|
|
|
|
2010-08-09 06:14:35 +08:00
|
|
|
dest += cairo_image_surface_get_stride (surface);
|
2004-08-17 23:07:27 +08:00
|
|
|
}
|
2004-08-16 02:01:11 +08:00
|
|
|
|
2010-08-09 06:14:35 +08:00
|
|
|
cairo_surface_mark_dirty (surface);
|
|
|
|
cairo_set_source_surface (cr, surface,
|
|
|
|
event->area.x, event->area.y);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
return FALSE;
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
2001-01-15 20:20:38 +08:00
|
|
|
static void
|
2002-10-29 04:13:17 +08:00
|
|
|
add_pigment (ColorselWater *water,
|
2004-08-15 23:31:20 +08:00
|
|
|
gboolean erase,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble much)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2004-08-16 02:01:11 +08:00
|
|
|
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (water);
|
2002-10-29 04:13:17 +08:00
|
|
|
|
2004-08-16 02:01:11 +08:00
|
|
|
much *= (gdouble) water->pressure_adjust;
|
1999-05-10 05:50:33 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (erase)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2004-08-17 23:07:27 +08:00
|
|
|
selector->rgb.r = 1.0 - (1.0 - selector->rgb.r) * (1.0 - much);
|
|
|
|
selector->rgb.g = 1.0 - (1.0 - selector->rgb.g) * (1.0 - much);
|
|
|
|
selector->rgb.b = 1.0 - (1.0 - selector->rgb.b) * (1.0 - much);
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-17 23:07:27 +08:00
|
|
|
gdouble r = calc (x, y, 0) / 256.0;
|
|
|
|
gdouble g = calc (x, y, 120) / 256.0;
|
|
|
|
gdouble b = calc (x, y, 240) / 256.0;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
selector->rgb.r *= (1.0 - (1.0 - r) * much);
|
|
|
|
selector->rgb.g *= (1.0 - (1.0 - g) * much);
|
|
|
|
selector->rgb.b *= (1.0 - (1.0 - b) * much);
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
gimp_rgb_clamp (&selector->rgb);
|
|
|
|
|
2002-10-29 04:13:17 +08:00
|
|
|
gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
|
|
|
|
|
|
|
|
gimp_color_selector_color_changed (selector);
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-29 04:13:17 +08:00
|
|
|
draw_brush (ColorselWater *water,
|
2004-08-15 23:31:20 +08:00
|
|
|
GtkWidget *widget,
|
|
|
|
gboolean erase,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble pressure)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2004-08-17 23:07:27 +08:00
|
|
|
gdouble much = sqrt (SQR (x - water->last_x) + SQR (y - water->last_y));
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
add_pigment (water, erase, x, y, much * pressure);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
water->last_x = x;
|
|
|
|
water->last_y = y;
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static gboolean
|
2001-01-08 05:07:14 +08:00
|
|
|
button_press_event (GtkWidget *widget,
|
2004-08-15 23:31:20 +08:00
|
|
|
GdkEventButton *event,
|
|
|
|
ColorselWater *water)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2009-10-18 00:58:28 +08:00
|
|
|
GtkAllocation allocation;
|
|
|
|
gboolean erase;
|
2001-01-16 00:52:22 +08:00
|
|
|
|
2009-10-18 00:58:28 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
|
|
|
water->last_x = event->x / allocation.width;
|
|
|
|
water->last_y = event->y / allocation.height;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
erase = (event->button != 1);
|
2002-10-20 18:14:17 +08:00
|
|
|
/* FIXME: (event->source == GDK_SOURCE_ERASER) */
|
1999-05-09 00:34:29 +08:00
|
|
|
|
2006-03-10 21:12:15 +08:00
|
|
|
if (event->state & GDK_SHIFT_MASK)
|
|
|
|
erase = !erase;
|
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
add_pigment (water, erase, water->last_x, water->last_y, 0.05);
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
water->motion_time = event->time;
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static gboolean
|
2001-01-08 05:07:14 +08:00
|
|
|
motion_notify_event (GtkWidget *widget,
|
2004-08-15 23:31:20 +08:00
|
|
|
GdkEventMotion *event,
|
|
|
|
ColorselWater *water)
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2009-10-18 00:58:28 +08:00
|
|
|
GtkAllocation allocation;
|
2002-10-20 18:14:17 +08:00
|
|
|
GdkTimeCoord **coords;
|
2001-01-16 00:52:22 +08:00
|
|
|
gint nevents;
|
|
|
|
gint i;
|
|
|
|
gboolean erase;
|
|
|
|
|
2009-10-18 00:58:28 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2001-01-08 05:07:14 +08:00
|
|
|
if (event->state & (GDK_BUTTON1_MASK |
|
2004-08-15 23:31:20 +08:00
|
|
|
GDK_BUTTON2_MASK |
|
|
|
|
GDK_BUTTON3_MASK |
|
|
|
|
GDK_BUTTON4_MASK))
|
1999-05-09 00:34:29 +08:00
|
|
|
{
|
2006-03-10 21:12:15 +08:00
|
|
|
guint32 last_motion_time = event->time;
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
erase = ((event->state &
|
|
|
|
(GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK)) ||
|
|
|
|
FALSE);
|
|
|
|
/* FIXME: (event->source == GDK_SOURCE_ERASER) */
|
|
|
|
|
2006-03-10 21:12:15 +08:00
|
|
|
if (event->state & GDK_SHIFT_MASK)
|
|
|
|
erase = !erase;
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
water->motion_time = event->time;
|
|
|
|
|
|
|
|
if (gdk_device_get_history (event->device,
|
|
|
|
event->window,
|
|
|
|
last_motion_time,
|
|
|
|
event->time,
|
|
|
|
&coords,
|
|
|
|
&nevents))
|
2004-08-15 23:31:20 +08:00
|
|
|
{
|
|
|
|
for (i = 0; i < nevents; i++)
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
|
|
|
gdouble x = 0.0;
|
|
|
|
gdouble y = 0.0;
|
|
|
|
gdouble pressure = 0.5;
|
|
|
|
|
|
|
|
gdk_device_get_axis (event->device, coords[i]->axes,
|
|
|
|
GDK_AXIS_X, &x);
|
|
|
|
gdk_device_get_axis (event->device, coords[i]->axes,
|
|
|
|
GDK_AXIS_Y, &y);
|
|
|
|
gdk_device_get_axis (event->device, coords[i]->axes,
|
|
|
|
GDK_AXIS_PRESSURE, &pressure);
|
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
draw_brush (water, widget, erase,
|
2009-10-18 00:58:28 +08:00
|
|
|
x / allocation.width,
|
|
|
|
y / allocation.height, pressure);
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
2001-01-16 00:52:22 +08:00
|
|
|
|
2004-08-15 23:31:20 +08:00
|
|
|
g_free (coords);
|
|
|
|
}
|
1999-05-09 00:34:29 +08:00
|
|
|
else
|
2004-08-15 23:31:20 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
gdouble pressure = 0.5;
|
|
|
|
|
|
|
|
gdk_event_get_axis ((GdkEvent *) event, GDK_AXIS_PRESSURE, &pressure);
|
|
|
|
|
2004-08-17 23:07:27 +08:00
|
|
|
draw_brush (water, widget, erase,
|
2009-10-18 00:58:28 +08:00
|
|
|
event->x / allocation.width,
|
|
|
|
event->y / allocation.height, pressure);
|
2004-08-15 23:31:20 +08:00
|
|
|
}
|
1999-05-09 00:34:29 +08:00
|
|
|
}
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2008-09-04 03:24:51 +08:00
|
|
|
/* Ask for more motion events in case the event was a hint */
|
|
|
|
gdk_event_request_motions (event);
|
1999-05-09 00:34:29 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static gboolean
|
2001-01-08 05:07:14 +08:00
|
|
|
proximity_out_event (GtkWidget *widget,
|
2001-01-16 00:52:22 +08:00
|
|
|
GdkEventProximity *event,
|
2004-08-15 23:31:20 +08:00
|
|
|
ColorselWater *water)
|
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,
|
2004-08-15 23:31:20 +08:00
|
|
|
ColorselWater *water)
|
1999-05-10 05:50:33 +08:00
|
|
|
{
|
2009-10-09 17:57:17 +08:00
|
|
|
water->pressure_adjust = (gtk_adjustment_get_upper (adj) -
|
|
|
|
gtk_adjustment_get_value (adj)) / 100.0;
|
1999-09-05 20:45:17 +08:00
|
|
|
}
|