@ -225,11 +225,11 @@ static void ui_draw_track(UIState *s, bool is_mpc, track_vertices_data *pvd) {
if ( is_mpc ) {
if ( is_mpc ) {
// Draw colored MPC track
// Draw colored MPC track
const Color clr = bg_colors [ s - > status ] ;
const Color clr = bg_colors [ s - > status ] ;
track_bg = nvgLinearGradient ( s - > vg , vwp_w , vwp_h , vwp_w , vwp _h* .4 ,
track_bg = nvgLinearGradient ( s - > vg , s - > fb_w , s - > fb_h , s - > fb_w , s - > fb _h* .4 ,
nvgRGBA ( clr . r , clr . g , clr . b , 255 ) , nvgRGBA ( clr . r , clr . g , clr . b , 255 / 2 ) ) ;
nvgRGBA ( clr . r , clr . g , clr . b , 255 ) , nvgRGBA ( clr . r , clr . g , clr . b , 255 / 2 ) ) ;
} else {
} else {
// Draw white vision track
// Draw white vision track
track_bg = nvgLinearGradient ( s - > vg , vwp_w , vwp_h , vwp_w , vwp _h* .4 ,
track_bg = nvgLinearGradient ( s - > vg , s - > fb_w , s - > fb_h , s - > fb_w , s - > fb _h* .4 ,
COLOR_WHITE , COLOR_WHITE_ALPHA ( 0 ) ) ;
COLOR_WHITE , COLOR_WHITE_ALPHA ( 0 ) ) ;
}
}
nvgFillPaint ( s - > vg , track_bg ) ;
nvgFillPaint ( s - > vg , track_bg ) ;
@ -338,23 +338,17 @@ static void ui_draw_vision_lanes(UIState *s) {
// Draw all world space objects.
// Draw all world space objects.
static void ui_draw_world ( UIState * s ) {
static void ui_draw_world ( UIState * s ) {
const UIScene * scene = & s - > scene ;
const UIScene * scene = & s - > scene ;
if ( ! scene - > world_objects_visible ) {
const Rect & viz_rect = scene - > viz_rect ;
return ;
const int viz_w = s - > fb_w - bdr_s * 2 ;
}
const int inner_height = float ( viz_w ) * s - > fb_h / s - > fb_w ;
const int inner_height = float ( viz_w ) * vwp_h / vwp_w ;
const int ui_viz_rx = scene - > ui_viz_rx ;
const int ui_viz_rw = scene - > ui_viz_rw ;
const int ui_viz_ro = scene - > ui_viz_ro ;
nvgSave ( s - > vg ) ;
nvgSave ( s - > vg ) ;
nvgScissor ( s - > vg , ui_viz_rx , box_y , ui_viz_rw , box_ h) ;
nvgScissor ( s - > vg , viz_rect . x , viz_rect . y , viz_rect . w , viz_rect . h ) ;
nvgTranslate ( s - > vg , ui_ viz_rx+ ui_viz_ro , box_y + ( box_ h- inner_height ) / 2.0 ) ;
nvgTranslate ( s - > vg , viz_rect . x + scene - > ui_viz_ro , viz_rect . y + ( viz_rect . h - inner_height ) / 2.0 ) ;
nvgScale ( s - > vg , ( float ) viz_w / s - > fb_w , ( float ) inner_height / s - > fb_h ) ;
nvgScale ( s - > vg , ( float ) viz_w / s - > fb_w , ( float ) inner_height / s - > fb_h ) ;
float w = 1440.0f ; // Why 1440?
float w = 1440.0f ; // Why 1440?
nvgTranslate ( s - > vg , ( vwp _w - w ) / 2.0f , 0.0 ) ;
nvgTranslate ( s - > vg , ( s - > fb _w - w ) / 2.0f , 0.0 ) ;
nvgTranslate ( s - > vg , - w / 2 , - 1080.0f / 2 ) ;
nvgTranslate ( s - > vg , - w / 2 , - 1080.0f / 2 ) ;
nvgScale ( s - > vg , 2.0 , 2.0 ) ;
nvgScale ( s - > vg , 2.0 , 2.0 ) ;
@ -387,8 +381,8 @@ 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 = ( s - > scene . ui_viz_r x + ( bdr_s * 2 ) ) ;
int viz_maxspeed_x = s - > scene . viz_rect . x + ( bdr_s * 2 ) ;
int viz_maxspeed_y = ( box_y + ( bdr_s * 1.5 ) ) ;
int viz_maxspeed_y = s - > scene . viz_rect . y + ( bdr_s * 1.5 ) ;
int viz_maxspeed_xo = 180 ;
int viz_maxspeed_xo = 180 ;
viz_maxspeed_xo = 0 ;
viz_maxspeed_xo = 0 ;
@ -413,29 +407,29 @@ static void ui_draw_vision_maxspeed(UIState *s) {
}
}
static void ui_draw_vision_speed ( UIState * s ) {
static void ui_draw_vision_speed ( UIState * s ) {
const UIScene * scene = & s - > scene ;
const Rect & viz_rect = s - > scene . viz_rect ;
float v_ego = s - > scene . controls_state . getVEgo ( ) ;
float v_ego = s - > scene . controls_state . getVEgo ( ) ;
float speed = v_ego * 2.2369363 + 0.5 ;
float speed = v_ego * 2.2369363 + 0.5 ;
if ( s - > is_metric ) {
if ( s - > is_metric ) {
speed = v_ego * 3.6 + 0.5 ;
speed = v_ego * 3.6 + 0.5 ;
}
}
const int viz_speed_w = 280 ;
const int viz_speed_w = 280 ;
const int viz_speed_x = scene - > ui_viz_rx + ( ( scene - > ui_viz_rw / 2 ) - ( viz_speed_w / 2 ) ) ;
const int viz_speed_x = viz_rect . centerX ( ) - 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 , viz_rect . y , viz_speed_w , header_h ) ;
nvgTextAlign ( s - > vg , NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE ) ;
nvgTextAlign ( s - > vg , NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE ) ;
snprintf ( speed_str , sizeof ( speed_str ) , " %d " , ( int ) speed ) ;
snprintf ( speed_str , sizeof ( speed_str ) , " %d " , ( int ) speed ) ;
ui_draw_text ( s - > vg , viz_speed_x + viz_speed_w / 2 , 240 , speed_str , 96 * 2.5 , COLOR_WHITE , s - > font_sans_bold ) ;
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_speed_x + viz_speed_w / 2 , 320 , s - > is_metric ? " km/h " : " mph " , 36 * 2.5 , COLOR_WHITE_ALPHA ( 200 ) , s - > font_sans_regular ) ;
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 ) ;
}
}
static void ui_draw_vision_event ( UIState * s ) {
static void ui_draw_vision_event ( UIState * s ) {
const int viz_event_w = 220 ;
const int viz_event_w = 220 ;
const int viz_event_x = ( ( s - > scene . ui_viz_rx + s - > scene . ui_viz_rw ) - ( viz_event_w + ( bdr_s * 2 ) ) ) ;
const int viz_event_x = s - > scene . viz_rect . right ( ) - ( viz_event_w + bdr_s * 2 ) ;
const int viz_event_y = ( box_y + ( bdr_s * 1.5 ) ) ;
const int viz_event_y = s - > scene . viz_rect . y + ( bdr_s * 1.5 ) ;
if ( s - > scene . controls_state . getDecelForModel ( ) & & s - > scene . controls_state . getEnabled ( ) ) {
if ( s - > scene . controls_state . getDecelForModel ( ) & & s - > scene . controls_state . getEnabled ( ) ) {
// draw winding road sign
// draw winding road sign
const int img_turn_size = 160 * 1.5 ;
const int img_turn_size = 160 * 1.5 ;
@ -462,17 +456,21 @@ static void ui_draw_vision_event(UIState *s) {
static void ui_draw_vision_face ( UIState * s ) {
static void ui_draw_vision_face ( UIState * s ) {
const int face_size = 96 ;
const int face_size = 96 ;
const int face_x = ( s - > scene . ui_ viz_rx + face_size + ( bdr_s * 2 ) ) ;
const int face_x = ( s - > scene . viz_rect . x + face_size + ( bdr_s * 2 ) ) ;
const int face_y = ( footer_y + ( ( footer_h - face_size ) / 2 ) ) ;
const int face_y = ( s - > scene . viz_rect . bottom ( ) - footer_h + ( ( footer_h - face_size ) / 2 ) ) ;
ui_draw_circle_image ( s - > vg , face_x , face_y , face_size , s - > img_face , s - > scene . dmonitoring_state . getFaceDetected ( ) ) ;
ui_draw_circle_image ( s - > vg , face_x , face_y , face_size , s - > img_face , s - > scene . dmonitoring_state . getFaceDetected ( ) ) ;
}
}
static void ui_draw_driver_view ( UIState * s ) {
static void ui_draw_driver_view ( UIState * s ) {
const UIScene * scene = & s - > scene ;
const UIScene * scene = & s - > scene ;
s - > scene . uilayout_sidebarcollapsed = true ;
s - > scene . uilayout_sidebarcollapsed = true ;
const int frame_x = scene - > ui_viz_rx ;
const Rect & viz_rect = s - > scene . viz_rect ;
const int frame_w = scene - > ui_viz_rw ;
const int ff_xoffset = 32 ;
const int valid_frame_w = 4 * box_h / 3 ;
const int frame_x = viz_rect . x ;
const int frame_w = viz_rect . w ;
const int valid_frame_w = 4 * viz_rect . h / 3 ;
const int box_y = viz_rect . y ;
const int box_h = viz_rect . h ;
const int valid_frame_x = frame_x + ( frame_w - valid_frame_w ) / 2 + ff_xoffset ;
const int valid_frame_x = frame_x + ( frame_w - valid_frame_w ) / 2 + ff_xoffset ;
// blackout
// blackout
@ -517,16 +515,13 @@ static void ui_draw_driver_view(UIState *s) {
}
}
static void ui_draw_vision_header ( UIState * s ) {
static void ui_draw_vision_header ( UIState * s ) {
const UIScene * scene = & s - > scene ;
const Rect & viz_rect = s - > scene . viz_rect ;
int ui_viz_rx = scene - > ui_viz_rx ;
NVGpaint gradient = nvgLinearGradient ( s - > vg , viz_rect . x ,
int ui_viz_rw = scene - > ui_viz_rw ;
viz_rect . y + ( header_h - ( header_h / 2.5 ) ) ,
viz_rect . x , viz_rect . y + header_h ,
NVGpaint gradient = nvgLinearGradient ( s - > vg , ui_viz_rx ,
( 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 ) ) ;
nvgRGBAf ( 0 , 0 , 0 , 0.45 ) , nvgRGBAf ( 0 , 0 , 0 , 0 ) ) ;
ui_draw_rect ( s - > vg , ui_viz_rx , box_y , ui_viz_r w, header_h , gradient ) ;
ui_draw_rect ( s - > vg , viz_rect . x , viz_rect . y , viz_rect . w , header_h , gradient ) ;
ui_draw_vision_maxspeed ( s ) ;
ui_draw_vision_maxspeed ( s ) ;
ui_draw_vision_speed ( s ) ;
ui_draw_vision_speed ( s ) ;
@ -543,7 +538,7 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size,
{ cereal : : ControlsState : : AlertSize : : NONE , 0 } ,
{ cereal : : ControlsState : : AlertSize : : NONE , 0 } ,
{ cereal : : ControlsState : : AlertSize : : SMALL , 241 } ,
{ cereal : : ControlsState : : AlertSize : : SMALL , 241 } ,
{ cereal : : ControlsState : : AlertSize : : MID , 390 } ,
{ cereal : : ControlsState : : AlertSize : : MID , 390 } ,
{ cereal : : ControlsState : : AlertSize : : FULL , vwp _h} } ;
{ cereal : : ControlsState : : AlertSize : : FULL , s - > fb _h} } ;
const UIScene * scene = & s - > scene ;
const UIScene * scene = & s - > scene ;
bool longAlert1 = strlen ( va_text1 ) > 15 ;
bool longAlert1 = strlen ( va_text1 ) > 15 ;
@ -551,10 +546,10 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size,
const uint8_t * color = alert_colors [ va_color ] ;
const uint8_t * color = alert_colors [ va_color ] ;
int alr_s = alert_size_map [ va_size ] ;
int alr_s = alert_size_map [ va_size ] ;
const int alr_x = scene - > ui_ viz_rx - bdr_s ;
const int alr_x = scene - > viz_rect . x - bdr_s ;
const int alr_w = scene - > ui_ viz_rw + ( bdr_s * 2 ) ;
const int alr_w = scene - > viz_rect . w + ( bdr_s * 2 ) ;
const int alr_h = alr_s + ( va_size = = cereal : : ControlsState : : AlertSize : : NONE ? 0 : bdr_s ) ;
const int alr_h = alr_s + ( va_size = = cereal : : ControlsState : : AlertSize : : NONE ? 0 : bdr_s ) ;
const int alr_y = vwp _h- alr_h ;
const int alr_y = s - > fb _h- alr_h ;
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 ) ) ) ;
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 ) ) ) ;
@ -584,21 +579,20 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size,
static void ui_draw_vision ( UIState * s ) {
static void ui_draw_vision ( UIState * s ) {
const UIScene * scene = & s - > scene ;
const UIScene * scene = & s - > scene ;
const Rect & viz_rect = scene - > viz_rect ;
// Draw video frames
// Draw video frames
glEnable ( GL_SCISSOR_TEST ) ;
glEnable ( GL_SCISSOR_TEST ) ;
glViewport ( scene - > ui_viz_r x+ scene - > ui_viz_ro , s - > fb_h - ( box_y + box_h ) , viz_w , box_ h) ;
glViewport ( viz_rect . x + scene - > ui_viz_ro , viz_rect . y , s - > fb_w - bdr_s * 2 , viz_rect . h ) ;
glScissor ( scene - > ui_viz_rx , s - > fb_h - ( box_y + box_h ) , scene - > ui_viz_rw , box_ h) ;
glScissor ( viz_rect . x , viz_rect . y , viz_rect . w , viz_rect . h ) ;
draw_frame ( s ) ;
draw_frame ( s ) ;
glDisable ( GL_SCISSOR_TEST ) ;
glDisable ( GL_SCISSOR_TEST ) ;
glViewport ( 0 , 0 , s - > fb_w , s - > fb_h ) ;
glViewport ( 0 , 0 , s - > fb_w , s - > fb_h ) ;
// Draw augmented elements
// Draw augmented elements
if ( ! scene - > frontview ) {
if ( ! scene - > frontview & & scene - > world_objects_visible ) {
ui_draw_world ( s ) ;
ui_draw_world ( s ) ;
}
}
// Set Speed, Current Speed, Status/Events
// Set Speed, Current Speed, Status/Events
if ( ! scene - > frontview ) {
if ( ! scene - > frontview ) {
ui_draw_vision_header ( s ) ;
ui_draw_vision_header ( s ) ;
@ -621,10 +615,13 @@ static void ui_draw_background(UIState *s) {
}
}
void ui_draw ( UIState * s ) {
void ui_draw ( UIState * s ) {
const bool hasSidebar = ! s - > scene . uilayout_sidebarcollapsed ;
s - > scene . viz_rect = Rect { bdr_s * 3 , bdr_s , s - > fb_w - 4 * bdr_s , s - > fb_h - 2 * bdr_s } ;
s - > scene . ui_viz_rx = hasSidebar ? box_x : ( box_x - sbr_w + ( bdr_s * 2 ) ) ;
s - > scene . ui_viz_ro = 0 ;
s - > scene . ui_viz_rw = hasSidebar ? box_w : ( box_w + sbr_w - ( bdr_s * 2 ) ) ;
if ( ! s - > scene . uilayout_sidebarcollapsed ) {
s - > scene . ui_viz_ro = hasSidebar ? - ( sbr_w - 6 * bdr_s ) : 0 ;
s - > scene . viz_rect . x = sbr_w + bdr_s ;
s - > scene . viz_rect . w = s - > fb_w - s - > scene . viz_rect . x - bdr_s ;
s - > scene . ui_viz_ro = - ( sbr_w - 6 * bdr_s ) ;
}
ui_draw_background ( s ) ;
ui_draw_background ( s ) ;
glEnable ( GL_BLEND ) ;
glEnable ( GL_BLEND ) ;
@ -704,14 +701,6 @@ static const mat4 device_transform = {{
0.0 , 0.0 , 0.0 , 1.0 ,
0.0 , 0.0 , 0.0 , 1.0 ,
} } ;
} } ;
// frame from 4/3 to box size with a 2x zoom
static const mat4 frame_transform = { {
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 ,
} } ;
// frame from 4/3 to 16/9 display
// frame from 4/3 to 16/9 display
static const mat4 full_to_wide_frame_transform = { {
static const mat4 full_to_wide_frame_transform = { {
.75 , 0.0 , 0.0 , 0.0 ,
.75 , 0.0 , 0.0 , 0.0 ,
@ -816,6 +805,14 @@ void ui_nvg_init(UIState *s) {
glBindVertexArray ( 0 ) ;
glBindVertexArray ( 0 ) ;
}
}
// frame from 4/3 to box size with a 2x zoom
const mat4 frame_transform = { {
( float ) ( 2 * ( 4. / 3. ) / ( ( float ) ( s - > fb_w - ( bdr_s * 2 ) ) / ( s - > fb_h - ( bdr_s * 2 ) ) ) ) , 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 ,
} } ;
s - > front_frame_mat = matmul ( device_transform , full_to_wide_frame_transform ) ;
s - > front_frame_mat = matmul ( device_transform , full_to_wide_frame_transform ) ;
s - > rear_frame_mat = matmul ( device_transform , frame_transform ) ;
s - > rear_frame_mat = matmul ( device_transform , frame_transform ) ;