shithub: puzzles

Download patch

ref: 407f29c46f35910ce3d7ddd41f13e94213c2597e
parent: 9249f096192b0a50e607024bf04736ef0506b5ea
author: Simon Tatham <[email protected]>
date: Sun Feb 22 07:05:38 EST 2009

Introduce some infrastructure to permit games' print functions to
draw dotted lines. No puzzle yet uses this, but one's about to.

[originally from svn r8453]

--- a/devel.but
+++ b/devel.but
@@ -2143,6 +2143,22 @@
 choose to vary line thicknesses at user request or due to printer
 capabilities.
 
+\S{print-line-width} \cw{print_line_dotted()}
+
+\c void print_line_dotted(drawing *dr, int dotted);
+
+This function is called to toggle the drawing of dotted lines during
+printing. It is not supported during drawing.
+
+The parameter \cq{dotted} is a boolean; \cw{TRUE} means that future
+lines drawn by \cw{draw_line()}, \cw{draw_circle} and
+\cw{draw_polygon()} will be dotted, and \cw{FALSE} means that they
+will be solid.
+
+Some front ends may impose restrictions on the width of dotted
+lines. Asking for a dotted line via this front end will override any
+line width request if the front end requires it.
+
 \H{drawing-frontend} The drawing API as implemented by the front end
 
 This section describes the drawing API in the function-pointer form
--- a/drawing.c
+++ b/drawing.c
@@ -283,3 +283,8 @@
      */
     dr->api->line_width(dr->handle, (float)sqrt(dr->scale) * width);
 }
+
+void print_line_dotted(drawing *dr, int dotted)
+{
+    dr->api->line_dotted(dr->handle, dotted);
+}
--- a/nestedvm.c
+++ b/nestedvm.c
@@ -184,7 +184,7 @@
     nestedvm_blitter_save,
     nestedvm_blitter_load,
     NULL, NULL, NULL, NULL, NULL, NULL, /* {begin,end}_{doc,page,puzzle} */
-    NULL,			       /* line_width */
+    NULL, NULL,			       /* line_width, line_dotted */
 };
 
 int jcallback_key_event(int x, int y, int keyval)
--- a/nullfe.c
+++ b/nullfe.c
@@ -36,6 +36,7 @@
 int print_rgb_hatched_colour(drawing *dr, float r, float g, float b, int hatch)
 { return 0; }
 void print_line_width(drawing *dr, int width) {}
+void print_line_dotted(drawing *dr, int dotted) {}
 void midend_supersede_game_desc(midend *me, char *desc, char *privdesc) {}
 void status_bar(drawing *dr, char *text) {}
 
--- a/ps.c
+++ b/ps.c
@@ -231,6 +231,17 @@
     ps_printf(ps, "%g setlinewidth\n", width);
 }
 
+static void ps_line_dotted(void *handle, int dotted)
+{
+    psdata *ps = (psdata *)handle;
+
+    if (dotted) {
+	ps_printf(ps, "[ currentlinewidth 3 mul ] 0 setdash\n");
+    } else {
+	ps_printf(ps, "[ ] 0 setdash\n");
+    }
+}
+
 static void ps_begin_doc(void *handle, int pages)
 {
     psdata *ps = (psdata *)handle;
@@ -321,6 +332,7 @@
     ps_end_page,
     ps_end_doc,
     ps_line_width,
+    ps_line_dotted,
 };
 
 psdata *ps_init(FILE *outfile, int colour)
--- a/puzzles.h
+++ b/puzzles.h
@@ -217,6 +217,7 @@
 int print_rgb_hatched_colour(drawing *dr, float r, float g, float b,
 			     int hatch);
 void print_line_width(drawing *dr, int width);
+void print_line_dotted(drawing *dr, int dotted);
 
 /*
  * midend.c
@@ -505,6 +506,7 @@
     void (*end_page)(void *handle, int number);
     void (*end_doc)(void *handle);
     void (*line_width)(void *handle, float width);
+    void (*line_dotted)(void *handle, int dotted);
 };
 
 /*
--- a/windows.c
+++ b/windows.c
@@ -225,7 +225,7 @@
     int printoffsetx, printoffsety;
     float printpixelscale;
     int fontstart;
-    int linewidth;
+    int linewidth, linedotted;
     drawing *dr;
     int xmin, ymin;
     float puzz_scale;
@@ -493,12 +493,16 @@
 	float r, g, b;
 	int width = thin ? 0 : fe->linewidth;
 
+	if (fe->linedotted)
+	    width = 0;
+
 	print_get_colour(fe->dr, colour, fe->printcolour, &hatch, &r, &g, &b);
 	/*
 	 * Stroking in hatched colours is not permitted.
 	 */
 	assert(hatch < 0);
-	pen = CreatePen(PS_SOLID, width, RGB(r * 255, g * 255, b * 255));
+	pen = CreatePen(fe->linedotted ? PS_DOT : PS_SOLID,
+			width, RGB(r * 255, g * 255, b * 255));
     } else {
 	pen = fe->pens[colour];
     }
@@ -792,6 +796,17 @@
     fe->linewidth = (int)(width * fe->printpixelscale);
 }
 
+static void win_line_dotted(void *handle, int dotted)
+{
+    frontend *fe = (frontend *)handle;
+
+    assert(fe->drawstatus != DRAWING);
+    if (fe->drawstatus == NOTHING)
+	return;
+
+    fe->linedotted = dotted;
+}
+
 static void win_begin_doc(void *handle, int pages)
 {
     frontend *fe = (frontend *)handle;
@@ -882,6 +897,7 @@
     fe->printpixelscale = scale;
 
     fe->linewidth = 1;
+    fe->linedotted = FALSE;
 }
 
 static void win_end_puzzle(void *handle)
@@ -963,6 +979,7 @@
     win_end_page,
     win_end_doc,
     win_line_width,
+    win_line_dotted,
 };
 
 void print(frontend *fe)