chiark / gitweb /
Introduce a front-end function to draw circles.
authorSimon Tatham <anakin@pobox.com>
Thu, 23 Jun 2005 08:24:52 +0000 (08:24 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 23 Jun 2005 08:24:52 +0000 (08:24 +0000)
[originally from svn r5991]

gtk.c
osx.m
puzzles.h
windows.c

diff --git a/gtk.c b/gtk.c
index e3bffa5f4b875be8392222304472e66faed41a42..2cbbde444deb87205f8ebd26b10f1d1d9392a808 100644 (file)
--- a/gtk.c
+++ b/gtk.c
@@ -334,6 +334,15 @@ void draw_polygon(frontend *fe, int *coords, int npoints,
     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 {
     GdkPixmap *pixmap;
     int w, h, x, y;
diff --git a/osx.m b/osx.m
index 74bd1b28b6d0d25bb9c62f686e74aaba0331961c..bc870214fcf4ad6ba4bd7940e75fd8aa879fe933 100644 (file)
--- a/osx.m
+++ b/osx.m
@@ -1172,6 +1172,26 @@ void draw_polygon(frontend *fe, int *coords, int npoints,
     else
        [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)
 {
     NSBezierPath *path = [NSBezierPath bezierPath];
index 987bd9b7b62eff749811d81ef805a3f8604a16d8..ed1fef6896230ef54e5051df21cc8f1fccd3273c 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -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_polygon(frontend *fe, int *coords, int npoints,
                   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 unclip(frontend *fe);
 void start_draw(frontend *fe);
index 7b3ef648b81eb6fd30f322a7d87a1aab9afb2c07..0cf81489a8cd5e3e94c88ba5a4fbb7de66e1c297 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -330,6 +330,24 @@ void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour)
     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,
                   int fill, int colour)
 {