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]
This commit is contained in:
Simon Tatham
2009-02-22 12:05:38 +00:00
parent 9249f09619
commit 407f29c46f
7 changed files with 56 additions and 3 deletions

View File

@ -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

View File

@ -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);
}

View 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)

View File

@ -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) {}

12
ps.c
View File

@ -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)

View File

@ -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);
};
/*

View File

@ -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)