Skip to content

Commit

Permalink
Referencing FORG's approach, dynamically determine the display positi…
Browse files Browse the repository at this point in the history
…on of the compass on the screen.
  • Loading branch information
Edison-CBS committed Aug 27, 2023
1 parent 795e851 commit 3a4fcb2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) {
propagateEvent = true;
} else {
recentlyTapped = true;
propagateEvent = true;
propagateEvent = true;
}

// propagation event to parent(HomeWindow)
Expand Down Expand Up @@ -308,10 +308,13 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par
main_layout->addWidget(experimental_btn, 0, Qt::AlignTop | Qt::AlignRight);

map_settings_btn = new MapSettingsButton(this);
main_layout->addWidget(map_settings_btn, 0, Qt::AlignBottom | Qt::AlignRight);
const bool flip_side = rightHandDM || compass;
const bool move_up = false;
const bool move_up_top = compass;
main_layout->addWidget(map_settings_btn, 0, (flip_side ? Qt::AlignLeft : Qt::AlignRight) | (move_up ? Qt::AlignCenter : move_up_top ? Qt::AlignTop : Qt::AlignBottom));

dm_img = loadPixmap("../assets/img_driver_face.png", {img_size + 5, img_size + 5});

// FrogPilot images
compass_inner_img = loadPixmap("../assets/images/compass_inner.png", {img_size, img_size});

Expand Down Expand Up @@ -377,7 +380,10 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
// hide map settings button for alerts and flip for right hand DM
if (map_settings_btn->isEnabled()) {
map_settings_btn->setVisible(!hideBottomIcons);
main_layout->setAlignment(map_settings_btn, (rightHandDM ? Qt::AlignLeft : Qt::AlignRight) | Qt::AlignBottom);
const bool flip_side = rightHandDM || compass;
const bool move_up = false;
const bool move_up_top = compass;
main_layout->setAlignment(map_settings_btn, (flip_side ? Qt::AlignLeft : Qt::AlignRight) | (move_up ? Qt::AlignCenter : move_up_top ? Qt::AlignTop : Qt::AlignBottom));
}
}

Expand Down Expand Up @@ -836,8 +842,7 @@ void AnnotatedCameraWidget::drawCompass(QPainter &p) {
const int y = rect().bottom() - 20 - 140;

// Enable Antialiasing
p.setRenderHint(QPainter::Antialiasing);
p.setRenderHint(QPainter::TextAntialiasing);
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);

// Configure the circles
p.setPen(QPen(Qt::white, 2));
Expand All @@ -858,14 +863,14 @@ void AnnotatedCameraWidget::drawCompass(QPainter &p) {
p.restore();

// Draw the cardinal directions
p.setFont(InterFont(25, QFont::Bold));
const auto drawDirection = [&](const QString &text, const int from, const int to, const int align) {
// Move the "E" and "W" directions a bit closer to the middle so they're more uniform
const int offset = (text == "E") ? -5 : ((text == "W") ? 5 : 0);
// Set the opacity based on whether the direction label is currently being pointed at
p.setOpacity((bearingDeg >= from && bearingDeg < to) ? 1.0 : 0.2);
p.drawText(QRect(x - inner_compass + offset, y - inner_compass, btn_size, btn_size), align, text);
};
p.setFont(InterFont(25, QFont::Bold));
drawDirection("N", 0, 68, Qt::AlignTop | Qt::AlignHCenter);
drawDirection("E", 23, 158, Qt::AlignRight | Qt::AlignVCenter);
drawDirection("S", 113, 248, Qt::AlignBottom | Qt::AlignHCenter);
Expand All @@ -889,12 +894,10 @@ void AnnotatedCameraWidget::drawCompass(QPainter &p) {
const auto drawCompassElements = [&](const int angle) {
const bool isCardinalDirection = angle % 90 == 0;
const int lineLength = isCardinalDirection ? 15 : 10;
const int lineWidth = isCardinalDirection ? 3 : 1;
bool isBold = abs(angle - static_cast<int>(bearingDeg)) <= 7;

// Set the current bearing degree value to bold
p.setFont(QFont("Inter", 8, isBold ? QFont::Bold : QFont::Normal));
p.setPen(QPen(Qt::white, lineWidth));

// Place the elements in their respective spots around their circles
p.save();
Expand All @@ -910,4 +913,6 @@ void AnnotatedCameraWidget::drawCompass(QPainter &p) {
for (int i = 0; i < 360; i += 15) {
drawCompassElements(i);
}

p.restore();
}

0 comments on commit 3a4fcb2

Please sign in to comment.