InputEvent.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /****************************************************************************
  2. Copyright (c) 2013 cocos2d-x.org
  3. Copyright (c) Microsoft Open Technologies, Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __WINRT_INPUT_EVENT__
  22. #define __WINRT_INPUT_EVENT__
  23. #include "platform/CCPlatformMacros.h"
  24. #include "platform/winrt/InputEventTypes.h"
  25. #include "base/ccTypes.h"
  26. #include <agile.h>
  27. NS_CC_BEGIN
  28. enum PointerEventType
  29. {
  30. PointerPressed,
  31. PointerMoved,
  32. PointerReleased,
  33. MousePressed,
  34. MouseMoved,
  35. MouseReleased,
  36. MouseWheelChanged,
  37. };
  38. enum MouseButton
  39. {
  40. Left = 0,
  41. Right = 1,
  42. Middle = 2,
  43. None
  44. };
  45. class CC_DLL InputEvent
  46. {
  47. public:
  48. InputEvent() {};
  49. virtual ~InputEvent() {};
  50. virtual void execute() = 0;
  51. };
  52. class CC_DLL AccelerometerEvent : public InputEvent
  53. {
  54. public:
  55. AccelerometerEvent(const cocos2d::Acceleration& event);
  56. virtual void execute();
  57. private:
  58. cocos2d::Acceleration m_event;
  59. };
  60. class CC_DLL PointerEvent : public InputEvent
  61. {
  62. public:
  63. PointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args);
  64. virtual void execute();
  65. private:
  66. PointerEventType m_type;
  67. Platform::Agile<Windows::UI::Core::PointerEventArgs> m_args;
  68. };
  69. class CC_DLL KeyboardEvent : public InputEvent
  70. {
  71. public:
  72. KeyboardEvent(Cocos2dKeyEvent type);
  73. KeyboardEvent(Cocos2dKeyEvent type, Platform::String^ text);
  74. virtual void execute();
  75. private:
  76. Cocos2dKeyEvent m_type;
  77. Platform::Agile<Platform::String> m_text;
  78. };
  79. enum WinRTKeyboardEventType
  80. {
  81. KeyPressed,
  82. KeyReleased,
  83. };
  84. class CC_DLL WinRTKeyboardEvent : public InputEvent
  85. {
  86. public:
  87. WinRTKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs^ args);
  88. virtual void execute();
  89. private:
  90. WinRTKeyboardEventType m_type;
  91. Platform::Agile<Windows::UI::Core::KeyEventArgs> m_key;
  92. };
  93. class CC_DLL BackButtonEvent : public InputEvent
  94. {
  95. public:
  96. BackButtonEvent();
  97. virtual void execute();
  98. };
  99. class CC_DLL CustomInputEvent : public InputEvent
  100. {
  101. public:
  102. CustomInputEvent(const std::function<void()>&);
  103. virtual void execute();
  104. private:
  105. std::function<void()> m_fun;
  106. };
  107. class UIEditBoxEvent : public cocos2d::InputEvent
  108. {
  109. public:
  110. UIEditBoxEvent(Platform::Object^ sender, Platform::String^ text, Windows::Foundation::EventHandler<Platform::String^>^ handle);
  111. virtual void execute();
  112. protected:
  113. Platform::Agile<Platform::Object^> m_sender;
  114. Platform::Agile<Platform::String^> m_text;
  115. Platform::Agile<Windows::Foundation::EventHandler<Platform::String^>^> m_handler;
  116. };
  117. ref class EndEventArgs sealed {
  118. public:
  119. EndEventArgs(int action, Platform::String^ text) : m_text(text), m_action(action) {}
  120. int GetAction() { return m_action; }
  121. Platform::String^ GetText() { return m_text; }
  122. private:
  123. int m_action;
  124. Platform::String^ m_text;
  125. };
  126. class UIEditBoxEndEvent : public cocos2d::InputEvent
  127. {
  128. public:
  129. UIEditBoxEndEvent(Platform::Object^ sender, Platform::String^ text, int action, Windows::Foundation::EventHandler<EndEventArgs^>^ handle);
  130. virtual void execute();
  131. protected:
  132. int m_action;
  133. Platform::Agile<Platform::Object^> m_sender;
  134. Platform::Agile<Platform::String^> m_text;
  135. Platform::Agile<Windows::Foundation::EventHandler<EndEventArgs^>^> m_handler;
  136. };
  137. NS_CC_END
  138. #endif // #ifndef __WINRT_INPUT_EVENT__