From 966db1eac4c5d124337504f08810ebdac788e680 Mon Sep 17 00:00:00 2001 From: hybrid Date: Mon, 16 Jun 2008 09:24:11 +0000 Subject: [PATCH] Added isWindowFocused and isWindowMinimized methods. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1383 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IrrlichtDevice.h | 8 +++++++ source/Irrlicht/CIrrDeviceLinux.cpp | 27 ++++++++++++++++------ source/Irrlicht/CIrrDeviceLinux.h | 8 ++++++- source/Irrlicht/CIrrDeviceSDL.cpp | 36 ++++++++++++++++++++++------- source/Irrlicht/CIrrDeviceSDL.h | 11 +++++---- source/Irrlicht/CIrrDeviceWin32.cpp | 26 ++++++++++++++++++--- source/Irrlicht/CIrrDeviceWin32.h | 6 +++++ source/Irrlicht/CIrrDeviceWinCE.cpp | 24 +++++++++++++++++-- source/Irrlicht/CIrrDeviceWinCE.h | 6 +++++ 9 files changed, 126 insertions(+), 26 deletions(-) diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index 8386ac1a..8c13e46d 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -151,6 +151,14 @@ namespace irr \return True if window is active. */ virtual bool isWindowActive() const = 0; + //! Checks if the Irrlicht window has focus + /** \return True if window has focus. */ + virtual bool isWindowFocused() const = 0; + + //! Checks if the Irrlicht window is minimized + /** \return True if window is minimized. */ + virtual bool isWindowMinimized() const = 0; + //! Notifies the device that it should close itself. /** IrrlichtDevice::run() will always return false after closeDevice() was called. */ virtual void closeDevice() = 0; diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index b57b39d7..d18cfac6 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -43,7 +43,7 @@ CIrrDeviceLinux::CIrrDeviceLinux(const SIrrlichtCreationParameters& param) display(0), visual(0), screennr(0), window(0), StdHints(0), SoftwareImage(0), #endif Width(param.WindowSize.Width), Height(param.WindowSize.Height), - Close(false), WindowActive(false), WindowMinimized(false), UseXVidMode(false), UseXRandR(false), UseGLXWindow(false), AutorepeatSupport(0) + Close(false), WindowHasFocus(false), WindowMinimized(false), UseXVidMode(false), UseXRandR(false), UseGLXWindow(false), AutorepeatSupport(0) { #ifdef _DEBUG setDebugName("CIrrDeviceLinux"); @@ -529,7 +529,7 @@ bool CIrrDeviceLinux::createWindow() XSetWMProtocols(display, window, &wmDelete, 1); XMapRaised(display, window); } - WindowActive=true; + WindowMinimized=false; XkbSetDetectableAutoRepeat(display, True, &AutorepeatSupport); #ifdef _IRR_COMPILE_WITH_OPENGL_ @@ -668,7 +668,6 @@ void CIrrDeviceLinux::createDriver() } - //! runs the device. Returns false if device wants to be deleted bool CIrrDeviceLinux::run() { @@ -722,11 +721,11 @@ bool CIrrDeviceLinux::run() break; case FocusIn: - WindowActive=true; + WindowHasFocus=true; break; case FocusOut: - WindowActive=false; + WindowHasFocus=false; break; case MotionNotify: @@ -859,7 +858,7 @@ void CIrrDeviceLinux::yield() //! Pause execution and let other processes to run for a specified amount of time. void CIrrDeviceLinux::sleep(u32 timeMs, bool pauseTimer=false) { - bool wasStopped = Timer ? Timer->isStopped() : true; + const bool wasStopped = Timer ? Timer->isStopped() : true; struct timespec ts; ts.tv_sec = (time_t) (timeMs / 1000); @@ -1011,7 +1010,21 @@ void CIrrDeviceLinux::closeDevice() //! returns if window is active. if not, nothing need to be drawn bool CIrrDeviceLinux::isWindowActive() const { - return WindowActive; + return (WindowHasFocus && !WindowMinimized); +} + + +//! returns if window has focus. +bool CIrrDeviceLinux::isWindowFocused() const +{ + return WindowHasFocus; +} + + +//! returns if window is minimized. +bool CIrrDeviceLinux::isWindowMinimized() const +{ + return WindowMinimized; } diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index 53059644..f64389bc 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -68,6 +68,12 @@ namespace irr //! returns if window is active. if not, nothing need to be drawn virtual bool isWindowActive() const; + //! returns if window has focus. + virtual bool isWindowFocused() const; + + //! returns if window is minimized. + virtual bool isWindowMinimized() const; + //! presents a surface in the client area virtual void present(video::IImage* surface, void* windowId=0, core::rect* src=0 ); @@ -305,7 +311,7 @@ namespace irr #endif u32 Width, Height; bool Close; - bool WindowActive; + bool WindowHasFocus; bool WindowMinimized; bool UseXVidMode; bool UseXRandR; diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index faf12c7a..80435b95 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -38,10 +38,12 @@ const char* wmDeleteWindow = "WM_DELETE_WINDOW"; //! constructor CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) - : CIrrDeviceStub(param), Resizeable(false), + : CIrrDeviceStub(param), Screen((SDL_Surface*)param.WindowId), SDL_Flags(SDL_HWSURFACE|SDL_ANYFORMAT), - Width(param.WindowSize.Width), Height(param.WindowSize.Height), Close(0), - WindowActive(false) + MouseX(0), MouseY(0), + Width(param.WindowSize.Width), Height(param.WindowSize.Height), + Close(0), Resizeable(false), + WindowHasFocus(false), WindowMinimized(false) { #ifdef _DEBUG setDebugName("CIrrDeviceSDL"); @@ -197,6 +199,7 @@ bool CIrrDeviceSDL::run() os::Timer::tick(); SEvent irrevent; + SDL_Event SDL_event; while ( !Close && SDL_PollEvent( &SDL_event ) ) { @@ -269,8 +272,12 @@ bool CIrrDeviceSDL::run() break; case SDL_ACTIVEEVENT: - if (SDL_event.active.state == SDL_APPMOUSEFOCUS) - WindowActive = (SDL_event.active.gain==1); + if ((SDL_event.active.state == SDL_APPMOUSEFOCUS) || + (SDL_event.active.state == SDL_APPINPUTFOCUS)) + WindowHasFocus = (SDL_event.active.gain==1); + else + if (SDL_event.active.state == SDL_APPACTIVE) + WindowMinimized = (SDL_event.active.gain!=1); break; default: @@ -293,7 +300,7 @@ void CIrrDeviceSDL::yield() //! pause execution for a specified time void CIrrDeviceSDL::sleep(u32 timeMs, bool pauseTimer) { - bool wasStopped = Timer ? Timer->isStopped() : true; + const bool wasStopped = Timer ? Timer->isStopped() : true; if (pauseTimer && !wasStopped) Timer->stop(); @@ -387,11 +394,24 @@ void CIrrDeviceSDL::setResizeAble(bool resize) } - //! returns if window is active. if not, nothing need to be drawn bool CIrrDeviceSDL::isWindowActive() const { - return WindowActive; + return (WindowHasFocus && !WindowMinimized); +} + + +//! returns if window has focus. +bool CIrrDeviceSDL::isWindowFocused() const +{ + return WindowHasFocus; +} + + +//! returns if window is minimized. +bool CIrrDeviceSDL::isWindowMinimized() const +{ + return WindowMinimized; } diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index 66c97b2b..1f9cb654 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -158,16 +158,17 @@ namespace irr void createKeyMap(); - s32 MouseX, MouseY; - bool Resizeable; - SDL_Surface* Screen; - SDL_Event SDL_event; int SDL_Flags; + s32 MouseX, MouseY; + u32 Width, Height; + bool Close; - bool WindowActive; + bool Resizeable; + bool WindowHasFocus; + bool WindowMinimized; struct SKeyMap { diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index c8691b6a..95b88f92 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -554,7 +554,7 @@ void CIrrDeviceWin32::yield() //! Pause execution and let other processes to run for a specified amount of time. void CIrrDeviceWin32::sleep(u32 timeMs, bool pauseTimer) { - bool wasStopped = Timer ? Timer->isStopped() : true; + const bool wasStopped = Timer ? Timer->isStopped() : true; if (pauseTimer && !wasStopped) Timer->stop(); @@ -668,8 +668,7 @@ void CIrrDeviceWin32::closeDevice() } - -//! returns if window is active. if not, nothing need to be drawn +//! returns if window is active. if not, nothing needs to be drawn bool CIrrDeviceWin32::isWindowActive() const { bool ret = (GetActiveWindow() == HWnd); @@ -678,6 +677,27 @@ bool CIrrDeviceWin32::isWindowActive() const } +//! returns if window has focus +bool CIrrDeviceWin32::isWindowFocused() const +{ + bool ret = (GetFocus() == HWnd); + _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; + return ret; +} + + +//! returns if window is minimized +bool CIrrDeviceWin32::isWindowMinimized() const +{ + WINDOWPLACEMENT plc; + plc.length=sizeof(WINDOWPLACEMENT); + bool ret=false; + if (GetWindowPlacement(HWnd,&plc)) + ret=(plc.showCmd & SW_SHOWMINIMIZED); + _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; + return ret; +} + //! switches to fullscreen bool CIrrDeviceWin32::switchToFullScreen(s32 width, s32 height, s32 bits) diff --git a/source/Irrlicht/CIrrDeviceWin32.h b/source/Irrlicht/CIrrDeviceWin32.h index 703951bf..6e00e76b 100644 --- a/source/Irrlicht/CIrrDeviceWin32.h +++ b/source/Irrlicht/CIrrDeviceWin32.h @@ -43,6 +43,12 @@ namespace irr //! returns if window is active. if not, nothing need to be drawn virtual bool isWindowActive() const; + //! returns if window has focus + virtual bool isWindowFocused() const; + + //! returns if window is minimized + virtual bool isWindowMinimized() const; + //! presents a surface in the client area virtual void present(video::IImage* surface, void* windowId=0, core::rect* src=0); diff --git a/source/Irrlicht/CIrrDeviceWinCE.cpp b/source/Irrlicht/CIrrDeviceWinCE.cpp index 2e53141c..273b5dbe 100644 --- a/source/Irrlicht/CIrrDeviceWinCE.cpp +++ b/source/Irrlicht/CIrrDeviceWinCE.cpp @@ -528,7 +528,7 @@ void CIrrDeviceWinCE::yield() //! Pause execution and let other processes to run for a specified amount of time. void CIrrDeviceWinCE::sleep(u32 timeMs, bool pauseTimer) { - bool wasStopped = Timer ? Timer->isStopped() : true; + const bool wasStopped = Timer ? Timer->isStopped() : true; if (pauseTimer && !wasStopped) Timer->stop(); @@ -657,7 +657,6 @@ void CIrrDeviceWinCE::closeDevice() } - //! returns if window is active. if not, nothing need to be drawn bool CIrrDeviceWinCE::isWindowActive() const { @@ -667,6 +666,27 @@ bool CIrrDeviceWinCE::isWindowActive() const } +//! returns if window has focus +bool CIrrDeviceWinCE::isWindowFocused() const +{ + bool ret = (GetFocus() == HWnd); + _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; + return ret; +} + + +//! returns if window is minimized +bool CIrrDeviceWinCE::isWindowMinimized() const +{ + WINDOWPLACEMENT plc; + plc.length=sizeof(WINDOWPLACEMENT); + bool ret=false; + if (GetWindowPlacement(HWnd,&plc)) + ret=(plc.showCmd & SW_SHOWMINIMIZED); + _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; + return ret; +} + //! switches to fullscreen bool CIrrDeviceWinCE::switchToFullScreen() diff --git a/source/Irrlicht/CIrrDeviceWinCE.h b/source/Irrlicht/CIrrDeviceWinCE.h index e4b8950e..854ef389 100644 --- a/source/Irrlicht/CIrrDeviceWinCE.h +++ b/source/Irrlicht/CIrrDeviceWinCE.h @@ -49,6 +49,12 @@ namespace irr //! returns if window is active. if not, nothing need to be drawn virtual bool isWindowActive() const; + //! returns if window has focus + virtual bool isWindowFocused() const; + + //! returns if window is minimized + virtual bool isWindowMinimized() const; + //! presents a surface in the client area virtual void present(video::IImage* surface, void* windowId = 0, core::rect* src=0 );