Debian Codegraph @

extern/agg24-svn/include/ctrl/agg_spline_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 spline_ctrl_impl, spline_ctrl
17 //
18 //----------------------------------------------------------------------------
19
20 #ifndef AGG_SPLINE_CTRL_INCLUDED
21 #define AGG_SPLINE_CTRL_INCLUDED
22
23 #include "agg_basics.h"
24 #include "agg_ellipse.h"
25 #include "agg_bspline.h"
26 #include "agg_conv_stroke.h"
27 #include "agg_path_storage.h"
28 #include "agg_trans_affine.h"
29 #include "agg_color_rgba.h"
30 #include "agg_ctrl.h"
31
32 namespace agg
33 {
34
35 //------------------------------------------------------------------------
36 // Class that can be used to create an interactive control to set up
37 // gamma arrays.
38 //------------------------------------------------------------------------
39 class spline_ctrl_impl : public ctrl
40 {
41 public:
42 spline_ctrl_impl(double x1, double y1, double x2, double y2,
43 unsigned num_pnt, bool flip_y=false);
44
45 // Set other parameters
46 void border_width(double t, double extra=0.0);
47 void curve_width(double t) { m_curve_width = t; }
48 void point_size(double s) { m_point_size = s; }
49
50 // Event handlers. Just call them if the respective events
51 // in your system occure. The functions return true if redrawing
52 // is required.
53 virtual bool in_rect(double x, double y) const;
54 virtual bool on_mouse_button_down(double x, double y);
55 virtual bool on_mouse_button_up(double x, double y);
56 virtual bool on_mouse_move(double x, double y, bool button_flag);
57 virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
58
59 void active_point(int i);
60
61 const double* spline() const { return m_spline_values; }
62 const int8u* spline8() const { return m_spline_values8; }
63 double value(double x) const;
64 void value(unsigned idx, double y);
65 void point(unsigned idx, double x, double y);
66 void x(unsigned idx, double x) { m_xp[idx] = x; }
67 void y(unsigned idx, double y) { m_yp[idx] = y; }
68 double x(unsigned idx) const { return m_xp[idx]; }
69 double y(unsigned idx) const { return m_yp[idx]; }
70 void update_spline();
71
72 // Vertex soutce interface
73 unsigned num_paths() { return 5; }
74 void rewind(unsigned path_id);
75 unsigned vertex(double* x, double* y);
76
77 private:
78 void calc_spline_box();
79 void calc_curve();
80 double calc_xp(unsigned idx);
81 double calc_yp(unsigned idx);
82 void set_xp(unsigned idx, double val);
83 void set_yp(unsigned idx, double val);
84
85 unsigned m_num_pnt;
86 double m_xp[32];
87 double m_yp[32];
88 bspline m_spline;
89 double m_spline_values[256];
90 int8u m_spline_values8[256];
91 double m_border_width;
92 double m_border_extra;
93 double m_curve_width;
94 double m_point_size;
95 double m_xs1;
96 double m_ys1;
97 double m_xs2;
98 double m_ys2;
99 path_storage m_curve_pnt;
100 conv_stroke<path_storage> m_curve_poly;
101 ellipse m_ellipse;
102 unsigned m_idx;
103 unsigned m_vertex;
104 double m_vx[32];
105 double m_vy[32];
106 int m_active_pnt;
107 int m_move_pnt;
108 double m_pdx;
109 double m_pdy;
110 const trans_affine* m_mtx;
111 };
112
113
114 template<class ColorT> class spline_ctrl : public spline_ctrl_impl
115 {
116 public:
117 spline_ctrl(double x1, double y1, double x2, double y2,
118 unsigned num_pnt, bool flip_y=false) :
119 spline_ctrl_impl(x1, y1, x2, y2, num_pnt, flip_y),
120 m_background_color(rgba(1.0, 1.0, 0.9)),
121 m_border_color(rgba(0.0, 0.0, 0.0)),
122 m_curve_color(rgba(0.0, 0.0, 0.0)),
123 m_inactive_pnt_color(rgba(0.0, 0.0, 0.0)),
124 m_active_pnt_color(rgba(1.0, 0.0, 0.0))
125 {
126 m_colors[0] = &m_background_color;
127 m_colors[1] = &m_border_color;
128 m_colors[2] = &m_curve_color;
129 m_colors[3] = &m_inactive_pnt_color;
130 m_colors[4] = &m_active_pnt_color;
131 }
132
133 // Set colors
134 void background_color(const ColorT& c) { m_background_color = c; }
135 void border_color(const ColorT& c) { m_border_color = c; }
136 void curve_color(const ColorT& c) { m_curve_color = c; }
137 void inactive_pnt_color(const ColorT& c) { m_inactive_pnt_color = c; }
138 void active_pnt_color(const ColorT& c) { m_active_pnt_color = c; }
139 const ColorT& color(unsigned i) const { return *m_colors[i]; }
140
141 private:
142 spline_ctrl(const spline_ctrl<ColorT>&);
143 const spline_ctrl<ColorT>& operator = (const spline_ctrl<ColorT>&);
144
145 ColorT m_background_color;
146 ColorT m_border_color;
147 ColorT m_curve_color;
148 ColorT m_inactive_pnt_color;
149 ColorT m_active_pnt_color;
150 ColorT* m_colors[5];
151 };
152
153
154
155
156 }
157
158
159 #endif