fix(gui): Stop game time clock from jittering horizontally#2860
fix(gui): Stop game time clock from jittering horizontally#2860bobtista wants to merge 1 commit into
Conversation
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h | Adds two Int member fields (m_gameTimeReservedWidth, m_gameTimeFrameReservedWidth) to InGameUI; straightforward, correctly aligned with surrounding members. |
| GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp | Initialises both reserved-width fields to 0 in the constructor; computes them from per-glyph measurements in refreshGameTimeResources(); uses the fixed values in drawGameTime() to anchor the timer left edge, with the frame counter following the timer's live right edge. Logic is correct. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["refreshGameTimeResources()"] --> B["Iterate digits '0'–'9'\nfind maxDigitWidth"]
B --> C["Measure ':' → colonWidth\nMeasure '.' → dotWidth"]
C --> D["m_gameTimeReservedWidth\n= 6×maxDigitWidth + 2×colonWidth\n\nm_gameTimeFrameReservedWidth\n= dotWidth + 2×maxDigitWidth"]
D --> E["Stored once per resource refresh"]
F["drawGameTime() (every frame)"] --> G["Set timer text HH:MM:SS\nSet frame text .NN"]
G --> H["horizontalTimerOffset\n= screenWidth − pos.x\n − ReservedWidth − FrameReservedWidth\n(FIXED left edge)"]
H --> I["horizontalFrameOffset\n= horizontalTimerOffset\n + gameTimeString.getWidth()\n(live, adjacent to timer text)"]
I --> J["Draw white timer at horizontalTimerOffset\nDraw grey .NN at horizontalFrameOffset"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["refreshGameTimeResources()"] --> B["Iterate digits '0'–'9'\nfind maxDigitWidth"]
B --> C["Measure ':' → colonWidth\nMeasure '.' → dotWidth"]
C --> D["m_gameTimeReservedWidth\n= 6×maxDigitWidth + 2×colonWidth\n\nm_gameTimeFrameReservedWidth\n= dotWidth + 2×maxDigitWidth"]
D --> E["Stored once per resource refresh"]
F["drawGameTime() (every frame)"] --> G["Set timer text HH:MM:SS\nSet frame text .NN"]
G --> H["horizontalTimerOffset\n= screenWidth − pos.x\n − ReservedWidth − FrameReservedWidth\n(FIXED left edge)"]
H --> I["horizontalFrameOffset\n= horizontalTimerOffset\n + gameTimeString.getWidth()\n(live, adjacent to timer text)"]
I --> J["Draw white timer at horizontalTimerOffset\nDraw grey .NN at horizontalFrameOffset"]
Reviews (1): Last reviewed commit: "fix(gui): Stop game time clock from jitt..." | Re-trigger Greptile
Addresses #2859
drawGameTime() positioned the top-right clock by subtracting live-measured text width every frame, right-anchored to the screen edge. With the proportional Tahoma font, digit widths change as the time ticks (and the .NN frame counter changes every frame), so the whole timer shifted a pixel or two each frame.
Reserve a fixed width per field from the widest digit and anchor the timer's left edge to it so the white clock no longer moves as digits change. The frame counter is butted against the timer's live right edge so the two stay adjacent.
TODO: