mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-03 22:53:44 +08:00
Not quite a pollo bowl
This commit is contained in:
@@ -7,6 +7,16 @@ import pyray as rl
|
||||
from openpilot.common.params import Params
|
||||
|
||||
|
||||
_BORDER_ROUNDNESS = 0.12
|
||||
_BORDER_RADIUS_MULTIPLE = 3.0
|
||||
|
||||
|
||||
def get_border_roundness(rect: rl.Rectangle, border_width: float) -> float:
|
||||
"""Keep a rectangular camera inset inside the rounded frame at thin widths."""
|
||||
min_dimension = max(1.0, min(rect.width, rect.height))
|
||||
return min(_BORDER_ROUNDNESS, 2.0 * _BORDER_RADIUS_MULTIPLE * border_width / min_dimension)
|
||||
|
||||
|
||||
def blend_colors(a: rl.Color, b: rl.Color, f: float) -> rl.Color:
|
||||
h0, s0, v0 = (hsv0 := rl.color_to_hsv(a)).x, hsv0.y, hsv0.z
|
||||
h1, s1, v1 = (hsv1 := rl.color_to_hsv(b)).x, hsv1.y, hsv1.z
|
||||
|
||||
@@ -11,6 +11,7 @@ from openpilot.selfdrive.ui.ui_state import ui_state
|
||||
from openpilot.selfdrive.ui.lib.starpilot_status import (
|
||||
CEM_OVERRIDE_COLOR, ENGAGED_COLOR, EXPERIMENTAL_COLOR, TRAFFIC_COLOR
|
||||
)
|
||||
from openpilot.selfdrive.ui.lib.starpilot_visuals import get_border_roundness
|
||||
|
||||
|
||||
|
||||
@@ -218,6 +219,7 @@ def get_traffic_border_colors() -> tuple[rl.Color, rl.Color] | None:
|
||||
def render_background_effects(rect: rl.Rectangle, border_width: float):
|
||||
global _smoothed_steer
|
||||
sm = ui_state.sm
|
||||
border_roundness = get_border_roundness(rect, border_width)
|
||||
|
||||
# 1. Turn Signal and Blind Spot indicators
|
||||
colors = get_traffic_border_colors()
|
||||
@@ -225,11 +227,11 @@ def render_background_effects(rect: rl.Rectangle, border_width: float):
|
||||
left_color, right_color = colors
|
||||
if left_color.a > 0:
|
||||
rl.begin_scissor_mode(int(rect.x), int(rect.y), int(rect.width // 2), int(rect.height))
|
||||
rl.draw_rectangle_rounded(rect, 0.12, 10, left_color)
|
||||
rl.draw_rectangle_rounded(rect, border_roundness, 10, left_color)
|
||||
rl.end_scissor_mode()
|
||||
if right_color.a > 0:
|
||||
rl.begin_scissor_mode(int(rect.x + rect.width // 2), int(rect.y), int(rect.width // 2), int(rect.height))
|
||||
rl.draw_rectangle_rounded(rect, 0.12, 10, right_color)
|
||||
rl.draw_rectangle_rounded(rect, border_roundness, 10, right_color)
|
||||
rl.end_scissor_mode()
|
||||
|
||||
# 2. Steering Torque Border
|
||||
@@ -262,7 +264,7 @@ def render_background_effects(rect: rl.Rectangle, border_width: float):
|
||||
else:
|
||||
rl.begin_scissor_mode(int(rect.x + rect.width - border_width), y_pos, int(border_width), int(visible_height))
|
||||
|
||||
rl.draw_rectangle_rounded(rect, 0.12, 10, col)
|
||||
rl.draw_rectangle_rounded(rect, border_roundness, 10, col)
|
||||
rl.end_scissor_mode()
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from openpilot.selfdrive.ui.onroad.starpilot.weather_icon import render_weather_
|
||||
from openpilot.selfdrive.ui.lib.starpilot_status import (
|
||||
get_screen_edge_color,
|
||||
)
|
||||
from openpilot.selfdrive.ui.lib.starpilot_visuals import get_border_roundness
|
||||
from openpilot.starpilot.common.favorite_slots import (
|
||||
build_favorite_slot_options,
|
||||
filter_favorite_slot_options,
|
||||
@@ -100,8 +101,9 @@ class StarPilotOnroadView(AugmentedRoadView):
|
||||
|
||||
def _render(self, rect: rl.Rectangle):
|
||||
border_width = self._get_border_width()
|
||||
border_roundness = get_border_roundness(rect, border_width)
|
||||
border_color = get_pulse_glide_border_color(ui_state.sm, get_screen_edge_color(ui_state))
|
||||
rl.draw_rectangle_rounded(rect, 0.12, 10, border_color)
|
||||
rl.draw_rectangle_rounded(rect, border_roundness, 10, border_color)
|
||||
render_background_effects(rect, border_width)
|
||||
|
||||
# The favorite menu has first claim on the lower-left gesture. Filtering
|
||||
@@ -159,7 +161,8 @@ class StarPilotOnroadView(AugmentedRoadView):
|
||||
|
||||
def _draw_border(self, rect: rl.Rectangle):
|
||||
border_width = self._get_border_width()
|
||||
rl.draw_rectangle_rounded_lines_ex(rect, 0.12, 10, border_width, rl.BLACK)
|
||||
border_roundness = get_border_roundness(rect, border_width)
|
||||
rl.draw_rectangle_rounded_lines_ex(rect, border_roundness, 10, border_width, rl.BLACK)
|
||||
border_rect = rl.Rectangle(rect.x + border_width, rect.y + border_width,
|
||||
rect.width - 2 * border_width, rect.height - 2 * border_width)
|
||||
render_overlay(border_rect, border_width)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import importlib.util
|
||||
import math
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parents[1] / "lib" / "starpilot_visuals.py"
|
||||
@@ -9,6 +11,7 @@ MODULE = importlib.util.module_from_spec(SPEC)
|
||||
assert SPEC is not None and SPEC.loader is not None
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
lead_indicator_enabled = MODULE.lead_indicator_enabled
|
||||
get_border_roundness = MODULE.get_border_roundness
|
||||
|
||||
|
||||
class FakeParams:
|
||||
@@ -29,6 +32,21 @@ class FakeParams:
|
||||
|
||||
|
||||
class TestStarPilotVisuals(unittest.TestCase):
|
||||
def test_border_roundness_contains_camera_corner(self):
|
||||
rect = SimpleNamespace(width=2160, height=1080)
|
||||
base_width = 30
|
||||
min_dimension = min(rect.width, rect.height)
|
||||
|
||||
for scale in (25, 50, 65, 100, 250):
|
||||
border_width = round(base_width * scale / 100)
|
||||
roundness = get_border_roundness(rect, border_width)
|
||||
radius = roundness * min_dimension / 2
|
||||
self.assertLessEqual(math.sqrt(2) * (radius - border_width), radius)
|
||||
|
||||
def test_border_roundness_preserves_stock_geometry(self):
|
||||
rect = SimpleNamespace(width=2160, height=1080)
|
||||
self.assertAlmostEqual(get_border_roundness(rect, 30), 0.12)
|
||||
|
||||
def test_lead_indicator_enabled_by_default(self):
|
||||
self.assertTrue(lead_indicator_enabled(FakeParams()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user