Skip to content

Commit cd82311

Browse files
committed
Apply auto-resizing also to border mode change
1 parent bf9212b commit cd82311

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

SDL/main.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,26 @@ static void update_palette(void)
232232
GB_set_palette(&gb, current_dmg_palette());
233233
}
234234

235-
static void screen_size_changed(void)
235+
static void screen_size_changed(bool resize_window)
236236
{
237237
SDL_DestroyTexture(texture);
238238
texture = SDL_CreateTexture(renderer, SDL_GetWindowPixelFormat(window), SDL_TEXTUREACCESS_STREAMING,
239239
GB_get_screen_width(&gb), GB_get_screen_height(&gb));
240240

241241
SDL_SetWindowMinimumSize(window, GB_get_screen_width(&gb), GB_get_screen_height(&gb));
242242

243+
if (resize_window) {
244+
signed current_window_width, current_window_height;
245+
SDL_GetWindowSize(window, &current_window_width, &current_window_height);
246+
247+
signed width = GB_get_screen_width(&gb) * configuration.default_scale;
248+
signed height = GB_get_screen_height(&gb) * configuration.default_scale;
249+
signed x, y;
250+
SDL_GetWindowPosition(window, &x, &y);
251+
SDL_SetWindowSize(window, width, height);
252+
SDL_SetWindowPosition(window, x - (width - current_window_width) / 2, y - (height - current_window_height) / 2);
253+
}
254+
243255
update_viewport();
244256
}
245257

@@ -250,6 +262,7 @@ static void open_menu(void)
250262
GB_audio_set_paused(true);
251263
}
252264
size_t previous_width = GB_get_screen_width(&gb);
265+
size_t previous_height = GB_get_screen_height(&gb);
253266
run_gui(true);
254267
rerender_screen();
255268
SDL_ShowCursor(SDL_DISABLE);
@@ -265,7 +278,11 @@ static void open_menu(void)
265278
GB_set_rewind_length(&gb, configuration.rewind_length);
266279
GB_set_rtc_mode(&gb, configuration.rtc_mode);
267280
if (previous_width != GB_get_screen_width(&gb)) {
268-
screen_size_changed();
281+
signed current_window_width, current_window_height;
282+
SDL_GetWindowSize(window, &current_window_width, &current_window_height);
283+
284+
screen_size_changed(current_window_width == previous_width * configuration.default_scale &&
285+
current_window_height == previous_height * configuration.default_scale);
269286
}
270287
}
271288

@@ -1162,7 +1179,7 @@ restart:;
11621179
replace_extension(filename, path_length, symbols_path, ".sym");
11631180
GB_debugger_load_symbol_file(&gb, symbols_path);
11641181

1165-
screen_size_changed();
1182+
screen_size_changed(false);
11661183

11671184
/* Run emulation */
11681185
while (true) {

0 commit comments

Comments
 (0)