[gtk+] render: Only render 4 different arrows
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] render: Only render 4 different arrows
- Date: Tue, 20 Jan 2015 05:34:20 +0000 (UTC)
commit fe028e27899e818f84bb007a44b83802a97ef071
Author: Benjamin Otte <otte redhat com>
Date: Mon Jan 19 05:44:47 2015 +0100
render: Only render 4 different arrows
Instead of supporting every angle, just support top, right, bottom and
left and round the angle to one of those directions.
Adwaita overrides arrows anyway and doesn't even look at the angle, so
this should not be a problem.
gtk/gtkcssimagebuiltin.c | 27 +++++++++++++++++++++++++--
gtk/gtkcssimagebuiltinprivate.h | 5 ++++-
gtk/gtkrender.c | 30 ++++++++++++++++++++++++++----
3 files changed, 55 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkcssimagebuiltin.c b/gtk/gtkcssimagebuiltin.c
index 1ce28e2..b80f568 100644
--- a/gtk/gtkcssimagebuiltin.c
+++ b/gtk/gtkcssimagebuiltin.c
@@ -219,6 +219,7 @@ gtk_css_image_builtin_draw_arrow (GtkCssImage *image,
cairo_t *cr,
double width,
double height,
+ GtkCssImageBuiltinType image_type,
const GdkRGBA * color)
{
double line_width;
@@ -226,7 +227,25 @@ gtk_css_image_builtin_draw_arrow (GtkCssImage *image,
size = MIN (width, height);
- cairo_translate (cr, width / 2.0 + size / 4.0, height / 2.0);
+ cairo_translate (cr, width / 2.0, height / 2.0);
+ switch (image_type)
+ {
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_UP:
+ break;
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_DOWN:
+ cairo_rotate (cr, G_PI);
+ break;
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT:
+ cairo_rotate (cr, 3 * G_PI / 2);
+ break;
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT:
+ cairo_rotate (cr, G_PI / 2);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ cairo_translate (cr, size / 4.0, 0);
line_width = size / 3.0 / sqrt (2);
cairo_set_line_width (cr, line_width);
@@ -867,9 +886,13 @@ gtk_css_image_builtin_draw (GtkCssImage *image,
fg_color, bg_color,
border_color, border_width);
break;
- case GTK_CSS_IMAGE_BUILTIN_ARROW:
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_UP:
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_DOWN:
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT:
+ case GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT:
gtk_css_image_builtin_draw_arrow (image, cr,
width, height,
+ image_type,
fg_color);
break;
case GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_LEFT:
diff --git a/gtk/gtkcssimagebuiltinprivate.h b/gtk/gtkcssimagebuiltinprivate.h
index 3f11a79..082a6e3 100644
--- a/gtk/gtkcssimagebuiltinprivate.h
+++ b/gtk/gtkcssimagebuiltinprivate.h
@@ -33,7 +33,10 @@ typedef enum {
GTK_CSS_IMAGE_BUILTIN_OPTION,
GTK_CSS_IMAGE_BUILTIN_OPTION_CHECKED,
GTK_CSS_IMAGE_BUILTIN_OPTION_INCONSISTENT,
- GTK_CSS_IMAGE_BUILTIN_ARROW,
+ GTK_CSS_IMAGE_BUILTIN_ARROW_UP,
+ GTK_CSS_IMAGE_BUILTIN_ARROW_DOWN,
+ GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT,
+ GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT,
GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_LEFT,
GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_LEFT,
GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_RIGHT,
diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c
index 542c467..54bc410 100644
--- a/gtk/gtkrender.c
+++ b/gtk/gtkrender.c
@@ -287,8 +287,32 @@ gtk_do_render_arrow (GtkStyleContext *context,
gdouble size)
{
GtkBorderStyle border_style;
+ GtkCssImageBuiltinType image_type;
gint border_width;
+ /* map [0, 2 * pi) to [0, 4) */
+ angle = round (2 * angle / G_PI);
+
+ switch (((int) angle) & 3)
+ {
+ case 0:
+ image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_UP;
+ break;
+ case 1:
+ image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT;
+ break;
+ case 2:
+ image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_DOWN;
+ break;
+ case 3:
+ image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT;
+ break;
+ default:
+ g_assert_not_reached ();
+ image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_UP;
+ break;
+ }
+
if (render_icon_image (context, cr, x, y, size, size))
return;
@@ -310,14 +334,12 @@ gtk_do_render_arrow (GtkStyleContext *context,
border_width = 0;
}
- cairo_translate (cr, x + size / 2.0, y + size / 2.0);
- cairo_rotate (cr, angle - G_PI_2);
- cairo_translate (cr, - size / 2.0, - size / 2.0);
+ 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,
- GTK_CSS_IMAGE_BUILTIN_ARROW,
+ image_type,
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_BACKGROUND_COLOR)),
_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_BORDER_TOP_COLOR)),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]