From 9b50b09ea3ce249dc4bf33784712f39abb2593cb Mon Sep 17 00:00:00 2001 From: cutealien Date: Sun, 13 Dec 2009 10:39:29 +0000 Subject: [PATCH] Add clearSystemMessages to IrrlichtDevices (implemented only for Win32 and Linux so far). git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3051 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 2 ++ include/IrrlichtDevice.h | 18 ++++++++++++++--- source/Irrlicht/CIrrDeviceLinux.cpp | 15 +++++++++++++++ source/Irrlicht/CIrrDeviceLinux.h | 3 +++ source/Irrlicht/CIrrDeviceStub.cpp | 8 +++++++- source/Irrlicht/CIrrDeviceStub.h | 4 ++++ source/Irrlicht/CIrrDeviceWin32.cpp | 30 +++++++++++++++++++---------- source/Irrlicht/CIrrDeviceWin32.h | 11 +++++++---- 8 files changed, 73 insertions(+), 18 deletions(-) diff --git a/changes.txt b/changes.txt index c4a4db2a..369b3108 100644 --- a/changes.txt +++ b/changes.txt @@ -1,4 +1,6 @@ Changes in 1.7 + + - Add clearSystemMessages to devices (implemented only for Linux and Win32 so far). - Fix incorrect cursorpos for resizable windows on Windows Vista (found and patched by buffer) diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index 7ab6f844..c2e0f093 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -179,8 +179,8 @@ namespace irr \return String which contains the version. */ virtual const c8* getVersion() const = 0; - //! Sets a new user event receiver which will receive events from the engine. - /** Return true in IEventReceiver::OnEvent to prevent the event from continuing along + //! Sets a new user event receiver which will receive events from the engine. + /** Return true in IEventReceiver::OnEvent to prevent the event from continuing along the chain of event receivers. The path that an event takes through the system depends on its type. See irr::EEVENT_TYPE for details. \param receiver New receiver to be used. */ @@ -221,7 +221,7 @@ namespace irr //! Activate any joysticks, and generate events for them. /** Irrlicht contains support for joysticks, but does not generate joystick events by default, - as this would consume joystick info that 3rd party libraries might rely on. Call this method to + as this would consume joystick info that 3rd party libraries might rely on. Call this method to activate joystick support in Irrlicht and to receive irr::SJoystickEvent events. \param joystickInfo On return, this will contain an array of each joystick that was found and activated. \return true if joysticks are supported on this device and _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ @@ -237,6 +237,18 @@ namespace irr virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast) =0; + //! Remove all messages pending in the system message loop + /** This function is usually used after messages have been buffered for a longer time, for example + when loading a large scene. Clearing the message loop prevents that mouse- or buttonclicks which users + have pressed in the meantime will now trigger unexpected actions in the gui.
+ So far the following messages are cleared:
+ Win32: All keyboard and mouse messages
+ Linux: All messages
+ All other devices are not yet supported here.
+ The function is still somewhat experimental, as the kind of messages we clear is based on just a few use-cases. + If you think further messages should be cleared, or some messages should not be cleared here, then please tell us. */ + virtual void clearSystemMessages() = 0; + //! Get the type of the device. /** This allows the user to check which windowing system is currently being used. */ diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp index 73173430..bf3b68f5 100644 --- a/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/source/Irrlicht/CIrrDeviceLinux.cpp @@ -1814,6 +1814,21 @@ void CIrrDeviceLinux::copyToClipboard(const c8* text) const #endif } +//! Remove all messages pending in the system message loop +void CIrrDeviceLinux::clearSystemMessages() +{ +#ifdef _IRR_COMPILE_WITH_X11_ + if (CreationParams.DriverType != video::EDT_NULL) + { + XEvent event; + while (XPending(display) > 0 ) + { + XNextEvent(display, &event); + } + } +#endif //_IRR_COMPILE_WITH_X11_ +} + void CIrrDeviceLinux::initXAtoms() { #ifdef _IRR_COMPILE_WITH_X11_ diff --git a/source/Irrlicht/CIrrDeviceLinux.h b/source/Irrlicht/CIrrDeviceLinux.h index 2900ad01..169e4101 100644 --- a/source/Irrlicht/CIrrDeviceLinux.h +++ b/source/Irrlicht/CIrrDeviceLinux.h @@ -116,6 +116,9 @@ namespace irr //! This sets the clipboard selection and _not_ the primary selection which you have on X on the middle mouse button. virtual void copyToClipboard(const c8* text) const; + //! Remove all messages pending in the system message loop + virtual void clearSystemMessages(); + //! Get the device type virtual E_DEVICE_TYPE getType() const { diff --git a/source/Irrlicht/CIrrDeviceStub.cpp b/source/Irrlicht/CIrrDeviceStub.cpp index e0eea4e7..79fb677b 100644 --- a/source/Irrlicht/CIrrDeviceStub.cpp +++ b/source/Irrlicht/CIrrDeviceStub.cpp @@ -181,7 +181,7 @@ u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_E if ( (clickTime-MouseMultiClicks.LastClickTime) < MouseMultiClicks.DoubleClickTime && core::abs_(MouseMultiClicks.LastClick.X - mouseX ) <= MAX_MOUSEMOVE && core::abs_(MouseMultiClicks.LastClick.Y - mouseY ) <= MAX_MOUSEMOVE - && MouseMultiClicks.CountSuccessiveClicks < 3 + && MouseMultiClicks.CountSuccessiveClicks < 3 && MouseMultiClicks.LastMouseInputEvent == inputEvent ) { @@ -352,6 +352,12 @@ u32 CIrrDeviceStub::getDoubleClickTime() const return MouseMultiClicks.DoubleClickTime; } +//! Remove all messages pending in the system message loop +void CIrrDeviceStub::clearSystemMessages() +{ +} + + } // end namespace irr diff --git a/source/Irrlicht/CIrrDeviceStub.h b/source/Irrlicht/CIrrDeviceStub.h index 55508732..2167fc4b 100644 --- a/source/Irrlicht/CIrrDeviceStub.h +++ b/source/Irrlicht/CIrrDeviceStub.h @@ -123,6 +123,10 @@ namespace irr //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse. virtual u32 getDoubleClickTime() const; + //! Remove all messages pending in the system message loop + virtual void clearSystemMessages(); + + protected: void createGUIAndScene(); diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp index 120b63e7..f830ceaf 100644 --- a/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/source/Irrlicht/CIrrDeviceWin32.cpp @@ -34,7 +34,7 @@ namespace irr #endif #ifdef _IRR_COMPILE_WITH_OPENGL_ - IVideoDriver* createOpenGLDriver(const irr::SIrrlichtCreationParameters& params, + IVideoDriver* createOpenGLDriver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device); #endif } @@ -218,16 +218,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey( ((lParam>>16) & 255), MY_MAPVK_VSC_TO_VK_EX ); // some keyboards will just return LEFT for both - left and right keys. So also check extend bit. - if (lParam & 0x1000000) + if (lParam & 0x1000000) event.KeyInput.Key = irr::KEY_RCONTROL; } if ( event.KeyInput.Key == irr::KEY_MENU ) { event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey( ((lParam>>16) & 255), MY_MAPVK_VSC_TO_VK_EX ); - if (lParam & 0x1000000) + if (lParam & 0x1000000) event.KeyInput.Key = irr::KEY_RMENU; } - + WORD KeyAsc=0; GetKeyboardState(allKeys); ToAscii((UINT)wParam,(UINT)lParam,allKeys,&KeyAsc,0); @@ -1185,6 +1185,16 @@ bool CIrrDeviceWin32::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &bright } +//! Remove all messages pending in the system message loop +void CIrrDeviceWin32::clearSystemMessages() +{ + MSG msg; + while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)) + {} + while (PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE)) + {} +} + // shows last error in a messagebox to help internal debugging. void CIrrDeviceWin32::ReportLastWinApiError() { @@ -1203,12 +1213,12 @@ void CIrrDeviceWin32::ReportLastWinApiError() FORMAT_MESSAGE_FROM_SYSTEM; LPVOID pTextBuffer = NULL; - DWORD dwCount = FormatMessage(dwFormatControl, - NULL, - dwError, - 0, - (LPTSTR) &pTextBuffer, - 0, + DWORD dwCount = FormatMessage(dwFormatControl, + NULL, + dwError, + 0, + (LPTSTR) &pTextBuffer, + 0, NULL); if(0 != dwCount) { diff --git a/source/Irrlicht/CIrrDeviceWin32.h b/source/Irrlicht/CIrrDeviceWin32.h index 95e3dd61..f65cd8ea 100644 --- a/source/Irrlicht/CIrrDeviceWin32.h +++ b/source/Irrlicht/CIrrDeviceWin32.h @@ -87,6 +87,9 @@ namespace irr //! Get the current Gamma Value for the Display virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast ); + //! Remove all messages pending in the system message loop + virtual void clearSystemMessages(); + //! Get the device type virtual E_DEVICE_TYPE getType() const { @@ -254,7 +257,7 @@ namespace irr WindowSize = size; if (size.Width!=0) InvWindowSize.Width = 1.0f / size.Width; - else + else InvWindowSize.Width = 0.f; if (size.Height!=0) @@ -271,12 +274,12 @@ namespace irr if (resizable) { BorderX = GetSystemMetrics(SM_CXSIZEFRAME); - BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYSIZEFRAME); + BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYSIZEFRAME); } else { BorderX = GetSystemMetrics(SM_CXDLGFRAME); - BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYDLGFRAME); + BorderY = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYDLGFRAME); } } else @@ -296,7 +299,7 @@ namespace irr DWORD xy = GetMessagePos(); p.x = GET_X_LPARAM(xy); p.y = GET_Y_LPARAM(xy); - } + } if (UseReferenceRect) {