Stores and manages a scene's render layers. More...
#include <RenderLayerContainer.h>
Public Types | |
using | Callback = std::function< void(const RenderLayer::Ptr &)> |
Callback. More... | |
using | Ptr = std::unique_ptr< Object > |
Unique object pointer. More... | |
Public Member Functions | |
RenderLayerContainer (const RenderLayerContainer &)=delete | |
Copy constructor. More... | |
RenderLayerContainer & | operator= (const RenderLayerContainer &)=delete |
Copy assignment operator. More... | |
RenderLayerContainer (RenderLayerContainer &&) noexcept=default | |
Move constructor. More... | |
RenderLayerContainer & | operator= (RenderLayerContainer &&) noexcept=default |
Move assignment operator. More... | |
RenderLayer::Ptr | create (const std::string &name) |
Create a layer. More... | |
void | add (Drawable &drawable, int renderOrder=0u, const std::string &renderLayer="default") |
Add a drawable object to a render layer in the container. More... | |
std::string | getClassName () const override |
Get the name of this class. More... | |
RenderLayer::Ptr | front () const |
Get the render layer at the front. More... | |
RenderLayer::Ptr | back () const |
Get the render layer at the back. More... | |
RenderLayer::Ptr | findByIndex (unsigned int index) const |
Get the layer at a given index. More... | |
RenderLayer::Ptr | findByName (const std::string &name) const |
Get a layer with the given name. More... | |
bool | isIndexValid (unsigned int index) const |
Check if a given index is within bounds or not. More... | |
bool | hasLayer (const std::string &name) const |
Check if the container has a layer with the given name. More... | |
bool | removeByIndex (unsigned int index) |
Remove the layer at the given index. More... | |
bool | removeByName (const std::string &name) |
Remove the layer with the given name from the container. More... | |
void | removeAll () |
Remove all layers from the container. More... | |
void | moveUp (unsigned int index) |
Move a layer one level up. More... | |
void | moveUp (const std::string &name) |
Move the layer up one level. More... | |
void | moveDown (unsigned int index) |
Move a layer one level down. More... | |
void | moveDown (const std::string &name) |
Move a layer one level down. More... | |
void | moveToFront (unsigned int index) |
Move a layer to the highest level (foreground) More... | |
void | moveToFront (const std::string &name) |
Move a layer to the highest level (foreground) More... | |
void | sendToBack (unsigned int index) |
Move a layer to the lowest level (background) More... | |
void | sendToBack (const std::string &name) |
Move a layer to the lowest level (background) More... | |
bool | swap (unsigned int layerOneIndex, unsigned int layerTwoIndex) |
Swap the render positions of two layers. More... | |
void | swap (const std::string &layerOne, const std::string &layerTwo) |
Swap the positions of two layers. More... | |
std::size_t | getCount () const |
Get the number of layer in the container. More... | |
void | forEachLayer (const Callback &callback) const |
Execute a callback for each layer in the container. More... | |
void | render (priv::RenderTarget &window) const |
~RenderLayerContainer () override | |
Destructor. More... | |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the tag assigned to the object. More... | |
unsigned int | getObjectId () const |
Get the unique id of the object. More... | |
virtual std::string | getClassType () const |
Get the name of the direct parent of an object instance. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to a specific property change event. More... | |
int | onPropertyChange (const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to any property change event. More... | |
void | suspendedEventListener (int id, bool suspend) |
Pause or resume execution of an event listener. More... | |
bool | isEventListenerSuspended (int id) const |
Check if an event listener is suspended or not. More... | |
bool | removeEventListener (const std::string &event, int id) |
Remove an event listener from an event. More... | |
bool | removeEventListener (int id) |
Remove an event listener. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | isSameObjectAs (const Object &other) const |
Check if another object is the same instance as this object. More... | |
Protected Member Functions | |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emitDestruction () |
Emit a destruction event. More... | |
Protected Attributes | |
EventEmitter | eventEmitter_ |
Event dispatcher. More... | |
Friends | |
class | Scene |
More... | |
class | Grid2D |
Stores and manages a scene's render layers.
A render layer container determines the order in which objects are drawn to the render window. After creating an object (e.g sprite), you specify the RenderLayer in which the object belongs to and the object will be rendered on top or below other objects depending on the index of its render layer in the render layer container.
Render layers are added to the container in ascending order with an index of 0 representing the the furthest background. Therefore, the last added render layer will always be the foreground. The layers are drawn from index 0 going upwards. Note that you cannot change the index of a layer (indexes will always be arranged in ascending order), however you can change the layer at a given index. This means that you can specify which layer gets rendered on top of which layer using appropriate member function. For example if you add a mountain sprite to a render layer at index 5 and a tree sprite to a render layer at index 6, then the mountain will be rendered first followed by the tree
This class is not directly instantiatable, it is created when you instantiate a Scene object. Each scene instance has its own render layers and a single render layer container accessed with ime::Scene::getRenderLayers
Definition at line 60 of file RenderLayerContainer.h.
using ime::RenderLayerContainer::Callback = std::function<void(const RenderLayer::Ptr&)> |
Callback.
Definition at line 62 of file RenderLayerContainer.h.
|
inherited |
|
delete |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
override |
Destructor.
void ime::RenderLayerContainer::add | ( | Drawable & | drawable, |
int | renderOrder = 0u , |
||
const std::string & | renderLayer = "default" |
||
) |
Add a drawable object to a render layer in the container.
drawable | The drawable object to be added |
renderOrder | The render order of the object in the render layer |
renderLayer | The RenderLayer to add the object belongs to |
If the render layer is unspecified or the specified layer cannot be found then the drawable will be added to the 'default' layer. The 'default' render layer is created by the Scene when you instantiate it. Note that the 'default' layer may be deleted from the container, however you must make sure that the layer you specify during a call to this function already exists in the container otherwise undefined behavior
RenderLayer::Ptr ime::RenderLayerContainer::back | ( | ) | const |
Get the render layer at the back.
RenderLayer::Ptr ime::RenderLayerContainer::create | ( | const std::string & | name | ) |
Create a layer.
name | The name of the layer to be created |
Note that the container keeps a pointer to the layer after it is created, therefore you don't need to keep the returned pointer alive after using it
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
protectedinherited |
Emit a destruction event.
RenderLayer::Ptr ime::RenderLayerContainer::findByIndex | ( | unsigned int | index | ) | const |
Get the layer at a given index.
index | The index of the layer to retrieve |
RenderLayer::Ptr ime::RenderLayerContainer::findByName | ( | const std::string & | name | ) | const |
Get a layer with the given name.
name | The name of the layer to retrieve |
void ime::RenderLayerContainer::forEachLayer | ( | const Callback & | callback | ) | const |
Execute a callback for each layer in the container.
callback | The callback to be executed |
RenderLayer::Ptr ime::RenderLayerContainer::front | ( | ) | const |
Get the render layer at the front.
|
overridevirtual |
|
virtualinherited |
Get the name of the direct parent of an object instance.
In contrast to getClassName() which returns the name of the concrete class, this function returns the name of the concrete class's base class. This function is implemented by all derived classes of ime::Object which also serve as base classes. For classes whose direct parent is this class, this function will return the name of this class
Reimplemented in ime::audio::Audio, ime::GameObject, ime::GridMover, ime::Collider, ime::Joint, ime::Drawable, ime::Shape, and ime::SpriteImage.
std::size_t ime::RenderLayerContainer::getCount | ( | ) | const |
Get the number of layer in the container.
|
inherited |
Get the unique id of the object.
Note that each instance of ime::Object has a unique id
|
inherited |
bool ime::RenderLayerContainer::hasLayer | ( | const std::string & | name | ) | const |
Check if the container has a layer with the given name.
name | The name of the layer to be checked |
|
inherited |
Check if an event listener is suspended or not.
id | The identification number of the listener to be checked |
This function also returns false if the specified event listener does not exist
bool ime::RenderLayerContainer::isIndexValid | ( | unsigned int | index | ) | const |
Check if a given index is within bounds or not.
index | The index to be checked |
|
inherited |
Check if another object is the same instance as this object.
other | The object to compare against this object |
void ime::RenderLayerContainer::moveDown | ( | const std::string & | name | ) |
Move a layer one level down.
name | The name of the layer to be moved |
This function has no effect if the layer does not exist or the layer is already at the lowest level
void ime::RenderLayerContainer::moveDown | ( | unsigned int | index | ) |
Move a layer one level down.
index | The index of the layer to be moved |
This function has no effect if the layer does not exist or the layer is already at the lowest level
void ime::RenderLayerContainer::moveToFront | ( | const std::string & | name | ) |
Move a layer to the highest level (foreground)
name | The name of the level to be moved |
This function has no effect if the layer does not exist or the layer is already at the highest level
void ime::RenderLayerContainer::moveToFront | ( | unsigned int | index | ) |
Move a layer to the highest level (foreground)
index | The index of the layer to be moved |
This function has no effect if the layer does not exist or the layer is already at the highest level
void ime::RenderLayerContainer::moveUp | ( | const std::string & | name | ) |
Move the layer up one level.
name | The name of the layer to be moved |
This function has no effect if the layer does not exist
void ime::RenderLayerContainer::moveUp | ( | unsigned int | index | ) |
Move a layer one level up.
index | The index of the layer to be moved |
This function has no effect if the index is out of bounds or the layer is already at the highest level
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it
|
inherited |
Add an event listener to any property change event.
callback | The function to be executed when any property changes |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to add an event listener to |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
callback | The function to be executed when the property changes |
A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called
Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.
|
delete |
Copy assignment operator.
|
defaultnoexcept |
Move assignment operator.
void ime::RenderLayerContainer::removeAll | ( | ) |
Remove all layers from the container.
bool ime::RenderLayerContainer::removeByIndex | ( | unsigned int | index | ) |
Remove the layer at the given index.
index | The index of the layer to be removed |
bool ime::RenderLayerContainer::removeByName | ( | const std::string & | name | ) |
Remove the layer with the given name from the container.
name | The name of the container to be removed |
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove an event listener from |
id | The unique id of the event listener to be removed |
|
inherited |
Remove an event listener.
id | The id of the event listener to be removed |
void ime::RenderLayerContainer::sendToBack | ( | const std::string & | name | ) |
Move a layer to the lowest level (background)
name | The name of the layer ot be moved |
This function has no effect if the layer does not exist or the layer is already at the lowest level
void ime::RenderLayerContainer::sendToBack | ( | unsigned int | index | ) |
Move a layer to the lowest level (background)
index | The index of the layer ot be moved |
This function has no effect if the layer does not exist or the layer is already at the lowest level
|
inherited |
Assign the object an alias.
tag | The alias of the object |
This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag
By default, the tag is an empty string
|
inherited |
Pause or resume execution of an event listener.
id | The event listeners unique identification number |
suspend | True to suspend/pause or false to unsuspend/resume |
void ime::RenderLayerContainer::swap | ( | const std::string & | layerOne, |
const std::string & | layerTwo | ||
) |
Swap the positions of two layers.
layerOne | The name of the first layer |
layerTwo | The name iof the second layer |
This function has no effect of either of the layers cannot be found
bool ime::RenderLayerContainer::swap | ( | unsigned int | layerOneIndex, |
unsigned int | layerTwoIndex | ||
) |
Swap the render positions of two layers.
layerOneIndex | The index of the first layer |
layerTwoIndex | The index of the second layer |
|
friend |
Definition at line 357 of file RenderLayerContainer.h.
|
friend |
Needs access to the constructor
Definition at line 356 of file RenderLayerContainer.h.
|
protectedinherited |