2 A simple graphical Hello World application implemented with mspgltk.
3 Demonstrates some of the most common widget types.
6 #include <msp/core/application.h>
7 #include <msp/graphics/simplewindow.h>
8 #include <msp/gl/blend.h>
9 #include <msp/gl/device.h>
10 #include <msp/gl/matrix.h>
11 #include <msp/gl/windowview.h>
12 #include <msp/gltk/button.h>
13 #include <msp/gltk/entry.h>
14 #include <msp/gltk/label.h>
15 #include <msp/gltk/panel.h>
16 #include <msp/gltk/resources.h>
17 #include <msp/gltk/root.h>
21 // Application class. Because it's so much nicer than global variables.
22 class HelloWorld: public Msp::RegisteredApplication<HelloWorld>
25 // A window and graphics device to display our widgets in
26 Graphics::SimpleWindow wnd;
30 // GLtk resources and widgets
33 GLtk::Entry *ent_name;
34 GLtk::Label *lbl_hello;
37 HelloWorld(int, char **);
44 HelloWorld::HelloWorld(int, char **):
48 // Load resources. This must be done before the root widget is created.
50 // A Root receives input from a Graphics::Window and passes it on
53 wnd.set_title("Hello World");
54 wnd.signal_close.connect(sigc::bind(sigc::mem_fun(this, &HelloWorld::exit), 0));
56 /* Container widgets will delete their contents upon destruction so we can
57 safely forget about the pointers after setting the widgets up. */
59 // Panels can be used to divide the window into sub-areas
60 GLtk::Panel *panel = new GLtk::Panel;
62 panel->set_geometry(GLtk::Geometry(20, 20, 160, 160));
65 // Prompts can be displayed with Labels
66 panel->add(*(lbl = new GLtk::Label("Type your name:")));
67 lbl->set_geometry(GLtk::Geometry(10, 130, 140, 20));
69 // The user can type text into an Entry
70 panel->add(*(ent_name = new GLtk::Entry));
71 ent_name->set_geometry(GLtk::Geometry(10, 100, 140, 27));
74 // Buttons can be wired to cause things to happen
75 panel->add(*(btn = new GLtk::Button("Hello")));
76 btn->set_geometry(GLtk::Geometry(10, 68, 140, 27));
77 btn->signal_clicked.connect(sigc::mem_fun(this, &HelloWorld::show_hello));
79 // Another label for displaying some information
80 panel->add(*(lbl_hello = new GLtk::Label));
81 lbl_hello->set_geometry(GLtk::Geometry(10, 42, 140, 20));
83 // The user might want to exit the program (*gasp*)
84 panel->add(*(btn = new GLtk::Button("Exit")));
85 btn->set_geometry(GLtk::Geometry(50, 10, 100, 27));
86 btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &HelloWorld::exit), 0));
88 view.set_content(&root);
90 // Done with setting things up, show the window!
94 // This function will be called periodically from the main loop
95 void HelloWorld::tick()
101 // Displays a greeting to the user
102 void HelloWorld::show_hello()
104 lbl_hello->set_text("Hello, "+ent_name->get_text()+"!");