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>
11 #include "resources.h"
19 Widget::Widget(const Resources &r):
30 parent->remove(*this);
33 void Widget::set_position(int x, int y)
39 void Widget::set_size(unsigned w, unsigned h)
45 void Widget::set_geometry(const Geometry &g)
50 void Widget::set_style(const string &s)
56 void Widget::render() const
59 throw InvalidState("Attempt to render a widget without a style");
62 GL::translate(geom.x, geom.y, 0);
63 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
68 void Widget::render_part(const Part &part) const
73 void Widget::render_graphic(const Part &part) const
76 part.render(geom, state);
80 void Widget::render_text(const Part &part, const string &text) const
82 const GL::Font *const font=style->get_font();
84 const float font_size=font->get_default_size();
85 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
89 part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
90 GL::scale_uniform(font_size);
92 const GL::Color &color=style->get_font_color();
93 glColor3f(color.r, color.g, color.b);
94 font->draw_string(text);
100 void Widget::update_style()
102 string sname=get_class();
103 if(!style_name.empty())
108 style=res.get<Style>(sname);
111 void Widget::set_parent(Panel *p)
114 throw InvalidState("Widget is already in a Panel");
118 void Widget::set_parent(Widget &w, Panel *p)
124 Widget::Loader::Loader(Widget &w):
127 add("position", &Loader::position);
128 add("size", &Loader::size);
129 add("style", &Loader::style);
130 add("visible", &Widget::visible);
133 void Widget::Loader::position(int x, int y)
135 wdg.set_position(x, y);
138 void Widget::Loader::size(unsigned w, unsigned h)
143 void Widget::Loader::style(const string &s)