]> git.tdb.fi Git - libs/gltk.git/blob - source/panel.cpp
Move all child widget handling into Container
[libs/gltk.git] / source / panel.cpp
1 #include <algorithm>
2 #include <msp/core/refptr.h>
3 #include "button.h"
4 #include "dropdown.h"
5 #include "entry.h"
6 #include "hslider.h"
7 #include "indicator.h"
8 #include "label.h"
9 #include "layout.h"
10 #include "list.h"
11 #include "panel.h"
12 #include "part.h"
13 #include "table.h"
14 #include "toggle.h"
15 #include "vslider.h"
16
17 using namespace std;
18
19 namespace Msp {
20 namespace GLtk {
21
22 Panel::Panel():
23         layout(0)
24 { }
25
26 Panel::~Panel()
27 {
28         delete layout;
29         layout = 0;
30 }
31
32 void Panel::set_layout(Layout *l)
33 {
34         l->set_container(*this);
35         delete layout;
36         layout = l;
37 }
38
39 void Panel::autosize()
40 {
41         if(layout)
42                 layout->autosize();
43 }
44
45 void Panel::render_special(const Part &part, GL::Renderer &renderer) const
46 {
47         if(part.get_name()=="children")
48         {
49                 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
50                         if((*i)->widget->is_visible())
51                                 (*i)->widget->render(renderer);
52         }
53 }
54
55 void Panel::on_geometry_change()
56 {
57         if(layout)
58                 layout->update();
59 }
60
61 void Panel::on_child_added(Widget &wdg)
62 {
63         if(layout)
64         {
65                 layout->add_widget(wdg);
66                 signal_autosize_changed.emit();
67         }
68 }
69
70 void Panel::on_child_removed(Widget &wdg)
71 {
72         if(layout)
73         {
74                 layout->remove_widget(wdg);
75                 signal_autosize_changed.emit();
76         }
77 }
78
79
80 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
81         Widget::Loader(p),
82         pnl(p),
83         wdg_map(m)
84 {
85         add("button",    &Loader::child<Button>);
86         add("dropdown",  &Loader::child<Dropdown>);
87         add("entry",     &Loader::child<Entry>);
88         add("hslider",   &Loader::child<HSlider>);
89         add("indicator", &Loader::child<Indicator>);
90         add("label",     &Loader::child<Label>);
91         add("list",      &Loader::child<List>);
92         add("panel",     &Loader::panel);
93         add("table",     &Loader::child<Table>);
94         add("toggle",    &Loader::child<Toggle>);
95         add("vslider",   &Loader::child<VSlider>);
96 }
97
98 template<typename T>
99 void Panel::Loader::child(const string &n)
100 {
101         RefPtr<T> chl = new T();
102         load_sub(*chl);
103         pnl.add(*chl.get());
104         wdg_map[n] = chl.release();
105 }
106
107 void Panel::Loader::panel(const string &n)
108 {
109         RefPtr<Panel> p = new Panel();
110         load_sub(*p, wdg_map);
111         pnl.add(*p.get());
112         wdg_map[n] = p.release();
113 }
114
115 } // namespace GLtk
116 } // namespace Msp