fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_arci.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
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. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
24 // "integer" circle drawing functions. These draw the limited
25 // circle types provided by X and NT graphics. The advantage of
26 // these is that small ones draw quite nicely (probably due to stored
27 // hand-drawn bitmaps of small circles!) and may be implemented by
28 // hardware and thus are fast.
29 
30 // Probably should add fl_chord.
31 
32 // 3/10/98: created
33 
34 #include <FL/fl_draw.H>
35 #include <FL/x.H>
36 #ifdef WIN32
37 # include <FL/math.h>
38 #endif
39 #include <config.h>
40 
41 void Fl_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) {
42  if (w <= 0 || h <= 0) return;
43 
44 #if defined(USE_X11)
45  XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
46 #elif defined(WIN32)
47  int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
48  int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
49  int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
50  int yb = y+h/2-int(h*sin(a2/180.0*M_PI));
51  if (fabs(a1 - a2) < 90) {
52  if (xa == xb && ya == yb) SetPixel(fl_gc, xa, ya, fl_RGB());
53  else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
54  } else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
55 #elif defined(__APPLE_QUARTZ__)
56  a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
57  float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
58  CGContextSetShouldAntialias(fl_gc, true);
59  if (w!=h) {
61  CGContextTranslateCTM(fl_gc, cx, cy);
62  CGContextScaleCTM(fl_gc, w-1.0f, h-1.0f);
63  CGContextAddArc(fl_gc, 0, 0, 0.5, a1, a2, 1);
65  } else {
66  float r = (w+h)*0.25f-0.5f;
67  CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
68  }
69  CGContextStrokePath(fl_gc);
70  CGContextSetShouldAntialias(fl_gc, false);
71 #else
72 # error unsupported platform
73 #endif
74 }
75 
76 void Fl_Graphics_Driver::pie(int x,int y,int w,int h,double a1,double a2) {
77  if (w <= 0 || h <= 0) return;
78 
79 #if defined(USE_X11)
80  XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
81  XFillArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
82 #elif defined(WIN32)
83  if (a1 == a2) return;
84  int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
85  int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
86  int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
87  int yb = y+h/2-int(h*sin(a2/180.0*M_PI));
88  SelectObject(fl_gc, fl_brush());
89  if (fabs(a1 - a2) < 90) {
90  if (xa == xb && ya == yb) {
91  MoveToEx(fl_gc, x+w/2, y+h/2, 0L);
92  LineTo(fl_gc, xa, ya);
93  SetPixel(fl_gc, xa, ya, fl_RGB());
94  } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
95  } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
96 #elif defined(__APPLE_QUARTZ__)
97  a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
98  float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
99  CGContextSetShouldAntialias(fl_gc, true);
100  if (w!=h) {
102  CGContextTranslateCTM(fl_gc, cx, cy);
103  CGContextScaleCTM(fl_gc, w, h);
104  CGContextAddArc(fl_gc, 0, 0, 0.5, a1, a2, 1);
105  CGContextAddLineToPoint(fl_gc, 0, 0);
108  } else {
109  float r = (w+h)*0.25f;
110  CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
111  CGContextAddLineToPoint(fl_gc, cx, cy);
113  }
115  CGContextSetShouldAntialias(fl_gc, false);
116 #else
117 # error unsupported platform
118 #endif
119 }
120 
121 //
122 // End of "$Id$".
123 //
fl_brush
FL_EXPORT HBRUSH fl_brush()
Definition: fl_color_win32.cxx:122
M_PI
#define M_PI
Definition: math.h:38
x.H
CGContextFillPath
#define CGContextFillPath(a)
Definition: cgdebug.h:155
CGContextRestoreGState
#define CGContextRestoreGState(a)
Definition: cgdebug.h:195
math.h
Fl_Graphics_Driver::pie
virtual void pie(int x, int y, int w, int h, double a1, double a2)
see fl_pie(int x, int y, int w, int h, double a1, double a2).
Definition: fl_arci.cxx:76
fl_RGB
COLORREF fl_RGB()
Definition: win32.H:120
Fl_Graphics_Driver::arc
virtual void arc(double x, double y, double r, double start, double end)
see fl_arc(double x, double y, double r, double start, double end).
Definition: fl_arc.cxx:37
fl_draw.H
utility header to pull drawing functions together
CGContextSaveGState
#define CGContextSaveGState(a)
Definition: cgdebug.h:185
fl_display
FL_EXPORT HINSTANCE fl_display
END TIMERS.
Definition: Fl_win32.cxx:2147
x
int x
Definition: test.c:73
fl_gc
CGContextRef fl_gc
Definition: Fl_win32.cxx:2568
y
int y
Definition: test.c:74
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
CGContextClosePath
#define CGContextClosePath(a)
Definition: cgdebug.h:165
fl_window
FL_EXPORT Window fl_window
Definition: Fl_win32.cxx:2571