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

Position, rotation, and scale component for 2D entities. More...

#include <spk_transform_2d.hpp>

Inheritance diagram for spk::Transform2D:
Inheritance graph
Collaboration diagram for spk::Transform2D:
Collaboration graph

Public Types

using EditionContract = spk::ContractProvider::Contract
 Subscription contract type for transform edits.
using EditionJob = spk::ContractProvider::Job
 Job callback type for transform edits.
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.

Public Member Functions

 Transform2D (const std::wstring &p_name)
 Creates a transform component.
const spk::Matrix4x4localModelMatrix () const
 Returns the local model matrix.
const spk::Matrix4x4modelMatrix () const
 Returns the world model matrix.
const spk::Matrix4x4localInverseModelMatrix () const
 Returns the inverse local model matrix.
const spk::Matrix4x4inverseModelMatrix () const
 Returns the inverse world model matrix.
void setLayer (const float &p_layer)
 Sets the rendering layer.
const float & layer () const
 Returns the local layer value.
float globalLayer () const
 Returns the world layer value.
void setPosition (const spk::Vector2 &p_position)
 Sets the local position.
const spk::Vector2position () const
 Returns the local position.
spk::Vector2 globalPosition () const
 Returns the world position.
void setScale (const spk::Vector2 &p_scale)
 Sets the local scale.
const spk::Vector2scale () const
 Returns the local scale.
spk::Vector2 globalScale () const
 Returns the world scale.
void setRotation (const float &p_rotation)
 Sets the local rotation.
const float & rotation () const
 Returns the local rotation.
float globalRotation () const
 Returns the world rotation.
void applyForce (const spk::Force2D &p_force)
 Applies a force to the transform velocity.
const spk::Force2Dvelocity () const
 Returns the current velocity.
void notifyParentTransformEdited ()
 Notifies the parent that this transform changed.
EditionContract subscribeToEdition (const EditionJob &p_job)
 Subscribes to transform edit events.
Public Member Functions inherited from spk::Component2D
 Component2D (const std::wstring &p_name)
 Builds a 2D component with a name.
Entity2Downer ()
 Returns the 2D owner entity.
const Entity2Downer () const
 Returns the 2D owner entity.
Public Member Functions inherited from spk::Component
 Component (const std::wstring &p_name)
 Builds a component with a name.
 ~Component () override
 Virtual destructor.
void setName (const std::wstring &p_name)
 Sets the component name.
void setPriority (const int &p_priority)
 Sets the component priority.
const std::wstring & name () const
 Returns the component name.
int priority () const
 Returns the component priority.
Entityowner ()
 Returns the owning entity.
const Entityowner () const
 Returns the owning entity.
virtual void start ()
 Called when the component starts.
virtual void awake ()
 Called when the component becomes active.
virtual void sleep ()
 Called when the component is put to sleep.
virtual void stop ()
 Called when the component stops.
virtual void handleGeometryChange (const spk::Extend2D &p_geometry)
 Handles geometry change events.
virtual void handlePaintEvent (spk::PaintEvent &p_event)
 Handles paint events.
virtual void handleKeyPressEvent (spk::KeyPressEvent &p_event)
 Handles key press events.
virtual void handleKeyReleaseEvent (spk::KeyReleaseEvent &p_event)
 Handles key release events.
virtual void handleGlyphEvent (spk::GlyphEvent &p_event)
 Handles glyph input events.
virtual void handleMousePressEvent (spk::MousePressEvent &p_event)
 Handles mouse press events.
virtual void handleMouseReleaseEvent (spk::MouseReleaseEvent &p_event)
 Handles mouse release events.
virtual void handleMouseDoubleClickEvent (spk::MouseDoubleClickEvent &p_event)
 Handles mouse double-click events.
virtual void handleMouseMotionEvent (spk::MouseMotionEvent &p_event)
 Handles mouse motion events.
virtual void handleMouseWheelEvent (spk::MouseWheelEvent &p_event)
 Handles mouse wheel events.
virtual void handleEnterResizeModeEvent (spk::EnterResizeModeEvent &p_event)
 Handles enter resize mode events.
virtual void handleResizeEvent (spk::ResizeEvent &p_event)
 Handles resize events.
virtual void handleExitResizeModeEvent (spk::ExitResizeModeEvent &p_event)
 Handles exit resize mode events.
virtual void handleQuitEvent (spk::QuitEvent &p_event)
 Handles quit events.
virtual void handleMoveEvent (spk::MoveEvent &p_event)
 Handles move events.
virtual void handleFullScreenModeEvent (spk::FullScreenModeEvent &p_event)
 Handles fullscreen mode events.
virtual void handleMaximizedModeEvent (spk::MaximizedModeEvent &p_event)
 Handles maximized mode events.
virtual void handleFocusEvent (spk::FocusEvent &p_event)
 Handles focus events.
virtual void handleUpdateEvent (spk::UpdateEvent &p_event)
 Handles update events.
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.

Protected Member Functions

void _onUpdateEvent (spk::UpdateEvent &p_event) override
 Updates transform state during update events.
const Transform2D_parentTransform () const
 Returns the parent transform if any.
void _releaseGlobalCache ()
 Clears cached global transform data.
void _notifyEdition ()
 Notifies subscribers that the transform changed.
Protected Member Functions inherited from spk::Component
virtual void _onGeometryChange (const spk::Extend2D &p_geometry)
 Handles geometry changes before public callbacks.
virtual void _onPaintEvent (spk::PaintEvent &p_event)
 Handles paint events before public callbacks.
virtual void _onKeyPressEvent (spk::KeyPressEvent &p_event)
 Handles key press events before public callbacks.
virtual void _onKeyReleaseEvent (spk::KeyReleaseEvent &p_event)
 Handles key release events before public callbacks.
virtual void _onGlyphEvent (spk::GlyphEvent &p_event)
 Handles glyph input events before public callbacks.
virtual void _onMousePressEvent (spk::MousePressEvent &p_event)
 Handles mouse press events before public callbacks.
virtual void _onMouseReleaseEvent (spk::MouseReleaseEvent &p_event)
 Handles mouse release events before public callbacks.
virtual void _onMouseDoubleClickEvent (spk::MouseDoubleClickEvent &p_event)
 Handles mouse double-click events before public callbacks.
virtual void _onMouseMotionEvent (spk::MouseMotionEvent &p_event)
 Handles mouse motion events before public callbacks.
virtual void _onMouseWheelEvent (spk::MouseWheelEvent &p_event)
 Handles mouse wheel events before public callbacks.
virtual void _onEnterResizeModeEvent (spk::EnterResizeModeEvent &p_event)
 Handles enter resize mode events before public callbacks.
virtual void _onResizeEvent (spk::ResizeEvent &p_event)
 Handles resize events before public callbacks.
virtual void _onExitResizeModeEvent (spk::ExitResizeModeEvent &p_event)
 Handles exit resize mode events before public callbacks.
virtual void _onQuitEvent (spk::QuitEvent &p_event)
 Handles quit events before public callbacks.
virtual void _onMoveEvent (spk::MoveEvent &p_event)
 Handles move events before public callbacks.
virtual void _onFullScreenModeEvent (spk::FullScreenModeEvent &p_event)
 Handles fullscreen mode events before public callbacks.
virtual void _onMaximizedModeEvent (spk::MaximizedModeEvent &p_event)
 Handles maximized mode events before public callbacks.
virtual void _onFocusEvent (spk::FocusEvent &p_event)
 Handles focus events before public callbacks.

Detailed Description

Position, rotation, and scale component for 2D entities.

Constructor & Destructor Documentation

◆ Transform2D()

spk::Transform2D::Transform2D ( const std::wstring & p_name)
explicit

Creates a transform component.

Parameters
p_nameComponent name.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ _onUpdateEvent()

void spk::Transform2D::_onUpdateEvent ( spk::UpdateEvent & p_event)
overrideprotectedvirtual

Updates transform state during update events.

Parameters
p_eventUpdate event.

Reimplemented from spk::Component.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parentTransform()

const Transform2D * spk::Transform2D::_parentTransform ( ) const
protected

Returns the parent transform if any.

Returns
Parent transform pointer or nullptr.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyForce()

void spk::Transform2D::applyForce ( const spk::Force2D & p_force)

Applies a force to the transform velocity.

Parameters
p_forceForce to apply.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalLayer()

float spk::Transform2D::globalLayer ( ) const

Returns the world layer value.

Returns
Layer value including parents.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalPosition()

spk::Vector2 spk::Transform2D::globalPosition ( ) const

Returns the world position.

Returns
World position.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalRotation()

float spk::Transform2D::globalRotation ( ) const

Returns the world rotation.

Returns
Rotation angle in radians.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalScale()

spk::Vector2 spk::Transform2D::globalScale ( ) const

Returns the world scale.

Returns
World scale.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inverseModelMatrix()

const spk::Matrix4x4 & spk::Transform2D::inverseModelMatrix ( ) const

Returns the inverse world model matrix.

Returns
Inverse world matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ layer()

const float & spk::Transform2D::layer ( ) const

Returns the local layer value.

Returns
Layer value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ localInverseModelMatrix()

const spk::Matrix4x4 & spk::Transform2D::localInverseModelMatrix ( ) const

Returns the inverse local model matrix.

Returns
Inverse local matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ localModelMatrix()

const spk::Matrix4x4 & spk::Transform2D::localModelMatrix ( ) const

Returns the local model matrix.

Returns
Local transform matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ modelMatrix()

const spk::Matrix4x4 & spk::Transform2D::modelMatrix ( ) const

Returns the world model matrix.

Returns
World transform matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ position()

const spk::Vector2 & spk::Transform2D::position ( ) const

Returns the local position.

Returns
Position value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotation()

const float & spk::Transform2D::rotation ( ) const

Returns the local rotation.

Returns
Rotation angle in radians.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scale()

const spk::Vector2 & spk::Transform2D::scale ( ) const

Returns the local scale.

Returns
Scale value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLayer()

void spk::Transform2D::setLayer ( const float & p_layer)

Sets the rendering layer.

Parameters
p_layerLayer value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPosition()

void spk::Transform2D::setPosition ( const spk::Vector2 & p_position)

Sets the local position.

Parameters
p_positionNew position.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRotation()

void spk::Transform2D::setRotation ( const float & p_rotation)

Sets the local rotation.

Parameters
p_rotationRotation angle in radians.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScale()

void spk::Transform2D::setScale ( const spk::Vector2 & p_scale)

Sets the local scale.

Parameters
p_scaleScale value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ subscribeToEdition()

Transform2D::EditionContract spk::Transform2D::subscribeToEdition ( const EditionJob & p_job)

Subscribes to transform edit events.

Parameters
p_jobCallback invoked on edits.
Returns
Subscription contract handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ velocity()

const spk::Force2D & spk::Transform2D::velocity ( ) const

Returns the current velocity.

Returns
Velocity force.
Here is the call graph for this function:
Here is the caller graph for this function:

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