Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
SpeedSlider Class Reference

Self-contained speed slider widget. More...

#include <SpeedSlider.hpp>

+ Inheritance diagram for SpeedSlider:
+ Collaboration diagram for SpeedSlider:

Public Member Functions

void syncFromServer (int serverTimeUnit)
 Snaps to the nearest step index matching serverTimeUnit. No-op if already initialized or serverTimeUnit is 0.
 
void reset ()
 Resets slider state. Call on reconnect so it re-syncs from the new server.
 
bool handleInput () override
 Processes mouse input.
 
std::optional< int > getPendingSpeedChange ()
 Returns and clears any pending speed change.
 
void draw (int scaledFontSize) const override
 Draws the slider panel at the bottom-left of the screen.
 
int currentSpeed () const
 
- Public Member Functions inherited from IWidget
virtual ~IWidget ()=default
 

Static Public Attributes

static constexpr int PANEL_WIDTH = 220
 
static constexpr int PANEL_HEIGHT = 58
 
static const std::vector< int > STEPS
 

Static Private Member Functions

static float _trackX (float panelX)
 
static float _trackY (float panelY, float panelH)
 
static float _trackW (float panelW)
 

Private Attributes

int _index = 23
 
bool _dragging = false
 
bool _initialized = false
 
std::optional< int > _pendingSpeed = std::nullopt
 

Detailed Description

Self-contained speed slider widget.

Encapsulates all state, input handling, and drawing for the server-speed slider panel displayed at the bottom-left of the screen. Matches the HUD visual style (same rounded panel, colors, and font scaling).

Discrete speed steps: 1, 2, 3, 4, then 5 to 200 in steps of 5.

Definition at line 17 of file SpeedSlider.hpp.

Member Function Documentation

◆ _trackW()

float SpeedSlider::_trackW ( float  panelW)
staticprivate

Definition at line 31 of file SpeedSlider.cpp.

Referenced by draw(), and handleInput().

+ Here is the caller graph for this function:

◆ _trackX()

float SpeedSlider::_trackX ( float  panelX)
staticprivate

Definition at line 29 of file SpeedSlider.cpp.

Referenced by draw(), and handleInput().

+ Here is the caller graph for this function:

◆ _trackY()

float SpeedSlider::_trackY ( float  panelY,
float  panelH 
)
staticprivate

Definition at line 30 of file SpeedSlider.cpp.

Referenced by draw(), and handleInput().

+ Here is the caller graph for this function:

◆ currentSpeed()

int SpeedSlider::currentSpeed ( ) const
inline

Definition at line 54 of file SpeedSlider.hpp.

References _index, and STEPS.

◆ draw()

void SpeedSlider::draw ( int  scaledFontSize) const
overridevirtual

Draws the slider panel at the bottom-left of the screen.

Parameters
scaledFontSizePre-scaled font size matching the HUD.

Implements IWidget.

Definition at line 94 of file SpeedSlider.cpp.

References _dragging, _index, _trackW(), _trackX(), _trackY(), ACCENT_COLOR, BG_COLOR, BORDER_COLOR, BORDER_THICKNESS, TextRenderer::draw(), I18n::get(), HANDLE_DRAG_COLOR, HANDLE_RADIUS, PANEL_HEIGHT, PANEL_WIDTH, ROUNDNESS, SEGMENTS, I18n::SPEED_LABEL, STEPS, TRACK_BG_COLOR, TRACK_FILL_COLOR, and TRACK_H.

Referenced by RaylibRenderer::_drawSpeedSlider().

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

◆ getPendingSpeedChange()

std::optional< int > SpeedSlider::getPendingSpeedChange ( )

Returns and clears any pending speed change.

Definition at line 87 of file SpeedSlider.cpp.

References _pendingSpeed.

Referenced by RaylibRenderer::handleInput().

+ Here is the caller graph for this function:

◆ handleInput()

bool SpeedSlider::handleInput ( )
overridevirtual

Processes mouse input.

Returns
true if the slider consumed the input.

Implements IWidget.

Definition at line 50 of file SpeedSlider.cpp.

References _dragging, _index, _pendingSpeed, _trackW(), _trackX(), _trackY(), HANDLE_RADIUS, PANEL_HEIGHT, PANEL_WIDTH, and STEPS.

Referenced by RaylibRenderer::handleInput().

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

◆ reset()

void SpeedSlider::reset ( )
inline

Resets slider state. Call on reconnect so it re-syncs from the new server.

Definition at line 31 of file SpeedSlider.hpp.

References _dragging, and _initialized.

Referenced by RaylibRenderer::init().

+ Here is the caller graph for this function:

◆ syncFromServer()

void SpeedSlider::syncFromServer ( int  serverTimeUnit)

Snaps to the nearest step index matching serverTimeUnit. No-op if already initialized or serverTimeUnit is 0.

Definition at line 33 of file SpeedSlider.cpp.

References _index, _initialized, and STEPS.

Referenced by RaylibRenderer::_drawSpeedSlider().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _dragging

bool SpeedSlider::_dragging = false
private

Definition at line 58 of file SpeedSlider.hpp.

Referenced by draw(), handleInput(), and reset().

◆ _index

int SpeedSlider::_index = 23
private

Definition at line 57 of file SpeedSlider.hpp.

Referenced by currentSpeed(), draw(), handleInput(), and syncFromServer().

◆ _initialized

bool SpeedSlider::_initialized = false
private

Definition at line 59 of file SpeedSlider.hpp.

Referenced by reset(), and syncFromServer().

◆ _pendingSpeed

std::optional<int> SpeedSlider::_pendingSpeed = std::nullopt
private

Definition at line 60 of file SpeedSlider.hpp.

Referenced by getPendingSpeedChange(), and handleInput().

◆ PANEL_HEIGHT

constexpr int SpeedSlider::PANEL_HEIGHT = 58
staticconstexpr

Definition at line 20 of file SpeedSlider.hpp.

Referenced by draw(), handleInput(), and RaylibRenderer::handleInput().

◆ PANEL_WIDTH

constexpr int SpeedSlider::PANEL_WIDTH = 220
staticconstexpr

Definition at line 19 of file SpeedSlider.hpp.

Referenced by draw(), handleInput(), and RaylibRenderer::handleInput().

◆ STEPS

const std::vector< int > SpeedSlider::STEPS
static
Initial value:
= {1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 35,
40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90,
95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145,
150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200}

Definition at line 11 of file SpeedSlider.hpp.

Referenced by currentSpeed(), draw(), handleInput(), and syncFromServer().


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