Skip to content

Commit

Permalink
Implement Toggle_Video_Fullscreen with SDL 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 committed Jun 17, 2023
1 parent a36cba3 commit 01d8530
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 18 additions & 0 deletions common/video_sdl1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ bool Set_Video_Mode(int w, int h, int bits_per_pixel)
void Toggle_Video_Fullscreen()
{
Settings.Video.Windowed = !Settings.Video.Windowed;

if (window) {
int win_flags = SDL_HWSURFACE | SDL_HWPALETTE;
SDL_Surface* new_window;

if (!Settings.Video.Windowed) {
win_flags |= SDL_FULLSCREEN;
}

new_window = SDL_SetVideoMode(window->w, window->h, 8, win_flags);
if (new_window) {
window = new_window;

/* The palette needs to be restored when switching to a new video mode */
SDL_SetPalette(window, SDL_LOGPAL, logpal, 0, 256);
SDL_SetPalette(window, SDL_PHYSPAL, physpal, 0, 256);
}
}
}

void Get_Video_Scale(float& x, float& y)
Expand Down
12 changes: 10 additions & 2 deletions common/wwkeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,11 @@ void WWKeyboardClass::Fill_Buffer_From_System(void)
#ifdef SDL2_BUILD
Put_Key_Message(event.key.keysym.scancode, false);
#else
Put_Key_Message(event.key.keysym.sym, false);
if (event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT)) {
/* Switching to full screen is handled in the key up event */
} else {
Put_Key_Message(event.key.keysym.sym, false);
}
#endif
break;
case SDL_KEYUP:
Expand All @@ -562,7 +566,11 @@ void WWKeyboardClass::Fill_Buffer_From_System(void)
Put_Key_Message(event.key.keysym.scancode, true);
}
#else
Put_Key_Message(event.key.keysym.sym, true);
if (event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT)) {
Toggle_Video_Fullscreen();
} else {
Put_Key_Message(event.key.keysym.sym, true);
}
#endif
break;
case SDL_MOUSEMOTION:
Expand Down

0 comments on commit 01d8530

Please sign in to comment.