From: Holger Schemel Date: Sun, 13 Mar 2022 10:17:55 +0000 (+0100) Subject: added stopping screen fading if "Escape" key event is pending X-Git-Tag: 4.3.2.0~78 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=59cc2c3d3bd985cc378f9cc6bfae6c5ebdb32e78;p=rocksndiamonds.git added stopping screen fading if "Escape" key event is pending --- diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 4108b2b5..1614b1e2 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -1225,6 +1225,9 @@ void SDLFadeRectangle(int x, int y, int width, int height, draw_border_function(); UpdateScreen_WithFrameDelay(&dst_rect2); + + if (PendingEscapeKeyEvent()) + break; } } } @@ -1281,6 +1284,9 @@ void SDLFadeRectangle(int x, int y, int width, int height, // only update the region of the screen that is affected from fading UpdateScreen_WithFrameDelay(&dst_rect2); + + if (PendingEscapeKeyEvent()) + break; } } else // fading in, fading out or cross-fading @@ -1307,6 +1313,9 @@ void SDLFadeRectangle(int x, int y, int width, int height, // only update the region of the screen that is affected from fading UpdateScreen_WithFrameDelay(&dst_rect); + + if (PendingEscapeKeyEvent()) + break; } } diff --git a/src/libgame/system.c b/src/libgame/system.c index 3eb9c62d..ea8288e0 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1845,6 +1845,24 @@ void PushUserEvent(int code, int value1, int value2) SDL_PushEvent((SDL_Event *)&event); } +boolean PendingEscapeKeyEvent(void) +{ + if (PendingEvent()) + { + Event event; + + // check if any key press event is pending + if (SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYDOWN) != 1) + return FALSE; + + // check if pressed key is "Escape" key + if (event.key.keysym.sym == KSYM_Escape) + return TRUE; + } + + return FALSE; +} + // ============================================================================ // joystick functions diff --git a/src/libgame/system.h b/src/libgame/system.h index afd737d1..123ddc9b 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -2025,6 +2025,7 @@ KeyMod GetKeyModStateFromEvents(void); void StartTextInput(int, int, int, int); void StopTextInput(void); void PushUserEvent(int, int, int); +boolean PendingEscapeKeyEvent(void); void InitJoysticks(void); boolean ReadJoystick(int, int *, int *, boolean *, boolean *);