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) {
sidebar->setVisible(false);
slayout->setCurrentWidget(ready);
this->showDriverView(true, true); // Temp
// this->showDriverView(true, true); // Temp
} else {
sidebar->setVisible(false);
slayout->setCurrentWidget(onroad);

View File

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