GG::SDLGUI Class Reference

This is an abstract singleton class that represents the GUI framework of an SDL OpenGL application. More...

#include <SDLGUI.h>

Inheritance diagram for GG::SDLGUI:

GG::GUI List of all members.

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 SDLGUIGetGUI ()
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 ()

Detailed Description

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.

Definition at line 74 of file SDLGUI.h.


Constructor & Destructor Documentation

GG::SDLGUI::SDLGUI ( int  w = 1024,
int  h = 768,
bool  calc_FPS = false,
const std::string &  app_name = "GG" 
) [explicit]

ctor


Member Function Documentation

virtual int GG::SDLGUI::AppWidth (  )  const [virtual]

returns the width of the application window/screen

Implements GG::GUI.

virtual int GG::SDLGUI::AppHeight (  )  const [virtual]

returns the height of the application window/screen

Implements GG::GUI.

virtual int GG::SDLGUI::Ticks (  )  const [virtual]

returns ms since the app started running

Implements GG::GUI.

void GG::SDLGUI::operator() (  ) 

external interface to Run()

Reimplemented from GG::GUI.

virtual void GG::SDLGUI::Exit ( int  code  )  [virtual]

does basic clean-up, then calls exit(); callable from anywhere in user code via GetGUI()

Implements GG::GUI.

virtual void GG::SDLGUI::Enter2DMode (  )  [pure virtual]

saves any current GL state, sets up GG-friendly 2D drawing mode. GG expects an orthographic projection, with the origin in the upper left corner, and with one unit of GL space equal to one pixel on the screen.

Implements GG::GUI.

virtual void GG::SDLGUI::Exit2DMode (  )  [pure virtual]

restores GL to its condition prior to Enter2DMode() call

Implements GG::GUI.

static SDLGUI* GG::SDLGUI::GetGUI (  )  [static]

allows any code to access the gui framework by calling SDLGUI::GetGUI()

Reimplemented from GG::GUI.

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]

handles all waiting system events (from SDL, DirectInput, etc.

). This function should only be called from custom EventPump event handlers.

Implements GG::GUI.

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]

clears the backbuffer, etc.

Implements GG::GUI.

virtual void GG::SDLGUI::RenderEnd (  )  [protected, virtual]

swaps buffers, etc.

Implements GG::GUI.

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]

initializes GUI state, then executes main event handler/render loop (PollAndRender())

Implements GG::GUI.


The documentation for this class was generated from the following file:
Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2