1 #include <msp/gl/matrix.h>
2 #include <msp/gl/transform.h>
12 void Widget::set_position(int x, int y)
18 void Widget::set_size(unsigned w, unsigned h)
24 void Widget::set_geometry(const Geometry &g)
29 void Widget::set_style(const string &s)
35 void Widget::render() const
38 throw InvalidState("Attempt to render a widget without a style");
41 GL::translate(geom.x, geom.y, 0);
42 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
47 Widget::Widget(const Resources &r):
53 void Widget::update_style()
55 string sname=get_class();
56 if(!style_name.empty())
61 style=res.get<Style>(sname);
64 void Widget::render_part(const Part &part) const
69 void Widget::render_graphic(const Part &part) const
72 part.render(geom, state);
76 void Widget::render_text(const Part &part, const string &text) const
78 const GL::Font *const font=style->get_font();
80 const float font_size=font->get_default_size();
81 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
85 part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
86 GL::scale_uniform(font_size);
88 const GL::Color &color=style->get_font_color();
89 glColor3f(color.r, color.g, color.b);
90 font->draw_string(text);
97 Widget::Loader::Loader(Widget &w):
100 add("position", &Loader::position);
101 add("size", &Loader::size);
102 add("style", &Loader::style);
105 void Widget::Loader::position(int x, int y)
107 wdg.set_position(x, y);
110 void Widget::Loader::size(unsigned w, unsigned h)
115 void Widget::Loader::style(const string &s)