]> git.tdb.fi Git - libs/gltk.git/commitdiff
Enable loading of widgets from datafiles (not implemented for all widgets yet)
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Oct 2007 06:57:31 +0000 (06:57 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Oct 2007 06:57:31 +0000 (06:57 +0000)
source/label.cpp
source/label.h
source/panel.cpp
source/panel.h
source/root.cpp
source/widget.cpp
source/widget.h

index d0aba354c9555a86485640e6ded619463d4d1b84..9676fa37ab148bfaccb23d1ccc65b38f363d48d7 100644 (file)
@@ -24,5 +24,17 @@ void Label::render_part(const Part &part) const
                Widget::render_part(part);
 }
 
+
+Label::Loader::Loader(Label &l):
+       Widget::Loader(l)
+{
+       add("text", &Label::text);
+}
+
+Label &Label::Loader::get_object()
+{
+       return static_cast<Label &>(wdg);
+}
+
 } // namespace GLtk
 } // namespace Msp
index 3de71b764c3db95d41341a7f630cf1eac0faf5da..8380ef0eaaa8676eca5b348790830690297b4924 100644 (file)
@@ -9,6 +9,13 @@ namespace GLtk {
 class Label: public Widget
 {
 public:
+       class Loader: public Widget::Loader
+       {
+       public:
+               Loader(Label &);
+               Label &get_object();
+       };
+
        Label(const Resources &, const std::string & =std::string());
        void set_text(const std::string &);
 private:
index d3e8df0c374c0f190e4da38ffb50617a588613a4..c93d430be07f16a988fa1a120af013104cd8889e 100644 (file)
@@ -1,6 +1,10 @@
+#include <msp/core/refptr.h>
+#include "label.h"
 #include "panel.h"
 #include "part.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GLtk {
 
@@ -142,5 +146,23 @@ void Panel::set_input_focus(Widget *wdg)
        }
 }
 
+
+Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
+       Widget::Loader(p),
+       panel(p),
+       wdg_map(m)
+{
+       add("label", &Loader::child<Label>);
+}
+
+template<typename T>
+void Panel::Loader::child(const string &n)
+{
+       RefPtr<T> chl=new T(panel.res);
+       load_sub(*chl);
+       panel.add(*chl.get());
+       wdg_map[n]=chl.release();
+}
+
 } // namespace GLtk
 } // namespace Msp
index 2fa7d8f88944480757d1676eeb8ac18a514503d5..bf17829c101449747c07a23d61170811dcb08d4c 100644 (file)
@@ -9,6 +9,19 @@ namespace GLtk {
 class Panel: public Widget
 {
 public:
+       class Loader: public Widget::Loader
+       {
+       private:
+               Panel &panel;
+               std::map<std::string, Widget *> &wdg_map;
+       
+       public:
+               Loader(Panel &, std::map<std::string, Widget *> &);
+       private:
+               template<typename T>
+               void child(const std::string &);
+       };
+
        Panel(const Resources &);
        ~Panel();
 
index f8a4d9f76dcf0ef920fad27bae6f8a9d222d6a99..83042a63f3c8a62339d40b7ae5708306fef398da 100644 (file)
@@ -9,10 +9,27 @@ Root::Root(Resources &r, Window &w):
 {
        set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
 
+       update_style();
+
        window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
        window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
        window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
 }
 
+void Root::button_press_event(int x, int y, unsigned btn, unsigned)
+{
+       button_press(x, y, btn);
+}
+
+void Root::button_release_event(int x, int y, unsigned btn, unsigned)
+{
+       button_release(x, y, btn);
+}
+
+void Root::pointer_motion_event(int x, int y)
+{
+       pointer_motion(x, y);
+}
+
 } // namespace GLtk
 } // namespace Msp
index d1f21bc9408113c1d65fb78ca711d1f5d51f6adf..f03ed39652f5d56f416f28707674a9a8da5d3f54 100644 (file)
@@ -93,5 +93,29 @@ 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);
+}
+
+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
index 47bc41096de58db1b43ada855d63875c83103ea1..79187f3b5e864bf40b77fdab827b93e676c3d38a 100644 (file)
@@ -15,6 +15,19 @@ class Style;
 class Widget
 {
 public:
+       class Loader: public Msp::DataFile::Loader
+       {
+       protected:
+               Widget &wdg;
+
+       public:
+               Loader(Widget &);
+       private:
+               void position(int, int);
+               void size(unsigned, unsigned);
+               void style(const std::string &);
+       };
+
        virtual ~Widget() { }
        void set_position(int, int);
        void set_size(unsigned, unsigned);