mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-30 02:52:04 +08:00
ui: combine OnroadHud into NvgWindow (#24369)
* ui: combine OnroadHUD and NVGWindow * draw hud first * cleanup * removed commented line * fix text rendering * increase cpu usage old-commit-hash: a3cfa444d37bacdac5278335ac7a49b6cb5b81f0
This commit is contained in:
@@ -26,7 +26,7 @@ PROCS = {
|
||||
"./camerad": 26.0,
|
||||
"./locationd": 9.1,
|
||||
"selfdrive.controls.plannerd": 11.7,
|
||||
"./_ui": 18.4,
|
||||
"./_ui": 21.0,
|
||||
"selfdrive.locationd.paramsd": 9.0,
|
||||
"./_sensord": 6.17,
|
||||
"selfdrive.controls.radard": 4.5,
|
||||
|
||||
+17
-25
@@ -18,18 +18,13 @@ OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) {
|
||||
stacked_layout->setStackingMode(QStackedLayout::StackAll);
|
||||
main_layout->addLayout(stacked_layout);
|
||||
|
||||
QStackedLayout *road_view_layout = new QStackedLayout;
|
||||
road_view_layout->setStackingMode(QStackedLayout::StackAll);
|
||||
nvg = new NvgWindow(VISION_STREAM_ROAD, this);
|
||||
road_view_layout->addWidget(nvg);
|
||||
hud = new OnroadHud(this);
|
||||
road_view_layout->addWidget(hud);
|
||||
|
||||
QWidget * split_wrapper = new QWidget;
|
||||
split = new QHBoxLayout(split_wrapper);
|
||||
split->setContentsMargins(0, 0, 0, 0);
|
||||
split->setSpacing(0);
|
||||
split->addLayout(road_view_layout);
|
||||
split->addWidget(nvg);
|
||||
|
||||
stacked_layout->addWidget(split_wrapper);
|
||||
|
||||
@@ -57,7 +52,7 @@ void OnroadWindow::updateState(const UIState &s) {
|
||||
alerts->updateAlert(alert, bgColor);
|
||||
}
|
||||
|
||||
hud->updateState(s);
|
||||
nvg->updateState(s);
|
||||
|
||||
if (bg != bgColor) {
|
||||
// repaint border
|
||||
@@ -167,15 +162,14 @@ void OnroadAlerts::paintEvent(QPaintEvent *event) {
|
||||
}
|
||||
}
|
||||
|
||||
// OnroadHud
|
||||
OnroadHud::OnroadHud(QWidget *parent) : QWidget(parent) {
|
||||
// NvgWindow
|
||||
|
||||
NvgWindow::NvgWindow(VisionStreamType type, QWidget* parent) : fps_filter(UI_FREQ, 3, 1. / UI_FREQ), CameraViewWidget("camerad", type, true, parent) {
|
||||
engage_img = loadPixmap("../assets/img_chffr_wheel.png", {img_size, img_size});
|
||||
dm_img = loadPixmap("../assets/img_driver_face.png", {img_size, img_size});
|
||||
|
||||
connect(this, &OnroadHud::valueChanged, [=] { update(); });
|
||||
}
|
||||
|
||||
void OnroadHud::updateState(const UIState &s) {
|
||||
void NvgWindow::updateState(const UIState &s) {
|
||||
const int SET_SPEED_NA = 255;
|
||||
const SubMaster &sm = *(s.sm);
|
||||
const auto cs = sm["controlsState"].getControlsState();
|
||||
@@ -202,9 +196,8 @@ void OnroadHud::updateState(const UIState &s) {
|
||||
}
|
||||
}
|
||||
|
||||
void OnroadHud::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
void NvgWindow::drawHud(QPainter &p) {
|
||||
p.save();
|
||||
|
||||
// Header gradient
|
||||
QLinearGradient bg(0, header_h - (header_h / 2.5), 0, header_h);
|
||||
@@ -246,9 +239,10 @@ void OnroadHud::paintEvent(QPaintEvent *event) {
|
||||
drawIcon(p, radius / 2 + (bdr_s * 2), rect().bottom() - footer_h / 2,
|
||||
dm_img, QColor(0, 0, 0, 70), dmActive ? 1.0 : 0.2);
|
||||
}
|
||||
p.restore();
|
||||
}
|
||||
|
||||
void OnroadHud::drawText(QPainter &p, int x, int y, const QString &text, int alpha) {
|
||||
void NvgWindow::drawText(QPainter &p, int x, int y, const QString &text, int alpha) {
|
||||
QFontMetrics fm(p.font());
|
||||
QRect init_rect = fm.boundingRect(text);
|
||||
QRect real_rect = fm.boundingRect(init_rect, 0, text);
|
||||
@@ -258,7 +252,7 @@ void OnroadHud::drawText(QPainter &p, int x, int y, const QString &text, int alp
|
||||
p.drawText(real_rect.x(), real_rect.bottom(), text);
|
||||
}
|
||||
|
||||
void OnroadHud::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity) {
|
||||
void NvgWindow::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity) {
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(bg);
|
||||
p.drawEllipse(x - radius / 2, y - radius / 2, radius, radius);
|
||||
@@ -266,11 +260,6 @@ void OnroadHud::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, flo
|
||||
p.drawPixmap(x - img_size / 2, y - img_size / 2, img);
|
||||
}
|
||||
|
||||
// NvgWindow
|
||||
|
||||
NvgWindow::NvgWindow(VisionStreamType type, QWidget* parent) : fps_filter(UI_FREQ, 3, 1. / UI_FREQ), CameraViewWidget("camerad", type, true, parent) {
|
||||
|
||||
}
|
||||
|
||||
void NvgWindow::initializeGL() {
|
||||
CameraViewWidget::initializeGL();
|
||||
@@ -377,11 +366,14 @@ void NvgWindow::drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV
|
||||
void NvgWindow::paintGL() {
|
||||
CameraViewWidget::paintGL();
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
drawHud(painter);
|
||||
|
||||
UIState *s = uiState();
|
||||
if (s->worldObjectsVisible()) {
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
drawLaneLines(painter, s);
|
||||
|
||||
|
||||
+27
-39
@@ -9,44 +9,6 @@
|
||||
|
||||
|
||||
// ***** onroad widgets *****
|
||||
|
||||
class OnroadHud : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString speed MEMBER speed NOTIFY valueChanged);
|
||||
Q_PROPERTY(QString speedUnit MEMBER speedUnit NOTIFY valueChanged);
|
||||
Q_PROPERTY(QString maxSpeed MEMBER maxSpeed NOTIFY valueChanged);
|
||||
Q_PROPERTY(bool is_cruise_set MEMBER is_cruise_set NOTIFY valueChanged);
|
||||
Q_PROPERTY(bool engageable MEMBER engageable NOTIFY valueChanged);
|
||||
Q_PROPERTY(bool dmActive MEMBER dmActive NOTIFY valueChanged);
|
||||
Q_PROPERTY(bool hideDM MEMBER hideDM NOTIFY valueChanged);
|
||||
Q_PROPERTY(int status MEMBER status NOTIFY valueChanged);
|
||||
|
||||
public:
|
||||
explicit OnroadHud(QWidget *parent);
|
||||
void updateState(const UIState &s);
|
||||
|
||||
private:
|
||||
void drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity);
|
||||
void drawText(QPainter &p, int x, int y, const QString &text, int alpha = 255);
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
QPixmap engage_img;
|
||||
QPixmap dm_img;
|
||||
const int radius = 192;
|
||||
const int img_size = (radius / 2) * 1.5;
|
||||
QString speed;
|
||||
QString speedUnit;
|
||||
QString maxSpeed;
|
||||
bool is_cruise_set = false;
|
||||
bool engageable = false;
|
||||
bool dmActive = false;
|
||||
bool hideDM = false;
|
||||
int status = STATUS_DISENGAGED;
|
||||
|
||||
signals:
|
||||
void valueChanged();
|
||||
};
|
||||
|
||||
class OnroadAlerts : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -65,9 +27,35 @@ private:
|
||||
// container window for the NVG UI
|
||||
class NvgWindow : public CameraViewWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString speed MEMBER speed);
|
||||
Q_PROPERTY(QString speedUnit MEMBER speedUnit);
|
||||
Q_PROPERTY(QString maxSpeed MEMBER maxSpeed);
|
||||
Q_PROPERTY(bool is_cruise_set MEMBER is_cruise_set);
|
||||
Q_PROPERTY(bool engageable MEMBER engageable);
|
||||
Q_PROPERTY(bool dmActive MEMBER dmActive);
|
||||
Q_PROPERTY(bool hideDM MEMBER hideDM);
|
||||
Q_PROPERTY(int status MEMBER status);
|
||||
|
||||
public:
|
||||
explicit NvgWindow(VisionStreamType type, QWidget* parent = 0);
|
||||
void updateState(const UIState &s);
|
||||
|
||||
private:
|
||||
void drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity);
|
||||
void drawText(QPainter &p, int x, int y, const QString &text, int alpha = 255);
|
||||
|
||||
QPixmap engage_img;
|
||||
QPixmap dm_img;
|
||||
const int radius = 192;
|
||||
const int img_size = (radius / 2) * 1.5;
|
||||
QString speed;
|
||||
QString speedUnit;
|
||||
QString maxSpeed;
|
||||
bool is_cruise_set = false;
|
||||
bool engageable = false;
|
||||
bool dmActive = false;
|
||||
bool hideDM = false;
|
||||
int status = STATUS_DISENGAGED;
|
||||
|
||||
protected:
|
||||
void paintGL() override;
|
||||
@@ -76,6 +64,7 @@ protected:
|
||||
void updateFrameMat(int w, int h) override;
|
||||
void drawLaneLines(QPainter &painter, const UIState *s);
|
||||
void drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV3::Reader &lead_data, const QPointF &vd);
|
||||
void drawHud(QPainter &p);
|
||||
inline QColor redColor(int alpha = 255) { return QColor(201, 34, 49, alpha); }
|
||||
inline QColor whiteColor(int alpha = 255) { return QColor(255, 255, 255, alpha); }
|
||||
|
||||
@@ -94,7 +83,6 @@ public:
|
||||
private:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void mousePressEvent(QMouseEvent* e) override;
|
||||
OnroadHud *hud;
|
||||
OnroadAlerts *alerts;
|
||||
NvgWindow *nvg;
|
||||
QColor bg = bg_colors[STATUS_DISENGAGED];
|
||||
|
||||
@@ -253,7 +253,6 @@ void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) {
|
||||
stream_width = vipc_client->buffers[0].width;
|
||||
stream_height = vipc_client->buffers[0].height;
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
Reference in New Issue
Block a user