Platform.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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()->touchEventInternal(evt, x, y, contactIndex);
  14. }
  15. }
  16. void Platform::keyEventInternal(Keyboard::KeyEvent evt, int key)
  17. {
  18. if (!Form::keyEventInternal(evt, key))
  19. {
  20. Game::getInstance()->keyEventInternal(evt, key);
  21. }
  22. }
  23. bool Platform::mouseEventInternal(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
  24. {
  25. if (Form::mouseEventInternal(evt, x, y, wheelDelta))
  26. return true;
  27. return Game::getInstance()->mouseEventInternal(evt, x, y, wheelDelta);
  28. }
  29. void Platform::gestureSwipeEventInternal(int x, int y, int direction)
  30. {
  31. Game::getInstance()->gestureSwipeEventInternal(x, y, direction);
  32. }
  33. void Platform::gesturePinchEventInternal(int x, int y, float scale)
  34. {
  35. Game::getInstance()->gesturePinchEventInternal(x, y, scale);
  36. }
  37. void Platform::gestureTapEventInternal(int x, int y)
  38. {
  39. Game::getInstance()->gestureTapEventInternal(x, y);
  40. }
  41. void Platform::gestureLongTapEventInternal(int x, int y, float duration)
  42. {
  43. Game::getInstance()->gestureLongTapEventInternal(x, y, duration);
  44. }
  45. void Platform::gestureDragEventInternal(int x, int y)
  46. {
  47. Game::getInstance()->gestureDragEventInternal(x, y);
  48. }
  49. void Platform::gestureDropEventInternal(int x, int y)
  50. {
  51. Game::getInstance()->gestureDropEventInternal(x, y);
  52. }
  53. void Platform::resizeEventInternal(unsigned int width, unsigned int height)
  54. {
  55. Game::getInstance()->resizeEventInternal(width, height);
  56. Form::resizeEventInternal(width, height);
  57. }
  58. void Platform::gamepadEventConnectedInternal(GamepadHandle handle, unsigned int buttonCount, unsigned int joystickCount, unsigned int triggerCount, const char* name)
  59. {
  60. Gamepad::add(handle, buttonCount, joystickCount, triggerCount, name);
  61. }
  62. void Platform::gamepadEventDisconnectedInternal(GamepadHandle handle)
  63. {
  64. Gamepad::remove(handle);
  65. }
  66. void Platform::gamepadButtonPressedEventInternal(GamepadHandle handle, Gamepad::ButtonMapping mapping)
  67. {
  68. Gamepad* gamepad = Gamepad::getGamepad(handle);
  69. unsigned int newButtons = gamepad->_buttons | (1 << mapping);
  70. gamepad->setButtons(newButtons);
  71. Form::gamepadButtonEventInternal(gamepad);
  72. }
  73. void Platform::gamepadButtonReleasedEventInternal(GamepadHandle handle, Gamepad::ButtonMapping mapping)
  74. {
  75. Gamepad* gamepad = Gamepad::getGamepad(handle);
  76. unsigned int newButtons = gamepad->_buttons & ~(1 << mapping);
  77. gamepad->setButtons(newButtons);
  78. Form::gamepadButtonEventInternal(gamepad);
  79. }
  80. void Platform::gamepadTriggerChangedEventInternal(GamepadHandle handle, unsigned int index, float value)
  81. {
  82. Gamepad* gamepad = Gamepad::getGamepad(handle);
  83. gamepad->setTriggerValue(index, value);
  84. Form::gamepadTriggerEventInternal(gamepad, index);
  85. }
  86. void Platform::gamepadJoystickChangedEventInternal(GamepadHandle handle, unsigned int index, float x, float y)
  87. {
  88. Gamepad* gamepad = Gamepad::getGamepad(handle);
  89. gamepad->setJoystickValue(index, x, y);
  90. Form::gamepadJoystickEventInternal(gamepad, index);
  91. }
  92. }