3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/matrix.h>
9 #include <msp/gl/transform.h>
10 #include "resources.h"
18 Widget::Widget(const Resources &r):
25 void Widget::set_position(int x, int y)
31 void Widget::set_size(unsigned w, unsigned h)
37 void Widget::set_geometry(const Geometry &g)
42 void Widget::set_style(const string &s)
48 void Widget::render() const
51 throw InvalidState("Attempt to render a widget without a style");
54 GL::translate(geom.x, geom.y, 0);
55 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
60 void Widget::render_part(const Part &part) const
65 void Widget::render_graphic(const Part &part) const
68 part.render(geom, state);
72 void Widget::render_text(const Part &part, const string &text) const
74 const GL::Font *const font=style->get_font();
76 const float font_size=font->get_default_size();
77 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
81 part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
82 GL::scale_uniform(font_size);
84 const GL::Color &color=style->get_font_color();
85 glColor3f(color.r, color.g, color.b);
86 font->draw_string(text);
92 void Widget::update_style()
94 string sname=get_class();
95 if(!style_name.empty())
100 style=res.get<Style>(sname);
104 Widget::Loader::Loader(Widget &w):
107 add("position", &Loader::position);
108 add("size", &Loader::size);
109 add("style", &Loader::style);
110 add("visible", &Widget::visible);
113 void Widget::Loader::position(int x, int y)
115 wdg.set_position(x, y);
118 void Widget::Loader::size(unsigned w, unsigned h)
123 void Widget::Loader::style(const string &s)