CCComponent.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 __CC_FRAMEWORK_COMPONENT_H__
  22. #define __CC_FRAMEWORK_COMPONENT_H__
  23. /// @cond DO_NOT_SHOW
  24. #include <string>
  25. #include "base/CCRef.h"
  26. #include "base/CCScriptSupport.h"
  27. NS_CC_BEGIN
  28. class Node;
  29. enum {
  30. kComponentOnEnter,
  31. kComponentOnExit,
  32. kComponentOnAdd,
  33. kComponentOnRemove,
  34. kComponentOnUpdate
  35. };
  36. class CC_DLL Component : public Ref
  37. {
  38. public:
  39. static Component* create();
  40. /**
  41. * @js NA
  42. * @lua NA
  43. */
  44. virtual ~Component();
  45. virtual bool init();
  46. bool isEnabled() const { return _enabled; }
  47. virtual void setEnabled(bool enabled);
  48. const std::string& getName() const { return _name; }
  49. virtual void setName(const std::string& name) { _name = name; }
  50. Node* getOwner() const { return _owner; }
  51. virtual void setOwner(Node *owner);
  52. virtual void update(float delta);
  53. virtual bool serialize(void* r);
  54. virtual void onEnter();
  55. virtual void onExit();
  56. virtual void onAdd();
  57. virtual void onRemove();
  58. CC_CONSTRUCTOR_ACCESS:
  59. /**
  60. * @js ctor
  61. */
  62. Component();
  63. protected:
  64. Node* _owner;
  65. std::string _name;
  66. bool _enabled;
  67. #if CC_ENABLE_SCRIPT_BINDING
  68. ccScriptType _scriptType; ///< type of script binding, lua or javascript
  69. #endif
  70. };
  71. NS_CC_END
  72. /// @endcond
  73. #endif // __CC_FRAMEWORK_COMPONENT_H__