2 * psychlops_figure_prototype.cpp
3 * Psychlops Standard Library (Universal)
5 * Last Modified 2009/02/15 by Kenchi HOSOKAWA
6 * (C) 2009 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
9 #include "psychlops_widget.h"
19 WidgetBase::WidgetBase() { parent_ = 0; }
20 Rectangle WidgetBase::getArea() { return area; }
21 Events::Container& WidgetBase::getParent() { return *parent_; }
22 Events::Container& WidgetBase::setParent(Events::Container &par) { parent_ = ∥ return *parent_; }
23 Events::Dispatcher& WidgetBase::getSlots() { return slots_; }
24 void WidgetBase::distribute(Event &ev) { getSlots().emit(ev); }
25 void WidgetBase::distribute(Events::PointerDeviceEvent &ev) { getSlots().emit(ev); }
26 void WidgetBase::tabStop(bool on_off)
28 Events::AddToTabstopList list(this);
39 bool Theme::initialized__ = false;
40 Image Theme::default_button, Theme::default_horiz_grad;
42 Theme::Theme(Color c1, Color c2, Stroke s1, Stroke s2)
44 normal_background = c1;
50 void Theme::initialize()
53 for(int i=0; i<2; i++) {
54 Theme::current.normal_foreground[i] = Color::black;
55 Theme::current.active_foreground[i] = Color::black;
56 Theme::current.normal_background[i] = Color(.85,.85,.85,.5);
57 Theme::current.active_background[i] = Color(.70,1.0,.85,.65);
58 Theme::current.over_background[i] = Color(.5,.5,1.0,.5);
59 Theme::current.normal_stroke[i] = Stroke(Color(.35,.35,.35,.75), 1, Stroke::SOLID);
60 Theme::current.active_stroke[i] = Stroke(Color(.35,.35,.35,.75), 2, Stroke::SOLID);
62 Theme::current.normal_background[ALERT] = Color(.8,.2,.1,.5);
63 Theme::current.over_background[ALERT] = Color(1,.25,0,.5);
65 default_button.set(1,20, Image::RGBA);
66 for(int y= 0; y< 5; y++) { double level = 0.5-y*0.1; default_button.pix(0,y,Color::white); default_button.alpha(0,y,level); }
67 for(int y= 5; y<15; y++) { default_button.pix(0,y,Color::white); default_button.alpha(0,y,0.1); }
68 for(int y=15; y<20; y++) { double level = (y-14)*0.075; default_button.pix(0,y,Color(.8,.8,.8)); default_button.alpha(0,y,level); }
69 Theme::current.button_back = &Theme::default_button;
70 default_horiz_grad.set(40,1, Image::RGBA);
71 for(int x= 0; x<15; x++) { double level = 0.25-x*0.01; default_horiz_grad.pix(x,0,Color::white); default_horiz_grad.alpha(x,0,level); }
72 for(int x=15; x<35; x++) { default_horiz_grad.pix(x,0,Color::white); default_horiz_grad.alpha(x,0,0.1); }
73 for(int x=35; x<40; x++) { double level = (x-33)*0.075; default_horiz_grad.pix(x,0,Color(.8,.8,.8)); default_horiz_grad.alpha(x,0,level); }
74 Theme::current.horiz_grad = &Theme::default_horiz_grad;
79 Point drawableMouse(Drawable &d){
80 Canvas *cnvs = dynamic_cast<Canvas*>(&d);
81 return (cnvs!=0) ? cnvs->mouse() : (Point)Mouse::uniPosition;
86 WidgetDatum::WidgetDatum() : datum(0,0,0) {}
87 WidgetDatum::~WidgetDatum() {}
88 const Point WidgetDatum::getDatum() const {
91 WidgetDatum& WidgetDatum::setDatum(const Point& p) {
95 WidgetDatum& WidgetDatum::centering(const Point & p) {
100 WidgetRect::WidgetRect()
101 : mleft(Mouse::left), pressFrame(-1), tabStopRegistered(false)
104 theme = &Theme::current;
105 theme_type = Theme::NORMAL;
108 const Point WidgetRect::getDatum() const { return area.getDatum(); }
109 WidgetRect& WidgetRect::setDatum(const Point& p) { area.setDatum(p); return *this; }
110 WidgetRect& WidgetRect::centering(const Point& p) { area.centering(p); return *this; }
112 double WidgetRect::getWidth() const { return area.getWidth(); }
113 double WidgetRect::getHeight() const { return area.getHeight(); }
114 double WidgetRect::getLeft() const { return area.getLeft(); }
115 double WidgetRect::getTop() const { return area.getTop(); }
116 double WidgetRect::getRight() const { return area.getRight(); }
117 double WidgetRect::getBottom() const { return area.getBottom(); }
118 WidgetRect& WidgetRect::alignLeft(const double lef) { area.alignLeft(lef); return *this; }
119 WidgetRect& WidgetRect::alignTop(const double to_) { area.alignTop(to_); return *this; }
120 WidgetRect& WidgetRect::alignRight(const double rig) { area.alignRight(rig); return *this; }
121 WidgetRect& WidgetRect::alignBottom(const double bot) { area.alignBottom(bot); return *this; }
123 WidgetRect& WidgetRect::set(double wid, double hei)
127 label.font.size = (size>0) ? size : Font::default_font.size;
130 WidgetRect& WidgetRect::set(std::wstring name)
132 return set(name, Font::default_font.size);
134 WidgetRect& WidgetRect::set(std::wstring name, double hei)
137 label.font.size = (size>0) ? size : Font::default_font.size;
138 label.setString(name);
139 area.set(hei*label.str.length(), hei);
142 WidgetRect& WidgetRect::setLabel(std::wstring s)
144 double size = area.getHeight()-4;
145 label.font.size = (size>5 && size<40) ? size : Font::default_font.size;
147 label.fill = theme->normal_foreground[theme_type];
150 WidgetRect& WidgetRect::draw(Drawable &target)
154 bool WidgetRect::pushed()
160 WidgetRect& WidgetRect::pushThis()
166 int WidgetRect::__LAST_TOTAL_REFRESH = 0;
167 double WidgetRect::__autoAlign_ = 10.0;
168 void WidgetRect::__autoAlign(WidgetRect &target)
171 if(Display::the_canvas!=0) {
172 if(__LAST_TOTAL_REFRESH!=Display::the_canvas->TOTAL_REFRESH) {
173 __LAST_TOTAL_REFRESH = Display::the_canvas->TOTAL_REFRESH;
178 target.area.shift(10, __autoAlign_);
179 __autoAlign_ += target.area.getHeight() + 10;
184 StackPanel::StackPanel()
186 orientation = VERTICAL;
189 StackPanel& StackPanel::setWidth(double wid)
191 area.set(wid, area.getHeight());
195 StackPanel& StackPanel::setHeight(double hei)
197 area.set(area.getWidth(), hei);
201 StackPanel& StackPanel::append(WidgetRect *target1, WidgetRect *target2, WidgetRect *target3, WidgetRect *target4, WidgetRect *target5)
203 if(target1!=0) { content.push_back(target1); }
204 if(target2!=0) { content.push_back(target2); }
205 if(target3!=0) { content.push_back(target3); }
206 if(target4!=0) { content.push_back(target4); }
207 if(target5!=0) { content.push_back(target5); }
210 StackPanel& StackPanel::remove(WidgetRect *target)
212 for(std::deque<WidgetRect *>::iterator i = content.begin(); i != content.end(); i++) {
220 void StackPanel::align(Orientation ori)
223 double dleft = getLeft(), dtop = getTop();
224 switch(orientation) {
226 if(!content.empty()) {
227 for(int i=0; i<content.size(); i++) {
228 content[i]->area.set(area.getWidth(), content[i]->area.getHeight());
229 content[i]->alignLeft(dleft);
230 content[i]->alignTop(dtop);
231 dtop += content[i]->getHeight() + pitch;
237 if(!content.empty()) {
238 for(int i=0; i<content.size(); i++) {
239 content[i]->alignLeft(dleft);
240 content[i]->alignTop(dtop);
241 dleft += content[i]->getWidth() + pitch;
248 StackPanel& StackPanel::draw(Drawable &target)
250 double dleft = getLeft(), dtop = getTop();
251 switch(orientation) {
253 if(!content.empty()) {
254 for(int i=0; i<content.size(); i++) {
255 content[i]->area.set(area.getWidth(), content[i]->area.getHeight());
256 content[i]->alignLeft(dleft);
257 content[i]->alignTop(dtop);
258 content[i]->draw(target);
259 dtop += content[i]->getHeight() + pitch;
265 if(!content.empty()) {
266 for(int i=0; i<content.size(); i++) {
267 content[i]->alignLeft(dleft);
268 content[i]->alignTop(dtop);
269 content[i]->draw(target);
270 dleft += content[i]->getWidth() + pitch;
279 StackPanel StackPanel::default_stack;
282 } /* <- namespace Widgets */
283 } /* <- namespace Psycholops */