PolyInputEvent.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyEvent.h"
  22. #include "PolyVector2.h"
  23. #include "PolyInputKeys.h"
  24. namespace Polycode {
  25. class TouchInfo {
  26. public:
  27. static const int TYPEBASE = 0x500;
  28. static const int TYPE_TOUCH = TYPEBASE + 0;
  29. static const int TYPE_PEN = TYPEBASE + 1;
  30. TouchInfo();
  31. int id;
  32. Vector2 position;
  33. int type;
  34. };
  35. /*
  36. class PointerInfo {
  37. public:
  38. int id;
  39. Vector2 position;
  40. int flag;
  41. };
  42. */
  43. /**
  44. * Event dispatched by CoreInput. This event is dispatched by CoreInput when input happens.
  45. */
  46. class _PolyExport InputEvent : public Event {
  47. public:
  48. InputEvent();
  49. InputEvent(Vector2 mousePosition,int timestamp);
  50. // InputEvent(PolyKEY key, int timestamp);
  51. InputEvent(PolyKEY key, wchar_t charCode, int timestamp);
  52. virtual ~InputEvent();
  53. // ----------------------------------------------------------------------------------------------------------------
  54. /** @name Input event types.
  55. * Possible input event types dispatched by CoreInput.
  56. */
  57. //@{
  58. static const int EVENTBASE_INPUTEVENT = 0x400;
  59. static const int EVENT_MOUSEDOWN = EVENTBASE_INPUTEVENT+0;
  60. static const int EVENT_MOUSEUP = EVENTBASE_INPUTEVENT+1;
  61. static const int EVENT_MOUSEMOVE = EVENTBASE_INPUTEVENT+2;
  62. static const int EVENT_MOUSEOVER = EVENTBASE_INPUTEVENT+3;
  63. static const int EVENT_MOUSEOUT = EVENTBASE_INPUTEVENT+4;
  64. static const int EVENT_DOUBLECLICK = EVENTBASE_INPUTEVENT+5;
  65. static const int EVENT_MOUSEUP_OUTSIDE = EVENTBASE_INPUTEVENT+6;
  66. static const int EVENT_MOUSEWHEEL_UP = EVENTBASE_INPUTEVENT+7;
  67. static const int EVENT_MOUSEWHEEL_DOWN = EVENTBASE_INPUTEVENT+8;
  68. static const int EVENT_KEYDOWN = EVENTBASE_INPUTEVENT+13;
  69. static const int EVENT_KEYUP = EVENTBASE_INPUTEVENT+14;
  70. static const int EVENT_JOYBUTTON_DOWN = EVENTBASE_INPUTEVENT+15;
  71. static const int EVENT_JOYBUTTON_UP = EVENTBASE_INPUTEVENT+16;
  72. static const int EVENT_JOYAXIS_MOVED = EVENTBASE_INPUTEVENT+17;
  73. static const int EVENT_JOYDEVICE_ATTACHED = EVENTBASE_INPUTEVENT+18;
  74. static const int EVENT_JOYDEVICE_DETACHED = EVENTBASE_INPUTEVENT+19;
  75. static const int EVENT_TOUCHES_BEGAN = EVENTBASE_INPUTEVENT+20;
  76. static const int EVENT_TOUCHES_MOVED = EVENTBASE_INPUTEVENT+21;
  77. static const int EVENT_TOUCHES_ENDED = EVENTBASE_INPUTEVENT+22;
  78. //@}
  79. // ----------------------------------------------------------------------------------------------------------------
  80. /**
  81. * If this is a mouse click event, the mouse button that's pressed.
  82. */
  83. int mouseButton;
  84. /**
  85. * If this is a mouse event, the mouse position.
  86. */
  87. Vector2 mousePosition;
  88. Vector2 getMousePosition() { return mousePosition; }
  89. PolyKEY getKey() { return key; }
  90. int getMouseButton() { return mouseButton; }
  91. /**
  92. * If this is a key event, the key code that's coming down or up.
  93. */
  94. PolyKEY key;
  95. wchar_t getCharCode();
  96. int keyCode() { return key; }
  97. /**
  98. * If this is a key press event, this will contain the unicode character that's being typed.
  99. */
  100. wchar_t charCode;
  101. int timestamp;
  102. std::vector<TouchInfo> touches;
  103. TouchInfo touch;
  104. int touchType;
  105. unsigned int joystickDeviceID;
  106. float joystickAxisValue;
  107. unsigned int joystickButton;
  108. unsigned int joystickAxis;
  109. unsigned int joystickIndex;
  110. Number hitDistance;
  111. protected:
  112. };
  113. }