/libmspgltk.a
/libmspgltk.so
/mspgltk.pc
+/widgetdemo
use "mspgltk";
};
+ program "widgetdemo"
+ {
+ source "examples/widgetdemo";
+ require "sigc++-2.0";
+ use "mspgltk";
+ };
+
source_tarball
{
source "License.txt";
//margin { right 1; top 1; bottom 1; };
};
- part "selection"
+ part "items"
{
- graphic NORMAL "blue_flat";
margin { left 3; right 14; top 3; bottom 3; };
};
+};
- part "items"
+style "listitem"
+{
+ part
{
- margin { left 3; right 14; top 3; bottom 3; };
+ graphic ACTIVE "blue_flat";
};
+
+ part "children";
};
graphic "grey_raised_divided"
--- /dev/null
+#include <msp/gltk/button.h>
+#include <msp/gltk/label.h>
+#include <msp/strings/format.h>
+#include "buttondemo.h"
+
+using namespace std;
+using namespace Msp;
+
+ButtonDemo::ButtonDemo()
+{
+ set_layout(new GLtk::Layout);
+
+ GLtk::Label *lbl_message = new GLtk::Label;
+ add(*lbl_message);
+
+ vector<GLtk::Button *> buttons;
+ for(unsigned i=0; i<5; ++i)
+ {
+ string text = format("Button %d", i+1);
+ GLtk::Button *btn = new GLtk::Button(text);
+ btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(lbl_message, &GLtk::Label::set_text), text+" was clicked"));
+ buttons.push_back(btn);
+ add(*btn);
+ if(i>0)
+ {
+ layout->add_constraint(*btn, GLtk::Layout::COPY_WIDTH, *buttons[0]);
+ layout->add_constraint(*btn, GLtk::Layout::COPY_HEIGHT, *buttons[0]);
+
+ if(i>=3)
+ {
+ layout->add_constraint(*btn, GLtk::Layout::RIGHT_OF, *buttons[i-1]);
+ layout->add_constraint(*btn, GLtk::Layout::ALIGN_TOP, *buttons[i-1]);
+ }
+ else
+ {
+ layout->add_constraint(*btn, GLtk::Layout::BELOW, *buttons[i-1]);
+ layout->add_constraint(*btn, GLtk::Layout::ALIGN_LEFT, *buttons[i-1]);
+ }
+ }
+ }
+
+ layout->add_constraint(*buttons[0], GLtk::Layout::BELOW, *lbl_message);
+
+ GLtk::Button *btn = new GLtk::Button("A big one");
+ btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(lbl_message, &GLtk::Label::set_text), "The big button was clicked"));
+ buttons.push_back(btn);
+ add(*btn);
+ layout->add_constraint(*btn, GLtk::Layout::ALIGN_TOP, *buttons[0]);
+ layout->add_constraint(*btn, GLtk::Layout::ALIGN_BOTTOM, *buttons[1]);
+ layout->add_constraint(*btn, GLtk::Layout::ALIGN_LEFT, *buttons[3]);
+ layout->add_constraint(*btn, GLtk::Layout::ALIGN_RIGHT, *buttons[4]);
+}
--- /dev/null
+#ifndef BUTTONDEMO_H_
+#define BUTTONDEMO_H_
+
+#include <msp/gltk/panel.h>
+
+class ButtonDemo: public Msp::GLtk::Panel
+{
+public:
+ ButtonDemo();
+};
+
+#endif
--- /dev/null
+#include <msp/gltk/column.h>
+#include <msp/gltk/label.h>
+#include "demoselector.h"
+
+using namespace std;
+using namespace Msp;
+
+DemoSelector::DemoSelector():
+ demos(&get_demo_title),
+ current_demo(0)
+{
+ set_layout(new GLtk::Layout);
+ layout->set_margin(GLtk::Sides(8));
+
+ GLtk::Column col(*layout);
+
+ GLtk::Label *lbl = new GLtk::Label("Select a widget:");
+ add(*lbl);
+
+ list.set_data(demos);
+ list.signal_item_selected.connect(sigc::mem_fun(this, &DemoSelector::item_selected));
+ add(list);
+ layout->set_expand(list, true, true);
+}
+
+void DemoSelector::add_demo(const string &t, GLtk::Panel *p)
+{
+ Demo demo;
+ demo.title = t;
+ demo.panel = p;
+ demos.append(demo);
+}
+
+void DemoSelector::item_selected(unsigned i)
+{
+ if(current_demo)
+ current_demo->panel->set_visible(false);
+ current_demo = &demos.get(i);
+ current_demo->panel->set_visible(true);
+}
+
+string DemoSelector::get_demo_title(const Demo &demo)
+{
+ return demo.title;
+}
--- /dev/null
+#ifndef DEMOSELECTOR_H_
+#define DEMOSELECTOR_H_
+
+#include <msp/gltk/list.h>
+#include <msp/gltk/panel.h>
+
+class DemoSelector: public Msp::GLtk::Panel
+{
+private:
+ struct Demo
+ {
+ std::string title;
+ Msp::GLtk::Panel *panel;
+ };
+
+ Msp::GLtk::List list;
+ Msp::GLtk::FunctionListData<Demo> demos;
+ const Demo *current_demo;
+
+public:
+ DemoSelector();
+
+ void add_demo(const std::string &, Msp::GLtk::Panel *);
+private:
+ void item_selected(unsigned);
+
+ static std::string get_demo_title(const Demo &);
+};
+
+#endif
--- /dev/null
+#include <msp/gltk/dropdown.h>
+#include <msp/strings/format.h>
+#include "dropdowndemo.h"
+
+using namespace std;
+using namespace Msp;
+
+DropdownDemo::DropdownDemo()
+{
+ set_layout(new GLtk::Layout);
+
+ GLtk::Dropdown *drp = new GLtk::Dropdown(categories);
+ drp->signal_item_selected.connect(sigc::mem_fun(this, &DropdownDemo::category_selected));
+ add(*drp);
+
+ categories.append("Arabic numerals");
+ categories.append("Roman numerals");
+ categories.append("Lowercase letters");
+ categories.append("Uppercase letters");
+
+ GLtk::Widget *prev = drp;
+ drp = new GLtk::Dropdown(values);
+ add(*drp);
+
+ layout->add_constraint(*drp, GLtk::Layout::BELOW, *prev);
+ layout->add_constraint(*drp, GLtk::Layout::ALIGN_LEFT, *prev);
+ layout->add_constraint(*drp, GLtk::Layout::ALIGN_RIGHT, *prev);
+}
+
+void DropdownDemo::category_selected(unsigned i)
+{
+ values.clear();
+ if(i==0)
+ {
+ for(unsigned j=0; j<=26; ++j)
+ values.append(format("%d", j));
+ }
+ else if(i==1)
+ {
+ for(unsigned j=1; j<=26; ++j)
+ {
+ string r = string(j/10, 'X');
+ if(j%10==9)
+ r += "IX";
+ else if(j%10>=4)
+ {
+ if(j%10==4)
+ r += 'I';
+ r += 'V';
+ }
+
+ if(j%5<=3)
+ r += string(j%5, 'I');
+
+ values.append(r);
+ }
+ }
+ else if(i==2)
+ {
+ for(unsigned j=0; j<26; ++j)
+ values.append(string(1, 'a'+j));
+ }
+ else if(i==3)
+ {
+ for(unsigned j=0; j<26; ++j)
+ values.append(string(1, 'A'+j));
+ }
+}
--- /dev/null
+#ifndef DROPDOWNDEMO_H_
+#define DROPDOWNDEMO_H_
+
+#include <msp/gltk/listdata.h>
+#include <msp/gltk/panel.h>
+
+class DropdownDemo: public Msp::GLtk::Panel
+{
+private:
+ Msp::GLtk::BasicListData<std::string> categories;
+ Msp::GLtk::BasicListData<std::string> values;
+
+public:
+ DropdownDemo();
+
+private:
+ void category_selected(unsigned);
+};
+
+#endif
--- /dev/null
+#include <msp/gltk/entry.h>
+#include <msp/gltk/label.h>
+#include "entrydemo.h"
+
+using namespace Msp;
+
+EntryDemo::EntryDemo()
+{
+ set_layout(new GLtk::Layout);
+
+ GLtk::Label *lbl = new GLtk::Label("Single-line entries:");
+ add(*lbl);
+
+ GLtk::Widget *prev = lbl;
+ for(unsigned i=0; i<2; ++i)
+ {
+ GLtk::Entry *ent = new GLtk::Entry;
+ ent->set_edit_size(20+i*40, 1);
+ add(*ent);
+ layout->add_constraint(*ent, GLtk::Layout::BELOW, *prev);
+ prev = ent;
+ }
+
+ lbl = new GLtk::Label("Multi-line entry:");
+ add(*lbl);
+ layout->add_constraint(*lbl, GLtk::Layout::BELOW, *prev);
+ prev = lbl;
+
+ GLtk::Entry *ent = new GLtk::Entry;
+ ent->set_multiline(true);
+ ent->set_edit_size(60, 5);
+ add(*ent);
+ layout->add_constraint(*ent, GLtk::Layout::BELOW, *prev);
+}
--- /dev/null
+#ifndef ENTRYDEMO_H_
+#define ENTRYDEMO_H_
+
+#include <msp/gltk/panel.h>
+
+class EntryDemo: public Msp::GLtk::Panel
+{
+public:
+ EntryDemo();
+};
+
+#endif
--- /dev/null
+#include <msp/gltk/label.h>
+#include <msp/gltk/toggle.h>
+#include <msp/strings/format.h>
+#include "toggledemo.h"
+
+using namespace Msp;
+
+ToggleDemo::ToggleDemo()
+{
+ set_layout(new GLtk::Layout);
+
+ GLtk::Label *lbl = new GLtk::Label("Standalone toggles:");
+ add(*lbl);
+
+ GLtk::Widget *prev = lbl;
+ for(unsigned i=0; i<4; ++i)
+ {
+ GLtk::Toggle *tgl = new GLtk::Toggle(format("Toggle %d", i+1));
+ add(*tgl);
+
+ layout->add_constraint(*tgl, GLtk::Layout::BELOW, *prev);
+ layout->add_constraint(*tgl, GLtk::Layout::ALIGN_LEFT, *prev);
+ layout->add_constraint(*tgl, GLtk::Layout::ALIGN_RIGHT, *prev);
+
+ prev = tgl;
+ }
+
+ for(unsigned i=0; i<2; ++i)
+ {
+ GLtk::Panel *group = new GLtk::Panel;
+ add(*group);
+ layout->add_constraint(*group, (i==0 ? GLtk::Layout::BELOW : GLtk::Layout::RIGHT_OF), *prev);
+ if(i>0)
+ layout->add_constraint(*group, GLtk::Layout::ALIGN_TOP, *prev);
+ group->set_layout(new GLtk::Layout);
+
+ lbl = new GLtk::Label(format("Group %d:", i+1));
+ group->add(*lbl);
+
+ prev = lbl;
+ for(unsigned j=0; j<4; ++j)
+ {
+ GLtk::Toggle *tgl = new GLtk::Toggle(format("Option %d", j+1));
+ tgl->set_style("option");
+ tgl->set_exclusive(true);
+ group->add(*tgl);
+
+ group->get_layout()->add_constraint(*tgl, GLtk::Layout::BELOW, *prev);
+ group->get_layout()->add_constraint(*tgl, GLtk::Layout::ALIGN_LEFT, *prev);
+ group->get_layout()->add_constraint(*tgl, GLtk::Layout::ALIGN_RIGHT, *prev);
+
+ prev = tgl;
+ }
+
+ prev = group;
+ }
+}
--- /dev/null
+#ifndef TOGGLEDEMO_H_
+#define TOGGLEDEMO_H_
+
+#include <msp/gltk/panel.h>
+
+class ToggleDemo: public Msp::GLtk::Panel
+{
+private:
+public:
+ ToggleDemo();
+};
+
+#endif
--- /dev/null
+#include <msp/gl/framebuffer.h>
+#include <msp/gltk/layout.h>
+#include "buttondemo.h"
+#include "dropdowndemo.h"
+#include "entrydemo.h"
+#include "toggledemo.h"
+#include "widgetdemo.h"
+
+using namespace std;
+using namespace Msp;
+
+WidgetDemo::WidgetDemo(int, char **):
+ window(800, 600),
+ 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);
+
+ root.add(selector);
+ root.get_layout()->set_expand(selector, false, true);
+
+ add_demo("Button", new ButtonDemo);
+ add_demo("Dropdown", new DropdownDemo);
+ add_demo("Entry", new EntryDemo);
+ add_demo("Toggle", new ToggleDemo);
+}
+
+int WidgetDemo::main()
+{
+ window.show();
+ return Application::main();
+}
+
+void WidgetDemo::tick()
+{
+ window.tick();
+ GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT);
+ root.render();
+ window.swap_buffers();
+}
+
+void WidgetDemo::add_demo(const string &title, GLtk::Panel *demo)
+{
+ 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);
+
+ selector.add_demo(title, demo);
+}
--- /dev/null
+#ifndef WIDGETDEMO_H_
+#define WIDGETDEMO_H_
+
+#include <msp/core/application.h>
+#include <msp/gltk/resources.h>
+#include <msp/gltk/root.h>
+#include <msp/graphics/simplewindow.h>
+#include "demoselector.h"
+
+class WidgetDemo: public Msp::RegisteredApplication<WidgetDemo>
+{
+private:
+ Msp::Graphics::SimpleGLWindow window;
+ Msp::GLtk::Resources resources;
+ Msp::GLtk::Root root;
+ DemoSelector selector;
+
+public:
+ WidgetDemo(int, char **);
+
+ virtual int main();
+private:
+ virtual void tick();
+
+ void add_demo(const std::string &, Msp::GLtk::Panel *);
+};
+
+#endif