Introduce a front-end function to draw circles.

[originally from svn r5991]
This commit is contained in:
Simon Tatham
2005-06-23 08:24:52 +00:00
parent 973ced1c7c
commit b909204392
4 changed files with 49 additions and 0 deletions

9
gtk.c
View File

@ -334,6 +334,15 @@ void draw_polygon(frontend *fe, int *coords, int npoints,
sfree(points); sfree(points);
} }
void draw_circle(frontend *fe, int cx, int cy, int radius,
int fill, int colour)
{
gdk_gc_set_foreground(fe->gc, &fe->colours[colour]);
gdk_draw_arc(fe->pixmap, fe->gc, fill,
cx - radius, cy - radius,
2 * radius, 2 * radius, 0, 360 * 64);
}
struct blitter { struct blitter {
GdkPixmap *pixmap; GdkPixmap *pixmap;
int w, h, x, y; int w, h, x, y;

20
osx.m
View File

@ -1172,6 +1172,26 @@ void draw_polygon(frontend *fe, int *coords, int npoints,
else else
[path stroke]; [path stroke];
} }
void draw_circle(frontend *fe, int cx, int cy, int radius,
int fill, int colour)
{
NSBezierPath *path = [NSBezierPath bezierPath];
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
assert(colour >= 0 && colour < fe->ncolours);
[fe->colours[colour] set];
[path appendBezierPathWithArcWithCenter:NSMakePoint(cx + 0.5, cy + 0.5)
radius:radius startAngle:0.0 endAngle:360.0];
[path closePath];
if (fill)
[path fill];
else
[path stroke];
}
void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour) void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour)
{ {
NSBezierPath *path = [NSBezierPath bezierPath]; NSBezierPath *path = [NSBezierPath bezierPath];

View File

@ -137,6 +137,8 @@ void draw_rect(frontend *fe, int x, int y, int w, int h, int colour);
void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour); void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour);
void draw_polygon(frontend *fe, int *coords, int npoints, void draw_polygon(frontend *fe, int *coords, int npoints,
int fill, int colour); int fill, int colour);
void draw_circle(frontend *fe, int cx, int cy, int radius,
int fill, int colour);
void clip(frontend *fe, int x, int y, int w, int h); void clip(frontend *fe, int x, int y, int w, int h);
void unclip(frontend *fe); void unclip(frontend *fe);
void start_draw(frontend *fe); void start_draw(frontend *fe);

View File

@ -330,6 +330,24 @@ void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour)
SelectObject(fe->hdc_bm, oldpen); SelectObject(fe->hdc_bm, oldpen);
} }
void draw_circle(frontend *fe, int cx, int cy, int radius,
int fill, int colour)
{
if (fill) {
HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]);
HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]);
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]);
MoveToEx(fe->hdc_bm, cx + radius, cy, NULL);
AngleArc(fe->hdc_bm, cx, cy, radius, 0.0F, 360.0F);
SelectObject(fe->hdc_bm, oldpen);
}
}
void draw_polygon(frontend *fe, int *coords, int npoints, void draw_polygon(frontend *fe, int *coords, int npoints,
int fill, int colour) int fill, int colour)
{ {