gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
CairoArc.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef CAIROARC_H_
18 #define CAIROARC_H_
19 
20 #include <cairo/cairo.h>
21 #ifdef _MSC_VER
22 #define _USE_MATH_DEFINES
23 #endif
24 #include <math.h>
25 
26 #define CAIROARC_DEFAULT_RADIUS 20.
27 #define CAIROARC_DEFAULT_FILLED false
28 #define CAIROARC_DEFAULT_THETASTART 0.
29 #define CAIROARC_DEFAULT_THETAEND M_PI/2.
30 
31 
36 class CairoArc {
37 protected:
38  double radius;
39  double thetaStart, thetaEnd;
40  bool filled;
41 public:
45  thetaStart=CAIROARC_DEFAULT_THETASTART;
48  }
49 
59  CairoArc(cairo_t *cr, double x, double y, double radiusIn, double angleStart, double angleEnd, bool fillIn){
60  draw(cr, x, y, radiusIn, angleStart, angleEnd, fillIn);
61  }
62 
63  virtual ~CairoArc() {}
64 
71  void settings(double radiusIn, double angleStart, double angleEnd, bool fillIn){
72  radius=radiusIn;
73  thetaStart=angleStart; thetaEnd=angleEnd;
74  filled=fillIn;
75  }
76 
82  void draw(cairo_t *cr, double x, double y, bool fillIn){
83  settings(radius, thetaStart, thetaEnd, fillIn);
84  draw(cr, x, y);
85  }
86 
92  void draw(cairo_t *cr, double x, double y, double radiusIn){
93  settings(radiusIn, thetaStart, thetaEnd, filled);
94  draw(cr, x, y);
95  }
96 
103  void draw(cairo_t *cr, double x, double y, double radiusIn, bool fillIn){
104  settings(radiusIn, thetaStart, thetaEnd, fillIn);
105  draw(cr, x, y);
106  }
107 
115  void draw(cairo_t *cr, double x, double y, double angleStart, double angleEnd, bool fillIn){
116  settings(radius, angleStart, angleEnd, fillIn);
117  draw(cr, x, y);
118  }
119 
127  void draw(cairo_t *cr, double x, double y, double radiusIn, double angleStart, double angleEnd){
128  settings(radiusIn, angleStart, angleEnd, filled);
129  draw(cr, x, y);
130  }
131 
140  void draw(cairo_t *cr, double x, double y, double radiusIn, double angleStart, double angleEnd, bool fillIn){
141  settings(radiusIn, angleStart, angleEnd, fillIn);
142  draw(cr, x, y);
143  }
144 
150  void draw(cairo_t *cr, double x, double y) {
151  cairo_move_to(cr, x, y); // start with the center at x, y
152  if (!filled)
153  cairo_move_to(cr, x+cos(thetaStart)*radius, y+sin(thetaStart)*radius);
154  cairo_arc(cr, x, y, radius, thetaStart, thetaEnd); // draw the arc
155  if (!filled)
156  cairo_stroke (cr);
157  else
158  cairo_fill (cr);
159  }
160 
164  double getRadius(){
165  return radius;
166  }
167 
171  double getAngleStart(){
172  return thetaStart;
173  }
174 
178  double getAngleEnd(){
179  return thetaEnd;
180  }
181 };
182 
183 #endif // CAIROARC_H_
void draw(cairo_t *cr, double x, double y, double radiusIn)
Definition: CairoArc.H:92
CairoArc()
Empty constructor.
Definition: CairoArc.H:43
float * x
double thetaEnd
The angles from start to end.
Definition: CairoArc.H:39
void draw(cairo_t *cr, double x, double y, double radiusIn, bool fillIn)
Definition: CairoArc.H:103
#define CAIROARC_DEFAULT_THETASTART
The default start angle.
Definition: CairoArc.H:28
bool filled
Whether to fill the box.
Definition: CairoArc.H:40
void draw(cairo_t *cr, double x, double y)
Definition: CairoArc.H:150
CairoArc(cairo_t *cr, double x, double y, double radiusIn, double angleStart, double angleEnd, bool fillIn)
Definition: CairoArc.H:59
double thetaStart
Definition: CairoArc.H:39
#define CAIROARC_DEFAULT_FILLED
The default fill value.
Definition: CairoArc.H:27
void draw(cairo_t *cr, double x, double y, double angleStart, double angleEnd, bool fillIn)
Definition: CairoArc.H:115
double getRadius()
Definition: CairoArc.H:164
void settings(double radiusIn, double angleStart, double angleEnd, bool fillIn)
Definition: CairoArc.H:71
#define CAIROARC_DEFAULT_THETAEND
The default ending angle (half circle)
Definition: CairoArc.H:29
void draw(cairo_t *cr, double x, double y, bool fillIn)
Definition: CairoArc.H:82
void draw(cairo_t *cr, double x, double y, double radiusIn, double angleStart, double angleEnd, bool fillIn)
Definition: CairoArc.H:140
#define CAIROARC_DEFAULT_RADIUS
The default radius.
Definition: CairoArc.H:26
float * y
void draw(cairo_t *cr, double x, double y, double radiusIn, double angleStart, double angleEnd)
Definition: CairoArc.H:127
virtual ~CairoArc()
Definition: CairoArc.H:63
double getAngleStart()
Definition: CairoArc.H:171
double radius
The radius of the circle.
Definition: CairoArc.H:38
double getAngleEnd()
Definition: CairoArc.H:178
gtkIOStream: /tmp/gtkiostream/include/CairoArc.H Source File
GTK+ IOStream  Beta