draw_polygon() and draw_circle() have always had a portability

constraint: because some front ends interpret `draw filled shape' to
mean `including its boundary' while others interpret it to mean `not
including its boundary' (and X seems to vacillate between the two
opinions as it moves around the shape!), you MUST NOT draw a filled
shape only. You can fill in one colour and outline in another, you
can fill or outline in the same colour, or you can just outline, but
just filling is a no-no.

This leads to a _lot_ of double calls to these functions, so I've
changed the interface. draw_circle() and draw_polygon() now each
take two colour arguments, a fill colour (which can be -1 for none)
and an outline colour (which must be valid). This should simplify
code in the game back ends, while also reducing the possibility for
coding error.

[originally from svn r6047]
This commit is contained in:
Simon Tatham
2005-07-03 09:35:29 +00:00
parent 8dd7ee3007
commit 64e114cce1
16 changed files with 106 additions and 113 deletions

View File

@ -333,26 +333,28 @@ void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour)
}
void draw_circle(frontend *fe, int cx, int cy, int radius,
int fill, int colour)
int fillcolour, int outlinecolour)
{
if (fill) {
HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]);
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
assert(outlinecolour >= 0);
if (fillcolour >= 0) {
HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[fillcolour]);
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[outlinecolour]);
Ellipse(fe->hdc_bm, cx - radius, cy - radius,
cx + radius + 1, cy + radius + 1);
SelectObject(fe->hdc_bm, oldbrush);
SelectObject(fe->hdc_bm, oldpen);
} else {
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
Arc(fe->hdc_bm, cx - radius, cy - radius,
cx + radius + 1, cy + radius + 1,
cx - radius, cy, cx - radius, cy);
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[outlinecolour]);
Arc(fe->hdc_bm, cx - radius, cy - radius,
cx + radius + 1, cy + radius + 1,
cx - radius, cy, cx - radius, cy);
SelectObject(fe->hdc_bm, oldpen);
}
}
void draw_polygon(frontend *fe, int *coords, int npoints,
int fill, int colour)
int fillcolour, int outlinecolour)
{
POINT *pts = snewn(npoints+1, POINT);
int i;
@ -363,14 +365,16 @@ void draw_polygon(frontend *fe, int *coords, int npoints,
pts[i].y = coords[j*2+1];
}
if (fill) {
HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]);
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
assert(outlinecolour >= 0);
if (fillcolour >= 0) {
HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[fillcolour]);
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[outlinecolour]);
Polygon(fe->hdc_bm, pts, npoints);
SelectObject(fe->hdc_bm, oldbrush);
SelectObject(fe->hdc_bm, oldpen);
} else {
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[outlinecolour]);
Polyline(fe->hdc_bm, pts, npoints+1);
SelectObject(fe->hdc_bm, oldpen);
}