Gorgon Game Engine
Layer Class Reference

This class is the base class for all layer types. More...

Inheritance diagram for Layer:
[legend]

Public Member Functions

 Layer ()
 Constructor that sets the layer to cover entire parent, no matter how big it is. More...
 
 Layer (const Geometry::Bounds &bounds)
 Initializing constructor. More...
 
 Layer (const Geometry::Point &location)
 Constructor that places the layer to the given location. More...
 
 Layer (const Layer &)=delete
 Copy constructor is disabled. More...
 
 Layer (Layer &&other)
 Move constructor. More...
 
virtual ~Layer ()
 Destructor. More...
 
virtual void Hide ()
 Hides this layer. More...
 
virtual bool IsVisible () const
 Returns whether this layer is effectively visible. More...
 
Layeroperator= (const Layer &)=delete
 Copy assignment is deleted. More...
 
Layeroperator= (Layer &&other)
 Move assignment. More...
 
virtual bool propagate_mouseevent (Input::Mouse::EventType evet, Geometry::Point location, Input::Mouse::Button button, float amount, MouseHandler &handlers)
 Propagates a mouse event. More...
 
virtual void Render ()
 Renders the current layer, default handling is to pass the request to the sub-layers. Rendering is not thread safe. More...
 
virtual void Show ()
 Displays this layer. More...
 
void Swap (Layer &other)
 Swaps two layers, mostly used for move semantics. More...
 

Public Attributes

const Containers::Collection< Layer > & Children
 Sub-layers that this layer holds, all the sub-layers are considered to be above current layer. More...
 

Static Public Attributes

static const Geometry::Bounds EntireRegion
 When used as layer bounds, represents the entire region its placed in. More...
 

Protected Member Functions

virtual void added (Layer &layer)
 Will be called when a layer is added. More...
 
void dotransformandclip (bool inverse=false)
 Performs transformation and clipping. Use inverse for reverse mapping for mouse events. More...
 
virtual void located (Layer *parent)
 Will be called when this layer is added to another. More...
 
virtual void removed (Layer &layer)
 Will be called when a layer is removed. More...
 
void reverttransformandclip ()
 Reverts previously done transformation. More...
 

Protected Attributes

Geometry::Bounds bounds
 Bounds of this layer. More...
 
Containers::Collection< Layerchildren
 Child layers that this layer holds, all child layers are considered to be above current layer. More...
 
bool isvisible
 Whether this layer is visible, invisible layers will not be drawn or receive any events. More...
 
std::string name
 For debugging. More...
 
Layerparent
 Parent layer, could be nullptr. More...
 

Children related functions

These functions deals with child layers.

void Add (Layer &layer)
 Adds the given layer as a child. More...
 
void Add (Layer *layer)
 Adds the given layer as a child. More...
 
void setname (std::string value)
 For debugging. More...
 
void Insert (Layer &layer, long under)
 Inserts the given layer before the given index. More...
 
void Insert (Layer *layer, long under)
 Inserts the given layer before the given index. More...
 
void Remove (Layer &layer)
 Removes the given layer. More...
 
void Remove (Layer *layer)
 Removes the given layer. More...
 
bool HasParent () const
 Returns whether this layer has a parent. More...
 
virtual LayerGetParent () const
 Returns the parent of this layer. More...
 
LayerGetTopLevel () const
 Returns the top level layer that contains this layer. More...
 
virtual Geometry::Point TranslateToTopLevel (Geometry::Point location={0, 0}) const
 Translates the given location to the top level. More...
 
LayerGetTopLevel ()
 

Iterator related functions

These functions return an iterator that allows children to be iterated.

Containers::Collection< Layer >::ConstIterator begin () const
 An iterator pointing to the start of the children. More...
 
Containers::Collection< Layer >::ConstIterator end () const
 An iterator pointing to the end of the children. More...
 
Containers::Collection< Layer >::ConstIterator First () const
 An iterator pointing to the start of the children. More...
 
Containers::Collection< Layer >::ConstIterator Last () const
 An iterator pointing to the last item of the children. More...
 

Ordering functions

This layer should be a in another layer for these methods to work.

void PlaceBefore (int before)
 Places this layer before the given index. More...
 
void PlaceToTop ()
 Places this layer to the top of the layer stack its in. More...
 
void PlaceToBottom ()
 Places this layer to the bottom of the layer stack. More...
 
int GetOrder () const
 Gets the current order of the stack. More...
 

Geometry related functions

These functions modify or return the boundaries of this layer

virtual void Move (const Geometry::Point &location)
 Moves this layer to the given location. More...
 
virtual void Move (int x, int y)
 Moves this layer to the given location. More...
 
virtual void Resize (const Geometry::Size &size)
 Resizes the layer to the given size. More...
 
virtual void Resize (int width, int height)
 Resizes the layer to the given size. More...
 
void SetWidth (int width)
 Resizes the layer to the given size. More...
 
void SetHeight (int height)
 Resizes the layer to the given size. More...
 
void SetBounds (const Geometry::Bounds &bounds)
 Sets the boundaries of this layer. More...
 
Geometry::Size GetSize () const
 Returns the size of the layer. More...
 
Geometry::Size GetCalculatedSize () const
 Returns the size of the layer. More...
 
int GetWidth () const
 Returns the width of the layer. More...
 
int GetHeight () const
 Returns the height of the layer. More...
 
Geometry::Point GetLocation () const
 Returns the current location of the layer. More...
 
int GetLeft () const
 Returns the current location of the layer. More...
 
int GetTop () const
 Returns the current location of the layer. More...
 
Geometry::Bounds GetBounds () const
 Returns the boundaries of the layer. More...
 
Geometry::Bounds GetEffectiveBounds () const
 Returns the effective boundaries of the layer. More...
 

Detailed Description

This class is the base class for all layer types.

All common methods are implemented with a common way. This class always implements basic processing functions. Derived classes can override them. Unless overridden these basic functions only propagate the call. Copying a layer is dangerous and therefore disabled.

Constructor & Destructor Documentation

◆ Layer() [1/5]

Layer ( const Geometry::Bounds bounds)

Initializing constructor.

◆ Layer() [2/5]

Layer ( )

Constructor that sets the layer to cover entire parent, no matter how big it is.

The location of the layer is set to be the origin

◆ Layer() [3/5]

Layer ( const Geometry::Point location)

Constructor that places the layer to the given location.

References basic_Size< T_ >::Max().

◆ Layer() [4/5]

Layer ( const Layer )
delete

Copy constructor is disabled.

◆ Layer() [5/5]

Layer ( Layer &&  other)

Move constructor.

References Layer::Swap().

◆ ~Layer()

~Layer ( )
virtual

Member Function Documentation

◆ Add() [1/2]

void Add ( Layer layer)

Adds the given layer as a child.

Notice that the newly added layer is drawn on top of others.

References Layer::added(), Layer::children, Layer::located(), Layer::parent, and Layer::Remove().

◆ Add() [2/2]

void Add ( Layer layer)

Adds the given layer as a child.

Notice that the newly added layer is drawn on top of others.

References Layer::Add().

◆ added()

virtual void added ( Layer layer)
protectedvirtual

Will be called when a layer is added.

This function will even be called when the given layer was already in the children.

Reimplemented in Window, and Window.

◆ begin()

Containers::Collection<Layer>::ConstIterator begin ( ) const

An iterator pointing to the start of the children.

References Layer::children.

◆ dotransformandclip()

◆ end()

Containers::Collection<Layer>::ConstIterator end ( ) const

An iterator pointing to the end of the children.

References Layer::children.

◆ First()

Containers::Collection<Layer>::ConstIterator First ( ) const

An iterator pointing to the start of the children.

References Layer::children.

◆ GetBounds()

Geometry::Bounds GetBounds ( ) const

Returns the boundaries of the layer.

References Layer::bounds.

◆ GetCalculatedSize()

Geometry::Size GetCalculatedSize ( ) const

Returns the size of the layer.

If any dimension size is 0, it means the layer will span its parent, this function will perform necessary calculation to get parent size.

References Layer::bounds, Layer::GetCalculatedSize(), Layer::GetLocation(), basic_Bounds< T_ >::GetSize(), Layer::GetSize(), and Layer::parent.

◆ GetEffectiveBounds()

Geometry::Bounds GetEffectiveBounds ( ) const

◆ GetHeight()

int GetHeight ( ) const

Returns the height of the layer.

References Layer::bounds, and basic_Bounds< T_ >::Height().

◆ GetLeft()

int GetLeft ( ) const

Returns the current location of the layer.

References Layer::bounds, and basic_Bounds< T_ >::Left.

◆ GetLocation()

Geometry::Point GetLocation ( ) const

Returns the current location of the layer.

References Layer::bounds, and basic_Bounds< T_ >::TopLeft().

◆ GetOrder()

int GetOrder ( ) const

Gets the current order of the stack.

0 means the layer is the bottommost layer in the stack

References Layer::children, and Layer::parent.

◆ GetParent()

virtual Layer& GetParent ( ) const
virtual

Returns the parent of this layer.

Throws if no parent is set. Use HasParent to make sure this layer has a parent

Exceptions
std::runtime_errorif no parent is set

References Layer::parent.

◆ GetSize()

Geometry::Size GetSize ( ) const

Returns the size of the layer.

References Layer::bounds, and basic_Bounds< T_ >::GetSize().

◆ GetTop()

int GetTop ( ) const

Returns the current location of the layer.

References Layer::bounds, and basic_Bounds< T_ >::Top.

◆ GetTopLevel() [1/2]

Layer& GetTopLevel ( )

◆ GetTopLevel() [2/2]

Layer& GetTopLevel ( ) const

Returns the top level layer that contains this layer.

References Layer::GetTopLevel(), and Layer::parent.

◆ GetWidth()

int GetWidth ( ) const

Returns the width of the layer.

References Layer::bounds, and basic_Bounds< T_ >::Width().

◆ HasParent()

bool HasParent ( ) const

Returns whether this layer has a parent.

References Layer::parent.

◆ Hide()

virtual void Hide ( )
virtual

Hides this layer.

Reimplemented in Window.

References Layer::isvisible.

◆ Insert() [1/2]

void Insert ( Layer layer,
long  under 
)

Inserts the given layer before the given index.

The newly inserted layer will be drawn under the layer in the given index

References Layer::added(), Layer::bounds, Layer::children, basic_Bounds< T_ >::Height(), Layer::located(), Layer::parent, Layer::Remove(), basic_Bounds< T_ >::SetHeight(), basic_Bounds< T_ >::SetWidth(), and basic_Bounds< T_ >::Width().

◆ Insert() [2/2]

void Insert ( Layer layer,
long  under 
)

Inserts the given layer before the given index.

The newly inserted layer will be drawn under the layer in the given index

References Layer::Insert().

◆ IsVisible()

virtual bool IsVisible ( ) const
virtual

Returns whether this layer is effectively visible.

Reimplemented in Window, and Window.

References Layer::isvisible, and Layer::parent.

◆ Last()

Containers::Collection<Layer>::ConstIterator Last ( ) const

An iterator pointing to the last item of the children.

References Layer::children.

◆ located()

virtual void located ( Layer parent)
protectedvirtual

Will be called when this layer is added to another.

Reimplemented in Window.

◆ Move() [1/2]

virtual void Move ( const Geometry::Point location)
virtual

Moves this layer to the given location.

Reimplemented in Window.

References Layer::bounds, and basic_Bounds< T_ >::Move().

◆ Move() [2/2]

virtual void Move ( int  x,
int  y 
)
virtual

Moves this layer to the given location.

Reimplemented in Window.

References Layer::bounds, and basic_Bounds< T_ >::Move().

◆ operator=() [1/2]

Layer& operator= ( const Layer )
delete

Copy assignment is deleted.

◆ operator=() [2/2]

Layer& operator= ( Layer &&  other)

Move assignment.

References Layer::children, Layer::parent, Layer::Remove(), and Layer::Swap().

◆ PlaceBefore()

void PlaceBefore ( int  before)

Places this layer before the given index.

This layer will be drawn above the given index.

References Layer::children, and Layer::parent.

◆ PlaceToBottom()

void PlaceToBottom ( )

Places this layer to the bottom of the layer stack.

References Layer::children, and Layer::parent.

◆ PlaceToTop()

void PlaceToTop ( )

Places this layer to the top of the layer stack its in.

This makes sure that its not being covered by other layers apart from its own children

References Layer::children, and Layer::parent.

◆ propagate_mouseevent()

bool propagate_mouseevent ( Input::Mouse::EventType  evet,
Geometry::Point  location,
Input::Mouse::Button  button,
float  amount,
MouseHandler handlers 
)
virtual

Propagates a mouse event.

Some events will be called directly. Do not use this function. Direct calls should never touch handlers. Input layers should cache perform transformations on direct calls. Direct calls should not be clipped. button is set only for Click/Down/Up events, amount will be set for Scroll/Zoom events. Mouse event system is not thread safe.

Reimplemented in Layer, and DropTarget.

References Layer::children, Layer::dotransformandclip(), Layer::GetCalculatedSize(), Gorgon::Input::needsclip(), Gorgon::Input::Mouse::Out, Layer::reverttransformandclip(), Gorgon::Transform, and Gorgon::Input::Keyboard::Keycodes::Up.

◆ Remove() [1/2]

void Remove ( Layer layer)

Removes the given layer.

References Layer::children, Layer::located(), Layer::parent, and Layer::removed().

◆ Remove() [2/2]

void Remove ( Layer layer)

Removes the given layer.

References Layer::Remove().

◆ removed()

virtual void removed ( Layer layer)
protectedvirtual

Will be called when a layer is removed.

This function will be called even if the given layer is not a child of this layer.

◆ Render()

void Render ( )
virtual

Renders the current layer, default handling is to pass the request to the sub-layers. Rendering is not thread safe.

Reimplemented in Window, ComponentStack, and Layer.

References Layer::children, Layer::dotransformandclip(), and Layer::reverttransformandclip().

◆ Resize() [1/2]

virtual void Resize ( const Geometry::Size size)
virtual

Resizes the layer to the given size.

Reimplemented in ComponentStack, and Window.

◆ Resize() [2/2]

virtual void Resize ( int  width,
int  height 
)
virtual

Resizes the layer to the given size.

Reimplemented in Window.

◆ reverttransformandclip()

void reverttransformandclip ( )
protected

Reverts previously done transformation.

References Gorgon::Clip, Gorgon::Offset, Gorgon::prev_Clip, Gorgon::prev_Offset, Gorgon::prev_Transform, and Gorgon::Transform.

◆ SetBounds()

void SetBounds ( const Geometry::Bounds bounds)

Sets the boundaries of this layer.

References Layer::bounds.

◆ SetHeight()

void SetHeight ( int  height)

Resizes the layer to the given size.

References Layer::bounds, and basic_Bounds< T_ >::SetHeight().

◆ setname()

void setname ( std::string  value)

For debugging.

References Layer::name.

◆ SetWidth()

void SetWidth ( int  width)

Resizes the layer to the given size.

References Layer::bounds, and basic_Bounds< T_ >::SetWidth().

◆ Show()

virtual void Show ( )
virtual

Displays this layer.

Reimplemented in Window.

References Layer::isvisible.

◆ Swap()

void Swap ( Layer other)

Swaps two layers, mostly used for move semantics.

References Layer::bounds, Layer::Children, Layer::children, Layer::isvisible, Layer::parent, and Gorgon::swap().

◆ TranslateToTopLevel()

virtual Geometry::Point TranslateToTopLevel ( Geometry::Point  location = {0, 0}) const
virtual

Translates the given location to the top level.

Member Data Documentation

◆ bounds

Geometry::Bounds bounds
protected

Bounds of this layer.

◆ Children

const Containers::Collection<Layer>& Children

Sub-layers that this layer holds, all the sub-layers are considered to be above current layer.

◆ children

Containers::Collection<Layer> children
protected

Child layers that this layer holds, all child layers are considered to be above current layer.

◆ EntireRegion

const Geometry::Bounds EntireRegion
static

When used as layer bounds, represents the entire region its placed in.

◆ isvisible

bool isvisible
protected

Whether this layer is visible, invisible layers will not be drawn or receive any events.

◆ name

std::string name
protected

For debugging.

◆ parent

Layer* parent
protected

Parent layer, could be nullptr.


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