GG
|
This is an abstract singleton class that represents the GUI framework of an SDL OpenGL application. More...
#include <SDLGUI.h>
Static Public Member Functions | |
static SDLGUI * | GetGUI () |
static GG::Key | GGKeyFromSDLKey (const SDL_keysym &key) |
Protected Member Functions | |
virtual void | SDLInit () |
virtual void | GLInit () |
virtual void | Initialize ()=0 |
virtual void | HandleSystemEvents () |
virtual void | HandleNonGGEvent (const SDL_Event &event) |
virtual void | RenderBegin () |
virtual void | RenderEnd () |
virtual void | FinalCleanup () |
virtual void | SDLQuit () |
virtual void | Run () |
Structors | |
SDLGUI (int w=1024, int h=768, bool calc_FPS=false, const std::string &app_name="GG") | |
virtual | ~SDLGUI () |
Accessors | |
virtual X | AppWidth () const |
virtual Y | AppHeight () const |
virtual unsigned int | Ticks () const |
Mutators | |
void | operator() () |
virtual void | Exit (int code) |
virtual void | Enter2DMode ()=0 |
virtual void | Exit2DMode ()=0 |
This is an abstract singleton class that represents the GUI framework of an SDL OpenGL application.
Usage:
Any application including an object of this class should declare that object as a local variable in main(). The name of this variable will herein be assumed to be "gui". It should be allocated on the stack; if it is created dynamically a leak may occur. SDLGUI is designed so the main() of the application can consist of just the one line "gui();".
To do this, the user needs only to override the Initialize() and FinalCleanup() methods, and ensure that the program does not terminate abnormally; this ensures FinalCleanup() is called when gui's destructor is invoked. Exit() can also perform cleanup and terminate the application cleanly.
Most of the member methods of SDLGUI have been declared virtual, to give the user great control when subclassing. The virtual function calls are usually not a performance issue, since none of the methods is called repeatedly, except HandleEvent(); if this is a problem, just create a new function in your subclass and call that from within Run() instead of HandleEvent(). Note that though the bulk of the program execution takes place within Run(), Run() itself is also only called once.
SDLGUI takes a two-tiered approach to event handling. The event pump calls HandleSystemEvents(), which polls for SDL events and handles them by first determining whether the event is GG-related, or some other non-GG event, such as SDL_QUIT, etc. GG events and non-GG events are passed to HandleGGEvent() and HandleNonGGEvent(), respectively. For most uses, there should be no need to override the behavior of HandleSDLEvents(). However, the HandleNonGGEvent() default implementation only responds to SDL_QUIT events, and so should be overridden in most cases.
virtual void GG::SDLGUI::HandleSystemEvents | ( | ) | [protected, virtual] |