Introduce some infrastructure to permit games' print functions to
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 22 Feb 2009 12:05:38 +0000 (12:05 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 22 Feb 2009 12:05:38 +0000 (12:05 +0000)
draw dotted lines. No puzzle yet uses this, but one's about to.

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@8453 cda61777-01e9-0310-a592-d414129be87e

devel.but
drawing.c
nestedvm.c
nullfe.c
ps.c
puzzles.h
windows.c

index 134cf13..67c1659 100644 (file)
--- a/devel.but
+++ b/devel.but
@@ -2143,6 +2143,22 @@ however, that it is a hint only: the central printing system may
 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
index b582b8f..26df1ff 100644 (file)
--- a/drawing.c
+++ b/drawing.c
@@ -283,3 +283,8 @@ void print_line_width(drawing *dr, int width)
      */
     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);
+}
index 757b65f..2bbf4e3 100644 (file)
@@ -184,7 +184,7 @@ const struct drawing_api nestedvm_drawing = {
     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)
index 2ecd238..325fd5a 100644 (file)
--- a/nullfe.c
+++ b/nullfe.c
@@ -36,6 +36,7 @@ int print_rgb_grey_colour(drawing *dr, float r, float g, float b, float grey)
 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) {}
 
diff --git a/ps.c b/ps.c
index 9f2c17f..f6a71bb 100644 (file)
--- a/ps.c
+++ b/ps.c
@@ -231,6 +231,17 @@ static void ps_line_width(void *handle, float width)
     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 @@ static const struct drawing_api ps_drawing = {
     ps_end_page,
     ps_end_doc,
     ps_line_width,
+    ps_line_dotted,
 };
 
 psdata *ps_init(FILE *outfile, int colour)
index a1acada..0e0cf97 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -217,6 +217,7 @@ int print_rgb_grey_colour(drawing *dr, float r, float g, float b, float grey);
 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 @@ struct drawing_api {
     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);
 };
 
 /*
index 6bcf895..6249d55 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -225,7 +225,7 @@ struct frontend {
     int printoffsetx, printoffsety;
     float printpixelscale;
     int fontstart;
-    int linewidth;
+    int linewidth, linedotted;
     drawing *dr;
     int xmin, ymin;
     float puzz_scale;
@@ -493,12 +493,16 @@ static void win_set_pen(frontend *fe, int colour, int thin)
        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 @@ static void win_line_width(void *handle, float width)
     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 @@ static void win_begin_puzzle(void *handle, float xm, float xc,
     fe->printpixelscale = scale;
 
     fe->linewidth = 1;
+    fe->linedotted = FALSE;
 }
 
 static void win_end_puzzle(void *handle)
@@ -963,6 +979,7 @@ const struct drawing_api win_drawing = {
     win_end_page,
     win_end_doc,
     win_line_width,
+    win_line_dotted,
 };
 
 void print(frontend *fe)