mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 05:53:41 +08:00
mici: clean up onroad wheel colors (#39452)
This commit is contained in:
@@ -7,6 +7,8 @@ import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openpilot.starpilot.ui.raylib import rl
|
||||
|
||||
from opendbc.car.structs import car
|
||||
@@ -134,6 +136,7 @@ class CompactHudRenderer:
|
||||
self.fonts = fonts
|
||||
self.asset_directory = asset_directory
|
||||
self._wheel: rl.Texture | None = None
|
||||
self._wheel_highlight: rl.Texture | None = None
|
||||
self._feedback = WheelFeedbackFade()
|
||||
self._engaged_tint = CompactStatusFade(0.1)
|
||||
self._speed_limit_widget = SpeedLimitWidget(fonts, Profile.COMPACT)
|
||||
@@ -163,6 +166,18 @@ class CompactHudRenderer:
|
||||
self._wheel = rl.load_texture_from_image(image)
|
||||
if not self._wheel.id:
|
||||
raise RuntimeError("Unable to create compact wheel texture")
|
||||
rl.image_format(image, rl.PixelFormat.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
|
||||
width, height = image.width, image.height
|
||||
mask = np.frombuffer(image.to_bytes(width * height * 4), dtype=np.uint8).reshape(height, width, 4)[:, :, 3]
|
||||
y, x = np.ogrid[:height, :width]
|
||||
radius = np.hypot(2 * (x + .5) / width - 1, 2 * (y + .5) / height - 1)
|
||||
pixels = np.full((height, width, 4), 255, dtype=np.uint8)
|
||||
pixels[:, :, 3] = mask * np.clip((1 - radius) * .5, 0, .5)
|
||||
overlay = rl.load_texture_from_image(rl.Image(None, width, height, 1, rl.PixelFormat.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8))
|
||||
if overlay.id:
|
||||
rl.update_texture(overlay, pixels)
|
||||
rl.set_texture_filter(overlay, rl.TextureFilter.TEXTURE_FILTER_BILINEAR)
|
||||
self._wheel_highlight = overlay
|
||||
finally:
|
||||
if image.data is not None:
|
||||
rl.unload_image(image)
|
||||
@@ -210,16 +225,21 @@ class CompactHudRenderer:
|
||||
placement(state.customization, "compact", "steering_wheel")["enabled"]):
|
||||
self.prepare()
|
||||
size, _ = widget_size(state.customization, "compact", "steering_wheel")
|
||||
rl.draw_texture_pro(self._wheel, rl.Rectangle(0, 0, 50, 50),
|
||||
rl.Rectangle(21 + wx + size / 2, 176 + wy + size / 2 + wheel_y, size, size),
|
||||
rl.Vector2(size / 2, size / 2), 0,
|
||||
rl.Color(*color, int(wheel_alpha)))
|
||||
source = rl.Rectangle(0, 0, 50, 50)
|
||||
dest = rl.Rectangle(21 + wx + size / 2, 176 + wy + size / 2 + wheel_y, size, size)
|
||||
origin = rl.Vector2(size / 2, size / 2)
|
||||
rl.draw_texture_pro(self._wheel, source, dest, origin, 0, rl.Color(*color, int(wheel_alpha)))
|
||||
highlight = int(wheel_alpha * (1.0 if steer_warning else tint if not state.appearance.wheel_pedal_feedback else 0.0))
|
||||
if self._wheel_highlight is not None and highlight:
|
||||
rl.draw_texture_pro(self._wheel_highlight, source, dest, origin, 0, rl.Color(255, 255, 255, highlight))
|
||||
|
||||
def close(self) -> None:
|
||||
self._speed_limit_widget.close()
|
||||
if self._wheel is not None and rl.is_window_ready():
|
||||
rl.unload_texture(self._wheel)
|
||||
self._wheel = None
|
||||
if self._wheel_highlight is not None and rl.is_window_ready():
|
||||
rl.unload_texture(self._wheel_highlight)
|
||||
self._wheel = self._wheel_highlight = None
|
||||
|
||||
def _set_speed_opacity(self, state: OnroadState, now_ns: int) -> float:
|
||||
if state.drive_frame != self._cruise_drive_frame:
|
||||
|
||||
Reference in New Issue
Block a user