From 720c15d03a602949e5768ae0efcd5e7b0e63b9d7 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 19 Oct 2023 18:57:02 +0200 Subject: [PATCH] - [NEW] game::windowHasFocus --- source/jgame.cpp | 7 +++++++ source/jgame.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/source/jgame.cpp b/source/jgame.cpp index 816805f..41c5f3b 100644 --- a/source/jgame.cpp +++ b/source/jgame.cpp @@ -6,6 +6,8 @@ namespace game { + bool windowHasFocus = true; + static bool (*loop)() = nullptr; static unsigned int ticks_per_frame = 1000/60; static std::map config; @@ -39,6 +41,7 @@ namespace game int main(int argc, char *argv[]) { + game::windowHasFocus = true; game::init(); input::init(draw::getZoom()); @@ -67,6 +70,10 @@ int main(int argc, char *argv[]) { input::updateWheel(e.wheel.y); } + if ( e.type == SDL_WINDOWEVENT ) { + if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) game::windowHasFocus = true; + if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) game::windowHasFocus = false; + } } if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame) diff --git a/source/jgame.h b/source/jgame.h index 7b09e2a..4396efe 100644 --- a/source/jgame.h +++ b/source/jgame.h @@ -6,6 +6,8 @@ #include "jfile.h" namespace game { + extern bool windowHasFocus; + void setUpdateTicks(const int ticks); void init();