MochiEngine
Loading...
Searching...
No Matches
Mochi::Graphics::AbstractGUI Class Reference

An abstract class meant to be extended with specific implementations for different renderers. It also provides basic methods called on update to manage navigation in the vertical axis. All overrideable methods on this class are meant to provide ways to implement a simple immediate GUI, not a stateful GUI. More...

#include <AbstractGUI.h>

Inheritance diagram for Mochi::Graphics::AbstractGUI:
Mochi::Graphics::DummyGUI Mochi::Graphics::SDLGUI

Public Member Functions

 AbstractGUI (FS::PackCatalog *catalog, IRenderer *renderer, Input::IActionManager *actionManager)
void Update (const float &dt)
 Resets the current selectable element count for elements to use GetNextId again this frame. Also checks vertical axis input to move the selected element.
virtual GUIResultButton Button (const GUIButtonOptions &options, const char *label, const GUITextOptions &textOptions)
 Shows a button with a text. It should be able to be navigated and pressed with the mouse.
virtual GUIResult Text (const char *label, const GUITextOptions &options)
 Shows a text.
virtual GUIResult Sprite (const GUIOptions &options)
 Shows a sprite.

Protected Member Functions

GUIElementId GetNextId ()
 Use this method withing selectable elements to provide them a unique id while the UI layout remains the same. If called deterministically, the same selectable elements should always have the same IDs if the layout didn't change.
virtual void OnUpdate ()
 Override this if the new system requires additional data processed each frame.

Protected Attributes

GUIElementId mFocusId
GUIElementId mPressedId
std::unique_ptr< AbstractTextureFactorymTextureFactory
IRenderermRenderer
FS::PackCatalogmCatalog
Input::IActionManagermActionManager

Detailed Description

An abstract class meant to be extended with specific implementations for different renderers. It also provides basic methods called on update to manage navigation in the vertical axis. All overrideable methods on this class are meant to provide ways to implement a simple immediate GUI, not a stateful GUI.

Remarks
This class is mostly provisional. A GUI class can be enormous and have a lot functionality. It is also an Immediate GUI, and arguments can be given to make a stateful GUI instead of a stateless GUI like this. Making a fully fledged UI system was not the point on the engine, and this class and its implementations could be improved when the samples need it.

Guarantees:

  • When implemented, UI shows each frame it is shown.
  • State of the currently selected UI element is the same while the UI layout don't change and GetNextId is called when needed.

Not responsible:

  • GetNextId should be called inside of the implementation when a element is selectable.

Constructor & Destructor Documentation

◆ AbstractGUI()

Mochi::Graphics::AbstractGUI::AbstractGUI ( FS::PackCatalog * catalog,
IRenderer * renderer,
Input::IActionManager * actionManager )
Parameters
catalogCatalog from which to get the UI sprites.
rendererRenderer used to draw the images.
actionManagerAction manager, used to interact with interactable UI elements, like buttons.

Member Function Documentation

◆ Button()

virtual GUIResultButton Mochi::Graphics::AbstractGUI::Button ( const GUIButtonOptions & options,
const char * label,
const GUITextOptions & textOptions )
inlinevirtual

Shows a button with a text. It should be able to be navigated and pressed with the mouse.

Parameters
optionsOptions for the button. Check GUIButtonOptions.
labelText that the button will show. Use an empty string if you don't want text.
textOptionsOptions for the text. Check GUITextOptions.
Returns
The state of the button in this frame, including if it is focused, pressed and released.

Reimplemented in Mochi::Graphics::SDLGUI.

◆ GetNextId()

GUIElementId Mochi::Graphics::AbstractGUI::GetNextId ( )
protected

Use this method withing selectable elements to provide them a unique id while the UI layout remains the same. If called deterministically, the same selectable elements should always have the same IDs if the layout didn't change.

Returns
The id of the element.

◆ Sprite()

virtual GUIResult Mochi::Graphics::AbstractGUI::Sprite ( const GUIOptions & options)
inlinevirtual

Shows a sprite.

Parameters
optionsOptions for the sprite. Check GUIOptions.
Returns
Space occupied by the UI, to be used as parent of other UIs.

Reimplemented in Mochi::Graphics::SDLGUI.

◆ Text()

virtual GUIResult Mochi::Graphics::AbstractGUI::Text ( const char * label,
const GUITextOptions & options )
inlinevirtual

Shows a text.

Parameters
labelThe text to show.
optionsOptions for the text. Check GUITextOptions.
Returns
Space occupied by the UI, to be used as parent of other UIs.

Reimplemented in Mochi::Graphics::SDLGUI.

◆ Update()

void Mochi::Graphics::AbstractGUI::Update ( const float & dt)

Resets the current selectable element count for elements to use GetNextId again this frame. Also checks vertical axis input to move the selected element.

Parameters
dtDelta time

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