|
|
|
@ -97,8 +97,7 @@ static void ui_draw_circle_image(NVGcontext *vg, int x, int y, int size, int ima |
|
|
|
|
nvgCircle(vg, x, y + (bdr_s * 1.5), size); |
|
|
|
|
nvgFillColor(vg, color); |
|
|
|
|
nvgFill(vg); |
|
|
|
|
const Rect rect = {x - (img_size / 2), img_y ? img_y : y - (size / 4), img_size, img_size}; |
|
|
|
|
ui_draw_image(vg, rect, image, img_alpha); |
|
|
|
|
ui_draw_image(vg, {x - (img_size / 2), img_y ? img_y : y - (size / 4), img_size, img_size}, image, img_alpha); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void ui_draw_circle_image(NVGcontext *vg, int x, int y, int size, int image, bool active) { |
|
|
|
@ -231,18 +230,17 @@ static void ui_draw_vision_maxspeed(UIState *s) { |
|
|
|
|
const bool is_cruise_set = maxspeed != 0 && maxspeed != SET_SPEED_NA; |
|
|
|
|
if (is_cruise_set && !s->is_metric) { maxspeed *= 0.6225; } |
|
|
|
|
|
|
|
|
|
auto [x, y, w, h] = std::tuple(s->scene.viz_rect.x + (bdr_s * 2), s->scene.viz_rect.y + (bdr_s * 1.5), 184, 202); |
|
|
|
|
|
|
|
|
|
ui_draw_rect(s->vg, x, y, w, h, COLOR_BLACK_ALPHA(100), 30); |
|
|
|
|
ui_draw_rect(s->vg, x, y, w, h, COLOR_WHITE_ALPHA(100), 20, 10); |
|
|
|
|
const Rect rect = {s->scene.viz_rect.x + (bdr_s * 2), int(s->scene.viz_rect.y + (bdr_s * 1.5)), 184, 202}; |
|
|
|
|
ui_fill_rect(s->vg, rect, COLOR_BLACK_ALPHA(100), 30.); |
|
|
|
|
ui_draw_rect(s->vg, rect, COLOR_WHITE_ALPHA(100), 10, 20.); |
|
|
|
|
|
|
|
|
|
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); |
|
|
|
|
ui_draw_text(s->vg, x + w / 2, 148, "MAX", 26 * 2.5, COLOR_WHITE_ALPHA(is_cruise_set ? 200 : 100), s->font_sans_regular); |
|
|
|
|
ui_draw_text(s->vg, rect.centerX(), 148, "MAX", 26 * 2.5, COLOR_WHITE_ALPHA(is_cruise_set ? 200 : 100), s->font_sans_regular); |
|
|
|
|
if (is_cruise_set) { |
|
|
|
|
const std::string maxspeed_str = std::to_string((int)std::nearbyint(maxspeed)); |
|
|
|
|
ui_draw_text(s->vg, x + w / 2, 242, maxspeed_str.c_str(), 48 * 2.5, COLOR_WHITE, s->font_sans_bold); |
|
|
|
|
ui_draw_text(s->vg, rect.centerX(), 242, maxspeed_str.c_str(), 48 * 2.5, COLOR_WHITE, s->font_sans_bold); |
|
|
|
|
} else { |
|
|
|
|
ui_draw_text(s->vg, x + w / 2, 242, "N/A", 42 * 2.5, COLOR_WHITE_ALPHA(100), s->font_sans_semibold); |
|
|
|
|
ui_draw_text(s->vg, rect.centerX(), 242, "N/A", 42 * 2.5, COLOR_WHITE_ALPHA(100), s->font_sans_semibold); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -294,25 +292,25 @@ static void ui_draw_driver_view(UIState *s) { |
|
|
|
|
const int blackout_w = rect.w - valid_rect.w; |
|
|
|
|
NVGpaint gradient = nvgLinearGradient(s->vg, blackout_x, rect.y, blackout_x + blackout_w, rect.y, |
|
|
|
|
COLOR_BLACK_ALPHA(is_rhd ? 255 : 0), COLOR_BLACK_ALPHA(is_rhd ? 0 : 255)); |
|
|
|
|
ui_draw_rect(s->vg, blackout_x, rect.y, blackout_w, rect.h, gradient); |
|
|
|
|
ui_draw_rect(s->vg, blackout_x, rect.y, blackout_w, rect.h, COLOR_BLACK_ALPHA(144)); |
|
|
|
|
ui_fill_rect(s->vg, {blackout_x, rect.y, blackout_w, rect.h}, gradient); |
|
|
|
|
ui_fill_rect(s->vg, {blackout_x, rect.y, blackout_w, rect.h}, COLOR_BLACK_ALPHA(144)); |
|
|
|
|
// border
|
|
|
|
|
ui_draw_rect(s->vg, rect.x, rect.y, rect.w, rect.h, bg_colors[STATUS_OFFROAD], 0, 1); |
|
|
|
|
ui_draw_rect(s->vg, rect, bg_colors[STATUS_OFFROAD], 1); |
|
|
|
|
|
|
|
|
|
const bool face_detected = s->scene.dmonitoring_state.getFaceDetected(); |
|
|
|
|
if (face_detected) { |
|
|
|
|
auto fxy_list = s->scene.driver_state.getFacePosition(); |
|
|
|
|
float face_x = fxy_list[0]; |
|
|
|
|
float face_y = fxy_list[1]; |
|
|
|
|
float fbox_x = valid_rect.centerX() + (is_rhd ? face_x : -face_x) * valid_rect.w; |
|
|
|
|
float fbox_y = valid_rect.centerY() + face_y * valid_rect.h; |
|
|
|
|
int fbox_x = valid_rect.centerX() + (is_rhd ? face_x : -face_x) * valid_rect.w; |
|
|
|
|
int fbox_y = valid_rect.centerY() + face_y * valid_rect.h; |
|
|
|
|
|
|
|
|
|
float alpha = 0.2; |
|
|
|
|
if (face_x = std::abs(face_x), face_y = std::abs(face_y); face_x <= 0.35 && face_y <= 0.4) |
|
|
|
|
alpha = 0.8 - (face_x > face_y ? face_x : face_y) * 0.6 / 0.375; |
|
|
|
|
|
|
|
|
|
const float box_size = 0.6 * rect.h / 2; |
|
|
|
|
ui_draw_rect(s->vg, fbox_x - box_size / 2, fbox_y - box_size / 2, box_size, box_size, nvgRGBAf(1.0, 1.0, 1.0, alpha), 35, 10); |
|
|
|
|
const int box_size = 0.6 * rect.h / 2; |
|
|
|
|
ui_draw_rect(s->vg, {fbox_x - box_size / 2, fbox_y - box_size / 2, box_size, box_size}, nvgRGBAf(1.0, 1.0, 1.0, alpha), 10, 35.); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// draw face icon
|
|
|
|
@ -329,7 +327,7 @@ static void ui_draw_vision_header(UIState *s) { |
|
|
|
|
viz_rect.x, viz_rect.y+header_h, |
|
|
|
|
nvgRGBAf(0,0,0,0.45), nvgRGBAf(0,0,0,0)); |
|
|
|
|
|
|
|
|
|
ui_draw_rect(s->vg, viz_rect.x, viz_rect.y, viz_rect.w, header_h, gradient); |
|
|
|
|
ui_fill_rect(s->vg, {viz_rect.x, viz_rect.y, viz_rect.w, header_h}, gradient); |
|
|
|
|
|
|
|
|
|
ui_draw_vision_maxspeed(s); |
|
|
|
|
ui_draw_vision_speed(s); |
|
|
|
@ -354,36 +352,33 @@ static void ui_draw_vision_alert(UIState *s) { |
|
|
|
|
|
|
|
|
|
NVGcolor color = bg_colors[s->status]; |
|
|
|
|
color.a *= get_alert_alpha(scene->alert_blinking_rate); |
|
|
|
|
int alr_s = alert_size_map[scene->alert_size]; |
|
|
|
|
|
|
|
|
|
const int alr_x = scene->viz_rect.x - bdr_s; |
|
|
|
|
const int alr_w = scene->viz_rect.w + (bdr_s * 2); |
|
|
|
|
const int alr_h = alr_s + bdr_s; |
|
|
|
|
const int alr_y = s->fb_h - alr_h; |
|
|
|
|
const int alr_h = alert_size_map[scene->alert_size] + bdr_s; |
|
|
|
|
const Rect rect = {.x = scene->viz_rect.x - bdr_s, |
|
|
|
|
.y = s->fb_h - alr_h, |
|
|
|
|
.w = scene->viz_rect.w + (bdr_s * 2), |
|
|
|
|
.h = alr_h}; |
|
|
|
|
|
|
|
|
|
ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, color); |
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, gradient); |
|
|
|
|
ui_fill_rect(s->vg, rect, color); |
|
|
|
|
ui_fill_rect(s->vg, rect, nvgLinearGradient(s->vg, rect.x, rect.y, rect.x, rect.bottom(),
|
|
|
|
|
nvgRGBAf(0.0, 0.0, 0.0, 0.05), nvgRGBAf(0.0, 0.0, 0.0, 0.35))); |
|
|
|
|
|
|
|
|
|
nvgFillColor(s->vg, COLOR_WHITE); |
|
|
|
|
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); |
|
|
|
|
|
|
|
|
|
if (scene->alert_size == cereal::ControlsState::AlertSize::SMALL) { |
|
|
|
|
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+15, scene->alert_text1.c_str(), 40*2.5, COLOR_WHITE, s->font_sans_semibold); |
|
|
|
|
ui_draw_text(s->vg, rect.centerX(), rect.centerY() + 15, scene->alert_text1.c_str(), 40*2.5, COLOR_WHITE, s->font_sans_semibold); |
|
|
|
|
} else if (scene->alert_size == cereal::ControlsState::AlertSize::MID) { |
|
|
|
|
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2-45, scene->alert_text1.c_str(), 48*2.5, COLOR_WHITE, s->font_sans_bold); |
|
|
|
|
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+75, scene->alert_text2.c_str(), 36*2.5, COLOR_WHITE, s->font_sans_regular); |
|
|
|
|
ui_draw_text(s->vg, rect.centerX(), rect.centerY() - 45, scene->alert_text1.c_str(), 48*2.5, COLOR_WHITE, s->font_sans_bold); |
|
|
|
|
ui_draw_text(s->vg, rect.centerX(), rect.centerY() + 75, scene->alert_text2.c_str(), 36*2.5, COLOR_WHITE, s->font_sans_regular); |
|
|
|
|
} else if (scene->alert_size == cereal::ControlsState::AlertSize::FULL) { |
|
|
|
|
nvgFontSize(s->vg, (longAlert1?72:96)*2.5); |
|
|
|
|
nvgFontFaceId(s->vg, s->font_sans_bold); |
|
|
|
|
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE); |
|
|
|
|
nvgTextBox(s->vg, alr_x, alr_y+(longAlert1?360:420), alr_w-60, scene->alert_text1.c_str(), NULL); |
|
|
|
|
nvgTextBox(s->vg, rect.x, rect.y+(longAlert1?360:420), rect.w-60, scene->alert_text1.c_str(), NULL); |
|
|
|
|
nvgFontSize(s->vg, 48*2.5); |
|
|
|
|
nvgFontFaceId(s->vg, s->font_sans_regular); |
|
|
|
|
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BOTTOM); |
|
|
|
|
nvgTextBox(s->vg, alr_x, alr_h-(longAlert1?300:360), alr_w-60, scene->alert_text2.c_str(), NULL); |
|
|
|
|
nvgTextBox(s->vg, rect.x, rect.h-(longAlert1?300:360), rect.w-60, scene->alert_text2.c_str(), NULL); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -466,25 +461,27 @@ void ui_draw_image(NVGcontext *vg, const Rect &r, int image, float alpha){ |
|
|
|
|
nvgFill(vg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGcolor color, float r, int width) { |
|
|
|
|
void ui_draw_rect(NVGcontext *vg, const Rect &r, NVGcolor color, int width, float radius) { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
radius > 0 ? nvgRoundedRect(vg, r.x, r.y, r.w, r.h, radius) : nvgRect(vg, r.x, r.y, r.w, r.h); |
|
|
|
|
nvgStrokeColor(vg, color); |
|
|
|
|
nvgStrokeWidth(vg, width); |
|
|
|
|
nvgStroke(vg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGpaint &paint, float r){ |
|
|
|
|
static inline void fill_rect(NVGcontext *vg, const Rect &r, const NVGcolor *color, const NVGpaint *paint, float radius) { |
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
r > 0? nvgRoundedRect(vg, x, y, w, h, r) : nvgRect(vg, x, y, w, h); |
|
|
|
|
nvgFillPaint(vg, paint); |
|
|
|
|
radius > 0? nvgRoundedRect(vg, r.x, r.y, r.w, r.h, radius) : nvgRect(vg, r.x, r.y, r.w, r.h); |
|
|
|
|
if (color) nvgFillColor(vg, *color); |
|
|
|
|
if (paint) nvgFillPaint(vg, *paint); |
|
|
|
|
nvgFill(vg); |
|
|
|
|
} |
|
|
|
|
void ui_fill_rect(NVGcontext *vg, const Rect &r, const NVGcolor &color, float radius) { |
|
|
|
|
fill_rect(vg, r, &color, nullptr, radius); |
|
|
|
|
} |
|
|
|
|
void ui_fill_rect(NVGcontext *vg, const Rect &r, const NVGpaint &paint, float radius){ |
|
|
|
|
fill_rect(vg, r, nullptr, &paint, radius); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const char frame_vertex_shader[] = |
|
|
|
|
#ifdef NANOVG_GL3_IMPLEMENTATION |
|
|
|
|