GUI
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
gui::GUISystem Class Reference

Manages creating widgets and events and provides routines governing GUI mechanisms. More...

#include <GUISystem.h>

Public Types

typedef std::map< EventType, CreateEventObjectMap
 

Public Member Functions

 GUISystem ()
 
 ~GUISystem ()
 
void setRenderer (Renderer *renderer)
 Sets Renderer object to be used. More...
 
RenderergetRenderer ()
 Returns associated Renderer object. More...
 
void render ()
 Renders the gui. More...
 
void addEventType (EventType eventType, CreateEventObject createFunc)
 Affiliates event identifier with creating function. More...
 
void handleEvents ()
 Calls functions associated with events. More...
 
void mouseMove (int x, int y)
 Updates gui state. To be called when mouse is moved. More...
 
void mouseButtonUp ()
 Updates gui state. To be called when mouse button is released. More...
 
void mouseButtonDown ()
 Updates gui state. To be called when mouse is pressed. More...
 
void keyChar (int unichar)
 Updates gui state. To be called when a character is typed or repeated. More...
 
void keyDown (int keyCode)
 Updates gui state. To be called when a key is pressed. More...
 
Handle< ButtonaddButton (int x, int y, int w, int h, std::string text)
 Creates Button widget and assigns it to the gui. More...
 
Handle< TextFieldaddTextField (int x, int y, int w, int h, std::string text)
 Creates TextField widget and assigns it to the gui. More...
 
Handle< EditBoxaddEditBox (int x, int y, int w, int h, bool multiline=false)
 Creates EditBox widget and assigns it to the gui. More...
 
Handle< ScrollbaraddScrollbar (int x, int y, int w, int h)
 Creates Scrollbar widget and assigns it to the gui. More...
 
Handle< WidgetaddWidget (CreateWidget createWidget, bool setEventQueue)
 Generic function for adding custom widgets. More...
 
Event createEvent (EventType eventType)
 Creates an event that can be emitted. More...
 
Event cloneEvent (const Event &event)
 Creates a copy of an Event object. More...
 
EventObjectcreateNull (EventObject *obj=NULL)
 Returns null pointer. More...
 
EventObjectcreateEventObject (EventObject *obj=NULL)
 Creates an EventObject object. More...
 
EventObjectcreateMouseEvent (EventObject *obj=NULL)
 Creates an MouseEvent object with default values. More...
 
EventObjectcreateKeyboardEvent (EventObject *obj=NULL)
 Creates an KeyboardEvent object. More...
 

Public Attributes

int mouseX
 
int mouseY
 Mouse x coordinate. More...
 

Private Attributes

Rendererrenderer
 Mouse y coordinate. More...
 
std::forward_list< Widget * > widgets
 
Map createEvtObjFuncs
 
EventQueue eventQueue
 
Widgetfocus
 

Detailed Description

Manages creating widgets and events and provides routines governing GUI mechanisms.

Definition at line 32 of file GUISystem.h.

Member Typedef Documentation

◆ Map

Definition at line 35 of file GUISystem.h.

Constructor & Destructor Documentation

◆ GUISystem()

GUISystem::GUISystem ( )

◆ ~GUISystem()

GUISystem::~GUISystem ( )

Definition at line 33 of file GUISystem.cpp.

Member Function Documentation

◆ addButton()

Handle< Button > GUISystem::addButton ( int  x,
int  y,
int  w,
int  h,
std::string  text 
)

Creates Button widget and assigns it to the gui.

Parameters
xX coordinate
yY coordinate
wWidth
hHeight
textText to be displayed
Returns
Handle to the Button object

Definition at line 156 of file GUISystem.cpp.

References gui::EventQueue::addToQueue(), gui::Renderer::color(), gui::Button::downStateColor, eventQueue, gui::EventEmitter::guiSystem, gui::Button::hoverStateColor, renderer, gui::EventEmitter::setQueue(), gui::Button::textColor, gui::Button::upStateColor, and widgets.

◆ addEditBox()

Handle< EditBox > GUISystem::addEditBox ( int  x,
int  y,
int  w,
int  h,
bool  multiline = false 
)

Creates EditBox widget and assigns it to the gui.

Parameters
xX coordinate
yY coordinate
wWidth
hHeight
multilineAre multiple lines allowed.
Returns
Handle to the EditBox object

Definition at line 189 of file GUISystem.cpp.

References gui::EventQueue::addToQueue(), gui::EditBox::backgroundColor, gui::Renderer::color(), gui::EditBox::cursorColor, eventQueue, gui::EditBox::frameColor, gui::EventEmitter::guiSystem, renderer, gui::EditBox::setMultiline(), gui::EventEmitter::setQueue(), gui::EditBox::textColor, and widgets.

◆ addEventType()

void GUISystem::addEventType ( EventType  eventType,
CreateEventObject  createFunc 
)

Affiliates event identifier with creating function.

Parameters
eventTypeEvent type identifier
createFuncFunction returning EventObject* pointer

Definition at line 313 of file GUISystem.cpp.

References createEvtObjFuncs.

◆ addScrollbar()

Handle< Scrollbar > GUISystem::addScrollbar ( int  x,
int  y,
int  w,
int  h 
)

Creates Scrollbar widget and assigns it to the gui.

Parameters
xX coordinate
yY coordinate
wWidth
hHeight
Returns
Handle to the Scrollbar object

Definition at line 210 of file GUISystem.cpp.

References gui::EventQueue::addToQueue(), gui::Scrollbar::backgroundColor, gui::Renderer::color(), eventQueue, gui::Scrollbar::frameColor, gui::EventEmitter::guiSystem, renderer, gui::EventEmitter::setQueue(), and widgets.

◆ addTextField()

Handle< TextField > GUISystem::addTextField ( int  x,
int  y,
int  w,
int  h,
std::string  text 
)

Creates TextField widget and assigns it to the gui.

Parameters
xX coordinate
yY coordinate
wWidth
hHeight
textText to be displayed
Returns
Handle to the TextField object

Definition at line 174 of file GUISystem.cpp.

References gui::EventQueue::addToQueue(), gui::Renderer::color(), eventQueue, gui::EventEmitter::guiSystem, renderer, gui::EventEmitter::setQueue(), gui::TextField::textColor, and widgets.

◆ addWidget()

Handle< Widget > GUISystem::addWidget ( CreateWidget  createWidget,
bool  setEventQueue 
)

Generic function for adding custom widgets.

Parameters
createWidgetX Function creating widget.
setEventQueueIf true, sets widget's addToQueue function.
Returns
Handle to the widget

Definition at line 226 of file GUISystem.cpp.

References gui::EventQueue::addToQueue(), eventQueue, gui::EventEmitter::guiSystem, gui::EventEmitter::setQueue(), and widgets.

◆ cloneEvent()

Event GUISystem::cloneEvent ( const Event event)

Creates a copy of an Event object.

Parameters
eventEvent object to be copied
Returns
Event object

Definition at line 256 of file GUISystem.cpp.

References createEvtObjFuncs, gui::Event::obj, and gui::Event::type.

◆ createEvent()

Event GUISystem::createEvent ( EventType  eventType)

Creates an event that can be emitted.

Parameters
eventTypeType of event
Returns
Event object

Definition at line 242 of file GUISystem.cpp.

References createEvtObjFuncs.

◆ createEventObject()

EventObject * GUISystem::createEventObject ( EventObject obj = NULL)

Creates an EventObject object.

Parameters
objEventObject to copy. Creates new object when NULL.
Returns
Pointer to the created object

Definition at line 273 of file GUISystem.cpp.

◆ createKeyboardEvent()

EventObject * GUISystem::createKeyboardEvent ( EventObject obj = NULL)

Creates an KeyboardEvent object.

Parameters
objEventObject to copy. Creates new object when NULL.
Returns
Pointer to the created object

Definition at line 301 of file GUISystem.cpp.

◆ createMouseEvent()

EventObject * GUISystem::createMouseEvent ( EventObject obj = NULL)

Creates an MouseEvent object with default values.

Parameters
objEventObject to copy. Creates new object when NULL.
Returns
Pointer to the created object

Definition at line 285 of file GUISystem.cpp.

References gui::MouseEvent::mouseX, mouseX, gui::MouseEvent::mouseY, and mouseY.

◆ createNull()

EventObject* gui::GUISystem::createNull ( EventObject obj = NULL)
inline

Returns null pointer.

Parameters
objIrrelevant here
Returns
Null pointer

Used for registering event types with no own properties.

Definition at line 171 of file GUISystem.h.

References createEventObject(), createKeyboardEvent(), and createMouseEvent().

◆ getRenderer()

Renderer* gui::GUISystem::getRenderer ( )
inline

◆ handleEvents()

void GUISystem::handleEvents ( )

Calls functions associated with events.

Definition at line 55 of file GUISystem.cpp.

References gui::EventQueue::empty(), eventQueue, and gui::EventQueue::getNextEvent().

◆ keyChar()

void GUISystem::keyChar ( int  unichar)

Updates gui state. To be called when a character is typed or repeated.

Definition at line 140 of file GUISystem.cpp.

References focus, and gui::Widget::keyChar().

◆ keyDown()

void GUISystem::keyDown ( int  keyCode)

Updates gui state. To be called when a key is pressed.

Definition at line 148 of file GUISystem.cpp.

References focus, and gui::Widget::keyDown().

◆ mouseButtonDown()

void GUISystem::mouseButtonDown ( )

Updates gui state. To be called when mouse is pressed.

Definition at line 108 of file GUISystem.cpp.

References focus, gui::Widget::focusIn(), gui::Widget::focusOut(), mouseX, mouseY, gui::Widget::STATE_DOWN, gui::Widget::stateChange(), and widgets.

◆ mouseButtonUp()

void GUISystem::mouseButtonUp ( )

Updates gui state. To be called when mouse button is released.

Definition at line 94 of file GUISystem.cpp.

References mouseX, mouseY, gui::Widget::STATE_HOVER, gui::Widget::STATE_UP, and widgets.

◆ mouseMove()

void GUISystem::mouseMove ( int  x,
int  y 
)

Updates gui state. To be called when mouse is moved.

Definition at line 66 of file GUISystem.cpp.

References mouseX, mouseY, gui::Widget::STATE_HOVER, gui::Widget::STATE_UP, and widgets.

◆ render()

void GUISystem::render ( )

Renders the gui.

Definition at line 43 of file GUISystem.cpp.

References gui::Renderer::clear(), renderer, gui::Renderer::setTarget(), and widgets.

◆ setRenderer()

void GUISystem::setRenderer ( Renderer renderer)

Sets Renderer object to be used.

Parameters
rendererRenderer* pointer

Definition at line 38 of file GUISystem.cpp.

References renderer.

Member Data Documentation

◆ createEvtObjFuncs

Map gui::GUISystem::createEvtObjFuncs
private

Definition at line 204 of file GUISystem.h.

◆ eventQueue

EventQueue gui::GUISystem::eventQueue
private

Definition at line 205 of file GUISystem.h.

◆ focus

Widget* gui::GUISystem::focus
private

Definition at line 207 of file GUISystem.h.

◆ mouseX

int gui::GUISystem::mouseX

Definition at line 196 of file GUISystem.h.

◆ mouseY

int gui::GUISystem::mouseY

Mouse x coordinate.

Definition at line 197 of file GUISystem.h.

◆ renderer

Renderer* gui::GUISystem::renderer
private

Mouse y coordinate.

Definition at line 202 of file GUISystem.h.

◆ widgets

std::forward_list<Widget*> gui::GUISystem::widgets
private

Definition at line 203 of file GUISystem.h.


The documentation for this class was generated from the following files: