GG::GUI Class Reference

An abstract base for an GUI framework class to drive the GG GUI. More...

#include <GUI.h>

Inheritance diagram for GG::GUI:

GG::OgreGUI GG::SDLGUI List of all members.

Signal Types

typedef boost::signal< bool(),
OrCombiner > 
AcceleratorSignalType

Slot Types

typedef AcceleratorSignalType::slot_type AcceleratorSlotType

Structors

virtual ~GUI ()

Accessors

const std::string & AppName () const
WndFocusWnd () const
WndGetWindowUnder (const Pt &pt) const
int DeltaT () const
virtual int Ticks () const=0
bool RenderingDragDropWnds () const
bool FPSEnabled () const
double FPS () const
std::string FPSString () const
double MaxFPS () const
virtual int AppWidth () const=0
virtual int AppHeight () const=0
int ButtonDownRepeatDelay () const
int ButtonDownRepeatInterval () const
int DoubleClickInterval () const
int MinDragTime () const
int MinDragDistance () const
bool DragDropWnd (const Wnd *wnd) const
bool MouseButtonDown (int bn) const
Pt MousePosition () const
Pt MouseMovement () const
Flags< ModKey > ModKeys () const
virtual std::set< std::pair<
int, int > > 
FindWords (const std::string &str) const
const boost::shared_ptr< StyleFactory > & GetStyleFactory () const
bool RenderCursor () const
const boost::shared_ptr< Cursor > & GetCursor () const
const_accel_iterator accel_begin () const
const_accel_iterator accel_end () const
AcceleratorSignalTypeAcceleratorSignal (Key key, Flags< ModKey > mod_keys=MOD_KEY_NONE) const

Mutators

void operator() ()
virtual void Exit (int code)=0
virtual void HandleSystemEvents ()=0
void HandleGGEvent (EventType event, Key key, Flags< ModKey > mod_keys, const Pt &pos, const Pt &rel)
void SetFocusWnd (Wnd *wnd)
virtual void Wait (int ms)
void Register (Wnd *wnd)
void RegisterModal (Wnd *wnd)
void Remove (Wnd *wnd)
void WndDying (Wnd *wnd)
void MoveUp (Wnd *wnd)
void MoveDown (Wnd *wnd)
virtual boost::shared_ptr<
ModalEventPump
CreateModalEventPump (bool &done)
void RegisterDragDropWnd (Wnd *wnd, const Pt &offset, Wnd *originating_wnd)
void CancelDragDrop ()
void RegisterTimer (Timer &timer)
void RemoveTimer (Timer &timer)
virtual void Enter2DMode ()=0
virtual void Exit2DMode ()=0
void EnableFPS (bool b=true)
void SetMaxFPS (double max)
void EnableMouseButtonDownRepeat (int delay, int interval)
void SetDoubleClickInterval (int interval)
void SetMinDragTime (int time)
void SetMinDragDistance (int distance)
void SetAccelerator (Key key, Flags< ModKey > mod_keys=MOD_KEY_NONE)
void RemoveAccelerator (Key key, Flags< ModKey > mod_keys=MOD_KEY_NONE)
boost::shared_ptr< FontGetFont (const std::string &font_filename, int pts, unsigned int range=Font::ALL_CHARS)
void FreeFont (const std::string &font_filename, int pts)
boost::shared_ptr< TextureStoreTexture (Texture *texture, const std::string &texture_name)
boost::shared_ptr< TextureStoreTexture (const boost::shared_ptr< Texture > &texture, const std::string &texture_name)
boost::shared_ptr< TextureGetTexture (const std::string &name, bool mipmap=false)
void FreeTexture (const std::string &name)
void SetStyleFactory (const boost::shared_ptr< StyleFactory > &factory)
void RenderCursor (bool render)
void SetCursor (const boost::shared_ptr< Cursor > &cursor)
void SaveWnd (const Wnd *wnd, const std::string &name, boost::archive::xml_oarchive &ar)
void LoadWnd (Wnd *&wnd, const std::string &name, boost::archive::xml_iarchive &ar)
template<class T>
void LoadWnd (T *&wnd, const std::string &name, boost::archive::xml_iarchive &ar)
void SetSaveWndFunction (SaveWndFn fn)
void SetLoadWndFunction (LoadWndFn fn)
void SetSaveLoadFunctions (const PluginInterface &interface)

Exceptions

 GG_ABSTRACT_EXCEPTION (Exception)
 GG_CONCRETE_EXCEPTION (BadFunctionPointer, GG::GUI, Exception)

Structors

 GUI (const std::string &app_name)

Mutators

void ProcessBrowseInfo ()
virtual void RenderBegin ()=0
virtual void Render ()
virtual void RenderEnd ()=0
void SetFPS (double FPS)
void SetDeltaT (int delta_t)

Public Types

enum  EventType {
  IDLE,
  KEYPRESS,
  KEYRELEASE,
  LPRESS,
  MPRESS,
  RPRESS,
  LRELEASE,
  MRELEASE,
  RRELEASE,
  MOUSEMOVE,
  MOUSEWHEEL
}
typedef std::set< std::pair<
Key, Flags< ModKey
> > >::const_iterator 
const_accel_iterator
typedef void(*) SaveWndFn (const Wnd *wnd, const std::string &name, boost::archive::xml_oarchive &ar)
typedef void(*) LoadWndFn (Wnd *&wnd, const std::string &name, boost::archive::xml_iarchive &ar)

Static Public Member Functions

static GUIGetGUI ()
static void RenderWindow (Wnd *wnd)

Protected Member Functions

virtual void Run ()=0

Friends

class EventPumpBase
struct GUIImpl

Detailed Description

An abstract base for an GUI framework class to drive the GG GUI.

This class has all the essential services that GG requires:

The user is required to provide several functions. The most vital functions the user is required to provide are: Enter2DMode(), Exit2DMode(), DeltaT(), PollAndRender() [virtual private], and Run() [virtual private]. Without these, GUI is pretty useless. In addition, HandleEvent() must be driven from PollAndRender(). The code driving HandleEvent() must interact with the hardware and/or operating system, and supply the appropriate EventType's, key presses, and mouse position info to HandleEvent(). It is the author's recommendation that the user use one of the provided SDL abd Ogre drivers to do this.

Keyboard accelerators may be defined, as mentioned above. Each defined accelerator has its own signal which is emitted each time the accelerator is detected. Client code should listen to the appropriate signal to act on an accelerator invocation. Each slot that is signalled with a keyboard accelerator should return true if it processed the accelerator, or false otherwise. This lets GUI know whether or not it should create a keystroke event and process it normally, sending it to the Wnd that currently has focus. Note that since signals can be connected to multiple slots, if even one slot returns true, no kestroke event is created. It is perfectly legal to return false even if an accelerator is processed, as long as you also then want the focus Wnd to receive a keystroke event. Also, note that all accelerators are processed before, and possbily instead of, any key events. So setting a plain "h" as a keyboard accelerator can (if it is processed normally by a slot) prevent any Wnd anywhere in your application from receiving "h" keystrokes. To avoid this:

A GUI-wide StyleFactory can be set; this controls the actual types of controls and dialogs that are created when a control or dialog creates one (e.g. when FileDlg encounters an error and creates a ThreeButtonDlg). This is overridden by any StyleFactory that may be installed in an individual Wnd.

A note about "button-down-repeat". When you click on the down-button on a scroll-bar, you probably expect the the button's action (scrolling down one increment) to repeat when you hold down the button, much like the way kestrokes are repeated when you hold down a keyboard key. This is in fact what happens, and it is accomplished by having the scroll and its buttons respond to extra LButtonDown events generated by the GUI. These extra messages, occur ButtonDownRepeatDelay() milliseconds after the button is first depressed, repeating every ButtonDownRepeatInterval() milliseconds thereafter. Only Wnds created with the REPEAT_BUTTON_DOWN flag receive such extra messages.

Definition at line 101 of file GUI.h.


Member Typedef Documentation

typedef boost::signal<bool (), OrCombiner> GG::GUI::AcceleratorSignalType

emitted when a keyboard accelerator is invoked.

A return value of true indicates that the accelerator was processed by some slot; otherwise, a keystroke event is processed instead.

Definition at line 114 of file GUI.h.

typedef AcceleratorSignalType::slot_type GG::GUI::AcceleratorSlotType

type of functor(s) invoked on a AcceleratorSignalType

Definition at line 118 of file GUI.h.

typedef std::set<std::pair<Key, Flags<ModKey> > >::const_iterator GG::GUI::const_accel_iterator

the type of iterator returned by accel_begin() and accel_end()

Definition at line 136 of file GUI.h.

typedef void(*) GG::GUI::SaveWndFn(const Wnd *wnd, const std::string &name, boost::archive::xml_oarchive &ar)

The type of function used to serialize Wnds.

Definition at line 139 of file GUI.h.

typedef void(*) GG::GUI::LoadWndFn(Wnd *&wnd, const std::string &name, boost::archive::xml_iarchive &ar)

The type of function used to deserialize Wnds.

Definition at line 142 of file GUI.h.


Member Enumeration Documentation

enum GG::GUI::EventType

these are the only events absolutely necessary for GG to function properly

Enumerator:
IDLE  nothing has changed since the last message, but the GUI might want to update some things anyway
KEYPRESS  a down key press or key repeat, with or without modifiers like Alt, Ctrl, Meta, etc.
KEYRELEASE  a key release, with or without modifiers like Alt, Ctrl, Meta, etc.
LPRESS  a left mouse button press
MPRESS  a middle mouse button press
RPRESS  a right mouse button press
LRELEASE  a left mouse button release
MRELEASE  a middle mouse button release
RRELEASE  a right mouse button release
MOUSEMOVE  movement of the mouse; may include relative motion in addition to absolute position
MOUSEWHEEL  rolling of the mouse wheel; this event is accompanied by the amount of roll in the y-component of the mouse's relative position (+ is up, - is down)

Definition at line 122 of file GUI.h.


Constructor & Destructor Documentation

virtual GG::GUI::~GUI (  )  [virtual]

virtual dtor

GG::GUI::GUI ( const std::string &  app_name  )  [protected]

protected ctor, called by derived classes


Member Function Documentation

const std::string& GG::GUI::AppName (  )  const

returns the user-defined name of the application

Wnd* GG::GUI::FocusWnd (  )  const

returns the GG::Wnd that currently has the input focus

Wnd* GG::GUI::GetWindowUnder ( const Pt pt  )  const

returns the GG::Wnd under the point pt

int GG::GUI::DeltaT (  )  const

returns ms since last frame was rendered

virtual int GG::GUI::Ticks (  )  const [pure virtual]

returns ms since the app started running

Implemented in GG::OgreGUI, and GG::SDLGUI.

bool GG::GUI::RenderingDragDropWnds (  )  const

returns true iff drag-and-drop Wnds are currently being rendered

bool GG::GUI::FPSEnabled (  )  const

returns true iff FPS calulations are turned on

double GG::GUI::FPS (  )  const

returns the frames per second at which the GUI is rendering

std::string GG::GUI::FPSString (  )  const

returns a string of the form "[m_FPS] frames per second"

double GG::GUI::MaxFPS (  )  const

returns the maximum allowed frames per second of rendering speed. 0 indicates no limit.

virtual int GG::GUI::AppWidth (  )  const [pure virtual]

returns the width of the application window/screen

Implemented in GG::OgreGUI, and GG::SDLGUI.

virtual int GG::GUI::AppHeight (  )  const [pure virtual]

returns the height of the application window/screen

Implemented in GG::OgreGUI, and GG::SDLGUI.

int GG::GUI::ButtonDownRepeatDelay (  )  const

returns the delay value set by EnableMouseButtonDownRepeat()

int GG::GUI::ButtonDownRepeatInterval (  )  const

returns the interval value set by EnableMouseButtonDownRepeat()

int GG::GUI::DoubleClickInterval (  )  const

returns the maximum interval allowed between clicks that is still considered a double-click, in ms

int GG::GUI::MinDragTime (  )  const

returns the minimum time (in ms) an item must be dragged before it is a valid drag

int GG::GUI::MinDragDistance (  )  const

returns the minimum distance an item must be dragged before it is a valid drag

bool GG::GUI::DragDropWnd ( const Wnd wnd  )  const

returns true if wnd is currently begin dragged as part of a drag-and-drop operation

bool GG::GUI::MouseButtonDown ( int  bn  )  const

returns the up/down states of the mouse buttons

Pt GG::GUI::MousePosition (  )  const

returns the absolute position of mouse, based on the last mouse motion event

Pt GG::GUI::MouseMovement (  )  const

returns the relative position of mouse, based on the last mouse motion event

Flags<ModKey> GG::GUI::ModKeys (  )  const

returns the set of modifier keys that are currently depressed, based on the last event

virtual std::set<std::pair<int, int> > GG::GUI::FindWords ( const std::string &  str  )  const [virtual]

Returns the (begin, end) indices of all the word-tokens in the given string.

This is perhaps an odd place for this function to exist, but the notion of what a "word" is is so application-specific that it was placed here so that users can customize this behavior.

const boost::shared_ptr<StyleFactory>& GG::GUI::GetStyleFactory (  )  const

returns the currently-installed style factory

bool GG::GUI::RenderCursor (  )  const

returns true iff the GUI is responsible for rendering the cursor

const boost::shared_ptr<Cursor>& GG::GUI::GetCursor (  )  const

returns the currently-installed cursor

const_accel_iterator GG::GUI::accel_begin (  )  const

returns an iterator to the first defined keyboard accelerator

const_accel_iterator GG::GUI::accel_end (  )  const

returns an iterator to the last + 1 defined keyboard accelerator

AcceleratorSignalType& GG::GUI::AcceleratorSignal ( Key  key,
Flags< ModKey >  mod_keys = MOD_KEY_NONE 
) const

returns the signal that is emitted when the requested keyboard accelerator is invoked.

void GG::GUI::operator() (  ) 

external interface to Run()

Reimplemented in GG::SDLGUI.

virtual void GG::GUI::Exit ( int  code  )  [pure virtual]

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

Implemented in GG::OgreGUI, and GG::SDLGUI.

virtual void GG::GUI::HandleSystemEvents (  )  [pure virtual]

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

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

Implemented in GG::OgreGUI, and GG::SDLGUI.

void GG::GUI::HandleGGEvent ( EventType  event,
Key  key,
Flags< ModKey >  mod_keys,
const Pt pos,
const Pt rel 
)

event handler for GG events

void GG::GUI::SetFocusWnd ( Wnd wnd  ) 

sets the input focus window to wnd

Referenced by GG::Spin< T >::EventFilter().

virtual void GG::GUI::Wait ( int  ms  )  [virtual]

suspends the GUI thread for ms milliseconds. Singlethreaded GUI subclasses may do nothing here, or may pause for ms milliseconds.

void GG::GUI::Register ( Wnd wnd  ) 

adds wnd into the z-list. Registering a null pointer or registering the same window multiple times is a no-op.

void GG::GUI::RegisterModal ( Wnd wnd  ) 

adds wnd onto the modal windows "stack"

void GG::GUI::Remove ( Wnd wnd  ) 

removes wnd from the z-list. Removing a null pointer or removing the same window multiple times is a no-op.

void GG::GUI::WndDying ( Wnd wnd  ) 

removes wnd from all GUI state variables, so that none of them point to a deleted object

void GG::GUI::MoveUp ( Wnd wnd  ) 

moves wnd to the top of the z-list

void GG::GUI::MoveDown ( Wnd wnd  ) 

moves wnd to the bottom of the z-list

virtual boost::shared_ptr<ModalEventPump> GG::GUI::CreateModalEventPump ( bool &  done  )  [virtual]

creates a new ModalEventPump that will terminate when done is set to true

Reimplemented in GG::OgreGUI.

void GG::GUI::RegisterDragDropWnd ( Wnd wnd,
const Pt offset,
Wnd originating_wnd 
)

adds wnd to the set of current drag-and-drop Wnds, to be rendered offset pixels from the cursor position.

originating_wnd indicates the original owner of wnd before the drag-and-drop.

Exceptions:
std::runtime_error May throw std::runtime_error if there are already other Wnds registered that belong to a window other than originating_wnd.

void GG::GUI::CancelDragDrop (  ) 

clears the set of current drag-and-drop Wnds

void GG::GUI::RegisterTimer ( Timer timer  ) 

adds timer to the list of active timers

void GG::GUI::RemoveTimer ( Timer timer  ) 

removes timer from the list of active timers

virtual void GG::GUI::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.

Implemented in GG::OgreGUI, and GG::SDLGUI.

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

restores GL to its condition prior to Enter2DMode() call

Implemented in GG::OgreGUI, and GG::SDLGUI.

void GG::GUI::EnableFPS ( bool  b = true  ) 

turns FPS calulations on or off

void GG::GUI::SetMaxFPS ( double  max  ) 

sets the maximum allowed FPS, so the render loop does not act as a spinlock when it runs very quickly. 0 indicates no limit.

void GG::GUI::EnableMouseButtonDownRepeat ( int  delay,
int  interval 
)

delay and interval are in ms; Setting delay to 0 disables mouse button-down repeating completely.

void GG::GUI::SetDoubleClickInterval ( int  interval  ) 

sets the maximum interval allowed between clicks that is still considered a double-click, in ms

void GG::GUI::SetMinDragTime ( int  time  ) 

sets the minimum time (in ms) an item must be dragged before it is a valid drag

void GG::GUI::SetMinDragDistance ( int  distance  ) 

sets the minimum distance an item must be dragged before it is a valid drag

void GG::GUI::SetAccelerator ( Key  key,
Flags< ModKey >  mod_keys = MOD_KEY_NONE 
)

establishes a keyboard accelerator.

Any key modifiers may be specified, or none at all.

void GG::GUI::RemoveAccelerator ( Key  key,
Flags< ModKey >  mod_keys = MOD_KEY_NONE 
)

removes a keyboard accelerator.

Any key modifiers may be specified, or none at all.

boost::shared_ptr<Font> GG::GUI::GetFont ( const std::string &  font_filename,
int  pts,
unsigned int  range = Font::ALL_CHARS 
)

returns a shared_ptr to the desired font

void GG::GUI::FreeFont ( const std::string &  font_filename,
int  pts 
)

removes the desired font from the managed pool; since shared_ptr's are used, the font may be deleted much later

boost::shared_ptr<Texture> GG::GUI::StoreTexture ( Texture texture,
const std::string &  texture_name 
)

adds an already-constructed texture to the managed pool

Warning:
calling code must not delete texture; the texture pool will do that.

boost::shared_ptr<Texture> GG::GUI::StoreTexture ( const boost::shared_ptr< Texture > &  texture,
const std::string &  texture_name 
)

adds an already-constructed texture to the managed pool

boost::shared_ptr<Texture> GG::GUI::GetTexture ( const std::string &  name,
bool  mipmap = false 
)

loads the requested texture from file name; mipmap textures are generated if mipmap is true

void GG::GUI::FreeTexture ( const std::string &  name  ) 

removes the desired texture from the managed pool; since shared_ptr's are used, the texture may be deleted much later

void GG::GUI::SetStyleFactory ( const boost::shared_ptr< StyleFactory > &  factory  ) 

sets the currently-installed style factory

void GG::GUI::RenderCursor ( bool  render  ) 

set this to true iff the GUI should render the cursor

void GG::GUI::SetCursor ( const boost::shared_ptr< Cursor > &  cursor  ) 

sets the currently-installed cursor

void GG::GUI::SaveWnd ( const Wnd wnd,
const std::string &  name,
boost::archive::xml_oarchive &  ar 
)

saves wnd to the archive ar, with the xml tag name.

Exceptions:
GG::GUI::BadFunctionPointer Throws GG::GUI::BadFunctionPointer if no Wnd-serializing function has ben defined by the user using SetSaveWndFunction().

void GG::GUI::LoadWnd ( Wnd *&  wnd,
const std::string &  name,
boost::archive::xml_iarchive &  ar 
)

loads wnd, with the xml tag name, from the archive ar.

Exceptions:
GG::GUI::BadFunctionPointer Throws GG::GUI::BadFunctionPointer if no Wnd-serializing function has ben defined by the user using SetLoadWndFunction().

Referenced by LoadWnd().

template<class T>
void GG::GUI::LoadWnd ( T *&  wnd,
const std::string &  name,
boost::archive::xml_iarchive &  ar 
) [inline]

Since LoadWnd() will only accept a referemce to a GG::Wnd*, this method is provided to more conveniently accept pointers to Wnd subclasses.

Definition at line 332 of file GUI.h.

References LoadWnd().

void GG::GUI::SetSaveWndFunction ( SaveWndFn  fn  ) 

sets fn to be the function invoked when SaveWnd() is called.

void GG::GUI::SetLoadWndFunction ( LoadWndFn  fn  ) 

sets fn to be the function invoked when LoadWnd() is called.

void GG::GUI::SetSaveLoadFunctions ( const PluginInterface interface  ) 

sets all the SaveWnd() and LoadWnd() function pointers to be the functions provided by interface.

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

allows any GG code access to GUI framework by calling GUI::GetGUI()

Reimplemented in GG::OgreGUI, and GG::SDLGUI.

Referenced by GG::Spin< T >::EventFilter().

static void GG::GUI::RenderWindow ( Wnd wnd  )  [static]

renders a window (if it is visible) and all its visible descendents recursively

GG::GUI::GG_ABSTRACT_EXCEPTION ( Exception   ) 

The base class for GUI exceptions.

GG::GUI::GG_CONCRETE_EXCEPTION ( BadFunctionPointer  ,
GG::GUI  ,
Exception   
)

Thrown when an attempt is made to invoke either of the save- or load-window functions before they have been set.

void GG::GUI::ProcessBrowseInfo (  )  [protected]

determines the current browse info mode, if any

virtual void GG::GUI::RenderBegin (  )  [protected, pure virtual]

clears the backbuffer, etc.

Implemented in GG::OgreGUI, and GG::SDLGUI.

virtual void GG::GUI::Render (  )  [protected, virtual]

renders the windows in the z-list

virtual void GG::GUI::RenderEnd (  )  [protected, pure virtual]

swaps buffers, etc.

Implemented in GG::OgreGUI, and GG::SDLGUI.

void GG::GUI::SetFPS ( double  FPS  )  [protected]

sets the FPS value based on the most recent calculation

void GG::GUI::SetDeltaT ( int  delta_t  )  [protected]

sets the time between the most recent frame and the one before it, in ms

virtual void GG::GUI::Run (  )  [protected, pure virtual]

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

Implemented in GG::OgreGUI, and GG::SDLGUI.


Friends And Related Function Documentation

friend class EventPumpBase [friend]

allows EventPumpBase types to drive GUI

Definition at line 312 of file GUI.h.


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