Debian Codegraph @

extern/agg24-svn/include/ctrl/agg_bezier_ctrl.h

raw
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: [email protected]
12 // [email protected]
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 //
16 // classes bezier_ctrl_impl, bezier_ctrl
17 //
18 //----------------------------------------------------------------------------
19
20 #ifndef AGG_BEZIER_CTRL_INCLUDED
21 #define AGG_BEZIER_CTRL_INCLUDED
22
23 #include "agg_math.h"
24 #include "agg_ellipse.h"
25 #include "agg_trans_affine.h"
26 #include "agg_color_rgba.h"
27 #include "agg_conv_stroke.h"
28 #include "agg_conv_curve.h"
29 #include "agg_polygon_ctrl.h"
30
31
32 namespace agg
33 {
34
35 //--------------------------------------------------------bezier_ctrl_impl
36 class bezier_ctrl_impl : public ctrl
37 {
38 public:
39 bezier_ctrl_impl();
40
41 void curve(double x1, double y1,
42 double x2, double y2,
43 double x3, double y3,
44 double x4, double y4);
45 curve4& curve();
46
47 double x1() const { return m_poly.xn(0); }
48 double y1() const { return m_poly.yn(0); }
49 double x2() const { return m_poly.xn(1); }
50 double y2() const { return m_poly.yn(1); }
51 double x3() const { return m_poly.xn(2); }
52 double y3() const { return m_poly.yn(2); }
53 double x4() const { return m_poly.xn(3); }
54 double y4() const { return m_poly.yn(3); }
55
56 void x1(double x) { m_poly.xn(0) = x; }
57 void y1(double y) { m_poly.yn(0) = y; }
58 void x2(double x) { m_poly.xn(1) = x; }
59 void y2(double y) { m_poly.yn(1) = y; }
60 void x3(double x) { m_poly.xn(2) = x; }
61 void y3(double y) { m_poly.yn(2) = y; }
62 void x4(double x) { m_poly.xn(3) = x; }
63 void y4(double y) { m_poly.yn(3) = y; }
64
65 void line_width(double w) { m_stroke.width(w); }
66 double line_width() const { return m_stroke.width(); }
67
68 void point_radius(double r) { m_poly.point_radius(r); }
69 double point_radius() const { return m_poly.point_radius(); }
70
71 virtual bool in_rect(double x, double y) const;
72 virtual bool on_mouse_button_down(double x, double y);
73 virtual bool on_mouse_button_up(double x, double y);
74 virtual bool on_mouse_move(double x, double y, bool button_flag);
75 virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
76
77 // Vertex source interface
78 unsigned num_paths() { return 7; };
79 void rewind(unsigned path_id);
80 unsigned vertex(double* x, double* y);
81
82
83 private:
84 curve4 m_curve;
85 ellipse m_ellipse;
86 conv_stroke<curve4> m_stroke;
87 polygon_ctrl_impl m_poly;
88 unsigned m_idx;
89 };
90
91
92
93 //----------------------------------------------------------bezier_ctrl
94 template<class ColorT> class bezier_ctrl : public bezier_ctrl_impl
95 {
96 public:
97 bezier_ctrl() :
98 m_color(rgba(0.0, 0.0, 0.0))
99 {
100 }
101
102 void line_color(const ColorT& c) { m_color = c; }
103 const ColorT& color(unsigned i) const { return m_color; }
104
105 private:
106 bezier_ctrl(const bezier_ctrl<ColorT>&);
107 const bezier_ctrl<ColorT>& operator = (const bezier_ctrl<ColorT>&);
108
109 ColorT m_color;
110 };
111
112
113
114
115
116 //--------------------------------------------------------curve3_ctrl_impl
117 class curve3_ctrl_impl : public ctrl
118 {
119 public:
120 curve3_ctrl_impl();
121
122 void curve(double x1, double y1,
123 double x2, double y2,
124 double x3, double y3);
125 curve3& curve();
126
127 double x1() const { return m_poly.xn(0); }
128 double y1() const { return m_poly.yn(0); }
129 double x2() const { return m_poly.xn(1); }
130 double y2() const { return m_poly.yn(1); }
131 double x3() const { return m_poly.xn(2); }
132 double y3() const { return m_poly.yn(2); }
133
134 void x1(double x) { m_poly.xn(0) = x; }
135 void y1(double y) { m_poly.yn(0) = y; }
136 void x2(double x) { m_poly.xn(1) = x; }
137 void y2(double y) { m_poly.yn(1) = y; }
138 void x3(double x) { m_poly.xn(2) = x; }
139 void y3(double y) { m_poly.yn(2) = y; }
140
141 void line_width(double w) { m_stroke.width(w); }
142 double line_width() const { return m_stroke.width(); }
143
144 void point_radius(double r) { m_poly.point_radius(r); }
145 double point_radius() const { return m_poly.point_radius(); }
146
147 virtual bool in_rect(double x, double y) const;
148 virtual bool on_mouse_button_down(double x, double y);
149 virtual bool on_mouse_button_up(double x, double y);
150 virtual bool on_mouse_move(double x, double y, bool button_flag);
151 virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
152
153 // Vertex source interface
154 unsigned num_paths() { return 6; };
155 void rewind(unsigned path_id);
156 unsigned vertex(double* x, double* y);
157
158
159 private:
160 curve3 m_curve;
161 ellipse m_ellipse;
162 conv_stroke<curve3> m_stroke;
163 polygon_ctrl_impl m_poly;
164 unsigned m_idx;
165 };
166
167
168
169 //----------------------------------------------------------curve3_ctrl
170 template<class ColorT> class curve3_ctrl : public curve3_ctrl_impl
171 {
172 public:
173 curve3_ctrl() :
174 m_color(rgba(0.0, 0.0, 0.0))
175 {
176 }
177
178 void line_color(const ColorT& c) { m_color = c; }
179 const ColorT& color(unsigned i) const { return m_color; }
180
181 private:
182 curve3_ctrl(const curve3_ctrl<ColorT>&);
183 const curve3_ctrl<ColorT>& operator = (const curve3_ctrl<ColorT>&);
184
185 ColorT m_color;
186 };
187
188
189
190
191 }
192
193
194
195 #endif
196