From da35e601018d3b7a0a06a0716f0cf433d555d208 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 25 Nov 2025 18:10:40 -0500 Subject: [PATCH] ui: display mouse coordinates with debug mode (#1512) * ui: add debug to display mouse coordinates * cleanup * use mouse x and y directly * even less * try this out * ui: increase `scroll` delay in UI Preview * sleep for clicks too * don't lol * try 1 secs * try this out * wait a sec before doing a screenshot * nah --- selfdrive/ui/layouts/settings/developer.py | 1 + system/ui/lib/application.py | 5 +++++ system/ui/sunnypilot/lib/application.py | 25 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/selfdrive/ui/layouts/settings/developer.py b/selfdrive/ui/layouts/settings/developer.py index f47cd310c..e3e462c54 100644 --- a/selfdrive/ui/layouts/settings/developer.py +++ b/selfdrive/ui/layouts/settings/developer.py @@ -148,6 +148,7 @@ class DeveloperLayout(Widget): self._params.put_bool("ShowDebugInfo", state) gui_app.set_show_touches(state) gui_app.set_show_fps(state) + gui_app.set_show_mouse_coords(state) def _on_enable_adb(self, state: bool): self._params.put_bool("AdbEnabled", state) diff --git a/system/ui/lib/application.py b/system/ui/lib/application.py index 727112783..e4850e9cb 100644 --- a/system/ui/lib/application.py +++ b/system/ui/lib/application.py @@ -227,6 +227,8 @@ class GuiApplication(GuiApplicationExt): self._render_profiler = None self._render_profile_start_time = None + GuiApplicationExt.__init__(self) + @property def frame(self): return self._frame @@ -467,6 +469,9 @@ class GuiApplication(GuiApplicationExt): if self._show_touches: self._draw_touch_points() + if self._show_mouse_coords: + self._draw_mouse_coordinates(gui_app.font(FontWeight.SEMI_BOLD)) + if self._grid_size > 0: self._draw_grid() diff --git a/system/ui/sunnypilot/lib/application.py b/system/ui/sunnypilot/lib/application.py index b39bf31e9..481886e37 100644 --- a/system/ui/sunnypilot/lib/application.py +++ b/system/ui/sunnypilot/lib/application.py @@ -6,10 +6,35 @@ See the LICENSE.md file in the root directory for more details. """ import os +import pyray as rl + +SHOW_MOUSE_COORDS = os.getenv("SHOW_MOUSE_COORDS") == "1" SUNNYPILOT_UI = os.getenv("SUNNYPILOT_UI", "1") == "1" class GuiApplicationExt: + def __init__(self): + self._show_mouse_coords = SHOW_MOUSE_COORDS + @staticmethod def sunnypilot_ui() -> bool: return SUNNYPILOT_UI + + def _draw_mouse_coordinates(self, font): + coords_text = f"X:{int(rl.get_mouse_x())}, Y:{int(rl.get_mouse_y())}" + + green_color = rl.Color(0, 159, 47, 255) # Match the green color of FPS counter + + # Calculate text width to position it at the right edge; estimate width based on text length + # Each character is approximately 10-12 pixels wide at font size 20 + estimated_text_width = len(coords_text) * 11 + + # Position text at the top right corner, 10px from the top + screen_width = self._scaled_width if self._scale != 1.0 else self._width + text_pos = rl.Vector2(screen_width - estimated_text_width - 10, 6) + + # Draw the text + rl.draw_text_ex(font, coords_text, text_pos, 20, 0, green_color) + + def set_show_mouse_coords(self, show: bool): + self._show_mouse_coords = show