|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
Main widget responsible for rendering and animating the dynamic blob. More...
#include <blob_animation.h>
Public Slots | |
| void | hideAnimation () |
| Hides the animation widget and pauses event tracking. | |
| void | setBackgroundColor (const QColor &color) |
| Sets the background color used for rendering. Updates the grid buffer and triggers a repaint. | |
| void | setBlobColor (const QColor &color) |
| Sets the border color of the blob. Triggers a repaint. | |
| void | setGridColor (const QColor &color) |
| Sets the color of the background grid lines. Updates the grid buffer and triggers a repaint. | |
| void | setGridSpacing (int spacing) |
| Sets the spacing between background grid lines. Updates the grid buffer and triggers a repaint. | |
| void | showAnimation () |
| Makes the animation widget visible and resumes event tracking. | |
Signals | |
| void | visualizationReset () |
| Emitted when the entire visualization is reset via ResetVisualization(). Allows other UI elements to update accordingly. | |
Public Member Functions | |
| BlobAnimation (QWidget *parent=nullptr) | |
| Constructs the BlobAnimation widget. Initializes parameters, states, event handlers, timers, and the physics thread. Sets up OpenGL format and connects signals/slots between components. | |
| QPointF | GetBlobCenter () const |
| Gets the current calculated center position of the blob. If control points are not yet initialized, return the center of the widget. | |
| void | PauseAllEventTracking () |
| Pauses all event tracking mechanisms (window move/resize). Stops timers, clears movement buffers, and disables the event handler. Switches the blob state to Idle. | |
| void | ResetLifeColor () |
| Resets the blob's border color to its original value before SetLifeColor() was called. | |
| void | ResetVisualization () |
| Resets the entire blob visualization to its initial state. Resets blob position, shape, and dynamics, resets the HUD, and emits visualizationReset(). | |
| void | ResumeAllEventTracking () |
| Resumes all event tracking mechanisms after being paused. Restarts timers, enables the event handler, resets the blob state, and forces a redrawing. | |
| void | SetLifeColor (const QColor &color) |
| Temporarily sets the blob's border color (e.g., for highlighting). Stores the original color to be restored later by ResetLifeColor(). | |
| ~BlobAnimation () override | |
| Destructor. Stops timers, cleans up OpenGL resources, joins the physics thread, and deletes state objects. | |
Protected Member Functions | |
| QRectF | CalculateBlobBoundingRect () |
| Calculates the bounding rectangle encompassing the blob's control points, including margins for border and glow. Used for optimizing paint events. | |
| void | DrawGrid () |
| Draws the background grid using a separate shader program and line primitives. Generates vertex data for horizontal and vertical lines based on grid spacing. | |
| bool | event (QEvent *event) override |
| Overridden generic event handler. | |
| bool | eventFilter (QObject *watched, QEvent *event) override |
| Overridden event filter. Delegates filtering primarily to BlobEventHandler. | |
| void | initializeGL () override |
| Initializes OpenGL functions, shaders, VAO, and VBO. Called once before the first paintGL call. | |
| void | paintEvent (QPaintEvent *event) override |
| Overridden paint event handler. Delegates rendering to BlobRenderer after checking if the paint area intersects the blob's bounding box. Uses a cached background pixmap for efficiency. | |
| void | paintGL () override |
| Renders the blob and grid using OpenGL. Called whenever the widget needs to be painted. Binds shaders, sets uniforms (projection matrix, colors, etc.), updates VBO data, and draws the blob geometry. | |
| void | resizeEvent (QResizeEvent *event) override |
| Overridden resize event handler. Delegates processing to BlobEventHandler. | |
| void | resizeGL (int w, int h) override |
| Handles OpenGL viewport updates when the widget is resized. | |
| void | UpdateBlobGeometry () |
| Updates the internal vertex buffer (gl_vertices_) based on the current blob_center_ and control_points_. Prepares the geometry data for rendering with GL_TRIANGLE_FAN. | |
Private Slots | |
| void | CheckWindowPosition () |
| Slot connected to window_position_timer_. Called frequently to check the window position. Adds position samples to the BlobTransitionManager if the window has moved or if the buffer is stale. | |
| void | HandleResizeTimeout () |
| Slot connected to resize_debounce_timer_. Called after a short delay following resize events. Resets the blob to the center, resets the grid buffer, and updates the widget. | |
| void | onStateResetTimeout () |
| Slot connected to state_reset_timer_. Called after a period of inactivity in Moving or Resizing state. Automatically switches the state back to Idle. | |
| void | processMovementBuffer () |
| Slot (or helper called by updateAnimation) to process the window movement buffer via BlobTransitionManager. Provides callbacks to apply inertia forces and update the last known window position. | |
| void | updateAnimation () |
| Slot connected to animation_timer_. Called periodically (~60 FPS) to update the animation state. Processes movement buffer, applies current state logic, and triggers a repaint if needed. | |
| void | updatePhysics () |
| Slot (or helper called by physics thread) to update the blob's physics simulation. Calls BlobPhysics methods for internal forces, collisions, smoothing, and constraints. | |
Private Member Functions | |
| void | ApplyForces (const QVector2D &force) |
| Applies an external force vector to the blob. Delegates force application to the current state object. | |
| void | ApplyIdleEffect () |
| Explicitly applies the idle state effect (e.g., heartbeat). Calls the Apply method of the idle_state_ object. | |
| void | InitializeBlob () |
| Initializes the blob's state (control points, target points, velocity, center) based on current parameters. Generates the initial organic shape. | |
| void | PhysicsThreadFunction () |
| The main function executed by the physics simulation thread. Enters a loop that repeatedly calls updatePhysics(), notifies the UI thread to update, and waits for the next frame time, controlled by physics_active_ flag and physics_condition_. | |
| void | ResetBlobToCenter () |
| Resets the blob's position to the center of the widget and regenerates its shape. Clears velocities and switches the state to Idle. | |
| void | SwitchToState (BlobConfig::AnimationState new_state) |
| Switches the blob's current animation state (Idle, Moving, Resizing). Updates the current_blob_state_ pointer and handles state-specific logic like timer management and resetting state properties. | |
Static Private Member Functions | |
| static std::vector< QPointF > | GenerateOrganicShape (const QPointF ¢er, double base_radius, int num_of_points) |
| Generates a set of points forming an organic, blob-like shape around a center point. Uses random factors combined with smoothing and sinusoidal variations to create irregularity. | |
Private Attributes | |
| QTimer | animation_timer_ |
| Main timer driving the animation updates (~60 FPS). | |
| QPointF | blob_center_ |
| The calculated center position of the blob. Protected by points_mutex_. | |
| std::vector< QPointF > | control_points_ |
| Vector storing the current positions of the blob's control points. Modified by physics and states. Protected by points_mutex_. | |
| BlobState * | current_blob_state_ |
| Pointer to the currently active state object (points to one of the above). | |
| BlobConfig::AnimationState | current_state_ = BlobConfig::kIdle |
| The current animation state (Idle, Moving, Resizing). | |
| QColor | default_life_color_ |
| Stores the default border color before SetLifeColor is called. | |
| BlobEventHandler | event_handler_ |
| Handles window move/resize event filtering and processing. | |
| QTimer | event_re_enable_timer_ |
| Timer for delayed re-enabling of events after transitions. | |
| bool | events_enabled_ = true |
| Flag indicating if event processing is currently enabled. | |
| std::vector< GLfloat > | gl_vertices_ |
| Vector storing vertex data (x, y pairs) to be uploaded to the VBO. | |
| BlobConfig::IdleParameters | idle_params_ |
| Structure holding parameters specific to the idle state animation (wave amplitude/frequency). | |
| std::unique_ptr< IdleState > | idle_state_ |
| Unique pointer to the Idle state logic object. | |
| QSize | last_size_ |
| Stores the last known size of the widget after a resize event. | |
| QPointF | last_window_position_ |
| Stores the last known window position. | |
| QPointF | last_window_position_timer_ |
| Stores the last window position recorded by the window_position_timer_. | |
| std::unique_ptr< MovingState > | moving_state_ |
| Unique pointer to the Moving state logic object. | |
| bool | needs_redraw_ = false |
| Flag indicating if a redrawing is needed in the next animation frame. | |
| bool | original_border_color_set_ = false |
| Flag indicating if default_life_color_ has been set. | |
| BlobConfig::BlobParameters | params_ |
| Structure holding general blob appearance parameters (colors, radius, points, etc.). | |
| BlobPhysics | physics_ |
| Object responsible for calculating physics interactions. | |
| std::atomic< bool > | physics_active_ {true} |
| Atomic flag controlling the physics thread loop. | |
| std::condition_variable | physics_condition_ |
| Condition variable used by the physics thread to wait for the next frame time. | |
| BlobConfig::PhysicsParameters | physics_params_ |
| Structure holding physics simulation parameters (stiffness, damping, etc.). | |
| std::thread | physics_thread_ |
| The separate thread object running the physics simulation (PhysicsThreadFunction). | |
| std::mutex | points_mutex_ |
| Mutex protecting access to shared data between UI and physics threads (control_points_, velocity_, etc.). | |
| double | precalc_max_distance_ = 0.0 |
| Precalculated maximum distance constraint for physics. | |
| double | precalc_min_distance_ = 0.0 |
| Precalculated minimum distance constraint for physics. | |
| BlobRenderer | renderer_ |
| Object responsible for rendering the blob, grid, and HUD. | |
| QTimer | resize_debounce_timer_ |
| Timer for debouncing resize events. | |
| std::unique_ptr< ResizingState > | resizing_state_ |
| Unique pointer to the Resizing state logic object. | |
| QOpenGLShaderProgram * | shader_program_ = nullptr |
| Pointer to the shader program used for rendering the blob. | |
| QTimer | state_reset_timer_ |
| Timer used to automatically switch back to Idle state after inactivity in Moving/Resizing state. | |
| std::vector< QPointF > | target_points_ |
| Vector storing the target positions for control points (used by physics). Protected by points_mutex_. | |
| BlobTransitionManager | transition_manager_ |
| Manages movement analysis, velocity calculation, and state transitions based on movement. | |
| QOpenGLVertexArrayObject | vao_ |
| Vertex Array Object encapsulating vertex buffer state. | |
| QOpenGLBuffer | vbo_ |
| Vertex Buffer Object storing blob geometry data. | |
| std::vector< QPointF > | velocity_ |
| Vector storing the current velocities of the blob's control points. Protected by points_mutex_. | |
| QTimer | window_position_timer_ |
| Timer for periodically checking the window position. | |
Main widget responsible for rendering and animating the dynamic blob.
This class integrates physics simulation (BlobPhysics), rendering (BlobRenderer), state management (IdleState, MovingState, ResizingState), event handling (BlobEventHandler), and transition logic (BlobTransitionManager) to create a fluid, interactive blob animation. It uses QOpenGLWidget for hardware-accelerated rendering and runs physics calculations in a separate thread for performance.
|
explicit |
Constructs the BlobAnimation widget. Initializes parameters, states, event handlers, timers, and the physics thread. Sets up OpenGL format and connects signals/slots between components.
| parent | Optional parent widget. |
|
override |
Destructor. Stops timers, cleans up OpenGL resources, joins the physics thread, and deletes state objects.
|
private |
Applies an external force vector to the blob. Delegates force application to the current state object.
| force | The force vector to apply. |
|
private |
Explicitly applies the idle state effect (e.g., heartbeat). Calls the Apply method of the idle_state_ object.
|
protected |
Calculates the bounding rectangle encompassing the blob's control points, including margins for border and glow. Used for optimizing paint events.
|
privateslot |
Slot connected to window_position_timer_. Called frequently to check the window position. Adds position samples to the BlobTransitionManager if the window has moved or if the buffer is stale.
|
protected |
Draws the background grid using a separate shader program and line primitives. Generates vertex data for horizontal and vertical lines based on grid spacing.
|
overrideprotected |
Overridden generic event handler.
| event | The event. |
|
overrideprotected |
Overridden event filter. Delegates filtering primarily to BlobEventHandler.
| watched | The object being watched. |
| event | The event. |
|
staticprivate |
Generates a set of points forming an organic, blob-like shape around a center point. Uses random factors combined with smoothing and sinusoidal variations to create irregularity.
| center | The center point for the shape. |
| base_radius | The average radius of the shape. |
| num_of_points | The number of control points to generate. |
|
inline |
Gets the current calculated center position of the blob. If control points are not yet initialized, return the center of the widget.
|
privateslot |
Slot connected to resize_debounce_timer_. Called after a short delay following resize events. Resets the blob to the center, resets the grid buffer, and updates the widget.
|
slot |
Hides the animation widget and pauses event tracking.
|
private |
Initializes the blob's state (control points, target points, velocity, center) based on current parameters. Generates the initial organic shape.
|
overrideprotected |
Initializes OpenGL functions, shaders, VAO, and VBO. Called once before the first paintGL call.
|
privateslot |
Slot connected to state_reset_timer_. Called after a period of inactivity in Moving or Resizing state. Automatically switches the state back to Idle.
|
overrideprotected |
Overridden paint event handler. Delegates rendering to BlobRenderer after checking if the paint area intersects the blob's bounding box. Uses a cached background pixmap for efficiency.
| event | The paint event. |
|
overrideprotected |
Renders the blob and grid using OpenGL. Called whenever the widget needs to be painted. Binds shaders, sets uniforms (projection matrix, colors, etc.), updates VBO data, and draws the blob geometry.
| void BlobAnimation::PauseAllEventTracking | ( | ) |
Pauses all event tracking mechanisms (window move/resize). Stops timers, clears movement buffers, and disables the event handler. Switches the blob state to Idle.
|
private |
The main function executed by the physics simulation thread. Enters a loop that repeatedly calls updatePhysics(), notifies the UI thread to update, and waits for the next frame time, controlled by physics_active_ flag and physics_condition_.
|
privateslot |
Slot (or helper called by updateAnimation) to process the window movement buffer via BlobTransitionManager. Provides callbacks to apply inertia forces and update the last known window position.
|
private |
Resets the blob's position to the center of the widget and regenerates its shape. Clears velocities and switches the state to Idle.
| void BlobAnimation::ResetLifeColor | ( | ) |
Resets the blob's border color to its original value before SetLifeColor() was called.
| void BlobAnimation::ResetVisualization | ( | ) |
Resets the entire blob visualization to its initial state. Resets blob position, shape, and dynamics, resets the HUD, and emits visualizationReset().
|
overrideprotected |
Overridden resize event handler. Delegates processing to BlobEventHandler.
| event | The resize event. |
|
overrideprotected |
Handles OpenGL viewport updates when the widget is resized.
| w | New width. |
| h | New height. |
| void BlobAnimation::ResumeAllEventTracking | ( | ) |
Resumes all event tracking mechanisms after being paused. Restarts timers, enables the event handler, resets the blob state, and forces a redrawing.
|
slot |
Sets the background color used for rendering. Updates the grid buffer and triggers a repaint.
| color | The new background color. |
|
slot |
Sets the border color of the blob. Triggers a repaint.
| color | The new blob border color. |
|
slot |
Sets the color of the background grid lines. Updates the grid buffer and triggers a repaint.
| color | The new grid color. |
|
slot |
Sets the spacing between background grid lines. Updates the grid buffer and triggers a repaint.
| spacing | The new grid spacing in pixels. |
| void BlobAnimation::SetLifeColor | ( | const QColor & | color | ) |
Temporarily sets the blob's border color (e.g., for highlighting). Stores the original color to be restored later by ResetLifeColor().
| color | The temporary color to apply. |
|
slot |
Makes the animation widget visible and resumes event tracking.
|
private |
Switches the blob's current animation state (Idle, Moving, Resizing). Updates the current_blob_state_ pointer and handles state-specific logic like timer management and resetting state properties.
| new_state | The target state to switch to. |
|
privateslot |
Slot connected to animation_timer_. Called periodically (~60 FPS) to update the animation state. Processes movement buffer, applies current state logic, and triggers a repaint if needed.
|
protected |
Updates the internal vertex buffer (gl_vertices_) based on the current blob_center_ and control_points_. Prepares the geometry data for rendering with GL_TRIANGLE_FAN.
|
privateslot |
Slot (or helper called by physics thread) to update the blob's physics simulation. Calls BlobPhysics methods for internal forces, collisions, smoothing, and constraints.
|
signal |
Emitted when the entire visualization is reset via ResetVisualization(). Allows other UI elements to update accordingly.
|
private |
Main timer driving the animation updates (~60 FPS).
|
private |
The calculated center position of the blob. Protected by points_mutex_.
|
private |
Vector storing the current positions of the blob's control points. Modified by physics and states. Protected by points_mutex_.
|
private |
Pointer to the currently active state object (points to one of the above).
|
private |
The current animation state (Idle, Moving, Resizing).
|
private |
Stores the default border color before SetLifeColor is called.
|
private |
Handles window move/resize event filtering and processing.
|
private |
Timer for delayed re-enabling of events after transitions.
|
private |
Flag indicating if event processing is currently enabled.
|
private |
Vector storing vertex data (x, y pairs) to be uploaded to the VBO.
|
private |
Structure holding parameters specific to the idle state animation (wave amplitude/frequency).
|
private |
Unique pointer to the Idle state logic object.
|
private |
Stores the last known size of the widget after a resize event.
|
private |
Stores the last known window position.
|
private |
Stores the last window position recorded by the window_position_timer_.
|
private |
Unique pointer to the Moving state logic object.
|
private |
Flag indicating if a redrawing is needed in the next animation frame.
|
private |
Flag indicating if default_life_color_ has been set.
|
private |
Structure holding general blob appearance parameters (colors, radius, points, etc.).
|
private |
Object responsible for calculating physics interactions.
|
private |
Atomic flag controlling the physics thread loop.
|
private |
Condition variable used by the physics thread to wait for the next frame time.
|
private |
Structure holding physics simulation parameters (stiffness, damping, etc.).
|
private |
The separate thread object running the physics simulation (PhysicsThreadFunction).
|
mutableprivate |
Mutex protecting access to shared data between UI and physics threads (control_points_, velocity_, etc.).
|
private |
Precalculated maximum distance constraint for physics.
|
private |
Precalculated minimum distance constraint for physics.
|
private |
Object responsible for rendering the blob, grid, and HUD.
|
private |
Timer for debouncing resize events.
|
private |
Unique pointer to the Resizing state logic object.
|
private |
Pointer to the shader program used for rendering the blob.
|
private |
Timer used to automatically switch back to Idle state after inactivity in Moving/Resizing state.
|
private |
Vector storing the target positions for control points (used by physics). Protected by points_mutex_.
|
private |
Manages movement analysis, velocity calculation, and state transitions based on movement.
|
private |
Vertex Array Object encapsulating vertex buffer state.
|
private |
Vertex Buffer Object storing blob geometry data.
|
private |
Vector storing the current velocities of the blob's control points. Protected by points_mutex_.
|
private |
Timer for periodically checking the window position.