11const std::vector<int>
SpeedSlider::STEPS = {1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 35,
12 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90,
13 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145,
14 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200};
22static constexpr Color
BG_COLOR = {20, 25, 35, 180};
38 int bestDiff = std::abs(
STEPS[0] - serverTimeUnit);
39 for (
int i = 1; i < static_cast<int>(
STEPS.size()); i++) {
40 int diff = std::abs(
STEPS[i] - serverTimeUnit);
41 if (diff < bestDiff) {
52 int sh = GetScreenHeight();
53 Rectangle panelRect = {10.0f,
static_cast<float>(sh -
PANEL_HEIGHT - 10),
56 float tx =
_trackX(panelRect.x);
57 float ty =
_trackY(panelRect.y, panelRect.height);
58 float tw =
_trackW(panelRect.width);
60 float t =
static_cast<float>(
_index) /
static_cast<float>(
STEPS.size() - 1);
61 float handleX = tx + tw * t;
66 Vector2 mouse = GetMousePosition();
68 if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) &&
69 (CheckCollisionPointRec(mouse, panelRect) || CheckCollisionPointRec(mouse, handleHit)))
73 if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
77 float frac = (mouse.x - tx) / tw;
78 frac = frac < 0.0f ? 0.0f : (frac > 1.0f ? 1.0f : frac);
79 _index =
static_cast<int>(frac *
static_cast<float>(
STEPS.size() - 1) + 0.5f);
96 int sh = GetScreenHeight();
98 float panelY =
static_cast<float>(sh -
PANEL_HEIGHT - 10);
102 Rectangle rect = {panelX, panelY, panelW, panelH};
108 TextRenderer::draw(label,
static_cast<int>(panelX + 10),
static_cast<int>(panelY + 8),
112 float ty =
_trackY(panelY, panelH);
117 float t =
static_cast<float>(
_index) /
static_cast<float>(
STEPS.size() - 1);
118 float fillW = tw * t;
122 float handleX = tx + fillW;
124 DrawCircle(
static_cast<int>(handleX),
static_cast<int>(ty),
HANDLE_RADIUS, handleColor);
static constexpr Color ACCENT_COLOR
static constexpr float TRACK_H
static constexpr Color HANDLE_DRAG_COLOR
static constexpr float BORDER_THICKNESS
static constexpr Color TRACK_FILL_COLOR
static constexpr float HANDLE_RADIUS
static constexpr float ROUNDNESS
static constexpr Color BORDER_COLOR
static constexpr Color TRACK_BG_COLOR
static constexpr int SEGMENTS
static constexpr Color BG_COLOR
static const char * get(Key key)
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
static constexpr int PANEL_WIDTH
std::optional< int > _pendingSpeed
static float _trackX(float panelX)
bool handleInput() override
Processes mouse input.
static void draw(const std::string &text, int x, int y, int fontSize, Color color)