From e59cbd5605386df241d22b7802b72a0e3967414d Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 16 Aug 2010 15:40:03 +0200 Subject: [PATCH] style: Convert draw_vline vfunc to a Cairo version --- gtk/gtkstyle.c | 65 ++++++++++++++++++++-------- gtk/gtkstyle.h | 29 ++++++++----- modules/engines/pixbuf/pixbuf-draw.c | 12 ++--- 3 files changed, 70 insertions(+), 36 deletions(-) diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index bce3d67c00..5800901333 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -109,9 +109,8 @@ static void gtk_default_draw_hline (GtkStyle *style, gint x2, gint y); static void gtk_default_draw_vline (GtkStyle *style, - GdkWindow *window, + cairo_t *cr, GtkStateType state_type, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint y1, @@ -1688,17 +1687,15 @@ gtk_default_draw_hline (GtkStyle *style, static void -gtk_default_draw_vline (GtkStyle *style, - GdkWindow *window, +gtk_default_draw_vline (GtkStyle *style, + cairo_t *cr, GtkStateType state_type, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint y1, gint y2, gint x) { - cairo_t *cr; gint thickness_light; gint thickness_dark; gint i; @@ -1706,15 +1703,8 @@ gtk_default_draw_vline (GtkStyle *style, thickness_light = style->xthickness / 2; thickness_dark = style->xthickness - thickness_light; - cr = gdk_cairo_create (window); cairo_set_line_width (cr, 1.0); - if (area) - { - gdk_cairo_rectangle (cr, area); - cairo_clip (cr); - } - for (i = 0; i < thickness_dark; i++) { _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], x + i, y1 + thickness_light - i, x + i, y2); } - - cairo_destroy (cr); } static void @@ -4905,13 +4893,56 @@ gtk_paint_vline (GtkStyle *style, gint y2_, gint x) { + cairo_t *cr; + g_return_if_fail (GTK_IS_STYLE (style)); g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL); g_return_if_fail (style->depth == gdk_drawable_get_depth (window)); - GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, - (GdkRectangle *) area, widget, detail, + cr = gtk_style_cairo_create (window, area); + + GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type, + widget, detail, 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); } /** diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h index 999babd733..ff208762fc 100644 --- a/gtk/gtkstyle.h +++ b/gtk/gtkstyle.h @@ -174,9 +174,8 @@ struct _GtkStyleClass gint x2, gint y); void (*draw_vline) (GtkStyle *style, - GdkWindow *window, + cairo_t *cr, GtkStateType state_type, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint y1_, @@ -470,15 +469,23 @@ void gtk_cairo_paint_hline (GtkStyle *style, gint x1, gint x2, gint y); -void gtk_paint_vline (GtkStyle *style, - GdkWindow *window, - GtkStateType state_type, - const GdkRectangle *area, - GtkWidget *widget, - const gchar *detail, - gint y1_, - gint y2_, - gint x); +void gtk_paint_vline (GtkStyle *style, + GdkWindow *window, + GtkStateType state_type, + const GdkRectangle *area, + GtkWidget *widget, + const gchar *detail, + gint y1_, + gint y2_, + 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, GdkWindow *window, GtkStateType state_type, diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c index 74007b6b68..f1f3c5b9b4 100644 --- a/modules/engines/pixbuf/pixbuf-draw.c +++ b/modules/engines/pixbuf/pixbuf-draw.c @@ -418,9 +418,8 @@ draw_hline (GtkStyle *style, static void draw_vline (GtkStyle *style, - GdkWindow *window, + cairo_t *cr, GtkStateType state, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint y1, @@ -430,9 +429,6 @@ draw_vline (GtkStyle *style, ThemeImage *image; ThemeMatchData match_data; - g_return_if_fail (style != NULL); - g_return_if_fail (window != NULL); - match_data.function = TOKEN_D_VLINE; match_data.detail = (gchar *)detail; match_data.flags = THEME_MATCH_ORIENTATION | THEME_MATCH_STATE; @@ -443,12 +439,12 @@ draw_vline (GtkStyle *style, if (image) { if (image->background) - theme_pixbuf_render_no_cairo (image->background, - window, area, COMPONENT_ALL, FALSE, + theme_pixbuf_render (image->background, + cr, COMPONENT_ALL, FALSE, x, y1, 2, (y2 - y1) + 1); } else - parent_class->draw_vline (style, window, state, area, widget, detail, + parent_class->draw_vline (style, cr, state, widget, detail, y1, y2, x); }