mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-05 05:22:07 +08:00
Rotate the steering wheel icon
This commit is contained in:
@@ -4,14 +4,18 @@
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrush &bg, float opacity) {
|
||||
void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrush &bg, float opacity, const int &angle) {
|
||||
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.save();
|
||||
p.translate(center);
|
||||
p.rotate(angle);
|
||||
p.setOpacity(opacity);
|
||||
p.drawPixmap(center - QPoint(img.width() / 2, img.height() / 2), img);
|
||||
p.drawPixmap(-QPoint(img.width() / 2, img.height() / 2), img);
|
||||
p.restore();
|
||||
p.setOpacity(1.0);
|
||||
}
|
||||
|
||||
@@ -55,6 +59,14 @@ void ExperimentalButton::updateState(const UIState &s, const FrogPilotUIState &f
|
||||
|
||||
updateBackgroundColor();
|
||||
|
||||
int current_steering_angle_deg = -carState.getSteeringAngleDeg();
|
||||
if (current_steering_angle_deg != steering_angle_deg && frogpilot_toggles.value("rotating_wheel").toBool()) {
|
||||
steering_angle_deg = current_steering_angle_deg;
|
||||
update();
|
||||
} else if (!frogpilot_toggles.value("rotating_wheel").toBool()) {
|
||||
steering_angle_deg = 0;
|
||||
}
|
||||
|
||||
if (params_memory.getBool("UpdateWheelImage")) {
|
||||
updateTheme();
|
||||
params_memory.remove("UpdateWheelImage");
|
||||
@@ -68,11 +80,11 @@ void ExperimentalButton::paintEvent(QPaintEvent *event) {
|
||||
|
||||
if (frogpilot_toggles.value("wheel_image").toString() == "stock") {
|
||||
QPixmap img = experimental_mode ? experimental_img : engage_img;
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, background_color, (isDown() || !engageable) ? 0.6 : 1.0);
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, background_color, (isDown() || !engageable) ? 0.6 : 1.0, steering_angle_deg);
|
||||
} else if (wheel_gif) {
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), wheel_gif->currentPixmap(), background_color, (isDown() || !engageable) ? 0.6 : 1.0);
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), wheel_gif->currentPixmap(), background_color, (isDown() || !engageable) ? 0.6 : 1.0, steering_angle_deg);
|
||||
} else if (!wheel_img.isNull()) {
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), wheel_img, background_color, (isDown() || !engageable) ? 0.6 : 1.0);
|
||||
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), wheel_img, background_color, (isDown() || !engageable) ? 0.6 : 1.0, steering_angle_deg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ private:
|
||||
void updateBackgroundColor();
|
||||
void updateTheme();
|
||||
|
||||
int steering_angle_deg;
|
||||
|
||||
Params params_memory{"", true};
|
||||
|
||||
QColor background_color;
|
||||
@@ -43,4 +45,4 @@ private:
|
||||
QSharedPointer<QMovie> wheel_gif;
|
||||
};
|
||||
|
||||
void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrush &bg, float opacity);
|
||||
void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrush &bg, float opacity, const int &angle = 0);
|
||||
|
||||
Reference in New Issue
Block a user