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) {
bg = QLinearGradient(0, height(), 0, 0); // Initialize bg to a default color
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setMargin(UI_BORDER_SIZE);
QStackedLayout *stacked_layout = new QStackedLayout;
@@ -824,44 +825,25 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
painter.save();
// 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);
// lanelines
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.drawPolygon(scene.lane_line_vertices[i]);
}
// road edges
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.drawPolygon(scene.road_edge_vertices[i]);
}
// paint path
QLinearGradient bg(0, height(), 0, 0);
// paint center lane path
QColor center_lane_color = bg_colors[CENTER_LANE_COLOR];
QLinearGradient path_gradient(0, height(), 0, 0);
if (experimentalMode || scene.acceleration_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
@@ -876,6 +858,7 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
try {
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;
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
// 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);
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
}
} catch (const std::exception& e) {
// Default shading if for some reason the above code fails
bg = 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)));
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)));
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 = QLinearGradient(0, height(), 0, 0);
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)));
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)));
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 {
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)));
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)));
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(0.0, QColor(center_lane_color.red(), center_lane_color.green(), center_lane_color.blue(), static_cast<int>(CENTER_LANE_ALPHA * 255 * 0.5)));
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)));
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);
// Paint path edges
QLinearGradient pe(0, height(), 0, 0);
if (alwaysOnLateralActive) {
QColor color = bg_colors[STATUS_ALWAYS_ON_LATERAL_ACTIVE];
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)));
} else if (conditionalStatus == 1 || conditionalStatus == 3 || conditionalStatus == 5 || experimentalMode) {
QColor color = bg_colors[STATUS_EXPERIMENTAL_ACTIVE];
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)));
} else if (trafficModeActive) {
pe.setColorAt(0.0, QColor::fromHslF(355 / 360., 0.71, 0.46, 1.0));
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)));
// don't paint if not engaged color
if (bg != bg_colors[STATUS_DISENGAGED]) {
// Use current background color
edge_color.setColorAt(0.0, QColor(bg.red(), bg.green(), bg.blue(), static_cast<int>(OTHER_LANE_ALPHA * 255)));
edge_color.setColorAt(0.5, QColor(bg.red(), bg.green(), bg.blue(), static_cast<int>(OTHER_LANE_ALPHA * 255 * 0.5)));
edge_color.setColorAt(1.0, QColor(bg.red(), bg.green(), bg.blue(), static_cast<int>(OTHER_LANE_ALPHA * 255 * 0.1)));
QPainterPath path;
path.addPolygon(scene.track_vertices);
path.addPolygon(scene.track_edge_vertices);
painter.setBrush(pe);
painter.drawPath(path);
}
QPainterPath path;
path.addPolygon(scene.track_vertices);
path.addPolygon(scene.track_edge_vertices);
painter.setBrush(pe);
painter.drawPath(path);
// Paint blindspot path
if (scene.blind_spot_path) {
QLinearGradient bs(0, height(), 0, 0);
@@ -1071,14 +1036,7 @@ void AnnotatedCameraWidget::drawLead(QPainter &painter, const cereal::ModelDataV
// chevron
QPointF chevron[] = {{x + (sz * 1.25), y + sz}, {x, y}, {x - (sz * 1.25), y + sz}};
// CLEARPILOT disabling custom theme colors
// 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.setBrush(redColor(fillAlpha));
painter.drawPolygon(chevron, std::size(chevron));
if (leadInfo) {