feat: add FS25_FarmHUD mod and FarmHUD desktop companion app
Initial commit: the FS25 Lua mod (live.json data export), the FS25-WebDashboard project (Node/web dashboard + PySide6 desktop variant), and FarmHUD (standalone PySide6 companion app with Discord Rich Presence, settings, and installer).
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""60-second speed sparkline - native repaint of the `#speedHistory` canvas."""
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
from PySide6.QtGui import QColor, QPainter, QPen
|
||||
from PySide6.QtWidgets import QWidget
|
||||
|
||||
WINDOW_S = 60.0
|
||||
|
||||
|
||||
class SpeedHistoryWidget(QWidget):
|
||||
def __init__(self, accent: str, parent=None) -> None:
|
||||
super().__init__(parent)
|
||||
self._accent = QColor(accent)
|
||||
self._points: list[tuple[float, float]] = []
|
||||
self.setMinimumHeight(48)
|
||||
|
||||
def set_accent(self, accent: str) -> None:
|
||||
self._accent = QColor(accent)
|
||||
self.update()
|
||||
|
||||
def set_points(self, points: list[tuple[float, float]]) -> None:
|
||||
self._points = points
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, event) -> None: # noqa: N802
|
||||
if len(self._points) < 2:
|
||||
return
|
||||
painter = QPainter(self)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
|
||||
w = self.width()
|
||||
h = self.height()
|
||||
now = time.monotonic()
|
||||
max_v = max(20.0, max(p[1] for p in self._points))
|
||||
|
||||
pen = QPen(self._accent, 2)
|
||||
painter.setPen(pen)
|
||||
|
||||
path_points = []
|
||||
for t, v in self._points:
|
||||
fx = 1 - (now - t) / WINDOW_S
|
||||
x = fx * w
|
||||
y = h - (v / max_v) * (h - 4) - 2
|
||||
path_points.append((x, y))
|
||||
|
||||
for i in range(1, len(path_points)):
|
||||
x0, y0 = path_points[i - 1]
|
||||
x1, y1 = path_points[i]
|
||||
painter.drawLine(int(x0), int(y0), int(x1), int(y1))
|
||||
Reference in New Issue
Block a user