1 #include <msp/gl/immediate.h>
2 #include <msp/gl/matrix.h>
3 #include <msp/gl/transform.h>
4 #include <msp/strings/formatter.h>
27 Container *p = parent;
33 void Widget::set_position(int x, int y)
40 void Widget::set_size(unsigned w, unsigned h)
47 void Widget::autosize()
51 const Style::PartSeq &parts = style->get_parts();
52 for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
53 if(i->get_name().empty())
55 geom.w = max(geom.w, i->get_geometry().w);
56 geom.h = max(geom.h, i->get_geometry().h);
60 void Widget::set_geometry(const Geometry &g)
66 void Widget::set_parent(Container *p)
69 throw InvalidState("Widget is already in a Container");
78 void Widget::set_style(const string &s)
84 void Widget::update_style()
87 for(top=this; top->parent; top=top->parent) ;
88 Root *root = dynamic_cast<Root *>(top);
93 string sname = get_class();
94 if(!style_name.empty())
100 style = root->get_resources().get<Style>(sname);
104 signal_autosize_changed.emit();
107 void Widget::set_tooltip(const string &t)
112 void Widget::set_visible(bool v)
119 signal_visibility_changed.emit(visible);
122 void Widget::set_focusable(bool f)
127 void Widget::set_focus()
130 throw InvalidState("No parent");
132 throw InvalidState("Can't set focus on invisible widget");
134 signal_request_focus.emit();
137 void Widget::render() const
140 throw InvalidState(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
143 GL::translate(geom.x, geom.y, 0);
144 const Style::PartSeq &parts = style->get_parts();
145 for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
147 if(i->get_name().empty())
149 GL::PushMatrix push_;
150 i->render(geom, state);
158 void Widget::pointer_enter()
163 void Widget::pointer_leave()
168 void Widget::focus_in()
173 void Widget::focus_out()
179 Widget::Loader::Loader(Widget &w):
180 DataFile::ObjectLoader<Widget>(w)
182 add("position", &Loader::position);
183 add("size", &Loader::size);
184 add("style", &Loader::style);
185 add("visible", &Widget::visible);
188 void Widget::Loader::position(int x, int y)
190 obj.set_position(x, y);
193 void Widget::Loader::size(unsigned w, unsigned h)
198 void Widget::Loader::style(const string &s)