]> git.tdb.fi Git - libs/gltk.git/blob - examples/widgetdemo/widgetdemo.cpp
fd52bf61f2d23098fcec77afa4a98a2872d0be3d
[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         resources("basic.skin"),
15         root(resources, window)
16 {
17         window.set_title("GLtk widget demo");
18         window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &WidgetDemo::exit), 0));
19
20         root.set_layout(new GLtk::Layout);
21
22         root.add(selector);
23         root.get_layout()->set_expand(selector, false, true);
24
25         add_demo("Button", new ButtonDemo);
26         add_demo("Dropdown", new DropdownDemo);
27         add_demo("Entry", new EntryDemo);
28         add_demo("Toggle", new ToggleDemo);
29 }
30
31 int WidgetDemo::main()
32 {
33         window.show();
34         return Application::main();
35 }
36
37 void WidgetDemo::tick()
38 {
39         window.tick();
40         GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT);
41         root.render();
42         window.swap_buffers();
43 }
44
45 void WidgetDemo::add_demo(const string &title, GLtk::Panel *demo)
46 {
47         demo->set_visible(false);
48         root.add(*demo);
49         root.get_layout()->add_constraint(*demo, GLtk::Layout::RIGHT_OF, selector);
50         root.get_layout()->set_expand(*demo, true, true);
51
52         selector.add_demo(title, demo);
53 }