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):
32 parent->remove(*this);
35 void Widget::set_position(int x, int y)
42 void Widget::set_size(unsigned w, unsigned h)
49 void Widget::set_geometry(const Geometry &g)
55 void Widget::set_style(const string &s)
61 void Widget::set_tooltip(const string &t)
66 void Widget::set_visible(bool v)
73 signal_visibility_changed.emit(visible);
76 void Widget::set_focus()
79 throw InvalidState("No parent");
81 throw InvalidState("Can't set focus on invisible widget");
83 signal_request_focus.emit();
86 void Widget::render() const
89 throw InvalidState(format("Attempt to render a widget without a style (class=\"%s\")", get_class()));
92 GL::translate(geom.x, geom.y, 0);
93 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
95 if(i->get_name().empty())
98 i->render(geom, state);
106 void Widget::pointer_enter()
111 void Widget::pointer_leave()
116 void Widget::focus_in()
121 void Widget::focus_out()
126 void Widget::update_style()
128 string sname=get_class();
129 if(!style_name.empty())
134 style=res.get<Style>(sname);
138 void Widget::set_parent(Container *p)
141 throw InvalidState("Widget is already in a Container");
147 void Widget::set_parent(Widget &w, Container *p)
153 Widget::Loader::Loader(Widget &w):
156 add("position", &Loader::position);
157 add("size", &Loader::size);
158 add("style", &Loader::style);
159 add("visible", &Widget::visible);
162 void Widget::Loader::position(int x, int y)
164 wdg.set_position(x, y);
167 void Widget::Loader::size(unsigned w, unsigned h)
172 void Widget::Loader::style(const string &s)