Skip to content

Commit ddca3f1

Browse files
author
KhalilSelyan
committed
style: scaled up circle and icon for the traffic light
Signed-off-by: KhalilSelyan <khalil@leodrive.ai>
1 parent 37fde74 commit ddca3f1

File tree

1 file changed

+27
-17
lines changed
  • common/autoware_overlay_rviz_plugin/autoware_vehicle_overlay_rviz_plugin/src

1 file changed

+27
-17
lines changed

common/autoware_overlay_rviz_plugin/autoware_vehicle_overlay_rviz_plugin/src/traffic_display.cpp

+27-17
Original file line numberDiff line numberDiff line change
@@ -55,50 +55,60 @@ void TrafficDisplay::drawTrafficLightIndicator(QPainter & painter, const QRectF
5555
painter.setRenderHint(QPainter::Antialiasing, true);
5656
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
5757

58+
// #C2C2C2
59+
painter.setPen(QPen(gray, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
60+
painter.setBrush(QBrush(gray, Qt::SolidPattern));
5861
// Define the area for the circle (background)
5962
QRectF circleRect = backgroundRect;
6063
circleRect.setWidth(backgroundRect.width() / 2 - 20);
6164
circleRect.setHeight(backgroundRect.height() - 20);
6265
circleRect.moveTopRight(QPointF(backgroundRect.right() - 10, backgroundRect.top() + 10));
6366

64-
painter.setBrush(QBrush(gray));
65-
painter.drawEllipse(circleRect.center(), 30, 30);
66-
67-
// Define the area for the traffic light image (should be smaller or positioned within the circle)
68-
QRectF imageRect =
69-
circleRect.adjusted(15, 15, -15, -15); // Adjusting the rectangle to make the image smaller
70-
71-
QImage scaled_traffic_image = traffic_light_image_.scaled(
72-
imageRect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
67+
painter.drawEllipse(circleRect);
7368

7469
if (current_traffic_.signals.size() > 0) {
7570
switch (current_traffic_.signals[0].elements[0].color) {
7671
case 1:
7772
painter.setBrush(QBrush(red));
78-
painter.drawEllipse(circleRect.center(), 30, 30);
73+
painter.drawEllipse(circleRect);
7974
break;
8075
case 2:
8176
painter.setBrush(QBrush(yellow));
82-
painter.drawEllipse(circleRect.center(), 30, 30);
77+
painter.drawEllipse(circleRect);
8378
break;
8479
case 3:
8580
painter.setBrush(QBrush(green));
86-
painter.drawEllipse(circleRect.center(), 30, 30);
81+
painter.drawEllipse(circleRect);
8782
break;
8883
case 4:
8984
painter.setBrush(QBrush(gray));
90-
painter.drawEllipse(circleRect.center(), 30, 30);
85+
painter.drawEllipse(circleRect);
9186
break;
9287
default:
9388
painter.setBrush(QBrush(gray));
94-
painter.drawEllipse(circleRect.center(), 30, 30);
89+
painter.drawEllipse(circleRect);
9590
break;
9691
}
9792
}
98-
// make the image thicker
99-
painter.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
10093

101-
painter.drawImage(imageRect, scaled_traffic_image);
94+
// Scaling factor (e.g., 1.5 for 150% size)
95+
qreal scaleFactor = 1.25;
96+
97+
// Calculate the scaled size
98+
QSize scaledSize = traffic_light_image_.size() * scaleFactor;
99+
100+
// Ensure the scaled image is still within the circle bounds or adjust scaleFactor accordingly
101+
102+
// Calculate the centered rectangle for the scaled image
103+
QRectF scaledImageRect(0, 0, scaledSize.width(), scaledSize.height());
104+
scaledImageRect.moveCenter(circleRect.center());
105+
106+
// Scale the image to the new size
107+
QImage scaledTrafficImage =
108+
traffic_light_image_.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
109+
110+
// Draw the scaled and centered image
111+
painter.drawImage(scaledImageRect.topLeft(), scaledTrafficImage);
102112
}
103113

104114
QImage TrafficDisplay::coloredImage(const QImage & source, const QColor & color)

0 commit comments

Comments
 (0)