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

fl_arci.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: fl_arci.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00033 // "integer" circle drawing functions.  These draw the limited
00034 // circle types provided by X and NT graphics.  The advantage of
00035 // these is that small ones draw quite nicely (probably due to stored
00036 // hand-drawn bitmaps of small circles!) and may be implemented by
00037 // hardware and thus are fast.
00038 
00039 // Probably should add fl_chord.
00040 
00041 // 3/10/98: created
00042 
00043 #include <FL/fl_draw.H>
00044 #include <FL/x.H>
00045 #ifdef WIN32
00046 #  include <FL/math.h>
00047 #endif
00048 #include <config.h>
00049 
00050 void Fl_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) {
00051   if (w <= 0 || h <= 0) return;
00052 
00053 #if defined(USE_X11)
00054   XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
00055 #elif defined(WIN32)
00056   int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
00057   int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
00058   int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
00059   int yb = y+h/2-int(h*sin(a2/180.0*M_PI));
00060   if (fabs(a1 - a2) < 90) {
00061     if (xa == xb && ya == yb) SetPixel(fl_gc, xa, ya, fl_RGB());
00062     else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
00063   } else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
00064 #elif defined(__APPLE_QUARTZ__)
00065   a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
00066   float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
00067   CGContextSetShouldAntialias(fl_gc, true);
00068   if (w!=h) {
00069     CGContextSaveGState(fl_gc);
00070     CGContextTranslateCTM(fl_gc, cx, cy);
00071     CGContextScaleCTM(fl_gc, w-1.0f, h-1.0f);
00072     CGContextAddArc(fl_gc, 0, 0, 0.5, a1, a2, 1);
00073     CGContextRestoreGState(fl_gc);
00074   } else {
00075     float r = (w+h)*0.25f-0.5f;
00076     CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
00077   }
00078   CGContextStrokePath(fl_gc);
00079   CGContextSetShouldAntialias(fl_gc, false);
00080 #else
00081 # error unsupported platform
00082 #endif
00083 }
00084 
00085 void Fl_Graphics_Driver::pie(int x,int y,int w,int h,double a1,double a2) {
00086   if (w <= 0 || h <= 0) return;
00087 
00088 #if defined(USE_X11)
00089   XFillArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
00090 #elif defined(WIN32)
00091   if (a1 == a2) return;
00092   int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
00093   int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
00094   int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
00095   int yb = y+h/2-int(h*sin(a2/180.0*M_PI));
00096   SelectObject(fl_gc, fl_brush());
00097   if (fabs(a1 - a2) < 90) {
00098     if (xa == xb && ya == yb) {
00099       MoveToEx(fl_gc, x+w/2, y+h/2, 0L); 
00100       LineTo(fl_gc, xa, ya);
00101       SetPixel(fl_gc, xa, ya, fl_RGB());
00102     } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
00103   } else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb); 
00104 #elif defined(__APPLE_QUARTZ__)
00105   a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
00106   float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
00107   CGContextSetShouldAntialias(fl_gc, true);
00108   if (w!=h) {
00109     CGContextSaveGState(fl_gc);
00110     CGContextTranslateCTM(fl_gc, cx, cy);
00111     CGContextScaleCTM(fl_gc, w, h);
00112     CGContextAddArc(fl_gc, 0, 0, 0.5, a1, a2, 1);
00113     CGContextAddLineToPoint(fl_gc, 0, 0);
00114     CGContextClosePath(fl_gc);
00115     CGContextRestoreGState(fl_gc);
00116   } else {
00117     float r = (w+h)*0.25f;
00118     CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
00119     CGContextAddLineToPoint(fl_gc, cx, cy);
00120     CGContextClosePath(fl_gc);
00121   }
00122   CGContextFillPath(fl_gc);
00123   CGContextSetShouldAntialias(fl_gc, false);
00124 #else
00125 # error unsupported platform
00126 #endif
00127 }
00128 
00129 //
00130 // End of "$Id: fl_arci.cxx 7903 2010-11-28 21:06:39Z matt $".
00131 //