gimpcolorwheel.c revision e440181edb0c182fc57ec12a2dffa371be698dda
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/* HSV color selector for GTK+
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Copyright (C) 1999 The Free Software Foundation
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Michael Natterer <mitch@gimp.org> (ported back to GIMP)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * This library is free software; you can redistribute it and/or
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * modify it under the terms of the GNU Lesser General Public
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * License as published by the Free Software Foundation; either
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * version 2 of the License, or (at your option) any later version.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * This library is distributed in the hope that it will be useful,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * but WITHOUT ANY WARRANTY; without even the implied warranty of
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Lesser General Public License for more details.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * You should have received a copy of the GNU Lesser General Public
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * License along with this library; if not, write to the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Boston, MA 02111-1307, USA.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * file for a list of people on the GTK+ Team. See the ChangeLog
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * files for a list of changes. These files are distributed with
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * This widget was adopted by Inkscape by Alex Valavanis <valavanisalex@gmail.com>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * on 2013-01-08. Last merges with GIMP code were applied using the following
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * commits from the GIMP git repository at
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * http://git.gnome.org/browse/gimp/tree/modules/gimpcolorwheel.c
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Gtk+ 2 code merge: commit 632c5 (2013-01-06)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Gtk+ 3 code merge: commit bcfc6, gtk3-port branch (2013-01-06)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/* Default ring fraction */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/* Default width/height */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/* Default ring width */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/* Dragging modes */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonytypedef enum
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/* Private part of the GimpColorWheel structure */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonytypedef struct
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony /* Color value */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony /* ring_width is this fraction of size */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony /* Size and ring width */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony /* Window for capturing events */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony /* Dragging mode */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_unmap (GtkWidget *widget);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_realize (GtkWidget *widget);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_unrealize (GtkWidget *widget);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_size_allocate (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic gboolean gimp_color_wheel_button_press (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic gboolean gimp_color_wheel_button_release (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic gboolean gimp_color_wheel_motion (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic gboolean gimp_color_wheel_draw (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_get_preferred_width (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_get_preferred_height (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic gboolean gimp_color_wheel_expose (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_size_request (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic gboolean gimp_color_wheel_grab_broken (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic gboolean gimp_color_wheel_focus (GtkWidget *widget,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic void gimp_color_wheel_move (GimpColorWheel *wheel,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyG_DEFINE_TYPE (GimpColorWheel, gimp_color_wheel, GTK_TYPE_WIDGET)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonygimp_color_wheel_class_init (GimpColorWheelClass *class)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony GimpColorWheelClass *wheel_class = GIMP_COLOR_WHEEL_CLASS (class);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->unrealize = gimp_color_wheel_unrealize;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->size_allocate = gimp_color_wheel_size_allocate;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->button_press_event = gimp_color_wheel_button_press;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->button_release_event = gimp_color_wheel_button_release;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->motion_notify_event = gimp_color_wheel_motion;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->get_preferred_width = gimp_color_wheel_get_preferred_width;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->get_preferred_height = gimp_color_wheel_get_preferred_height;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->size_request = gimp_color_wheel_size_request;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->expose_event = gimp_color_wheel_expose;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony widget_class->grab_broken_event = gimp_color_wheel_grab_broken;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, 0,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony g_type_class_add_private (object_class, sizeof (GimpColorWheelPrivate));
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony priv = G_TYPE_INSTANCE_GET_PRIVATE (wheel, GIMP_TYPE_COLOR_WHEEL,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony gtk_widget_set_has_window (GTK_WIDGET (wheel), FALSE);
NULL);
NULL);
NULL);
NULL);
allocation->x,
allocation->y,
gdouble *s,
gdouble *v)
gdouble f, p, q, t;
saturation = *s;
value = *v;
switch ((int) hue)
*h = value;
*s = value;
*s = value;
*v = value;
*v = value;
*h = value;
/* Computes the vertices of the saturation/value triangle */
static gboolean
gdouble x,
gdouble y)
/* Computes a saturation/value pair based on the mouse coordinates */
gdouble x,
gdouble y,
gdouble *s,
gdouble *v)
x -= center_x;
y = center_y - y;
/* Computes whether a point is inside the saturation/value triangle */
static gboolean
gdouble x,
gdouble y)
gdouble x,
gdouble y)
cursor =
static gboolean
return TRUE;
static gboolean
gdouble x, y;
return FALSE;
x = event->x;
y = event->y;
priv->s,
priv->v);
return TRUE;
gdouble s, v;
return TRUE;
return FALSE;
static gboolean
gdouble x, y;
return FALSE;
x = event->x;
y = event->y;
gdouble s, v;
return TRUE;
static gboolean
gdouble x, y;
return FALSE;
x = event->x;
y = event->y;
return TRUE;
gdouble s, v;
return TRUE;
return FALSE;
gdouble r, g, b;
r = hue;
hsv_to_rgb (&r, &g, &b);
r = priv->h;
hsv_to_rgb (&r, &g, &b);
gdouble s,
gdouble v,
gint *r,
gint *g,
gint *b)
hsv_to_rgb (&h, &s, &v);
#define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
gint t;
gdouble r, g, b;
r = priv->h;
g = priv->s;
b = priv->v;
hsv_to_rgb (&r, &g, &b);
NULL);
static gboolean
return FALSE;
static gint
return FALSE;
allocation.x,
allocation.y,
return FALSE;
static gboolean
return TRUE;
switch (dir)
case GTK_DIR_UP:
return FALSE;
case GTK_DIR_DOWN:
return FALSE;
case GTK_DIR_LEFT:
case GTK_DIR_TAB_BACKWARD:
return FALSE;
case GTK_DIR_RIGHT:
case GTK_DIR_TAB_FORWARD:
return FALSE;
return TRUE;
gimp_color_wheel_new (void)
gdouble h,
gdouble s,
gdouble v)
priv->h = h;
priv->s = s;
priv->v = v;
gdouble *h,
gdouble *s,
gdouble *v)
if (h) *h = priv->h;
if (s) *s = priv->s;
if (v) *v = priv->v;
switch (dir)
case GTK_DIR_UP:
case GTK_DIR_DOWN:
case GTK_DIR_LEFT:
case GTK_DIR_RIGHT: