ui: HUD drawing optimizations and fixes (#1342)

* no duplicated speed drawing

* reuse polygon
This commit is contained in:
Jason Wen
2025-10-09 10:28:56 -04:00
committed by GitHub
parent 73123aa400
commit 6d356d520e
2 changed files with 8 additions and 6 deletions
+7 -6
View File
@@ -21,6 +21,8 @@ HudRendererSP::HudRendererSP() {
green_light_alert_large_img = loadPixmap("../../sunnypilot/selfdrive/assets/images/green_light.png", {large_max, large_max});
lead_depart_alert_small_img = loadPixmap("../../sunnypilot/selfdrive/assets/images/lead_depart.png", {small_max, small_max});
lead_depart_alert_large_img = loadPixmap("../../sunnypilot/selfdrive/assets/images/lead_depart.png", {large_max, large_max});
standstillTimerOctagon.reserve(8);
}
void HudRendererSP::updateState(const UIState &s) {
@@ -132,7 +134,6 @@ void HudRendererSP::draw(QPainter &p, const QRect &surface_rect) {
if (is_cruise_available) {
drawSetSpeedSP(p, surface_rect);
}
drawCurrentSpeedSP(p, surface_rect);
if (!hideVEgoUI) {
drawCurrentSpeedSP(p, surface_rect);
@@ -404,19 +405,19 @@ void HudRendererSP::drawStandstillTimer(QPainter &p, int x, int y) {
// stop sign for standstill timer
const int size = 190; // size
const float angle = M_PI / 8.0;
const float angle = M_PI / 8.0f;
QPolygon octagon;
standstillTimerOctagon.clear();
for (int i = 0; i < 8; i++) {
float curr_angle = angle + i * M_PI / 4.0;
float curr_angle = angle + i * M_PI / 4.0f;
int point_x = x + size / 2 * cos(curr_angle);
int point_y = y + size / 2 * sin(curr_angle);
octagon << QPoint(point_x, point_y);
standstillTimerOctagon << QPoint(point_x, point_y);
}
p.setPen(QPen(Qt::white, 6));
p.setBrush(QColor(255, 90, 81, 200)); // red pastel
p.drawPolygon(octagon);
p.drawPolygon(standstillTimerOctagon);
QString time_str = QString("%1:%2").arg(minute, 1, 10, QChar('0')).arg(second, 2, 10, QChar('0'));
p.setFont(InterFont(55, QFont::Bold));
+1
View File
@@ -69,6 +69,7 @@ private:
bool standstillTimer;
bool isStandstill;
float standstillElapsedTime;
QPolygon standstillTimerOctagon;
bool longOverride;
bool smartCruiseControlVisionEnabled;
bool smartCruiseControlVisionActive;