nav: flip instruction images for RHD (#22877)

* nav instruction icon for rhd

* we dont need rhd for active direction

* define suffix as constant

* ps version icon

* reflect icon instead

Co-authored-by: Willem Melching <willem.melching@gmail.com>
pull/22966/head
eFini 3 years ago committed by GitHub
parent 4960578bdf
commit 52c4ab73a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      selfdrive/ui/qt/maps/map.cc
  2. 1
      selfdrive/ui/qt/maps/map.h

@ -4,6 +4,7 @@
#include <QDebug> #include <QDebug>
#include <QPainterPath> #include <QPainterPath>
#include <QFileInfo>
#include "selfdrive/common/swaglog.h" #include "selfdrive/common/swaglog.h"
#include "selfdrive/ui/ui.h" #include "selfdrive/ui/ui.h"
@ -21,6 +22,8 @@ const float MAX_PITCH = 50;
const float MIN_PITCH = 0; const float MIN_PITCH = 0;
const float MAP_SCALE = 2; const float MAP_SCALE = 2;
const QString ICON_SUFFIX = ".png";
MapWindow::MapWindow(const QMapboxGLSettings &settings) : MapWindow::MapWindow(const QMapboxGLSettings &settings) :
m_settings(settings), velocity_filter(0, 10, 0.05) { m_settings(settings), velocity_filter(0, 10, 0.05) {
sm = new SubMaster({"liveLocationKalman", "navInstruction", "navRoute"}); sm = new SubMaster({"liveLocationKalman", "navInstruction", "navRoute"});
@ -324,6 +327,7 @@ void MapWindow::offroadTransition(bool offroad) {
} }
MapInstructions::MapInstructions(QWidget * parent) : QWidget(parent) { MapInstructions::MapInstructions(QWidget * parent) : QWidget(parent) {
is_rhd = Params().getBool("IsRHD");
QHBoxLayout *main_layout = new QHBoxLayout(this); QHBoxLayout *main_layout = new QHBoxLayout(this);
main_layout->setContentsMargins(11, 50, 11, 11); main_layout->setContentsMargins(11, 50, 11, 11);
{ {
@ -442,10 +446,22 @@ void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruct
if (!modifier.isEmpty()) { if (!modifier.isEmpty()) {
fn += "_" + modifier; fn += "_" + modifier;
} }
fn += + ".png"; fn += ICON_SUFFIX;
fn = fn.replace(' ', '_'); fn = fn.replace(' ', '_');
// for rhd, reflect direction and then flip
if (is_rhd) {
if (fn.contains("left")) {
fn.replace(QString("left"), QString("right"));
} else if (fn.contains("right")) {
fn.replace(QString("right"), QString("left"));
}
}
QPixmap pix(fn); QPixmap pix(fn);
if (is_rhd) {
pix = pix.transformed(QTransform().scale(-1, 1));
}
icon_01->setPixmap(pix.scaledToWidth(200, Qt::SmoothTransformation)); icon_01->setPixmap(pix.scaledToWidth(200, Qt::SmoothTransformation));
icon_01->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); icon_01->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
icon_01->setVisible(true); icon_01->setVisible(true);
@ -476,7 +492,7 @@ void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruct
fn += "turn_straight"; fn += "turn_straight";
} }
QPixmap pix(fn + ".png"); QPixmap pix(fn + ICON_SUFFIX);
auto icon = new QLabel; auto icon = new QLabel;
int wh = active ? 125 : 75; int wh = active ? 125 : 75;
icon->setPixmap(pix.scaled(wh, wh, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); icon->setPixmap(pix.scaled(wh, wh, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

@ -36,6 +36,7 @@ private:
QWidget *lane_widget; QWidget *lane_widget;
QHBoxLayout *lane_layout; QHBoxLayout *lane_layout;
bool error = false; bool error = false;
bool is_rhd = false;
public: public:
MapInstructions(QWidget * parent=nullptr); MapInstructions(QWidget * parent=nullptr);

Loading…
Cancel
Save