[gnome-software/1205-reviews-ratings-are-rounded-to-integer-stars: 34/34] gs-star-image: Use actual star width for the fraction color fill
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1205-reviews-ratings-are-rounded-to-integer-stars: 34/34] gs-star-image: Use actual star width for the fraction color fill
- Date: Tue, 1 Jun 2021 20:04:51 +0000 (UTC)
commit 287eead7357d88c5c10a3db4d4742189d9659f52
Author: Milan Crha <mcrha redhat com>
Date: Tue Jun 1 21:52:38 2021 +0200
gs-star-image: Use actual star width for the fraction color fill
Rather than using the radius, use the actual drawn width for the fraction
calculation, thus smaller numbers are evenly spread in the drawn part.
src/gs-star-image.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/gs-star-image.c b/src/gs-star-image.c
index 2c3baec90..2fd01e30a 100644
--- a/src/gs-star-image.c
+++ b/src/gs-star-image.c
@@ -22,7 +22,9 @@ static void
gs_star_image_outline_star (cairo_t *cr,
gint x,
gint y,
- gint radius)
+ gint radius,
+ gint *out_min_x,
+ gint *out_max_x)
{
const struct _points {
gdouble x, y;
@@ -38,16 +40,35 @@ gs_star_image_outline_star (cairo_t *cr,
{ 0.951057, -0.309017 },
{ 0.224513, -0.309017 }
};
- gint ii, nn = G_N_ELEMENTS (points);
+ gint ii, nn = G_N_ELEMENTS (points), xx, yy;
if (radius <= 0)
return;
cairo_translate (cr, radius, radius);
- cairo_move_to (cr, points[0].x * radius, points[0].y * radius);
+
+ xx = points[0].x * radius;
+ yy = points[0].y * radius;
+
+ if (out_min_x)
+ *out_min_x = xx;
+
+ if (out_max_x)
+ *out_max_x = xx;
+
+ cairo_move_to (cr, xx, yy);
for (ii = 1; ii <= nn; ii++) {
- cairo_line_to (cr, points[ii % nn].x * radius, points[ii % nn].y * radius);
+ xx = points[ii % nn].x * radius;
+ yy = points[ii % nn].y * radius;
+
+ if (out_min_x && *out_min_x > xx)
+ *out_min_x = xx;
+
+ if (out_max_x && *out_max_x < xx)
+ *out_max_x = xx;
+
+ cairo_line_to (cr, xx, yy);
}
}
@@ -101,6 +122,7 @@ gs_star_image_draw (GtkWidget *widget,
GtkStyleContext *style_context;
GdkRGBA *star_bg = NULL;
GdkRGBA star_fg;
+ gint min_x = -radius, max_x = radius;
gtk_widget_style_get (widget,
"star-bg", &star_bg,
@@ -112,7 +134,7 @@ gs_star_image_draw (GtkWidget *widget,
&star_fg);
cairo_save (cr);
- gs_star_image_outline_star (cr, allocation.x, allocation.y, radius);
+ gs_star_image_outline_star (cr, allocation.x, allocation.y, radius, &min_x, &max_x);
cairo_clip (cr);
if (star_bg)
gdk_cairo_set_source_rgba (cr, star_bg);
@@ -122,7 +144,7 @@ gs_star_image_draw (GtkWidget *widget,
cairo_fill (cr);
gdk_cairo_set_source_rgba (cr, &star_fg);
- cairo_rectangle (cr, -radius, -radius, 2 * radius * fraction, 2 * radius);
+ cairo_rectangle (cr, min_x, -radius, (max_x - min_x) * fraction, 2 * radius);
cairo_fill (cr);
cairo_restore (cr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]