OSDN Git Service

first
[psychlops/cpp.git] / psychlops / extension / standard / widgets / psychlops_widgets.h
1 /*
2  *  psychlops_widgets_prototype.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2009/02/15 by Kenchi HOSOKAWA
6  *  (C) 2009 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #ifndef HEADER_PSYCHLOPS_WIDGETS
10 #define HEADER_PSYCHLOPS_WIDGETS
11
12 #include <string>
13 #include "../../../core/graphic/psychlops_g_module.h"
14 #include "../../../psychlops_core.h"
15 #include "../psychophysics/psychlops_exp_psychophysics.h"
16 #include "psychlops_widgets_event.h"
17 #include "psychlops_widget.h"
18
19
20 namespace Psychlops {
21
22
23 namespace Widgets {
24
25         class TextBlock : public WidgetBase
26         {
27                 protected:
28                 bool initialized;
29                 void initialize();
30                 Letters label;
31                 std::wstring content;
32
33                 public:
34                 TextBlock();
35                 TextBlock(std::wstring s, double hei = Font::default_font.size);
36                 virtual Point getHitDatum();
37                 //virtual Rectangle getArea();
38                 virtual TextBlock& set(std::wstring s, double hei = Font::default_font.size);
39                 virtual TextBlock& set(double w, double h);
40                 void setText(const std::wstring &str);
41                 std::wstring& getText();
42         };
43
44
45         class Button_ : public TextBlock {
46         protected:
47                 void (*onClick)();
48                 void evokeP(Events::Evoke &);
49                 void evokeMouse(Events::MouseLeftUp &e);
50         public:
51                 Button_();
52                 Button_(std::wstring s, double size = 0);
53                 //virtual Button_& set_(std::wstring s, double hei = Font::default_font.size);
54                 //virtual Button_& set_(double w, double h);
55                 virtual void onEvoked(void (*f)());
56         };
57
58
59
60
61
62
63
64
65
66
67
68
69
70         class TextBox : public WidgetRect {
71         protected:
72                 void setBase();
73                 Letters cache;
74                 std::wstring content;
75         public:
76                 TextBox();
77                 TextBox(std::wstring s);
78                 virtual TextBox& set(std::wstring s);
79                 virtual TextBox& draw(Drawable &target = *Drawable::prime);
80                 void setText(const std::wstring &str);
81                 std::wstring& getText();
82         };
83
84         class Button : public WidgetRect {
85         protected:
86                 void (*onClick)();
87                 void (*onClickP)(void *);
88                 void setBase();
89         public:
90                 void *arg;
91                 Button();
92                 Button(std::wstring s);
93                 Button(std::wstring s, double size);
94                 virtual Button& set(std::wstring s, double hei = Font::default_font.size);
95                 virtual Button& set(double w, double h);
96                 virtual Button& draw(Drawable &target = *Drawable::prime);
97         };
98
99         class ToggleButton : public Button {
100         protected:
101                 bool checked_;
102         public:
103                 ToggleButton();
104                 ToggleButton(std::wstring s);
105                 ToggleButton(std::wstring s, double size);
106                 bool toggle();
107                 bool toggle(bool on_off);
108                 bool isChecked();
109                 virtual ToggleButton& draw(Drawable &target = *Drawable::prime);
110         };
111
112         class ScreenShotButton : public Button {
113         protected:
114                 static void shoot(void *fname);
115                 static Image buffer;
116         public:
117                 std::string name;
118                 ScreenShotButton(char *name);
119         };
120
121         class Slider : public WidgetRect {
122         protected:
123                 bool dragged;
124                 double local;
125                 bool isLocal_;
126                 ExperimentalMethods::Variable *var;
127                 bool changed_;
128                 void setBase();
129         public:
130                 enum ScaleMode { LINEAR, LOG };
131                 ScaleMode scale_mode;
132                 static const Interval def_itvl;
133                 Rectangle internal;
134                 bool show_value;
135
136                 Slider();
137                 ~Slider();
138                 Slider(ExperimentalMethods::Variable &v);
139                 Slider(double wid, double hei);
140                 Slider(std::string s, Interval rng = def_itvl, double d_step = 0.1, double e_step = 1);
141                 template<typename T, typename S> Slider(T &item, std::string s, Interval rng = def_itvl, S d_step = 0.1, S e_step = 0.05)
142                 {
143                         setBase();
144                         set(s);
145                         link(s, item, rng, d_step, e_step);
146                 }
147                 virtual Slider& set(ExperimentalMethods::Variable &v);
148                 virtual Slider& set(std::string s, Interval rng = def_itvl, double d_step = 0.1, double e_step = 0.05);
149                 virtual Slider& setSize(double wid, double hei);
150                 virtual Slider& setLabel(std::string s);
151                 virtual Slider& setLabel(std::wstring s);
152                 //virtual Slider& setLabel(std::string s, double hei = Font::default_font.size);
153                 //virtual Slider& setLabel(std::wstring s, double hei = Font::default_font.size);
154                 virtual Slider& draw(Drawable &target = *Drawable::prime);
155                 Slider& linkTo(ExperimentalMethods::Variable *v);
156                 Slider& operator =(ExperimentalMethods::Variable &v);
157                 template<typename T, typename S> Slider& link(T &item, Interval rng = def_itvl, S d_step = 0.1, S e_step = 0.05) { return link(item, " ", rng, d_step, e_step); }
158                 template<typename T, typename S> Slider& link(T &item, std::string s, Interval rng = def_itvl, S d_step = 0.1, S e_step = 0.05)
159                 {
160                         setLabel(s);
161                         ExperimentalMethods::VariableInstance<T>* v = new ExperimentalMethods::VariableInstance<T>(&item);
162                         v->set(s, rng, d_step, e_step);
163                         var = v;
164                         isLocal_ = true;
165                         StackPanel::default_stack.remove(this);
166                         return *this;
167                 }
168                 bool changed();
169                 operator double();
170                 double operator =(double v);
171                 void setByRatio(double ratio);
172                 double getRatio() const;
173                 Interval getInterval() const;
174                 Interval setInterval(const Interval &itvl);
175                 void increment(int modulation = 0);
176                 void decrement(int modulation = 0);
177         };
178
179         class Dial : public WidgetDatum {
180         protected:
181                 Rectangle ext, internal;
182                 Letters let;
183                 double current_theta, former_theta, factor;
184                 double local;
185                 double *var;
186                 bool pressed, dragged;
187                 bool changed_;
188         public:
189                 Dial();
190                 Dial(double r);
191                 void setBase();
192                 Dial& label(std::wstring s);
193                 Dial& set(double r);
194                 Dial& draw(Drawable &target = *Drawable::prime);
195                 Dial& link(double &item, double fac = 1);
196                 bool changed();
197                 operator double();
198                 double operator =(double v);
199         };
200
201         class SelectBox : public WidgetRect
202         {
203                 protected:
204                 std::deque<Letters> item;
205                 int selected_;
206                 bool vertical_;
207                 Group holder_;
208                 void appendL(Letters &let);
209
210                 public:
211                 SelectBox();
212                 SelectBox(double hei);
213                 SelectBox& set(double hei);
214                 SelectBox& set(double wid, double hei);
215                 void makeVertical();
216                 template<class T> void append(T arg)
217                 {
218                         Letters let(arg);
219                         appendL(let);
220                 }
221                 int getSelected();
222                 void setSelected(int dd);
223                 void next();
224                 void retreat();
225                 void hid();
226                 virtual SelectBox& draw(Drawable &target = *Drawable::prime);
227         };
228
229
230         class CloseButton : public Button
231         {
232                 protected:
233                 public:
234                 CloseButton();
235                 static void exitApp();
236         };
237
238         class MinimizeButton : public Button
239         {
240                 protected:
241                 Canvas* window;
242                 public:
243                 MinimizeButton(Canvas &target);
244                 static void minimizeApp(void *hwnd);
245         };
246
247         class TitleBar : public WidgetDatum
248         {
249         public:
250                 static TitleBar *default_titlebar;
251
252         protected:
253
254                 CloseButton close;
255                 MinimizeButton minimize;
256                 Rectangle area;
257                 HumanInterfaceDevice::ButtonStateHolder mleft;
258                 Point begin_m, begin_w, begin_w_size;
259
260                 bool dragged_;
261                 public:
262                 TitleBar(Canvas &target);
263                 TitleBar& draw(Drawable &target = *Drawable::prime);
264         };
265
266
267 namespace Dialog {
268
269         void alert(std::string message);
270         void alert(std::wstring message);
271         std::string getOpenFileName();
272
273 }       /*      <- namespace Dialog     */
274
275
276 }       /*      <- namespace Widgets    */
277 }       /*      <- namespace Psycholops         */
278
279
280 #endif