Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
IdleState Class Referencefinal

Implements the Idle state behavior for the Blob animation. More...

#include <idle_state.h>

Inheritance diagram for IdleState:
Collaboration diagram for IdleState:

Public Member Functions

void Apply (std::vector< QPointF > &control_points, std::vector< QPointF > &velocity, QPointF &blob_center, const BlobConfig::BlobParameters &params) override
 Applies the idle animation effects (waves, rotation, centering) or the initial heartbeat effect. Called periodically by the animation loop when this state is active. If is_initializing_ is true, applies the heartbeat effect. Otherwise, applies the standard idle wave and rotation.
 
void ApplyForce (const QVector2D &force, std::vector< QPointF > &velocity, QPointF &blob_center, const std::vector< QPointF > &control_points, double blob_radius) override
 Applies an external force to the blob with dampening specific to the Idle state. The force is scaled based on the distance of each control point from the center and applied primarily to velocity. A small portion of the force is also applied directly to the blob's center position.
 
void ApplyHeartbeatEffect (const std::vector< QPointF > &control_points, std::vector< QPointF > &velocity, const QPointF &blob_center, const BlobConfig::BlobParameters &params)
 Applies a pulsating "heartbeat" effect to the blob. Used during the initial phase after entering the Idle state. The effect runs for a defined number of beats (kRequiredHeartbeats). Modifies control point velocities to create expansion and contraction.
 
 IdleState ()
 Constructs an IdleState object. Initializes phase offsets.
 
void ResetInitialization ()
 Resets the initialization state, causing the heartbeat effect to play again. Sets is_initializing_ to true and resets heartbeat counters.
 
void UpdatePhases ()
 Updates the internal phase variables used for the wave and rotation animations. Increments wave_phase, second_phase_, and rotation_phase_, wrapping them around 2*PI.
 
- Public Member Functions inherited from BlobState
virtual ~BlobState ()=default
 Virtual destructor. Ensures proper cleanup when deleting derived state objects through a base class pointer.
 

Private Attributes

int heartbeat_count_ = 0
 Counter for the number of heartbeats completed during initialization.
 
double heartbeat_phase_ = 0.0
 Current phase of the heartbeat animation cycle (0 to 2*PI).
 
BlobConfig::IdleParameters idle_params_
 Parameters specific to the idle animation (wave amplitude, frequency, phase).
 
bool is_initializing_ = true
 Flag indicating if the state is currently running the initial heartbeat animation.
 
double rotation_phase_ = 0.0
 Phase offset for the rotational effect.
 
double second_phase_ = 0.0
 Phase offset for the secondary wave effect.
 

Static Private Attributes

static constexpr int kRequiredHeartbeats = 1
 The number of heartbeat cycles to perform during initialization.
 

Detailed Description

Implements the Idle state behavior for the Blob animation.

This state applies subtle wave and rotation effects to the blob when it's not actively moving or resizing. It also includes an initial "heartbeat" animation upon entering the state. Forces applied in this state are dampened compared to other states.

Constructor & Destructor Documentation

◆ IdleState()

IdleState::IdleState ( )

Constructs an IdleState object. Initializes phase offsets.

Member Function Documentation

◆ Apply()

void IdleState::Apply ( std::vector< QPointF > & control_points,
std::vector< QPointF > & velocity,
QPointF & blob_center,
const BlobConfig::BlobParameters & params )
overridevirtual

Applies the idle animation effects (waves, rotation, centering) or the initial heartbeat effect. Called periodically by the animation loop when this state is active. If is_initializing_ is true, applies the heartbeat effect. Otherwise, applies the standard idle wave and rotation.

Parameters
control_pointsReference to the vector of current control point positions (modified).
velocityReference to the vector of current control point velocities (modified).
blob_centerReference to the blob's center position (modified).
paramsBlob appearance parameters (read-only).

Implements BlobState.

Here is the call graph for this function:

◆ ApplyForce()

void IdleState::ApplyForce ( const QVector2D & force,
std::vector< QPointF > & velocity,
QPointF & blob_center,
const std::vector< QPointF > & control_points,
double blob_radius )
overridevirtual

Applies an external force to the blob with dampening specific to the Idle state. The force is scaled based on the distance of each control point from the center and applied primarily to velocity. A small portion of the force is also applied directly to the blob's center position.

Parameters
forceThe external force vector to apply.
velocityReference to the vector of current control point velocities (modified).
blob_centerReference to the blob's center position (modified).
control_pointsReference to the vector of current control point positions (read-only).
blob_radiusThe current average radius of the blob (read-only).

Implements BlobState.

◆ ApplyHeartbeatEffect()

void IdleState::ApplyHeartbeatEffect ( const std::vector< QPointF > & control_points,
std::vector< QPointF > & velocity,
const QPointF & blob_center,
const BlobConfig::BlobParameters & params )

Applies a pulsating "heartbeat" effect to the blob. Used during the initial phase after entering the Idle state. The effect runs for a defined number of beats (kRequiredHeartbeats). Modifies control point velocities to create expansion and contraction.

Parameters
control_pointsReference to the vector of current control point positions (read-only).
velocityReference to the vector of current control point velocities (modified).
blob_centerThe current center position of the blob (read-only).
paramsBlob appearance parameters (read-only).
Here is the caller graph for this function:

◆ ResetInitialization()

void IdleState::ResetInitialization ( )

Resets the initialization state, causing the heartbeat effect to play again. Sets is_initializing_ to true and resets heartbeat counters.

◆ UpdatePhases()

void IdleState::UpdatePhases ( )

Updates the internal phase variables used for the wave and rotation animations. Increments wave_phase, second_phase_, and rotation_phase_, wrapping them around 2*PI.

Here is the caller graph for this function:

Member Data Documentation

◆ heartbeat_count_

int IdleState::heartbeat_count_ = 0
private

Counter for the number of heartbeats completed during initialization.

◆ heartbeat_phase_

double IdleState::heartbeat_phase_ = 0.0
private

Current phase of the heartbeat animation cycle (0 to 2*PI).

◆ idle_params_

BlobConfig::IdleParameters IdleState::idle_params_
private

Parameters specific to the idle animation (wave amplitude, frequency, phase).

◆ is_initializing_

bool IdleState::is_initializing_ = true
private

Flag indicating if the state is currently running the initial heartbeat animation.

◆ kRequiredHeartbeats

int IdleState::kRequiredHeartbeats = 1
staticconstexprprivate

The number of heartbeat cycles to perform during initialization.

◆ rotation_phase_

double IdleState::rotation_phase_ = 0.0
private

Phase offset for the rotational effect.

◆ second_phase_

double IdleState::second_phase_ = 0.0
private

Phase offset for the secondary wave effect.


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