Platform.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Implementation of base platform-agnostic platform functionality.
  2. #include "Base.h"
  3. #include "Platform.h"
  4. #include "Game.h"
  5. #include "ScriptController.h"
  6. #include "Form.h"
  7. namespace gameplay
  8. {
  9. void Platform::touchEventInternal(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex, bool actuallyMouse)
  10. {
  11. if (actuallyMouse || !Form::touchEventInternal(evt, x, y, contactIndex))
  12. {
  13. Game::getInstance()->touchEvent(evt, x, y, contactIndex);
  14. Game::getInstance()->getScriptController()->touchEvent(evt, x, y, contactIndex);
  15. }
  16. }
  17. void Platform::keyEventInternal(Keyboard::KeyEvent evt, int key)
  18. {
  19. if (!Form::keyEventInternal(evt, key))
  20. {
  21. Game::getInstance()->keyEvent(evt, key);
  22. Game::getInstance()->getScriptController()->keyEvent(evt, key);
  23. }
  24. }
  25. bool Platform::mouseEventInternal(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
  26. {
  27. if (Form::mouseEventInternal(evt, x, y, wheelDelta))
  28. {
  29. return true;
  30. }
  31. else if (Game::getInstance()->mouseEvent(evt, x, y, wheelDelta))
  32. {
  33. return true;
  34. }
  35. else
  36. {
  37. return Game::getInstance()->getScriptController()->mouseEvent(evt, x, y, wheelDelta);
  38. }
  39. }
  40. void Platform::resizeEventInternal(unsigned int width, unsigned int height)
  41. {
  42. // Update the width and height of the game
  43. Game* game = Game::getInstance();
  44. if (game->_width != width || game->_height != height)
  45. {
  46. game->_width = width;
  47. game->_height = height;
  48. game->resizeEvent(width, height);
  49. game->getScriptController()->resizeEvent(width, height);
  50. }
  51. }
  52. void Platform::gamepadEventInternal(Gamepad::GamepadEvent evt, Gamepad* gamepad, unsigned int analogIndex)
  53. {
  54. switch(evt)
  55. {
  56. case Gamepad::CONNECTED_EVENT:
  57. case Gamepad::DISCONNECTED_EVENT:
  58. Game::getInstance()->gamepadEvent(evt, gamepad);
  59. Game::getInstance()->getScriptController()->gamepadEvent(evt, gamepad);
  60. break;
  61. case Gamepad::BUTTON_EVENT:
  62. case Gamepad::JOYSTICK_EVENT:
  63. case Gamepad::TRIGGER_EVENT:
  64. Form::gamepadEventInternal(evt, gamepad, analogIndex);
  65. break;
  66. }
  67. }
  68. void Platform::gamepadEventConnectedInternal(GamepadHandle handle, unsigned int buttonCount, unsigned int joystickCount, unsigned int triggerCount,
  69. unsigned int vendorId, unsigned int productId, const char* vendorString, const char* productString)
  70. {
  71. Gamepad::add(handle, buttonCount, joystickCount, triggerCount, vendorId, productId, vendorString, productString);
  72. }
  73. void Platform::gamepadEventDisconnectedInternal(GamepadHandle handle)
  74. {
  75. Gamepad::remove(handle);
  76. }
  77. }