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

Handles the rendering of the blob, background grid, and HUD elements. More...

#include <blob_renderer.h>

Collaboration diagram for BlobRenderer:

Public Member Functions

 BlobRenderer ()
 Constructs a BlobRenderer object. Initializes member variables to default states.
 
void DrawBackground (QPainter &painter, const QColor &background_color, const QColor &grid_color, int grid_spacing, int width, int height)
 Draws the background, including a static texture and the dynamic grid. Uses internal caching (grid_buffer_) to avoid redrawing the grid every frame if parameters haven't changed. It also draws a static background texture underneath the grid.
 
void DrawCompleteHUD (QPainter &painter, const QPointF &blob_center, double blob_radius, const QColor &hud_color, int width, int height) const
 Draws the complete static Heads-Up Display (HUD) elements used in the Idle state. Includes corner markers, text labels (ID, radius, amplitude), and a target circle around the blob.
 
void ForceHUDInitialization (const QPointF &blob_center, double blob_radius, const QColor &hud_color, int width, int height)
 Forces the immediate initialization and buffering of the static HUD elements for the Idle state. Calls InitializeIdleState and then renders the HUD into the static_hud_buffer_.
 
void InitializeIdleState ()
 Initializes parameters specific to the Idle state HUD display. Generates random ID, calculates amplitude based on time, gets current timestamp. Reset the HUD buffer flags.
 
void RenderBlob (QPainter &painter, const std::vector< QPointF > &control_points, const QPointF &blob_center, const BlobConfig::BlobParameters &params)
 Renders the blob shape itself (filling, border, glow).
 
void RenderScene (QPainter &painter, const std::vector< QPointF > &control_points, const QPointF &blob_center, const BlobConfig::BlobParameters &params, const BlobRenderState &render_state, int width, int height, QPixmap &background_cache, QSize &last_background_size, QColor &last_background_color, QColor &last_grid_color, int &last_grid_spacing)
 Renders the entire scene, including a background, blob, and potentially HUD. Orchestrates the drawing process, using cached background and HUD elements when in the Idle state. Handles the logic for preparing HUD buffers when transitioning to the Idle state.
 
void ResetGridBuffer ()
 Resets the internal grid buffer pixmap, forcing it to be redrawn on the next frame.
 
void ResetHUD ()
 Resets the HUD buffers and flags, forcing reinitialization on the next transition to Idle state.
 
void UpdateGridBuffer (const QColor &background_color, const QColor &grid_color, int grid_spacing, int width, int height)
 Updates the internal buffer containing the rendered background grid. Called when grid parameters (colors, spacing) or widget size change.
 
 ~BlobRenderer ()
 Destructor for BlobRenderer. Cleans up allocated resources.
 

Private Member Functions

void DrawGlowEffect (QPainter &painter, const QPainterPath &blob_path, const QColor &border_color, int glow_radius)
 Draws the glow effect around the blob path. Uses internal caching (glow_buffer_) to optimize rendering, especially in the Idle state. Delegates the actual drawing to RenderGlowEffect when the buffer needs updating.
 

Static Private Member Functions

static void DrawBorder (QPainter &painter, const QPainterPath &blob_path, const QColor &border_color, int border_width)
 Draws the border outline of the blob. Includes a main border and a thinner, lighter inner line for a neon effect.
 
static void DrawFilling (QPainter &painter, const QPainterPath &blob_path, const QPointF &blob_center, double blob_radius, const QColor &border_color)
 Draws the filling inside the blob path using a radial gradient. The gradient fades from a lighter, semi-transparent center towards a darker, transparent edge.
 
static void RenderGlowEffect (QPainter &painter, const QPainterPath &blob_path, const QColor &border_color, int glow_radius)
 Renders the multi-layered glow effect using QPainter drawPath operations with varying pen widths and colors. This static method performs the actual drawing logic used by DrawGlowEffect when updating the cache.
 

Private Attributes

QPixmap glow_buffer_
 Cached pixmap containing the rendered glow effect. Updated based on blob shape, color, and state.
 
QPixmap grid_buffer_
 Cached pixmap containing the rendered grid lines. Updated when grid parameters or size change.
 
double idle_amplitude_
 Calculated amplitude value displayed in the Idle state HUD.
 
QString idle_blob_id_
 Randomly generated ID string displayed in the Idle state HUD.
 
bool idle_hud_initialized_
 Flag indicating if the static HUD elements for the Idle state have been initialized and buffered.
 
QString idle_timestamp_
 Timestamp string displayed in the Idle state HUD (potentially dynamic, currently static after init).
 
bool is_rendering_active_
 Flag indicating if rendering is currently active (used for state transition logic).
 
BlobConfig::AnimationState last_animation_state_
 Stores the animation state from the previous frame, used for detecting state changes.
 
QColor last_background_color_
 Stores the background color used for the last grid_buffer_ update.
 
QColor last_glow_color_
 Stores the border color used for the last glow_buffer_ update.
 
QPainterPath last_glow_path_
 Stores the blob path used for the last glow_buffer_ update.
 
int last_glow_radius_
 Stores the glow radius used for the last glow_buffer_ update.
 
QSize last_glow_size_
 Stores the viewport size used for the last glow_buffer_ update.
 
QColor last_grid_color_
 Stores the grid color used for the last grid_buffer_ update.
 
int last_grid_spacing_
 Stores the grid spacing used for the last grid_buffer_ update.
 
QSize last_size_
 Stores the size used for the last grid_buffer_ update.
 
PathMarkersManagermarkers_manager_
 Markers Manager for drawing animated markers alongside blob border (currently unused).
 
bool static_background_initialized_
 Flag indicating if static_background_texture_ has been initialized.
 
QPixmap static_background_texture_
 Cached pixmap containing a static background texture (e.g., gradient, noise). Initialized once.
 
QPixmap static_hud_buffer_
 Cached pixmap containing the static elements of the HUD rendered during Idle state initialization.
 

Detailed Description

Handles the rendering of the blob, background grid, and HUD elements.

This class encapsulates all drawing logic for the Blob animation. It uses QPainter to draw the blob shape (filling, border, glow), the background grid, and informational Heads-Up Display (HUD) elements. It employs caching mechanisms (QPixmap buffers) for the background, grid, glow effect, and HUD to optimize performance, especially when the blob is in the Idle state.

Constructor & Destructor Documentation

◆ BlobRenderer()

BlobRenderer::BlobRenderer ( )
inline

Constructs a BlobRenderer object. Initializes member variables to default states.

◆ ~BlobRenderer()

BlobRenderer::~BlobRenderer ( )
inline

Destructor for BlobRenderer. Cleans up allocated resources.

Member Function Documentation

◆ DrawBackground()

void BlobRenderer::DrawBackground ( QPainter & painter,
const QColor & background_color,
const QColor & grid_color,
int grid_spacing,
int width,
int height )

Draws the background, including a static texture and the dynamic grid. Uses internal caching (grid_buffer_) to avoid redrawing the grid every frame if parameters haven't changed. It also draws a static background texture underneath the grid.

Parameters
painterThe QPainter to use for drawing.
background_colorThe desired background color (used for grid buffer update check).
grid_colorThe desired color for the grid lines.
grid_spacingThe desired spacing between grid lines.
widthThe current width of the rendering area.
heightThe current height of the rendering area.
Here is the caller graph for this function:

◆ DrawBorder()

void BlobRenderer::DrawBorder ( QPainter & painter,
const QPainterPath & blob_path,
const QColor & border_color,
int border_width )
staticprivate

Draws the border outline of the blob. Includes a main border and a thinner, lighter inner line for a neon effect.

Parameters
painterThe QPainter to use for drawing.
blob_pathThe QPainterPath representing the blob's outline.
border_colorThe color of the main border.
border_widthThe width of the main border.
Here is the caller graph for this function:

◆ DrawCompleteHUD()

void BlobRenderer::DrawCompleteHUD ( QPainter & painter,
const QPointF & blob_center,
double blob_radius,
const QColor & hud_color,
int width,
int height ) const

Draws the complete static Heads-Up Display (HUD) elements used in the Idle state. Includes corner markers, text labels (ID, radius, amplitude), and a target circle around the blob.

Parameters
painterThe QPainter to use for drawing.
blob_centerThe center position of the blob.
blob_radiusThe radius of the blob.
hud_colorThe color for the HUD elements.
widthThe width of the rendering area.
heightThe height of the rendering area.
Here is the caller graph for this function:

◆ DrawFilling()

void BlobRenderer::DrawFilling ( QPainter & painter,
const QPainterPath & blob_path,
const QPointF & blob_center,
double blob_radius,
const QColor & border_color )
staticprivate

Draws the filling inside the blob path using a radial gradient. The gradient fades from a lighter, semi-transparent center towards a darker, transparent edge.

Parameters
painterThe QPainter to use for drawing.
blob_pathThe QPainterPath representing the blob's outline.
blob_centerThe center point for the radial gradient.
blob_radiusThe radius for the radial gradient.
border_colorThe base color used to derive gradient colors.
Here is the caller graph for this function:

◆ DrawGlowEffect()

void BlobRenderer::DrawGlowEffect ( QPainter & painter,
const QPainterPath & blob_path,
const QColor & border_color,
int glow_radius )
private

Draws the glow effect around the blob path. Uses internal caching (glow_buffer_) to optimize rendering, especially in the Idle state. Delegates the actual drawing to RenderGlowEffect when the buffer needs updating.

Parameters
painterThe QPainter to use for drawing.
blob_pathThe QPainterPath representing the blob's outline.
border_colorThe base color for the glow.
glow_radiusThe radius/spread of the glow effect.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ForceHUDInitialization()

void BlobRenderer::ForceHUDInitialization ( const QPointF & blob_center,
double blob_radius,
const QColor & hud_color,
int width,
int height )

Forces the immediate initialization and buffering of the static HUD elements for the Idle state. Calls InitializeIdleState and then renders the HUD into the static_hud_buffer_.

Parameters
blob_centerThe current center of the blob.
blob_radiusThe current radius of the blob.
hud_colorThe color to use for HUD elements.
widthThe current width of the rendering area.
heightThe current height of the rendering area.
Here is the call graph for this function:

◆ InitializeIdleState()

void BlobRenderer::InitializeIdleState ( )

Initializes parameters specific to the Idle state HUD display. Generates random ID, calculates amplitude based on time, gets current timestamp. Reset the HUD buffer flags.

Here is the caller graph for this function:

◆ RenderBlob()

void BlobRenderer::RenderBlob ( QPainter & painter,
const std::vector< QPointF > & control_points,
const QPointF & blob_center,
const BlobConfig::BlobParameters & params )

Renders the blob shape itself (filling, border, glow).

Parameters
painterThe QPainter to use for drawing.
control_pointsThe current positions of the blob's control points.
blob_centerThe calculated center of the blob.
paramsBlob appearance parameters (colors, radius, etc.).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RenderGlowEffect()

void BlobRenderer::RenderGlowEffect ( QPainter & painter,
const QPainterPath & blob_path,
const QColor & border_color,
int glow_radius )
staticprivate

Renders the multi-layered glow effect using QPainter drawPath operations with varying pen widths and colors. This static method performs the actual drawing logic used by DrawGlowEffect when updating the cache.

Parameters
painterThe QPainter to draw onto (typically the glow buffer painter).
blob_pathThe QPainterPath representing the blob's outline.
border_colorThe base color for the glow.
glow_radiusThe radius/spread of the glow effect.
Here is the caller graph for this function:

◆ RenderScene()

void BlobRenderer::RenderScene ( QPainter & painter,
const std::vector< QPointF > & control_points,
const QPointF & blob_center,
const BlobConfig::BlobParameters & params,
const BlobRenderState & render_state,
int width,
int height,
QPixmap & background_cache,
QSize & last_background_size,
QColor & last_background_color,
QColor & last_grid_color,
int & last_grid_spacing )

Renders the entire scene, including a background, blob, and potentially HUD. Orchestrates the drawing process, using cached background and HUD elements when in the Idle state. Handles the logic for preparing HUD buffers when transitioning to the Idle state.

Parameters
painterThe QPainter to use for drawing.
control_pointsThe current positions of the blob's control points.
blob_centerThe calculated center of the blob.
paramsBlob appearance parameters.
render_stateCurrent rendering state information (opacity, scale, animation state, etc.).
widthThe current width of the rendering area.
heightThe current height of the rendering area.
background_cacheReference to the QPixmap used for caching the background (managed externally, typically by BlobAnimation).
last_background_sizeReference to the size used for the last background cache update.
last_background_colorReference to the background color used for the last cache update.
last_grid_colorReference to the grid color used for the last cache update.
last_grid_spacingReference to the grid spacing used for the last cache update.
Here is the call graph for this function:

◆ ResetGridBuffer()

void BlobRenderer::ResetGridBuffer ( )
inline

Resets the internal grid buffer pixmap, forcing it to be redrawn on the next frame.

◆ ResetHUD()

void BlobRenderer::ResetHUD ( )
inline

Resets the HUD buffers and flags, forcing reinitialization on the next transition to Idle state.

◆ UpdateGridBuffer()

void BlobRenderer::UpdateGridBuffer ( const QColor & background_color,
const QColor & grid_color,
int grid_spacing,
int width,
int height )

Updates the internal buffer containing the rendered background grid. Called when grid parameters (colors, spacing) or widget size change.

Parameters
background_colorThe background color to fill behind the grid.
grid_colorThe color of the grid lines.
grid_spacingThe spacing between grid lines in pixels.
widthThe current width of the rendering area.
heightThe current height of the rendering area.

Member Data Documentation

◆ glow_buffer_

QPixmap BlobRenderer::glow_buffer_
private

Cached pixmap containing the rendered glow effect. Updated based on blob shape, color, and state.

◆ grid_buffer_

QPixmap BlobRenderer::grid_buffer_
private

Cached pixmap containing the rendered grid lines. Updated when grid parameters or size change.

◆ idle_amplitude_

double BlobRenderer::idle_amplitude_
private

Calculated amplitude value displayed in the Idle state HUD.

◆ idle_blob_id_

QString BlobRenderer::idle_blob_id_
private

Randomly generated ID string displayed in the Idle state HUD.

◆ idle_hud_initialized_

bool BlobRenderer::idle_hud_initialized_
private

Flag indicating if the static HUD elements for the Idle state have been initialized and buffered.

◆ idle_timestamp_

QString BlobRenderer::idle_timestamp_
private

Timestamp string displayed in the Idle state HUD (potentially dynamic, currently static after init).

◆ is_rendering_active_

bool BlobRenderer::is_rendering_active_
private

Flag indicating if rendering is currently active (used for state transition logic).

◆ last_animation_state_

BlobConfig::AnimationState BlobRenderer::last_animation_state_
private

Stores the animation state from the previous frame, used for detecting state changes.

◆ last_background_color_

QColor BlobRenderer::last_background_color_
private

Stores the background color used for the last grid_buffer_ update.

◆ last_glow_color_

QColor BlobRenderer::last_glow_color_
private

Stores the border color used for the last glow_buffer_ update.

◆ last_glow_path_

QPainterPath BlobRenderer::last_glow_path_
private

Stores the blob path used for the last glow_buffer_ update.

◆ last_glow_radius_

int BlobRenderer::last_glow_radius_
private

Stores the glow radius used for the last glow_buffer_ update.

◆ last_glow_size_

QSize BlobRenderer::last_glow_size_
private

Stores the viewport size used for the last glow_buffer_ update.

◆ last_grid_color_

QColor BlobRenderer::last_grid_color_
private

Stores the grid color used for the last grid_buffer_ update.

◆ last_grid_spacing_

int BlobRenderer::last_grid_spacing_
private

Stores the grid spacing used for the last grid_buffer_ update.

◆ last_size_

QSize BlobRenderer::last_size_
private

Stores the size used for the last grid_buffer_ update.

◆ markers_manager_

PathMarkersManager* BlobRenderer::markers_manager_
private

Markers Manager for drawing animated markers alongside blob border (currently unused).

◆ static_background_initialized_

bool BlobRenderer::static_background_initialized_
private

Flag indicating if static_background_texture_ has been initialized.

◆ static_background_texture_

QPixmap BlobRenderer::static_background_texture_
private

Cached pixmap containing a static background texture (e.g., gradient, noise). Initialized once.

◆ static_hud_buffer_

QPixmap BlobRenderer::static_hud_buffer_
private

Cached pixmap containing the static elements of the HUD rendered during Idle state initialization.


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