Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
SpeedSlider.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <vector>
5
6#include "IWidget.hpp"
7
17class SpeedSlider : public IWidget {
18 public:
19 static constexpr int PANEL_WIDTH = 220;
20 static constexpr int PANEL_HEIGHT = 58;
21
22 static const std::vector<int> STEPS;
23
28 void syncFromServer(int serverTimeUnit);
29
31 void reset()
32 {
33 _initialized = false;
34 _dragging = false;
35 }
36
41 bool handleInput() override;
42
46 std::optional<int> getPendingSpeedChange();
47
52 void draw(int scaledFontSize) const override;
53
54 int currentSpeed() const { return STEPS[_index]; }
55
56 private:
57 int _index = 23; // default: 100 (index 23 in STEPS)
58 bool _dragging = false;
59 bool _initialized = false;
60 std::optional<int> _pendingSpeed = std::nullopt;
61
62 static float _trackX(float panelX);
63 static float _trackY(float panelY, float panelH);
64 static float _trackW(float panelW);
65};
Interface for GUI widgets.
Interface for GUI widgets.
Definition IWidget.hpp:11
Self-contained speed slider widget.
static constexpr int PANEL_HEIGHT
static float _trackY(float panelY, float panelH)
void draw(int scaledFontSize) const override
Draws the slider panel at the bottom-left of the screen.
static float _trackW(float panelW)
std::optional< int > getPendingSpeedChange()
Returns and clears any pending speed change.
void syncFromServer(int serverTimeUnit)
Snaps to the nearest step index matching serverTimeUnit. No-op if already initialized or serverTimeUn...
static const std::vector< int > STEPS
void reset()
Resets slider state. Call on reconnect so it re-syncs from the new server.
int currentSpeed() const
static constexpr int PANEL_WIDTH
std::optional< int > _pendingSpeed
static float _trackX(float panelX)
bool handleInput() override
Processes mouse input.