mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-05 13:32:05 +08:00
ui/onroad: move duplicated code to drawIcon() (#29149)
* move duplicate code to function drawIcon * fix center point old-commit-hash: cef693f3097bf9c7a34e6d61afcac341814ab341
This commit is contained in:
+14
-31
@@ -12,6 +12,17 @@
|
||||
#include "selfdrive/ui/qt/maps/map_panel.h"
|
||||
#endif
|
||||
|
||||
static void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrush &bg, float opacity) {
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setOpacity(1.0); // bg dictates opacity of ellipse
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(bg);
|
||||
p.drawEllipse(center, btn_size / 2, btn_size / 2);
|
||||
p.setOpacity(opacity);
|
||||
p.drawPixmap(center - QPoint(img.width() / 2, img.height() / 2), img);
|
||||
p.setOpacity(1.0);
|
||||
}
|
||||
|
||||
OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout->setMargin(UI_BORDER_SIZE);
|
||||
@@ -213,17 +224,8 @@ void ExperimentalButton::updateState(const UIState &s) {
|
||||
|
||||
void ExperimentalButton::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QPoint center(btn_size / 2, btn_size / 2);
|
||||
QPixmap img = experimental_mode ? experimental_img : engage_img;
|
||||
|
||||
p.setOpacity(1.0);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(QColor(0, 0, 0, 166));
|
||||
p.drawEllipse(center, btn_size / 2, btn_size / 2);
|
||||
p.setOpacity((isDown() || !engageable) ? 0.6 : 1.0);
|
||||
p.drawPixmap((btn_size - img_size) / 2, (btn_size - img_size) / 2, img);
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -239,16 +241,7 @@ MapSettingsButton::MapSettingsButton(QWidget *parent) : QPushButton(parent) {
|
||||
|
||||
void MapSettingsButton::paintEvent(QPaintEvent *event) {
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QPoint center(btn_size / 2, btn_size / 2);
|
||||
|
||||
p.setOpacity(1.0);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(QColor(0, 0, 0, 166));
|
||||
p.drawEllipse(center, btn_size / 2, btn_size / 2);
|
||||
p.setOpacity(isDown() ? 0.6 : 1.0);
|
||||
p.drawPixmap((btn_size - img_size) / 2, (btn_size - img_size) / 2, settings_img);
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), settings_img, QColor(0, 0, 0, 166), isDown() ? 0.6 : 1.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -436,16 +429,6 @@ void AnnotatedCameraWidget::drawText(QPainter &p, int x, int y, const QString &t
|
||||
p.drawText(real_rect.x(), real_rect.bottom(), text);
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidget::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity) {
|
||||
p.setOpacity(1.0); // bg dictates opacity of ellipse
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(bg);
|
||||
p.drawEllipse(x - btn_size / 2, y - btn_size / 2, btn_size, btn_size);
|
||||
p.setOpacity(opacity);
|
||||
p.drawPixmap(x - img.size().width() / 2, y - img.size().height() / 2, img);
|
||||
p.setOpacity(1.0);
|
||||
}
|
||||
|
||||
void AnnotatedCameraWidget::initializeGL() {
|
||||
CameraWidget::initializeGL();
|
||||
qInfo() << "OpenGL version:" << QString((const char*)glGetString(GL_VERSION));
|
||||
@@ -544,7 +527,7 @@ void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s)
|
||||
int x = rightHandDM ? width() - offset : offset;
|
||||
int y = height() - offset;
|
||||
float opacity = dmActive ? 0.65 : 0.2;
|
||||
drawIcon(painter, x, y, dm_img, blackColor(70), opacity);
|
||||
drawIcon(painter, QPoint(x, y), dm_img, blackColor(70), opacity);
|
||||
|
||||
// face
|
||||
QPointF face_kpts_draw[std::size(default_face_kpts_3d)];
|
||||
|
||||
@@ -84,7 +84,6 @@ public:
|
||||
MapSettingsButton *map_settings_btn;
|
||||
|
||||
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);
|
||||
|
||||
QVBoxLayout *main_layout;
|
||||
|
||||
Reference in New Issue
Block a user