CCEventController.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /****************************************************************************
  2. Copyright (c) 2014 cocos2d-x.org
  3. Copyright (c) 2014-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #ifndef __cocos2d_libs__EventController__
  23. #define __cocos2d_libs__EventController__
  24. #include "platform/CCPlatformMacros.h"
  25. #include "base/CCEvent.h"
  26. /**
  27. * @addtogroup base
  28. * @{
  29. */
  30. NS_CC_BEGIN
  31. /// @cond EventController
  32. class Controller;
  33. class EventListenerController;
  34. /** @class EventController
  35. * @brief Controller event.
  36. */
  37. class CC_DLL EventController : public Event
  38. {
  39. public:
  40. /** ControllerEventType Controller event type.*/
  41. enum class ControllerEventType
  42. {
  43. CONNECTION,
  44. BUTTON_STATUS_CHANGED,
  45. AXIS_STATUS_CHANGED,
  46. };
  47. /** Create a EventController with controller event type, controller and key code.
  48. *
  49. * @param type A given controller event type.
  50. * @param controller A given controller pointer.
  51. * @param keyCode A given key code.
  52. * @return An autoreleased EventController object.
  53. */
  54. EventController(ControllerEventType type, Controller* controller, int keyCode);
  55. /** Create a EventController with controller event type, controller and whether or not is connected.
  56. *
  57. * @param type A given controller event type.
  58. * @param controller A given controller pointer.
  59. * @param isConnected True if it is connected.
  60. * @return An autoreleased EventController object.
  61. */
  62. EventController(ControllerEventType type, Controller* controller, bool isConnected);
  63. /** Gets the event type of the controller.
  64. *
  65. * @return The event type of the controller.
  66. */
  67. ControllerEventType getControllerEventType() const { return _controllerEventType; }
  68. Controller* getController() const { return _controller; }
  69. /** Gets the key code of the controller.
  70. *
  71. * @return The key code of the controller.
  72. */
  73. int getKeyCode() const{ return _keyCode; }
  74. void setKeyCode(int keyCode) { _keyCode = keyCode;}
  75. /** Sets the connect status.
  76. *
  77. * @param True if it's connected.
  78. */
  79. void setConnectStatus(bool isConnected) {_isConnected = isConnected;}
  80. /** Gets the connect status.
  81. *
  82. * @return True if it's connected.
  83. */
  84. bool isConnected() const { return _isConnected; }
  85. protected:
  86. ControllerEventType _controllerEventType;
  87. Controller* _controller;
  88. int _keyCode;
  89. bool _isConnected;
  90. friend class EventListenerController;
  91. };
  92. /// @endcond EventController
  93. NS_CC_END
  94. // end of base group
  95. /// @}
  96. #endif /* defined(__cocos2d_libs__EventController__) */