This commit is contained in:
Your Name
2024-05-03 09:03:38 -05:00
parent f70ca7178d
commit 83155a30b9
2 changed files with 35 additions and 72 deletions

View File

@@ -46,6 +46,7 @@ static void drawIconGif(QPainter &p, const QPoint &center, const QMovie &img, co
} }
OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent), scene(uiState()->scene) { OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent), scene(uiState()->scene) {
bg = QLinearGradient(0, height(), 0, 0); // Initialize bg to a default color
QVBoxLayout *main_layout = new QVBoxLayout(this); QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setMargin(UI_BORDER_SIZE); main_layout->setMargin(UI_BORDER_SIZE);
QStackedLayout *stacked_layout = new QStackedLayout; QStackedLayout *stacked_layout = new QStackedLayout;
@@ -824,44 +825,25 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
painter.save(); painter.save();
// CLEARPILOT: color channel code rewriten to allow custom colors // CLEARPILOT: color channel code rewriten to allow custom colors
// Center lane color
// This should be moved to ui.h
int base_red = 150;
int base_green = 150;
int base_blue = 150;
float path_alpha = 0.30; // 60% opacity
float other_alpha = 0.75; // 60% opacity
QColor center_lane_color(base_red, base_green, base_blue);
SubMaster &sm = *(s->sm); SubMaster &sm = *(s->sm);
// lanelines // lanelines
for (int i = 0; i < std::size(scene.lane_line_vertices); ++i) { for (int i = 0; i < std::size(scene.lane_line_vertices); ++i) {
// if (currentHolidayTheme != 0) {
// painter.setBrush(std::get<2>(holidayThemeConfiguration[currentHolidayTheme]).begin()->second);
// } else if (customColors != 0) {
// painter.setBrush(std::get<2>(themeConfiguration[customColors]).begin()->second);
// } else {
painter.setBrush(QColor::fromRgbF(1.0, 1.0, 1.0, std::clamp<float>(scene.lane_line_probs[i], 0.0, 0.7))); painter.setBrush(QColor::fromRgbF(1.0, 1.0, 1.0, std::clamp<float>(scene.lane_line_probs[i], 0.0, 0.7)));
// }
painter.drawPolygon(scene.lane_line_vertices[i]); painter.drawPolygon(scene.lane_line_vertices[i]);
} }
// road edges // road edges
for (int i = 0; i < std::size(scene.road_edge_vertices); ++i) { for (int i = 0; i < std::size(scene.road_edge_vertices); ++i) {
// if (currentHolidayTheme != 0) {
// painter.setBrush(std::get<2>(holidayThemeConfiguration[currentHolidayTheme]).begin()->second);
// } else if (customColors != 0) {
// painter.setBrush(std::get<2>(themeConfiguration[customColors]).begin()->second);
// } else {
painter.setBrush(QColor::fromRgbF(1.0, 0, 0, std::clamp<float>(1.0 - scene.road_edge_stds[i], 0.0, 1.0))); painter.setBrush(QColor::fromRgbF(1.0, 0, 0, std::clamp<float>(1.0 - scene.road_edge_stds[i], 0.0, 1.0)));
// }
painter.drawPolygon(scene.road_edge_vertices[i]); painter.drawPolygon(scene.road_edge_vertices[i]);
} }
// paint path // paint center lane path
QLinearGradient bg(0, height(), 0, 0); QColor center_lane_color = bg_colors[CENTER_LANE_COLOR];
QLinearGradient path_gradient(0, height(), 0, 0);
if (experimentalMode || scene.acceleration_path) { if (experimentalMode || scene.acceleration_path) {
// The first half of track_vertices are the points for the right side of the path // The first half of track_vertices are the points for the right side of the path
// and the indices match the positions of accel from uiPlan // and the indices match the positions of accel from uiPlan
@@ -876,6 +858,7 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
try { try {
for (int i = 0; i < max_len; ++i) { for (int i = 0; i < max_len; ++i) {
// Rewrote to generate color based off of bg_colors[CENTER_LANE_COLOR] constant
if (scene.track_vertices[i].y() < 0 || scene.track_vertices[i].y() > height()) continue; if (scene.track_vertices[i].y() < 0 || scene.track_vertices[i].y() > height()) continue;
float lin_grad_point = (height() - scene.track_vertices[i].y()) / height(); float lin_grad_point = (height() - scene.track_vertices[i].y()) / height();
@@ -888,63 +871,45 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
float adjusted_lightness = util::map_val(adjusted_saturation, 0.f, 1.f, static_cast<float>(_l), 0.95f); // Using base lightness as a starting point float adjusted_lightness = util::map_val(adjusted_saturation, 0.f, 1.f, static_cast<float>(_l), 0.95f); // Using base lightness as a starting point
// Calculate dynamic alpha based on lin_grad_point // Calculate dynamic alpha based on lin_grad_point
float dynamic_alpha = util::map_val(lin_grad_point, 0.75f / 2.f, 0.75f, path_alpha, 0.f); float dynamic_alpha = util::map_val(lin_grad_point, 0.75f / 2.f, 0.75f, CENTER_LANE_ALPHA, 0.f);
QColor final_color = QColor::fromHslF(static_cast<float>(_h / 360.f), adjusted_saturation, adjusted_lightness, dynamic_alpha); QColor final_color = QColor::fromHslF(static_cast<float>(_h / 360.f), adjusted_saturation, adjusted_lightness, dynamic_alpha);
bg.setColorAt(lin_grad_point, final_color); path_gradient.setColorAt(lin_grad_point, final_color);
i += (i + 2) < max_len ? 1 : 0; // Skipping a point to optimize rendering i += (i + 2) < max_len ? 1 : 0; // Skipping a point to optimize rendering
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
// Default shading if for some reason the above code fails // Default shading if for some reason the above code fails
bg = QLinearGradient(0, height(), 0, 0); path_gradient = QLinearGradient(0, height(), 0, 0);
bg.setColorAt(0.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(other_alpha * 255 * 0.4))); path_gradient.setColorAt(0.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(CENTER_LANE_ALPHA * 255 * 0.5)));
bg.setColorAt(0.5, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(other_alpha * 255 * 0.35))); path_gradient.setColorAt(0.5, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(CENTER_LANE_ALPHA * 255 * 0.4)));
bg.setColorAt(1.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(other_alpha * 255 * 0.0))); path_gradient.setColorAt(1.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(OTHER_LANE_ALPHA * 255 * 0.0)));
} }
} else { } else {
bg.setColorAt(0.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(other_alpha * 255 * 0.4))); path_gradient.setColorAt(0.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(CENTER_LANE_ALPHA * 255 * 0.5)));
bg.setColorAt(0.5, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(other_alpha * 255 * 0.35))); path_gradient.setColorAt(0.5, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(CENTER_LANE_ALPHA * 255 * 0.4)));
bg.setColorAt(1.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(other_alpha * 255 * 0.0))); path_gradient.setColorAt(1.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(CENTER_LANE_ALPHA * 255 * 0.0)));
} }
painter.setBrush(bg); painter.setBrush(path_gradient);
painter.drawPolygon(scene.track_vertices); painter.drawPolygon(scene.track_vertices);
// Paint path edges // Paint path edges
QLinearGradient pe(0, height(), 0, 0); // don't paint if not engaged color
if (alwaysOnLateralActive) { if (bg != bg_colors[STATUS_DISENGAGED]) {
QColor color = bg_colors[STATUS_ALWAYS_ON_LATERAL_ACTIVE]; // Use current background color
pe.setColorAt(0.0, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255))); edge_color.setColorAt(0.0, QColor(bg.red(), bg.green(), bg.blue(), static_cast<int>(OTHER_LANE_ALPHA * 255)));
pe.setColorAt(0.5, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255 * 0.5))); edge_color.setColorAt(0.5, QColor(bg.red(), bg.green(), bg.blue(), static_cast<int>(OTHER_LANE_ALPHA * 255 * 0.5)));
pe.setColorAt(1.0, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255 * 0.1))); edge_color.setColorAt(1.0, QColor(bg.red(), bg.green(), bg.blue(), static_cast<int>(OTHER_LANE_ALPHA * 255 * 0.1)));
} else if (conditionalStatus == 1 || conditionalStatus == 3 || conditionalStatus == 5 || experimentalMode) {
QColor color = bg_colors[STATUS_EXPERIMENTAL_ACTIVE]; QPainterPath path;
pe.setColorAt(0.0, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255))); path.addPolygon(scene.track_vertices);
pe.setColorAt(0.5, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255 * 0.5))); path.addPolygon(scene.track_edge_vertices);
pe.setColorAt(1.0, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255 * 0.1)));
} else if (trafficModeActive) { painter.setBrush(pe);
pe.setColorAt(0.0, QColor::fromHslF(355 / 360., 0.71, 0.46, 1.0)); painter.drawPath(path);
pe.setColorAt(0.5, QColor::fromHslF(355 / 360., 0.71, 0.46, 0.5));
pe.setColorAt(1.0, QColor::fromHslF(355 / 360., 0.71, 0.46, 0.1));
} else if (scene.navigate_on_openpilot) {
pe.setColorAt(0.0, QColor::fromHslF(205 / 360., 0.85, 0.56, 1.0));
pe.setColorAt(0.5, QColor::fromHslF(205 / 360., 0.85, 0.56, 0.5));
pe.setColorAt(1.0, QColor::fromHslF(205 / 360., 0.85, 0.56, 0.1));
} else {
QColor color = bg_colors[STATUS_ENGAGED];
pe.setColorAt(0.0, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255)));
pe.setColorAt(0.5, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255 * 0.5)));
pe.setColorAt(1.0, QColor(color.red(), color.green(), color.blue(), static_cast<int>(other_alpha * 255 * 0.1)));
} }
QPainterPath path;
path.addPolygon(scene.track_vertices);
path.addPolygon(scene.track_edge_vertices);
painter.setBrush(pe);
painter.drawPath(path);
// Paint blindspot path // Paint blindspot path
if (scene.blind_spot_path) { if (scene.blind_spot_path) {
QLinearGradient bs(0, height(), 0, 0); QLinearGradient bs(0, height(), 0, 0);
@@ -1071,14 +1036,7 @@ void AnnotatedCameraWidget::drawLead(QPainter &painter, const cereal::ModelDataV
// chevron // chevron
QPointF chevron[] = {{x + (sz * 1.25), y + sz}, {x, y}, {x - (sz * 1.25), y + sz}}; QPointF chevron[] = {{x + (sz * 1.25), y + sz}, {x, y}, {x - (sz * 1.25), y + sz}};
// CLEARPILOT disabling custom theme colors painter.setBrush(redColor(fillAlpha));
// if (currentHolidayTheme != 0) {
// painter.setBrush(std::get<2>(holidayThemeConfiguration[currentHolidayTheme]).begin()->second);
// } else if (customColors != 0) {
// painter.setBrush(std::get<2>(themeConfiguration[customColors]).begin()->second);
// } else {
painter.setBrush(redColor(fillAlpha));
// }
painter.drawPolygon(chevron, std::size(chevron)); painter.drawPolygon(chevron, std::size(chevron));
if (leadInfo) { if (leadInfo) {

View File

@@ -125,8 +125,12 @@ typedef enum UIStatus {
STATUS_ALWAYS_ON_LATERAL_ACTIVE, STATUS_ALWAYS_ON_LATERAL_ACTIVE,
STATUS_TRAFFIC_MODE_ACTIVE, STATUS_TRAFFIC_MODE_ACTIVE,
STATUS_EXPERIMENTAL_ACTIVE, STATUS_EXPERIMENTAL_ACTIVE,
CENTER_LANE_COLOR,
} UIStatus; } UIStatus;
const float CENTER_LANE_ALPHA = 0.35;
const float OTHER_LANE_ALPHA = 0.75;
// Clearpilot custom colors // Clearpilot custom colors
const QColor bg_colors [] = { const QColor bg_colors [] = {
[STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8), [STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8),
@@ -135,6 +139,7 @@ const QColor bg_colors [] = {
[STATUS_ALWAYS_ON_LATERAL_ACTIVE] = QColor(162, 221, 235, 0xd1), // Gray [STATUS_ALWAYS_ON_LATERAL_ACTIVE] = QColor(162, 221, 235, 0xd1), // Gray
[STATUS_TRAFFIC_MODE_ACTIVE] = QColor(0xc9, 0x22, 0x31, 0xd1), // ? unused? [STATUS_TRAFFIC_MODE_ACTIVE] = QColor(0xc9, 0x22, 0x31, 0xd1), // ? unused?
[STATUS_EXPERIMENTAL_ACTIVE] = QColor(201, 41, 204, 0xd1), // Magenta [STATUS_EXPERIMENTAL_ACTIVE] = QColor(201, 41, 204, 0xd1), // Magenta
[CENTER_LANE_COLOR] = QColor(150, 150, 150, 0xd1), // Gray
}; };
static std::map<cereal::ControlsState::AlertStatus, QColor> alert_colors = { static std::map<cereal::ControlsState::AlertStatus, QColor> alert_colors = {