themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / fl_arci.cxx
blob963d62c6d5dc2848f0fa122a5771b476acdb1559
1 //
2 // "$Id: fl_arci.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
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
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 /**
29 \file fl_arci.cxx
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.
41 // 3/10/98: created
43 #include <FL/fl_draw.H>
44 #include <FL/x.H>
45 #ifdef WIN32
46 # include <FL/math.h>
47 #endif
48 #include <config.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;
53 #if defined(USE_X11)
54 XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
55 #elif defined(WIN32)
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);
68 if (w!=h) {
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);
74 } else {
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);
80 #else
81 # error unsupported platform
82 #endif
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;
88 #if defined(USE_X11)
89 XFillArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
90 #elif defined(WIN32)
91 if (a1 == a2) return;
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);
108 if (w!=h) {
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);
116 } else {
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);
124 #else
125 # error unsupported platform
126 #endif
130 // End of "$Id: fl_arci.cxx 7903 2010-11-28 21:06:39Z matt $".