chiark / gitweb /
Update changelog for 20170923.ff218728-0+iwj2~3.gbpc58e0c release
[sgt-puzzles.git] / drawing.c
index 4cbb46dbdf4aa971f0592a19e004adaa0dbd7e7a..caf0b4b43af16036072b39f4d1a80e9387f1486e 100644 (file)
--- a/drawing.c
+++ b/drawing.c
@@ -71,7 +71,7 @@ void drawing_free(drawing *dr)
 }
 
 void draw_text(drawing *dr, int x, int y, int fonttype, int fontsize,
-               int align, int colour, char *text)
+               int align, int colour, const char *text)
 {
     dr->api->draw_text(dr->handle, x, y, fonttype, fontsize, align,
                       colour, text);
@@ -87,6 +87,36 @@ void draw_line(drawing *dr, int x1, int y1, int x2, int y2, int colour)
     dr->api->draw_line(dr->handle, x1, y1, x2, y2, colour);
 }
 
+void draw_thick_line(drawing *dr, float thickness,
+                    float x1, float y1, float x2, float y2, int colour)
+{
+    if (thickness < 1.0)
+        thickness = 1.0;
+    if (dr->api->draw_thick_line) {
+       dr->api->draw_thick_line(dr->handle, thickness,
+                                x1, y1, x2, y2, colour);
+    } else {
+       /* We'll fake it up with a filled polygon.  The tweak to the
+        * thickness empirically compensates for rounding errors, because
+        * polygon rendering uses integer coordinates.
+        */
+       float len = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
+       float tvhatx = (x2 - x1)/len * (thickness/2 - 0.2);
+       float tvhaty = (y2 - y1)/len * (thickness/2 - 0.2);
+       int p[8];
+
+       p[0] = x1 - tvhaty;
+       p[1] = y1 + tvhatx;
+       p[2] = x2 - tvhaty;
+       p[3] = y2 + tvhatx;
+       p[4] = x2 + tvhaty;
+       p[5] = y2 - tvhatx;
+       p[6] = x1 + tvhaty;
+       p[7] = y1 - tvhatx;
+       dr->api->draw_polygon(dr->handle, p, 4, colour, colour);
+    }
+}
+
 void draw_polygon(drawing *dr, int *coords, int npoints,
                   int fillcolour, int outlinecolour)
 {
@@ -160,7 +190,7 @@ char *text_fallback(drawing *dr, const char *const *strings, int nstrings)
     return NULL;                      /* placate optimiser */
 }
 
-void status_bar(drawing *dr, char *text)
+void status_bar(drawing *dr, const char *text)
 {
     char *rewritten;