This commit is contained in:
Your Name
2024-04-29 12:55:27 -05:00
parent 1f340a4996
commit f4145d48e6
2 changed files with 265 additions and 265 deletions

View File

@@ -89,7 +89,7 @@ void HomeWindow::offroadTransition(bool offroad) {
if (offroad) { if (offroad) {
sidebar->setVisible(false); sidebar->setVisible(false);
slayout->setCurrentWidget(ready); slayout->setCurrentWidget(ready);
this->showDriverView(true, true); // Temp // this->showDriverView(true, true); // Temp
} else { } else {
sidebar->setVisible(false); sidebar->setVisible(false);
slayout->setCurrentWidget(onroad); slayout->setCurrentWidget(onroad);

View File

@@ -119,76 +119,76 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) {
// FrogPilot clickable widgets // FrogPilot clickable widgets
bool widgetClicked = false; bool widgetClicked = false;
// Change cruise control increments button // // Change cruise control increments button
QRect maxSpeedRect(7, 25, 225, 225); // QRect maxSpeedRect(7, 25, 225, 225);
bool isMaxSpeedClicked = maxSpeedRect.contains(e->pos()) && scene.reverse_cruise_ui; // bool isMaxSpeedClicked = maxSpeedRect.contains(e->pos()) && scene.reverse_cruise_ui;
// Hide speed button // // Hide speed button
QRect hideSpeedRect(rect().center().x() - 175, 50, 350, 350); // QRect hideSpeedRect(rect().center().x() - 175, 50, 350, 350);
bool isSpeedClicked = hideSpeedRect.contains(e->pos()) && scene.hide_speed_ui; // bool isSpeedClicked = hideSpeedRect.contains(e->pos()) && scene.hide_speed_ui;
// Speed limit confirmation buttons // // Speed limit confirmation buttons
QSize size = this->size(); // QSize size = this->size();
QRect leftRect(0, 0, size.width() / 2, size.height()); // QRect leftRect(0, 0, size.width() / 2, size.height());
QRect rightRect = leftRect.translated(size.width() / 2, 0); // QRect rightRect = leftRect.translated(size.width() / 2, 0);
bool isLeftSideClicked = leftRect.contains(e->pos()) && scene.speed_limit_changed; // bool isLeftSideClicked = leftRect.contains(e->pos()) && scene.speed_limit_changed;
bool isRightSideClicked = rightRect.contains(e->pos()) && scene.speed_limit_changed; // bool isRightSideClicked = rightRect.contains(e->pos()) && scene.speed_limit_changed;
// Speed limit offset button // // Speed limit offset button
QRect speedLimitRect(7, 250, 225, 225); // QRect speedLimitRect(7, 250, 225, 225);
bool isSpeedLimitClicked = speedLimitRect.contains(e->pos()) && scene.show_slc_offset_ui; // bool isSpeedLimitClicked = speedLimitRect.contains(e->pos()) && scene.show_slc_offset_ui;
if (isMaxSpeedClicked || isSpeedClicked || isSpeedLimitClicked) { // if (isMaxSpeedClicked || isSpeedClicked || isSpeedLimitClicked) {
if (isMaxSpeedClicked) { // if (isMaxSpeedClicked) {
std::thread([this]() { // std::thread([this]() {
bool currentReverseCruise = scene.reverse_cruise; // bool currentReverseCruise = scene.reverse_cruise;
uiState()->scene.reverse_cruise = !currentReverseCruise; // uiState()->scene.reverse_cruise = !currentReverseCruise;
params.putBoolNonBlocking("ReverseCruise", !currentReverseCruise); // params.putBoolNonBlocking("ReverseCruise", !currentReverseCruise);
paramsMemory.putBool("FrogPilotTogglesUpdated", true); // paramsMemory.putBool("FrogPilotTogglesUpdated", true);
std::this_thread::sleep_for(std::chrono::seconds(1)); // std::this_thread::sleep_for(std::chrono::seconds(1));
paramsMemory.putBool("FrogPilotTogglesUpdated", false); // paramsMemory.putBool("FrogPilotTogglesUpdated", false);
}).detach(); // }).detach();
} else if (isSpeedClicked) { // } else if (isSpeedClicked) {
bool currentHideSpeed = scene.hide_speed; // bool currentHideSpeed = scene.hide_speed;
uiState()->scene.hide_speed = !currentHideSpeed; // uiState()->scene.hide_speed = !currentHideSpeed;
params.putBoolNonBlocking("HideSpeed", !currentHideSpeed); // params.putBoolNonBlocking("HideSpeed", !currentHideSpeed);
} else if (isSpeedLimitClicked) { // } else if (isSpeedLimitClicked) {
bool currentShowSLCOffset = scene.show_slc_offset; // bool currentShowSLCOffset = scene.show_slc_offset;
scene.show_slc_offset = !currentShowSLCOffset; // scene.show_slc_offset = !currentShowSLCOffset;
params.putBoolNonBlocking("ShowSLCOffset", !currentShowSLCOffset); // params.putBoolNonBlocking("ShowSLCOffset", !currentShowSLCOffset);
} // }
widgetClicked = true; // widgetClicked = true;
} else if (isLeftSideClicked || isRightSideClicked) { // } else if (isLeftSideClicked || isRightSideClicked) {
bool slcConfirmed = isLeftSideClicked && !scene.right_hand_drive || isRightSideClicked && scene.right_hand_drive; // bool slcConfirmed = isLeftSideClicked && !scene.right_hand_drive || isRightSideClicked && scene.right_hand_drive;
paramsMemory.putBoolNonBlocking("SLCConfirmed", slcConfirmed); // paramsMemory.putBoolNonBlocking("SLCConfirmed", slcConfirmed);
paramsMemory.putBoolNonBlocking("SLCConfirmedPressed", true); // paramsMemory.putBoolNonBlocking("SLCConfirmedPressed", true);
widgetClicked = true; // widgetClicked = true;
// If the click wasn't for anything specific, change the value of "ExperimentalMode" // // If the click wasn't for anything specific, change the value of "ExperimentalMode"
} else if (scene.experimental_mode_via_screen && e->pos() != timeoutPoint) { // } else if (scene.experimental_mode_via_screen && e->pos() != timeoutPoint) {
if (clickTimer.isActive()) { // if (clickTimer.isActive()) {
clickTimer.stop(); // clickTimer.stop();
if (scene.conditional_experimental) { // if (scene.conditional_experimental) {
int override_value = (scene.conditional_status >= 1 && scene.conditional_status <= 6) ? 0 : scene.conditional_status >= 7 ? 5 : 6; // int override_value = (scene.conditional_status >= 1 && scene.conditional_status <= 6) ? 0 : scene.conditional_status >= 7 ? 5 : 6;
paramsMemory.putIntNonBlocking("CEStatus", override_value); // paramsMemory.putIntNonBlocking("CEStatus", override_value);
} else { // } else {
bool experimentalMode = params.getBool("ExperimentalMode"); // bool experimentalMode = params.getBool("ExperimentalMode");
params.putBoolNonBlocking("ExperimentalMode", !experimentalMode); // params.putBoolNonBlocking("ExperimentalMode", !experimentalMode);
} // }
} else { // } else {
clickTimer.start(500); // clickTimer.start(500);
} // }
widgetClicked = true; // widgetClicked = true;
} // }
#ifdef ENABLE_MAPS #ifdef ENABLE_MAPS
if (map != nullptr && !widgetClicked) { if (map != nullptr && !widgetClicked) {
@@ -552,17 +552,17 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par
// Neokii screen recorder // Neokii screen recorder
recorder_btn = new ScreenRecorder(this); recorder_btn = new ScreenRecorder(this);
buttons_layout->addWidget(recorder_btn); // buttons_layout->addWidget(recorder_btn);
experimental_btn = new ExperimentalButton(this); experimental_btn = new ExperimentalButton(this);
buttons_layout->addWidget(experimental_btn); // buttons_layout->addWidget(experimental_btn);
QVBoxLayout *top_right_layout = new QVBoxLayout(); QVBoxLayout *top_right_layout = new QVBoxLayout();
top_right_layout->setSpacing(0); top_right_layout->setSpacing(0);
top_right_layout->addLayout(buttons_layout); top_right_layout->addLayout(buttons_layout);
pedal_icons = new PedalIcons(this); pedal_icons = new PedalIcons(this);
top_right_layout->addWidget(pedal_icons, 0, Qt::AlignRight); // top_right_layout->addWidget(pedal_icons, 0, Qt::AlignRight);
main_layout->addLayout(top_right_layout, 0); main_layout->addLayout(top_right_layout, 0);
main_layout->setAlignment(top_right_layout, Qt::AlignTop | Qt::AlignRight); main_layout->setAlignment(top_right_layout, Qt::AlignTop | Qt::AlignRight);
@@ -1017,44 +1017,44 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
} }
void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s) { void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s) {
painter.save(); // painter.save();
// base icon // // base icon
int offset = UI_BORDER_SIZE + btn_size / 2; // int offset = UI_BORDER_SIZE + btn_size / 2;
int x = rightHandDM ? width() - offset : offset; // int x = rightHandDM ? width() - offset : offset;
x += onroadDistanceButton ? 250 : 0; // x += onroadDistanceButton ? 250 : 0;
offset += showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar || roadNameUI ? 25 : 0; // offset += showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar || roadNameUI ? 25 : 0;
int y = height() - offset; // int y = height() - offset;
float opacity = dmActive ? 0.65 : 0.2; // float opacity = dmActive ? 0.65 : 0.2;
drawIcon(painter, QPoint(x, y), dm_img, blackColor(70), opacity); // drawIcon(painter, QPoint(x, y), dm_img, blackColor(70), opacity);
// face // // face
QPointF face_kpts_draw[std::size(default_face_kpts_3d)]; // QPointF face_kpts_draw[std::size(default_face_kpts_3d)];
float kp; // float kp;
for (int i = 0; i < std::size(default_face_kpts_3d); ++i) { // for (int i = 0; i < std::size(default_face_kpts_3d); ++i) {
kp = (scene.face_kpts_draw[i].v[2] - 8) / 120 + 1.0; // kp = (scene.face_kpts_draw[i].v[2] - 8) / 120 + 1.0;
face_kpts_draw[i] = QPointF(scene.face_kpts_draw[i].v[0] * kp + x, scene.face_kpts_draw[i].v[1] * kp + y); // face_kpts_draw[i] = QPointF(scene.face_kpts_draw[i].v[0] * kp + x, scene.face_kpts_draw[i].v[1] * kp + y);
} // }
painter.setPen(QPen(QColor::fromRgbF(1.0, 1.0, 1.0, opacity), 5.2, Qt::SolidLine, Qt::RoundCap)); // painter.setPen(QPen(QColor::fromRgbF(1.0, 1.0, 1.0, opacity), 5.2, Qt::SolidLine, Qt::RoundCap));
painter.drawPolyline(face_kpts_draw, std::size(default_face_kpts_3d)); // painter.drawPolyline(face_kpts_draw, std::size(default_face_kpts_3d));
// tracking arcs // // tracking arcs
const int arc_l = 133; // const int arc_l = 133;
const float arc_t_default = 6.7; // const float arc_t_default = 6.7;
const float arc_t_extend = 12.0; // const float arc_t_extend = 12.0;
QColor arc_color = QColor::fromRgbF(0.545 - 0.445 * s->engaged(), // QColor arc_color = QColor::fromRgbF(0.545 - 0.445 * s->engaged(),
0.545 + 0.4 * s->engaged(), // 0.545 + 0.4 * s->engaged(),
0.545 - 0.285 * s->engaged(), // 0.545 - 0.285 * s->engaged(),
0.4 * (1.0 - dm_fade_state)); // 0.4 * (1.0 - dm_fade_state));
float delta_x = -scene.driver_pose_sins[1] * arc_l / 2; // float delta_x = -scene.driver_pose_sins[1] * arc_l / 2;
float delta_y = -scene.driver_pose_sins[0] * arc_l / 2; // float delta_y = -scene.driver_pose_sins[0] * arc_l / 2;
painter.setPen(QPen(arc_color, arc_t_default+arc_t_extend*fmin(1.0, scene.driver_pose_diff[1] * 5.0), Qt::SolidLine, Qt::RoundCap)); // painter.setPen(QPen(arc_color, arc_t_default+arc_t_extend*fmin(1.0, scene.driver_pose_diff[1] * 5.0), Qt::SolidLine, Qt::RoundCap));
painter.drawArc(QRectF(std::fmin(x + delta_x, x), y - arc_l / 2, fabs(delta_x), arc_l), (scene.driver_pose_sins[1]>0 ? 90 : -90) * 16, 180 * 16); // painter.drawArc(QRectF(std::fmin(x + delta_x, x), y - arc_l / 2, fabs(delta_x), arc_l), (scene.driver_pose_sins[1]>0 ? 90 : -90) * 16, 180 * 16);
painter.setPen(QPen(arc_color, arc_t_default+arc_t_extend*fmin(1.0, scene.driver_pose_diff[0] * 5.0), Qt::SolidLine, Qt::RoundCap)); // painter.setPen(QPen(arc_color, arc_t_default+arc_t_extend*fmin(1.0, scene.driver_pose_diff[0] * 5.0), Qt::SolidLine, Qt::RoundCap));
painter.drawArc(QRectF(x - arc_l / 2, std::fmin(y + delta_y, y), arc_l, fabs(delta_y)), (scene.driver_pose_sins[0]>0 ? 0 : 180) * 16, 180 * 16); // painter.drawArc(QRectF(x - arc_l / 2, std::fmin(y + delta_y, y), arc_l, fabs(delta_y)), (scene.driver_pose_sins[0]>0 ? 0 : 180) * 16, 180 * 16);
painter.restore(); // painter.restore();
} }
void AnnotatedCameraWidget::drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV3::Reader &lead_data, const QPointF &vd, const float v_ego) { void AnnotatedCameraWidget::drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV3::Reader &lead_data, const QPointF &vd, const float v_ego) {
@@ -1230,13 +1230,13 @@ void AnnotatedCameraWidget::initializeFrogPilotWidgets() {
bottom_layout = new QHBoxLayout(); bottom_layout = new QHBoxLayout();
distance_btn = new DistanceButton(this); distance_btn = new DistanceButton(this);
bottom_layout->addWidget(distance_btn); // bottom_layout->addWidget(distance_btn);
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); // QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
bottom_layout->addItem(spacer); // bottom_layout->addItem(spacer);
compass_img = new Compass(this); compass_img = new Compass(this);
bottom_layout->addWidget(compass_img); // bottom_layout->addWidget(compass_img);
map_settings_btn_bottom = new MapSettingsButton(this); map_settings_btn_bottom = new MapSettingsButton(this);
bottom_layout->addWidget(map_settings_btn_bottom); bottom_layout->addWidget(map_settings_btn_bottom);
@@ -1297,13 +1297,13 @@ void AnnotatedCameraWidget::initializeFrogPilotWidgets() {
}); });
// Initialize the timer for the screen recorder // Initialize the timer for the screen recorder
QTimer *record_timer = new QTimer(this); // QTimer *record_timer = new QTimer(this);
connect(record_timer, &QTimer::timeout, this, [this]() { // connect(record_timer, &QTimer::timeout, this, [this]() {
if (recorder_btn) { // if (recorder_btn) {
recorder_btn->update_screen(); // recorder_btn->update_screen();
} // }
}); // });
record_timer->start(1000 / UI_FREQ); // record_timer->start(1000 / UI_FREQ);
} }
void AnnotatedCameraWidget::updateFrogPilotWidgets() { void AnnotatedCameraWidget::updateFrogPilotWidgets() {
@@ -1328,7 +1328,7 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets() {
customColors = scene.custom_colors; customColors = scene.custom_colors;
experimentalMode = scene.experimental_mode; // experimentalMode = scene.experimental_mode;
laneDetectionWidth = scene.lane_detection_width; laneDetectionWidth = scene.lane_detection_width;
laneWidthLeft = scene.lane_width_left; laneWidthLeft = scene.lane_width_left;
@@ -1399,14 +1399,14 @@ void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
drawStatusBar(p); drawStatusBar(p);
} }
if (customSignals != 0 && (turnSignalLeft || turnSignalRight) && !bigMapOpen) { // if (customSignals != 0 && (turnSignalLeft || turnSignalRight) && !bigMapOpen) {
if (!animationTimer->isActive()) { // if (!animationTimer->isActive()) {
animationTimer->start(totalFrames * 11); // 440 milliseconds per loop; syncs up perfectly with my 2019 Lexus ES 350 turn signal clicks // animationTimer->start(totalFrames * 11); // 440 milliseconds per loop; syncs up perfectly with my 2019 Lexus ES 350 turn signal clicks
} // }
drawTurnSignals(p); // drawTurnSignals(p);
} else if (animationTimer->isActive()) { // } else if (animationTimer->isActive()) {
animationTimer->stop(); // animationTimer->stop();
} // }
if (leadInfo && !bigMapOpen) { if (leadInfo && !bigMapOpen) {
drawLeadInfo(p); drawLeadInfo(p);
@@ -1417,24 +1417,24 @@ void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
} }
bool enableCompass = compass && !hideBottomIcons; bool enableCompass = compass && !hideBottomIcons;
compass_img->setVisible(enableCompass); // compass_img->setVisible(enableCompass);
if (enableCompass) { // if (enableCompass) {
compass_img->updateState(); // compass_img->updateState();
bottom_layout->setAlignment(compass_img, (rightHandDM ? Qt::AlignLeft : Qt::AlignRight)); // bottom_layout->setAlignment(compass_img, (rightHandDM ? Qt::AlignLeft : Qt::AlignRight));
} // }
bool enableDistanceButton = onroadDistanceButton && !hideBottomIcons; bool enableDistanceButton = onroadDistanceButton && !hideBottomIcons;
distance_btn->setVisible(enableDistanceButton); // distance_btn->setVisible(enableDistanceButton);
if (enableDistanceButton) { // if (enableDistanceButton) {
distance_btn->updateState(); // distance_btn->updateState();
bottom_layout->setAlignment(distance_btn, (rightHandDM ? Qt::AlignRight : Qt::AlignLeft)); // bottom_layout->setAlignment(distance_btn, (rightHandDM ? Qt::AlignRight : Qt::AlignLeft));
} // }
bool enablePedalIcons = scene.pedals_on_ui && !bigMapOpen; bool enablePedalIcons = scene.pedals_on_ui && !bigMapOpen;
pedal_icons->setVisible(enablePedalIcons); // pedal_icons->setVisible(enablePedalIcons);
if (enablePedalIcons) { // if (enablePedalIcons) {
pedal_icons->updateState(); // pedal_icons->updateState();
} // }
map_settings_btn_bottom->setEnabled(map_settings_btn->isEnabled()); map_settings_btn_bottom->setEnabled(map_settings_btn->isEnabled());
if (map_settings_btn_bottom->isEnabled()) { if (map_settings_btn_bottom->isEnabled()) {
@@ -1446,176 +1446,176 @@ void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) {
} }
Compass::Compass(QWidget *parent) : QWidget(parent), scene(uiState()->scene) { Compass::Compass(QWidget *parent) : QWidget(parent), scene(uiState()->scene) {
setFixedSize(btn_size * 1.5, btn_size * 1.5); // setFixedSize(btn_size * 1.5, btn_size * 1.5);
compassSize = btn_size; // compassSize = btn_size;
circleOffset = compassSize / 2; // circleOffset = compassSize / 2;
degreeLabelOffset = circleOffset + 25; // degreeLabelOffset = circleOffset + 25;
innerCompass = compassSize / 2; // innerCompass = compassSize / 2;
x = (btn_size * 1.5) / 2 + 20; // x = (btn_size * 1.5) / 2 + 20;
y = (btn_size * 1.5) / 2; // y = (btn_size * 1.5) / 2;
compassInnerImg = loadPixmap("../frogpilot/assets/other_images/compass_inner.png", QSize(compassSize / 1.75, compassSize / 1.75)); // compassInnerImg = loadPixmap("../frogpilot/assets/other_images/compass_inner.png", QSize(compassSize / 1.75, compassSize / 1.75));
staticElements = QPixmap(size()); // staticElements = QPixmap(size());
staticElements.fill(Qt::transparent); // staticElements.fill(Qt::transparent);
QPainter p(&staticElements); // QPainter p(&staticElements);
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); // p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
QPen whitePen(Qt::white, 2); // QPen whitePen(Qt::white, 2);
p.setPen(whitePen); // p.setPen(whitePen);
p.setOpacity(1.0); // p.setOpacity(1.0);
p.setBrush(QColor(0, 0, 0, 100)); // p.setBrush(QColor(0, 0, 0, 100));
p.drawEllipse(x - circleOffset, y - circleOffset, circleOffset * 2, circleOffset * 2); // p.drawEllipse(x - circleOffset, y - circleOffset, circleOffset * 2, circleOffset * 2);
p.setBrush(Qt::NoBrush); // p.setBrush(Qt::NoBrush);
p.drawEllipse(x - (innerCompass + 5), y - (innerCompass + 5), (innerCompass + 5) * 2, (innerCompass + 5) * 2); // p.drawEllipse(x - (innerCompass + 5), y - (innerCompass + 5), (innerCompass + 5) * 2, (innerCompass + 5) * 2);
p.drawEllipse(x - degreeLabelOffset, y - degreeLabelOffset, degreeLabelOffset * 2, degreeLabelOffset * 2); // p.drawEllipse(x - degreeLabelOffset, y - degreeLabelOffset, degreeLabelOffset * 2, degreeLabelOffset * 2);
QPainterPath outerCircle, innerCircle; // QPainterPath outerCircle, innerCircle;
outerCircle.addEllipse(x - degreeLabelOffset, y - degreeLabelOffset, degreeLabelOffset * 2, degreeLabelOffset * 2); // outerCircle.addEllipse(x - degreeLabelOffset, y - degreeLabelOffset, degreeLabelOffset * 2, degreeLabelOffset * 2);
innerCircle.addEllipse(x - circleOffset, y - circleOffset, compassSize, compassSize); // innerCircle.addEllipse(x - circleOffset, y - circleOffset, compassSize, compassSize);
p.fillPath(outerCircle.subtracted(innerCircle), Qt::black); // p.fillPath(outerCircle.subtracted(innerCircle), Qt::black);
} }
void Compass::updateState() { void Compass::updateState() {
if (bearingDeg != scene.bearing_deg) { // if (bearingDeg != scene.bearing_deg) {
update(); // update();
bearingDeg = scene.bearing_deg; // bearingDeg = scene.bearing_deg;
} // }
} }
void Compass::paintEvent(QPaintEvent *event) { void Compass::paintEvent(QPaintEvent *event) {
QPainter p(this); // QPainter p(this);
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); // p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
bearingDeg = fmod(bearingDeg, 360); // bearingDeg = fmod(bearingDeg, 360);
if (bearingDeg < 0) { // if (bearingDeg < 0) {
bearingDeg += 360; // bearingDeg += 360;
} // }
p.drawPixmap(0, 0, staticElements); // p.drawPixmap(0, 0, staticElements);
p.translate(x, y); // p.translate(x, y);
p.rotate(bearingDeg); // p.rotate(bearingDeg);
p.drawPixmap(-compassInnerImg.width() / 2, -compassInnerImg.height() / 2, compassInnerImg); // p.drawPixmap(-compassInnerImg.width() / 2, -compassInnerImg.height() / 2, compassInnerImg);
p.rotate(-bearingDeg); // p.rotate(-bearingDeg);
p.translate(-x, -y); // p.translate(-x, -y);
QFont font = InterFont(10, QFont::Normal); // QFont font = InterFont(10, QFont::Normal);
for (int i = 0; i < 360; i += 15) { // for (int i = 0; i < 360; i += 15) {
bool isBold = abs(i - bearingDeg) <= 7; // bool isBold = abs(i - bearingDeg) <= 7;
font.setWeight(isBold ? QFont::Bold : QFont::Normal); // font.setWeight(isBold ? QFont::Bold : QFont::Normal);
p.setFont(font); // p.setFont(font);
p.setPen(QPen(Qt::white, i % 90 == 0 ? 2 : 1)); // p.setPen(QPen(Qt::white, i % 90 == 0 ? 2 : 1));
p.save(); // p.save();
p.translate(x, y); // p.translate(x, y);
p.rotate(i); // p.rotate(i);
p.drawLine(0, -(compassSize / 2 - (i % 90 == 0 ? 12 : 8)), 0, -(compassSize / 2)); // p.drawLine(0, -(compassSize / 2 - (i % 90 == 0 ? 12 : 8)), 0, -(compassSize / 2));
p.translate(0, -(compassSize / 2 + 12)); // p.translate(0, -(compassSize / 2 + 12));
p.rotate(-i); // p.rotate(-i);
p.drawText(QRect(-20, -10, 40, 20), Qt::AlignCenter, QString::number(i)); // p.drawText(QRect(-20, -10, 40, 20), Qt::AlignCenter, QString::number(i));
p.restore(); // p.restore();
} // }
p.setFont(InterFont(20, QFont::Bold)); // p.setFont(InterFont(20, QFont::Bold));
std::map<QString, std::tuple<QPair<float, float>, int, QColor>> directionInfo = { // std::map<QString, std::tuple<QPair<float, float>, int, QColor>> directionInfo = {
{"N", {{292.5, 67.5}, Qt::AlignTop | Qt::AlignHCenter, Qt::white}}, // {"N", {{292.5, 67.5}, Qt::AlignTop | Qt::AlignHCenter, Qt::white}},
{"E", {{22.5, 157.5}, Qt::AlignRight | Qt::AlignVCenter, Qt::white}}, // {"E", {{22.5, 157.5}, Qt::AlignRight | Qt::AlignVCenter, Qt::white}},
{"S", {{112.5, 247.5}, Qt::AlignBottom | Qt::AlignHCenter, Qt::white}}, // {"S", {{112.5, 247.5}, Qt::AlignBottom | Qt::AlignHCenter, Qt::white}},
{"W", {{202.5, 337.5}, Qt::AlignLeft | Qt::AlignVCenter, Qt::white}} // {"W", {{202.5, 337.5}, Qt::AlignLeft | Qt::AlignVCenter, Qt::white}}
}; // };
int directionOffset = 20; // int directionOffset = 20;
for (auto &item : directionInfo) { // for (auto &item : directionInfo) {
QString direction = item.first; // QString direction = item.first;
auto &[range, alignmentFlag, color] = item.second; // auto &[range, alignmentFlag, color] = item.second;
auto &[minRange, maxRange] = range; // auto &[minRange, maxRange] = range;
QRect textRect(x - innerCompass + directionOffset, y - innerCompass + directionOffset, innerCompass * 2 - 2 * directionOffset, innerCompass * 2 - 2 * directionOffset); // QRect textRect(x - innerCompass + directionOffset, y - innerCompass + directionOffset, innerCompass * 2 - 2 * directionOffset, innerCompass * 2 - 2 * directionOffset);
bool isInRange = false; // bool isInRange = false;
if (minRange > maxRange) { // if (minRange > maxRange) {
isInRange = bearingDeg >= minRange || bearingDeg <= maxRange; // isInRange = bearingDeg >= minRange || bearingDeg <= maxRange;
} else { // } else {
isInRange = bearingDeg >= minRange && bearingDeg <= maxRange; // isInRange = bearingDeg >= minRange && bearingDeg <= maxRange;
} // }
p.setOpacity(isInRange ? 1.0 : 0.2); // p.setOpacity(isInRange ? 1.0 : 0.2);
p.setPen(QPen(color)); // p.setPen(QPen(color));
p.drawText(textRect, alignmentFlag, direction); // p.drawText(textRect, alignmentFlag, direction);
} // }
} }
DistanceButton::DistanceButton(QWidget *parent) : QPushButton(parent), scene(uiState()->scene) { DistanceButton::DistanceButton(QWidget *parent) : QPushButton(parent), scene(uiState()->scene) {
setFixedSize(btn_size * 1.5, btn_size * 1.5); // setFixedSize(btn_size * 1.5, btn_size * 1.5);
profile_data = { // profile_data = {
{QPixmap("../frogpilot/assets/other_images/traffic.png"), "Traffic"}, // {QPixmap("../frogpilot/assets/other_images/traffic.png"), "Traffic"},
{QPixmap("../frogpilot/assets/other_images/aggressive.png"), "Aggressive"}, // {QPixmap("../frogpilot/assets/other_images/aggressive.png"), "Aggressive"},
{QPixmap("../frogpilot/assets/other_images/standard.png"), "Standard"}, // {QPixmap("../frogpilot/assets/other_images/standard.png"), "Standard"},
{QPixmap("../frogpilot/assets/other_images/relaxed.png"), "Relaxed"} // {QPixmap("../frogpilot/assets/other_images/relaxed.png"), "Relaxed"}
}; // };
profile_data_kaofui = { // profile_data_kaofui = {
{QPixmap("../frogpilot/assets/other_images/traffic_kaofui.png"), "Traffic"}, // {QPixmap("../frogpilot/assets/other_images/traffic_kaofui.png"), "Traffic"},
{QPixmap("../frogpilot/assets/other_images/aggressive_kaofui.png"), "Aggressive"}, // {QPixmap("../frogpilot/assets/other_images/aggressive_kaofui.png"), "Aggressive"},
{QPixmap("../frogpilot/assets/other_images/standard_kaofui.png"), "Standard"}, // {QPixmap("../frogpilot/assets/other_images/standard_kaofui.png"), "Standard"},
{QPixmap("../frogpilot/assets/other_images/relaxed_kaofui.png"), "Relaxed"} // {QPixmap("../frogpilot/assets/other_images/relaxed_kaofui.png"), "Relaxed"}
}; // };
transitionTimer.start(); // transitionTimer.start();
connect(this, &QPushButton::pressed, this, &DistanceButton::buttonPressed); // connect(this, &QPushButton::pressed, this, &DistanceButton::buttonPressed);
connect(this, &QPushButton::released, this, &DistanceButton::buttonReleased); // connect(this, &QPushButton::released, this, &DistanceButton::buttonReleased);
} }
void DistanceButton::buttonPressed() { void DistanceButton::buttonPressed() {
paramsMemory.putBool("OnroadDistanceButtonPressed", true); // paramsMemory.putBool("OnroadDistanceButtonPressed", true);
} }
void DistanceButton::buttonReleased() { void DistanceButton::buttonReleased() {
paramsMemory.putBool("OnroadDistanceButtonPressed", false); // paramsMemory.putBool("OnroadDistanceButtonPressed", false);
} }
void DistanceButton::updateState() { void DistanceButton::updateState() {
if (trafficModeActive != scene.traffic_mode_active || personality != static_cast<int>(scene.personality) && !trafficModeActive) { // if (trafficModeActive != scene.traffic_mode_active || personality != static_cast<int>(scene.personality) && !trafficModeActive) {
transitionTimer.restart(); // transitionTimer.restart();
} // }
personality = static_cast<int>(scene.personality); // personality = static_cast<int>(scene.personality);
trafficModeActive = scene.traffic_mode_active; // trafficModeActive = scene.traffic_mode_active;
} }
void DistanceButton::paintEvent(QPaintEvent *event) { void DistanceButton::paintEvent(QPaintEvent *event) {
QPainter p(this); // QPainter p(this);
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); // p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
constexpr qreal fadeDuration = 1000.0; // constexpr qreal fadeDuration = 1000.0;
constexpr qreal textDuration = 3000.0; // constexpr qreal textDuration = 3000.0;
int elapsed = transitionTimer.elapsed(); // int elapsed = transitionTimer.elapsed();
qreal textOpacity = qBound(0.0, 1.0 - ((elapsed - textDuration) / fadeDuration), 1.0); // qreal textOpacity = qBound(0.0, 1.0 - ((elapsed - textDuration) / fadeDuration), 1.0);
qreal imageOpacity = qBound(0.0, (elapsed - textDuration) / fadeDuration, 1.0); // qreal imageOpacity = qBound(0.0, (elapsed - textDuration) / fadeDuration, 1.0);
int profile = trafficModeActive ? 0 : personality + 1; // int profile = trafficModeActive ? 0 : personality + 1;
auto &[profileImage, profileText] = scene.use_kaofui_icons ? profile_data_kaofui[profile] : profile_data[profile]; // auto &[profileImage, profileText] = scene.use_kaofui_icons ? profile_data_kaofui[profile] : profile_data[profile];
if (textOpacity != 0.0) { // if (textOpacity != 0.0) {
p.setOpacity(textOpacity); // p.setOpacity(textOpacity);
p.setFont(InterFont(40, QFont::Bold)); // p.setFont(InterFont(40, QFont::Bold));
p.setPen(Qt::white); // p.setPen(Qt::white);
QRect textRect(-25, 0, width(), height() + 95); // QRect textRect(-25, 0, width(), height() + 95);
p.drawText(textRect, Qt::AlignCenter, profileText); // p.drawText(textRect, Qt::AlignCenter, profileText);
} // }
if (imageOpacity != 0.0) { // if (imageOpacity != 0.0) {
drawIcon(p, QPoint((btn_size / 2) * 1.25, btn_size / 2 + 95), profileImage, Qt::transparent, imageOpacity); // drawIcon(p, QPoint((btn_size / 2) * 1.25, btn_size / 2 + 95), profileImage, Qt::transparent, imageOpacity);
} // }
} }
void AnnotatedCameraWidget::drawLeadInfo(QPainter &p) { void AnnotatedCameraWidget::drawLeadInfo(QPainter &p) {
@@ -1740,34 +1740,34 @@ PedalIcons::PedalIcons(QWidget *parent) : QWidget(parent), scene(uiState()->scen
} }
void PedalIcons::updateState() { void PedalIcons::updateState() {
acceleration = scene.acceleration; // acceleration = scene.acceleration;
accelerating = acceleration > 0.25; // accelerating = acceleration > 0.25;
decelerating = acceleration < -0.25; // decelerating = acceleration < -0.25;
if (accelerating || decelerating) { // if (accelerating || decelerating) {
update(); // update();
} // }
} }
void PedalIcons::paintEvent(QPaintEvent *event) { void PedalIcons::paintEvent(QPaintEvent *event) {
QPainter p(this); // QPainter p(this);
p.setRenderHint(QPainter::Antialiasing); // p.setRenderHint(QPainter::Antialiasing);
int totalWidth = 2 * img_size; // int totalWidth = 2 * img_size;
int startX = (width() - totalWidth) / 2; // int startX = (width() - totalWidth) / 2;
int brakeX = startX + img_size / 2; // int brakeX = startX + img_size / 2;
int gasX = startX + img_size; // int gasX = startX + img_size;
float brakeOpacity = scene.standstill ? 1.0f : decelerating ? std::max(0.25f, std::abs(acceleration)) : 0.25f; // float brakeOpacity = scene.standstill ? 1.0f : decelerating ? std::max(0.25f, std::abs(acceleration)) : 0.25f;
float gasOpacity = accelerating ? std::max(0.25f, acceleration) : 0.25f; // float gasOpacity = accelerating ? std::max(0.25f, acceleration) : 0.25f;
p.setOpacity(brakeOpacity); // p.setOpacity(brakeOpacity);
p.drawPixmap(brakeX, (height() - img_size) / 2, brake_pedal_img); // p.drawPixmap(brakeX, (height() - img_size) / 2, brake_pedal_img);
p.setOpacity(gasOpacity); // p.setOpacity(gasOpacity);
p.drawPixmap(gasX, (height() - img_size) / 2, gas_pedal_img); // p.drawPixmap(gasX, (height() - img_size) / 2, gas_pedal_img);
} }
void AnnotatedCameraWidget::drawSLCConfirmation(QPainter &p) { void AnnotatedCameraWidget::drawSLCConfirmation(QPainter &p) {