1
0

CCEventController.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /****************************************************************************
  2. Copyright (c) 2014 cocos2d-x.org
  3. Copyright (c) 2014-2017 Chukong 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 __cocos2d_libs__EventController__
  22. #define __cocos2d_libs__EventController__
  23. #include "platform/CCPlatformMacros.h"
  24. #include "base/CCEvent.h"
  25. /**
  26. * @addtogroup base
  27. * @{
  28. */
  29. NS_CC_BEGIN
  30. /// @cond EventController
  31. class Controller;
  32. class EventListenerController;
  33. /** @class EventController
  34. * @brief Controller event.
  35. */
  36. class EventController : public Event
  37. {
  38. public:
  39. /** ControllerEventType Controller event type.*/
  40. enum class ControllerEventType
  41. {
  42. CONNECTION,
  43. BUTTON_STATUS_CHANGED,
  44. AXIS_STATUS_CHANGED,
  45. };
  46. /** Create a EventController with controller event type, controller and key code.
  47. *
  48. * @param type A given controller event type.
  49. * @param controller A given controller pointer.
  50. * @param keyCode A given key code.
  51. * @return An autoreleased EventController object.
  52. */
  53. EventController(ControllerEventType type, Controller* controller, int keyCode);
  54. /** Create a EventController with controller event type, controller and whether or not is connected.
  55. *
  56. * @param type A given controller event type.
  57. * @param controller A given controller pointer.
  58. * @param isConnected True if it is connected.
  59. * @return An autoreleased EventController object.
  60. */
  61. EventController(ControllerEventType type, Controller* controller, bool isConnected);
  62. /** Gets the event type of the controller.
  63. *
  64. * @return The event type of the controller.
  65. */
  66. ControllerEventType getControllerEventType() const { return _controllerEventType; }
  67. Controller* getController() const { return _controller; }
  68. /** Gets the key code of the controller.
  69. *
  70. * @return The key code of the controller.
  71. */
  72. int getKeyCode() const{ return _keyCode; }
  73. void setKeyCode(int keyCode) { _keyCode = keyCode;}
  74. /** Sets the connect status.
  75. *
  76. * @param True if it's connected.
  77. */
  78. void setConnectStatus(bool isConnected) {_isConnected = isConnected;}
  79. /** Gets the connect status.
  80. *
  81. * @return True if it's connected.
  82. */
  83. bool isConnected() const { return _isConnected; }
  84. protected:
  85. ControllerEventType _controllerEventType;
  86. Controller* _controller;
  87. int _keyCode;
  88. bool _isConnected;
  89. friend class EventListenerController;
  90. };
  91. /// @endcond EventController
  92. NS_CC_END
  93. // end of base group
  94. /// @}
  95. #endif /* defined(__cocos2d_libs__EventController__) */