summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-01-19 17:30:43 +0100
committerBenjamin Otte <otte@redhat.com>2015-01-20 06:30:19 +0100
commitcc4d34e6884b958505dfd888d9b53b4b39084581 (patch)
treec2e048edb5c1cae4f5e4095cc032bd36da56ed97
parent45541cbf10a13716680df52c6a214495fb8243d7 (diff)
downloadgtk+-cc4d34e6884b958505dfd888d9b53b4b39084581.tar.gz
render: Render builtin images as regular CSS images
This not only reduces code, but also allows for builtin images to have shadows or be transformed using -gtk-icon-transform.
-rw-r--r--gtk/gtkcssimagebuiltin.c6
-rw-r--r--gtk/gtkrender.c97
2 files changed, 23 insertions, 80 deletions
diff --git a/gtk/gtkcssimagebuiltin.c b/gtk/gtkcssimagebuiltin.c
index f64edc385a..6562931c21 100644
--- a/gtk/gtkcssimagebuiltin.c
+++ b/gtk/gtkcssimagebuiltin.c
@@ -877,6 +877,12 @@ gtk_css_image_builtin_draw (GtkCssImage *image,
double height,
GtkCssImageBuiltinType image_type)
{
+ if (!GTK_IS_CSS_IMAGE_BUILTIN (image))
+ {
+ _gtk_css_image_draw (image, cr, width, height);
+ return;
+ }
+
switch (image_type)
{
default:
diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c
index 6b03ac4985..133ba2fd29 100644
--- a/gtk/gtkrender.c
+++ b/gtk/gtkrender.c
@@ -37,13 +37,14 @@
#include "fallback-c89.c"
-static gboolean
-render_icon_image (GtkStyleContext *context,
- cairo_t *cr,
- double x,
- double y,
- double width,
- double height)
+static void
+render_icon_image (GtkStyleContext *context,
+ cairo_t *cr,
+ double x,
+ double y,
+ double width,
+ double height,
+ GtkCssImageBuiltinType builtin_type)
{
const GtkCssValue *shadows;
cairo_matrix_t matrix, transform_matrix;
@@ -51,10 +52,7 @@ render_icon_image (GtkStyleContext *context,
image = _gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE));
if (image == NULL)
- return TRUE;
-
- if (GTK_IS_CSS_IMAGE_BUILTIN (image))
- return FALSE;
+ return;
shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SHADOW);
@@ -70,20 +68,18 @@ render_icon_image (GtkStyleContext *context,
if (_gtk_css_shadows_value_is_none (shadows))
{
cairo_transform (cr, &matrix);
- _gtk_css_image_draw (image, cr, width, height);
+ gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
}
else
{
cairo_push_group (cr);
cairo_transform (cr, &matrix);
- _gtk_css_image_draw (image, cr, width, height);
+ gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
cairo_pop_group_to_source (cr);
_gtk_css_shadows_value_paint_icon (shadows, cr);
cairo_paint (cr);
}
}
-
- return TRUE;
}
static void
@@ -105,15 +101,7 @@ gtk_do_render_check (GtkStyleContext *context,
else
image_type = GTK_CSS_IMAGE_BUILTIN_CHECK;
- if (render_icon_image (context, cr, x, y, width, height))
- return;
-
- cairo_translate (cr, x, y);
-
- gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
- cr,
- width, height,
- image_type);
+ render_icon_image (context, cr, x, y, width, height, image_type);
}
/**
@@ -178,15 +166,7 @@ gtk_do_render_option (GtkStyleContext *context,
else
image_type = GTK_CSS_IMAGE_BUILTIN_OPTION;
- if (render_icon_image (context, cr, x, y, width, height))
- return;
-
- cairo_translate (cr, x, y);
-
- gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
- cr,
- width, height,
- image_type);
+ render_icon_image (context, cr, x, y, width, height, image_type);
}
/**
@@ -263,15 +243,7 @@ gtk_do_render_arrow (GtkStyleContext *context,
break;
}
- if (render_icon_image (context, cr, x, y, size, size))
- return;
-
- cairo_translate (cr, x, y);
-
- gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
- cr,
- size, size,
- image_type);
+ render_icon_image (context, cr, x, y, size, size, image_type);
}
/**
@@ -439,15 +411,7 @@ gtk_do_render_expander (GtkStyleContext *context,
: GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_LEFT;
}
- if (render_icon_image (context, cr, x, y, width, height))
- return;
-
- cairo_translate (cr, x, y);
-
- gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
- cr,
- width, height,
- image_type);
+ render_icon_image (context, cr, x, y, width, height, image_type);
}
/**
@@ -1001,11 +965,6 @@ gtk_do_render_handle (GtkStyleContext *context,
gtk_render_background (context, cr, x, y, width, height);
gtk_render_frame (context, cr, x, y, width, height);
- if (render_icon_image (context, cr, x, y, width, height))
- return;
-
- cairo_translate (cr, x, y);
-
if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_GRIP))
{
GtkJunctionSides sides = gtk_style_context_get_junction_sides (context);
@@ -1039,10 +998,7 @@ gtk_do_render_handle (GtkStyleContext *context,
type = GTK_CSS_IMAGE_BUILTIN_HANDLE;
}
- gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
- cr,
- width, height,
- type);
+ render_icon_image (context, cr, x, y, width, height, type);
}
/**
@@ -1136,25 +1092,6 @@ gtk_render_paint_spinner (cairo_t *cr,
cairo_restore (cr);
}
-static void
-gtk_do_render_activity (GtkStyleContext *context,
- cairo_t *cr,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height)
-{
- if (render_icon_image (context, cr, x, y, width, height))
- return;
-
- cairo_translate (cr, x, y);
-
- gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
- cr,
- width, height,
- GTK_CSS_IMAGE_BUILTIN_SPINNER);
-}
-
/**
* gtk_render_activity:
* @context: a #GtkStyleContext
@@ -1187,7 +1124,7 @@ gtk_render_activity (GtkStyleContext *context,
cairo_save (cr);
cairo_new_path (cr);
- gtk_do_render_activity (context, cr, x, y, width, height);
+ render_icon_image (context, cr, x, y, width, height, GTK_CSS_IMAGE_BUILTIN_SPINNER);
cairo_restore (cr);
}