Platform.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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::gestureSwipeEventInternal(int x, int y, int direction)
  41. {
  42. // TODO: Add support to Form for gestures
  43. Game::getInstance()->gestureSwipeEvent(x, y, direction);
  44. Game::getInstance()->getScriptController()->gestureSwipeEvent(x, y, direction);
  45. }
  46. void Platform::gesturePinchEventInternal(int x, int y, float scale)
  47. {
  48. // TODO: Add support to Form for gestures
  49. Game::getInstance()->gesturePinchEvent(x, y, scale);
  50. Game::getInstance()->getScriptController()->gesturePinchEvent(x, y, scale);
  51. }
  52. void Platform::gestureTapEventInternal(int x, int y)
  53. {
  54. // TODO: Add support to Form for gestures
  55. Game::getInstance()->gestureTapEvent(x, y);
  56. Game::getInstance()->getScriptController()->gestureTapEvent(x, y);
  57. }
  58. void Platform::gestureLongTapEventInternal(int x, int y, float duration)
  59. {
  60. // TODO: Add support to Form for gestures
  61. Game::getInstance()->gestureLongTapEvent(x, y, duration);
  62. Game::getInstance()->getScriptController()->gestureLongTapEvent(x, y, duration);
  63. }
  64. void Platform::gestureDragEventInternal(int x, int y)
  65. {
  66. // TODO: Add support to Form for gestures
  67. Game::getInstance()->gestureDragEvent(x, y);
  68. Game::getInstance()->getScriptController()->gestureDragEvent(x, y);
  69. }
  70. void Platform::gestureDropEventInternal(int x, int y)
  71. {
  72. // TODO: Add support to Form for gestures
  73. Game::getInstance()->gestureDropEvent(x, y);
  74. Game::getInstance()->getScriptController()->gestureDropEvent(x, y);
  75. }
  76. void Platform::resizeEventInternal(unsigned int width, unsigned int height)
  77. {
  78. // Update the width and height of the game
  79. Game* game = Game::getInstance();
  80. if (game->_width != width || game->_height != height)
  81. {
  82. game->_width = width;
  83. game->_height = height;
  84. game->resizeEvent(width, height);
  85. game->getScriptController()->resizeEvent(width, height);
  86. }
  87. Form::resizeEventInternal(width, height);
  88. }
  89. void Platform::gamepadEventInternal(Gamepad::GamepadEvent evt, Gamepad* gamepad, unsigned int analogIndex)
  90. {
  91. if (!Form::gamepadEventInternal(evt, gamepad, analogIndex))
  92. {
  93. Game::getInstance()->gamepadEvent(evt, gamepad);
  94. Game::getInstance()->getScriptController()->gamepadEvent(evt, gamepad);
  95. }
  96. }
  97. void Platform::gamepadEventConnectedInternal(GamepadHandle handle, unsigned int buttonCount, unsigned int joystickCount, unsigned int triggerCount,
  98. unsigned int vendorId, unsigned int productId, const char* vendorString, const char* productString)
  99. {
  100. Gamepad::add(handle, buttonCount, joystickCount, triggerCount, vendorId, productId, vendorString, productString);
  101. }
  102. void Platform::gamepadEventDisconnectedInternal(GamepadHandle handle)
  103. {
  104. Gamepad::remove(handle);
  105. }
  106. }