1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-14 01:42:05 +04:00
|
|
|
/**
|
|
|
|
\file fl_arci.cxx
|
|
|
|
\brief Utility functions for drawing circles using integers
|
|
|
|
*/
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
// "integer" circle drawing functions. These draw the limited
|
|
|
|
// circle types provided by X and NT graphics. The advantage of
|
|
|
|
// these is that small ones draw quite nicely (probably due to stored
|
|
|
|
// hand-drawn bitmaps of small circles!) and may be implemented by
|
|
|
|
// hardware and thus are fast.
|
|
|
|
|
|
|
|
// Probably should add fl_chord.
|
|
|
|
|
|
|
|
// 3/10/98: created
|
|
|
|
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/x.H>
|
|
|
|
#ifdef WIN32
|
2006-10-11 05:23:52 +04:00
|
|
|
# include <FL/math.h>
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
2008-10-14 03:44:22 +04:00
|
|
|
#include <config.h>
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
void Fl_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) {
|
1998-10-06 22:21:25 +04:00
|
|
|
if (w <= 0 || h <= 0) return;
|
2008-10-14 03:10:43 +04:00
|
|
|
|
|
|
|
#if defined(USE_X11)
|
|
|
|
XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
|
|
|
|
#elif defined(WIN32)
|
1998-10-06 22:21:25 +04:00
|
|
|
int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
|
|
|
|
int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
|
|
|
|
int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
|
|
|
|
int yb = y+h/2-int(h*sin(a2/180.0*M_PI));
|
2006-10-11 05:23:52 +04:00
|
|
|
if (fabs(a1 - a2) < 90) {
|
|
|
|
if (xa == xb && ya == yb) SetPixel(fl_gc, xa, ya, fl_RGB());
|
|
|
|
else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
|
|
|
|
} else Arc(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
|
2004-08-25 04:20:27 +04:00
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-08-27 04:22:28 +04:00
|
|
|
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
|
|
|
|
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
|
2009-12-07 01:21:55 +03:00
|
|
|
CGContextSetShouldAntialias(fl_gc, true);
|
2004-08-27 04:22:28 +04:00
|
|
|
if (w!=h) {
|
|
|
|
CGContextSaveGState(fl_gc);
|
|
|
|
CGContextTranslateCTM(fl_gc, cx, cy);
|
|
|
|
CGContextScaleCTM(fl_gc, w-1.0f, h-1.0f);
|
|
|
|
CGContextAddArc(fl_gc, 0, 0, 0.5, a1, a2, 1);
|
|
|
|
CGContextRestoreGState(fl_gc);
|
|
|
|
} else {
|
|
|
|
float r = (w+h)*0.25f-0.5f;
|
|
|
|
CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
|
|
|
|
}
|
2004-08-26 04:18:43 +04:00
|
|
|
CGContextStrokePath(fl_gc);
|
2009-12-07 01:21:55 +03:00
|
|
|
CGContextSetShouldAntialias(fl_gc, false);
|
1998-10-06 22:21:25 +04:00
|
|
|
#else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error unsupported platform
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
void Fl_Graphics_Driver::pie(int x,int y,int w,int h,double a1,double a2) {
|
1998-10-06 22:21:25 +04:00
|
|
|
if (w <= 0 || h <= 0) return;
|
2008-10-14 03:10:43 +04:00
|
|
|
|
|
|
|
#if defined(USE_X11)
|
|
|
|
XFillArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
|
|
|
|
#elif defined(WIN32)
|
1998-10-06 22:21:25 +04:00
|
|
|
if (a1 == a2) return;
|
|
|
|
int xa = x+w/2+int(w*cos(a1/180.0*M_PI));
|
|
|
|
int ya = y+h/2-int(h*sin(a1/180.0*M_PI));
|
|
|
|
int xb = x+w/2+int(w*cos(a2/180.0*M_PI));
|
|
|
|
int yb = y+h/2-int(h*sin(a2/180.0*M_PI));
|
|
|
|
SelectObject(fl_gc, fl_brush());
|
2006-10-11 05:23:52 +04:00
|
|
|
if (fabs(a1 - a2) < 90) {
|
|
|
|
if (xa == xb && ya == yb) {
|
|
|
|
MoveToEx(fl_gc, x+w/2, y+h/2, 0L);
|
|
|
|
LineTo(fl_gc, xa, ya);
|
|
|
|
SetPixel(fl_gc, xa, ya, fl_RGB());
|
|
|
|
} else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
|
|
|
|
} else Pie(fl_gc, x, y, x+w, y+h, xa, ya, xb, yb);
|
2004-08-25 04:20:27 +04:00
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-08-27 04:22:28 +04:00
|
|
|
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
|
|
|
|
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
|
2009-12-07 01:21:55 +03:00
|
|
|
CGContextSetShouldAntialias(fl_gc, true);
|
2004-08-27 04:22:28 +04:00
|
|
|
if (w!=h) {
|
|
|
|
CGContextSaveGState(fl_gc);
|
|
|
|
CGContextTranslateCTM(fl_gc, cx, cy);
|
|
|
|
CGContextScaleCTM(fl_gc, w, h);
|
|
|
|
CGContextAddArc(fl_gc, 0, 0, 0.5, a1, a2, 1);
|
|
|
|
CGContextAddLineToPoint(fl_gc, 0, 0);
|
|
|
|
CGContextClosePath(fl_gc);
|
|
|
|
CGContextRestoreGState(fl_gc);
|
|
|
|
} else {
|
|
|
|
float r = (w+h)*0.25f;
|
|
|
|
CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
|
|
|
|
CGContextAddLineToPoint(fl_gc, cx, cy);
|
|
|
|
CGContextClosePath(fl_gc);
|
|
|
|
}
|
2004-08-26 10:18:12 +04:00
|
|
|
CGContextFillPath(fl_gc);
|
2009-12-07 01:21:55 +03:00
|
|
|
CGContextSetShouldAntialias(fl_gc, false);
|
1998-10-06 22:21:25 +04:00
|
|
|
#else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error unsupported platform
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
|
|
|
}
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|