render: Make rendering the background a single function

This commit is contained in:
Benjamin Otte 2014-10-08 03:26:01 +02:00
parent 3c50c0988a
commit 05460f4982
3 changed files with 56 additions and 84 deletions

View File

@ -492,14 +492,11 @@ gtk_do_render_background (GtkStyleContext *context,
gdouble width,
gdouble height)
{
GtkThemingBackground bg;
_gtk_theming_background_init (&bg, context,
x, y,
width, height,
gtk_style_context_get_junction_sides (context));
_gtk_theming_background_render (&bg, cr);
gtk_theming_background_render (context,
cr,
x, y,
width, height,
gtk_style_context_get_junction_sides (context));
}
/**
@ -1580,7 +1577,6 @@ gtk_do_render_extension (GtkStyleContext *context,
gdouble height,
GtkPositionType gap_side)
{
GtkThemingBackground bg;
GtkJunctionSides junction = 0;
guint hidden_side = 0;
@ -1604,11 +1600,11 @@ gtk_do_render_extension (GtkStyleContext *context,
break;
}
_gtk_theming_background_init (&bg, context,
x, y,
width, height,
junction);
_gtk_theming_background_render (&bg, cr);
gtk_theming_background_render (context,
cr,
x, y,
width, height,
junction);
render_frame_internal (context, cr,
x, y, width, height,

View File

@ -43,6 +43,20 @@
*/
#include "fallback-c89.c"
typedef struct _GtkThemingBackground GtkThemingBackground;
struct _GtkThemingBackground {
GtkStyleContext *context;
cairo_rectangle_t paint_area;
GtkRoundedBox border_box;
GtkRoundedBox padding_box;
GtkRoundedBox content_box;
GtkJunctionSides junction;
GdkRGBA bg_color;
};
static const GtkRoundedBox *
gtk_theming_background_get_box (GtkThemingBackground *bg,
GtkCssArea area)
@ -308,63 +322,44 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg)
}
void
_gtk_theming_background_init (GtkThemingBackground *bg,
GtkStyleContext *context,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
GtkJunctionSides junction)
{
g_assert (bg != NULL);
bg->context = context;
bg->paint_area.x = x;
bg->paint_area.y = y;
bg->paint_area.width = width;
bg->paint_area.height = height;
bg->junction = junction;
_gtk_theming_background_init_context (bg);
}
void
_gtk_theming_background_render (GtkThemingBackground *bg,
cairo_t *cr)
gtk_theming_background_render (GtkStyleContext *context,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
GtkJunctionSides junction)
{
GtkThemingBackground bg;
gint idx;
GtkCssValue *background_image;
background_image = _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
bg.context = context;
bg.paint_area.x = x;
bg.paint_area.y = y;
bg.paint_area.width = width;
bg.paint_area.height = height;
bg.junction = junction;
_gtk_theming_background_init_context (&bg);
background_image = _gtk_style_context_peek_property (bg.context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
cairo_save (cr);
cairo_translate (cr, bg->paint_area.x, bg->paint_area.y);
cairo_translate (cr, bg.paint_area.x, bg.paint_area.y);
_gtk_theming_background_apply_shadow (bg, cr, FALSE); /* Outset shadow */
_gtk_theming_background_apply_shadow (&bg, cr, FALSE); /* Outset shadow */
_gtk_theming_background_paint_color (bg, cr, background_image);
_gtk_theming_background_paint_color (&bg, cr, background_image);
for (idx = _gtk_css_array_value_get_n_values (background_image) - 1; idx >= 0; idx--)
{
_gtk_theming_background_paint_layer (bg, idx, cr);
_gtk_theming_background_paint_layer (&bg, idx, cr);
}
_gtk_theming_background_apply_shadow (bg, cr, TRUE); /* Inset shadow */
_gtk_theming_background_apply_shadow (&bg, cr, TRUE); /* Inset shadow */
cairo_restore (cr);
}
gboolean
_gtk_theming_background_has_background_image (GtkThemingBackground *bg)
{
GtkCssImage *image;
GtkCssValue *value = _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
if (_gtk_css_array_value_get_n_values (value) == 0)
return FALSE;
image = _gtk_css_image_value_get_image (_gtk_css_array_value_get_nth (value, 0));
return (image != NULL);
}

View File

@ -29,32 +29,13 @@
G_BEGIN_DECLS
typedef struct _GtkThemingBackground GtkThemingBackground;
struct _GtkThemingBackground {
GtkStyleContext *context;
cairo_rectangle_t paint_area;
GtkRoundedBox border_box;
GtkRoundedBox padding_box;
GtkRoundedBox content_box;
GtkJunctionSides junction;
GdkRGBA bg_color;
};
void _gtk_theming_background_init (GtkThemingBackground *bg,
GtkStyleContext *context,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
GtkJunctionSides junction);
void _gtk_theming_background_render (GtkThemingBackground *bg,
cairo_t *cr);
gboolean _gtk_theming_background_has_background_image (GtkThemingBackground *bg);
void gtk_theming_background_render (GtkStyleContext *context,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
GtkJunctionSides junction);
G_END_DECLS