QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Quasar::LayerStack Class Reference

Owns the layers of an application and keeps them in order, from the bottom to the top. More...

#include <quasar/core/LayerStack.h>

Public Types

using Iterator = std::vector<Scope<Layer>>::iterator
 Iterator over the layers, from the bottom to the top.
using ConstIterator = std::vector<Scope<Layer>>::const_iterator
 Iterator over the layers, from the bottom to the top, without changing them.

Public Member Functions

 ~LayerStack ()
 Detaches every layer, from the top to the bottom, then destroys them.
 LayerStack (const LayerStack &)=delete
LayerStack & operator= (const LayerStack &)=delete
 LayerStack (LayerStack &&)=delete
LayerStack & operator= (LayerStack &&)=delete
Layer & PushLayer (Scope< Layer > layer)
 Adds a regular layer above the other regular layers and below every overlay, then attaches it.
Layer & PushOverlay (Scope< Layer > overlay)
 Adds an overlay above every layer and overlay, then attaches it.
Scope< Layer > PopLayer (Layer &layer)
 Detaches a regular layer and removes it from the stack.
Scope< Layer > PopOverlay (Layer &overlay)
 Detaches an overlay and removes it from the stack.
void OnEvent (Event &event)
 Sends an event to the layers, from the top to the bottom, until one of them handles it.
void Clear ()
 Detaches every layer, from the top to the bottom, then removes and destroys them all.
std::size_t GetSize () const
 Returns the number of layers and overlays in the stack.
Iterator begin ()
 Returns an iterator to the bottom layer.
Iterator end ()
 Returns an iterator past the top layer.
ConstIterator begin () const
 Returns an iterator to the bottom layer.
ConstIterator end () const
 Returns an iterator past the top layer.

Detailed Description

Owns the layers of an application and keeps them in order, from the bottom to the top.

Regular layers, like the game scene, are at the bottom. Overlays, like the editor panels or a debug view, are always above every regular layer, whatever the order they were added in. Each kind keeps its own order: a new layer goes above the other layers, and a new overlay above the other overlays.

Iterating over the stack goes from the bottom to the top, which is the order for updating and rendering. Use std::views::reverse(stack) to go from the top to the bottom, which is the order for events. Do not add or remove layers while iterating.

Member Function Documentation

◆ PushLayer()

Layer & Quasar::LayerStack::PushLayer ( Scope< Layer > layer)

Adds a regular layer above the other regular layers and below every overlay, then attaches it.

Parameters
layerThe layer to add. It must not be empty.
Returns
The added layer, which stays owned by the stack.

◆ PushOverlay()

Layer & Quasar::LayerStack::PushOverlay ( Scope< Layer > overlay)

Adds an overlay above every layer and overlay, then attaches it.

Parameters
overlayThe overlay to add. It must not be empty.
Returns
The added overlay, which stays owned by the stack.

◆ PopLayer()

Scope< Layer > Quasar::LayerStack::PopLayer ( Layer & layer)

Detaches a regular layer and removes it from the stack.

Returns
The removed layer, now owned by the caller, or an empty Scope if it is not a regular layer of this stack. In that case, a warning is logged.

◆ PopOverlay()

Scope< Layer > Quasar::LayerStack::PopOverlay ( Layer & overlay)

Detaches an overlay and removes it from the stack.

Returns
The removed overlay, now owned by the caller, or an empty Scope if it is not an overlay of this stack. In that case, a warning is logged.

◆ OnEvent()

void Quasar::LayerStack::OnEvent ( Event & event)

Sends an event to the layers, from the top to the bottom, until one of them handles it.

An event that is already handled is not sent to any layer.


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