mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-19 00:02:08 +08:00
Big UI : Dedicated to Dora and all the Explorers
This commit is contained in:
@@ -3,6 +3,7 @@ from dataclasses import dataclass
|
||||
from openpilot.common.constants import CV
|
||||
from openpilot.selfdrive.ui.onroad.exp_button import ExpButton
|
||||
from openpilot.selfdrive.ui.onroad.starpilot.navigation_card import NavigationCardRenderer
|
||||
from openpilot.selfdrive.ui.onroad.starpilot.compass import get_compass_text
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
|
||||
from openpilot.system.ui.lib.application import gui_app, FontWeight
|
||||
from openpilot.system.ui.lib.multilang import tr
|
||||
@@ -190,3 +191,10 @@ class HudRenderer(Widget):
|
||||
unit_text_size = measure_text_cached(self._font_medium, unit_text, FONT_SIZES.speed_unit)
|
||||
unit_pos = rl.Vector2(rect.x + rect.width / 2 - unit_text_size.x / 2, 290 - unit_text_size.y / 2)
|
||||
rl.draw_text_ex(self._font_medium, unit_text, unit_pos, FONT_SIZES.speed_unit, 0, COLORS.WHITE_TRANSLUCENT)
|
||||
|
||||
compass_text = get_compass_text()
|
||||
if compass_text:
|
||||
compass_font_size = 50
|
||||
compass_size = measure_text_cached(self._font_bold, compass_text, compass_font_size)
|
||||
compass_pos = rl.Vector2(rect.x + rect.width / 2 - compass_size.x / 2, 65 - compass_size.y / 2)
|
||||
rl.draw_text_ex(self._font_bold, compass_text, compass_pos, compass_font_size, 0, rl.Color(255, 255, 255, 180))
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import pyray as rl
|
||||
from openpilot.selfdrive.ui.ui_state import ui_state
|
||||
from openpilot.system.ui.lib.text_measure import measure_text_cached
|
||||
|
||||
def render_compass(rect: rl.Rectangle, font):
|
||||
def get_compass_text() -> str | None:
|
||||
if not ui_state.params.get_bool("Compass"):
|
||||
return
|
||||
return None
|
||||
|
||||
# Retrieve bearing
|
||||
bearing = 0.0
|
||||
@@ -21,55 +19,7 @@ def render_compass(rect: rl.Rectangle, font):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Draw background
|
||||
rl.draw_rectangle_rounded(rect, 0.2, 10, rl.Color(0, 0, 0, 166))
|
||||
rl.draw_rectangle_rounded_lines_ex(rect, 0.2, 10, 4, rl.Color(0, 0, 0, 255))
|
||||
|
||||
# Clip ribbon to widget boundary
|
||||
rl.begin_scissor_mode(int(rect.x + 4), int(rect.y + 4), int(rect.width - 8), int(rect.height - 8))
|
||||
|
||||
# Display range: +/- 45 degrees
|
||||
range_deg = 45
|
||||
pixels_per_degree = rect.width / (range_deg * 2.0)
|
||||
|
||||
start_deg = int(bearing - range_deg)
|
||||
end_deg = int(bearing + range_deg) + 1
|
||||
|
||||
labels = {0: "N", 45: "NE", 90: "E", 135: "SE", 180: "S", 225: "SW", 270: "W", 315: "NW"}
|
||||
|
||||
for deg in range(start_deg, end_deg):
|
||||
norm_deg = (deg + 360) % 360
|
||||
offset_deg = deg - bearing
|
||||
x = rect.x + rect.width / 2.0 + offset_deg * pixels_per_degree
|
||||
|
||||
if rect.x <= x <= rect.x + rect.width:
|
||||
if norm_deg % 45 == 0:
|
||||
notch_height = 25
|
||||
notch_width = 3
|
||||
lbl = labels.get(norm_deg, "")
|
||||
if lbl:
|
||||
lbl_sz = measure_text_cached(font, lbl, 22)
|
||||
rl.draw_text_ex(font, lbl, rl.Vector2(int(x - lbl_sz.x / 2), int(rect.y + 12)), 22, 0, rl.WHITE)
|
||||
elif norm_deg % 15 == 0:
|
||||
notch_height = 15
|
||||
notch_width = 2
|
||||
elif norm_deg % 5 == 0:
|
||||
notch_height = 8
|
||||
notch_width = 1
|
||||
else:
|
||||
continue
|
||||
|
||||
y_start = rect.y + rect.height - notch_height - 10
|
||||
y_end = rect.y + rect.height - 10
|
||||
rl.draw_line_ex(rl.Vector2(int(x), int(y_start)), rl.Vector2(int(x), int(y_end)), notch_width, rl.WHITE)
|
||||
|
||||
rl.end_scissor_mode()
|
||||
|
||||
# Draw static triangular pointer pointing UP at bottom center
|
||||
triangle_size = 12
|
||||
tx = rect.x + rect.width / 2
|
||||
ty = rect.y + rect.height - 12
|
||||
v1 = rl.Vector2(int(tx), int(ty - triangle_size))
|
||||
v2 = rl.Vector2(int(tx - triangle_size / 1.5), int(ty))
|
||||
v3 = rl.Vector2(int(tx + triangle_size / 1.5), int(ty))
|
||||
rl.draw_triangle(v1, v2, v3, rl.WHITE)
|
||||
bearing = bearing % 360
|
||||
directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
|
||||
idx = int((bearing + 22.5) // 45) % 8
|
||||
return f"- {directions[idx]} -"
|
||||
|
||||
@@ -391,38 +391,19 @@ class StarPilotOnroadView(AugmentedRoadView):
|
||||
from openpilot.selfdrive.ui.onroad.starpilot.pause_indicators import render_longitudinal_paused
|
||||
render_longitudinal_paused(badge_rect)
|
||||
|
||||
# 2. Render Compass & Weather (on the opposite side of DM icon)
|
||||
# Dimensions
|
||||
compass_w = 120
|
||||
compass_h = 120
|
||||
weather_w = 120
|
||||
weather_h = 120
|
||||
|
||||
# Determine compass position
|
||||
if not dm.is_rhd:
|
||||
# LHD: Compass on the far right
|
||||
cx = self._content_rect.x + self._content_rect.width - 30 - compass_w
|
||||
else:
|
||||
# RHD: Compass on the far left
|
||||
cx = self._content_rect.x + 30
|
||||
|
||||
cy = dm.position_y - compass_h / 2
|
||||
compass_rect = rl.Rectangle(cx, cy, compass_w, compass_h)
|
||||
|
||||
# Render Compass
|
||||
from openpilot.selfdrive.ui.onroad.starpilot.compass import render_compass
|
||||
render_compass(compass_rect, self._font_medium)
|
||||
|
||||
# Render Weather next to Compass
|
||||
# 2. Render Weather (on the opposite side of DM icon)
|
||||
plan = ui_state.sm["starpilotPlan"] if ui_state.sm.valid.get("starpilotPlan", False) else None
|
||||
if plan and plan.weatherId != 0:
|
||||
weather_w = 120
|
||||
weather_h = 120
|
||||
if not dm.is_rhd:
|
||||
# LHD: Weather to the left of Compass
|
||||
wx = cx - spacing - weather_w
|
||||
# LHD: Weather on the far right
|
||||
wx = self._content_rect.x + self._content_rect.width - 30 - weather_w
|
||||
else:
|
||||
# RHD: Weather to the right of Compass
|
||||
wx = cx + compass_w + spacing
|
||||
# RHD: Weather on the far left
|
||||
wx = self._content_rect.x + 30
|
||||
|
||||
cy = dm.position_y - weather_h / 2
|
||||
weather_rect = rl.Rectangle(wx, cy, weather_w, weather_h)
|
||||
from openpilot.selfdrive.ui.onroad.starpilot.weather_icon import render_weather_icon
|
||||
render_weather_icon(weather_rect)
|
||||
|
||||
Reference in New Issue
Block a user