UITextAtlas.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 __UILABELATLAS_H__
  22. #define __UILABELATLAS_H__
  23. #include "ui/UIWidget.h"
  24. #include "ui/GUIExport.h"
  25. NS_CC_BEGIN
  26. /**
  27. * @addtogroup ui
  28. * @{
  29. */
  30. class Label;
  31. struct CC_DLL ResourceData;
  32. namespace ui {
  33. /**
  34. * @brief UI TextAtlas widget.
  35. */
  36. class CC_GUI_DLL TextAtlas : public Widget
  37. {
  38. DECLARE_CLASS_GUI_INFO
  39. public:
  40. /**
  41. * Default constructor.
  42. *
  43. * @lua new
  44. */
  45. TextAtlas();
  46. /**
  47. * Default destructor.
  48. *
  49. * @lua NA
  50. */
  51. virtual ~TextAtlas();
  52. /**
  53. * Create a TexAtlas object.
  54. *
  55. * @return An autoreleased TextAtlas object.
  56. */
  57. static TextAtlas* create();
  58. /**
  59. * Create a LabelAtlas from a char map file.
  60. *
  61. * @param stringValue A given string needs to be displayed.
  62. * @param charMapFile A given char map file name.
  63. * @param itemWidth The element width.
  64. * @param itemHeight The element height.
  65. * @param startCharMap The starting char of the atlas.
  66. * @return An autoreleased TextAtlas object.
  67. */
  68. static TextAtlas* create(const std::string& stringValue,
  69. const std::string& charMapFile,
  70. int itemWidth,
  71. int itemHeight,
  72. const std::string& startCharMap);
  73. /** Initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas.
  74. *
  75. * @param stringValue A given string needs to be displayed.
  76. * @param charMapFile A given char map file name.
  77. * @param itemWidth The element width.
  78. * @param itemHeight The element height.
  79. * @param startCharMap The starting char of the atlas.
  80. */
  81. void setProperty(const std::string& stringValue,
  82. const std::string& charMapFile,
  83. int itemWidth,
  84. int itemHeight,
  85. const std::string& startCharMap);
  86. /**Set string value for labelatlas.
  87. *
  88. * @param value A given string needs to be displayed.
  89. */
  90. CC_DEPRECATED_ATTRIBUTE void setStringValue(const std::string& value){this->setString(value);}
  91. void setString(const std::string& value);
  92. /**Get string value for labelatlas.
  93. *
  94. * @return The string value of TextAtlas.
  95. */
  96. CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue() const{return this->getString();}
  97. const std::string& getString() const;
  98. /**
  99. * Gets the string length of the label.
  100. * Note: This length will be larger than the raw string length,
  101. * if you want to get the raw string length, you should call this->getString().size() instead
  102. *
  103. * @return string length.
  104. */
  105. ssize_t getStringLength()const;
  106. //override "getVirtualRendererSize" method of widget.
  107. virtual Size getVirtualRendererSize() const override;
  108. //override "getVirtualRenderer" method of widget.
  109. virtual Node* getVirtualRenderer() override;
  110. /**
  111. * Returns the "class name" of widget.
  112. */
  113. virtual std::string getDescription() const override;
  114. /**
  115. * @js NA
  116. */
  117. virtual void adaptRenderers() override;
  118. ResourceData getRenderFile();
  119. protected:
  120. virtual void initRenderer() override;
  121. virtual void onSizeChanged() override;
  122. void labelAtlasScaleChangedWithSize();
  123. virtual Widget* createCloneInstance() override;
  124. virtual void copySpecialProperties(Widget* model) override;
  125. protected:
  126. Label* _labelAtlasRenderer;
  127. std::string _stringValue;
  128. std::string _charMapFileName;
  129. int _itemWidth;
  130. int _itemHeight;
  131. std::string _startCharMap;
  132. bool _labelAtlasRendererAdaptDirty;
  133. };
  134. }
  135. // end of ui group
  136. /// @}
  137. NS_CC_END
  138. #endif /* defined(__CocoGUI__LabelAtlas__) */