UITextBMFont.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 __UILABELBMFONT_H__
  22. #define __UILABELBMFONT_H__
  23. #include "ui/UIWidget.h"
  24. #include "ui/GUIExport.h"
  25. /**
  26. * @addtogroup ui
  27. * @{
  28. */
  29. NS_CC_BEGIN
  30. class Label;
  31. struct CC_DLL ResourceData;
  32. namespace ui {
  33. /**
  34. * A widget for displaying BMFont label.
  35. */
  36. class CC_GUI_DLL TextBMFont : public Widget
  37. {
  38. DECLARE_CLASS_GUI_INFO
  39. public:
  40. /**
  41. * Default constructor
  42. * @js ctor
  43. * @lua new
  44. */
  45. TextBMFont();
  46. /**
  47. * Default destructor
  48. * @js NA
  49. * @lua NA
  50. */
  51. virtual ~TextBMFont();
  52. /**
  53. * Allocates and initializes.
  54. */
  55. static TextBMFont* create();
  56. static TextBMFont* create(const std::string& text, const std::string& filename);
  57. /** init a bitmap font atlas with an initial string and the FNT file */
  58. void setFntFile(const std::string& fileName);
  59. /** set string value for labelbmfont*/
  60. CC_DEPRECATED_ATTRIBUTE void setText(const std::string& value){this->setString(value);}
  61. void setString(const std::string& value);
  62. /** get string value for labelbmfont*/
  63. CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue()const{return this->getString();}
  64. const std::string& getString()const;
  65. /**
  66. * Gets the string length of the label.
  67. * Note: This length will be larger than the raw string length,
  68. * if you want to get the raw string length, you should call this->getString().size() instead
  69. *
  70. * @return string length.
  71. */
  72. ssize_t getStringLength()const;
  73. virtual Size getVirtualRendererSize() const override;
  74. virtual Node* getVirtualRenderer() override;
  75. /**
  76. * Returns the "class name" of widget.
  77. */
  78. virtual std::string getDescription() const override;
  79. ResourceData getRenderFile();
  80. /**
  81. * reset TextBMFont inner label
  82. */
  83. void resetRender();
  84. protected:
  85. virtual void initRenderer() override;
  86. virtual void onSizeChanged() override;
  87. void labelBMFontScaleChangedWithSize();
  88. virtual Widget* createCloneInstance() override;
  89. virtual void copySpecialProperties(Widget* model) override;
  90. virtual void adaptRenderers() override;
  91. protected:
  92. Label* _labelBMFontRenderer;
  93. std::string _fntFileName;
  94. std::string _stringValue;
  95. bool _labelBMFontRendererAdaptDirty;
  96. };
  97. }
  98. NS_CC_END
  99. // end of ui group
  100. /// @}
  101. #endif /* defined(__LabelBMFont__) */