CCEvent.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /****************************************************************************
  2. Copyright (c) 2013-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  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 __CCEVENT_H__
  22. #define __CCEVENT_H__
  23. #include "base/CCRef.h"
  24. #include "platform/CCPlatformMacros.h"
  25. /**
  26. * @addtogroup base
  27. * @{
  28. */
  29. NS_CC_BEGIN
  30. class Node;
  31. /** @class Event
  32. * @brief Base class of all kinds of events.
  33. */
  34. class CC_DLL Event : public Ref
  35. {
  36. public:
  37. /** Type Event type.*/
  38. enum class Type
  39. {
  40. TOUCH,
  41. KEYBOARD,
  42. ACCELERATION,
  43. MOUSE,
  44. FOCUS,
  45. GAME_CONTROLLER,
  46. CUSTOM
  47. };
  48. CC_CONSTRUCTOR_ACCESS:
  49. /** Constructor */
  50. Event(Type type);
  51. public:
  52. /** Destructor.
  53. */
  54. virtual ~Event();
  55. /** Gets the event type.
  56. *
  57. * @return The event type.
  58. */
  59. Type getType() const { return _type; }
  60. /** Stops propagation for current event.
  61. */
  62. void stopPropagation() { _isStopped = true; }
  63. /** Checks whether the event has been stopped.
  64. *
  65. * @return True if the event has been stopped.
  66. */
  67. bool isStopped() const { return _isStopped; }
  68. /** Gets current target of the event.
  69. * @return The target with which the event associates.
  70. * @note It's only available when the event listener is associated with node.
  71. * It returns 0 when the listener is associated with fixed priority.
  72. */
  73. Node* getCurrentTarget() { return _currentTarget; }
  74. protected:
  75. /** Sets current target */
  76. void setCurrentTarget(Node* target) { _currentTarget = target; }
  77. Type _type; ///< Event type
  78. bool _isStopped; ///< whether the event has been stopped.
  79. Node* _currentTarget; ///< Current target
  80. friend class EventDispatcher;
  81. };
  82. NS_CC_END
  83. // end of base group
  84. /// @}
  85. #endif // __CCEVENT_H__