cssimage: Fix angle computation for gradients to corners

This commit is contained in:
Benjamin Otte 2015-01-08 19:30:19 +01:00
parent 0d5acf2a05
commit 9474215a43

View File

@ -135,6 +135,7 @@ gtk_css_image_linear_draw (GtkCssImage *image,
{ {
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image); GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
double angle; /* actual angle of the gradiant line in degrees */
double x, y; /* coordinates of start point */ double x, y; /* coordinates of start point */
double length; /* distance in pixels for 100% */ double length; /* distance in pixels for 100% */
double start, end; /* position of first/last point on gradient line - with gradient line being [0, 1] */ double start, end; /* position of first/last point on gradient line - with gradient line being [0, 1] */
@ -145,27 +146,37 @@ gtk_css_image_linear_draw (GtkCssImage *image,
{ {
guint side = _gtk_css_number_value_get (linear->angle, 100); guint side = _gtk_css_number_value_get (linear->angle, 100);
if (side & (1 << GTK_CSS_RIGHT)) /* special casing the regular cases here so we don't get rounding errors */
x = width; switch (side)
else if (side & (1 << GTK_CSS_LEFT)) {
x = -width; case 1 << GTK_CSS_RIGHT:
else angle = 90;
x = 0; break;
case 1 << GTK_CSS_LEFT:
if (side & (1 << GTK_CSS_TOP)) angle = 270;
y = -height; break;
else if (side & (1 << GTK_CSS_BOTTOM)) case 1 << GTK_CSS_TOP:
y = height; angle = 0;
else break;
y = 0; case 1 << GTK_CSS_BOTTOM:
angle = 180;
break;
default:
angle = atan2 (side & 1 << GTK_CSS_TOP ? -width : width,
side & 1 << GTK_CSS_LEFT ? -height : height);
angle = 180 * angle / G_PI + 90;
break;
}
} }
else else
{ {
gtk_css_image_linear_compute_start_point (_gtk_css_number_value_get (linear->angle, 100), angle = _gtk_css_number_value_get (linear->angle, 100);
width, height,
&x, &y);
} }
gtk_css_image_linear_compute_start_point (angle,
width, height,
&x, &y);
length = sqrt (x * x + y * y); length = sqrt (x * x + y * y);
gtk_css_image_linear_get_start_end (linear, length, &start, &end); gtk_css_image_linear_get_start_end (linear, length, &start, &end);
pattern = cairo_pattern_create_linear (x * (start - 0.5), y * (start - 0.5), pattern = cairo_pattern_create_linear (x * (start - 0.5), y * (start - 0.5),