From: hgn Date: Sun, 14 Apr 2024 23:06:56 +0000 (+0100) Subject: update font to include australia title. Update other glyph mappings X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=cc5c184b1264d2e33398c1a4c03e75fb42ca04f5 update font to include australia title. Update other glyph mappings --- diff --git a/src/fonts/vg_font_thin_3.png b/src/fonts/vg_font_thin_3.png index 1989a44..ad1f1f4 100644 Binary files a/src/fonts/vg_font_thin_3.png and b/src/fonts/vg_font_thin_3.png differ diff --git a/src/fonts/vg_font_thin_3.xcf b/src/fonts/vg_font_thin_3.xcf index 8275f06..20f4098 100644 Binary files a/src/fonts/vg_font_thin_3.xcf and b/src/fonts/vg_font_thin_3.xcf differ diff --git a/vg_build_font.h b/vg_build_font.h index 5f0fd3b..5278ca1 100644 --- a/vg_build_font.h +++ b/vg_build_font.h @@ -6,10 +6,13 @@ void vg_build_font_face_run( vg_font_face *face, char first, char last, i16 x, i16 y ) { - u32 count = (u32)last - (u32)first; + u32 uf = *((u8 *)&first), + ul = *((u8 *)&last); + + u32 count = ul - uf; for( u32 i=0; i<=count; i ++ ) { - u32 index = (u32)first + i; + u32 index = uf + i; face->map[index].x = x+(i*face->cw); face->map[index].y = y; } @@ -107,6 +110,7 @@ void vg_build_default_font(void) vg_build_font_face_run( &small, 'A', 'Z', 0, 14 ); vg_build_font_face_run( &small, 'a', 'z', 0, 28 ); vg_build_font_face_run( &small, '0', '9', 208,14 ); + vg_build_font_face_run( &small, 0x7f, 0xa4, 0,42 ); vg_build_write_font_face( fp, &small ); vg_font_face large = @@ -123,13 +127,14 @@ void vg_build_default_font(void) vg_build_font_face_run( &large, 'A', 'Z', 0, 77 ); vg_build_font_face_run( &large, 'a', 'z', 0, 98 ); vg_build_font_face_run( &large, '0', '9', 312,77 ); + vg_build_font_face_run( &large, 0x7f, 0xa4, 0,119 ); vg_build_write_font_face( fp, &large ); vg_font_face title = { .name = "vgf_default_title", .cw=24, .ch=42, - .sx=24, .sy=42, + .sx=20, .sy=42, .baseline=12, }; vg_build_font_face_run( &title, '!', '/', 24, 140 ); @@ -142,6 +147,11 @@ void vg_build_default_font(void) vg_build_font_face_run( &title, 'a', 'u', 0, 266 ); vg_build_font_face_run( &title, 'v', 'z', 0, 350 ); vg_build_font_face_run( &title, '0', '9', 120,308 ); + vg_build_font_face_run( &title, 0x89, 0x8c, 409,182 ); + vg_build_font_face_run( &title, 0x8d, 0x92, 360,308 ); + vg_build_font_face_run( &title, 0x7f, 0x88, 120,350 ); + vg_build_font_face_run( &title, 0x93, 0x98, 360,350 ); + vg_build_font_face_run( &title, 0x99, 0xa4, 0,392 ); vg_build_write_font_face( fp, &title ); fclose( fp ); diff --git a/vg_imgui.c b/vg_imgui.c index a4af9ae..51792ff 100644 --- a/vg_imgui.c +++ b/vg_imgui.c @@ -430,17 +430,20 @@ void ui_flush( enum ui_shader shader, f32 w, f32 h ){ vg_ui.vert_start = vg_ui.cur_vert; } -void ui_fill_rect( ui_rect rect, u32 colour, ui_px uv[4] ) +struct ui_vert *ui_fill_rect( ui_rect rect, u32 colour, ui_px uv[4] ) { /* this if far from ideal but stops us from crashing */ if( (vg_ui.cur_vert + 4 > vg_ui.max_verts) || (vg_ui.cur_indice + 6 > vg_ui.max_indices)) - return; + { + return &vg_ui.vertex_buffer[0]; + } struct ui_vert *vertices = &vg_ui.vertex_buffer[ vg_ui.cur_vert ]; u16 *indices = &vg_ui.indice_buffer[ vg_ui.cur_indice ]; - for( int i=0; i<4; i++ ){ + for( int i=0; i<4; i++ ) + { vertices[i].colour = colour; } @@ -465,17 +468,20 @@ void ui_fill_rect( ui_rect rect, u32 colour, ui_px uv[4] ) u16 start = vg_ui.cur_vert; u32 mesh[] = { 0,2,1, 0,3,2 }; - for( u32 i=0; isx*scale*4; @@ -907,10 +928,10 @@ u32 ui_ntext( ui_rect rect, const char *str, u32 len, ui_px scale, return printed_chars; } -void ui_text( ui_rect rect, const char *str, ui_px scale, - enum ui_align align, u32 colour ) +u32 ui_text( ui_rect rect, const char *str, ui_px scale, + enum ui_align align, u32 colour ) { - ui_ntext( rect, str, 1024, scale, align, colour ); + return ui_ntext( rect, str, 1024, scale, align, colour ); } void ui_font_face( vg_font_face *ff ) diff --git a/vg_imgui.h b/vg_imgui.h index 955f365..82468e3 100644 --- a/vg_imgui.h +++ b/vg_imgui.h @@ -220,8 +220,8 @@ enum ui_button_state { void vg_ui_init(void); void rect_copy( ui_rect a, ui_rect b ); void ui_flush( enum ui_shader shader, f32 w, f32 h ); -void ui_fill_rect( ui_rect rect, u32 colour, ui_px uv[4] ); -void ui_fill( ui_rect rect, u32 colour ); +struct ui_vert *ui_fill_rect( ui_rect rect, u32 colour, ui_px uv[4] ); +struct ui_vert *ui_fill( ui_rect rect, u32 colour ); void ui_outline( ui_rect rect, ui_px thickness, u32 colour, u32 mask ); void ui_split( ui_rect rect, enum ui_axis other, ui_px width, ui_px gap, ui_rect l, ui_rect r ); @@ -253,8 +253,8 @@ u32 ui_opacity( u32 colour, f32 opacity ); void ui_font_face( vg_font_face *ff ); u32 ui_ntext( ui_rect rect, const char *str, u32 len, ui_px scale, enum ui_align align, u32 colour ); -void ui_text( ui_rect rect, const char *str, ui_px scale, - enum ui_align align, u32 colour ); +u32 ui_text( ui_rect rect, const char *str, ui_px scale, + enum ui_align align, u32 colour ); void ui_panel( ui_rect in_rect, ui_rect out_panel ); void ui_label( ui_rect rect, const char *text, ui_px size, ui_px gap, ui_rect r ); diff --git a/vg_input.c b/vg_input.c index 3c138d0..74732f4 100644 --- a/vg_input.c +++ b/vg_input.c @@ -395,19 +395,19 @@ const char *controller_button_str( SDL_GameControllerButton button ) { static const char *controller_glyphs[ SDL_CONTROLLER_BUTTON_MAX ][2] = { /* xbox/generic playstation */ - [ SDL_CONTROLLER_BUTTON_A ] = { "\x1e\x85","\x1e\x82" }, - [ SDL_CONTROLLER_BUTTON_B ] = { "\x1e\x86","\x1e\x81" }, - [ SDL_CONTROLLER_BUTTON_X ] = { "\x1e\x83","\x1e\x7f" }, - [ SDL_CONTROLLER_BUTTON_Y ] = { "\x1e\x84","\x1e\x80" }, - [ SDL_CONTROLLER_BUTTON_LEFTSTICK ] = { "\x87", "\x87" }, - [ SDL_CONTROLLER_BUTTON_RIGHTSTICK ] = { "\x8b", "\x8b" }, - [ SDL_CONTROLLER_BUTTON_LEFTSHOULDER ] = { "\x91", "\x91" }, - [ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ]= { "\x92", "\x92" }, - [ SDL_CONTROLLER_BUTTON_DPAD_LEFT ] = { "\x1e\x93","\x1e\x93" }, - [ SDL_CONTROLLER_BUTTON_DPAD_UP ] = { "\x1e\x94","\x1e\x94" }, - [ SDL_CONTROLLER_BUTTON_DPAD_RIGHT ] = { "\x1e\x95","\x1e\x95" }, - [ SDL_CONTROLLER_BUTTON_DPAD_DOWN ] = { "\x1e\x96","\x1e\x96" }, - [ SDL_CONTROLLER_BUTTON_GUIDE ] = { "\x91", "\x91" }, + [ SDL_CONTROLLER_BUTTON_A ] = { KGRN "\x06\x02\x85",KBLU "\x06\x02\x82" }, + [ SDL_CONTROLLER_BUTTON_B ] = { KRED "\x06\x02\x86",KRED "\x06\x02\x81" }, + [ SDL_CONTROLLER_BUTTON_X ] = { KBLU "\x06\x02\x83",KMAG "\x06\x02\x7f" }, + [ SDL_CONTROLLER_BUTTON_Y ] = { KYEL "\x06\x02\x84",KGRN "\x06\x02\x80" }, + [ SDL_CONTROLLER_BUTTON_LEFTSTICK ] = { "\x87","\x87" }, + [ SDL_CONTROLLER_BUTTON_RIGHTSTICK ] = { "\x8b","\x8b" }, + [ SDL_CONTROLLER_BUTTON_LEFTSHOULDER ] = { "\x91","\x91" }, + [ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER ]= { "\x92","\x92" }, + [ SDL_CONTROLLER_BUTTON_DPAD_LEFT ] = { "\x93","\x93" }, + [ SDL_CONTROLLER_BUTTON_DPAD_UP ] = { "\x94","\x94" }, + [ SDL_CONTROLLER_BUTTON_DPAD_RIGHT ] = { "\x95","\x95" }, + [ SDL_CONTROLLER_BUTTON_DPAD_DOWN ] = { "\x96","\x96" }, + [ SDL_CONTROLLER_BUTTON_GUIDE ] = { "\x91","\x91" }, }; if( vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS3 || @@ -438,14 +438,7 @@ void vg_keyboard_key_string( vg_str *str, u32 key, int special_glyphs ) { if( (key >= SDLK_a) && (key <= SDLK_z) ){ key = (key-SDLK_a)+(u32)'A'; - - if( special_glyphs ){ - vg_strcatch( str, '\x1f' ); - vg_strcatch( str, key ); - vg_strcatch( str, ' ' ); - } - else - vg_strcatch( str, key ); + vg_strcatch( str, key ); } else if( (key == SDLK_LSHIFT) || (key == SDLK_RSHIFT) ) vg_strcat( str, special_glyphs? "\x9e": "shift" ); @@ -460,13 +453,13 @@ void vg_keyboard_key_string( vg_str *str, u32 key, int special_glyphs ) else if( key == SDLK_ESCAPE ) vg_strcat( str, special_glyphs? "\xa3": "escape" ); else if( key == SDLK_RIGHT ) - vg_strcat( str, special_glyphs? "\x1f\x95 ": "right" ); + vg_strcat( str, special_glyphs? "\x95 ": "right" ); else if( key == SDLK_LEFT ) - vg_strcat( str, special_glyphs? "\x1f\x93 ": "left" ); + vg_strcat( str, special_glyphs? "\x93 ": "left" ); else if( key == SDLK_UP ) - vg_strcat( str, special_glyphs? "\x1f\x94 ": "up" ); + vg_strcat( str, special_glyphs? "\x94 ": "up" ); else if( key == SDLK_DOWN ) - vg_strcat( str, special_glyphs? "\x1f\x96 ": "down" ); + vg_strcat( str, special_glyphs? "\x96 ": "down" ); else { vg_strcat( str, "keyboard key #" ); vg_strcati32( str, key );