style: Convert draw_vline vfunc to a Cairo version

This commit is contained in:
Benjamin Otte 2010-08-16 15:40:03 +02:00
parent abaecf4308
commit e59cbd5605
3 changed files with 70 additions and 36 deletions

View File

@ -109,9 +109,8 @@ static void gtk_default_draw_hline (GtkStyle *style,
gint x2, gint x2,
gint y); gint y);
static void gtk_default_draw_vline (GtkStyle *style, static void gtk_default_draw_vline (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state_type, GtkStateType state_type,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint y1, gint y1,
@ -1689,16 +1688,14 @@ gtk_default_draw_hline (GtkStyle *style,
static void static void
gtk_default_draw_vline (GtkStyle *style, gtk_default_draw_vline (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state_type, GtkStateType state_type,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint y1, gint y1,
gint y2, gint y2,
gint x) gint x)
{ {
cairo_t *cr;
gint thickness_light; gint thickness_light;
gint thickness_dark; gint thickness_dark;
gint i; gint i;
@ -1706,15 +1703,8 @@ gtk_default_draw_vline (GtkStyle *style,
thickness_light = style->xthickness / 2; thickness_light = style->xthickness / 2;
thickness_dark = style->xthickness - thickness_light; thickness_dark = style->xthickness - thickness_light;
cr = gdk_cairo_create (window);
cairo_set_line_width (cr, 1.0); cairo_set_line_width (cr, 1.0);
if (area)
{
gdk_cairo_rectangle (cr, area);
cairo_clip (cr);
}
for (i = 0; i < thickness_dark; i++) for (i = 0; i < thickness_dark; i++)
{ {
_cairo_draw_line (cr, &style->dark[state_type], _cairo_draw_line (cr, &style->dark[state_type],
@ -1731,8 +1721,6 @@ gtk_default_draw_vline (GtkStyle *style,
_cairo_draw_line (cr, &style->light[state_type], _cairo_draw_line (cr, &style->light[state_type],
x + i, y1 + thickness_light - i, x + i, y2); x + i, y1 + thickness_light - i, x + i, y2);
} }
cairo_destroy (cr);
} }
static void static void
@ -4905,13 +4893,56 @@ gtk_paint_vline (GtkStyle *style,
gint y2_, gint y2_,
gint x) gint x)
{ {
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_vline != NULL); g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != 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_vline (style, window, state_type, cr = gtk_style_cairo_create (window, area);
(GdkRectangle *) area, widget, detail,
GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
widget, detail,
y1_, y2_, x); y1_, y2_, x);
cairo_destroy (cr);
}
/**
* gtk_cairo_paint_vline:
* @style: a #GtkStyle
* @cr: a #cairo_t
* @state_type: a state
* @widget: (allow-none): the widget
* @detail: (allow-none): a style detail
* @y1_: the starting y coordinate
* @y2_: the ending y coordinate
* @x: the x coordinate
*
* Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @cr
* using the given style and state.
*/
void
gtk_cairo_paint_vline (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
gint y1_,
gint y2_,
gint x)
{
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (cr != NULL);
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
cairo_save (cr);
GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
widget, detail,
y1_, y2_, x);
cairo_restore (cr);
} }
/** /**

View File

@ -174,9 +174,8 @@ struct _GtkStyleClass
gint x2, gint x2,
gint y); gint y);
void (*draw_vline) (GtkStyle *style, void (*draw_vline) (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state_type, GtkStateType state_type,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint y1_, gint y1_,
@ -479,6 +478,14 @@ void gtk_paint_vline (GtkStyle *style,
gint y1_, gint y1_,
gint y2_, gint y2_,
gint x); gint x);
void gtk_cairo_paint_vline (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
gint y1_,
gint y2_,
gint x);
void gtk_paint_shadow (GtkStyle *style, void gtk_paint_shadow (GtkStyle *style,
GdkWindow *window, GdkWindow *window,
GtkStateType state_type, GtkStateType state_type,

View File

@ -418,9 +418,8 @@ draw_hline (GtkStyle *style,
static void static void
draw_vline (GtkStyle *style, draw_vline (GtkStyle *style,
GdkWindow *window, cairo_t *cr,
GtkStateType state, GtkStateType state,
GdkRectangle *area,
GtkWidget *widget, GtkWidget *widget,
const gchar *detail, const gchar *detail,
gint y1, gint y1,
@ -430,9 +429,6 @@ draw_vline (GtkStyle *style,
ThemeImage *image; ThemeImage *image;
ThemeMatchData match_data; ThemeMatchData match_data;
g_return_if_fail (style != NULL);
g_return_if_fail (window != NULL);
match_data.function = TOKEN_D_VLINE; match_data.function = TOKEN_D_VLINE;
match_data.detail = (gchar *)detail; match_data.detail = (gchar *)detail;
match_data.flags = THEME_MATCH_ORIENTATION | THEME_MATCH_STATE; match_data.flags = THEME_MATCH_ORIENTATION | THEME_MATCH_STATE;
@ -443,12 +439,12 @@ draw_vline (GtkStyle *style,
if (image) if (image)
{ {
if (image->background) if (image->background)
theme_pixbuf_render_no_cairo (image->background, theme_pixbuf_render (image->background,
window, area, COMPONENT_ALL, FALSE, cr, COMPONENT_ALL, FALSE,
x, y1, 2, (y2 - y1) + 1); x, y1, 2, (y2 - y1) + 1);
} }
else else
parent_class->draw_vline (style, window, state, area, widget, detail, parent_class->draw_vline (style, cr, state, widget, detail,
y1, y2, x); y1, y2, x);
} }