GtkThemingEngine: Add vmethod to render radio buttons.

This commit is contained in:
Carlos Garnacho 2010-03-20 17:37:34 +01:00
parent 401625b8b3
commit 263f6de0e5
2 changed files with 89 additions and 0 deletions

View File

@ -42,6 +42,12 @@ static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
gdouble y,
gdouble width,
gdouble height);
static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height);
G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
@ -74,6 +80,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
klass->render_check = gtk_theming_engine_render_check;
klass->render_option = gtk_theming_engine_render_option;
g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
}
@ -378,5 +385,81 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
gdk_color_free (text_color);
}
static void
gtk_theming_engine_render_option (GtkThemingEngine *engine,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height)
{
GtkStateFlags flags;
GdkColor *base_color, *fg_color, *text_color;
const GtkWidgetPath *path;
GtkStateType state;
gdouble radius;
flags = gtk_theming_engine_get_state (engine);
path = gtk_theming_engine_get_path (engine);
radius = MIN (width, height) / 2 - 0.5;
cairo_save (cr);
cairo_set_line_width (cr, 1);
if (flags & GTK_STATE_FLAG_PRELIGHT)
state = GTK_STATE_PRELIGHT;
else
state = GTK_STATE_NORMAL;
gtk_theming_engine_get (engine, state,
"foreground-color", &fg_color,
"base-color", &base_color,
"text-color", &text_color,
NULL);
if (!gtk_widget_path_has_parent (path, GTK_TYPE_MENU))
{
cairo_arc (cr,
x + (width / 2),
y + (height / 2),
radius,
0, 2 * G_PI);
gdk_cairo_set_source_color (cr, base_color);
cairo_fill_preserve (cr);
if (gtk_widget_path_has_parent (path, GTK_TYPE_TREE_VIEW))
gdk_cairo_set_source_color (cr, text_color);
else
gdk_cairo_set_source_color (cr, fg_color);
cairo_stroke (cr);
}
if (gtk_widget_path_has_parent (path, GTK_TYPE_MENU))
gdk_cairo_set_source_color (cr, fg_color);
else
gdk_cairo_set_source_color (cr, text_color);
if (gtk_theming_engine_is_state_set (engine, GTK_STATE_INCONSISTENT))
{
cairo_move_to (cr, x + (width * 0.2), y + (height / 2));
cairo_line_to (cr, x + (width * 0.8), y + (height / 2));
cairo_stroke (cr);
}
if (gtk_theming_engine_is_state_set (engine, GTK_STATE_ACTIVE))
{
cairo_arc (cr,
x + (width / 2),
y + (height / 2),
radius / 2,
0, 2 * G_PI);
cairo_fill (cr);
}
cairo_restore (cr);
}
#define __GTK_THEMING_ENGINE_C__
#include "gtkaliasdef.c"

View File

@ -55,6 +55,12 @@ struct GtkThemingEngineClass
gdouble y,
gdouble width,
gdouble height);
void (* render_option) (GtkThemingEngine *engine,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height);
};
GType gtk_theming_engine_get_type (void) G_GNUC_CONST;