From 474de78ac17f4bcf205766ea0393059fbf2ace1e Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 23 Jan 2016 21:02:49 +0000 Subject: OpenGL arc and pie drawing (Mmmmh, pie!) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11036 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/cfg_gfx/gdi.H | 5 ++++ src/cfg_gfx/gdi_arci.cxx | 62 ++++++++++++++++++++++++++++++++++++++ src/cfg_gfx/opengl.H | 5 ++++ src/cfg_gfx/opengl_arci.cxx | 68 +++++++++++++++++++++++++++++++++++++++++ src/cfg_gfx/quartz.H | 5 ++++ src/cfg_gfx/quartz_arci.cxx | 73 +++++++++++++++++++++++++++++++++++++++++++++ src/cfg_gfx/xlib.H | 5 ++++ src/cfg_gfx/xlib_arci.cxx | 42 ++++++++++++++++++++++++++ 8 files changed, 265 insertions(+) create mode 100644 src/cfg_gfx/gdi_arci.cxx create mode 100644 src/cfg_gfx/opengl_arci.cxx create mode 100644 src/cfg_gfx/quartz_arci.cxx create mode 100644 src/cfg_gfx/xlib_arci.cxx (limited to 'src/cfg_gfx') diff --git a/src/cfg_gfx/gdi.H b/src/cfg_gfx/gdi.H index 6994959d0..9fe5ab0bc 100644 --- a/src/cfg_gfx/gdi.H +++ b/src/cfg_gfx/gdi.H @@ -94,6 +94,11 @@ protected: void end_complex_polygon(); void gap(); void circle(double x, double y, double r); + // --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed + // using void Fl_Graphics_Driver::arc(double x, double y, double r, double start, double end); + // --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx + void arc(int x, int y, int w, int h, double a1, double a2); + void pie(int x, int y, int w, int h, double a1, double a2); }; diff --git a/src/cfg_gfx/gdi_arci.cxx b/src/cfg_gfx/gdi_arci.cxx new file mode 100644 index 000000000..d2cf5f5b3 --- /dev/null +++ b/src/cfg_gfx/gdi_arci.cxx @@ -0,0 +1,62 @@ +// +// "$Id$" +// +// Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2016 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#ifndef FL_CFG_GFX_GDI_ARCI_CXX +#define FL_CFG_GFX_GDI_ARCI_CXX + +/** + \file gdi_arci.cxx + \brief Utility functions for drawing circles using integers +*/ + +#include + +void Fl_GDI_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) { + if (w <= 0 || h <= 0) 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)); + 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); +} + +void Fl_GDI_Graphics_Driver::pie(int x,int y,int w,int h,double a1,double a2) { + if (w <= 0 || h <= 0) return; + 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()); + 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); +} + +#endif FL_CFG_GFX_GDI_ARCI_CXX + +// +// End of "$Id$". +// diff --git a/src/cfg_gfx/opengl.H b/src/cfg_gfx/opengl.H index dae36eb20..a741416f7 100644 --- a/src/cfg_gfx/opengl.H +++ b/src/cfg_gfx/opengl.H @@ -86,6 +86,11 @@ public: void end_complex_polygon(); void fixloop(); void circle(double x, double y, double r); + // --- implementation is in src/fl_arc.cxx which includes src/cfg_gfx/xxx_arc.cxx if needed + // using void Fl_Graphics_Driver::arc(double x, double y, double r, double start, double end); + // --- implementation is in src/fl_arci.cxx which includes src/cfg_gfx/xxx_arci.cxx + void arc(int x, int y, int w, int h, double a1, double a2); + void pie(int x, int y, int w, int h, double a1, double a2); }; diff --git a/src/cfg_gfx/opengl_arci.cxx b/src/cfg_gfx/opengl_arci.cxx new file mode 100644 index 000000000..0f902b2bd --- /dev/null +++ b/src/cfg_gfx/opengl_arci.cxx @@ -0,0 +1,68 @@ +// +// "$Id$" +// +// Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2010 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#ifndef FL_CFG_GFX_OPENGL_ARCI_CXX +#define FL_CFG_GFX_OPENGL_ARCI_CXX + +/** + \file opengl_arci.cxx + \brief Utility functions for drawing circles using integers +*/ + +#include + +void Fl_OpenGL_Graphics_Driver::arc(int x,int y,int w,int h,double a1,double a2) { + if (w <= 0 || h <= 0) return; + while (a2