UI: simplify ui_draw_vision_speed (#19594)
* simplify draw_vision_speed * use std::nearbyint * use std::to_string old-commit-hash: ba4fb80e92145d7c31003b17a758f6a9c6a633c9
This commit is contained in:
@@ -325,23 +325,11 @@ static void ui_draw_vision_maxspeed(UIState *s) {
|
||||
}
|
||||
|
||||
static void ui_draw_vision_speed(UIState *s) {
|
||||
const Rect &viz_rect = s->scene.viz_rect;
|
||||
float v_ego = s->scene.controls_state.getVEgo();
|
||||
float speed = v_ego * 2.2369363 + 0.5;
|
||||
if (s->is_metric){
|
||||
speed = v_ego * 3.6 + 0.5;
|
||||
}
|
||||
const int viz_speed_w = 280;
|
||||
const int viz_speed_x = viz_rect.centerX() - viz_speed_w/2;
|
||||
char speed_str[32];
|
||||
|
||||
nvgBeginPath(s->vg);
|
||||
nvgRect(s->vg, viz_speed_x, viz_rect.y, viz_speed_w, header_h);
|
||||
const float speed = s->scene.controls_state.getVEgo() * (s->is_metric ? 3.6 : 2.2369363);
|
||||
const std::string speed_str = std::to_string((int)std::nearbyint(speed));
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
|
||||
|
||||
snprintf(speed_str, sizeof(speed_str), "%d", (int)speed);
|
||||
ui_draw_text(s->vg, viz_rect.centerX(), 240, speed_str, 96*2.5, COLOR_WHITE, s->font_sans_bold);
|
||||
ui_draw_text(s->vg, viz_rect.centerX(), 320, s->is_metric?"km/h":"mph", 36*2.5, COLOR_WHITE_ALPHA(200), s->font_sans_regular);
|
||||
ui_draw_text(s->vg, s->scene.viz_rect.centerX(), 240, speed_str.c_str(), 96 * 2.5, COLOR_WHITE, s->font_sans_bold);
|
||||
ui_draw_text(s->vg, s->scene.viz_rect.centerX(), 320, s->is_metric ? "km/h" : "mph", 36 * 2.5, COLOR_WHITE_ALPHA(200), s->font_sans_regular);
|
||||
}
|
||||
|
||||
static void ui_draw_vision_event(UIState *s) {
|
||||
|
||||
Reference in New Issue
Block a user