Skip to content

Commit

Permalink
prevent mouse input when window loses focus
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Jul 9, 2024
1 parent 5846abe commit 5954a55
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions samples/golf/buildnumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef BUILD_NUMBER_H_
#define BUILD_NUMBER_H_

#define BUILDNUMBER 6766
#define BUILDNUMBER_STR "6766"
#define BUILDNUMBER 6767
#define BUILDNUMBER_STR "6767"

#endif /* BUILD_NUMBER_H_ */
32 changes: 32 additions & 0 deletions samples/golf/src/golf/GolfState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,38 @@ bool GolfState::handleEvent(const cro::Event& evt)
}
}

else if (evt.type == SDL_WINDOWEVENT)
{
switch (evt.window.event)
{
default: break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
//this needs to be delayed a frame so mouse clincking on the
//open window doesn't get sent to the input parser
if (m_currentPlayer.client == m_sharedData.localConnectionData.connectionID
&& !m_sharedData.localConnectionData.playerData[m_currentPlayer.player].isCPU)
{
auto entity = m_uiScene.createEntity();
entity.addComponent<cro::Callback>().active = true;
entity.getComponent<cro::Callback>().function =
[&](cro::Entity e, float)
{
m_inputParser.setSuspended(false);
e.getComponent<cro::Callback>().active = false;
m_uiScene.destroyEntity(e);
};
}
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
if (m_currentPlayer.client == m_sharedData.localConnectionData.connectionID
&& !m_sharedData.localConnectionData.playerData[m_currentPlayer.player].isCPU)
{
m_inputParser.setSuspended(true);
}
break;
}
}

m_gameScene.forwardEvent(evt);
m_skyScene.forwardEvent(evt);
m_uiScene.forwardEvent(evt);
Expand Down

0 comments on commit 5954a55

Please sign in to comment.