#include <math.h>
#include <string.h>
-#include "gdk/gdkkeysyms.h"
-
#include "gtkhsv.h"
#include "gtkbindings.h"
#include "gtkmarshalers.h"
-#include "gtktypeutils.h"
+#include "gtktypebuiltins.h"
#include "gtkintl.h"
/* Default width/height */
priv->window = gdk_window_new (parent_window, &attr, attr_mask);
gdk_window_set_user_data (priv->window, hsv);
gdk_window_show (priv->window);
-
- gtk_widget_style_attach (widget);
}
static void
/* Event handlers */
static void
-set_cross_grab (GtkHSV *hsv,
- guint32 time)
+set_cross_grab (GtkHSV *hsv,
+ GdkDevice *device,
+ guint32 time)
{
GtkHSVPrivate *priv = hsv->priv;
GdkCursor *cursor;
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (hsv)),
GDK_CROSSHAIR);
- gdk_pointer_grab (priv->window, FALSE,
- (GDK_POINTER_MOTION_MASK
- | GDK_POINTER_MOTION_HINT_MASK
- | GDK_BUTTON_RELEASE_MASK),
- NULL,
- cursor,
- time);
- gdk_cursor_unref (cursor);
+ gdk_device_grab (device,
+ priv->window,
+ GDK_OWNERSHIP_NONE,
+ FALSE,
+ GDK_POINTER_MOTION_MASK
+ | GDK_POINTER_MOTION_HINT_MASK
+ | GDK_BUTTON_RELEASE_MASK,
+ cursor,
+ time);
+ g_object_unref (cursor);
}
static gboolean
if (priv->mode != DRAG_NONE || event->button != 1)
return FALSE;
-
+
x = event->x;
y = event->y;
-
+
if (is_in_ring (hsv, x, y))
{
priv->mode = DRAG_H;
- set_cross_grab (hsv, event->time);
-
+ set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
+
gtk_hsv_set_color (hsv,
compute_v (hsv, x, y),
priv->s,
gtk_widget_grab_focus (widget);
priv->focus_on_ring = TRUE;
-
+
return TRUE;
}
-
+
if (is_in_triangle (hsv, x, y))
{
gdouble s, v;
-
+
priv->mode = DRAG_SV;
- set_cross_grab (hsv, event->time);
-
+ set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
+
compute_sv (hsv, x, y, &s, &v);
gtk_hsv_set_color (hsv, priv->h, s, v);
gtk_widget_grab_focus (widget);
priv->focus_on_ring = FALSE;
-
+
return TRUE;
}
-
+
return FALSE;
}
if (priv->mode == DRAG_NONE || event->button != 1)
return FALSE;
-
+
/* Set the drag mode to DRAG_NONE so that signal handlers for "catched"
* can see that this is the final color state.
*/
-
mode = priv->mode;
priv->mode = DRAG_NONE;
-
+
x = event->x;
y = event->y;
g_assert_not_reached ();
}
- gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
- event->time);
+ gdk_device_ungrab (gdk_event_get_device ((GdkEvent *) event), event->time);
+
return TRUE;
}
{
GtkHSV *hsv = GTK_HSV (widget);
GtkHSVPrivate *priv = hsv->priv;
- GdkModifierType mods;
- double x, y;
+ gdouble x, y;
if (priv->mode == DRAG_NONE)
return FALSE;
gdk_event_request_motions (event);
x = event->x;
y = event->y;
- mods = event->state;
if (priv->mode == DRAG_H)
{
gint x_start, x_end;
cairo_surface_t *source;
gdouble r, g, b;
- gchar *detail;
gint stride;
int width, height;
-
+ GtkStyleContext *context;
+ GtkStateFlags state;
+
priv = hsv->priv;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
b = priv->v;
hsv_to_rgb (&r, &g, &b);
+ context = gtk_widget_get_style_context (widget);
+
+ gtk_style_context_save (context);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_set_state (context, state);
+
if (INTENSITY (r, g, b) > 0.5)
{
- detail = "colorwheel_light";
+ gtk_style_context_add_class (context, "light-area-focus");
cairo_set_source_rgb (cr, 0., 0., 0.);
}
else
{
- detail = "colorwheel_dark";
+ gtk_style_context_add_class (context, "dark-area-focus");
cairo_set_source_rgb (cr, 1., 1., 1.);
}
"focus-padding", &focus_pad,
NULL);
- gtk_paint_focus (gtk_widget_get_style (widget),
- cr,
- gtk_widget_get_state (widget),
- widget, detail,
- xx - FOCUS_RADIUS - focus_width - focus_pad,
- yy - FOCUS_RADIUS - focus_width - focus_pad,
- 2 * (FOCUS_RADIUS + focus_width + focus_pad),
- 2 * (FOCUS_RADIUS + focus_width + focus_pad));
+ gtk_render_focus (context, cr,
+ xx - FOCUS_RADIUS - focus_width - focus_pad,
+ yy - FOCUS_RADIUS - focus_width - focus_pad,
+ 2 * (FOCUS_RADIUS + focus_width + focus_pad),
+ 2 * (FOCUS_RADIUS + focus_width + focus_pad));
}
+
+ gtk_style_context_restore (context);
}
/* Paints the contents of the HSV color selector */
paint_triangle (hsv, cr);
if (gtk_widget_has_focus (widget) && priv->focus_on_ring)
- gtk_paint_focus (gtk_widget_get_style (widget),
- cr,
- gtk_widget_get_state (widget),
- widget, NULL,
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
+ {
+ GtkStyleContext *context;
+ GtkStateFlags state;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
+
+ gtk_render_focus (context, cr, 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ gtk_style_context_restore (context);
+ }
return FALSE;
}
/**
* gtk_hsv_get_color:
* @hsv: An HSV color selector
- * @h: Return value for the hue
- * @s: Return value for the saturation
- * @v: Return value for the value
+ * @h: (out): Return value for the hue
+ * @s: (out): Return value for the saturation
+ * @v: (out): Return value for the value
*
* Queries the current color in an HSV color selector.
* Returned values will be in the [0.0, 1.0] range.
/**
* gtk_hsv_get_metrics:
* @hsv: An HSV color selector
- * @size: Return value for the diameter of the hue ring
- * @ring_width: Return value for the width of the hue ring
+ * @size: (out): Return value for the diameter of the hue ring
+ * @ring_width: (out): Return value for the width of the hue ring
*
* Queries the size and ring width of an HSV color selector.
*
* @h: Hue
* @s: Saturation
* @v: Value
- * @r: Return value for the red component
- * @g: Return value for the green component
- * @b: Return value for the blue component
+ * @r: (out): Return value for the red component
+ * @g: (out): Return value for the green component
+ * @b: (out): Return value for the blue component
*
* Converts a color from HSV space to RGB.
* Input values must be in the [0.0, 1.0] range;
* @r: Red
* @g: Green
* @b: Blue
- * @h: Return value for the hue component
- * @s: Return value for the saturation component
- * @v: Return value for the value component
+ * @h: (out): Return value for the hue component
+ * @s: (out): Return value for the saturation component
+ * @v: (out): Return value for the value component
*
* Converts a color from RGB space to HSV.
* Input values must be in the [0.0, 1.0] range;