UIPageViewIndicator.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /****************************************************************************
  2. Copyright (c) 2015 Neo Kim (neo.kim@neofect.com)
  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 __UIPAGEVIEWINDICATOR_H__
  22. #define __UIPAGEVIEWINDICATOR_H__
  23. #include "ui/UIPageView.h"
  24. #include "2d/CCSprite.h"
  25. NS_CC_BEGIN
  26. /**
  27. * @addtogroup ui
  28. * @{
  29. */
  30. namespace ui {
  31. class PageViewIndicator : public ProtectedNode
  32. {
  33. public:
  34. /**
  35. * Create a page view indicator with its parent page view.
  36. * @return A page view indicator instance.
  37. */
  38. static PageViewIndicator* create();
  39. PageViewIndicator();
  40. virtual ~PageViewIndicator();
  41. void setDirection(PageView::Direction direction);
  42. void reset(ssize_t numberOfTotalPages);
  43. void indicate(ssize_t index);
  44. void clear();
  45. void setSpaceBetweenIndexNodes(float spaceBetweenIndexNodes);
  46. float getSpaceBetweenIndexNodes() const { return _spaceBetweenIndexNodes; }
  47. void setSelectedIndexColor(const Color3B& color) { _currentIndexNode->setColor(color); }
  48. const Color3B& getSelectedIndexColor() const { return _currentIndexNode->getColor(); }
  49. void setIndexNodesColor(const Color3B& indexNodesColor);
  50. const Color3B& getIndexNodesColor() const { return _indexNodesColor; }
  51. void setIndexNodesScale(float indexNodesScale);
  52. float getIndexNodesScale() const { return _indexNodesScale; }
  53. void setSelectedIndexOpacity(GLubyte opacity) { _currentIndexNode->setOpacity(opacity); }
  54. GLubyte getSelectedIndexOpacity() const { return _currentIndexNode->getOpacity(); }
  55. void setIndexNodesOpacity(GLubyte opacity);
  56. GLubyte getIndexNodesOpacity() const { return _indexNodesOpacity; }
  57. /**
  58. * Sets texture for index nodes.
  59. *
  60. * @param fileName File name of texture.
  61. * @param resType @see TextureResType .
  62. */
  63. void setIndexNodesTexture(const std::string& texName,Widget::TextureResType texType = Widget::TextureResType::LOCAL);
  64. protected:
  65. bool init() override;
  66. void increaseNumberOfPages();
  67. void decreaseNumberOfPages();
  68. void rearrange();
  69. PageView::Direction _direction;
  70. Vector<Sprite*> _indexNodes;
  71. Sprite* _currentIndexNode;
  72. Sprite* _currentOverlappingIndexNode;
  73. float _spaceBetweenIndexNodes;
  74. float _indexNodesScale;
  75. Color3B _indexNodesColor;
  76. GLubyte _indexNodesOpacity;
  77. bool _useDefaultTexture;
  78. std::string _indexNodesTextureFile;
  79. Widget::TextureResType _indexNodesTexType;
  80. };
  81. }
  82. // end of ui group
  83. /// @}
  84. NS_CC_END
  85. #endif /* defined(__UIPAGEVIEWINDICATOR_H__) */