mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 08:14:00 +08:00
+222
-308
@@ -53,19 +53,16 @@
|
||||
|
||||
const int vwp_w = 1920;
|
||||
const int vwp_h = 1080;
|
||||
const int nav_w = 0;
|
||||
const int nav_ww= 0;
|
||||
const int nav_w = 640;
|
||||
const int nav_ww= 760;
|
||||
const int sbr_w = 300;
|
||||
const int bdr_s = 30;
|
||||
const int box_x = sbr_w+bdr_s;
|
||||
const int box_y = bdr_s;
|
||||
const int box_w = vwp_w-sbr_w-(bdr_s*2);
|
||||
const int box_h = vwp_h-(bdr_s*2);
|
||||
const int viz_x = box_x+nav_w;
|
||||
const int viz_y = box_y;
|
||||
const int viz_w = box_w-nav_w;
|
||||
const int viz_h = box_h;
|
||||
const int viz_header_h = 420;
|
||||
const int viz_w = vwp_w-(bdr_s*2);
|
||||
const int header_h = 420;
|
||||
|
||||
const uint8_t bg_colors[][4] = {
|
||||
[STATUS_STOPPED] = {0x07, 0x23, 0x39, 0xff},
|
||||
@@ -77,7 +74,7 @@ const uint8_t bg_colors[][4] = {
|
||||
|
||||
const uint8_t alert_colors[][4] = {
|
||||
[STATUS_STOPPED] = {0x07, 0x23, 0x39, 0xf1},
|
||||
[STATUS_DISENGAGED] = {0x17, 0x33, 0x49, 0xf1},
|
||||
[STATUS_DISENGAGED] = {0x17, 0x33, 0x49, 0xc8},
|
||||
[STATUS_ENGAGED] = {0x17, 0x86, 0x44, 0xf1},
|
||||
[STATUS_WARNING] = {0xDA, 0x6F, 0x25, 0xf1},
|
||||
[STATUS_ALERT] = {0xC9, 0x22, 0x31, 0xf1},
|
||||
@@ -115,12 +112,10 @@ typedef struct UIScene {
|
||||
|
||||
bool uilayout_sidebarcollapsed;
|
||||
bool uilayout_mapenabled;
|
||||
// responsive sizes for sidebar
|
||||
// responsive layout
|
||||
int ui_viz_rx;
|
||||
int ui_viz_rw;
|
||||
// responsize offset for frame + projections
|
||||
int ui_frame_offset;
|
||||
int ui_world_offset;
|
||||
int ui_viz_ro;
|
||||
|
||||
int lead_status;
|
||||
float lead_d_rel, lead_y_rel, lead_v_rel;
|
||||
@@ -228,8 +223,6 @@ typedef struct UIState {
|
||||
static int last_brightness = -1;
|
||||
static void set_brightness(int brightness) {
|
||||
if (last_brightness != brightness) {
|
||||
//printf("setting brightness %d\n", brightness);
|
||||
// can't hurt
|
||||
FILE *f = fopen("/sys/class/leds/lcd-backlight/brightness", "wb");
|
||||
if (f != NULL) {
|
||||
fprintf(f, "%d", brightness);
|
||||
@@ -309,7 +302,7 @@ static const mat4 device_transform = {{
|
||||
|
||||
// frame from 4/3 to box size with a 2x zoon
|
||||
static const mat4 frame_transform = {{
|
||||
2*(4./3.)/((float)box_w/viz_h), 0.0, 0.0, 0.0,
|
||||
2*(4./3.)/((float)viz_w/box_h), 0.0, 0.0, 0.0,
|
||||
0.0, 2.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0,
|
||||
@@ -445,7 +438,6 @@ static bool try_load_intrinsics(mat3 *intrinsic_matrix) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs,
|
||||
int num_back_fds, const int *back_fds,
|
||||
const VisionStreamBufs front_bufs, int num_front_fds,
|
||||
@@ -495,12 +487,6 @@ static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs,
|
||||
}
|
||||
}
|
||||
|
||||
static bool ui_alert_active(UIState *s) {
|
||||
return (nanos_since_boot() - s->scene.alert_ts) < 20000000000ULL &&
|
||||
strlen(s->scene.alert_text1) > 0 &&
|
||||
s->scene.alert_size == cereal_Live100Data_AlertSize_full;
|
||||
}
|
||||
|
||||
static void ui_update_frame(UIState *s) {
|
||||
assert(glGetError() == GL_NO_ERROR);
|
||||
|
||||
@@ -580,8 +566,6 @@ vec3 car_space_to_full_frame(const UIState *s, vec4 car_space_projective) {
|
||||
return p_image;
|
||||
}
|
||||
|
||||
|
||||
// TODO: refactor with draw_path
|
||||
static void draw_cross(UIState *s, float x_in, float y_in, float sz, NVGcolor color) {
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
@@ -626,52 +610,58 @@ static void draw_cross(UIState *s, float x_in, float y_in, float sz, NVGcolor co
|
||||
nvgRestore(s->vg);
|
||||
}
|
||||
|
||||
static void draw_x_y(UIState *s, const float *x_coords, const float *y_coords, size_t num_points,
|
||||
NVGcolor color) {
|
||||
static void draw_chevron(UIState *s, float x_in, float y_in, float sz,
|
||||
NVGcolor fillColor, NVGcolor glowColor) {
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
nvgSave(s->vg);
|
||||
|
||||
// path coords are worked out in rgb-box space
|
||||
nvgTranslate(s->vg, 240.0f, 0.0);
|
||||
|
||||
// zooom in 2x
|
||||
nvgTranslate(s->vg, -1440.0f / 2, -1080.0f / 2);
|
||||
nvgScale(s->vg, 2.0, 2.0);
|
||||
|
||||
nvgScale(s->vg, 1440.0f / s->rgb_width, 1080.0f / s->rgb_height);
|
||||
|
||||
const vec4 p_car_space = (vec4){{x_in, y_in, 0., 1.}};
|
||||
const vec3 p_full_frame = car_space_to_full_frame(s, p_car_space);
|
||||
|
||||
sz *= 30;
|
||||
sz /= (x_in / 3 + 30);
|
||||
if (sz > 30) sz = 30;
|
||||
if (sz < 15) sz = 15;
|
||||
|
||||
float x = p_full_frame.v[0];
|
||||
float y = p_full_frame.v[1];
|
||||
|
||||
// glow
|
||||
nvgBeginPath(s->vg);
|
||||
nvgStrokeColor(s->vg, color);
|
||||
nvgStrokeWidth(s->vg, 2);
|
||||
bool started = false;
|
||||
|
||||
for (int i=0; i<num_points; i++) {
|
||||
float px = x_coords[i];
|
||||
float py = y_coords[i];
|
||||
vec4 p_car_space = (vec4){{px, py, 0., 1.}};
|
||||
vec3 p_full_frame = car_space_to_full_frame(s, p_car_space);
|
||||
|
||||
float x = p_full_frame.v[0];
|
||||
float y = p_full_frame.v[1];
|
||||
if (x < 0 || y < 0.) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
nvgMoveTo(s->vg, x, y);
|
||||
started = true;
|
||||
} else {
|
||||
nvgLineTo(s->vg, x, y);
|
||||
}
|
||||
float g_xo = 5;
|
||||
float g_yo = 2;
|
||||
if (x >= 0 && y >= 0.) {
|
||||
nvgMoveTo(s->vg, x+(sz*1.35)+g_xo, y+sz+g_yo);
|
||||
nvgLineTo(s->vg, x, y-g_xo);
|
||||
nvgLineTo(s->vg, x-(sz*1.35)-g_xo, y+sz+g_yo);
|
||||
nvgLineTo(s->vg, x+(sz*1.35)+g_xo, y+sz+g_yo);
|
||||
nvgClosePath(s->vg);
|
||||
}
|
||||
nvgFillColor(s->vg, glowColor);
|
||||
nvgFill(s->vg);
|
||||
|
||||
nvgStroke(s->vg);
|
||||
// chevron
|
||||
nvgBeginPath(s->vg);
|
||||
if (x >= 0 && y >= 0.) {
|
||||
nvgMoveTo(s->vg, x+(sz*1.25), y+sz);
|
||||
nvgLineTo(s->vg, x, y);
|
||||
nvgLineTo(s->vg, x-(sz*1.25), y+sz);
|
||||
nvgLineTo(s->vg, x+(sz*1.25), y+sz);
|
||||
nvgClosePath(s->vg);
|
||||
}
|
||||
nvgFillColor(s->vg, fillColor);
|
||||
nvgFill(s->vg);
|
||||
|
||||
nvgRestore(s->vg);
|
||||
}
|
||||
|
||||
static void draw_path(UIState *s, const float *points, float off,
|
||||
static void ui_draw_lane_edge(UIState *s, const float *points, float off,
|
||||
NVGcolor color, int width) {
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
@@ -717,12 +707,112 @@ static void draw_path(UIState *s, const float *points, float off,
|
||||
nvgRestore(s->vg);
|
||||
}
|
||||
|
||||
static void draw_model_path(UIState *s, const PathData path, NVGcolor color) {
|
||||
draw_path(s, path.points, 0.0, color, 4*path.prob);
|
||||
static void ui_draw_lane(UIState *s, const PathData path, NVGcolor color) {
|
||||
ui_draw_lane_edge(s, path.points, 0.0, color, 5*path.prob);
|
||||
float var = min(path.std, 0.7);
|
||||
color.a /= 4;
|
||||
draw_path(s, path.points, -var, color, 2);
|
||||
draw_path(s, path.points, var, color, 2);
|
||||
ui_draw_lane_edge(s, path.points, -var, color, 2);
|
||||
ui_draw_lane_edge(s, path.points, var, color, 2);
|
||||
}
|
||||
|
||||
static void ui_draw_track(UIState *s, bool is_mpc) {
|
||||
const UIScene *scene = &s->scene;
|
||||
const PathData path = scene->model.path;
|
||||
const float *mpc_x_coords = &scene->mpc_x[0];
|
||||
const float *mpc_y_coords = &scene->mpc_y[0];
|
||||
|
||||
nvgSave(s->vg);
|
||||
nvgTranslate(s->vg, 240.0f, 0.0); // rgb-box space
|
||||
nvgTranslate(s->vg, -1440.0f / 2, -1080.0f / 2); // zoom 2x
|
||||
nvgScale(s->vg, 2.0, 2.0);
|
||||
nvgScale(s->vg, 1440.0f / s->rgb_width, 1080.0f / s->rgb_height);
|
||||
nvgBeginPath(s->vg);
|
||||
|
||||
bool started = false;
|
||||
|
||||
int track_start_x = 0;
|
||||
int track_start_y = 0;
|
||||
int track_end_x = 0;
|
||||
int track_end_y = 0;
|
||||
|
||||
int lead_d = (int)scene->lead_d_rel*2.;
|
||||
int path_height = is_mpc?((lead_d>5)?min(lead_d, 25)-min(lead_d/5,5):20)
|
||||
:((lead_d>0)?min(lead_d, 50)-min(lead_d/2.5,15):50);
|
||||
float off = is_mpc?0.3:0.5;
|
||||
|
||||
// left side up
|
||||
for (int i=0; i<path_height; i++) {
|
||||
float px, py;
|
||||
if (is_mpc) {
|
||||
px = mpc_x_coords[i];
|
||||
py = mpc_y_coords[i] - off;
|
||||
} else {
|
||||
px = (float)i;
|
||||
py = path.points[i] - off;
|
||||
}
|
||||
|
||||
vec4 p_car_space = (vec4){{px, py, 0., 1.}};
|
||||
vec3 p_full_frame = car_space_to_full_frame(s, p_car_space);
|
||||
float x = p_full_frame.v[0];
|
||||
float y = p_full_frame.v[1];
|
||||
if (x < 0 || y < 0.) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
nvgMoveTo(s->vg, x, y);
|
||||
track_start_x = x;
|
||||
track_start_y = y;
|
||||
started = true;
|
||||
} else {
|
||||
nvgLineTo(s->vg, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// right side down
|
||||
for (int i=path_height; i>0; i--) {
|
||||
float px, py;
|
||||
if (is_mpc) {
|
||||
px = mpc_x_coords[i];
|
||||
py = mpc_y_coords[i] + off;
|
||||
} else {
|
||||
px = (float)i;
|
||||
py = path.points[i] + off;
|
||||
}
|
||||
|
||||
vec4 p_car_space = (vec4){{px, py, 0., 1.}};
|
||||
vec3 p_full_frame = car_space_to_full_frame(s, p_car_space);
|
||||
float x = p_full_frame.v[0];
|
||||
float y = p_full_frame.v[1];
|
||||
if (x < 0 || y < 0.) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
nvgMoveTo(s->vg, x, y);
|
||||
track_end_y = y;
|
||||
track_end_x = x;
|
||||
started = true;
|
||||
} else {
|
||||
nvgLineTo(s->vg, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
NVGpaint track_bg;
|
||||
if (is_mpc) {
|
||||
// green track
|
||||
const uint8_t *clr = bg_colors[s->status];
|
||||
track_bg = nvgLinearGradient(s->vg, track_start_x, track_start_y, track_end_x, track_end_y,
|
||||
nvgRGBA(clr[0], clr[1], clr[2], 255), nvgRGBA(clr[0], clr[1], clr[2], 150));
|
||||
} else {
|
||||
// white track
|
||||
track_bg = nvgLinearGradient(s->vg, track_start_x, track_start_y, track_end_x, track_end_y,
|
||||
nvgRGBA(255, 255, 255, 150), nvgRGBA(255, 255, 255, 75));
|
||||
}
|
||||
|
||||
nvgFillPaint(s->vg, track_bg);
|
||||
nvgFill(s->vg);
|
||||
nvgRestore(s->vg);
|
||||
}
|
||||
|
||||
static void draw_steering(UIState *s, float curvature) {
|
||||
@@ -732,27 +822,23 @@ static void draw_steering(UIState *s, float curvature) {
|
||||
points[i] = y_actual;
|
||||
}
|
||||
|
||||
draw_path(s, points, 0.0, nvgRGBA(0, 0, 255, 128), 5);
|
||||
ui_draw_lane_edge(s, points, 0.0, nvgRGBA(0, 0, 255, 128), 5);
|
||||
}
|
||||
|
||||
static void draw_frame(UIState *s) {
|
||||
// draw frame texture
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
mat4 out_mat;
|
||||
float x1, x2, y1, y2;
|
||||
if (s->scene.frontview) {
|
||||
out_mat = device_transform; // full 16/9
|
||||
|
||||
// flip horizontally so it looks like a mirror
|
||||
x2 = (float)scene->front_box_x / s->rgb_front_width;
|
||||
x1 = (float)(scene->front_box_x + scene->front_box_width) / s->rgb_front_width;
|
||||
|
||||
y1 = (float)scene->front_box_y / s->rgb_front_height;
|
||||
y2 = (float)(scene->front_box_y + scene->front_box_height) / s->rgb_front_height;
|
||||
} else {
|
||||
out_mat = matmul(device_transform, frame_transform);
|
||||
|
||||
x1 = 1.0;
|
||||
x2 = 0.0;
|
||||
y1 = 1.0;
|
||||
@@ -791,137 +877,25 @@ static void draw_frame(UIState *s) {
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, &frame_indicies[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw a rect at specific position with specific dimensions
|
||||
*/
|
||||
static void ui_draw_rounded_rect(
|
||||
NVGcontext* c,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height,
|
||||
int radius,
|
||||
NVGcolor color
|
||||
) {
|
||||
|
||||
int bottom_x = x + width;
|
||||
int bottom_y = y + height;
|
||||
|
||||
nvgBeginPath(c);
|
||||
|
||||
// Position the rect
|
||||
nvgRoundedRect(c, x, y, bottom_x, bottom_y, radius);
|
||||
|
||||
// Color the rect
|
||||
nvgFillColor(c, color);
|
||||
|
||||
// Draw the rect
|
||||
nvgFill(c);
|
||||
|
||||
// Draw white border around rect
|
||||
nvgStrokeColor(c, nvgRGBA(255,255,255,200));
|
||||
nvgStroke(c);
|
||||
}
|
||||
|
||||
static void fill_lane(UIState *s, const float *l_points, const float *r_points, float off,
|
||||
NVGcolor color) {
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
nvgSave(s->vg);
|
||||
|
||||
// path coords are worked out in rgb-box space
|
||||
nvgTranslate(s->vg, 240.0f, 0.0);
|
||||
|
||||
// zoom in 2x
|
||||
nvgTranslate(s->vg, -1440.0f / 2, -1080.0f / 2);
|
||||
nvgScale(s->vg, 2.0, 2.0);
|
||||
|
||||
nvgScale(s->vg, 1440.0f / s->rgb_width, 1080.0f / s->rgb_height);
|
||||
|
||||
nvgBeginPath(s->vg);
|
||||
bool started = false;
|
||||
|
||||
int gradient_start_x = 0;
|
||||
int gradient_start_y = 0;
|
||||
int gradient_end_x = 0;
|
||||
int gradient_end_y = 0;
|
||||
|
||||
// left side of lane
|
||||
for (int i=0; i<50; i++) {
|
||||
float px = (float)i;
|
||||
float py = l_points[i] + off;
|
||||
|
||||
vec4 p_car_space = (vec4){{px, py, 0., 1.}};
|
||||
vec3 p_full_frame = car_space_to_full_frame(s, p_car_space);
|
||||
|
||||
float x = p_full_frame.v[0];
|
||||
float y = p_full_frame.v[1];
|
||||
if (x < 0 || y < 0.) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
nvgMoveTo(s->vg, x, y);
|
||||
gradient_start_x = x;
|
||||
gradient_start_y = y;
|
||||
started = true;
|
||||
} else {
|
||||
nvgLineTo(s->vg, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// right side of lane
|
||||
for (int i=50; i>0; i--) {
|
||||
float px = (float)i;
|
||||
float py = r_points[i] + off;
|
||||
|
||||
vec4 p_car_space = (vec4){{px, py, 0., 1.}};
|
||||
vec3 p_full_frame = car_space_to_full_frame(s, p_car_space);
|
||||
|
||||
float x = p_full_frame.v[0];
|
||||
float y = p_full_frame.v[1];
|
||||
if (x < 0 || y < 0.) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
nvgMoveTo(s->vg, x, y);
|
||||
started = true;
|
||||
} else {
|
||||
nvgLineTo(s->vg, x, y);
|
||||
gradient_end_y = y;
|
||||
gradient_end_x = x;
|
||||
}
|
||||
}
|
||||
|
||||
NVGpaint bg = nvgLinearGradient(s->vg, gradient_start_x, gradient_start_y, gradient_end_x, gradient_end_y,
|
||||
nvgRGBAf(0.6, 0.6, 0.6, 1.0*scene->model.left_lane.prob), nvgRGBAf(0.6, 0.6, 0.6, 1.0*scene->model.right_lane.prob));
|
||||
|
||||
nvgFillPaint(s->vg, bg);
|
||||
nvgFill(s->vg);
|
||||
|
||||
nvgRestore(s->vg);
|
||||
}
|
||||
|
||||
static void ui_draw_vision_lanes(UIState *s) {
|
||||
const UIScene *scene = &s->scene;
|
||||
if ((nanos_since_boot() - scene->model_ts) < 1000000000ULL) {
|
||||
// draw left lane edge
|
||||
draw_model_path(
|
||||
ui_draw_lane(
|
||||
s, scene->model.left_lane,
|
||||
nvgRGBAf(1.0, 1.0, 1.0, scene->model.left_lane.prob));
|
||||
|
||||
// draw right lane edge
|
||||
draw_model_path(
|
||||
ui_draw_lane(
|
||||
s, scene->model.right_lane,
|
||||
nvgRGBAf(1.0, 1.0, 1.0, scene->model.right_lane.prob));
|
||||
|
||||
// draw projected path line
|
||||
draw_path(s, scene->model.path.points, 0.0f, nvgRGBA(0xc0, 0xc0, 0xc0, 255), 5);
|
||||
// draw vision path
|
||||
ui_draw_track(s, false);
|
||||
|
||||
// draw MPC only if engaged
|
||||
// draw MPC path when engaged
|
||||
if (scene->engaged) {
|
||||
draw_x_y(s, &scene->mpc_x[0], &scene->mpc_y[0], 20, nvgRGBA(255, 0, 0, 255));
|
||||
ui_draw_track(s, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1057,39 +1031,6 @@ static void ui_draw_vision_topbar(UIState *s) {
|
||||
nvgText(s->vg, right_x+right_width/2, 185, "LEAD CAR", NULL);
|
||||
}
|
||||
|
||||
static void ui_draw_calibration_status(UIState *s) {
|
||||
const UIScene *scene = &s->scene;
|
||||
int ui_viz_rx = scene->ui_viz_rx;
|
||||
int ui_viz_rw = scene->ui_viz_rw;
|
||||
|
||||
int viz_calib_w = 1120;
|
||||
int viz_calib_x = (ui_viz_rx + ((ui_viz_rw/2) - (viz_calib_w/2)));
|
||||
int viz_calib_y = 760;
|
||||
int viz_calib_h = 250;
|
||||
int viz_calibtext_x = (ui_viz_rx + (ui_viz_rw/2));
|
||||
|
||||
nvgBeginPath(s->vg);
|
||||
nvgStrokeWidth(s->vg, 10);
|
||||
nvgRoundedRect(s->vg, viz_calib_x, viz_calib_y, viz_calib_w, viz_calib_h, 20);
|
||||
nvgStroke(s->vg);
|
||||
nvgFillColor(s->vg, nvgRGBA(0,0,0,180));
|
||||
nvgFill(s->vg);
|
||||
|
||||
nvgFontSize(s->vg, 40*2.5);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
|
||||
nvgFontFace(s->vg, "sans-semibold");
|
||||
nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 220));
|
||||
char calib_status_str[64];
|
||||
snprintf(calib_status_str, sizeof(calib_status_str), "Calibration in Progress: %d%%", scene->cal_perc);
|
||||
|
||||
nvgText(s->vg, viz_calibtext_x, viz_calib_y+100, calib_status_str, NULL);
|
||||
if (s->is_metric) {
|
||||
nvgText(s->vg, viz_calibtext_x, viz_calib_y+200, "Drive above 72 km/h", NULL);
|
||||
} else {
|
||||
nvgText(s->vg, viz_calibtext_x, viz_calib_y+200, "Drive above 45 mph", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_draw_gpsplanner_status(UIState *s) {
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
@@ -1129,7 +1070,7 @@ static void ui_draw_vision_maxspeed(UIState *s) {
|
||||
float maxspeed = s->scene.v_cruise;
|
||||
|
||||
const int viz_maxspeed_x = (ui_viz_rx + (bdr_s*2));
|
||||
const int viz_maxspeed_y = (viz_y + (bdr_s*1.5));
|
||||
const int viz_maxspeed_y = (box_y + (bdr_s*1.5));
|
||||
const int viz_maxspeed_w = 180;
|
||||
const int viz_maxspeed_h = 202;
|
||||
char maxspeed_str[32];
|
||||
@@ -1174,7 +1115,7 @@ static void ui_draw_vision_speed(UIState *s) {
|
||||
char speed_str[32];
|
||||
|
||||
nvgBeginPath(s->vg);
|
||||
nvgRect(s->vg, viz_speed_x, viz_y, viz_speed_w, viz_header_h);
|
||||
nvgRect(s->vg, viz_speed_x, box_y, viz_speed_w, header_h);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
|
||||
|
||||
if (s->is_metric) {
|
||||
@@ -1204,21 +1145,21 @@ static void ui_draw_vision_wheel(UIState *s) {
|
||||
const int ui_viz_rw = scene->ui_viz_rw;
|
||||
const int viz_event_w = 220;
|
||||
const int viz_event_x = ((ui_viz_rx + ui_viz_rw) - (viz_event_w + (bdr_s*2)));
|
||||
const int viz_event_y = (viz_y + (bdr_s*1.5));
|
||||
const int viz_event_h = (viz_header_h - (bdr_s*1.5));
|
||||
const int viz_event_y = (box_y + (bdr_s*1.5));
|
||||
const int viz_event_h = (header_h - (bdr_s*1.5));
|
||||
// draw steering wheel
|
||||
const int viz_wheel_size = 96;
|
||||
const int viz_wheel_x = viz_event_x + (viz_event_w-viz_wheel_size);
|
||||
const int viz_wheel_y = viz_event_y + (viz_wheel_size/2);
|
||||
const int img_wheel_size = viz_wheel_size*1.5;
|
||||
const int img_wheel_x = viz_wheel_x-(img_wheel_size/2);
|
||||
const int img_wheel_y = viz_wheel_y-25;
|
||||
const int bg_wheel_size = 96;
|
||||
const int bg_wheel_x = viz_event_x + (viz_event_w-bg_wheel_size);
|
||||
const int bg_wheel_y = viz_event_y + (bg_wheel_size/2);
|
||||
const int img_wheel_size = bg_wheel_size*1.5;
|
||||
const int img_wheel_x = bg_wheel_x-(img_wheel_size/2);
|
||||
const int img_wheel_y = bg_wheel_y-25;
|
||||
float img_wheel_alpha = 0.5f;
|
||||
bool is_engaged = (s->status == STATUS_ENGAGED);
|
||||
bool is_warning = (s->status == STATUS_WARNING);
|
||||
if (is_engaged || is_warning) {
|
||||
nvgBeginPath(s->vg);
|
||||
nvgCircle(s->vg, viz_wheel_x, (viz_wheel_y + (bdr_s*1.5)), viz_wheel_size);
|
||||
nvgCircle(s->vg, bg_wheel_x, (bg_wheel_y + (bdr_s*1.5)), bg_wheel_size);
|
||||
if (is_engaged) {
|
||||
nvgFillColor(s->vg, nvgRGBA(23, 134, 68, 255));
|
||||
} else if (is_warning) {
|
||||
@@ -1242,11 +1183,11 @@ static void ui_draw_vision_header(UIState *s) {
|
||||
|
||||
nvgBeginPath(s->vg);
|
||||
NVGpaint gradient = nvgLinearGradient(s->vg, ui_viz_rx,
|
||||
(viz_y+(viz_header_h-(viz_header_h/2.5))),
|
||||
ui_viz_rx, viz_y+viz_header_h,
|
||||
(box_y+(header_h-(header_h/2.5))),
|
||||
ui_viz_rx, box_y+header_h,
|
||||
nvgRGBAf(0,0,0,0.45), nvgRGBAf(0,0,0,0));
|
||||
nvgFillPaint(s->vg, gradient);
|
||||
nvgRect(s->vg, ui_viz_rx, viz_y, ui_viz_rw, viz_header_h);
|
||||
nvgRect(s->vg, ui_viz_rx, box_y, ui_viz_rw, header_h);
|
||||
nvgFill(s->vg);
|
||||
|
||||
ui_draw_vision_maxspeed(s);
|
||||
@@ -1254,19 +1195,20 @@ static void ui_draw_vision_header(UIState *s) {
|
||||
ui_draw_vision_wheel(s);
|
||||
}
|
||||
|
||||
static void ui_draw_vision_alert(UIState *s) {
|
||||
static void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
|
||||
const char* va_text1, const char* va_text2) {
|
||||
const UIScene *scene = &s->scene;
|
||||
int ui_viz_rx = scene->ui_viz_rx;
|
||||
int ui_viz_rw = scene->ui_viz_rw;
|
||||
bool hasSidebar = !s->scene.uilayout_sidebarcollapsed;
|
||||
bool mapEnabled = s->scene.uilayout_mapenabled;
|
||||
bool longAlert1 = strlen(scene->alert_text1) > 15;
|
||||
bool longAlert1 = strlen(va_text1) > 15;
|
||||
|
||||
const uint8_t *color = alert_colors[s->status];
|
||||
const int alr_s = alert_sizes[s->alert_size];
|
||||
const int alr_x = ui_viz_rx-(mapEnabled?(hasSidebar?nav_w:(nav_ww+(bdr_s*2))):0)-bdr_s;
|
||||
const int alr_w = ui_viz_rw+(mapEnabled?(hasSidebar?nav_w:(nav_ww+(bdr_s*2))):0)+(bdr_s*2);
|
||||
const int alr_h = alr_s+(s->alert_size==ALERTSIZE_NONE?0:bdr_s);
|
||||
const uint8_t *color = alert_colors[va_color];
|
||||
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_w = 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_y = vwp_h-alr_h;
|
||||
|
||||
nvgBeginPath(s->vg);
|
||||
@@ -1284,41 +1226,52 @@ static void ui_draw_vision_alert(UIState *s) {
|
||||
nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 255));
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
|
||||
|
||||
if (s->alert_size == ALERTSIZE_SMALL) {
|
||||
if (va_size == ALERTSIZE_SMALL) {
|
||||
nvgFontFace(s->vg, "sans-semibold");
|
||||
nvgFontSize(s->vg, 40*2.5);
|
||||
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+15, scene->alert_text1, NULL);
|
||||
} else if (s->alert_size == ALERTSIZE_MID) {
|
||||
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+15, va_text1, NULL);
|
||||
} else if (va_size== ALERTSIZE_MID) {
|
||||
nvgFontFace(s->vg, "sans-bold");
|
||||
nvgFontSize(s->vg, 48*2.5);
|
||||
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2-45, scene->alert_text1, NULL);
|
||||
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2-45, va_text1, NULL);
|
||||
nvgFontFace(s->vg, "sans-regular");
|
||||
nvgFontSize(s->vg, 36*2.5);
|
||||
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+75, scene->alert_text2, NULL);
|
||||
} else if (s->alert_size == ALERTSIZE_FULL) {
|
||||
nvgText(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+75, va_text2, NULL);
|
||||
} else if (va_size== ALERTSIZE_FULL) {
|
||||
nvgFontSize(s->vg, (longAlert1?72:96)*2.5);
|
||||
nvgFontFace(s->vg, "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, NULL);
|
||||
nvgTextBox(s->vg, alr_x, alr_y+(longAlert1?360:420), alr_w-60, va_text1, NULL);
|
||||
nvgFontSize(s->vg, 48*2.5);
|
||||
nvgFontFace(s->vg, "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, NULL);
|
||||
nvgTextBox(s->vg, alr_x, alr_h-(longAlert1?300:360), alr_w-60, va_text2, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_draw_calibration_status(UIState *s) {
|
||||
const UIScene *scene = &s->scene;
|
||||
char calib_str1[64];
|
||||
char calib_str2[64];
|
||||
snprintf(calib_str1, sizeof(calib_str1), "Calibration in Progress: %d%%", scene->cal_perc);
|
||||
snprintf(calib_str2, sizeof(calib_str2), (s->is_metric?"Drive above 72 km/h":"Drive above 45 mph"));
|
||||
|
||||
ui_draw_vision_alert(s, ALERTSIZE_MID, s->status, calib_str1, calib_str2);
|
||||
}
|
||||
|
||||
static void ui_draw_vision(UIState *s) {
|
||||
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;
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// scissor for EON UI
|
||||
// Draw video frames
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(ui_viz_rx, s->fb_h-(viz_y+viz_h), ui_viz_rw, viz_h);
|
||||
glViewport(ui_viz_rx, s->fb_h-(viz_y+viz_h), ui_viz_rw, viz_h);
|
||||
glViewport(ui_viz_rx+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);
|
||||
draw_frame(s);
|
||||
glViewport(0, 0, s->fb_w, s->fb_h);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
@@ -1330,74 +1283,41 @@ static void ui_draw_vision(UIState *s) {
|
||||
nvgBeginFrame(s->vg, s->fb_w, s->fb_h, 1.0f);
|
||||
nvgSave(s->vg);
|
||||
|
||||
// hack for eon
|
||||
const int inner_height = ui_viz_rw*9/16;
|
||||
nvgScissor(s->vg, ui_viz_rx, viz_y, ui_viz_rw, viz_h);
|
||||
nvgTranslate(s->vg, ui_viz_rx, viz_y + (viz_h-inner_height)/2.0);
|
||||
nvgScale(s->vg, (float)ui_viz_rw / s->fb_w, (float)inner_height / s->fb_h);
|
||||
// Draw augmented elements
|
||||
const int inner_height = viz_w*9/16;
|
||||
nvgScissor(s->vg, ui_viz_rx, box_y, ui_viz_rw, box_h);
|
||||
nvgTranslate(s->vg, ui_viz_rx+ui_viz_ro, box_y + (box_h-inner_height)/2.0);
|
||||
nvgScale(s->vg, (float)viz_w / s->fb_w, (float)inner_height / s->fb_h);
|
||||
|
||||
if (!scene->frontview) {
|
||||
ui_draw_world(s);
|
||||
|
||||
if (scene->lead_status) {
|
||||
draw_cross(s, scene->lead_d_rel + 2.7, scene->lead_y_rel, 30,
|
||||
nvgRGBA(255, 0, 0, 128));
|
||||
draw_chevron(s, scene->lead_d_rel+2.7, scene->lead_y_rel, 30,
|
||||
nvgRGBA(201, 34, 49, 255), nvgRGBA(218, 202, 37, 255));
|
||||
}
|
||||
}
|
||||
|
||||
nvgRestore(s->vg);
|
||||
|
||||
// Set Speed, Current Speed, Status/Events
|
||||
ui_draw_vision_header(s);
|
||||
if (scene->cal_status == CALIBRATION_UNCALIBRATED) {
|
||||
ui_draw_calibration_status(s);
|
||||
|
||||
if (s->scene.alert_size != ALERTSIZE_NONE) {
|
||||
// Controls Alerts
|
||||
ui_draw_vision_alert(s, s->scene.alert_size, s->status,
|
||||
s->scene.alert_text1, s->scene.alert_text2);
|
||||
} else {
|
||||
// Calibration Status
|
||||
if (scene->cal_status == CALIBRATION_UNCALIBRATED) {
|
||||
ui_draw_calibration_status(s);
|
||||
}
|
||||
}
|
||||
ui_draw_vision_alert(s);
|
||||
|
||||
nvgEndFrame(s->vg);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
|
||||
static void ui_draw_alerts(UIState *s) {
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
if (!ui_alert_active(s)) return;
|
||||
|
||||
assert(s->status < ARRAYSIZE(alert_colors));
|
||||
const uint8_t *color = alert_colors[s->status];
|
||||
|
||||
char alert_text1_upper[1024] = {0};
|
||||
for (int i=0; scene->alert_text1[i] && i < sizeof(alert_text1_upper)-1; i++) {
|
||||
alert_text1_upper[i] = toupper(scene->alert_text1[i]);
|
||||
}
|
||||
|
||||
nvgBeginPath(s->vg);
|
||||
nvgRect(s->vg, box_x, box_y, box_w, box_h);
|
||||
nvgFillColor(s->vg, nvgRGBA(color[0], color[1], color[2], color[3]));
|
||||
nvgFill(s->vg);
|
||||
|
||||
nvgFontFace(s->vg, "sans-semibold");
|
||||
|
||||
if (strlen(alert_text1_upper) > 15) {
|
||||
nvgFontSize(s->vg, 72.0*2.5);
|
||||
} else {
|
||||
nvgFontSize(s->vg, 96.0*2.5);
|
||||
}
|
||||
nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 255));
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
|
||||
nvgTextBox(s->vg, box_x + 50, box_y + 287, box_w - 50, alert_text1_upper, NULL);
|
||||
|
||||
|
||||
if (strlen(scene->alert_text2) > 0) {
|
||||
|
||||
nvgFontFace(s->vg, "sans-regular");
|
||||
nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 255));
|
||||
nvgFontSize(s->vg, 44.0*2.5);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BOTTOM);
|
||||
nvgTextBox(s->vg, box_x + 50, box_y + box_h - 250, box_w - 50, scene->alert_text2, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_draw_blank(UIState *s) {
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
@@ -1453,11 +1373,6 @@ static void ui_draw(UIState *s) {
|
||||
|
||||
nvgBeginFrame(s->vg, s->fb_w, s->fb_h, 1.0f);
|
||||
|
||||
if (s->vision_connected && !s->scene.uilayout_sidebarcollapsed) {
|
||||
ui_draw_aside(s);
|
||||
}
|
||||
// ui_draw_alerts(s);
|
||||
|
||||
nvgEndFrame(s->vg);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
@@ -1553,8 +1468,7 @@ static void ui_update(UIState *s) {
|
||||
// Default UI Measurements (Assumes sidebar visible)
|
||||
s->scene.ui_viz_rx = box_x;
|
||||
s->scene.ui_viz_rw = box_w;
|
||||
s->scene.ui_frame_offset = -(sbr_w - 4*bdr_s);
|
||||
s->scene.ui_world_offset = -(sbr_w - 6*bdr_s);
|
||||
s->scene.ui_viz_ro = -(sbr_w - 4*bdr_s);
|
||||
|
||||
s->vision_connect_firstrun = false;
|
||||
}
|
||||
@@ -1814,13 +1728,13 @@ static void ui_update(UIState *s) {
|
||||
bool hasSidebar = !s->scene.uilayout_sidebarcollapsed;
|
||||
bool mapEnabled = s->scene.uilayout_mapenabled;
|
||||
if (mapEnabled) {
|
||||
s->scene.ui_viz_rx = hasSidebar ? viz_x : (viz_x-(bdr_s*2));
|
||||
s->scene.ui_viz_rw = hasSidebar ? viz_w : (viz_w+(bdr_s*2));
|
||||
s->scene.ui_viz_rx = hasSidebar ? (box_x+nav_w) : (box_x+nav_w-(bdr_s*4));
|
||||
s->scene.ui_viz_rw = hasSidebar ? (box_w-nav_w) : (box_w-nav_w+(bdr_s*4));
|
||||
s->scene.ui_viz_ro = -(sbr_w + 4*bdr_s);
|
||||
} else {
|
||||
s->scene.ui_viz_rx = hasSidebar ? box_x : (box_x-sbr_w+bdr_s*2);
|
||||
s->scene.ui_viz_rw = hasSidebar ? box_w : (box_w+sbr_w-(bdr_s*2));
|
||||
s->scene.ui_frame_offset = hasSidebar ? -(sbr_w - 4*bdr_s) : -(bdr_s*2);
|
||||
s->scene.ui_world_offset = hasSidebar ? -(sbr_w - 6*bdr_s) : -(bdr_s*2);
|
||||
s->scene.ui_viz_ro = hasSidebar ? -(sbr_w - 6*bdr_s) : 0;
|
||||
}
|
||||
}
|
||||
capn_free(&ctx);
|
||||
|
||||
Reference in New Issue
Block a user