Added pause on focus lost (SDL1 and SDL2 only)

This commit is contained in:
John Collins 2020-08-20 00:03:46 -05:00
parent 417d59e7d2
commit 7ed635efd6
3 changed files with 19 additions and 4 deletions

View File

@ -30,6 +30,7 @@
#include "course_table.h"
#include "thread6.h"
#include "../../include/libc/stdlib.h"
#include "print.h"
#include "pc/pc_main.h"
#include "pc/cliopts.h"
@ -154,7 +155,7 @@ struct CreditsEntry sCreditsSequence[] = {
{ LEVEL_CASTLE_GROUNDS, 1, 1, -128, { 0, 906, -1200 }, NULL },
{ LEVEL_NONE, 0, 1, 0, { 0, 0, 0 }, NULL },
};
extern bool focus_Lost;
struct MarioState gMarioStates[1];
struct HudDisplay gHudDisplay;
s16 sCurrPlayMode;
@ -961,6 +962,7 @@ void basic_update(UNUSED s16 *arg) {
int gPressedStart = 0;
s32 play_mode_normal(void) {
if (gCurrDemoInput != NULL) {
print_intro_text();
if (gPlayer1Controller->buttonPressed & END_DEMO) {
@ -997,11 +999,12 @@ s32 play_mode_normal(void) {
set_play_mode(PLAY_MODE_CHANGE_LEVEL);
} else if (sTransitionTimer != 0) {
set_play_mode(PLAY_MODE_CHANGE_AREA);
} else if (pressed_pause()) {
} else if (pressed_pause() || focus_Lost) {
lower_background_noise(1);
cancel_rumble();
gCameraMovementFlags |= CAM_MOVE_PAUSE_SCREEN;
set_play_mode(PLAY_MODE_PAUSED);
focus_Lost = FALSE;
}
}

View File

@ -26,7 +26,7 @@
#else
# define FRAMERATE 30
#endif
bool focus_Lost = FALSE;
static int inverted_scancode_table[512];
static kb_callback_t kb_key_down = NULL;
@ -202,6 +202,11 @@ static void gfx_sdl_onkeyup(int scancode) {
static void gfx_sdl_handle_events(void) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type.event = SDL_WINDOWEVENT_FOCUS_LOST)
{
focus_Lost = TRUE;
}
switch (event.type) {
#ifndef TARGET_WEB
// Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259
@ -222,6 +227,7 @@ static void gfx_sdl_handle_events(void) {
case SDL_QUIT:
game_exit();
break;
}
}
}

View File

@ -41,7 +41,7 @@
#else
# define FRAMERATE 30
#endif
bool focus_Lost = FALSE;
static SDL_Window *wnd;
static SDL_GLContext ctx = NULL;
static int inverted_scancode_table[512];
@ -282,11 +282,13 @@ static void gfx_sdl_handle_events(void) {
// Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259
case SDL_KEYDOWN:
gfx_sdl_onkeydown(event.key.keysym.scancode);
break;
case SDL_KEYUP:
gfx_sdl_onkeyup(event.key.keysym.scancode);
break;
#endif
case SDL_WINDOWEVENT: // TODO: Check if this makes sense to be included in the Web build
if (!IS_FULLSCREEN()) {
switch (event.window.event) {
@ -300,12 +302,16 @@ static void gfx_sdl_handle_events(void) {
configWindow.w = event.window.data1;
configWindow.h = event.window.data2;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
focus_Lost = TRUE;
break;
}
}
break;
case SDL_QUIT:
game_exit();
break;
}
}