forked from AuroraMiddleware/gtk
cssimage: Fix angle computation for gradients to corners
This commit is contained in:
parent
0d5acf2a05
commit
9474215a43
@ -135,6 +135,7 @@ gtk_css_image_linear_draw (GtkCssImage *image,
|
||||
{
|
||||
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
|
||||
cairo_pattern_t *pattern;
|
||||
double angle; /* actual angle of the gradiant line in degrees */
|
||||
double x, y; /* coordinates of start point */
|
||||
double length; /* distance in pixels for 100% */
|
||||
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);
|
||||
|
||||
if (side & (1 << GTK_CSS_RIGHT))
|
||||
x = width;
|
||||
else if (side & (1 << GTK_CSS_LEFT))
|
||||
x = -width;
|
||||
else
|
||||
x = 0;
|
||||
|
||||
if (side & (1 << GTK_CSS_TOP))
|
||||
y = -height;
|
||||
else if (side & (1 << GTK_CSS_BOTTOM))
|
||||
y = height;
|
||||
else
|
||||
y = 0;
|
||||
/* special casing the regular cases here so we don't get rounding errors */
|
||||
switch (side)
|
||||
{
|
||||
case 1 << GTK_CSS_RIGHT:
|
||||
angle = 90;
|
||||
break;
|
||||
case 1 << GTK_CSS_LEFT:
|
||||
angle = 270;
|
||||
break;
|
||||
case 1 << GTK_CSS_TOP:
|
||||
angle = 0;
|
||||
break;
|
||||
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
|
||||
{
|
||||
gtk_css_image_linear_compute_start_point (_gtk_css_number_value_get (linear->angle, 100),
|
||||
width, height,
|
||||
&x, &y);
|
||||
angle = _gtk_css_number_value_get (linear->angle, 100);
|
||||
}
|
||||
|
||||
gtk_css_image_linear_compute_start_point (angle,
|
||||
width, height,
|
||||
&x, &y);
|
||||
|
||||
length = sqrt (x * x + y * y);
|
||||
gtk_css_image_linear_get_start_end (linear, length, &start, &end);
|
||||
pattern = cairo_pattern_create_linear (x * (start - 0.5), y * (start - 0.5),
|
||||
|
Loading…
Reference in New Issue
Block a user