4#include <QOpenGLBuffer>
5#include <QOpenGLFunctions>
6#include <QOpenGLVertexArrayObject>
7#include <QOpenGLWidget>
15class QOpenGLShaderProgram;
30class BlobAnimation final :
public QOpenGLWidget,
protected QOpenGLFunctions {
56 return {width() / 2.0, height() / 2.0};
193 void resizeGL(
int w,
int h)
override;
286 static std::vector<QPointF>
GenerateOrganicShape(
const QPointF ¢er,
double base_radius,
int num_of_points);
QPointF GetBlobCenter() const
Gets the current calculated center position of the blob. If control points are not yet initialized,...
Definition blob_animation.h:53
BlobConfig::AnimationState current_state_
The current animation state (Idle, Moving, Resizing).
Definition blob_animation.h:331
BlobConfig::IdleParameters idle_params_
Structure holding parameters specific to the idle state animation (wave amplitude/frequency).
Definition blob_animation.h:318
void updateAnimation()
Slot connected to animation_timer_. Called periodically (~60 FPS) to update the animation state....
Definition blob_animation.cpp:276
void initializeGL() override
Initializes OpenGL functions, shaders, VAO, and VBO. Called once before the first paintGL call.
Definition blob_animation.cpp:457
void DrawGrid()
Draws the background grid using a separate shader program and line primitives. Generates vertex data ...
Definition blob_animation.cpp:563
void paintGL() override
Renders the blob and grid using OpenGL. Called whenever the widget needs to be painted....
Definition blob_animation.cpp:509
double precalc_max_distance_
Precalculated maximum distance constraint for physics.
Definition blob_animation.h:358
bool eventFilter(QObject *watched, QEvent *event) override
Overridden event filter. Delegates filtering primarily to BlobEventHandler.
Definition blob_animation.cpp:433
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....
Definition blob_animation.cpp:673
void setBackgroundColor(const QColor &color)
Sets the background color used for rendering. Updates the grid buffer and triggers a repaint.
Definition blob_animation.cpp:406
std::atomic< bool > physics_active_
Atomic flag controlling the physics thread loop.
Definition blob_animation.h:363
QPointF blob_center_
The calculated center position of the blob. Protected by points_mutex_.
Definition blob_animation.h:328
void ResetVisualization()
Resets the entire blob visualization to its initial state. Resets blob position, shape,...
Definition blob_animation.cpp:749
~BlobAnimation() override
Destructor. Stops timers, cleans up OpenGL resources, joins the physics thread, and deletes state obj...
Definition blob_animation.cpp:182
QTimer window_position_timer_
Timer for periodically checking the window position.
Definition blob_animation.h:301
void InitializeBlob()
Initializes the blob's state (control points, target points, velocity, center) based on current param...
Definition blob_animation.cpp:203
BlobPhysics physics_
Object responsible for calculating physics interactions.
Definition blob_animation.h:339
void resizeGL(int w, int h) override
Handles OpenGL viewport updates when the widget is resized.
Definition blob_animation.cpp:542
void HandleResizeTimeout()
Slot connected to resize_debounce_timer_. Called after a short delay following resize events....
Definition blob_animation.cpp:131
BlobAnimation(QWidget *parent=nullptr)
Constructs the BlobAnimation widget. Initializes parameters, states, event handlers,...
Definition blob_animation.cpp:14
void hideAnimation()
Hides the animation widget and pauses event tracking.
Definition blob_animation.cpp:767
BlobConfig::PhysicsParameters physics_params_
Structure holding physics simulation parameters (stiffness, damping, etc.).
Definition blob_animation.h:316
QTimer event_re_enable_timer_
Timer for delayed re-enabling of events after transitions.
Definition blob_animation.h:370
std::thread physics_thread_
The separate thread object running the physics simulation (PhysicsThreadFunction).
Definition blob_animation.h:375
void updatePhysics()
Slot (or helper called by physics thread) to update the blob's physics simulation....
Definition blob_animation.cpp:317
double precalc_min_distance_
Precalculated minimum distance constraint for physics.
Definition blob_animation.h:356
bool needs_redraw_
Flag indicating if a redrawing is needed in the next animation frame.
Definition blob_animation.h:372
void CheckWindowPosition()
Slot connected to window_position_timer_. Called frequently to check the window position....
Definition blob_animation.cpp:138
std::vector< QPointF > control_points_
Vector storing the current positions of the blob's control points. Modified by physics and states....
Definition blob_animation.h:321
std::mutex points_mutex_
Mutex protecting access to shared data between UI and physics threads (control_points_,...
Definition blob_animation.h:361
void paintEvent(QPaintEvent *event) override
Overridden paint event handler. Delegates rendering to BlobRenderer after checking if the paint area ...
Definition blob_animation.cpp:218
std::vector< QPointF > target_points_
Vector storing the target positions for control points (used by physics). Protected by points_mutex_.
Definition blob_animation.h:323
BlobState * current_blob_state_
Pointer to the currently active state object (points to one of the above).
Definition blob_animation.h:350
std::condition_variable physics_condition_
Condition variable used by the physics thread to wait for the next frame time.
Definition blob_animation.h:365
BlobConfig::BlobParameters params_
Structure holding general blob appearance parameters (colors, radius, points, etc....
Definition blob_animation.h:314
std::unique_ptr< ResizingState > resizing_state_
Unique pointer to the Resizing state logic object.
Definition blob_animation.h:348
QTimer animation_timer_
Main timer driving the animation updates (~60 FPS).
Definition blob_animation.h:334
void resizeEvent(QResizeEvent *event) override
Overridden resize event handler. Delegates processing to BlobEventHandler.
Definition blob_animation.cpp:333
std::vector< GLfloat > gl_vertices_
Vector storing vertex data (x, y pairs) to be uploaded to the VBO.
Definition blob_animation.h:384
void showAnimation()
Makes the animation widget visible and resumes event tracking.
Definition blob_animation.cpp:760
BlobEventHandler event_handler_
Handles window move/resize event filtering and processing.
Definition blob_animation.h:296
void ApplyForces(const QVector2D &force)
Applies an external force vector to the blob. Delegates force application to the current state object...
Definition blob_animation.cpp:397
void processMovementBuffer()
Slot (or helper called by updateAnimation) to process the window movement buffer via BlobTransitionMa...
Definition blob_animation.cpp:301
void ResetBlobToCenter()
Resets the blob's position to the center of the widget and regenerates its shape. Clears velocities a...
Definition blob_animation.cpp:731
void setBlobColor(const QColor &color)
Sets the border color of the blob. Triggers a repaint.
Definition blob_animation.cpp:666
void SwitchToState(BlobConfig::AnimationState new_state)
Switches the blob's current animation state (Idle, Moving, Resizing). Updates the current_blob_state_...
Definition blob_animation.cpp:350
QRectF CalculateBlobBoundingRect()
Calculates the bounding rectangle encompassing the blob's control points, including margins for borde...
Definition blob_animation.cpp:252
void onStateResetTimeout()
Slot connected to state_reset_timer_. Called after a period of inactivity in Moving or Resizing state...
Definition blob_animation.cpp:340
void PhysicsThreadFunction()
The main function executed by the physics simulation thread. Enters a loop that repeatedly calls upda...
Definition blob_animation.cpp:163
QTimer resize_debounce_timer_
Timer for debouncing resize events.
Definition blob_animation.h:305
QPointF last_window_position_timer_
Stores the last window position recorded by the window_position_timer_.
Definition blob_animation.h:303
QOpenGLBuffer vbo_
Vertex Buffer Object storing blob geometry data.
Definition blob_animation.h:380
QOpenGLShaderProgram * shader_program_
Pointer to the shader program used for rendering the blob.
Definition blob_animation.h:378
std::unique_ptr< IdleState > idle_state_
Unique pointer to the Idle state logic object.
Definition blob_animation.h:344
void visualizationReset()
Emitted when the entire visualization is reset via ResetVisualization(). Allows other UI elements to ...
QSize last_size_
Stores the last known size of the widget after a resize event.
Definition blob_animation.h:307
void PauseAllEventTracking()
Pauses all event tracking mechanisms (window move/resize). Stops timers, clears movement buffers,...
Definition blob_animation.cpp:644
void setGridSpacing(int spacing)
Sets the spacing between background grid lines. Updates the grid buffer and triggers a repaint.
Definition blob_animation.cpp:424
void setGridColor(const QColor &color)
Sets the color of the background grid lines. Updates the grid buffer and triggers a repaint.
Definition blob_animation.cpp:415
std::vector< QPointF > velocity_
Vector storing the current velocities of the blob's control points. Protected by points_mutex_.
Definition blob_animation.h:325
BlobTransitionManager transition_manager_
Manages movement analysis, velocity calculation, and state transitions based on movement.
Definition blob_animation.h:298
bool events_enabled_
Flag indicating if event processing is currently enabled.
Definition blob_animation.h:368
QTimer state_reset_timer_
Timer used to automatically switch back to Idle state after inactivity in Moving/Resizing state.
Definition blob_animation.h:336
void UpdateBlobGeometry()
Updates the internal vertex buffer (gl_vertices_) based on the current blob_center_ and control_point...
Definition blob_animation.cpp:546
void ApplyIdleEffect()
Explicitly applies the idle state effect (e.g., heartbeat). Calls the Apply method of the idle_state_...
Definition blob_animation.cpp:402
void SetLifeColor(const QColor &color)
Temporarily sets the blob's border color (e.g., for highlighting). Stores the original color to be re...
Definition blob_animation.cpp:437
QOpenGLVertexArrayObject vao_
Vertex Array Object encapsulating vertex buffer state.
Definition blob_animation.h:382
bool event(QEvent *event) override
Overridden generic event handler.
Definition blob_animation.cpp:346
void ResumeAllEventTracking()
Resumes all event tracking mechanisms after being paused. Restarts timers, enables the event handler,...
Definition blob_animation.cpp:654
void ResetLifeColor()
Resets the blob's border color to its original value before SetLifeColor() was called.
Definition blob_animation.cpp:448
QPointF last_window_position_
Stores the last known window position.
Definition blob_animation.h:353
BlobRenderer renderer_
Object responsible for rendering the blob, grid, and HUD.
Definition blob_animation.h:341
QColor default_life_color_
Stores the default border color before SetLifeColor is called.
Definition blob_animation.h:309
bool original_border_color_set_
Flag indicating if default_life_color_ has been set.
Definition blob_animation.h:311
std::unique_ptr< MovingState > moving_state_
Unique pointer to the Moving state logic object.
Definition blob_animation.h:346
Handles and processes window events (move, resize) for the Blob animation.
Definition blob_event_handler.h:21
Handles the physics simulation for the Blob animation.
Definition blob_physics.h:24
Handles the rendering of the blob, background grid, and HUD elements.
Definition blob_renderer.h:33
Abstract base class defining the interface for different blob animation states.
Definition blob_state.h:16
Manages transitions and movement analysis for the Blob animation based on window events.
Definition blob_transition_manager.h:15
Implements the Idle state behavior for the Blob animation.
Definition idle_state.h:13
Implements the Moving state behavior for the Blob animation.
Definition moving_state.h:14
Implements the Resizing state behavior for the Blob animation.
Definition resizing_state.h:15
AnimationState
Defines the possible animation states for the blob.
Definition blob_config.h:16
@ kIdle
The blob is stationary or exhibiting subtle idle animations.
Definition blob_config.h:17
Structure holding parameters related to the blob's visual appearance and basic geometry.
Definition blob_config.h:25
Structure holding parameters specific to the Idle state animation.
Definition blob_config.h:73
Structure holding parameters controlling the physics simulation of the blob.
Definition blob_config.h:51