From d798288b2cd52ab1adbbbd6869fcee9d6f96e8e7 Mon Sep 17 00:00:00 2001 From: James Vecellio Date: Mon, 3 Nov 2025 06:54:03 -0800 Subject: [PATCH] more --- selfdrive/ui/sunnypilot/qt/onroad/hud.cc | 87 +++++++++++++++++--- selfdrive/ui/sunnypilot/qt/onroad/hud.h | 7 +- sunnypilot/selfdrive/assets/nav_left.png | 3 - sunnypilot/selfdrive/assets/nav_right.png | 3 - sunnypilot/selfdrive/assets/nav_straight.png | 3 - 5 files changed, 78 insertions(+), 25 deletions(-) delete mode 100644 sunnypilot/selfdrive/assets/nav_left.png delete mode 100644 sunnypilot/selfdrive/assets/nav_right.png delete mode 100644 sunnypilot/selfdrive/assets/nav_straight.png diff --git a/selfdrive/ui/sunnypilot/qt/onroad/hud.cc b/selfdrive/ui/sunnypilot/qt/onroad/hud.cc index 33a5b8bcad..8e797fe7ff 100644 --- a/selfdrive/ui/sunnypilot/qt/onroad/hud.cc +++ b/selfdrive/ui/sunnypilot/qt/onroad/hud.cc @@ -15,10 +15,6 @@ HudRendererSP::HudRendererSP() { plus_arrow_up_img = loadPixmap("../../sunnypilot/selfdrive/assets/img_plus_arrow_up", {90, 90}); minus_arrow_down_img = loadPixmap("../../sunnypilot/selfdrive/assets/img_minus_arrow_down", {90, 90}); - nav_left_img = loadPixmap("../../sunnypilot/selfdrive/assets/nav_left", {176, 176}); - nav_right_img = loadPixmap("../../sunnypilot/selfdrive/assets/nav_right", {176, 176}); - nav_straight_img = loadPixmap("../../sunnypilot/selfdrive/assets/nav_straight", {176, 176}); - int size = e2e_alert_size * 2 - 40; green_light_alert_img = loadPixmap("../../sunnypilot/selfdrive/assets/images/green_light.png", {size, size}); lead_depart_alert_img = loadPixmap("../../sunnypilot/selfdrive/assets/images/lead_depart.png", {size, size}); @@ -194,8 +190,8 @@ void HudRendererSP::updateState(const UIState &s) { navigationStreet = instruction; } } else { - navigationStreet = "---"; - navigationDistance = "---"; + navigationStreet = "W. Gonzalez Blvd."; // sample fields for metadrive sim (@nayan) + navigationDistance = "5.8 mi"; navigationArrowType = "straight"; } } @@ -943,21 +939,26 @@ void HudRendererSP::drawNavigationHUD(QPainter &p, const QRect &surface_rect) { int arrowSize = 176; int cy_offset = (navigationArrowType == "left" || navigationArrowType == "right") ? -20 : 0; int cx = x - 100; - int cy = y + arrowSize/2 + cy_offset; + int textY = y + arrowSize/2 + cy_offset; + int cy = (navigationArrowType == "straight") ? textY + 20 : textY + 60; // make straight more centered-ish bc its big boy + + p.save(); + p.setPen(Qt::NoPen); + p.setBrush(Qt::white); - QPixmap arrow_img; if (navigationArrowType == "left") { - arrow_img = nav_left_img; + drawLeftArrow(p, cx, cy, arrowSize); } else if (navigationArrowType == "right") { - arrow_img = nav_right_img; + drawRightArrow(p, cx, cy, arrowSize); } else { - arrow_img = nav_straight_img; + drawStraightArrow(p, cx, cy, arrowSize); } - p.drawPixmap(cx - arrowSize/2, cy - arrowSize/2, arrowSize, arrowSize, arrow_img); + p.restore(); + int gap = (navigationArrowType == "left") ? -10 : 20; int textX = cx + arrowSize/2 + gap; - int textY = y + arrowSize/2; + if (navigationArrowType == "right") textX += 40; // move that beech over for right arrow // Draw distance text p.setFont(InterFont(80, QFont::Bold)); @@ -968,3 +969,63 @@ void HudRendererSP::drawNavigationHUD(QPainter &p, const QRect &surface_rect) { int streetY = textY + 60; // draw street name below distance text p.drawText(textX, streetY, navigationStreet); } + +void HudRendererSP::drawStraightArrow(QPainter &p, int cx, int cy, int size) { + int rectWidth = size * 0.2; + int rectHeight = size * 0.6; + int rectX = cx - rectWidth / 2; + int rectY = cy - rectHeight / 2; + p.drawRect(rectX, rectY, rectWidth, rectHeight); + + int triangleHeight = size * 0.3; + int triangleBaseWidth = rectWidth * 3; + QPolygon triangle; + triangle << QPoint(cx - triangleBaseWidth / 2, rectY) + << QPoint(cx + triangleBaseWidth / 2, rectY) + << QPoint(cx, rectY - triangleHeight); + p.drawPolygon(triangle); +} + +void HudRendererSP::drawLeftArrow(QPainter &p, int cx, int cy, int size) { + int vertHeight = size * 0.6; + int vertWidth = size * 0.2; + int vertX = cx - vertWidth / 2; + int vertY = cy - vertHeight; + p.drawRect(vertX, vertY, vertWidth, vertHeight); + + int horizWidth = size * 0.4; + int horizHeight = size * 0.2; + int horizX = cx - horizWidth + vertWidth / 2 + 1; // 1 to adjust pix gap bc my math ain't mathing today + int horizY = cy - vertHeight - horizHeight / 2; + p.drawRect(horizX, horizY, horizWidth, horizHeight); + + int triangleWidth = size * 0.4; + int triangleHeight = size * 0.4; + QPolygon triangle; + triangle << QPoint(horizX, horizY + horizHeight / 2 - triangleHeight / 2) + << QPoint(horizX, horizY + horizHeight / 2 + triangleHeight / 2) + << QPoint(horizX - triangleWidth, horizY + horizHeight / 2); + p.drawPolygon(triangle); // I think i dislike qpolygons. they're mad annoying +} + +void HudRendererSP::drawRightArrow(QPainter &p, int cx, int cy, int size) { + int vertHeight = size * 0.6; + int vertWidth = size * 0.2; + int vertX = cx - vertWidth / 2; + int vertY = cy - vertHeight; + p.drawRect(vertX, vertY, vertWidth, vertHeight); + + int horizWidth = size * 0.4; + int horizHeight = size * 0.2; + int horizX = cx - vertWidth / 2; + int horizY = cy - vertHeight - horizHeight / 2; + p.drawRect(horizX, horizY, horizWidth, horizHeight); + + int triangleWidth = size * 0.4; + int triangleHeight = size * 0.4; + QPolygon triangle; + triangle << QPoint(horizX + horizWidth, horizY + horizHeight / 2 - triangleHeight / 2) + << QPoint(horizX + horizWidth, horizY + horizHeight / 2 + triangleHeight / 2) + << QPoint(horizX + horizWidth + triangleWidth, horizY + horizHeight / 2); + p.drawPolygon(triangle); +} diff --git a/selfdrive/ui/sunnypilot/qt/onroad/hud.h b/selfdrive/ui/sunnypilot/qt/onroad/hud.h index 47df291a40..af2b0e149b 100644 --- a/selfdrive/ui/sunnypilot/qt/onroad/hud.h +++ b/selfdrive/ui/sunnypilot/qt/onroad/hud.h @@ -41,6 +41,10 @@ private: void drawBlinker(QPainter &p, const QRect &surface_rect); void drawNavigationHUD(QPainter &p, const QRect &surface_rect); + void drawStraightArrow(QPainter &p, int cx, int cy, int size); + void drawLeftArrow(QPainter &p, int cx, int cy, int size); + void drawRightArrow(QPainter &p, int cx, int cy, int size); + bool lead_status; float lead_d_rel; float lead_v_rel; @@ -126,7 +130,4 @@ private: QString navigationStreet; QString navigationDistance; QString navigationArrowType; - QPixmap nav_left_img; - QPixmap nav_right_img; - QPixmap nav_straight_img; }; diff --git a/sunnypilot/selfdrive/assets/nav_left.png b/sunnypilot/selfdrive/assets/nav_left.png deleted file mode 100644 index 1622c7b389..0000000000 --- a/sunnypilot/selfdrive/assets/nav_left.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:946954b61ee5c89f01481cb030a6364f5ee447b4c8408f64214510e30b53715d -size 780 diff --git a/sunnypilot/selfdrive/assets/nav_right.png b/sunnypilot/selfdrive/assets/nav_right.png deleted file mode 100644 index 36ff2ff4e6..0000000000 --- a/sunnypilot/selfdrive/assets/nav_right.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a5ef8830e879dec513eee7bdab7dbb035b09fbccd8bcce61f0c8bf2c731380b8 -size 777 diff --git a/sunnypilot/selfdrive/assets/nav_straight.png b/sunnypilot/selfdrive/assets/nav_straight.png deleted file mode 100644 index 83f5c52a79..0000000000 --- a/sunnypilot/selfdrive/assets/nav_straight.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:74d5e2d8b69a997e2f8661145581277972718f17ead82c2401a62de0911731f5 -size 839