2 // "$Id: fl_arci.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
30 \brief Utility functions for drawing circles using integers
33 // "integer" circle drawing functions. These draw the limited
34 // circle types provided by X and NT graphics. The advantage of
35 // these is that small ones draw quite nicely (probably due to stored
36 // hand-drawn bitmaps of small circles!) and may be implemented by
37 // hardware and thus are fast.
39 // Probably should add fl_chord.
43 #include <FL/fl_draw.H>
50 void Fl_Graphics_Driver::arc(int x
,int y
,int w
,int h
,double a1
,double a2
) {
51 if (w
<= 0 || h
<= 0) return;
54 XDrawArc(fl_display
, fl_window
, fl_gc
, x
,y
,w
-1,h
-1, int(a1
*64),int((a2
-a1
)*64));
56 int xa
= x
+w
/2+int(w
*cos(a1
/180.0*M_PI
));
57 int ya
= y
+h
/2-int(h
*sin(a1
/180.0*M_PI
));
58 int xb
= x
+w
/2+int(w
*cos(a2
/180.0*M_PI
));
59 int yb
= y
+h
/2-int(h
*sin(a2
/180.0*M_PI
));
60 if (fabs(a1
- a2
) < 90) {
61 if (xa
== xb
&& ya
== yb
) SetPixel(fl_gc
, xa
, ya
, fl_RGB());
62 else Arc(fl_gc
, x
, y
, x
+w
, y
+h
, xa
, ya
, xb
, yb
);
63 } else Arc(fl_gc
, x
, y
, x
+w
, y
+h
, xa
, ya
, xb
, yb
);
64 #elif defined(__APPLE_QUARTZ__)
65 a1
= (-a1
)/180.0f
*M_PI
; a2
= (-a2
)/180.0f
*M_PI
;
66 float cx
= x
+ 0.5f
*w
- 0.5f
, cy
= y
+ 0.5f
*h
- 0.5f
;
67 CGContextSetShouldAntialias(fl_gc
, true);
69 CGContextSaveGState(fl_gc
);
70 CGContextTranslateCTM(fl_gc
, cx
, cy
);
71 CGContextScaleCTM(fl_gc
, w
-1.0f
, h
-1.0f
);
72 CGContextAddArc(fl_gc
, 0, 0, 0.5, a1
, a2
, 1);
73 CGContextRestoreGState(fl_gc
);
75 float r
= (w
+h
)*0.25f
-0.5f
;
76 CGContextAddArc(fl_gc
, cx
, cy
, r
, a1
, a2
, 1);
78 CGContextStrokePath(fl_gc
);
79 CGContextSetShouldAntialias(fl_gc
, false);
81 # error unsupported platform
85 void Fl_Graphics_Driver::pie(int x
,int y
,int w
,int h
,double a1
,double a2
) {
86 if (w
<= 0 || h
<= 0) return;
89 XFillArc(fl_display
, fl_window
, fl_gc
, x
,y
,w
-1,h
-1, int(a1
*64),int((a2
-a1
)*64));
92 int xa
= x
+w
/2+int(w
*cos(a1
/180.0*M_PI
));
93 int ya
= y
+h
/2-int(h
*sin(a1
/180.0*M_PI
));
94 int xb
= x
+w
/2+int(w
*cos(a2
/180.0*M_PI
));
95 int yb
= y
+h
/2-int(h
*sin(a2
/180.0*M_PI
));
96 SelectObject(fl_gc
, fl_brush());
97 if (fabs(a1
- a2
) < 90) {
98 if (xa
== xb
&& ya
== yb
) {
99 MoveToEx(fl_gc
, x
+w
/2, y
+h
/2, 0L);
100 LineTo(fl_gc
, xa
, ya
);
101 SetPixel(fl_gc
, xa
, ya
, fl_RGB());
102 } else Pie(fl_gc
, x
, y
, x
+w
, y
+h
, xa
, ya
, xb
, yb
);
103 } else Pie(fl_gc
, x
, y
, x
+w
, y
+h
, xa
, ya
, xb
, yb
);
104 #elif defined(__APPLE_QUARTZ__)
105 a1
= (-a1
)/180.0f
*M_PI
; a2
= (-a2
)/180.0f
*M_PI
;
106 float cx
= x
+ 0.5f
*w
- 0.5f
, cy
= y
+ 0.5f
*h
- 0.5f
;
107 CGContextSetShouldAntialias(fl_gc
, true);
109 CGContextSaveGState(fl_gc
);
110 CGContextTranslateCTM(fl_gc
, cx
, cy
);
111 CGContextScaleCTM(fl_gc
, w
, h
);
112 CGContextAddArc(fl_gc
, 0, 0, 0.5, a1
, a2
, 1);
113 CGContextAddLineToPoint(fl_gc
, 0, 0);
114 CGContextClosePath(fl_gc
);
115 CGContextRestoreGState(fl_gc
);
117 float r
= (w
+h
)*0.25f
;
118 CGContextAddArc(fl_gc
, cx
, cy
, r
, a1
, a2
, 1);
119 CGContextAddLineToPoint(fl_gc
, cx
, cy
);
120 CGContextClosePath(fl_gc
);
122 CGContextFillPath(fl_gc
);
123 CGContextSetShouldAntialias(fl_gc
, false);
125 # error unsupported platform
130 // End of "$Id: fl_arci.cxx 7903 2010-11-28 21:06:39Z matt $".