From 48717d2b08fdb3820a06a0e2552d41aa67e08d47 Mon Sep 17 00:00:00 2001 From: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Date: Fri, 27 Nov 2026 13:05:51 -0500 Subject: [PATCH] Remove Aethergauge unused transitions --- openpilot/starpilot/ui/onroad_cem_gauge.py | 129 ++++++++------------- 1 file changed, 50 insertions(+), 79 deletions(-) diff --git a/openpilot/starpilot/ui/onroad_cem_gauge.py b/openpilot/starpilot/ui/onroad_cem_gauge.py index 37a18731e3..662539de2b 100644 --- a/openpilot/starpilot/ui/onroad_cem_gauge.py +++ b/openpilot/starpilot/ui/onroad_cem_gauge.py @@ -54,30 +54,8 @@ COLOR_CEM_SPEED = rl.Color(112, 192, 216, 255) COLOR_REDUCTION = rl.Color(255, 191, 0, 220) -def _channels(color): - """Extract (r, g, b, a) from either an rl.Color struct or a 4-tuple.""" - if hasattr(color, "r"): - return color.r, color.g, color.b, color.a - return color[0], color[1], color[2], color[3] - -def _with_alpha(color, a: int) -> rl.Color: - r, g, b, _ = _channels(color) - return rl.Color(r, g, b, max(0, min(255, a))) - -def _fade(color, alpha: float) -> rl.Color: - r, g, b, a = _channels(color) - return rl.Color(r, g, b, max(0, min(255, int(a * alpha)))) - -def _lerp_color(a, b, t: float) -> rl.Color: - t = max(0.0, min(1.0, t)) - ar, ag, ab, _ = _channels(a) - br, bg, bb, _ = _channels(b) - return rl.Color( - ar + int((br - ar) * t), - ag + int((bg - ag) * t), - ab + int((bb - ab) * t), - 255, - ) +def _with_alpha(color: rl.Color, a: int) -> rl.Color: + return rl.Color(color.r, color.g, color.b, max(0, min(255, a))) def _pulse(freq: float) -> float: return 0.5 + 0.5 * math.sin(rl.get_time() * freq) @@ -105,11 +83,10 @@ def _get_perspective_offset(t: float, data: 'AetherGaugeData | None') -> float: max_offset_top = math.tanh(path_y_far * PERSPECTIVE_GAIN) * PERSPECTIVE_MAX_OFFSET return max_offset_top * (t ** PERSPECTIVE_EXPONENT) -def _draw_text_with_shadow(fonts: BitmapFonts, role: FontRole, text: str, pos: rl.Vector2, size: int, - color: rl.Color, alpha: float = 1.0): +def _draw_text_with_shadow(fonts: BitmapFonts, role: FontRole, text: str, pos: rl.Vector2, size: int, color: rl.Color): for dx, dy in ((-1, -1), (1, -1), (-1, 1), (1, 1)): - fonts.draw(text, role, size, pos.x + dx, pos.y + dy, _fade(rl.BLACK, alpha)) - fonts.draw(text, role, size, pos.x, pos.y, _fade(color, alpha)) + fonts.draw(text, role, size, pos.x + dx, pos.y + dy, rl.BLACK) + fonts.draw(text, role, size, pos.x, pos.y, color) class IndicatorType(Enum): @@ -199,7 +176,7 @@ class AetherGauge: rect = rl.Rectangle(saved['x'] - CEM_GAUGE_INSET[0], saved['y'] - CEM_GAUGE_INSET[1], *CEM_GAUGE_FRAME) self._render_unified_road(rect, rect.x + rect.width / 2, rect.y + 145 - ROAD_HALF_SIZE, data) - def _render_unified_road(self, rect, icx, icy, data, alpha=1.0): + def _render_unified_road(self, rect, icx, icy, data): bottom = icy + ROAD_HALF_SIZE if data.indicator_type == IndicatorType.STOP_LIGHT: @@ -223,35 +200,34 @@ class AetherGauge: points_left.append(rl.Vector2(cx_t - w_t, y_t)) points_right.append(rl.Vector2(cx_t + w_t, y_t)) - fill_color = _fade(_with_alpha(data.color, FILL_ALPHA), alpha) + fill_color = _with_alpha(data.color, FILL_ALPHA) for i in range(ROAD_SEGMENTS): t = i / ROAD_SEGMENTS stroke = ROAD_THICKNESS * (1.0 - 0.6 * t) rl.draw_triangle(points_left[i], points_right[i], points_left[i+1], fill_color) rl.draw_triangle(points_right[i], points_right[i+1], points_left[i+1], fill_color) - rl.draw_line_ex(points_left[i], points_left[i+1], stroke, _fade(COLOR_SHADOW, alpha)) - rl.draw_line_ex(points_right[i], points_right[i+1], stroke, _fade(COLOR_SHADOW, alpha)) - rl.draw_line_ex(points_left[i], points_left[i+1], stroke, _fade(data.color, alpha)) - rl.draw_line_ex(points_right[i], points_right[i+1], stroke, _fade(data.color, alpha)) + rl.draw_line_ex(points_left[i], points_left[i+1], stroke, COLOR_SHADOW) + rl.draw_line_ex(points_right[i], points_right[i+1], stroke, COLOR_SHADOW) + rl.draw_line_ex(points_left[i], points_left[i+1], stroke, data.color) + rl.draw_line_ex(points_right[i], points_right[i+1], stroke, data.color) it = data.indicator_type if it == IndicatorType.STOP_LIGHT: - self._draw_stop_line(icx, bottom, distance, data, alpha) + self._draw_stop_line(icx, bottom, distance, data) if it == IndicatorType.LEAD: - self._draw_lead_car(icx, bottom, data, alpha) + self._draw_lead_car(icx, bottom, data) if it in (IndicatorType.ROAD_CURVE, IndicatorType.STOP_LIGHT): - self._draw_standard_chevrons(icx, bottom, distance, data, alpha) + self._draw_standard_chevrons(icx, bottom, distance, data) if it == IndicatorType.STOP_LIGHT: - self._draw_traffic_light(icx, icy, distance, data, alpha) + self._draw_traffic_light(icx, icy, distance, data) + self._draw_mini_cradle(icx, bottom, data) - self._draw_mini_cradle(icx, bottom, data, alpha) - - def _draw_stop_line(self, icx, bottom, distance, data, alpha=1.0): + def _draw_stop_line(self, icx, bottom, distance, data): t, cx_line, cy_line = _road_xy(distance, icx, bottom, data, self._current_road_h) w_line = ROAD_W_BOTTOM - t * (ROAD_W_BOTTOM - ROAD_W_TOP) @@ -261,10 +237,10 @@ class AetherGauge: fade = 1.0 - t * 0.5 glow_a = int(150 * fade) - rl.draw_line_ex(p_left, p_right, max(3.0 * SCALE, 7.0 * SCALE * fade), _fade(_with_alpha(COLOR_STOP_LINE_GLOW, glow_a), alpha)) - rl.draw_line_ex(p_left, p_right, max(1.5 * SCALE, 3.5 * SCALE * fade), _fade(COLOR_STOP_LINE_CORE, alpha)) + rl.draw_line_ex(p_left, p_right, max(3.0 * SCALE, 7.0 * SCALE * fade), _with_alpha(COLOR_STOP_LINE_GLOW, glow_a)) + rl.draw_line_ex(p_left, p_right, max(1.5 * SCALE, 3.5 * SCALE * fade), COLOR_STOP_LINE_CORE) - def _draw_lead_car(self, icx, bottom, data, alpha=1.0): + def _draw_lead_car(self, icx, bottom, data): t_lead, cx_lead, cy_lead = _road_xy(6.5, icx, bottom, data, self._current_road_h) t_lead = max(0.15, min(0.85, t_lead)) @@ -276,16 +252,16 @@ class AetherGauge: is_slower = data.indicator_extra == "slower" if is_stopped: - border_color = _fade(COLOR_LEAD_STOPPED, alpha) + border_color = COLOR_LEAD_STOPPED elif is_slower: - border_color = _fade(_with_alpha(data.color, int(160 + 95 * _pulse(1.2))), alpha) + border_color = _with_alpha(data.color, int(160 + 95 * _pulse(1.2))) else: - border_color = _fade(data.color, alpha) + border_color = data.color # Car body: cabin and main body with high-contrast outlines for rect_args, corner_r, fill in [ - ((cx_lead - W * 0.3, cy_lead - H, W * 0.6, H * 0.45), 0.5, _fade(rl.Color(15, 15, 15, 240), alpha)), - ((cx_lead - W / 2, cy_lead - H * 0.65, W, H * 0.55), 0.3, _fade(rl.Color(20, 20, 20, 240), alpha)), + ((cx_lead - W * 0.3, cy_lead - H, W * 0.6, H * 0.45), 0.5, rl.Color(15, 15, 15, 240)), + ((cx_lead - W / 2, cy_lead - H * 0.65, W, H * 0.55), 0.3, rl.Color(20, 20, 20, 240)), ]: r = rl.Rectangle(*rect_args) rl.draw_rectangle_rounded(r, corner_r, 4, fill) @@ -301,23 +277,23 @@ class AetherGauge: if is_stopped: pulse = _pulse(2.5) r_glow = int(W * 0.10 * (1.0 + 0.4 * pulse)) - rl.draw_circle(glow_x, glow_y, r_glow + 4, _fade(rl.Color(255, 30, 60, int(60 + 40 * pulse)), alpha)) - rl.draw_circle(glow_x, glow_y, r_glow, _fade(rl.Color(255, 30, 60, int(150 + 105 * pulse)), alpha)) - c_tl = _fade(rl.Color(255, 220, 220, 255), alpha) + rl.draw_circle(glow_x, glow_y, r_glow + 4, rl.Color(255, 30, 60, int(60 + 40 * pulse))) + rl.draw_circle(glow_x, glow_y, r_glow, rl.Color(255, 30, 60, int(150 + 105 * pulse))) + c_tl = rl.Color(255, 220, 220, 255) elif is_slower: pulse = _pulse(1.2) r_glow = int(W * 0.08 * (1.0 + 0.2 * pulse)) - rl.draw_circle(glow_x, glow_y, r_glow, _fade(rl.Color(255, 140, 30, int(100 + 80 * pulse)), alpha)) - c_tl = _fade(rl.Color(255, 160, 60, int(180 + 75 * pulse)), alpha) + rl.draw_circle(glow_x, glow_y, r_glow, rl.Color(255, 140, 30, int(100 + 80 * pulse))) + c_tl = rl.Color(255, 160, 60, int(180 + 75 * pulse)) else: - c_tl = _fade(COLOR_FORCE_STOP, alpha) + c_tl = COLOR_FORCE_STOP rl.draw_rectangle(tl_x, tl_y, int(tl_w), int(tl_h), c_tl) # Wheels wheel_y = int(cy_lead - H * 0.1) wheel_w = int(W * 0.12) wheel_h = int(H * 0.1) - wheel_c = _fade(rl.Color(10, 10, 10, 255), alpha) + wheel_c = rl.Color(10, 10, 10, 255) rl.draw_rectangle(int(cx_lead - W * 0.4), wheel_y, wheel_w, wheel_h, wheel_c) rl.draw_rectangle(int(cx_lead + W * 0.28), wheel_y, wheel_w, wheel_h, wheel_c) @@ -340,12 +316,12 @@ class AetherGauge: rx = cx_t + chevron_w chev_a = max(0, min(255, int(data.color.a * (1.0 - t / t_lead) * math.sin(t / t_lead * math.pi)))) - c_color = _fade(_with_alpha(data.color, chev_a), alpha) + c_color = _with_alpha(data.color, chev_a) rl.draw_line_ex(rl.Vector2(lx, cy_t - chevron_w * 0.5), rl.Vector2(cx_t, cy_t), chevron_thick, c_color) rl.draw_line_ex(rl.Vector2(rx, cy_t - chevron_w * 0.5), rl.Vector2(cx_t, cy_t), chevron_thick, c_color) - def _draw_standard_chevrons(self, icx, bottom, distance, data, alpha=1.0): + def _draw_standard_chevrons(self, icx, bottom, distance, data): is_stop = data.indicator_type == IndicatorType.STOP_LIGHT dt = rl.get_frame_time() v_ego = self._speed_mps @@ -387,15 +363,15 @@ class AetherGauge: alpha_factor = math.sin((t / max_t) * math.pi) if max_t > 0.01 else 0.0 chev_a = max(0, min(255, int(data.color.a * alpha_factor))) - chev_color = _fade(_with_alpha(data.color, chev_a), alpha) - chev_shadow = _fade(rl.Color(0, 0, 0, int(chev_a * 0.5)), alpha) + chev_color = _with_alpha(data.color, chev_a) + chev_shadow = rl.Color(0, 0, 0, int(chev_a * 0.5)) rl.draw_line_ex(rl.Vector2(lx, ly + 1.5), rl.Vector2(cx_t, cy_t + 1.5), chevron_thick, chev_shadow) rl.draw_line_ex(rl.Vector2(rx, ry + 1.5), rl.Vector2(cx_t, cy_t + 1.5), chevron_thick, chev_shadow) rl.draw_line_ex(rl.Vector2(lx, ly), rl.Vector2(cx_t, cy_t), chevron_thick, chev_color) rl.draw_line_ex(rl.Vector2(rx, ry), rl.Vector2(cx_t, cy_t), chevron_thick, chev_color) - def _draw_traffic_light(self, icx, icy, distance, data, alpha=1.0): + def _draw_traffic_light(self, icx, icy, distance, data): t_light, cx_light, cy_road = _road_xy(distance, icx, icy + ROAD_HALF_SIZE, data, self._current_road_h) s_light = 1.0 - t_light @@ -404,10 +380,10 @@ class AetherGauge: width = 15.0 * SCALE * scale_light height = 36.0 * SCALE * scale_light - rl.draw_rectangle_rounded(rl.Rectangle(cx_light - width/2, cy_light - height/2 + 1.5, width, height), 0.25, 4, _fade(rl.Color(0, 0, 0, 120), alpha)) + rl.draw_rectangle_rounded(rl.Rectangle(cx_light - width/2, cy_light - height/2 + 1.5, width, height), 0.25, 4, rl.Color(0, 0, 0, 120)) rect_housing = rl.Rectangle(cx_light - width/2, cy_light - height/2, width, height) - rl.draw_rectangle_rounded(rect_housing, 0.25, 4, _fade(rl.Color(22, 22, 22, 255), alpha)) - rl.draw_rectangle_rounded_lines_ex(rect_housing, 0.25, 4, 1.5, _fade(rl.Color(100, 100, 100, 255), alpha)) + rl.draw_rectangle_rounded(rect_housing, 0.25, 4, rl.Color(22, 22, 22, 255)) + rl.draw_rectangle_rounded_lines_ex(rect_housing, 0.25, 4, 1.5, rl.Color(100, 100, 100, 255)) r_bulb = 3.2 * SCALE * scale_light active_light = data.indicator_extra if data.indicator_extra in ("red", "yellow", "green") else "red" @@ -420,40 +396,35 @@ class AetherGauge: for y, name, active_c, inactive_c in bulbs: if name == "red" and active_light == "red": glow_pulse = _pulse(1.5) - rl.draw_circle_v(rl.Vector2(cx_light, y), r_bulb + 8.0 * SCALE * glow_pulse, _fade(rl.Color(255, 30, 60, 25), alpha)) - rl.draw_circle_v(rl.Vector2(cx_light, y), r_bulb + 4.0 * SCALE * glow_pulse, _fade(rl.Color(255, 30, 60, 60), alpha)) - c = _fade(active_c if active_light == name else inactive_c, alpha) - rl.draw_circle_v(rl.Vector2(cx_light, y), r_bulb, c) + rl.draw_circle_v(rl.Vector2(cx_light, y), r_bulb + 8.0 * SCALE * glow_pulse, rl.Color(255, 30, 60, 25)) + rl.draw_circle_v(rl.Vector2(cx_light, y), r_bulb + 4.0 * SCALE * glow_pulse, rl.Color(255, 30, 60, 60)) + rl.draw_circle_v(rl.Vector2(cx_light, y), r_bulb, active_c if active_light == name else inactive_c) - def _draw_mini_cradle(self, cx, bottom, data, alpha=1.0): + def _draw_mini_cradle(self, cx, bottom, data): if not data.text: return if data.is_numeric: val_size = self.fonts.measure(data.text, FontRole.BOLD, int(50 * SCALE)) val_pos = rl.Vector2(int(cx - val_size.width / 2), int(bottom + 6 * SCALE)) - _draw_text_with_shadow(self.fonts, FontRole.BOLD, data.text, val_pos, int(50 * SCALE), data.color, alpha) + _draw_text_with_shadow(self.fonts, FontRole.BOLD, data.text, val_pos, int(50 * SCALE), data.color) accent_y = int(val_pos.y + val_size.height + 2 * SCALE) accent_w = int(val_size.width + 16 * SCALE) accent_x = int(cx - accent_w / 2) - rl.draw_line_ex( - rl.Vector2(accent_x, accent_y), - rl.Vector2(accent_x + accent_w, accent_y), - 2.0 * SCALE, - _fade(_with_alpha(data.color, 160), alpha), - ) + rl.draw_line_ex(rl.Vector2(accent_x, accent_y), rl.Vector2(accent_x + accent_w, accent_y), 2.0 * SCALE, + _with_alpha(data.color, 160)) if data.reduction_text: red_size = self.fonts.measure(data.reduction_text, FontRole.MEDIUM, int(22 * SCALE)) red_pos = rl.Vector2(int(cx + val_size.width / 2 + 6 * SCALE), int(val_pos.y + val_size.height / 2 - red_size.height / 2)) - _draw_text_with_shadow(self.fonts, FontRole.MEDIUM, data.reduction_text, red_pos, int(22 * SCALE), COLOR_REDUCTION, alpha) + _draw_text_with_shadow(self.fonts, FontRole.MEDIUM, data.reduction_text, red_pos, int(22 * SCALE), COLOR_REDUCTION) if data.unit: unit_size = self.fonts.measure(data.unit, FontRole.MEDIUM, int(20 * SCALE)) unit_pos = rl.Vector2(int(cx - unit_size.width / 2), int(accent_y + 3 * SCALE)) - _draw_text_with_shadow(self.fonts, FontRole.MEDIUM, data.unit, unit_pos, int(20 * SCALE), rl.Color(255, 255, 255, 180), alpha) + _draw_text_with_shadow(self.fonts, FontRole.MEDIUM, data.unit, unit_pos, int(20 * SCALE), rl.Color(255, 255, 255, 180)) else: val_size = self.fonts.measure(data.text, FontRole.BOLD, int(32 * SCALE)) val_pos = rl.Vector2(int(cx - val_size.width / 2), int(bottom + 10 * SCALE)) - _draw_text_with_shadow(self.fonts, FontRole.BOLD, data.text, val_pos, int(32 * SCALE), data.color, alpha) + _draw_text_with_shadow(self.fonts, FontRole.BOLD, data.text, val_pos, int(32 * SCALE), data.color)