Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions selfdrive/ui/mici/onroad/hud_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
SET_SPEED_NA = 255
KM_TO_MILE = 0.621371
CRUISE_DISABLED_CHAR = '–'

SET_SPEED_PERSISTENCE = 2.5 # seconds


Expand All @@ -34,10 +33,6 @@ class Colors:
WHITE_TRANSLUCENT = rl.Color(255, 255, 255, 200)


FONT_SIZES = FontSizes()
COLORS = Colors()


class TurnIntent(Widget):
FADE_IN_ANGLE = 30 # degrees

Expand Down Expand Up @@ -249,7 +244,7 @@ def _draw_set_speed(self, rect: rl.Rectangle) -> None:
self._font_display,
set_speed_text,
rl.Vector2(x + 13 + 4, y + 3 - 8 - 3 + 4),
FONT_SIZES.set_speed,
FontSizes.set_speed,
0,
set_speed_color,
)
Expand All @@ -258,20 +253,20 @@ def _draw_set_speed(self, rect: rl.Rectangle) -> None:
rl.draw_text_ex(
self._font_semi_bold,
max_text,
rl.Vector2(x + 25, y + FONT_SIZES.set_speed - 7 + 4),
FONT_SIZES.max_speed,
rl.Vector2(x + 25, y + FontSizes.set_speed - 7 + 4),
FontSizes.max_speed,
0,
max_color,
)

def _draw_current_speed(self, rect: rl.Rectangle) -> None:
"""Draw the current vehicle speed and unit."""
speed_text = str(round(self.speed))
speed_text_size = measure_text_cached(self._font_bold, speed_text, FONT_SIZES.current_speed)
speed_text_size = measure_text_cached(self._font_bold, speed_text, FontSizes.current_speed)
speed_pos = rl.Vector2(rect.x + rect.width / 2 - speed_text_size.x / 2, 180 - speed_text_size.y / 2)
rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FONT_SIZES.current_speed, 0, COLORS.WHITE)
rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FontSizes.current_speed, 0, Colors.WHITE)

unit_text = tr("km/h") if ui_state.is_metric else tr("mph")
unit_text_size = measure_text_cached(self._font_medium, unit_text, FONT_SIZES.speed_unit)
unit_text_size = measure_text_cached(self._font_medium, unit_text, FontSizes.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)
rl.draw_text_ex(self._font_medium, unit_text, unit_pos, FontSizes.speed_unit, 0, Colors.WHITE_TRANSLUCENT)
57 changes: 26 additions & 31 deletions selfdrive/ui/onroad/hud_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ class Colors:
HEADER_GRADIENT_END = rl.BLANK


UI_CONFIG = UIConfig()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they need to be dataclasses either, maybe enum if anything, but not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling in duplicate only in the hud_render.py

FONT_SIZES = FontSizes()
COLORS = Colors()


class HudRenderer(Widget):
def __init__(self):
super().__init__()
Expand All @@ -70,7 +65,7 @@ def __init__(self):
self._font_bold: rl.Font = gui_app.font(FontWeight.BOLD)
self._font_medium: rl.Font = gui_app.font(FontWeight.MEDIUM)

self._exp_button: ExpButton = ExpButton(UI_CONFIG.button_size, UI_CONFIG.wheel_icon_size)
self._exp_button: ExpButton = ExpButton(UIConfig.button_size, UIConfig.wheel_icon_size)

def _update_state(self) -> None:
"""Update HUD state based on car state and controls state."""
Expand Down Expand Up @@ -107,74 +102,74 @@ def _render(self, rect: rl.Rectangle) -> None:
int(rect.x),
int(rect.y),
int(rect.width),
UI_CONFIG.header_height,
COLORS.HEADER_GRADIENT_START,
COLORS.HEADER_GRADIENT_END,
UIConfig.header_height,
Colors.HEADER_GRADIENT_START,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the classes to all upper case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, shall we change the Colors of sidebar.py to capital letters as well?

sidebar.py

->

Color scheme

class Colors:
WHITE = rl.WHITE
WHITE_DIM = rl.Color(255, 255, 255, 85)
GRAY = rl.Color(84, 84, 84, 255)

Status colors

GOOD = rl.WHITE
WARNING = rl.Color(218, 202, 37, 255)
DANGER = rl.Color(201, 34, 49, 255)
UP_TO_DATE = rl.Color(128, 216, 166, 255)

UI elements

METRIC_BORDER = rl.Color(255, 255, 255, 85)
BUTTON_NORMAL = rl.WHITE
BUTTON_PRESSED = rl.Color(255, 255, 255, 166)

Colors.HEADER_GRADIENT_END,
)

if self.is_cruise_available:
self._draw_set_speed(rect)

self._draw_current_speed(rect)

button_x = rect.x + rect.width - UI_CONFIG.border_size - UI_CONFIG.button_size
button_y = rect.y + UI_CONFIG.border_size
self._exp_button.render(rl.Rectangle(button_x, button_y, UI_CONFIG.button_size, UI_CONFIG.button_size))
button_x = rect.x + rect.width - UIConfig.border_size - UIConfig.button_size
button_y = rect.y + UIConfig.border_size
self._exp_button.render(rl.Rectangle(button_x, button_y, UIConfig.button_size, UIConfig.button_size))

def user_interacting(self) -> bool:
return self._exp_button.is_pressed

def _draw_set_speed(self, rect: rl.Rectangle) -> None:
"""Draw the MAX speed indicator box."""
set_speed_width = UI_CONFIG.set_speed_width_metric if ui_state.is_metric else UI_CONFIG.set_speed_width_imperial
x = rect.x + 60 + (UI_CONFIG.set_speed_width_imperial - set_speed_width) // 2
set_speed_width = UIConfig.set_speed_width_metric if ui_state.is_metric else UIConfig.set_speed_width_imperial
x = rect.x + 60 + (UIConfig.set_speed_width_imperial - set_speed_width) // 2
y = rect.y + 45

set_speed_rect = rl.Rectangle(x, y, set_speed_width, UI_CONFIG.set_speed_height)
rl.draw_rectangle_rounded(set_speed_rect, 0.35, 10, COLORS.BLACK_TRANSLUCENT)
rl.draw_rectangle_rounded_lines_ex(set_speed_rect, 0.35, 10, 6, COLORS.BORDER_TRANSLUCENT)
set_speed_rect = rl.Rectangle(x, y, set_speed_width, UIConfig.set_speed_height)
rl.draw_rectangle_rounded(set_speed_rect, 0.35, 10, Colors.BLACK_TRANSLUCENT)
rl.draw_rectangle_rounded_lines_ex(set_speed_rect, 0.35, 10, 6, Colors.BORDER_TRANSLUCENT)

max_color = COLORS.GREY
set_speed_color = COLORS.DARK_GREY
max_color = Colors.GREY
set_speed_color = Colors.DARK_GREY
if self.is_cruise_set:
set_speed_color = COLORS.WHITE
set_speed_color = Colors.WHITE
if ui_state.status == UIStatus.ENGAGED:
max_color = COLORS.ENGAGED
max_color = Colors.ENGAGED
elif ui_state.status == UIStatus.DISENGAGED:
max_color = COLORS.DISENGAGED
max_color = Colors.DISENGAGED
elif ui_state.status == UIStatus.OVERRIDE:
max_color = COLORS.OVERRIDE
max_color = Colors.OVERRIDE

max_text = tr("MAX")
max_text_width = measure_text_cached(self._font_semi_bold, max_text, FONT_SIZES.max_speed).x
max_text_width = measure_text_cached(self._font_semi_bold, max_text, FontSizes.max_speed).x
rl.draw_text_ex(
self._font_semi_bold,
max_text,
rl.Vector2(x + (set_speed_width - max_text_width) / 2, y + 27),
FONT_SIZES.max_speed,
FontSizes.max_speed,
0,
max_color,
)

set_speed_text = CRUISE_DISABLED_CHAR if not self.is_cruise_set else str(round(self.set_speed))
speed_text_width = measure_text_cached(self._font_bold, set_speed_text, FONT_SIZES.set_speed).x
speed_text_width = measure_text_cached(self._font_bold, set_speed_text, FontSizes.set_speed).x
rl.draw_text_ex(
self._font_bold,
set_speed_text,
rl.Vector2(x + (set_speed_width - speed_text_width) / 2, y + 77),
FONT_SIZES.set_speed,
FontSizes.set_speed,
0,
set_speed_color,
)

def _draw_current_speed(self, rect: rl.Rectangle) -> None:
"""Draw the current vehicle speed and unit."""
speed_text = str(round(self.speed))
speed_text_size = measure_text_cached(self._font_bold, speed_text, FONT_SIZES.current_speed)
speed_text_size = measure_text_cached(self._font_bold, speed_text, FontSizes.current_speed)
speed_pos = rl.Vector2(rect.x + rect.width / 2 - speed_text_size.x / 2, 180 - speed_text_size.y / 2)
rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FONT_SIZES.current_speed, 0, COLORS.WHITE)
rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FontSizes.current_speed, 0, Colors.WHITE)

unit_text = tr("km/h") if ui_state.is_metric else tr("mph")
unit_text_size = measure_text_cached(self._font_medium, unit_text, FONT_SIZES.speed_unit)
unit_text_size = measure_text_cached(self._font_medium, unit_text, FontSizes.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)
rl.draw_text_ex(self._font_medium, unit_text, unit_pos, FontSizes.speed_unit, 0, Colors.WHITE_TRANSLUCENT)
Loading