themingbackground: Use an array instead of 3 separate members

Simplifies code
This commit is contained in:
Benjamin Otte 2014-10-08 04:59:58 +02:00
parent 05460f4982
commit 8abf82fcf4

View File

@ -45,35 +45,18 @@
typedef struct _GtkThemingBackground GtkThemingBackground; typedef struct _GtkThemingBackground GtkThemingBackground;
#define N_BOXES (3)
struct _GtkThemingBackground { struct _GtkThemingBackground {
GtkStyleContext *context; GtkStyleContext *context;
cairo_rectangle_t paint_area; cairo_rectangle_t paint_area;
GtkRoundedBox border_box; GtkRoundedBox boxes[N_BOXES];
GtkRoundedBox padding_box;
GtkRoundedBox content_box;
GtkJunctionSides junction; GtkJunctionSides junction;
GdkRGBA bg_color; GdkRGBA bg_color;
}; };
static const GtkRoundedBox *
gtk_theming_background_get_box (GtkThemingBackground *bg,
GtkCssArea area)
{
switch (area)
{
case GTK_CSS_AREA_BORDER_BOX:
return &bg->border_box;
case GTK_CSS_AREA_PADDING_BOX:
return &bg->padding_box;
case GTK_CSS_AREA_CONTENT_BOX:
return &bg->content_box;
default:
g_return_val_if_reached (&bg->border_box);
}
}
static void static void
_gtk_theming_background_paint_color (GtkThemingBackground *bg, _gtk_theming_background_paint_color (GtkThemingBackground *bg,
cairo_t *cr, cairo_t *cr,
@ -86,7 +69,7 @@ _gtk_theming_background_paint_color (GtkThemingBackground *bg,
n_values - 1)); n_values - 1));
cairo_save (cr); cairo_save (cr);
_gtk_rounded_box_path (gtk_theming_background_get_box (bg, clip), cr); _gtk_rounded_box_path (&bg->boxes[clip], cr);
cairo_clip (cr); cairo_clip (cr);
gdk_cairo_set_source_rgba (cr, &bg->bg_color); gdk_cairo_set_source_rgba (cr, &bg->bg_color);
@ -115,12 +98,11 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
_gtk_css_array_value_get_nth ( _gtk_css_array_value_get_nth (
_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE), _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE),
idx)); idx));
origin = gtk_theming_background_get_box ( origin = &bg->boxes[
bg,
_gtk_css_area_value_get ( _gtk_css_area_value_get (
_gtk_css_array_value_get_nth ( _gtk_css_array_value_get_nth (
_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_ORIGIN), _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_ORIGIN),
idx))); idx))];
width = origin->box.width; width = origin->box.width;
height = origin->box.height; height = origin->box.height;
@ -147,12 +129,11 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
cairo_save (cr); cairo_save (cr);
_gtk_rounded_box_path ( _gtk_rounded_box_path (
gtk_theming_background_get_box ( &bg->boxes[
bg,
_gtk_css_area_value_get ( _gtk_css_area_value_get (
_gtk_css_array_value_get_nth ( _gtk_css_array_value_get_nth (
_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_CLIP), _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_CLIP),
idx))), idx))],
cr); cr);
cairo_clip (cr); cairo_clip (cr);
@ -285,7 +266,7 @@ _gtk_theming_background_apply_shadow (GtkThemingBackground *bg,
{ {
_gtk_css_shadows_value_paint_box (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BOX_SHADOW), _gtk_css_shadows_value_paint_box (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BOX_SHADOW),
cr, cr,
inset ? &bg->padding_box : &bg->border_box, &bg->boxes[inset ? GTK_CSS_AREA_PADDING_BOX : GTK_CSS_AREA_BORDER_BOX],
inset); inset);
} }
@ -307,16 +288,16 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg)
* In the future we might want to support different origins or clips, but * In the future we might want to support different origins or clips, but
* right now we just shrink to the default. * right now we just shrink to the default.
*/ */
_gtk_rounded_box_init_rect (&bg->border_box, 0, 0, bg->paint_area.width, bg->paint_area.height); _gtk_rounded_box_init_rect (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], 0, 0, bg->paint_area.width, bg->paint_area.height);
_gtk_rounded_box_apply_border_radius_for_context (&bg->border_box, bg->context, bg->junction); _gtk_rounded_box_apply_border_radius_for_context (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], bg->context, bg->junction);
bg->padding_box = bg->border_box; bg->boxes[GTK_CSS_AREA_PADDING_BOX] = bg->boxes[GTK_CSS_AREA_BORDER_BOX];
_gtk_rounded_box_shrink (&bg->padding_box, _gtk_rounded_box_shrink (&bg->boxes[GTK_CSS_AREA_PADDING_BOX],
border.top, border.right, border.top, border.right,
border.bottom, border.left); border.bottom, border.left);
bg->content_box = bg->padding_box; bg->boxes[GTK_CSS_AREA_CONTENT_BOX] = bg->boxes[GTK_CSS_AREA_PADDING_BOX];
_gtk_rounded_box_shrink (&bg->content_box, _gtk_rounded_box_shrink (&bg->boxes[GTK_CSS_AREA_CONTENT_BOX],
padding.top, padding.right, padding.top, padding.right,
padding.bottom, padding.left); padding.bottom, padding.left);
} }