@ -99,9 +99,6 @@ namespace SFO
void InputWrapper : : capture ( )
void InputWrapper : : capture ( )
{
{
SDL_Event evt ;
SDL_Event evt ;
bool resize = false ;
size_t size_x = 0 ;
size_t size_y = 0 ;
while ( SDL_PollEvent ( & evt ) )
while ( SDL_PollEvent ( & evt ) )
{
{
switch ( evt . type )
switch ( evt . type )
@ -125,25 +122,42 @@ namespace SFO
case SDL_MOUSEBUTTONUP :
case SDL_MOUSEBUTTONUP :
mMouseListener - > mouseReleased ( evt . button , evt . button . button ) ;
mMouseListener - > mouseReleased ( evt . button , evt . button . button ) ;
break ;
break ;
case SDL_KEYDOWN :
case SDL_KEYDOWN :
_handleKeyPress ( evt . key ) ;
_handleKeyPress ( evt . key ) ;
break ;
break ;
case SDL_KEYUP :
case SDL_KEYUP :
mKeyboardListener - > keyReleased ( evt . key ) ;
mKeyboardListener - > keyReleased ( evt . key ) ;
break ;
break ;
case SDL_WINDOWEVENT_RESIZED :
case SDL_WINDOWEVENT :
resize = true ;
handleWindowEvent ( evt ) ;
size_x = evt . window . data1 ;
size_y = evt . window . data2 ;
break ;
break ;
case SDL_QUIT :
case SDL_QUIT :
Ogre : : Root : : getSingleton ( ) . queueEndRendering ( ) ;
Ogre : : Root : : getSingleton ( ) . queueEndRendering ( ) ;
break ;
break ;
default :
std : : cerr < < " Unhandled SDL event of type " < < evt . type < < std : : endl ;
break ;
}
}
}
}
if ( resize )
}
mOgreWindow - > resize ( size_x , size_y ) ;
void InputWrapper : : handleWindowEvent ( const SDL_Event & evt )
{
switch ( evt . window . event ) {
case SDL_WINDOWEVENT_ENTER :
mMouseInWindow = true ;
break ;
case SDL_WINDOWEVENT_LEAVE :
mMouseInWindow = false ;
SDL_SetWindowGrab ( mSDLWindow , SDL_FALSE ) ;
SDL_SetRelativeMouseMode ( SDL_FALSE ) ;
break ;
case SDL_WINDOWEVENT_RESIZED :
case SDL_WINDOWEVENT_FOCUS_GAINED :
case SDL_WINDOWEVENT_FOCUS_LOST :
case SDL_WINDOWEVENT_CLOSE :
break ;
}
}
}
bool InputWrapper : : isModifierHeld ( int mod )
bool InputWrapper : : isModifierHeld ( int mod )
@ -163,25 +177,25 @@ namespace SFO
/// \brief Locks the pointer to the window
/// \brief Locks the pointer to the window
void InputWrapper : : setGrabPointer ( bool grab )
void InputWrapper : : setGrabPointer ( bool grab )
{
{
mGrabPointer = grab ;
mGrabPointer = grab & & mMouseInWindow ;
SDL_SetWindowGrab ( mSDLWindow , grab ? SDL_TRUE : SDL_FALSE ) ;
SDL_SetWindowGrab ( mSDLWindow , grab && mMouseInWindow ? SDL_TRUE : SDL_FALSE ) ;
}
}
/// \brief Set the mouse to relative positioning. Doesn't move the cursor
/// \brief Set the mouse to relative positioning. Doesn't move the cursor
/// and disables mouse acceleration.
/// and disables mouse acceleration.
void InputWrapper : : setMouseRelative ( bool relative )
void InputWrapper : : setMouseRelative ( bool relative )
{
{
if ( mMouseRelative = = relative )
if ( mMouseRelative = = relative & & mMouseInWindow )
return ;
return ;
mMouseRelative = relative ;
mMouseRelative = relative & & mMouseInWindow ;
mWrapPointer = false ;
mWrapPointer = false ;
//eep, wrap the pointer manually if the input driver doesn't support
//eep, wrap the pointer manually if the input driver doesn't support
//relative positioning natively
//relative positioning natively
int success = SDL_SetRelativeMouseMode ( relative ? SDL_TRUE : SDL_FALSE ) ;
int success = SDL_SetRelativeMouseMode ( relative && mMouseInWindow ? SDL_TRUE : SDL_FALSE ) ;
if ( relative & & success ! = 0 )
if ( relative & & mMouseInWindow & & success ! = 0 )
mWrapPointer = true ;
mWrapPointer = true ;
//now remove all mouse events using the old setting from the queue
//now remove all mouse events using the old setting from the queue