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: mcseem@antigrain.com
12 //          mcseemagg@yahoo.com
13 //          http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 //
16 // classes cbox_ctrl_impl, cbox_ctrl
17 //
18 //----------------------------------------------------------------------------
19 
20 #ifndef AGG_CBOX_CTRL_INCLUDED
21 #define AGG_CBOX_CTRL_INCLUDED
22 
23 #include "agg_basics.h"
24 #include "agg_conv_stroke.h"
25 #include "agg_gsv_text.h"
26 #include "agg_trans_affine.h"
27 #include "agg_color_rgba.h"
28 #include "agg_ctrl.h"
29 
30 
31 
32 namespace agg
33 {
34 
35     //----------------------------------------------------------cbox_ctrl_impl
36     class cbox_ctrl_impl : public ctrl
37     {
38     public:
39         cbox_ctrl_impl(double x, double y, const char* label, bool flip_y=false);
40 
text_thickness(double t)41         void text_thickness(double t)  { m_text_thickness = t; }
42         void text_size(double h, double w=0.0);
43 
label()44         const char* label() { return m_label; }
45         void label(const char* l);
46 
status()47         bool status() const { return m_status; }
status(bool st)48         void status(bool st) { m_status = st; }
49 
50         virtual bool in_rect(double x, double y) const;
51         virtual bool on_mouse_button_down(double x, double y);
52         virtual bool on_mouse_button_up(double x, double y);
53         virtual bool on_mouse_move(double x, double y, bool button_flag);
54         virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
55 
56         // Vertex soutce interface
num_paths()57         unsigned num_paths() { return 3; };
58         void     rewind(unsigned path_id);
59         unsigned vertex(double* x, double* y);
60 
61     private:
62         double   m_text_thickness;
63         double   m_text_height;
64         double   m_text_width;
65         char     m_label[128];
66         bool     m_status;
67         double   m_vx[32];
68         double   m_vy[32];
69 
70         gsv_text              m_text;
71         conv_stroke<gsv_text> m_text_poly;
72 
73         unsigned m_idx;
74         unsigned m_vertex;
75     };
76 
77 
78     //----------------------------------------------------------cbox_ctrl_impl
79     template<class ColorT> class cbox_ctrl : public cbox_ctrl_impl
80     {
81     public:
82         cbox_ctrl(double x, double y, const char* label, bool flip_y=false) :
cbox_ctrl_impl(x,y,label,flip_y)83             cbox_ctrl_impl(x, y, label, flip_y),
84             m_text_color(rgba(0.0, 0.0, 0.0)),
85             m_inactive_color(rgba(0.0, 0.0, 0.0)),
86             m_active_color(rgba(0.4, 0.0, 0.0))
87         {
88             m_colors[0] = &m_inactive_color;
89             m_colors[1] = &m_text_color;
90             m_colors[2] = &m_active_color;
91         }
92 
text_color(const ColorT & c)93         void text_color(const ColorT& c) { m_text_color = c; }
inactive_color(const ColorT & c)94         void inactive_color(const ColorT& c) { m_inactive_color = c; }
active_color(const ColorT & c)95         void active_color(const ColorT& c) { m_active_color = c; }
96 
color(unsigned i)97         const ColorT& color(unsigned i) const { return *m_colors[i]; }
98 
99     private:
100         cbox_ctrl(const cbox_ctrl<ColorT>&);
101         const cbox_ctrl<ColorT>& operator = (const cbox_ctrl<ColorT>&);
102 
103         ColorT m_text_color;
104         ColorT m_inactive_color;
105         ColorT m_active_color;
106         ColorT* m_colors[3];
107     };
108 
109 
110 }
111 
112 #endif
113