3 This file is part of libmspgltk
4 Copyright © 2007-2011 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>
12 #include "container.h"
13 #include "resources.h"
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_parent(Container *p)
59 throw InvalidState("Widget is already in a Container");
66 void Widget::set_style(const string &s)
72 void Widget::update_style()
75 for(top=this; top->parent; top=top->parent) ;
76 Root *root = dynamic_cast<Root *>(top);
81 string sname = get_class();
82 if(!style_name.empty())
88 style = root->get_resources().get<Style>(sname);
94 void Widget::set_tooltip(const string &t)
99 void Widget::set_visible(bool v)
106 signal_visibility_changed.emit(visible);
109 void Widget::set_focusable(bool f)
114 void Widget::set_focus()
117 throw InvalidState("No parent");
119 throw InvalidState("Can't set focus on invisible widget");
121 signal_request_focus.emit();
124 void Widget::render() const
127 throw InvalidState(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
130 GL::translate(geom.x, geom.y, 0);
131 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
133 if(i->get_name().empty())
135 GL::PushMatrix push_;
136 i->render(geom, state);
144 void Widget::pointer_enter()
149 void Widget::pointer_leave()
154 void Widget::focus_in()
159 void Widget::focus_out()
165 Widget::Loader::Loader(Widget &w):
168 add("position", &Loader::position);
169 add("size", &Loader::size);
170 add("style", &Loader::style);
171 add("visible", &Widget::visible);
174 void Widget::Loader::position(int x, int y)
176 wdg.set_position(x, y);
179 void Widget::Loader::size(unsigned w, unsigned h)
184 void Widget::Loader::style(const string &s)