From 9e5d9ff28d9ac3c546c9a3a625ad91d057a6f6ba Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Sat, 27 Mar 2010 21:27:52 +0100 Subject: [PATCH] GtkThemingEngine: Add vmethod to render a handle area. --- gtk/gtkthemingengine.c | 83 ++++++++++++++++++++++++++++++++++++++++++ gtk/gtkthemingengine.h | 7 ++++ 2 files changed, 90 insertions(+) diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c index 6a2bd38a0e..3a019dc995 100644 --- a/gtk/gtkthemingengine.c +++ b/gtk/gtkthemingengine.c @@ -119,6 +119,13 @@ static void gtk_theming_engine_render_extension (GtkThemingEngine *engine, gdouble width, gdouble height, GtkPositionType gap_side); +static void gtk_theming_engine_render_handle (GtkThemingEngine *engine, + cairo_t *cr, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + GtkOrientation orientation); G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT) @@ -162,6 +169,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass) klass->render_slider = gtk_theming_engine_render_slider; klass->render_frame_gap = gtk_theming_engine_render_frame_gap; klass->render_extension = gtk_theming_engine_render_extension; + klass->render_handle = gtk_theming_engine_render_handle; g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate)); } @@ -1344,5 +1352,80 @@ gtk_theming_engine_render_extension (GtkThemingEngine *engine, gdk_color_free (bg_color); } +static void +paint_point (cairo_t *cr, + const GdkColor *lighter, + const GdkColor *darker, + gdouble x, + gdouble y) +{ + cairo_move_to (cr, x - 0.5, y + 1); + cairo_line_to (cr, x - 0.5, y - 0.5); + cairo_line_to (cr, x + 1, y - 0.5); + gdk_cairo_set_source_color (cr, lighter); + cairo_stroke (cr); + + cairo_move_to (cr, x + 1.5, y); + cairo_line_to (cr, x + 1.5, y + 1.5); + cairo_line_to (cr, x, y + 1.5); + gdk_cairo_set_source_color (cr, darker); + cairo_stroke (cr); +} + +static void +gtk_theming_engine_render_handle (GtkThemingEngine *engine, + cairo_t *cr, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + GtkOrientation orientation) +{ + GtkStateFlags flags; + GtkStateType state; + GdkColor *bg_color; + GdkColor lighter, darker; + gint xx, yy; + + cairo_save (cr); + flags = gtk_theming_engine_get_state (engine); + + if (flags & GTK_STATE_FLAG_ACTIVE) + state = GTK_STATE_ACTIVE; + else if (flags & GTK_STATE_FLAG_PRELIGHT) + state = GTK_STATE_PRELIGHT; + else if (flags & GTK_STATE_FLAG_INSENSITIVE) + state = GTK_STATE_INSENSITIVE; + else + state = GTK_STATE_NORMAL; + + cairo_set_line_width (cr, 1); + + gtk_theming_engine_get (engine, state, + "background-color", &bg_color, + NULL); + color_shade (bg_color, 0.7, &darker); + color_shade (bg_color, 1.3, &lighter); + + add_path_rounded_rectangle (cr, 0, + SIDE_BOTTOM | SIDE_RIGHT | SIDE_TOP | SIDE_LEFT, + x, y, width, height); + cairo_close_path (cr); + + gdk_cairo_set_source_color (cr, bg_color); + cairo_fill (cr); + + if (orientation == GTK_ORIENTATION_HORIZONTAL) + for (xx = x + width / 2 - 15; xx <= x + width / 2 + 15; xx += 5) + paint_point (cr, &lighter, &darker, xx, y + height / 2 - 1); + else + for (yy = y + height / 2 - 15; yy <= y + height / 2 + 15; yy += 5) + paint_point (cr, &lighter, &darker, x + width / 2, yy); + + cairo_restore (cr); + + gdk_color_free (bg_color); +} + #define __GTK_THEMING_ENGINE_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h index 31e7635eca..6ff8214098 100644 --- a/gtk/gtkthemingengine.h +++ b/gtk/gtkthemingengine.h @@ -125,6 +125,13 @@ struct GtkThemingEngineClass gdouble width, gdouble height, GtkOrientation orientation); + void (* render_handle) (GtkThemingEngine *engine, + cairo_t *cr, + gdouble x, + gdouble y, + gdouble width, + gdouble height, + GtkOrientation orientation); }; GType gtk_theming_engine_get_type (void) G_GNUC_CONST;