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 bool Widget::button_press(int x, int y, unsigned btn)
49 if(x>=geom.x && y>=geom.y && x<geom.x+static_cast<int>(geom.w) && y<geom.y+static_cast<int>(geom.h))
51 on_button_press(x, y, btn);
58 bool Widget::button_release(int x, int y, unsigned btn)
60 if(x>=geom.x && y>=geom.y && x<geom.x+static_cast<int>(geom.w) && y<geom.y+static_cast<int>(geom.h))
62 on_button_release(x, y, btn);
69 Widget::Widget(const Resources &r):
75 void Widget::update_style()
77 style=&res.get_style(get_class(), style_name);
80 void Widget::render_part(const Part &part) const
85 void Widget::render_graphic(const Part &part) const
88 part.render(geom, state);
92 void Widget::render_text(const Part &part, const string &text) const
94 const GL::Font *const font=style->get_font();
96 const float font_size=font->get_default_size();
97 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
101 part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font_size));
102 GL::scale_uniform(font_size);
104 const Color &color=style->get_font_color();
105 glColor3f(color.r, color.g, color.b);
106 font->draw_string(text);