Commit fe028e27 authored by Benjamin Otte's avatar Benjamin Otte

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.
parent 118c8876
......@@ -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:
......
......@@ -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,
......
......@@ -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)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment