X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=helloworld.cpp;h=4f85964d9d2c45e28aa90bae843237d92d657d47;hb=f0b600c3b1739f7e088da6ab8eb7c2e67adf592c;hp=95e5f598e077802fd215b4b03dac03e991795c1d;hpb=7fab31cbb378ff8cbd63afad62c6f3b1cb3fd33e;p=libs%2Fgltk.git diff --git a/helloworld.cpp b/helloworld.cpp index 95e5f59..4f85964 100644 --- a/helloworld.cpp +++ b/helloworld.cpp @@ -1,24 +1,12 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - /* A simple graphical Hello World application implemented with mspgltk. Demonstrates some of the most common widget types. */ #include -#include -#include -#include -#include +#include #include #include -#include -#include #include #include #include @@ -29,23 +17,18 @@ Demonstrates some of the most common widget types. using namespace Msp; // Application class. Because it's so much nicer than global variables. -class HelloWorld: public Msp::Application +class HelloWorld: public Msp::RegisteredApplication { private: - // Objects for setting up an OpenGL window - Graphics::Display dpy; - Graphics::Window wnd; - Graphics::GLContext glc; + // An OpenGL window to display our widgets in + Graphics::SimpleGLWindow wnd; // GLtk resources and widgets GLtk::Resources res; - RefPtr root; + GLtk::Root root; GLtk::Entry *ent_name; GLtk::Label *lbl_hello; - // Indicate our main class to the core library - static Application::RegApp reg; - public: HelloWorld(int, char **); private: @@ -53,58 +36,49 @@ private: void show_hello(); }; -Application::RegApp HelloWorld::reg; - HelloWorld::HelloWorld(int, char **): - wnd(dpy, 200, 200), - glc(wnd) + wnd(200, 200), + // Load resources. This must be done before the root widget is created. + res("basic.skin"), + // A Root receives input from a Graphics::Window and passes it on + root(res, wnd) { wnd.set_title("Hello World"); wnd.signal_close.connect(sigc::bind(sigc::mem_fun(this, &HelloWorld::exit), 0)); - // Load resources. This must be done before any widgets are created. - DataFile::load(res, "helloworld.gui"); - - // A Root receives input from a Graphics::Window and passes it on - root=new GLtk::Root(res, wnd); - /* Container widgets will delete their contents upon destruction so we can safely forget about the pointers after setting the widgets up. */ // Panels can be used to divide the window into sub-areas - GLtk::Panel *panel=new GLtk::Panel(res); - root->add(*panel); + GLtk::Panel *panel = new GLtk::Panel; + root.add(*panel); panel->set_geometry(GLtk::Geometry(20, 20, 160, 160)); GLtk::Label *lbl; // Prompts can be displayed with Labels - panel->add(*(lbl=new GLtk::Label(res, "Type your name below:"))); + panel->add(*(lbl = new GLtk::Label("Type your name below:"))); lbl->set_geometry(GLtk::Geometry(10, 130, 140, 20)); // The user can type text into an Entry - panel->add(*(ent_name=new GLtk::Entry(res))); + panel->add(*(ent_name = new GLtk::Entry)); ent_name->set_geometry(GLtk::Geometry(10, 110, 140, 20)); GLtk::Button *btn; // Buttons can be wired to cause things to happen - panel->add(*(btn=new GLtk::Button(res, "Hello"))); + panel->add(*(btn = new GLtk::Button("Hello"))); btn->set_geometry(GLtk::Geometry(10, 85, 140, 20)); btn->signal_clicked.connect(sigc::mem_fun(this, &HelloWorld::show_hello)); // Another label for displaying some information - panel->add(*(lbl_hello=new GLtk::Label(res))); + panel->add(*(lbl_hello = new GLtk::Label)); lbl_hello->set_geometry(GLtk::Geometry(10, 65, 140, 20)); // The user might want to exit the program (*gasp*) - panel->add(*(btn=new GLtk::Button(res, "Exit"))); + panel->add(*(btn = new GLtk::Button("Exit"))); btn->set_geometry(GLtk::Geometry(50, 10, 100, 20)); btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &HelloWorld::exit), 0)); - // Font rendering requires blending - GL::enable(GL::BLEND); - GL::blend_func(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA); - // Done with setting things up, show the window! wnd.show(); } @@ -112,18 +86,18 @@ HelloWorld::HelloWorld(int, char **): // This function will be called periodically from the main loop void HelloWorld::tick() { - dpy.tick(); + wnd.tick(); // Set up an orthogonal projection matching the root widget - GL::matrix_mode(GL::PROJECTION); - GL::load_identity(); - GL::ortho_bottomleft(200, 200); - GL::matrix_mode(GL::MODELVIEW); - GL::load_identity(); + GL::MatrixStack::projection() = GL::Matrix::ortho_bottomleft(200, 200); + GL::MatrixStack::modelview() = GL::Matrix(); + + // Font rendering requires blending + GL::Bind bind_blend(GL::Blend::alpha()); - root->render(); + root.render(); - glc.swap_buffers(); + wnd.swap_buffers(); } // Displays a greeting to the user