Skip to content

Commit 1d35ab5

Browse files
committed
Preserve hidden window startup & validate font IDs
1 parent 2b3cc48 commit 1d35ab5

6 files changed

Lines changed: 237 additions & 113 deletions

File tree

demo/demo.cpp

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,47 @@ static void load_demo_fonts()
484484
demo_grid3_font = load_demo_font( &cache, "fonts/Bitter-Regular.ttf", buffer5, 44.0f );
485485
}
486486

487+
static ve_font_id pick_first_available_demo_font( std::initializer_list< ve_font_id > ids )
488+
{
489+
for ( ve_font_id id : ids ) {
490+
if ( id >= 0 ) {
491+
return id;
492+
}
493+
}
494+
return static_cast< ve_font_id >( -1 );
495+
}
496+
497+
static void normalize_demo_font_ids( ve_font_id* huge_font = nullptr )
498+
{
499+
print_font = pick_first_available_demo_font( { print_font, title_font, small_font, mono_font, demo_serif_font, demo_mono_font, demo_grid3_font } );
500+
title_font = pick_first_available_demo_font( { title_font, print_font, mono_font, demo_serif_font } );
501+
mono_font = pick_first_available_demo_font( { mono_font, print_font, title_font } );
502+
small_font = pick_first_available_demo_font( { small_font, print_font, title_font, mono_font } );
503+
logo_font = pick_first_available_demo_font( { logo_font, title_font, print_font } );
504+
demo_sans_font = pick_first_available_demo_font( { demo_sans_font, print_font, title_font } );
505+
demo_serif_font = pick_first_available_demo_font( { demo_serif_font, print_font, title_font } );
506+
demo_script_font = pick_first_available_demo_font( { demo_script_font, demo_serif_font, demo_sans_font, print_font } );
507+
demo_mono_font = pick_first_available_demo_font( { demo_mono_font, mono_font, print_font } );
508+
demo_chinese_font = pick_first_available_demo_font( { demo_chinese_font, demo_japanese_font, demo_grid2_font, print_font } );
509+
demo_japanese_font = pick_first_available_demo_font( { demo_japanese_font, demo_chinese_font, demo_grid2_font, print_font } );
510+
demo_korean_font = pick_first_available_demo_font( { demo_korean_font, demo_chinese_font, demo_japanese_font, print_font } );
511+
demo_thai_font = pick_first_available_demo_font( { demo_thai_font, demo_sans_font, print_font } );
512+
demo_arabic_font = pick_first_available_demo_font( { demo_arabic_font, print_font } );
513+
demo_hebrew_font = pick_first_available_demo_font( { demo_hebrew_font, print_font } );
514+
demo_raincode_font = pick_first_available_demo_font( { demo_raincode_font, demo_mono_font, print_font } );
515+
demo_grid2_font = pick_first_available_demo_font( { demo_grid2_font, demo_chinese_font, demo_japanese_font, print_font } );
516+
demo_grid3_font = pick_first_available_demo_font( { demo_grid3_font, demo_serif_font, print_font } );
517+
if ( huge_font != nullptr && *huge_font < 0 ) {
518+
*huge_font = print_font;
519+
}
520+
}
521+
487522
void init_demo()
488523
{
489524
ve_fontcache_init( &cache );
490525
ve_fontcache_configure_snap( &cache, window_size.width, window_size.height );
491526
load_demo_fonts();
527+
normalize_demo_font_ids();
492528
}
493529

494530
void render_demo( TinyWindow::tWindow* window, float dT )
@@ -1071,15 +1107,6 @@ static int run_backend_test_mode()
10711107
int total_skipped = 0;
10721108

10731109
const auto run_mode = [&]( const char* mode_name, bool use_freetype ) {
1074-
auto pick_first_available = []( std::initializer_list< ve_font_id > ids ) {
1075-
for ( ve_font_id id : ids ) {
1076-
if ( id >= 0 ) {
1077-
return id;
1078-
}
1079-
}
1080-
return static_cast< ve_font_id >( -1 );
1081-
};
1082-
10831110
cache = ve_fontcache();
10841111
ve_fontcache_init( &cache, use_freetype );
10851112
ve_fontcache_configure_snap( &cache, window_size.width, window_size.height );
@@ -1108,23 +1135,14 @@ static int run_backend_test_mode()
11081135
logo_font = load_demo_font( &cache, "fonts/OpenSans-Regular.ttf", fallback_logo_buffer, 72.0f );
11091136
}
11101137
};
1111-
const auto normalize_font_ids = [&]( ve_font_id& huge_font ) {
1112-
print_font = pick_first_available( { print_font, title_font, small_font, mono_font, demo_serif_font, demo_mono_font, demo_grid3_font } );
1113-
title_font = pick_first_available( { title_font, print_font, mono_font, demo_serif_font } );
1114-
small_font = pick_first_available( { small_font, print_font, title_font } );
1115-
logo_font = pick_first_available( { logo_font, title_font, print_font } );
1116-
if ( huge_font < 0 ) {
1117-
huge_font = print_font;
1118-
}
1119-
};
11201138
if ( !use_freetype ) {
11211139
apply_font_fallbacks();
11221140
}
11231141
ve_font_id huge_test_font = load_demo_font( &cache, "fonts/NotoSansJP-Light.otf", huge_buffer, 200.0f );
11241142
if ( huge_test_font < 0 && !use_freetype ) {
11251143
huge_test_font = load_demo_font( &cache, "fonts/OpenSans-Regular.ttf", huge_buffer, 200.0f );
11261144
}
1127-
normalize_font_ids( huge_test_font );
1145+
normalize_demo_font_ids( &huge_test_font );
11281146

11291147
bool fonts_ready =
11301148
print_font >= 0
@@ -1180,7 +1198,7 @@ static int run_backend_test_mode()
11801198
apply_font_fallbacks();
11811199
}
11821200
ve_font_id refreshed_huge_font = -1;
1183-
normalize_font_ids( refreshed_huge_font );
1201+
normalize_demo_font_ids( &refreshed_huge_font );
11841202
clear_backend_test_surfaces( true );
11851203
};
11861204

demo/demo_dx11.cpp

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,11 +1166,47 @@ static void load_demo_fonts()
11661166
demo_grid3_font = load_demo_font( &cache, "fonts/Bitter-Regular.ttf", buffer5, 44.0f );
11671167
}
11681168

1169+
static ve_font_id pick_first_available_demo_font( std::initializer_list< ve_font_id > ids )
1170+
{
1171+
for ( ve_font_id id : ids ) {
1172+
if ( id >= 0 ) {
1173+
return id;
1174+
}
1175+
}
1176+
return static_cast< ve_font_id >( -1 );
1177+
}
1178+
1179+
static void normalize_demo_font_ids( ve_font_id* huge_font = nullptr )
1180+
{
1181+
print_font = pick_first_available_demo_font( { print_font, title_font, small_font, mono_font, demo_serif_font, demo_mono_font, demo_grid3_font } );
1182+
title_font = pick_first_available_demo_font( { title_font, print_font, mono_font, demo_serif_font } );
1183+
mono_font = pick_first_available_demo_font( { mono_font, print_font, title_font } );
1184+
small_font = pick_first_available_demo_font( { small_font, print_font, title_font, mono_font } );
1185+
logo_font = pick_first_available_demo_font( { logo_font, title_font, print_font } );
1186+
demo_sans_font = pick_first_available_demo_font( { demo_sans_font, print_font, title_font } );
1187+
demo_serif_font = pick_first_available_demo_font( { demo_serif_font, print_font, title_font } );
1188+
demo_script_font = pick_first_available_demo_font( { demo_script_font, demo_serif_font, demo_sans_font, print_font } );
1189+
demo_mono_font = pick_first_available_demo_font( { demo_mono_font, mono_font, print_font } );
1190+
demo_chinese_font = pick_first_available_demo_font( { demo_chinese_font, demo_japanese_font, demo_grid2_font, print_font } );
1191+
demo_japanese_font = pick_first_available_demo_font( { demo_japanese_font, demo_chinese_font, demo_grid2_font, print_font } );
1192+
demo_korean_font = pick_first_available_demo_font( { demo_korean_font, demo_chinese_font, demo_japanese_font, print_font } );
1193+
demo_thai_font = pick_first_available_demo_font( { demo_thai_font, demo_sans_font, print_font } );
1194+
demo_arabic_font = pick_first_available_demo_font( { demo_arabic_font, print_font } );
1195+
demo_hebrew_font = pick_first_available_demo_font( { demo_hebrew_font, print_font } );
1196+
demo_raincode_font = pick_first_available_demo_font( { demo_raincode_font, demo_mono_font, print_font } );
1197+
demo_grid2_font = pick_first_available_demo_font( { demo_grid2_font, demo_chinese_font, demo_japanese_font, print_font } );
1198+
demo_grid3_font = pick_first_available_demo_font( { demo_grid3_font, demo_serif_font, print_font } );
1199+
if ( huge_font != nullptr && *huge_font < 0 ) {
1200+
*huge_font = print_font;
1201+
}
1202+
}
1203+
11691204
void init_demo()
11701205
{
11711206
ve_fontcache_init( &cache );
11721207
ve_fontcache_configure_snap( &cache, window_size.width, window_size.height );
11731208
load_demo_fonts();
1209+
normalize_demo_font_ids();
11741210
}
11751211

11761212
void render_demo( float dT )
@@ -1707,15 +1743,6 @@ static int run_backend_test_mode()
17071743
int total_skipped = 0;
17081744

17091745
const auto run_mode = [&]( const char* mode_name, bool use_freetype ) {
1710-
auto pick_first_available = []( std::initializer_list< ve_font_id > ids ) {
1711-
for ( ve_font_id id : ids ) {
1712-
if ( id >= 0 ) {
1713-
return id;
1714-
}
1715-
}
1716-
return static_cast< ve_font_id >( -1 );
1717-
};
1718-
17191746
cache = ve_fontcache();
17201747
ve_fontcache_init( &cache, use_freetype );
17211748
ve_fontcache_configure_snap( &cache, window_size.width, window_size.height );
@@ -1744,23 +1771,14 @@ static int run_backend_test_mode()
17441771
logo_font = load_demo_font( &cache, "fonts/OpenSans-Regular.ttf", fallback_logo_buffer, 72.0f );
17451772
}
17461773
};
1747-
const auto normalize_font_ids = [&]( ve_font_id& huge_font ) {
1748-
print_font = pick_first_available( { print_font, title_font, small_font, mono_font, demo_serif_font, demo_mono_font, demo_grid3_font } );
1749-
title_font = pick_first_available( { title_font, print_font, mono_font, demo_serif_font } );
1750-
small_font = pick_first_available( { small_font, print_font, title_font } );
1751-
logo_font = pick_first_available( { logo_font, title_font, print_font } );
1752-
if ( huge_font < 0 ) {
1753-
huge_font = print_font;
1754-
}
1755-
};
17561774
if ( !use_freetype ) {
17571775
apply_font_fallbacks();
17581776
}
17591777
ve_font_id huge_test_font = load_demo_font( &cache, "fonts/NotoSansJP-Light.otf", huge_buffer, 200.0f );
17601778
if ( huge_test_font < 0 && !use_freetype ) {
17611779
huge_test_font = load_demo_font( &cache, "fonts/OpenSans-Regular.ttf", huge_buffer, 200.0f );
17621780
}
1763-
normalize_font_ids( huge_test_font );
1781+
normalize_demo_font_ids( &huge_test_font );
17641782

17651783
bool fonts_ready =
17661784
print_font >= 0
@@ -1816,7 +1834,7 @@ static int run_backend_test_mode()
18161834
apply_font_fallbacks();
18171835
}
18181836
ve_font_id refreshed_huge_font = -1;
1819-
normalize_font_ids( refreshed_huge_font );
1837+
normalize_demo_font_ids( &refreshed_huge_font );
18201838
clear_backend_test_surfaces( true );
18211839
};
18221840

demo/demo_vrhi.cpp

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,11 +1237,47 @@ static void load_demo_fonts()
12371237
demo_grid3_font = load_demo_font( &cache, "fonts/Bitter-Regular.ttf", buffer5, 44.0f );
12381238
}
12391239

1240+
static ve_font_id pick_first_available_demo_font( std::initializer_list< ve_font_id > ids )
1241+
{
1242+
for ( ve_font_id id : ids ) {
1243+
if ( id >= 0 ) {
1244+
return id;
1245+
}
1246+
}
1247+
return static_cast< ve_font_id >( -1 );
1248+
}
1249+
1250+
static void normalize_demo_font_ids( ve_font_id* huge_font = nullptr )
1251+
{
1252+
print_font = pick_first_available_demo_font( { print_font, title_font, small_font, mono_font, demo_serif_font, demo_mono_font, demo_grid3_font } );
1253+
title_font = pick_first_available_demo_font( { title_font, print_font, mono_font, demo_serif_font } );
1254+
mono_font = pick_first_available_demo_font( { mono_font, print_font, title_font } );
1255+
small_font = pick_first_available_demo_font( { small_font, print_font, title_font, mono_font } );
1256+
logo_font = pick_first_available_demo_font( { logo_font, title_font, print_font } );
1257+
demo_sans_font = pick_first_available_demo_font( { demo_sans_font, print_font, title_font } );
1258+
demo_serif_font = pick_first_available_demo_font( { demo_serif_font, print_font, title_font } );
1259+
demo_script_font = pick_first_available_demo_font( { demo_script_font, demo_serif_font, demo_sans_font, print_font } );
1260+
demo_mono_font = pick_first_available_demo_font( { demo_mono_font, mono_font, print_font } );
1261+
demo_chinese_font = pick_first_available_demo_font( { demo_chinese_font, demo_japanese_font, demo_grid2_font, print_font } );
1262+
demo_japanese_font = pick_first_available_demo_font( { demo_japanese_font, demo_chinese_font, demo_grid2_font, print_font } );
1263+
demo_korean_font = pick_first_available_demo_font( { demo_korean_font, demo_chinese_font, demo_japanese_font, print_font } );
1264+
demo_thai_font = pick_first_available_demo_font( { demo_thai_font, demo_sans_font, print_font } );
1265+
demo_arabic_font = pick_first_available_demo_font( { demo_arabic_font, print_font } );
1266+
demo_hebrew_font = pick_first_available_demo_font( { demo_hebrew_font, print_font } );
1267+
demo_raincode_font = pick_first_available_demo_font( { demo_raincode_font, demo_mono_font, print_font } );
1268+
demo_grid2_font = pick_first_available_demo_font( { demo_grid2_font, demo_chinese_font, demo_japanese_font, print_font } );
1269+
demo_grid3_font = pick_first_available_demo_font( { demo_grid3_font, demo_serif_font, print_font } );
1270+
if ( huge_font != nullptr && *huge_font < 0 ) {
1271+
*huge_font = print_font;
1272+
}
1273+
}
1274+
12401275
void init_demo()
12411276
{
1242-
ve_fontcache_init( &cache );
1243-
ve_fontcache_configure_snap( &cache, window_size.width, window_size.height );
1244-
load_demo_fonts();
1277+
ve_fontcache_init( &cache );
1278+
ve_fontcache_configure_snap( &cache, window_size.width, window_size.height );
1279+
load_demo_fonts();
1280+
normalize_demo_font_ids();
12451281
}
12461282

12471283
void render_demo( float dT )
@@ -1789,15 +1825,6 @@ static int run_backend_test_mode()
17891825
int total_skipped = 0;
17901826

17911827
const auto run_mode = [&]( const char* mode_name, bool use_freetype ) {
1792-
auto pick_first_available = []( std::initializer_list< ve_font_id > ids ) {
1793-
for ( ve_font_id id : ids ) {
1794-
if ( id >= 0 ) {
1795-
return id;
1796-
}
1797-
}
1798-
return static_cast< ve_font_id >( -1 );
1799-
};
1800-
18011828
cache = ve_fontcache();
18021829
ve_fontcache_init( &cache, use_freetype );
18031830
ve_fontcache_configure_snap( &cache, window_size.width, window_size.height );
@@ -1826,23 +1853,14 @@ static int run_backend_test_mode()
18261853
logo_font = load_demo_font( &cache, "fonts/OpenSans-Regular.ttf", fallback_logo_buffer, 72.0f );
18271854
}
18281855
};
1829-
const auto normalize_font_ids = [&]( ve_font_id& huge_font ) {
1830-
print_font = pick_first_available( { print_font, title_font, small_font, mono_font, demo_serif_font, demo_mono_font, demo_grid3_font } );
1831-
title_font = pick_first_available( { title_font, print_font, mono_font, demo_serif_font } );
1832-
small_font = pick_first_available( { small_font, print_font, title_font } );
1833-
logo_font = pick_first_available( { logo_font, title_font, print_font } );
1834-
if ( huge_font < 0 ) {
1835-
huge_font = print_font;
1836-
}
1837-
};
18381856
if ( !use_freetype ) {
18391857
apply_font_fallbacks();
18401858
}
18411859
ve_font_id huge_test_font = load_demo_font( &cache, "fonts/NotoSansJP-Light.otf", huge_buffer, 200.0f );
18421860
if ( huge_test_font < 0 && !use_freetype ) {
18431861
huge_test_font = load_demo_font( &cache, "fonts/OpenSans-Regular.ttf", huge_buffer, 200.0f );
18441862
}
1845-
normalize_font_ids( huge_test_font );
1863+
normalize_demo_font_ids( &huge_test_font );
18461864

18471865
bool fonts_ready =
18481866
print_font >= 0
@@ -1898,7 +1916,7 @@ static int run_backend_test_mode()
18981916
apply_font_fallbacks();
18991917
}
19001918
ve_font_id refreshed_huge_font = -1;
1901-
normalize_font_ids( refreshed_huge_font );
1919+
normalize_demo_font_ids( &refreshed_huge_font );
19021920
clear_backend_test_surfaces( true );
19031921
};
19041922

0 commit comments

Comments
 (0)