]> git.tdb.fi Git - libs/gltk.git/blobdiff - examples/widgetdemo/widgetdemo.cpp
Add an example of dialogs in the widget demo program
[libs/gltk.git] / examples / widgetdemo / widgetdemo.cpp
index fd52bf61f2d23098fcec77afa4a98a2872d0be3d..b1482e72ae93f10c9652f5cadacdc954e6afbaae 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/gl/framebuffer.h>
 #include <msp/gltk/layout.h>
 #include "buttondemo.h"
+#include "dialogdemo.h"
 #include "dropdowndemo.h"
 #include "entrydemo.h"
 #include "toggledemo.h"
@@ -11,21 +12,26 @@ using namespace Msp;
 
 WidgetDemo::WidgetDemo(int, char **):
        window(800, 600),
+       gl_device(window),
+       view(window),
        resources("basic.skin"),
        root(resources, window)
 {
        window.set_title("GLtk widget demo");
        window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &WidgetDemo::exit), 0));
 
-       root.set_layout(new GLtk::Layout);
+       GLtk::Layout &root_layout = root.get_or_create_layout();
 
        root.add(selector);
-       root.get_layout()->set_expand(selector, false, true);
+       root_layout.set_expand(selector, false, true);
 
        add_demo("Button", new ButtonDemo);
+       add_demo("Dialog", new DialogDemo);
        add_demo("Dropdown", new DropdownDemo);
        add_demo("Entry", new EntryDemo);
        add_demo("Toggle", new ToggleDemo);
+
+       view.set_content(&root);
 }
 
 int WidgetDemo::main()
@@ -37,17 +43,17 @@ int WidgetDemo::main()
 void WidgetDemo::tick()
 {
        window.tick();
-       GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT);
-       root.render();
-       window.swap_buffers();
+       view.render();
 }
 
 void WidgetDemo::add_demo(const string &title, GLtk::Panel *demo)
 {
+       GLtk::Layout &root_layout = root.get_or_create_layout();
+
        demo->set_visible(false);
        root.add(*demo);
-       root.get_layout()->add_constraint(*demo, GLtk::Layout::RIGHT_OF, selector);
-       root.get_layout()->set_expand(*demo, true, true);
+       root_layout.add_constraint(*demo, GLtk::Layout::RIGHT_OF, selector);
+       root_layout.set_expand(*demo, true, true);
 
        selector.add_demo(title, demo);
 }