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
master
cutealien 2009-12-13 10:39:29 +00:00
parent dae1088202
commit 9b50b09ea3
8 changed files with 73 additions and 18 deletions

View File

@ -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)

View File

@ -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. <br>
So far the following messages are cleared:<br>
Win32: All keyboard and mouse messages<br>
Linux: All messages<br>
All other devices are not yet supported here.<br>
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. */

View File

@ -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_

View File

@ -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
{

View File

@ -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

View File

@ -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();

View File

@ -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)
{

View File

@ -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)
{