[gtk+] cssimage: Fix angle computation for gradients to corners
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssimage: Fix angle computation for gradients to corners
- Date: Thu, 8 Jan 2015 18:31:30 +0000 (UTC)
commit 9474215a43b116cf6098b11ef967a10afc495923
Author: Benjamin Otte <otte redhat com>
Date: Thu Jan 8 19:30:19 2015 +0100
cssimage: Fix angle computation for gradients to corners
gtk/gtkcssimagelinear.c | 43 +++++++++++++++++++++++++++----------------
1 files changed, 27 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index a5b0955..f8ee0b2 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -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),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]