1 #include <msp/gl/matrix.h>
2 #include <msp/strings/format.h>
25 Container *p = parent;
31 void Widget::set_position(int x, int y)
39 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)
67 void Widget::set_parent(Container *p)
70 throw hierarchy_error("widget already parented");
79 void Widget::set_style(const string &s)
85 void Widget::update_style()
88 for(top=this; top->parent; top=top->parent) ;
89 Root *root = dynamic_cast<Root *>(top);
94 string sname = get_class();
95 if(!style_name.empty())
101 style = &root->get_resources().get<Style>(sname);
105 signal_autosize_changed.emit();
109 void Widget::set_tooltip(const string &t)
114 void Widget::set_visible(bool v)
121 signal_visibility_changed.emit(visible);
124 void Widget::set_focusable(bool f)
129 void Widget::set_focus()
132 throw hierarchy_error("no parent");
134 throw logic_error("!visible");
136 signal_request_focus.emit();
139 void Widget::set_state(State mask, State bits)
141 state = (state&~mask)|bits;
145 void Widget::rebuild()
150 const Style::PartSeq &parts = style->get_parts();
151 list<CachedPart>::iterator j = cached_parts.begin();
152 for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i, ++j)
154 if(j==cached_parts.end())
155 j = cached_parts.insert(j, CachedPart());
156 if(i->get_name().empty())
157 i->build(geom, state, *j);
159 rebuild_special(*i, *j);
163 void Widget::render(GL::Renderer &renderer) const
166 throw logic_error(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
168 GL::MatrixStack::Push _pushm(renderer.matrix_stack());
169 renderer.matrix_stack() *= GL::Matrix::translation(geom.x, geom.y, 0);
170 const Style::PartSeq &parts = style->get_parts();
171 list<CachedPart>::const_iterator j = cached_parts.begin();
172 for(Style::PartSeq::const_iterator i=parts.begin(); (i!=parts.end() && j!=cached_parts.end()); ++i, ++j)
174 if(j->mesh && j->texture)
176 renderer.set_texture(j->texture);
177 j->mesh->draw(renderer);
179 else if(!i->get_name().empty())
180 render_special(*i, renderer);
184 void Widget::pointer_enter()
189 void Widget::pointer_leave()
194 void Widget::focus_in()
199 void Widget::focus_out()
205 Widget::Loader::Loader(Widget &w):
206 DataFile::ObjectLoader<Widget>(w)
208 add("position", &Loader::position);
209 add("size", &Loader::size);
210 add("style", &Loader::style);
211 add("visible", &Widget::visible);
214 void Widget::Loader::position(int x, int y)
216 obj.set_position(x, y);
219 void Widget::Loader::size(unsigned w, unsigned h)
224 void Widget::Loader::style(const string &s)