3 * Psychlops Standard Library (Universal)
5 * Last Modified 2009/02/15 by Kenchi HOSOKAWA
6 * (C) 2009 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
9 #ifndef HEADER_PSYCHLOPS_WIDGETS
10 #define HEADER_PSYCHLOPS_WIDGETS
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"
25 class TextBlock : public WidgetBase
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();
45 class Button_ : public TextBlock {
48 void evokeP(Events::Evoke &);
49 void evokeMouse(Events::MouseLeftUp &e);
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)());
70 class TextBox : public WidgetRect {
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();
84 class Button : public WidgetRect {
87 void (*onClickP)(void *);
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);
99 class ToggleButton : public Button {
104 ToggleButton(std::wstring s);
105 ToggleButton(std::wstring s, double size);
107 bool toggle(bool on_off);
109 virtual ToggleButton& draw(Drawable &target = *Drawable::prime);
112 class ScreenShotButton : public Button {
114 static void shoot(void *fname);
118 ScreenShotButton(char *name);
121 class Slider : public WidgetRect {
126 ExperimentalMethods::Variable *var;
130 enum ScaleMode { LINEAR, LOG };
131 ScaleMode scale_mode;
132 static const Interval def_itvl;
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)
145 link(s, item, rng, d_step, e_step);
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)
161 ExperimentalMethods::VariableInstance<T>* v = new ExperimentalMethods::VariableInstance<T>(&item);
162 v->set(s, rng, d_step, e_step);
165 StackPanel::default_stack.remove(this);
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);
179 class Dial : public WidgetDatum {
181 Rectangle ext, internal;
183 double current_theta, former_theta, factor;
186 bool pressed, dragged;
192 Dial& label(std::wstring s);
194 Dial& draw(Drawable &target = *Drawable::prime);
195 Dial& link(double &item, double fac = 1);
198 double operator =(double v);
201 class SelectBox : public WidgetRect
204 std::deque<Letters> item;
208 void appendL(Letters &let);
212 SelectBox(double hei);
213 SelectBox& set(double hei);
214 SelectBox& set(double wid, double hei);
216 template<class T> void append(T arg)
222 void setSelected(int dd);
226 virtual SelectBox& draw(Drawable &target = *Drawable::prime);
230 class CloseButton : public Button
235 static void exitApp();
238 class MinimizeButton : public Button
243 MinimizeButton(Canvas &target);
244 static void minimizeApp(void *hwnd);
247 class TitleBar : public WidgetDatum
250 static TitleBar *default_titlebar;
255 MinimizeButton minimize;
257 HumanInterfaceDevice::ButtonStateHolder mleft;
258 Point begin_m, begin_w, begin_w_size;
262 TitleBar(Canvas &target);
263 TitleBar& draw(Drawable &target = *Drawable::prime);
269 void alert(std::string message);
270 void alert(std::wstring message);
271 std::string getOpenFileName();
273 } /* <- namespace Dialog */
276 } /* <- namespace Widgets */
277 } /* <- namespace Psycholops */