From cc2cf306f32c856f5b76f0c49adb1a35a39a232f Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sat, 11 May 2024 13:04:46 -0700 Subject: [PATCH] Visuals - Custom Onroad UI - Road Name Display the current road's name at the bottom of the screen. Sourced from OpenStreetMap. Credit goes to Pfeiferj! https: //github.com/pfeiferj Co-Authored-By: Jacob Pfeifer --- selfdrive/ui/qt/onroad.cc | 24 ++++++++++++++++++++---- selfdrive/ui/qt/onroad.h | 1 + selfdrive/ui/ui.cc | 1 + selfdrive/ui/ui.h | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 6204883..f2e14ed 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -230,7 +230,7 @@ void OnroadAlerts::paintEvent(QPaintEvent *event) { int margin = 40; int radius = 30; - int offset = scene.show_aol_status_bar || scene.show_cem_status_bar ? 25 : 0; + int offset = scene.show_aol_status_bar || scene.show_cem_status_bar || scene.road_name_ui ? 25 : 0; if (alert.size == cereal::ControlsState::AlertSize::FULL) { margin = 0; radius = 0; @@ -715,7 +715,7 @@ void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s) int offset = UI_BORDER_SIZE + btn_size / 2; int x = rightHandDM ? width() - offset : offset; x += onroadDistanceButton ? 250 : 0; - offset += showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar ? 25 : 0; + offset += showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar || roadNameUI ? 25 : 0; int y = height() - offset; float opacity = dmActive ? 0.65 : 0.2; drawIcon(painter, QPoint(x, y), dm_img, blackColor(70), opacity); @@ -951,6 +951,8 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets() { onroadDistanceButton = scene.onroad_distance_button; + roadNameUI = scene.road_name_ui; + speedLimitController = scene.speed_limit_controller; showSLCOffset = speedLimitController && scene.show_slc_offset; slcOverridden = speedLimitController && scene.speed_limit_overridden; @@ -961,7 +963,7 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets() { } void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) { - if (showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar) { + if (showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar || roadNameUI) { drawStatusBar(p); } @@ -1288,6 +1290,8 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) { {16, tr("Experimental Mode activated for stop") + (mapOpen ? "" : tr(" sign / stop light"))}, }; + QString roadName = roadNameUI ? QString::fromStdString(paramsMemory.get("RoadName")) : QString(); + if (alwaysOnLateralActive && showAlwaysOnLateralStatusBar) { newStatus = tr("Always On Lateral active") + (mapOpen ? "" : tr(". Press the \"Cruise Control\" button to disable")); } else if (showConditionalExperimentalStatusBar) { @@ -1308,7 +1312,7 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) { } } - if (newStatus != lastShownStatus) { + if (newStatus != lastShownStatus || roadName.isEmpty()) { displayStatusText = true; lastShownStatus = newStatus; timer.restart(); @@ -1320,10 +1324,15 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) { p.setPen(Qt::white); p.setRenderHint(QPainter::TextAntialiasing); + static qreal roadNameOpacity; static qreal statusTextOpacity; int elapsed = timer.elapsed(); if (displayStatusText) { statusTextOpacity = qBound(0.0, 1.0 - (elapsed - textDuration) / fadeDuration, 1.0); + roadNameOpacity = 1.0 - statusTextOpacity; + } else { + roadNameOpacity = qBound(0.0, elapsed / fadeDuration, 1.0); + statusTextOpacity = 0.0; } p.setOpacity(statusTextOpacity); @@ -1331,5 +1340,12 @@ void AnnotatedCameraWidget::drawStatusBar(QPainter &p) { textRect.moveBottom(statusBarRect.bottom() - 50); p.drawText(textRect, Qt::AlignCenter | Qt::TextWordWrap, newStatus); + if (!roadName.isEmpty()) { + p.setOpacity(roadNameOpacity); + textRect = p.fontMetrics().boundingRect(statusBarRect, Qt::AlignCenter | Qt::TextWordWrap, roadName); + textRect.moveBottom(statusBarRect.bottom() - 50); + p.drawText(textRect, Qt::AlignCenter | Qt::TextWordWrap, roadName); + } + p.restore(); } diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 6c83430..0ab92ae 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -201,6 +201,7 @@ private: bool experimentalMode; bool mapOpen; bool onroadDistanceButton; + bool roadNameUI; bool showAlwaysOnLateralStatusBar; bool showConditionalExperimentalStatusBar; bool showSLCOffset; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 76105f1..e3098c6 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -309,6 +309,7 @@ void ui_update_frogpilot_params(UIState *s) { scene.pedals_on_ui = custom_onroad_ui && params.getBool("PedalsOnUI"); scene.dynamic_pedals_on_ui = scene.pedals_on_ui && params.getBool("DynamicPedalsOnUI"); scene.static_pedals_on_ui = scene.pedals_on_ui && params.getBool("StaticPedalsOnUI"); + scene.road_name_ui = custom_onroad_ui && params.getBool("RoadNameUI"); scene.disable_smoothing_mtsc = params.getBool("MTSCEnabled") && params.getBool("DisableMTSCSmoothing"); scene.disable_smoothing_vtsc = params.getBool("VisionTurnControl") && params.getBool("DisableVTSCSmoothing"); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 4fb458b..f5080fd 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -210,6 +210,7 @@ typedef struct UIScene { bool reverse_cruise; bool reverse_cruise_ui; bool right_hand_drive; + bool road_name_ui; bool show_aol_status_bar; bool show_cem_status_bar; bool show_slc_offset;