Skip to content

Commit

Permalink
fix android input
Browse files Browse the repository at this point in the history
  • Loading branch information
dgengin committed Jun 25, 2016
1 parent 570888c commit 9c4b630
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ void Game::processEvents()
case sf::Event::MouseMoved:
onMouseMoved(evt.mouseMove);
break;
#ifdef __ANDROID__
case sf::Event::TouchBegan:
onTouchBegan(evt.touch);
break;
case sf::Event::TouchMoved:
onTouchMoved(evt.touch);
break;
case sf::Event::TouchEnded:
onTouchEnded(evt.touch);
break;
#endif
default:
break;
}
Expand Down Expand Up @@ -232,6 +243,9 @@ void Game::onKeyPressed(const sf::Event::KeyEvent& evt)
if (disableInput == false)
{
keyPressed = evt;
#ifdef __ANDROID__
keyPressed.system = false;
#endif
}
}

Expand Down Expand Up @@ -269,7 +283,33 @@ void Game::onMouseMoved(const sf::Event::MouseMoveEvent& evt)
updateMouse(sf::Vector2i(evt.x, evt.y));
mouseMoved = true;
}
#ifdef __ANDROID__
void Game::onTouchBegan(const sf::Event::TouchEvent& evt)
{
updateMouse(sf::Vector2i(evt.x, evt.y));
sf::Event::MouseButtonEvent mouseEvt;
mouseEvt.button = sf::Mouse::Left;
mouseEvt.x = evt.x;
mouseEvt.y = evt.y;
onMouseButtonPressed(mouseEvt);
}

void Game::onTouchMoved(const sf::Event::TouchEvent& evt)
{
updateMouse(sf::Vector2i(evt.x, evt.y));
mouseMoved = true;
}

void Game::onTouchEnded(const sf::Event::TouchEvent& evt)
{
updateMouse(sf::Vector2i(evt.x, evt.y));
sf::Event::MouseButtonEvent mouseEvt;
mouseEvt.button = sf::Mouse::Left;
mouseEvt.x = evt.x;
mouseEvt.y = evt.y;
onMouseButtonReleased(mouseEvt);
}
#endif
void Game::updateMouse()
{
updateMouse(sf::Mouse::getPosition(window));
Expand Down
5 changes: 5 additions & 0 deletions src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class Game : public sf::NonCopyable
void onMouseButtonPressed(const sf::Event::MouseButtonEvent& evt);
void onMouseButtonReleased(const sf::Event::MouseButtonEvent& evt);
void onMouseMoved(const sf::Event::MouseMoveEvent& evt);
#ifdef __ANDROID__
void onTouchBegan(const sf::Event::TouchEvent& evt);
void onTouchMoved(const sf::Event::TouchEvent& evt);
void onTouchEnded(const sf::Event::TouchEvent& evt);
#endif

void updateMouse(const sf::Vector2i mousePos);
void checkKeyPress();
Expand Down
5 changes: 4 additions & 1 deletion src/Parser/ParseKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ namespace Parser
evt.alt = getBool(elem, "alt");
evt.control = getBool(elem, "control");
evt.shift = getBool(elem, "shift");
#ifdef __ANDROID__
evt.system = false;
#else
evt.system = getBool(elem, "system");

#endif
const auto& keyElem = elem["key"];

if (keyElem.IsArray() == true)
Expand Down

0 comments on commit 9c4b630

Please sign in to comment.