]> git.tdb.fi Git - libs/gltk.git/blob - examples/widgetdemo/widgetdemo.cpp
52545a2b2b86c1f099a2a3bc96ff4cbb43d801cd
[libs/gltk.git] / examples / widgetdemo / widgetdemo.cpp
1 #include <msp/gl/framebuffer.h>
2 #include <msp/gltk/layout.h>
3 #include "buttondemo.h"
4 #include "dropdowndemo.h"
5 #include "entrydemo.h"
6 #include "toggledemo.h"
7 #include "widgetdemo.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 WidgetDemo::WidgetDemo(int, char **):
13         window(800, 600),
14         gl_device(window),
15         view(window),
16         resources("basic.skin"),
17         root(resources, window)
18 {
19         window.set_title("GLtk widget demo");
20         window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &WidgetDemo::exit), 0));
21
22         GLtk::Layout &root_layout = root.get_or_create_layout();
23
24         root.add(selector);
25         root_layout.set_expand(selector, false, true);
26
27         add_demo("Button", new ButtonDemo);
28         add_demo("Dropdown", new DropdownDemo);
29         add_demo("Entry", new EntryDemo);
30         add_demo("Toggle", new ToggleDemo);
31
32         view.set_content(&root);
33 }
34
35 int WidgetDemo::main()
36 {
37         window.show();
38         return Application::main();
39 }
40
41 void WidgetDemo::tick()
42 {
43         window.tick();
44         view.render();
45 }
46
47 void WidgetDemo::add_demo(const string &title, GLtk::Panel *demo)
48 {
49         GLtk::Layout &root_layout = root.get_or_create_layout();
50
51         demo->set_visible(false);
52         root.add(*demo);
53         root_layout.add_constraint(*demo, GLtk::Layout::RIGHT_OF, selector);
54         root_layout.set_expand(*demo, true, true);
55
56         selector.add_demo(title, demo);
57 }