raylib: show touches flag for debugging (#35671)

* show touches

* type
pull/35674/head
Shane Smiskol 6 days ago committed by GitHub
parent 17d9b12693
commit c9731d6aa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      system/ui/lib/application.py

@ -4,19 +4,21 @@ import os
import time import time
import pyray as rl import pyray as rl
from collections.abc import Callable from collections.abc import Callable
from collections import deque
from dataclasses import dataclass from dataclasses import dataclass
from enum import IntEnum from enum import IntEnum
from importlib.resources import as_file, files from importlib.resources import as_file, files
from openpilot.common.swaglog import cloudlog from openpilot.common.swaglog import cloudlog
from openpilot.system.hardware import HARDWARE from openpilot.system.hardware import HARDWARE
DEFAULT_FPS = 60 DEFAULT_FPS = int(os.getenv("FPS", "60"))
FPS_LOG_INTERVAL = 5 # Seconds between logging FPS drops FPS_LOG_INTERVAL = 5 # Seconds between logging FPS drops
FPS_DROP_THRESHOLD = 0.9 # FPS drop threshold for triggering a warning FPS_DROP_THRESHOLD = 0.9 # FPS drop threshold for triggering a warning
FPS_CRITICAL_THRESHOLD = 0.5 # Critical threshold for triggering strict actions FPS_CRITICAL_THRESHOLD = 0.5 # Critical threshold for triggering strict actions
ENABLE_VSYNC = os.getenv("ENABLE_VSYNC", "1") == "1" ENABLE_VSYNC = os.getenv("ENABLE_VSYNC", "1") == "1"
SHOW_FPS = os.getenv("SHOW_FPS") == '1' SHOW_FPS = os.getenv("SHOW_FPS") == '1'
SHOW_TOUCHES = os.getenv("SHOW_TOUCHES") == '1'
STRICT_MODE = os.getenv("STRICT_MODE") == '1' STRICT_MODE = os.getenv("STRICT_MODE") == '1'
SCALE = float(os.getenv("SCALE", "1.0")) SCALE = float(os.getenv("SCALE", "1.0"))
@ -61,6 +63,9 @@ class GuiApplication:
self._trace_log_callback = None self._trace_log_callback = None
self._modal_overlay = ModalOverlay() self._modal_overlay = ModalOverlay()
# Debug variables
self._mouse_history: deque[rl.Vector2] = deque(maxlen=DEFAULT_FPS * 2)
def request_close(self): def request_close(self):
self._window_close_requested = True self._window_close_requested = True
@ -190,6 +195,19 @@ class GuiApplication:
if SHOW_FPS: if SHOW_FPS:
rl.draw_fps(10, 10) rl.draw_fps(10, 10)
if SHOW_TOUCHES:
if rl.is_mouse_button_pressed(rl.MouseButton.MOUSE_BUTTON_LEFT):
self._mouse_history.clear()
self._mouse_history.append(rl.get_mouse_position())
if self._mouse_history:
mouse_pos = self._mouse_history[-1]
rl.draw_circle(int(mouse_pos.x), int(mouse_pos.y), 15, rl.RED)
for idx, mouse_pos in enumerate(self._mouse_history):
perc = idx / len(self._mouse_history)
color = rl.Color(min(int(255 * (1.5 - perc)), 255), int(min(255 * (perc + 0.5), 255)), 50, 255)
rl.draw_circle(int(mouse_pos.x), int(mouse_pos.y), 5, color)
rl.end_drawing() rl.end_drawing()
self._monitor_fps() self._monitor_fps()
except KeyboardInterrupt: except KeyboardInterrupt:

Loading…
Cancel
Save