style: Convert draw_option vfunc to Cairo version

This commit is contained in:
Benjamin Otte 2010-08-16 21:58:15 +02:00
parent fed19bcf50
commit f2dc8a26ed
3 changed files with 77 additions and 36 deletions

View File

@ -179,10 +179,9 @@ static void gtk_default_draw_check (GtkStyle *style,
gint width, gint width,
gint height); gint height);
static void gtk_default_draw_option (GtkStyle *style, static void gtk_default_draw_option (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state_type, GtkStateType state_type,
GtkShadowType shadow_type, GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint x, gint x,
@ -2891,10 +2890,9 @@ gtk_default_draw_check (GtkStyle *style,
static void static void
gtk_default_draw_option (GtkStyle *style, gtk_default_draw_option (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state_type, GtkStateType state_type,
GtkShadowType shadow_type, GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint x, gint x,
@ -2902,7 +2900,6 @@ gtk_default_draw_option (GtkStyle *style,
gint width, gint width,
gint height) gint height)
{ {
cairo_t *cr = gdk_cairo_create (window);
enum { BUTTON, MENU, CELL } type = BUTTON; enum { BUTTON, MENU, CELL } type = BUTTON;
int exterior_size; int exterior_size;
@ -2914,12 +2911,6 @@ gtk_default_draw_option (GtkStyle *style,
type = MENU; type = MENU;
} }
if (area)
{
gdk_cairo_rectangle (cr, area);
cairo_clip (cr);
}
exterior_size = MIN (width, height); exterior_size = MIN (width, height);
if (exterior_size % 2 == 0) /* Ensure odd */ if (exterior_size % 2 == 0) /* Ensure odd */
exterior_size -= 1; exterior_size -= 1;
@ -3005,8 +2996,6 @@ gtk_default_draw_option (GtkStyle *style,
line_thickness); line_thickness);
cairo_fill (cr); cairo_fill (cr);
} }
cairo_destroy (cr);
} }
static void static void
@ -5416,13 +5405,60 @@ gtk_paint_option (GtkStyle *style,
gint width, gint width,
gint height) gint height)
{ {
cairo_t *cr;
g_return_if_fail (GTK_IS_STYLE (style)); g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL); g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
g_return_if_fail (style->depth == gdk_drawable_get_depth (window)); g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, cr = gtk_style_cairo_create (window, area);
(GdkRectangle *) area, widget, detail,
gtk_cairo_paint_option (style, cr, state_type, shadow_type,
widget, detail,
x, y, width, height);
cairo_destroy (cr);
}
/**
* gtk_cairo_paint_option:
* @style: a #GtkStyle
* @cr: a #cairo_t
* @state_type: a state
* @shadow_type: the type of shadow to draw
* @widget: (allow-none): the widget
* @detail: (allow-none): a style detail
* @x: x origin of the rectangle to draw the option in
* @y: y origin of the rectangle to draw the option in
* @width: the width of the rectangle to draw the option in
* @height: the height of the rectangle to draw the option in
*
* Draws a radio button indicator in the given rectangle on @cr with
* the given parameters.
*/
void
gtk_cairo_paint_option (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height)
{
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
g_return_if_fail (cr != NULL);
cairo_save (cr);
GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
widget, detail,
x, y, width, height); x, y, width, height);
cairo_restore (cr);
} }
/** /**

View File

@ -244,10 +244,9 @@ struct _GtkStyleClass
gint width, gint width,
gint height); gint height);
void (*draw_option) (GtkStyle *style, void (*draw_option) (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state_type, GtkStateType state_type,
GtkShadowType shadow_type, GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint x, gint x,
@ -610,17 +609,27 @@ void gtk_cairo_paint_check (GtkStyle *style,
gint y, gint y,
gint width, gint width,
gint height); gint height);
void gtk_paint_option (GtkStyle *style, void gtk_paint_option (GtkStyle *style,
GdkWindow *window, GdkWindow *window,
GtkStateType state_type, GtkStateType state_type,
GtkShadowType shadow_type, GtkShadowType shadow_type,
const GdkRectangle *area, const GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint x, gint x,
gint y, gint y,
gint width, gint width,
gint height); gint height);
void gtk_cairo_paint_option (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
void gtk_paint_tab (GtkStyle *style, void gtk_paint_tab (GtkStyle *style,
GdkWindow *window, GdkWindow *window,
GtkStateType state_type, GtkStateType state_type,

View File

@ -714,11 +714,10 @@ draw_check (GtkStyle *style,
} }
static void static void
draw_option (GtkStyle *style, draw_option (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state, GtkStateType state,
GtkShadowType shadow, GtkShadowType shadow,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint x, gint x,
@ -728,18 +727,15 @@ draw_option (GtkStyle *style,
{ {
ThemeMatchData match_data; ThemeMatchData match_data;
g_return_if_fail(style != NULL);
g_return_if_fail(window != NULL);
match_data.function = TOKEN_D_OPTION; match_data.function = TOKEN_D_OPTION;
match_data.detail = (gchar *)detail; match_data.detail = (gchar *)detail;
match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE; match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
match_data.shadow = shadow; match_data.shadow = shadow;
match_data.state = state; match_data.state = state;
if (!draw_simple_image_no_cairo (style, window, area, widget, &match_data, TRUE, TRUE, if (!draw_simple_image (style, cr, widget, &match_data, TRUE, TRUE,
x, y, width, height)) x, y, width, height))
parent_class->draw_option (style, window, state, shadow, area, widget, detail, parent_class->draw_option (style, cr, state, shadow, widget, detail,
x, y, width, height); x, y, width, height);
} }