CCClippingRectangleNode.h 3.5 KB

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