3 This file is part of libmspgltk
4 Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/immediate.h>
9 #include <msp/gl/matrix.h>
10 #include <msp/gl/transform.h>
11 #include <msp/strings/formatter.h>
13 #include "resources.h"
21 Widget::Widget(const Resources &r):
33 parent->remove(*this);
36 void Widget::set_position(int x, int y)
43 void Widget::set_size(unsigned w, unsigned h)
50 void Widget::set_geometry(const Geometry &g)
56 void Widget::set_style(const string &s)
62 void Widget::set_tooltip(const string &t)
67 void Widget::set_visible(bool v)
74 signal_visibility_changed.emit(visible);
77 void Widget::set_focusable(bool f)
82 void Widget::set_focus()
85 throw InvalidState("No parent");
87 throw InvalidState("Can't set focus on invisible widget");
89 signal_request_focus.emit();
92 void Widget::render() const
95 throw InvalidState(format("Attempt to render a widget without a style (class=\"%s\")", get_class()));
98 GL::translate(geom.x, geom.y, 0);
99 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
101 if(i->get_name().empty())
103 GL::PushMatrix push_;
104 i->render(geom, state);
112 void Widget::pointer_enter()
117 void Widget::pointer_leave()
122 void Widget::focus_in()
127 void Widget::focus_out()
132 void Widget::update_style()
134 string sname=get_class();
135 if(!style_name.empty())
140 style=res.get<Style>(sname);
144 void Widget::set_parent(Container *p)
147 throw InvalidState("Widget is already in a Container");
153 void Widget::set_parent(Widget &w, Container *p)
159 Widget::Loader::Loader(Widget &w):
162 add("position", &Loader::position);
163 add("size", &Loader::size);
164 add("style", &Loader::style);
165 add("visible", &Widget::visible);
168 void Widget::Loader::position(int x, int y)
170 wdg.set_position(x, y);
173 void Widget::Loader::size(unsigned w, unsigned h)
178 void Widget::Loader::style(const string &s)