Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Entity2D Class Reference

Entity owning a Transform2D component. More...

#include <spk_entity_2d.hpp>

Inheritance diagram for spk::Entity2D:
Inheritance graph
Collaboration diagram for spk::Entity2D:
Collaboration graph

Public Member Functions

 Entity2D (const std::wstring &p_name, spk::Entity *p_parent=nullptr)
 Creates a 2D entity with an optional parent.
Transform2Dtransform ()
 Returns the entity transform.
const Transform2Dtransform () const
 Returns the entity transform.
void notifyChildTransformsEdited ()
 Notifies children that their parent transform changed.
Public Member Functions inherited from spk::Entity
 Entity (const std::wstring &p_name, Entity *p_owner=nullptr)
 Creates an entity with a name and optional owner.
 Entity ()
 Creates an unnamed entity.
 Entity (const Entity &)=delete
Entityoperator= (const Entity &)=delete
virtual void setName (const std::wstring &p_name)
 Sets the entity name.
void setPriority (const int &p_priority)
 Sets the entity priority.
void addTag (const std::wstring &p_tag)
 Adds a tag to the entity.
void removeTag (const std::wstring &p_tag)
 Removes a tag from the entity.
void clearTags ()
 Clears all tags.
bool containTag (const std::wstring &p_tag) const
 Checks if the entity contains a tag.
void setEngine (GameEngine *p_engine)
 Assigns the owning game engine.
GameEngineengine ()
 Returns the owning game engine.
const GameEngineengine () const
 Returns the owning game engine.
const std::wstring & name () const
 Returns the entity name.
const std::set< std::wstring > & tags () const
 Returns the set of tags.
int priority () const
 Returns the entity priority.
size_t componentCount () const
 Returns the number of components.
void removeAllComponents ()
 Removes all components from the entity.
void addChild (Entity *p_child) override
 Adds a child entity.
void removeChild (Entity *p_child) override
 Removes a child entity.
void clearChildren ()
 Removes all children.
std::vector< Entity * > & children () override
 Returns mutable children list.
const std::vector< Entity * > & children () const override
 Returns children list.
template<typename TComponentType, typename... TArgs>
TComponentType & addComponent (TArgs &&...p_args)
 Creates and adds a component of the given type.
void removeComponent (const std::wstring &p_name)
 Removes a component by name.
template<typename TComponentType>
TComponentType * getComponent (const std::wstring &p_name=L"")
 Returns the first component matching the type and optional name.
template<typename TComponentType>
std::vector< TComponentType * > getComponents ()
 Returns all components matching the type.
template<typename TComponentType>
const TComponentType * getComponent (const std::wstring &p_name=L"") const
 Returns the first component matching the type and optional name.
template<typename TComponentType>
std::vector< const TComponentType * > getComponents () const
 Returns all components matching the type.
virtual void handleGeometryChange (const spk::Extend2D &p_geometry) final
 Dispatches geometry change events to components.
virtual void handlePaintEvent (spk::PaintEvent &p_event) final
 Dispatches paint events to components.
virtual void handleKeyPressEvent (spk::KeyPressEvent &p_event) final
 Dispatches key press events to components.
virtual void handleKeyReleaseEvent (spk::KeyReleaseEvent &p_event) final
 Dispatches key release events to components.
virtual void handleGlyphEvent (spk::GlyphEvent &p_event) final
 Dispatches glyph input events to components.
virtual void handleMousePressEvent (spk::MousePressEvent &p_event) final
 Dispatches mouse press events to components.
virtual void handleMouseReleaseEvent (spk::MouseReleaseEvent &p_event) final
 Dispatches mouse release events to components.
virtual void handleMouseDoubleClickEvent (spk::MouseDoubleClickEvent &p_event) final
 Dispatches mouse double click events to components.
virtual void handleMouseMotionEvent (spk::MouseMotionEvent &p_event) final
 Dispatches mouse motion events to components.
virtual void handleMouseWheelEvent (spk::MouseWheelEvent &p_event) final
 Dispatches mouse wheel events to components.
virtual void handleEnterResizeModeEvent (spk::EnterResizeModeEvent &p_event) final
 Dispatches enter resize mode events to components.
virtual void handleResizeEvent (spk::ResizeEvent &p_event) final
 Dispatches resize events to components.
virtual void handleExitResizeModeEvent (spk::ExitResizeModeEvent &p_event) final
 Dispatches exit resize mode events to components.
virtual void handleQuitEvent (spk::QuitEvent &p_event) final
 Dispatches quit events to components.
virtual void handleMoveEvent (spk::MoveEvent &p_event) final
 Dispatches move events to components.
virtual void handleFullScreenModeEvent (spk::FullScreenModeEvent &p_event) final
 Dispatches fullscreen events to components.
virtual void handleMaximizedModeEvent (spk::MaximizedModeEvent &p_event) final
 Dispatches maximized events to components.
virtual void handleFocusEvent (spk::FocusEvent &p_event) final
 Dispatches focus events to components.
virtual void handleUpdateEvent (spk::UpdateEvent &p_event) final
 Dispatches update events to components.
void sortChildren ()
 Sorts children by priority.
void sortComponent ()
 Sorts components by priority.
EntitygetChild (const std::wstring &p_name)
 Returns the first child matching the name.
const EntitygetChild (const std::wstring &p_name) const
 Returns the first child matching the name.
std::vector< Entity * > getChildren (const std::wstring &p_name)
 Returns all children matching the name.
std::vector< const Entity * > getChildren (const std::wstring &p_name) const
 Returns all children matching the name.
bool contains (const std::wstring &p_name) const
 Checks if a child with the name exists.
size_t count (const std::wstring &p_name) const
 Counts children matching the name.
EntitygetChildByTag (const std::wstring &p_tag)
 Returns the first child matching a tag.
const EntitygetChildByTag (const std::wstring &p_tag) const
 Returns the first child matching a tag.
std::vector< Entity * > getChildrenByTag (const std::wstring &p_tag)
 Returns all children matching a tag.
std::vector< const Entity * > getChildrenByTag (const std::wstring &p_tag) const
 Returns all children matching a tag.
bool containsTag (const std::wstring &p_tag) const
 Checks if a child with the tag exists.
size_t countTag (const std::wstring &p_tag) const
 Counts children matching a tag.
EntitygetChildByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And)
 Returns the first child matching a set of tags.
const EntitygetChildByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Returns the first child matching a set of tags.
std::vector< Entity * > getChildrenByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And)
 Returns all children matching a set of tags.
std::vector< const Entity * > getChildrenByTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Returns all children matching a set of tags.
bool containsTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Checks if a child matching all tags exists.
size_t countTags (const std::span< const std::wstring > &p_tags, spk::BinaryOperator p_binaryOperator=spk::BinaryOperator::And) const
 Counts children matching all tags.
Public Member Functions inherited from spk::InherenceObject< Entity >
Entityparent () const
 Returns the parent pointer.
void clearChildren ()
 Clears the children list and resets each child's parent pointer.
Public Member Functions inherited from spk::ActivableObject
 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.

Additional Inherited Members

Public Types inherited from spk::Entity
using Contract = spk::ActivableObject::Contract
 Contract type for activation callbacks.
using Job = spk::ActivableObject::Job
 Job callback type for activation callbacks.
Public Types inherited from spk::ActivableObject
using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.

Detailed Description

Entity owning a Transform2D component.

Constructor & Destructor Documentation

◆ Entity2D()

spk::Entity2D::Entity2D ( const std::wstring & p_name,
spk::Entity * p_parent = nullptr )

Creates a 2D entity with an optional parent.

Parameters
p_nameEntity name.
p_parentOptional parent entity.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ transform() [1/2]

Transform2D & spk::Entity2D::transform ( )

Returns the entity transform.

Returns
Reference to the Transform2D component.
Here is the caller graph for this function:

◆ transform() [2/2]

const Transform2D & spk::Entity2D::transform ( ) const

Returns the entity transform.

Returns
Const reference to the Transform2D component.

The documentation for this class was generated from the following files:
  • includes/structure/engine/2d/spk_entity_2d.hpp
  • srcs/structure/engine/2d/spk_entity_2d.cpp