@@ -31,7 +31,7 @@ We'll run the `replay` tool with the demo route to get data streaming for testin
3131tools/replay/replay --demo
3232
3333# in terminal 2
34- selfdrive/ui/ui
34+ ./ selfdrive/ui/ui.py
3535```
3636
3737The openpilot UI should launch and show a replay of the demo route.
@@ -43,39 +43,41 @@ If you have your own comma device, you can replace `--demo` with one of your own
4343
4444Now let’s update the speed display color in the UI.
4545
46- Search for the function responsible for rendering UI text :
46+ Search for the function responsible for rendering the current speed :
4747``` bash
48- git grep " drawText " selfdrive/ui/qt/ onroad/hud.cc
48+ git grep " _draw_current_speed " selfdrive/ui/onroad/hud_renderer.py
4949```
5050
51- You’ ll find the relevant code inside ` selfdrive/ui/qt/ onroad/hud.cc ` , in this function:
51+ You' ll find the relevant code inside ` selfdrive/ui/onroad/hud_renderer.py ` , in this function:
5252
53- ``` cpp
54- void HudRenderer::drawText (QPainter &p, int x, int y, const QString &text, int alpha) {
55- QRect real_rect = p.fontMetrics().boundingRect(text);
56- real_rect.moveCenter({x, y - real_rect.height() / 2});
57-
58- p.setPen(QColor(0xff, 0xff, 0xff, alpha)); // <- this sets the speed text color
59- p.drawText(real_rect.x(), real_rect.bottom(), text);
60- }
53+ ``` python
54+ def _draw_current_speed (self , rect : rl.Rectangle) -> None :
55+ """ Draw the current vehicle speed and unit."""
56+ speed_text = str (round (self .speed))
57+ speed_text_size = measure_text_cached(self ._font_bold, speed_text, FONT_SIZES .current_speed)
58+ speed_pos = rl.Vector2(rect.x + rect.width / 2 - speed_text_size.x / 2 , 180 - speed_text_size.y / 2 )
59+ rl.draw_text_ex(self ._font_bold, speed_text, speed_pos, FONT_SIZES .current_speed, 0 , COLORS .white) # <- this sets the speed text color
6160```
6261
63- Change the `QColor(...)` line to make it **blue** instead of white. A nice soft blue is `#8080FF`, which translates to :
62+ Change the ` COLORS.white ` to make it ** blue** instead of white. A nice soft blue is ` #8080FF ` , which you can add to the COLORS section and use :
6463
6564``` diff
66- - p.setPen(QColor(0xff, 0xff, 0xff, alpha));
67- + p.setPen(QColor(0x80, 0x80, 0xFF, alpha));
65+ + # Add this to the COLORS definition (usually at the top of the file)
66+ + blue: rl.Color = rl.Color(0x80, 0x80, 0xFF, 255)
67+ +
68+ - rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FONT_SIZES.current_speed, 0, COLORS.white)
69+ + rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FONT_SIZES.current_speed, 0, COLORS.blue)
6870```
6971
70- This change will tint all speed-related UI text to blue with the same transparency ( ` alpha ` ) .
72+ This change will make the speed display text blue.
7173
7274---
7375
7476## 4. Rebuild the UI
7577
76- After making changes, rebuild Openpilot so your new UI is compiled :
78+ After making changes, re-run the demo replay to see your new UI:
7779``` bash
78- scons -j $( nproc ) && selfdrive/ui/ui
80+ ./ selfdrive/ui/ui.py
7981```
8082![ ] ( https://blog.comma.ai/img/blue_speed_ui.png )
8183
0 commit comments