CCComponent.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /****************************************************************************
  2. Copyright (c) 2013-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CC_FRAMEWORK_COMPONENT_H__
  21. #define __CC_FRAMEWORK_COMPONENT_H__
  22. /// @cond DO_NOT_SHOW
  23. #include <string>
  24. #include "base/CCRef.h"
  25. #include "base/CCScriptSupport.h"
  26. NS_CC_BEGIN
  27. class Node;
  28. enum {
  29. kComponentOnEnter,
  30. kComponentOnExit,
  31. kComponentOnAdd,
  32. kComponentOnRemove,
  33. kComponentOnUpdate
  34. };
  35. class CC_DLL Component : public Ref
  36. {
  37. public:
  38. static Component* create();
  39. /**
  40. * @js NA
  41. * @lua NA
  42. */
  43. virtual ~Component();
  44. virtual bool init();
  45. bool isEnabled() const { return _enabled; }
  46. virtual void setEnabled(bool enabled);
  47. const std::string& getName() const { return _name; }
  48. virtual void setName(const std::string& name) { _name = name; }
  49. Node* getOwner() const { return _owner; }
  50. virtual void setOwner(Node *owner);
  51. virtual void update(float delta);
  52. virtual bool serialize(void* r);
  53. virtual void onEnter();
  54. virtual void onExit();
  55. virtual void onAdd();
  56. virtual void onRemove();
  57. CC_CONSTRUCTOR_ACCESS:
  58. /**
  59. * @js ctor
  60. */
  61. Component();
  62. protected:
  63. Node* _owner;
  64. std::string _name;
  65. bool _enabled;
  66. #if CC_ENABLE_SCRIPT_BINDING
  67. ccScriptType _scriptType; ///< type of script binding, lua or javascript
  68. #endif
  69. };
  70. NS_CC_END
  71. /// @endcond
  72. #endif // __CC_FRAMEWORK_COMPONENT_H__