]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Support loading Buttons from datafiles
[libs/gltk.git] / source / widget.cpp
index 7f153eb5540e4462bfa57645fab2b113cfb06a8b..e1538dec221bedc9a190c5904421ce6e1d16d87c 100644 (file)
@@ -47,12 +47,19 @@ void Widget::render() const
 Widget::Widget(const Resources &r):
        res(r),
        style(0),
-       state(NORMAL)
+       state(NORMAL),
+       visible(true)
 { }
 
 void Widget::update_style()
 {
-       style=&res.get_style(get_class(), style_name);
+       string sname=get_class();
+       if(!style_name.empty())
+       {
+               sname+='-';
+               sname+=style_name;
+       }
+       style=res.get<Style>(sname);
 }
 
 void Widget::render_part(const Part &part) const
@@ -79,7 +86,7 @@ void Widget::render_text(const Part &part, const string &text) const
        part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
        GL::scale_uniform(font_size);
 
-       const Color &color=style->get_font_color();
+       const GL::Color &color=style->get_font_color();
        glColor3f(color.r, color.g, color.b);
        font->draw_string(text);
        glColor3f(1, 1, 1);
@@ -87,5 +94,30 @@ void Widget::render_text(const Part &part, const string &text) const
        GL::pop_matrix();
 }
 
+
+Widget::Loader::Loader(Widget &w):
+       wdg(w)
+{
+       add("position", &Loader::position);
+       add("size",     &Loader::size);
+       add("style",    &Loader::style);
+       add("visible",  &Widget::visible);
+}
+
+void Widget::Loader::position(int x, int y)
+{
+       wdg.set_position(x, y);
+}
+
+void Widget::Loader::size(unsigned w, unsigned h)
+{
+       wdg.set_size(w, h);
+}
+
+void Widget::Loader::style(const string &s)
+{
+       wdg.set_style(s);
+}
+
 } // namespace GLtk
 } // namespace Msp