OSDN Git Service

first
[psychlops/cpp.git] / psychlops / extension / standard / widgets / psychlops_widget.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_WIDGET
10 #define HEADER_PSYCHLOPS_WIDGET
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
18
19 namespace Psychlops {
20
21         class Widget : public Figure {
22         };
23 namespace ExperimentalMethods
24 {
25         class Variable;
26 }
27
28 namespace Widgets {
29
30         class WidgetBase : public Events::Emittable, public Group
31         {
32                 protected:
33                 Events::Container *parent_;
34                 Events::Dispatcher slots_;
35                 public:
36                 Rectangle area;
37
38                 public:
39                 WidgetBase();
40                 virtual Rectangle getArea();
41                 virtual Events::Container& getParent();
42                 virtual Events::Container& setParent(Events::Container &par);
43                 virtual Events::Dispatcher& getSlots();
44                 virtual void distribute(Event &ev);
45                 virtual void distribute(Events::PointerDeviceEvent &event);
46                 void tabStop(bool on_off = true);
47         };
48
49
50
51
52
53
54
55         struct Theme {
56                 static bool initialized__;
57                 static Image default_button, default_horiz_grad;
58                 enum TYPE_TAG { NORMAL, ALERT };
59                 public:
60                 Color normal_foreground[2], active_foreground[2];
61                 Color normal_background[2], active_background[2], over_background[2];
62                 Stroke normal_stroke[2], active_stroke[2];
63                 Image *button_back, *horiz_grad;
64
65                 static Theme current;
66                 static void initialize();
67         };
68
69         Point drawableMouse(Drawable &d);
70
71
72
73
74         class WidgetDatum : public Widget {
75         public:
76                 Point datum;
77                 WidgetDatum();
78                 ~WidgetDatum();
79                 virtual const Point getDatum() const;
80                 virtual WidgetDatum& setDatum(const Point&);
81                 virtual WidgetDatum& centering(const Point&);
82                 using Figure::centering;
83         };
84
85         class WidgetRect : public Widget {
86                 protected:
87                 HumanInterfaceDevice::ButtonStateHolder mleft;
88                 int pressFrame;
89                 bool tabStopRegistered;
90
91                 bool pushed_;
92
93                 public:
94                 static int __LAST_TOTAL_REFRESH;
95                 static double __autoAlign_;
96                 static void __autoAlign(WidgetRect &target);            
97
98                 Theme *theme;
99                 Theme::TYPE_TAG theme_type;
100                 Rectangle area;
101                 Letters label;
102
103                 WidgetRect();
104                 virtual const Point getDatum() const;
105                 virtual WidgetRect& setDatum(const Point&);
106                 virtual WidgetRect& centering(const Point&);
107                 using Figure::centering;
108                 double getWidth() const;
109                 double getHeight() const;
110                 double getLeft() const;
111                 double getTop() const;
112                 double getRight() const;
113                 double getBottom() const;
114                 WidgetRect& alignLeft(const double lef);
115                 WidgetRect& alignTop(const double to_);
116                 WidgetRect& alignRight(const double rig);
117                 WidgetRect& alignBottom(const double bot);
118
119                 virtual WidgetRect& set(double wid, double hei);
120                 virtual WidgetRect& set(std::wstring name);
121                 virtual WidgetRect& set(std::wstring name, double hei);
122                 virtual WidgetRect& setLabel(std::wstring s);
123                 virtual WidgetRect& draw(Drawable &target = *Drawable::prime);
124                 bool pushed();
125                 WidgetRect& pushThis();
126         };
127
128         class StackPanel : public WidgetRect {
129         protected:
130                 std::deque< WidgetRect* > content;
131         public:
132                 enum Orientation { VERTICAL, HORIZONTAL };
133                 Orientation orientation;
134                 bool forceBase, forceAnother;
135
136                 double pitch;
137                 StackPanel();
138                 StackPanel& setWidth(double wid);
139                 StackPanel& setHeight(double hei);
140                 StackPanel& append(WidgetRect *target1, WidgetRect *target2=0, WidgetRect *target3=0, WidgetRect *target4=0, WidgetRect *target5=0);
141                 StackPanel& remove(WidgetRect *target);
142                 void align(Orientation ori = VERTICAL);
143                 virtual StackPanel& draw(Drawable &target = *Drawable::prime);
144
145                 static StackPanel default_stack;
146         };
147
148
149
150 }       /*      <- namespace Widgets    */
151 }       /*      <- namespace Psycholops         */
152
153
154 #endif