From c7e79eb8f43ad8284e0041c64372a10ed392a212 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sun, 5 Feb 2017 18:21:32 +0100 Subject: [PATCH] Pause and resume the movies when the window lost the focus --- blupi.cpp | 4 ++++ movie.cpp | 22 ++++++++++++++++++++++ movie.h | 2 ++ 3 files changed, 28 insertions(+) diff --git a/blupi.cpp b/blupi.cpp index f5a91c4..cda21b9 100644 --- a/blupi.cpp +++ b/blupi.cpp @@ -324,6 +324,8 @@ void WindowProc2 (const SDL_Event &event) } SDL_SetWindowTitle (g_window, "Blupi"); if (g_pSound != nullptr) g_pSound->RestartMusic (); + if (g_pMovie) + g_pMovie->Resume (); return; case SDL_WINDOWEVENT_FOCUS_LOST: @@ -333,6 +335,8 @@ void WindowProc2 (const SDL_Event &event) } SDL_SetWindowTitle (g_window, "Blupi -- stop"); if (g_pSound != nullptr) g_pSound->SuspendMusic (); + if (g_pMovie) + g_pMovie->Pause (); return; } break; diff --git a/movie.cpp b/movie.cpp index 7b67f22..cd294ca 100644 --- a/movie.cpp +++ b/movie.cpp @@ -250,6 +250,28 @@ void CMovie::Stop() SDL_RenderSetLogicalSize (g_renderer, 0, 0); } +void CMovie::Pause () +{ + if (!m_bEnable || !m_fPlaying) + return; + + if (Kit_GetPlayerState (m_player) != KIT_PLAYING) + return; + + Kit_PlayerPause (m_player); +} + +void CMovie::Resume () +{ + if (!m_bEnable || !m_fPlaying) + return; + + if (Kit_GetPlayerState (m_player) != KIT_PAUSED) + return; + + Kit_PlayerPlay (m_player); +} + bool CMovie::Render () { if (!m_bEnable || !m_fPlaying) diff --git a/movie.h b/movie.h index 3464c38..fae366c 100644 --- a/movie.h +++ b/movie.h @@ -21,6 +21,8 @@ public: bool IsExist(char *pFilename); bool Play(RECT rect, char *pFilename); void Stop(); + void Pause (); + void Resume (); bool Render (); protected: