simplify drawing text and rect (#1446)

* add ui_draw_text

remove draw textbox

make draw_text static

add blank line

* add ui_draw_text

remove draw textbox

make draw_text static

add blank line

add ui_draw_rect

draw rounded rect

fx typo

* remove used variables

* reduce lines

fix typo

* resolve confilit
old-commit-hash: 846a58507f
commatwo_master
Dean Lee 5 years ago committed by GitHub
parent 9974fa017f
commit c1641cc035
  1. 261
      selfdrive/ui/paint.cc
  2. 20
      selfdrive/ui/sidebar.cc
  3. 2
      selfdrive/ui/ui.hpp

@ -57,6 +57,13 @@ static float lerp(float v0, float v1, float t) {
return (1 - t) * v0 + t * v1; return (1 - t) * v0 + t * v1;
} }
static void ui_draw_text(NVGcontext *vg, float x, float y, const char* string, float size, NVGcolor color, int font){
nvgFontFaceId(vg, font);
nvgFontSize(vg, size);
nvgFillColor(vg, color);
nvgText(vg, x, y, string, NULL);
}
static void draw_chevron(UIState *s, float x_in, float y_in, float sz, static void draw_chevron(UIState *s, float x_in, float y_in, float sz,
NVGcolor fillColor, NVGcolor glowColor) { NVGcolor fillColor, NVGcolor glowColor) {
const vec4 p_car_space = (vec4){{x_in, y_in, 0., 1.}}; const vec4 p_car_space = (vec4){{x_in, y_in, 0., 1.}};
@ -406,11 +413,6 @@ static void ui_draw_vision_maxspeed(UIState *s) {
/*if (!s->longitudinal_control){ /*if (!s->longitudinal_control){
return; return;
}*/ }*/
const UIScene *scene = &s->scene;
int ui_viz_rx = scene->ui_viz_rx;
int ui_viz_rw = scene->ui_viz_rw;
char maxspeed_str[32]; char maxspeed_str[32];
float maxspeed = s->scene.v_cruise; float maxspeed = s->scene.v_cruise;
int maxspeed_calc = maxspeed * 0.6225 + 0.5; int maxspeed_calc = maxspeed * 0.6225 + 0.5;
@ -430,7 +432,7 @@ static void ui_draw_vision_maxspeed(UIState *s) {
int viz_maxspeed_w = 184; int viz_maxspeed_w = 184;
int viz_maxspeed_h = 202; int viz_maxspeed_h = 202;
int viz_maxspeed_x = (ui_viz_rx + (bdr_s*2)); int viz_maxspeed_x = (s->scene.ui_viz_rx + (bdr_s*2));
int viz_maxspeed_y = (box_y + (bdr_s*1.5)); int viz_maxspeed_y = (box_y + (bdr_s*1.5));
int viz_maxspeed_xo = 180; int viz_maxspeed_xo = 180;
@ -442,63 +444,32 @@ static void ui_draw_vision_maxspeed(UIState *s) {
#endif #endif
// Draw Background // Draw Background
nvgBeginPath(s->vg); ui_draw_rect(s->vg, viz_maxspeed_x, viz_maxspeed_y, viz_maxspeed_w, viz_maxspeed_h,
nvgRoundedRect(s->vg, viz_maxspeed_x, viz_maxspeed_y, viz_maxspeed_w, viz_maxspeed_h, 30); is_set_over_limit ? nvgRGBA(218, 111, 37, 180) : COLOR_BLACK_ALPHA(100), 30);
if (is_set_over_limit) {
nvgFillColor(s->vg, nvgRGBA(218, 111, 37, 180));
} else {
nvgFillColor(s->vg, COLOR_BLACK_ALPHA(100));
}
nvgFill(s->vg);
// Draw Border // Draw Border
nvgBeginPath(s->vg); NVGcolor color = COLOR_WHITE_ALPHA(100);
nvgRoundedRect(s->vg, viz_maxspeed_x, viz_maxspeed_y, viz_maxspeed_w, viz_maxspeed_h, 20);
if (is_set_over_limit) { if (is_set_over_limit) {
nvgStrokeColor(s->vg, COLOR_OCHRE); color = COLOR_OCHRE;
} else if (is_speedlim_valid && !s->is_ego_over_limit) { } else if (is_speedlim_valid) {
nvgStrokeColor(s->vg, COLOR_WHITE); color = s->is_ego_over_limit ? COLOR_WHITE_ALPHA(20) : COLOR_WHITE;
} else if (is_speedlim_valid && s->is_ego_over_limit) {
nvgStrokeColor(s->vg, COLOR_WHITE_ALPHA(20));
} else {
nvgStrokeColor(s->vg, COLOR_WHITE_ALPHA(100));
} }
nvgStrokeWidth(s->vg, 10);
nvgStroke(s->vg);
// Draw "MAX" Text ui_draw_rect(s->vg, viz_maxspeed_x, viz_maxspeed_y, viz_maxspeed_w, viz_maxspeed_h, color, 20, 10);
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
nvgFontFaceId(s->vg, s->font_sans_regular);
nvgFontSize(s->vg, 26*2.5);
if (is_cruise_set) {
nvgFillColor(s->vg, COLOR_WHITE_ALPHA(200));
} else {
nvgFillColor(s->vg, COLOR_WHITE_ALPHA(100));
}
const int text_x = viz_maxspeed_x + (viz_maxspeed_xo / 2) + (viz_maxspeed_w / 2); const int text_x = viz_maxspeed_x + (viz_maxspeed_xo / 2) + (viz_maxspeed_w / 2);
nvgText(s->vg, text_x, 148, "MAX", NULL); ui_draw_text(s->vg, text_x, 148, "MAX", 26 * 2.5, COLOR_WHITE_ALPHA(is_cruise_set ? 200 : 100), s->font_sans_regular);
// Draw Speed Text
nvgFontFaceId(s->vg, s->font_sans_bold);
nvgFontSize(s->vg, 48*2.5);
if (is_cruise_set) { if (is_cruise_set) {
snprintf(maxspeed_str, sizeof(maxspeed_str), "%d", maxspeed_calc); snprintf(maxspeed_str, sizeof(maxspeed_str), "%d", maxspeed_calc);
nvgFillColor(s->vg, COLOR_WHITE); ui_draw_text(s->vg, text_x, 242, maxspeed_str, 48 * 2.5, COLOR_WHITE, s->font_sans_bold);
nvgText(s->vg, text_x, 242, maxspeed_str, NULL);
} else { } else {
nvgFontFaceId(s->vg, s->font_sans_semibold); ui_draw_text(s->vg, text_x, 242, "N/A", 42 * 2.5, COLOR_WHITE_ALPHA(100), s->font_sans_semibold);
nvgFontSize(s->vg, 42*2.5);
nvgFillColor(s->vg, COLOR_WHITE_ALPHA(100));
nvgText(s->vg, text_x, 242, "N/A", NULL);
} }
} }
static void ui_draw_vision_speedlimit(UIState *s) { static void ui_draw_vision_speedlimit(UIState *s) {
const UIScene *scene = &s->scene;
int ui_viz_rx = scene->ui_viz_rx;
int ui_viz_rw = scene->ui_viz_rw;
char speedlim_str[32]; char speedlim_str[32];
float speedlimit = s->scene.speedlimit; float speedlimit = s->scene.speedlimit;
int speedlim_calc = speedlimit * 2.2369363 + 0.5; int speedlim_calc = speedlimit * 2.2369363 + 0.5;
@ -515,7 +486,7 @@ static void ui_draw_vision_speedlimit(UIState *s) {
int viz_speedlim_w = 180; int viz_speedlim_w = 180;
int viz_speedlim_h = 202; int viz_speedlim_h = 202;
int viz_speedlim_x = (ui_viz_rx + (bdr_s*2)); int viz_speedlim_x = (s->scene.ui_viz_rx + (bdr_s*2));
int viz_speedlim_y = (box_y + (bdr_s*1.5)); int viz_speedlim_y = (box_y + (bdr_s*1.5));
if (!is_speedlim_valid) { if (!is_speedlim_valid) {
viz_speedlim_w -= 5; viz_speedlim_w -= 5;
@ -523,98 +494,55 @@ static void ui_draw_vision_speedlimit(UIState *s) {
viz_speedlim_x += 9; viz_speedlim_x += 9;
viz_speedlim_y += 5; viz_speedlim_y += 5;
} }
int viz_speedlim_bdr = is_speedlim_valid ? 30 : 15;
// Draw Background // Draw Background
nvgBeginPath(s->vg); NVGcolor color = COLOR_WHITE_ALPHA(100);
nvgRoundedRect(s->vg, viz_speedlim_x, viz_speedlim_y, viz_speedlim_w, viz_speedlim_h, viz_speedlim_bdr);
if (is_speedlim_valid && s->is_ego_over_limit) { if (is_speedlim_valid && s->is_ego_over_limit) {
nvgFillColor(s->vg, nvgRGBA(218, 111, 37, 180)); color = nvgRGBA(218, 111, 37, 180);
} else if (is_speedlim_valid) { } else if (is_speedlim_valid) {
nvgFillColor(s->vg, COLOR_WHITE); color = COLOR_WHITE;
} else {
nvgFillColor(s->vg, COLOR_WHITE_ALPHA(100));
} }
nvgFill(s->vg); ui_draw_rect(s->vg, viz_speedlim_x, viz_speedlim_y, viz_speedlim_w, viz_speedlim_h, color, is_speedlim_valid ? 30 : 15);
// Draw Border // Draw Border
if (is_speedlim_valid) { if (is_speedlim_valid) {
nvgStrokeWidth(s->vg, 10); ui_draw_rect(s->vg, viz_speedlim_x, viz_speedlim_y, viz_speedlim_w, viz_speedlim_h,
nvgStroke(s->vg); s->is_ego_over_limit ? COLOR_OCHRE : COLOR_WHITE, 20, 10);
nvgBeginPath(s->vg);
nvgRoundedRect(s->vg, viz_speedlim_x, viz_speedlim_y, viz_speedlim_w, viz_speedlim_h, 20);
if (s->is_ego_over_limit) {
nvgStrokeColor(s->vg, COLOR_OCHRE);
} else if (is_speedlim_valid) {
nvgStrokeColor(s->vg, COLOR_WHITE);
}
} }
const float text_x = viz_speedlim_x + viz_speedlim_w / 2;
const float text_y = viz_speedlim_y + (is_speedlim_valid ? 50 : 45);
// Draw "Speed Limit" Text // Draw "Speed Limit" Text
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
nvgFontFaceId(s->vg, s->font_sans_semibold); color = is_speedlim_valid && s->is_ego_over_limit ? COLOR_WHITE : COLOR_BLACK;
nvgFontSize(s->vg, 50); ui_draw_text(s->vg, text_x + (is_speedlim_valid ? 6 : 0), text_y, "SMART", 50, color, s->font_sans_semibold);
nvgFillColor(s->vg, COLOR_BLACK); ui_draw_text(s->vg, text_x + (is_speedlim_valid ? 6 : 0), text_y + 40, "SPEED", 50, color, s->font_sans_semibold);
if (is_speedlim_valid && s->is_ego_over_limit) {
nvgFillColor(s->vg, COLOR_WHITE);
}
const int text_x = viz_speedlim_x + viz_speedlim_w / 2;
nvgText(s->vg, text_x + (is_speedlim_valid ? 6 : 0), viz_speedlim_y + (is_speedlim_valid ? 50 : 45), "SMART", NULL);
nvgText(s->vg, text_x + (is_speedlim_valid ? 6 : 0), viz_speedlim_y + (is_speedlim_valid ? 90 : 85), "SPEED", NULL);
// Draw Speed Text // Draw Speed Text
nvgFontFaceId(s->vg, s->font_sans_bold); color = s->is_ego_over_limit ? COLOR_WHITE : COLOR_BLACK;
nvgFontSize(s->vg, 48*2.5);
if (s->is_ego_over_limit) {
nvgFillColor(s->vg, COLOR_WHITE);
} else {
nvgFillColor(s->vg, COLOR_BLACK);
}
if (is_speedlim_valid) { if (is_speedlim_valid) {
snprintf(speedlim_str, sizeof(speedlim_str), "%d", speedlim_calc); snprintf(speedlim_str, sizeof(speedlim_str), "%d", speedlim_calc);
nvgText(s->vg, text_x, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), speedlim_str, NULL); ui_draw_text(s->vg, text_x, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), speedlim_str, 48*2.5, color, s->font_sans_bold);
} else { } else {
nvgFontFaceId(s->vg, s->font_sans_semibold); ui_draw_text(s->vg, text_x, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), "N/A", 42*2.5, color, s->font_sans_semibold);
nvgFontSize(s->vg, 42*2.5);
nvgText(s->vg, text_x, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), "N/A", NULL);
} }
} }
static void ui_draw_vision_speed(UIState *s) { static void ui_draw_vision_speed(UIState *s) {
const UIScene *scene = &s->scene; const UIScene *scene = &s->scene;
int ui_viz_rx = scene->ui_viz_rx; float speed = s->scene.v_ego * 2.2369363 + 0.5;
int ui_viz_rw = scene->ui_viz_rw; if (s->is_metric){
float speed = s->scene.v_ego; speed = s->scene.v_ego * 3.6 + 0.5;
}
const int viz_speed_w = 280; const int viz_speed_w = 280;
const int viz_speed_x = ui_viz_rx+((ui_viz_rw/2)-(viz_speed_w/2)); const int viz_speed_x = scene->ui_viz_rx+((scene->ui_viz_rw/2)-(viz_speed_w/2));
char speed_str[32]; char speed_str[32];
nvgBeginPath(s->vg); nvgBeginPath(s->vg);
nvgRect(s->vg, viz_speed_x, box_y, viz_speed_w, header_h); nvgRect(s->vg, viz_speed_x, box_y, viz_speed_w, header_h);
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
if (s->is_metric) { snprintf(speed_str, sizeof(speed_str), "%d", (int)speed);
snprintf(speed_str, sizeof(speed_str), "%d", (int)(speed * 3.6 + 0.5)); ui_draw_text(s->vg, viz_speed_x + viz_speed_w / 2, 240, speed_str, 96*2.5, COLOR_WHITE, s->font_sans_bold);
} else { ui_draw_text(s->vg, viz_speed_x + viz_speed_w / 2, 320, s->is_metric?"kph":"mph", 36*2.5, COLOR_WHITE_ALPHA(200), s->font_sans_regular);
snprintf(speed_str, sizeof(speed_str), "%d", (int)(speed * 2.2369363 + 0.5));
}
const int text_x = viz_speed_x + viz_speed_w / 2;
nvgFontFaceId(s->vg, s->font_sans_bold);
nvgFontSize(s->vg, 96*2.5);
nvgFillColor(s->vg, COLOR_WHITE);
nvgText(s->vg, text_x, 240, speed_str, NULL);
nvgFontFaceId(s->vg, s->font_sans_regular);
nvgFontSize(s->vg, 36*2.5);
nvgFillColor(s->vg, COLOR_WHITE_ALPHA(200));
if (s->is_metric) {
nvgText(s->vg, text_x, 320, "kph", NULL);
} else {
nvgText(s->vg, text_x, 320, "mph", NULL);
}
} }
static void ui_draw_vision_event(UIState *s) { static void ui_draw_vision_event(UIState *s) {
@ -666,38 +594,23 @@ static void ui_draw_driver_view(UIState *s) {
// blackout // blackout
if (!scene->is_rhd) { if (!scene->is_rhd) {
nvgBeginPath(s->vg);
NVGpaint gradient = nvgLinearGradient(s->vg, valid_frame_x + valid_frame_w, NVGpaint gradient = nvgLinearGradient(s->vg, valid_frame_x + valid_frame_w,
box_y, box_y,
valid_frame_x + box_h / 2, box_y, valid_frame_x + box_h / 2, box_y,
nvgRGBAf(0,0,0,1), nvgRGBAf(0,0,0,0)); nvgRGBAf(0,0,0,1), nvgRGBAf(0,0,0,0));
nvgFillPaint(s->vg, gradient); ui_draw_rect(s->vg, valid_frame_x + box_h / 2, box_y, valid_frame_w - box_h / 2, box_h, gradient);
nvgRect(s->vg, valid_frame_x + box_h / 2, box_y, valid_frame_w - box_h / 2, box_h);
nvgFill(s->vg);
} else { } else {
nvgBeginPath(s->vg);
NVGpaint gradient = nvgLinearGradient(s->vg, valid_frame_x, NVGpaint gradient = nvgLinearGradient(s->vg, valid_frame_x,
box_y, box_y,
valid_frame_w - box_h / 2, box_y, valid_frame_w - box_h / 2, box_y,
nvgRGBAf(0,0,0,1), nvgRGBAf(0,0,0,0)); nvgRGBAf(0,0,0,1), nvgRGBAf(0,0,0,0));
nvgFillPaint(s->vg, gradient); ui_draw_rect(s->vg, valid_frame_x, box_y, valid_frame_w - box_h / 2, box_h, gradient);
nvgRect(s->vg, valid_frame_x, box_y, valid_frame_w - box_h / 2, box_h);
nvgFill(s->vg);
} }
nvgBeginPath(s->vg); ui_draw_rect(s->vg, scene->is_rhd ? valid_frame_x : valid_frame_x + box_h / 2, box_y, valid_frame_w - box_h / 2, box_h, COLOR_BLACK_ALPHA(144));
nvgRect(s->vg, scene->is_rhd ? valid_frame_x:valid_frame_x + box_h / 2, box_y, valid_frame_w - box_h / 2, box_h);
nvgFillColor(s->vg, COLOR_BLACK_ALPHA(144));
nvgFill(s->vg);
// borders // borders
nvgBeginPath(s->vg); ui_draw_rect(s->vg, frame_x, box_y, valid_frame_x - frame_x, box_h, nvgRGBA(23, 51, 73, 255));
nvgRect(s->vg, frame_x, box_y, valid_frame_x - frame_x, box_h); ui_draw_rect(s->vg, valid_frame_x + valid_frame_w, box_y, frame_w - valid_frame_w - (valid_frame_x - frame_x), box_h, nvgRGBA(23, 51, 73, 255));
nvgFillColor(s->vg, nvgRGBA(23,51,73,255));
nvgFill(s->vg);
nvgBeginPath(s->vg);
nvgRect(s->vg, valid_frame_x + valid_frame_w, box_y, frame_w - valid_frame_w - (valid_frame_x - frame_x), box_h);
nvgFillColor(s->vg, nvgRGBA(23,51,73,255));
nvgFill(s->vg);
// draw face box // draw face box
if (scene->face_prob > 0.4) { if (scene->face_prob > 0.4) {
@ -709,17 +622,11 @@ static void ui_draw_driver_view(UIState *s) {
fbox_x = valid_frame_x + valid_frame_w - box_h / 2 + (scene->face_x + 0.5) * (box_h / 2) - 0.5 * 0.6 * box_h / 2; fbox_x = valid_frame_x + valid_frame_w - box_h / 2 + (scene->face_x + 0.5) * (box_h / 2) - 0.5 * 0.6 * box_h / 2;
} }
if (abs(scene->face_x) <= 0.35 && abs(scene->face_y) <= 0.4) { if (abs(scene->face_x) <= 0.35 && abs(scene->face_y) <= 0.4) {
nvgBeginPath(s->vg); ui_draw_rect(s->vg, fbox_x, fbox_y, 0.6 * box_h / 2, 0.6 * box_h / 2,
nvgRoundedRect(s->vg, fbox_x, fbox_y, 0.6 * box_h / 2, 0.6 * box_h / 2, 35); nvgRGBAf(1.0, 1.0, 1.0, 0.8 - ((abs(scene->face_x) > abs(scene->face_y) ? abs(scene->face_x) : abs(scene->face_y))) * 0.6 / 0.375),
nvgStrokeColor(s->vg, nvgRGBAf(1.0, 1.0, 1.0, 0.8 - ((abs(scene->face_x) > abs(scene->face_y) ? abs(scene->face_x):abs(scene->face_y))) * 0.6 / 0.375)); 35, 10);
nvgStrokeWidth(s->vg, 10);
nvgStroke(s->vg);
} else { } else {
nvgBeginPath(s->vg); ui_draw_rect(s->vg, fbox_x, fbox_y, 0.6 * box_h / 2, 0.6 * box_h / 2, nvgRGBAf(1.0, 1.0, 1.0, 0.2), 35, 10);
nvgRoundedRect(s->vg, fbox_x, fbox_y, 0.6 * box_h / 2, 0.6 * box_h / 2, 35);
nvgStrokeColor(s->vg, nvgRGBAf(1.0, 1.0, 1.0, 0.2));
nvgStrokeWidth(s->vg, 10);
nvgStroke(s->vg);
} }
} else { } else {
; ;
@ -737,14 +644,11 @@ static void ui_draw_vision_header(UIState *s) {
int ui_viz_rx = scene->ui_viz_rx; int ui_viz_rx = scene->ui_viz_rx;
int ui_viz_rw = scene->ui_viz_rw; int ui_viz_rw = scene->ui_viz_rw;
nvgBeginPath(s->vg);
NVGpaint gradient = nvgLinearGradient(s->vg, ui_viz_rx, NVGpaint gradient = nvgLinearGradient(s->vg, ui_viz_rx,
(box_y+(header_h-(header_h/2.5))), (box_y+(header_h-(header_h/2.5))),
ui_viz_rx, box_y+header_h, ui_viz_rx, box_y+header_h,
nvgRGBAf(0,0,0,0.45), nvgRGBAf(0,0,0,0)); nvgRGBAf(0,0,0,0.45), nvgRGBAf(0,0,0,0));
nvgFillPaint(s->vg, gradient); ui_draw_rect(s->vg, ui_viz_rx, box_y, ui_viz_rw, header_h, gradient);
nvgRect(s->vg, ui_viz_rx, box_y, ui_viz_rw, header_h);
nvgFill(s->vg);
ui_draw_vision_maxspeed(s); ui_draw_vision_maxspeed(s);
@ -756,12 +660,8 @@ static void ui_draw_vision_header(UIState *s) {
} }
static void ui_draw_vision_footer(UIState *s) { static void ui_draw_vision_footer(UIState *s) {
const UIScene *scene = &s->scene;
int ui_viz_rx = scene->ui_viz_rx;
int ui_viz_rw = scene->ui_viz_rw;
nvgBeginPath(s->vg); nvgBeginPath(s->vg);
nvgRect(s->vg, ui_viz_rx, footer_y, ui_viz_rw, footer_h); nvgRect(s->vg, s->scene.ui_viz_rx, footer_y, s->scene.ui_viz_rw, footer_h);
ui_draw_vision_face(s); ui_draw_vision_face(s);
@ -773,45 +673,31 @@ static void ui_draw_vision_footer(UIState *s) {
void ui_draw_vision_alert(UIState *s, int va_size, int va_color, void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
const char* va_text1, const char* va_text2) { const char* va_text1, const char* va_text2) {
const UIScene *scene = &s->scene; const UIScene *scene = &s->scene;
int ui_viz_rx = scene->ui_viz_rx;
int ui_viz_rw = scene->ui_viz_rw;
const bool hasSidebar = !scene->uilayout_sidebarcollapsed; const bool hasSidebar = !scene->uilayout_sidebarcollapsed;
const bool mapEnabled = scene->uilayout_mapenabled; const bool mapEnabled = scene->uilayout_mapenabled;
bool longAlert1 = strlen(va_text1) > 15; bool longAlert1 = strlen(va_text1) > 15;
const uint8_t *color = alert_colors[va_color]; const uint8_t *color = alert_colors[va_color];
const int alr_s = alert_sizes[va_size]; const int alr_s = alert_sizes[va_size];
const int alr_x = ui_viz_rx-(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)-bdr_s; const int alr_x = scene->ui_viz_rx-(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)-bdr_s;
const int alr_w = ui_viz_rw+(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)+(bdr_s*2); const int alr_w = scene->ui_viz_rw+(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)+(bdr_s*2);
const int alr_h = alr_s+(va_size==ALERTSIZE_NONE?0:bdr_s); const int alr_h = alr_s+(va_size==ALERTSIZE_NONE?0:bdr_s);
const int alr_y = vwp_h-alr_h; const int alr_y = vwp_h-alr_h;
nvgBeginPath(s->vg); ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, nvgRGBA(color[0],color[1],color[2],(color[3]*s->alert_blinking_alpha)));
nvgRect(s->vg, alr_x, alr_y, alr_w, alr_h);
nvgFillColor(s->vg, nvgRGBA(color[0],color[1],color[2],(color[3]*s->alert_blinking_alpha)));
nvgFill(s->vg);
nvgBeginPath(s->vg);
NVGpaint gradient = nvgLinearGradient(s->vg, alr_x, alr_y, alr_x, alr_y+alr_h, NVGpaint gradient = nvgLinearGradient(s->vg, alr_x, alr_y, alr_x, alr_y+alr_h,
nvgRGBAf(0.0,0.0,0.0,0.05), nvgRGBAf(0.0,0.0,0.0,0.35)); nvgRGBAf(0.0,0.0,0.0,0.05), nvgRGBAf(0.0,0.0,0.0,0.35));
nvgFillPaint(s->vg, gradient); ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, gradient);
nvgRect(s->vg, alr_x, alr_y, alr_w, alr_h);
nvgFill(s->vg);
nvgFillColor(s->vg, COLOR_WHITE); nvgFillColor(s->vg, COLOR_WHITE);
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
if (va_size == ALERTSIZE_SMALL) { if (va_size == ALERTSIZE_SMALL) {
nvgFontFaceId(s->vg, s->font_sans_semibold); ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+15, va_text1, 40*2.5, COLOR_WHITE, s->font_sans_semibold);
nvgFontSize(s->vg, 40*2.5);
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+15, va_text1, NULL);
} else if (va_size== ALERTSIZE_MID) { } else if (va_size== ALERTSIZE_MID) {
nvgFontFaceId(s->vg, s->font_sans_bold); ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2-45, va_text1, 48*2.5, COLOR_WHITE, s->font_sans_bold);
nvgFontSize(s->vg, 48*2.5); ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+75, va_text2, 36*2.5, COLOR_WHITE, s->font_sans_regular);
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2-45, va_text1, NULL);
nvgFontFaceId(s->vg, s->font_sans_regular);
nvgFontSize(s->vg, 36*2.5);
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+75, va_text2, NULL);
} else if (va_size== ALERTSIZE_FULL) { } else if (va_size== ALERTSIZE_FULL) {
nvgFontSize(s->vg, (longAlert1?72:96)*2.5); nvgFontSize(s->vg, (longAlert1?72:96)*2.5);
nvgFontFaceId(s->vg, s->font_sans_bold); nvgFontFaceId(s->vg, s->font_sans_bold);
@ -826,14 +712,11 @@ void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
static void ui_draw_vision(UIState *s) { static void ui_draw_vision(UIState *s) {
const UIScene *scene = &s->scene; const UIScene *scene = &s->scene;
int ui_viz_rx = scene->ui_viz_rx;
int ui_viz_rw = scene->ui_viz_rw;
int ui_viz_ro = scene->ui_viz_ro;
// Draw video frames // Draw video frames
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
glViewport(ui_viz_rx+ui_viz_ro, s->fb_h-(box_y+box_h), viz_w, box_h); glViewport(scene->ui_viz_rx+scene->ui_viz_ro, s->fb_h-(box_y+box_h), viz_w, box_h);
glScissor(ui_viz_rx, s->fb_h-(box_y+box_h), ui_viz_rw, box_h); glScissor(scene->ui_viz_rx, s->fb_h-(box_y+box_h), scene->ui_viz_rw, box_h);
draw_frame(s); draw_frame(s);
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
@ -891,6 +774,26 @@ void ui_draw_image(NVGcontext *vg, float x, float y, float w, float h, int image
nvgFill(vg); nvgFill(vg);
} }
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGcolor color, float r, int width) {
nvgBeginPath(vg);
r > 0? nvgRoundedRect(vg, x, y, w, h, r) : nvgRect(vg, x, y, w, h);
if (width) {
nvgStrokeColor(vg, color);
nvgStrokeWidth(vg, width);
nvgStroke(vg);
} else {
nvgFillColor(vg, color);
nvgFill(vg);
}
}
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGpaint paint, float r){
nvgBeginPath(vg);
r > 0? nvgRoundedRect(vg, x, y, w, h, r) : nvgRect(vg, x, y, w, h);
nvgFillPaint(vg, paint);
nvgFill(vg);
}
#ifdef NANOVG_GL3_IMPLEMENTATION #ifdef NANOVG_GL3_IMPLEMENTATION
static const char frame_vertex_shader[] = static const char frame_vertex_shader[] =
"#version 150 core\n" "#version 150 core\n"

@ -5,11 +5,7 @@
static void ui_draw_sidebar_background(UIState *s) { static void ui_draw_sidebar_background(UIState *s) {
int sbr_x = !s->scene.uilayout_sidebarcollapsed ? 0 : -(sbr_w) + bdr_s * 2; int sbr_x = !s->scene.uilayout_sidebarcollapsed ? 0 : -(sbr_w) + bdr_s * 2;
ui_draw_rect(s->vg, sbr_x, 0, sbr_w, vwp_h, COLOR_BLACK_ALPHA(85));
nvgBeginPath(s->vg);
nvgRect(s->vg, sbr_x, 0, sbr_w, vwp_h);
nvgFillColor(s->vg, COLOR_BLACK_ALPHA(85));
nvgFill(s->vg);
} }
static void ui_draw_sidebar_settings_button(UIState *s) { static void ui_draw_sidebar_settings_button(UIState *s) {
@ -46,11 +42,8 @@ static void ui_draw_sidebar_battery_icon(UIState *s) {
int battery_img = strcmp(s->scene.batteryStatus, "Charging") == 0 ? int battery_img = strcmp(s->scene.batteryStatus, "Charging") == 0 ?
s->img_battery_charging : s->img_battery; s->img_battery_charging : s->img_battery;
nvgBeginPath(s->vg); ui_draw_rect(s->vg, battery_img_x + 6, battery_img_y + 5,
nvgRect(s->vg, battery_img_x + 6, battery_img_y + 5, ((battery_img_w - 19) * (s->scene.batteryPercent * 0.01)), battery_img_h - 11, COLOR_WHITE);
((battery_img_w - 19) * (s->scene.batteryPercent * 0.01)), battery_img_h - 11);
nvgFillColor(s->vg, COLOR_WHITE);
nvgFill(s->vg);
ui_draw_image(s->vg, battery_img_x, battery_img_y, battery_img_w, battery_img_h, battery_img, 1.0f); ui_draw_image(s->vg, battery_img_x, battery_img_y, battery_img_w, battery_img_h, battery_img, 1.0f);
} }
@ -90,11 +83,8 @@ static void ui_draw_sidebar_metric(UIState *s, const char* label_str, const char
status_color = COLOR_RED; status_color = COLOR_RED;
} }
nvgBeginPath(s->vg); ui_draw_rect(s->vg, metric_x, metric_y, metric_w, metric_h,
nvgRoundedRect(s->vg, metric_x, metric_y, metric_w, metric_h, 20); severity > 0 ? COLOR_WHITE : COLOR_WHITE_ALPHA(85), 20, 2);
nvgStrokeColor(s->vg, severity > 0 ? COLOR_WHITE : COLOR_WHITE_ALPHA(85));
nvgStrokeWidth(s->vg, 2);
nvgStroke(s->vg);
nvgBeginPath(s->vg); nvgBeginPath(s->vg);
nvgRoundedRectVarying(s->vg, metric_x + 6, metric_y + 6, 18, metric_h - 12, 25, 0, 0, 25); nvgRoundedRectVarying(s->vg, metric_x + 6, metric_y + 6, 18, metric_h - 12, 25, 0, 0, 25);

@ -313,6 +313,8 @@ void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
void ui_draw(UIState *s); void ui_draw(UIState *s);
void ui_draw_sidebar(UIState *s); void ui_draw_sidebar(UIState *s);
void ui_draw_image(NVGcontext *vg, float x, float y, float w, float h, int image, float alpha); void ui_draw_image(NVGcontext *vg, float x, float y, float w, float h, int image, float alpha);
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGcolor color, float r = 0, int width = 0);
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGpaint paint, float r = 0);
void ui_nvg_init(UIState *s); void ui_nvg_init(UIState *s);
#endif #endif

Loading…
Cancel
Save