[GameState] Now release the mouse when the window loses focus.

This commit is contained in:
Quentin Bazin 2018-06-30 04:45:49 +02:00
parent 6b0fc907ee
commit cae6fee434

View File

@ -66,6 +66,16 @@ void GameState::onEvent(const SDL_Event &event) {
else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE && &m_stateStack->top() == this) {
m_stateStack->push<PauseMenuState>(this);
}
else if (event.type == SDL_WINDOWEVENT) {
if (event.window.event == SDL_WINDOWEVENT_LEAVE) {
Mouse::setCursorGrabbed(false);
Mouse::setCursorVisible(true);
}
else if (event.window.event == SDL_WINDOWEVENT_ENTER) {
Mouse::setCursorGrabbed(true);
Mouse::setCursorVisible(false);
}
}
m_hotbar.onEvent(event);
m_blockCursor.onEvent(event, m_hotbar);