1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry (AGG) - Version 2.5
3 // A high quality rendering engine for C++
4 // Copyright (C) 2002-2006 Maxim Shemanarev
5 // Contact: mcseem@antigrain.com
6 //          mcseemagg@yahoo.com
7 //          http://antigrain.com
8 //
9 // AGG is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // AGG is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with AGG; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 // MA 02110-1301, USA.
23 //----------------------------------------------------------------------------
24 
25 #ifndef AGG_CBOX_CTRL_INCLUDED
26 #define AGG_CBOX_CTRL_INCLUDED
27 
28 #include "agg_basics.h"
29 #include "agg_conv_stroke.h"
30 #include "agg_gsv_text.h"
31 #include "agg_trans_affine.h"
32 #include "agg_color_rgba.h"
33 #include "agg_ctrl.h"
34 
35 
36 
37 namespace agg
38 {
39 
40     //----------------------------------------------------------cbox_ctrl_impl
41     class cbox_ctrl_impl : public ctrl
42     {
43     public:
44         cbox_ctrl_impl(double x, double y, const char* label, bool flip_y=false);
45 
text_thickness(double t)46         void text_thickness(double t)  { m_text_thickness = t; }
47         void text_size(double h, double w=0.0);
48 
label()49         const char* label() { return m_label; }
50         void label(const char* l);
51 
status()52         bool status() const { return m_status; }
status(bool st)53         void status(bool st) { m_status = st; }
54 
55         virtual bool in_rect(double x, double y) const;
56         virtual bool on_mouse_button_down(double x, double y);
57         virtual bool on_mouse_button_up(double x, double y);
58         virtual bool on_mouse_move(double x, double y, bool button_flag);
59         virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
60 
61         // Vertex soutce interface
num_paths()62         unsigned num_paths() { return 3; };
63         void     rewind(unsigned path_id);
64         unsigned vertex(double* x, double* y);
65 
66     private:
67         double   m_text_thickness;
68         double   m_text_height;
69         double   m_text_width;
70         char     m_label[128];
71         bool     m_status;
72         double   m_vx[32];
73         double   m_vy[32];
74 
75         gsv_text              m_text;
76         conv_stroke<gsv_text> m_text_poly;
77 
78         unsigned m_idx;
79         unsigned m_vertex;
80     };
81 
82 
83     //----------------------------------------------------------cbox_ctrl_impl
84     template<class ColorT> class cbox_ctrl : public cbox_ctrl_impl
85     {
86     public:
87         cbox_ctrl(double x, double y, const char* label, bool flip_y=false) :
cbox_ctrl_impl(x,y,label,flip_y)88             cbox_ctrl_impl(x, y, label, flip_y),
89             m_text_color(rgba(0.0, 0.0, 0.0)),
90             m_inactive_color(rgba(0.0, 0.0, 0.0)),
91             m_active_color(rgba(0.4, 0.0, 0.0))
92         {
93             m_colors[0] = &m_inactive_color;
94             m_colors[1] = &m_text_color;
95             m_colors[2] = &m_active_color;
96         }
97 
text_color(const ColorT & c)98         void text_color(const ColorT& c) { m_text_color = c; }
inactive_color(const ColorT & c)99         void inactive_color(const ColorT& c) { m_inactive_color = c; }
active_color(const ColorT & c)100         void active_color(const ColorT& c) { m_active_color = c; }
101 
color(unsigned i)102         const ColorT& color(unsigned i) const { return *m_colors[i]; }
103 
104     private:
105         cbox_ctrl(const cbox_ctrl<ColorT>&);
106         const cbox_ctrl<ColorT>& operator = (const cbox_ctrl<ColorT>&);
107 
108         ColorT m_text_color;
109         ColorT m_inactive_color;
110         ColorT m_active_color;
111         ColorT* m_colors[3];
112     };
113 
114 
115 }
116 
117 #endif
118