#include <SDLGUI.h>
Inheritance diagram for GG::SDLGUI:
Structors | |
SDLGUI (int w=1024, int h=768, bool calc_FPS=false, const std::string &app_name="GG") | |
Accessors | |
virtual int | AppWidth () const |
virtual int | AppHeight () const |
virtual int | Ticks () const |
Mutators | |
void | operator() () |
virtual void | Exit (int code) |
virtual void | Enter2DMode ()=0 |
virtual void | Exit2DMode ()=0 |
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 () |
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.
Definition at line 74 of file SDLGUI.h.
GG::SDLGUI::SDLGUI | ( | int | w = 1024 , |
|
int | h = 768 , |
|||
bool | calc_FPS = false , |
|||
const std::string & | app_name = "GG" | |||
) | [explicit] |
ctor
virtual int GG::SDLGUI::AppWidth | ( | ) | const [virtual] |
virtual int GG::SDLGUI::AppHeight | ( | ) | const [virtual] |
virtual int GG::SDLGUI::Ticks | ( | ) | const [virtual] |
virtual void GG::SDLGUI::Exit | ( | int | code | ) | [virtual] |
virtual void GG::SDLGUI::Enter2DMode | ( | ) | [pure virtual] |
virtual void GG::SDLGUI::Exit2DMode | ( | ) | [pure virtual] |
static SDLGUI* GG::SDLGUI::GetGUI | ( | ) | [static] |
static GG::Key GG::SDLGUI::GGKeyFromSDLKey | ( | const SDL_keysym & | key | ) | [static] |
gives the GGKey equivalent of key
virtual void GG::SDLGUI::SDLInit | ( | ) | [protected, virtual] |
initializes SDL, FE, and SDL OpenGL functionality
virtual void GG::SDLGUI::GLInit | ( | ) | [protected, virtual] |
allows user to specify OpenGL initialization code; called at the end of SDLInit()
virtual void GG::SDLGUI::Initialize | ( | ) | [protected, pure virtual] |
provides one-time gui initialization
virtual void GG::SDLGUI::HandleSystemEvents | ( | ) | [protected, virtual] |
virtual void GG::SDLGUI::HandleNonGGEvent | ( | const SDL_Event & | event | ) | [protected, virtual] |
event handler for all SDL events that are not GG-related
virtual void GG::SDLGUI::RenderBegin | ( | ) | [protected, virtual] |
virtual void GG::SDLGUI::RenderEnd | ( | ) | [protected, virtual] |
virtual void GG::SDLGUI::FinalCleanup | ( | ) | [protected, virtual] |
provides one-time gui cleanup
virtual void GG::SDLGUI::SDLQuit | ( | ) | [protected, virtual] |
cleans up SDL and (if used) FE
virtual void GG::SDLGUI::Run | ( | ) | [protected, virtual] |