CCClippingRectangleNode.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * cocos2d for iPhone: http://www.cocos2d-iphone.org
  3. * cocos2d-x: http://www.cocos2d-x.org
  4. *
  5. * Copyright (c) 2012 Pierre-David Bélanger
  6. * Copyright (c) 2012 cocos2d-x.org
  7. * Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef __MISCNODE_CCCLIPPING_RECTANGLE_NODE_H__
  29. #define __MISCNODE_CCCLIPPING_RECTANGLE_NODE_H__
  30. #include "2d/CCNode.h"
  31. #include "renderer/CCCustomCommand.h"
  32. #include "platform/CCGL.h"
  33. NS_CC_BEGIN
  34. /**
  35. * @addtogroup _2d
  36. * @{
  37. */
  38. /**
  39. @brief Clipping Rectangle Node.
  40. @details A node that clipped with specified rectangle.
  41. The region of ClippingRectangleNode doesn't support any transform except scale.
  42. @js NA
  43. */
  44. class CC_DLL ClippingRectangleNode : public Node
  45. {
  46. public:
  47. /**
  48. @brief Create node with specified clipping region.
  49. @param clippingRegion Specify the clipping rectangle.
  50. @return If the creation success, return a pointer of ClippingRectangleNode; otherwise return nil.
  51. */
  52. static ClippingRectangleNode* create(const Rect& clippingRegion);
  53. /**
  54. @brief Create a clipping rectangle node.
  55. @return If the creation success, return a pointer of ClippingRectangleNode; otherwise return nil.
  56. */
  57. static ClippingRectangleNode* create();
  58. /**
  59. @brief Get the clipping rectangle.
  60. @return The clipping rectangle.
  61. */
  62. const Rect& getClippingRegion() const {
  63. return _clippingRegion;
  64. }
  65. /**
  66. @brief Set the clipping rectangle.
  67. @param clippingRegion Specify the clipping rectangle.
  68. */
  69. void setClippingRegion(const Rect& clippingRegion);
  70. /**
  71. @brief Get whether the clipping is enabled or not.
  72. @return Whether the clipping is enabled or not. Default is true.
  73. */
  74. bool isClippingEnabled() const {
  75. return _clippingEnabled;
  76. }
  77. /**
  78. @brief Enable/Disable the clipping.
  79. @param enabled Pass true to enable clipping. Pass false to disable clipping.
  80. */
  81. void setClippingEnabled(bool enabled) {
  82. _clippingEnabled = enabled;
  83. }
  84. //virtual void draw(Renderer* renderer, const Mat4 &transform, uint32_t flags) override;
  85. virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
  86. protected:
  87. ClippingRectangleNode()
  88. : _clippingEnabled(true)
  89. {
  90. }
  91. void onBeforeVisitScissor();
  92. void onAfterVisitScissor();
  93. Rect _clippingRegion;
  94. bool _clippingEnabled;
  95. CustomCommand _beforeVisitCmdScissor;
  96. CustomCommand _afterVisitCmdScissor;
  97. };
  98. // end of _2d group
  99. /// @}
  100. NS_CC_END
  101. #endif