|
|
|
@ -23,7 +23,11 @@ namespace SFO
|
|
|
|
|
mJoyListener(NULL),
|
|
|
|
|
mKeyboardListener(NULL),
|
|
|
|
|
mMouseListener(NULL),
|
|
|
|
|
mWindowListener(NULL)
|
|
|
|
|
mWindowListener(NULL),
|
|
|
|
|
mWindowHasFocus(true),
|
|
|
|
|
mWantGrab(false),
|
|
|
|
|
mWantRelative(false),
|
|
|
|
|
mWantMouseVisible(false)
|
|
|
|
|
{
|
|
|
|
|
_setupOISKeys();
|
|
|
|
|
}
|
|
|
|
@ -51,13 +55,16 @@ namespace SFO
|
|
|
|
|
switch(evt.type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
|
//ignore this if it happened due to a warp
|
|
|
|
|
// Ignore this if it happened due to a warp
|
|
|
|
|
if(!_handleWarpMotion(evt.motion))
|
|
|
|
|
{
|
|
|
|
|
mMouseListener->mouseMoved(_packageMouseMotion(evt));
|
|
|
|
|
// If in relative mode, don't trigger events unless window has focus
|
|
|
|
|
if (!mWantRelative || mWindowHasFocus)
|
|
|
|
|
mMouseListener->mouseMoved(_packageMouseMotion(evt));
|
|
|
|
|
|
|
|
|
|
//try to keep the mouse inside the window
|
|
|
|
|
_wrapMousePointer(evt.motion);
|
|
|
|
|
// Try to keep the mouse inside the window
|
|
|
|
|
if (mWindowHasFocus)
|
|
|
|
|
_wrapMousePointer(evt.motion);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SDL_MOUSEWHEEL:
|
|
|
|
@ -118,11 +125,11 @@ namespace SFO
|
|
|
|
|
switch (evt.window.event) {
|
|
|
|
|
case SDL_WINDOWEVENT_ENTER:
|
|
|
|
|
mMouseInWindow = true;
|
|
|
|
|
updateMouseSettings();
|
|
|
|
|
break;
|
|
|
|
|
case SDL_WINDOWEVENT_LEAVE:
|
|
|
|
|
mMouseInWindow = false;
|
|
|
|
|
SDL_SetWindowGrab(mSDLWindow, SDL_FALSE);
|
|
|
|
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
|
|
|
|
updateMouseSettings();
|
|
|
|
|
break;
|
|
|
|
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
|
|
|
|
int w,h;
|
|
|
|
@ -149,10 +156,15 @@ namespace SFO
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
|
|
|
|
mWindowHasFocus = true;
|
|
|
|
|
updateMouseSettings();
|
|
|
|
|
if (mWindowListener)
|
|
|
|
|
mWindowListener->windowFocusChange(true);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
|
mWindowHasFocus = false;
|
|
|
|
|
updateMouseSettings();
|
|
|
|
|
if (mWindowListener)
|
|
|
|
|
mWindowListener->windowFocusChange(false);
|
|
|
|
|
break;
|
|
|
|
@ -193,25 +205,43 @@ namespace SFO
|
|
|
|
|
/// \brief Locks the pointer to the window
|
|
|
|
|
void InputWrapper::setGrabPointer(bool grab)
|
|
|
|
|
{
|
|
|
|
|
mGrabPointer = grab && mMouseInWindow;
|
|
|
|
|
SDL_SetWindowGrab(mSDLWindow, grab && mMouseInWindow ? SDL_TRUE : SDL_FALSE);
|
|
|
|
|
mWantGrab = grab;
|
|
|
|
|
updateMouseSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// \brief Set the mouse to relative positioning. Doesn't move the cursor
|
|
|
|
|
/// and disables mouse acceleration.
|
|
|
|
|
void InputWrapper::setMouseRelative(bool relative)
|
|
|
|
|
{
|
|
|
|
|
if(mMouseRelative == relative && mMouseInWindow)
|
|
|
|
|
mWantRelative = relative;
|
|
|
|
|
updateMouseSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputWrapper::setMouseVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
mWantMouseVisible = visible;
|
|
|
|
|
updateMouseSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputWrapper::updateMouseSettings()
|
|
|
|
|
{
|
|
|
|
|
mGrabPointer = mWantGrab && mMouseInWindow && mWindowHasFocus;
|
|
|
|
|
SDL_SetWindowGrab(mSDLWindow, mGrabPointer ? SDL_TRUE : SDL_FALSE);
|
|
|
|
|
|
|
|
|
|
SDL_ShowCursor(mWantMouseVisible || !mWindowHasFocus);
|
|
|
|
|
|
|
|
|
|
bool relative = mWantRelative && mMouseInWindow && mWindowHasFocus;
|
|
|
|
|
if(mMouseRelative == relative)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mMouseRelative = relative && mMouseInWindow;
|
|
|
|
|
mMouseRelative = relative;
|
|
|
|
|
|
|
|
|
|
mWrapPointer = false;
|
|
|
|
|
|
|
|
|
|
//eep, wrap the pointer manually if the input driver doesn't support
|
|
|
|
|
//relative positioning natively
|
|
|
|
|
int success = SDL_SetRelativeMouseMode(relative && mMouseInWindow ? SDL_TRUE : SDL_FALSE);
|
|
|
|
|
if(relative && mMouseInWindow && success != 0)
|
|
|
|
|
int success = SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE);
|
|
|
|
|
if(relative && success != 0)
|
|
|
|
|
mWrapPointer = true;
|
|
|
|
|
|
|
|
|
|
//now remove all mouse events using the old setting from the queue
|
|
|
|
|