summaryrefslogtreecommitdiff
path: root/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx
blob: c0fd58aea6b0cc14b6f58423ade87de80b24ba14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// "$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
//

/**
  \file Fl_OpenGL_Graphics_Driver_arci.cxx
  \brief Utility functions for drawing circles using integers
*/

#include <config.h>
#include "../../config_lib.h"
#include "Fl_OpenGL_Graphics_Driver.H"
#include <FL/gl.h>
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_RGB_Image.H>
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#define _USE_MATH_DEFINES
#include <math.h>

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<a1) a2 += 360.0;  // TODO: write a sensible fmod angle alignment here
  a1 = a1/180.0f*M_PI; a2 = a2/180.0f*M_PI;
  double cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
  double rMax; if (w<h) rMax = h/2; else rMax = w/2;
  int nSeg = (int)(10 * sqrt(rMax))+1;
  double incr = (a2-a1)/(double)nSeg;

  glBegin(GL_LINE_STRIP);
  for (int i=0; i<nSeg; i++) {
    glVertex2d(cx+cos(a1)*rMax, cy-sin(a1)*rMax);
    a1 += incr;
  }
  glEnd();
}

void Fl_OpenGL_Graphics_Driver::pie(int x,int y,int w,int h,double a1,double a2) {
  if (w <= 0 || h <= 0) return;
  while (a2<a1) a2 += 360.0;  // TODO: write a sensible fmod angle alignment here
  a1 = a1/180.0f*M_PI; a2 = a2/180.0f*M_PI;
  double cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
  double rMax; if (w<h) rMax = h/2; else rMax = w/2;
  int nSeg = (int)(10 * sqrt(rMax))+1;
  double incr = (a2-a1)/(double)nSeg;

  glBegin(GL_TRIANGLE_FAN);
  glVertex2d(cx, cy);
  for (int i=0; i<nSeg+1; i++) {
    glVertex2d(cx+cos(a1)*rMax, cy-sin(a1)*rMax);
    a1 += incr;
  }
  glEnd();
}

//
// End of "$Id$".
//