@@ -531,6 +531,7 @@ static void keyboard_event_to_angband_key(const SDL_KeyboardEvent *key,
531
531
bool kp_as_mod , keycode_t * ch , uint8_t * mods );
532
532
static void textinput_event_to_angband_key (const SDL_TextInputEvent * key ,
533
533
bool kp_as_mod , keycode_t * ch , uint8_t * mods );
534
+ static void recreate_textures (struct my_app * a , bool all );
534
535
535
536
/* Global variables. */
536
537
@@ -1973,6 +1974,7 @@ static void show_shortcut_editor(struct sdlpui_window *w, int x, int y)
1973
1974
1974
1975
w -> shorte -> ftb = & shortcut_editor_funcs ;
1975
1976
w -> shorte -> pop_callback = hide_shortcut_editor ;
1977
+ w -> shorte -> recreate_textures_callback = NULL ;
1976
1978
w -> shorte -> next = NULL ;
1977
1979
w -> shorte -> prev = NULL ;
1978
1980
w -> shorte -> texture = NULL ;
@@ -2005,13 +2007,45 @@ static void hide_about(struct sdlpui_dialog *d, struct sdlpui_window *w,
2005
2007
}
2006
2008
}
2007
2009
2010
+ static void recreate_about_dialog_textures (struct sdlpui_dialog * d ,
2011
+ struct sdlpui_window * w , bool all )
2012
+ {
2013
+ struct sdlpui_simple_info * psi ;
2014
+ int i ;
2015
+
2016
+ if (!all ) {
2017
+ return ;
2018
+ }
2019
+
2020
+ SDL_assert (d -> type_code == SDLPUI_DIALOG_SIMPLE_INFO );
2021
+ psi = (struct sdlpui_simple_info * )d -> priv ;
2022
+
2023
+ /* Recreate the static texture for the one image in the dialog. */
2024
+ for (i = 0 ; i < psi -> number ; ++ i ) {
2025
+ if (psi -> labels [i ].type_code == SDLPUI_CTRL_IMAGE ) {
2026
+ char path [4096 ];
2027
+ struct sdlpui_image * pi =
2028
+ (struct sdlpui_image * )psi -> labels [i ].priv ;
2029
+
2030
+ if (pi -> image ) {
2031
+ SDL_DestroyTexture (pi -> image );
2032
+ }
2033
+ path_build (path , sizeof (path ), DEFAULT_ABOUT_ICON_DIR ,
2034
+ DEFAULT_ABOUT_ICON );
2035
+ pi -> image = load_image (w , path );
2036
+ break ;
2037
+ }
2038
+ }
2039
+ }
2040
+
2008
2041
static void show_about (struct sdlpui_window * window , int x , int y )
2009
2042
{
2010
2043
if (!window -> infod ) {
2011
2044
char path [4096 ];
2012
2045
SDL_Texture * texture ;
2013
2046
2014
- window -> infod = sdlpui_start_simple_info ("Ok" , NULL , 0 );
2047
+ window -> infod = sdlpui_start_simple_info ("Ok" , NULL ,
2048
+ recreate_about_dialog_textures , 0 );
2015
2049
path_build (path , sizeof (path ), DEFAULT_ABOUT_ICON_DIR ,
2016
2050
DEFAULT_ABOUT_ICON );
2017
2051
texture = load_image (window , path );
@@ -2146,7 +2180,7 @@ static struct sdlpui_dialog *handle_menu_windows(struct sdlpui_control *ctrl,
2146
2180
int ul_x_win , int ul_y_win )
2147
2181
{
2148
2182
struct sdlpui_dialog * result = sdlpui_start_simple_menu (
2149
- dlg , ctrl , MAX_WINDOWS , true, false, NULL , 0 );
2183
+ dlg , ctrl , MAX_WINDOWS , true, false, NULL , NULL , 0 );
2150
2184
unsigned int i ;
2151
2185
2152
2186
for (i = 1 ; i < MAX_WINDOWS ; ++ i ) {
@@ -2332,8 +2366,8 @@ static struct sdlpui_dialog *handle_menu_tile_sizes(struct sdlpui_control *ctrl,
2332
2366
*/
2333
2367
bool disabled = (window -> graphics .id == GRAPHICS_NONE
2334
2368
|| !character_generated || !inkey_flag );
2335
- struct sdlpui_dialog * result =
2336
- sdlpui_start_simple_menu ( dlg , ctrl , 2 , true, false, NULL , 0 );
2369
+ struct sdlpui_dialog * result = sdlpui_start_simple_menu ( dlg , ctrl , 2 ,
2370
+ true, false, NULL , NULL , 0 );
2337
2371
struct sdlpui_control * c ;
2338
2372
2339
2373
c = sdlpui_get_simple_menu_next_unused (result , SDLPUI_MFLG_NONE );
@@ -2365,7 +2399,7 @@ static struct sdlpui_dialog *handle_menu_tile_sets(struct sdlpui_control *ctrl,
2365
2399
*/
2366
2400
bool disabled = !character_generated || !inkey_flag ;
2367
2401
struct sdlpui_dialog * result = sdlpui_start_simple_menu (dlg , ctrl ,
2368
- 0 , true, false, NULL , 0 );
2402
+ 0 , true, false, NULL , NULL , 0 );
2369
2403
graphics_mode * mode = graphics_modes ;
2370
2404
2371
2405
while (mode ) {
@@ -2389,7 +2423,7 @@ static struct sdlpui_dialog *handle_menu_tiles(struct sdlpui_control *ctrl,
2389
2423
int ul_x_win , int ul_y_win )
2390
2424
{
2391
2425
struct sdlpui_dialog * result = sdlpui_start_simple_menu (dlg , ctrl , 2 ,
2392
- true, false, NULL , 0 );
2426
+ true, false, NULL , NULL , 0 );
2393
2427
struct sdlpui_control * c ;
2394
2428
2395
2429
c = sdlpui_get_simple_menu_next_unused (result , SDLPUI_MFLG_NONE );
@@ -2585,7 +2619,8 @@ static struct sdlpui_dialog *handle_menu_font_sizes(
2585
2619
calculate_subwindow_font_size_bounds (subwindow , NULL ,
2586
2620
& subwindow -> min_font_size , & subwindow -> max_font_size );
2587
2621
SDL_assert (subwindow );
2588
- result = sdlpui_start_simple_menu (dlg , ctrl , 2 , true, false, NULL , 0 );
2622
+ result = sdlpui_start_simple_menu (dlg , ctrl , 2 , true, false, NULL ,
2623
+ NULL , 0 );
2589
2624
c = sdlpui_get_simple_menu_next_unused (result , SDLPUI_MFLG_NONE );
2590
2625
sdlpui_create_menu_ranged_int (c , "- %2d points +" , SDLPUI_HOR_LEFT ,
2591
2626
handle_menu_font_size , tag , !is_vector_font
@@ -2647,7 +2682,7 @@ static struct sdlpui_dialog *handle_menu_font_names(struct sdlpui_control *ctrl,
2647
2682
count = window -> app -> font_count - start ;
2648
2683
}
2649
2684
result = sdlpui_start_simple_menu (dlg , ctrl ,
2650
- count + ((more_nesting ) ? 1 : 0 ), true, false, NULL , 0 );
2685
+ count + ((more_nesting ) ? 1 : 0 ), true, false, NULL , NULL , 0 );
2651
2686
if (more_nesting ) {
2652
2687
c = sdlpui_get_simple_menu_next_unused (result ,
2653
2688
SDLPUI_MFLG_NONE );
@@ -2683,7 +2718,7 @@ static struct sdlpui_dialog *handle_menu_purpose(struct sdlpui_control *ctrl,
2683
2718
subw_idx = (* ctrl -> ftb -> get_tag )(ctrl );
2684
2719
SDL_assert (subw_idx >= 0 && subw_idx != MAIN_SUBWINDOW );
2685
2720
result = sdlpui_start_simple_menu (dlg , ctrl ,
2686
- (int )N_ELEMENTS (window_flag_desc ), true, false, NULL , 0 );
2721
+ (int )N_ELEMENTS (window_flag_desc ), true, false, NULL , NULL , 0 );
2687
2722
while (i < (int )N_ELEMENTS (window_flag_desc )) {
2688
2723
if (window_flag_desc [i ]) {
2689
2724
struct sdlpui_control * c =
@@ -2714,7 +2749,8 @@ static struct sdlpui_dialog *handle_menu_font(struct sdlpui_control *ctrl,
2714
2749
2715
2750
SDL_assert (ctrl -> ftb -> get_tag );
2716
2751
tag = (* ctrl -> ftb -> get_tag )(ctrl );
2717
- result = sdlpui_start_simple_menu (dlg , ctrl , 2 , true, false, NULL , 0 );
2752
+ result = sdlpui_start_simple_menu (dlg , ctrl , 2 , true, false, NULL ,
2753
+ NULL , 0 );
2718
2754
c = sdlpui_get_simple_menu_next_unused (result , SDLPUI_MFLG_NONE );
2719
2755
sdlpui_create_submenu_button (c , "Name" , SDLPUI_HOR_LEFT ,
2720
2756
handle_menu_font_names , SDLPUI_CHILD_MENU_RIGHT , tag , false);
@@ -2813,7 +2849,7 @@ static struct sdlpui_dialog *handle_menu_alpha(struct sdlpui_control *ctrl,
2813
2849
nstep = 1 + ((100 - DEFAULT_ALPHA_LOWEST + (DEFAULT_ALPHA_STEP - 1 ))
2814
2850
/ DEFAULT_ALPHA_STEP );
2815
2851
result = sdlpui_start_simple_menu (dlg , ctrl , nstep , true, false,
2816
- NULL , 0 );
2852
+ NULL , NULL , 0 );
2817
2853
for (i = 0 ; i < nstep ; ++ i ) {
2818
2854
int alpha_pct = MIN (100 ,
2819
2855
DEFAULT_ALPHA_LOWEST + i * DEFAULT_ALPHA_STEP );
@@ -2879,7 +2915,7 @@ static struct sdlpui_dialog *handle_menu_terms(struct sdlpui_control *ctrl,
2879
2915
SDL_assert (subwindow );
2880
2916
result = sdlpui_start_simple_menu (dlg , ctrl ,
2881
2917
(subwindow -> index == MAIN_SUBWINDOW ) ? 4 : 5 , true, false,
2882
- handle_menu_term_pop , tag );
2918
+ handle_menu_term_pop , NULL , tag );
2883
2919
c = sdlpui_get_simple_menu_next_unused (result , SDLPUI_MFLG_NONE );
2884
2920
sdlpui_create_submenu_button (c , "Font" , SDLPUI_HOR_LEFT ,
2885
2921
handle_menu_font , SDLPUI_CHILD_MENU_RIGHT , tag , false);
@@ -2919,7 +2955,7 @@ static struct sdlpui_dialog *handle_menu_button(struct sdlpui_control *ctrl,
2919
2955
struct sdlpui_dialog * result = sdlpui_start_simple_menu (
2920
2956
parent , ctrl , 3 + (int )N_ELEMENTS (angband_term_name )
2921
2957
+ ((window -> index == MAIN_WINDOW ) ? 2 : 0 ), true, false,
2922
- NULL , 0 );
2958
+ NULL , NULL , 0 );
2923
2959
unsigned int i ;
2924
2960
struct sdlpui_control * c ;
2925
2961
@@ -4091,6 +4127,12 @@ static void wait_anykey(struct my_app *a)
4091
4127
case SDL_QUIT :
4092
4128
handle_quit ();
4093
4129
break ;
4130
+ case SDL_RENDER_TARGETS_RESET :
4131
+ recreate_textures (a , false);
4132
+ break ;
4133
+ case SDL_RENDER_DEVICE_RESET :
4134
+ recreate_textures (a , true);
4135
+ break ;
4094
4136
case SDL_WINDOWEVENT :
4095
4137
handle_windowevent (a , & event .window );
4096
4138
return ;
@@ -4135,6 +4177,12 @@ static bool get_event(struct my_app *a)
4135
4177
case SDL_WINDOWEVENT :
4136
4178
handle_windowevent (a , & event .window );
4137
4179
return false;
4180
+ case SDL_RENDER_TARGETS_RESET :
4181
+ recreate_textures (a , false);
4182
+ return false;
4183
+ case SDL_RENDER_DEVICE_RESET :
4184
+ recreate_textures (a , true);
4185
+ return false;
4138
4186
case SDL_QUIT :
4139
4187
handle_quit ();
4140
4188
return false;
@@ -5088,6 +5136,88 @@ static void free_font(struct font *font)
5088
5136
mem_free (font );
5089
5137
}
5090
5138
5139
+ static void recreate_textures (struct my_app * a , bool all )
5140
+ {
5141
+ int i ;
5142
+
5143
+ reload_all_graphics (a , current_graphics_mode );
5144
+ for (i = 0 ; i < MAX_WINDOWS ; ++ i ) {
5145
+ struct sdlpui_window * w = & a -> windows [i ];
5146
+ struct sdlpui_dialog * d ;
5147
+ int j ;
5148
+
5149
+ if (!w -> loaded ) {
5150
+ continue ;
5151
+ }
5152
+
5153
+ /*
5154
+ * Recreate the dynamic texture used to cache the dialog font.
5155
+ */
5156
+ if (w -> dialog_font -> cache .texture ) {
5157
+ SDL_DestroyTexture (w -> dialog_font -> cache .texture );
5158
+ w -> dialog_font -> cache .texture = NULL ;
5159
+ make_font_cache (w , w -> dialog_font );
5160
+ }
5161
+
5162
+ /* Recreate the static texture used for the stipple pattern. */
5163
+ if (all && w -> stipple .texture ) {
5164
+ SDL_DestroyTexture (w -> stipple .texture );
5165
+ w -> stipple = sdlpui_compute_stipple (w -> renderer );
5166
+ }
5167
+
5168
+ /*
5169
+ * Recreate the texture used for the wallpaper. That texture
5170
+ * is dynamic if the wallpapering mode is WALLPAPER_TILED;
5171
+ * otherwise, that texture is static.
5172
+ */
5173
+ if (w -> wallpaper .mode != WALLPAPER_DONT_SHOW
5174
+ && w -> wallpaper .texture && (all
5175
+ || w -> wallpaper .mode == WALLPAPER_TILED )) {
5176
+ SDL_DestroyTexture (w -> wallpaper .texture );
5177
+ w -> wallpaper .texture = NULL ;
5178
+ if (w -> config ) {
5179
+ load_wallpaper (w , w -> config -> wallpaper_path );
5180
+ } else {
5181
+ load_default_wallpaper (w );
5182
+ }
5183
+ }
5184
+
5185
+ /*
5186
+ * Recreate the textures for subwindows; those are all
5187
+ * dynamic.
5188
+ */
5189
+ for (j = 0 ; j < MAX_SUBWINDOWS ; ++ j ) {
5190
+ struct subwindow * sw = w -> subwindows [j ];
5191
+
5192
+ if (!sw ) {
5193
+ continue ;
5194
+ }
5195
+ if (!sw -> texture ) {
5196
+ SDL_DestroyTexture (sw -> texture );
5197
+ sw -> texture = make_subwindow_texture (w ,
5198
+ sw -> full_rect .w , sw -> full_rect .h );
5199
+ SDL_assert (sw -> texture );
5200
+ }
5201
+ if (sw -> font -> cache .texture ) {
5202
+ SDL_DestroyTexture (sw -> font -> cache .texture );
5203
+ sw -> font -> cache .texture = NULL ;
5204
+ make_font_cache (w , sw -> font );
5205
+ }
5206
+ }
5207
+
5208
+ /*
5209
+ * Recreate any textures used by dialogs or menus in the window.
5210
+ */
5211
+ for (d = w -> d_head ; d ; d = d -> next ) {
5212
+ if (d -> recreate_textures_callback ) {
5213
+ (* d -> recreate_textures_callback )(d , w , all );
5214
+ }
5215
+ }
5216
+ }
5217
+
5218
+ refresh_angband_terms (a );
5219
+ }
5220
+
5091
5221
static bool is_ok_col_row (const struct subwindow * subwindow ,
5092
5222
const SDL_Rect * rect , int cell_w , int cell_h )
5093
5223
{
@@ -5332,7 +5462,7 @@ static void load_status_bar(struct sdlpui_window *window)
5332
5462
window -> status_bar = sdlpui_start_simple_menu (NULL , NULL ,
5333
5463
2 + N_ELEMENTS (window -> subwindows )
5334
5464
+ ((window -> index == MAIN_WINDOW ) ? 1 : 0 ), false, true,
5335
- NULL , 0 );
5465
+ NULL , NULL , 0 );
5336
5466
c = sdlpui_get_simple_menu_next_unused (window -> status_bar ,
5337
5467
SDLPUI_MFLG_NONE );
5338
5468
sdlpui_create_submenu_button (c , "Menu" , SDLPUI_HOR_CENTER ,
0 commit comments