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"
34 Container *p = parent;
40 void Widget::set_position(int x, int y)
47 void Widget::set_size(unsigned w, unsigned h)
54 void Widget::autosize()
58 const Style::PartSeq &parts = style->get_parts();
59 for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
60 if(i->get_name().empty())
62 geom.w = max(geom.w, i->get_geometry().w);
63 geom.h = max(geom.h, i->get_geometry().h);
67 void Widget::set_geometry(const Geometry &g)
73 void Widget::set_parent(Container *p)
76 throw InvalidState("Widget is already in a Container");
85 void Widget::set_style(const string &s)
91 void Widget::update_style()
94 for(top=this; top->parent; top=top->parent) ;
95 Root *root = dynamic_cast<Root *>(top);
100 string sname = get_class();
101 if(!style_name.empty())
107 style = root->get_resources().get<Style>(sname);
111 signal_autosize_changed.emit();
114 void Widget::set_tooltip(const string &t)
119 void Widget::set_visible(bool v)
126 signal_visibility_changed.emit(visible);
129 void Widget::set_focusable(bool f)
134 void Widget::set_focus()
137 throw InvalidState("No parent");
139 throw InvalidState("Can't set focus on invisible widget");
141 signal_request_focus.emit();
144 void Widget::render() const
147 throw InvalidState(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
150 GL::translate(geom.x, geom.y, 0);
151 const Style::PartSeq &parts = style->get_parts();
152 for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
154 if(i->get_name().empty())
156 GL::PushMatrix push_;
157 i->render(geom, state);
165 void Widget::pointer_enter()
170 void Widget::pointer_leave()
175 void Widget::focus_in()
180 void Widget::focus_out()
186 Widget::Loader::Loader(Widget &w):
187 DataFile::ObjectLoader<Widget>(w)
189 add("position", &Loader::position);
190 add("size", &Loader::size);
191 add("style", &Loader::style);
192 add("visible", &Widget::visible);
195 void Widget::Loader::position(int x, int y)
197 obj.set_position(x, y);
200 void Widget::Loader::size(unsigned w, unsigned h)
205 void Widget::Loader::style(const string &s)