Skip to content

Commit

Permalink
renderer resizing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Nov 7, 2021
1 parent 1c5dd84 commit b242cca
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/sdl/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ static void update_keymod(SDL_Keymod keymod) {
}

static SDL_Window *window;
static int charw, charh;
static int charw = 8, charh = 14;

static int charset_update_requested = 0;
static u8* charset_update_data = NULL;

static int palette_update_requested = 0;
static u32* palette_update_data = NULL;
static u8 windowed = 1;
static int windowed_old_w, windowed_old_h;

void calc_render_area(SDL_Rect *rect, int w, int h, int *scale_out, int flags) {
int iw = 80*charw;
Expand Down Expand Up @@ -288,15 +290,20 @@ static void sdl_resize_window(int delta, bool only_if_too_small) {

if (window == NULL) return;

SDL_SetWindowMinimumSize(window, iw, ih);

SDL_GetWindowSize(window, &w, &h);
calc_render_area(NULL, w, h, &scale, 0);
scale += delta;
if (scale < 1) scale = 1;

iw *= scale;
ih *= scale;
if (!only_if_too_small || ((iw > w) || (ih > h))) {
SDL_SetWindowSize(window, iw, ih);

if (windowed) {
if (!only_if_too_small || ((iw > w) || (ih > h))) {
SDL_SetWindowSize(window, iw, ih);
}
}
}

Expand All @@ -317,7 +324,6 @@ void zeta_update_charset(int width, int height, u8* data) {
gif_writer_on_charset_change(gif_writer_s);
}
#endif
sdl_resize_window(0, true);
SDL_UnlockMutex(render_data_update_mutex);
}

Expand Down Expand Up @@ -353,7 +359,6 @@ int main(int argc, char **argv) {
int scode, kcode;

SDL_Thread* zzt_thread;
u8 windowed = 1;

init_posix_vfs("");

Expand Down Expand Up @@ -393,6 +398,7 @@ int main(int argc, char **argv) {
}
}
window = renderer->get_window();
sdl_resize_window(0, false);

SDL_zero(requested_audio_spec);
requested_audio_spec.freq = 48000;
Expand Down Expand Up @@ -560,6 +566,7 @@ int main(int argc, char **argv) {
if (event.key.keysym.scancode == SDL_SCANCODE_RETURN && KEYMOD_ALT(event.key.keysym.mod)) {
// Alt+ENTER
if (windowed) {
SDL_GetWindowSize(window, &windowed_old_w, &windowed_old_h);
SDL_DisplayMode mode;
SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(window), &mode);
SDL_SetWindowSize(window, mode.w, mode.h);
Expand All @@ -568,7 +575,8 @@ int main(int argc, char **argv) {
SDL_SetRelativeMouseMode(1);
} else {
SDL_SetWindowFullscreen(window, 0);
SDL_SetWindowSize(window, 80*charw, 25*charh);
SDL_SetWindowSize(window, windowed_old_w, windowed_old_h);
sdl_resize_window(0, true);
// drop focus
SDL_SetRelativeMouseMode(0);
}
Expand Down Expand Up @@ -651,6 +659,7 @@ int main(int argc, char **argv) {
SDL_LockMutex(render_data_update_mutex);

if (charset_update_requested) {
sdl_resize_window(0, true);
renderer->update_charset(charw, charh, charset_update_data);
charset_update_requested = 0;
}
Expand Down

0 comments on commit b242cca

Please sign in to comment.