[gnome-software/1205-reviews-ratings-are-rounded-to-integer-stars] gs-star-image: Make the star image robust
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1205-reviews-ratings-are-rounded-to-integer-stars] gs-star-image: Make the star image robust
- Date: Wed, 2 Jun 2021 12:08:30 +0000 (UTC)
commit b6c7f99bbc89d227bdb633d0c946b21cf1ab7612
Author: Milan Crha <mcrha redhat com>
Date: Wed Jun 2 14:06:56 2021 +0200
gs-star-image: Make the star image robust
Mimic what starred-symbolic looks like in Adwaita, to have the star icon
robust, not slim.
src/gs-star-image.c | 129 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 100 insertions(+), 29 deletions(-)
---
diff --git a/src/gs-star-image.c b/src/gs-star-image.c
index 2fd01e30a..418aa97d2 100644
--- a/src/gs-star-image.c
+++ b/src/gs-star-image.c
@@ -26,50 +26,121 @@ gs_star_image_outline_star (cairo_t *cr,
gint *out_min_x,
gint *out_max_x)
{
+ typedef enum _Op {
+ OP_MOVE_TO,
+ OP_CURVE,
+ OP_LINE_TO
+ } Op;
const struct _points {
- gdouble x, y;
+ Op op;
+ gdouble x1, y1, x2, y2, x3, y3;
} points[] = {
- { 0.000000, -1.000000 },
- { -0.224513, -0.309017 },
- { -0.951057, -0.309017 },
- { -0.363271, 0.118034 },
- { -0.587785, 0.809017 },
- { 0.0, 0.381966 },
- { 0.587785, 0.809017 },
- { 0.363271, 0.118034 },
- { 0.951057, -0.309017 },
- { 0.224513, -0.309017 }
+ { OP_MOVE_TO, 0.996, 0.016 },
+ { OP_CURVE, 0.941, 0.016, 0.898, 0.043, 0.871, 0.066 },
+ { OP_CURVE, 0.844, 0.094, 0.824, 0.117, 0.809, 0.145 },
+ { OP_CURVE, 0.777, 0.199, 0.754, 0.258, 0.73, 0.316 },
+ { OP_CURVE, 0.711, 0.375, 0.688, 0.434, 0.668, 0.477 },
+ { OP_CURVE, 0.66, 0.5, 0.66, 0.496, 0.656, 0.504 },
+ { OP_LINE_TO, 0.23, 0.504 },
+ { OP_CURVE, 0.176, 0.504, 0.125, 0.539, 0.109, 0.59 },
+ { OP_CURVE, 0.078, 0.684, 0.121, 0.742, 0.156, 0.797 },
+ { OP_CURVE, 0.188, 0.848, 0.23, 0.898, 0.273, 0.945 },
+ { OP_CURVE, 0.316, 0.992, 0.359, 1.039, 0.391, 1.078 },
+ { OP_CURVE, 0.426, 1.117, 0.445, 1.152, 0.441, 1.145 },
+ { OP_CURVE, 0.43, 1.113, 0.438, 1.148, 0.426, 1.191 },
+ { OP_CURVE, 0.414, 1.234, 0.395, 1.293, 0.371, 1.352 },
+ { OP_CURVE, 0.352, 1.41, 0.332, 1.469, 0.324, 1.531 },
+ { OP_CURVE, 0.316, 1.562, 0.316, 1.594, 0.32, 1.629 },
+ { OP_CURVE, 0.328, 1.664, 0.352, 1.715, 0.395, 1.746 },
+ { OP_CURVE, 0.441, 1.773, 0.492, 1.777, 0.531, 1.773 },
+ { OP_CURVE, 0.566, 1.77, 0.598, 1.758, 0.629, 1.746 },
+ { OP_CURVE, 0.688, 1.719, 0.746, 1.688, 0.801, 1.652 },
+ { OP_CURVE, 0.855, 1.617, 0.91, 1.578, 0.953, 1.555 },
+ { OP_CURVE, 0.996, 1.531, 1.035, 1.527, 1.008, 1.527 },
+ { OP_CURVE, 0.977, 1.527, 1.016, 1.531, 1.059, 1.555 },
+ { OP_CURVE, 1.098, 1.578, 1.152, 1.617, 1.207, 1.652 },
+ { OP_CURVE, 1.258, 1.688, 1.312, 1.723, 1.371, 1.746 },
+ { OP_CURVE, 1.402, 1.762, 1.434, 1.773, 1.469, 1.777 },
+ { OP_CURVE, 1.508, 1.781, 1.562, 1.777, 1.605, 1.742 },
+ { OP_CURVE, 1.613, 1.738, 1.617, 1.734, 1.621, 1.73 },
+ { OP_CURVE, 1.684, 1.668, 1.691, 1.578, 1.68, 1.516 },
+ { OP_CURVE, 1.668, 1.449, 1.648, 1.395, 1.625, 1.34 },
+ { OP_CURVE, 1.602, 1.285, 1.582, 1.23, 1.57, 1.191 },
+ { OP_CURVE, 1.559, 1.148, 1.559, 1.125, 1.559, 1.125 },
+ { OP_CURVE, 1.555, 1.145, 1.57, 1.113, 1.605, 1.078 },
+ { OP_CURVE, 1.641, 1.047, 1.688, 1.004, 1.734, 0.961 },
+ { OP_CURVE, 1.781, 0.914, 1.828, 0.867, 1.863, 0.809 },
+ { OP_CURVE, 1.902, 0.754, 1.934, 0.672, 1.902, 0.586 },
+ { OP_CURVE, 1.883, 0.535, 1.836, 0.504, 1.781, 0.504 },
+ { OP_LINE_TO, 1.332, 0.504 },
+ { OP_CURVE, 1.332, 0.5, 1.332, 0.5, 1.328, 0.496 },
+ { OP_CURVE, 1.309, 0.461, 1.289, 0.402, 1.266, 0.34 },
+ { OP_CURVE, 1.242, 0.281, 1.223, 0.215, 1.191, 0.16 },
+ { OP_CURVE, 1.176, 0.129, 1.16, 0.102, 1.133, 0.074 },
+ { OP_CURVE, 1.105, 0.047, 1.059, 0.016, 0.996, 0.016 }
};
- gint ii, nn = G_N_ELEMENTS (points), xx, yy;
+ gint ii, nn = G_N_ELEMENTS (points), x1, y1, x2, y2, x3, y3;
if (radius <= 0)
return;
+ #define check_boundary(xx) G_STMT_START { \
+ if (out_min_x && *out_min_x > xx) \
+ *out_min_x = xx; \
+ \
+ if (out_max_x && *out_max_x < xx) \
+ *out_max_x = xx; \
+ \
+ } G_STMT_END
+
cairo_translate (cr, radius, radius);
- xx = points[0].x * radius;
- yy = points[0].y * radius;
+ x1 = (points[0].x1 - 1.0) * radius;
+ y1 = (points[0].y1 - 1.0) * radius;
if (out_min_x)
- *out_min_x = xx;
+ *out_min_x = x1;
if (out_max_x)
- *out_max_x = xx;
-
- cairo_move_to (cr, xx, yy);
-
- for (ii = 1; ii <= nn; ii++) {
- xx = points[ii % nn].x * radius;
- yy = points[ii % nn].y * radius;
-
- if (out_min_x && *out_min_x > xx)
- *out_min_x = xx;
+ *out_max_x = x1;
+
+ cairo_move_to (cr, x1, y1);
+
+ for (ii = 1; ii < nn; ii++) {
+ switch (points[ii].op) {
+ case OP_MOVE_TO:
+ x1 = (points[ii].x1 - 1.0) * radius;
+ y1 = (points[ii].y1 - 1.0) * radius;
+ check_boundary (x1);
+ cairo_move_to (cr, x1, y1);
+ break;
+ case OP_LINE_TO:
+ x1 = (points[ii].x1 - 1.0) * radius;
+ y1 = (points[ii].y1 - 1.0) * radius;
+ check_boundary (x1);
+ cairo_line_to (cr, x1, y1);
+ break;
+ case OP_CURVE:
+ x1 = (points[ii].x1 - 1.0) * radius;
+ y1 = (points[ii].y1 - 1.0) * radius;
+ check_boundary (x1);
+ x2 = (points[ii].x2 - 1.0) * radius;
+ y2 = (points[ii].y2 - 1.0) * radius;
+ check_boundary (x2);
+ x3 = (points[ii].x3 - 1.0) * radius;
+ y3 = (points[ii].y3 - 1.0) * radius;
+ check_boundary (x3);
+ cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
+ break;
+ default:
+ g_warn_if_reached ();
+ break;
+ }
+ }
- if (out_max_x && *out_max_x < xx)
- *out_max_x = xx;
+ cairo_close_path (cr);
- cairo_line_to (cr, xx, yy);
- }
+ #undef check_boundary
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]