CCLabelBMFont.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2011 Zynga Inc.
  5. Copyright (c) 2013-2016 Chukong Technologies Inc.
  6. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  7. http://www.cocos2d-x.org
  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. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE.
  23. Use any of these editors to generate BMFonts:
  24. http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
  25. http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
  26. http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
  27. http://www.angelcode.com/products/bmfont/ (Free, Windows only)
  28. ****************************************************************************/
  29. #ifndef __CCBITMAP_FONT_ATLAS_H__
  30. #define __CCBITMAP_FONT_ATLAS_H__
  31. /// @cond DO_NOT_SHOW
  32. #include "2d/CCLabel.h"
  33. #if CC_LABELBMFONT_DEBUG_DRAW
  34. #include "renderer/CCCustomCommand.h"
  35. #include "2d/CCDrawNode.h"
  36. #endif
  37. NS_CC_BEGIN
  38. #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
  39. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  40. #elif _MSC_VER >= 1400 //vs 2005 or higher
  41. #pragma warning (push)
  42. #pragma warning (disable: 4996)
  43. #endif
  44. /** @brief LabelBMFont is a subclass of SpriteBatchNode.
  45. Features:
  46. - Treats each character like a Sprite. This means that each individual character can be:
  47. - rotated
  48. - scaled
  49. - translated
  50. - tinted
  51. - change the opacity
  52. - It can be used as part of a menu item.
  53. - anchorPoint can be used to align the "label"
  54. - Supports AngelCode text format
  55. Limitations:
  56. - All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it
  57. because it might affect the rendering
  58. LabelBMFont implements the protocol LabelProtocol, like Label and LabelAtlas.
  59. LabelBMFont has the flexibility of Label, the speed of LabelAtlas and all the features of Sprite.
  60. If in doubt, use LabelBMFont instead of LabelAtlas / Label.
  61. Supported editors:
  62. http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
  63. http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
  64. http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
  65. http://www.angelcode.com/products/bmfont/ (Free, Windows only)
  66. @since v0.8
  67. */
  68. class CC_DLL CC_DEPRECATED_ATTRIBUTE LabelBMFont : public Node, public LabelProtocol, public BlendProtocol
  69. {
  70. public:
  71. /**
  72. * @js ctor
  73. */
  74. LabelBMFont();
  75. /**
  76. * @js NA
  77. * @lua NA
  78. */
  79. virtual ~LabelBMFont();
  80. /** creates a bitmap font atlas with an initial string and the FNT file */
  81. static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width = 0, TextHAlignment alignment = TextHAlignment::LEFT,const Vec2& imageOffset = Vec2::ZERO);
  82. /** Creates an label.
  83. */
  84. static LabelBMFont * create();
  85. /** init a bitmap font atlas with an initial string and the FNT file */
  86. bool initWithString(const std::string& str, const std::string& fntFile, float width = 0, TextHAlignment alignment = TextHAlignment::LEFT,const Vec2& imageOffset = Vec2::ZERO);
  87. // super method
  88. virtual void setString(const std::string& newString) override;
  89. virtual const std::string& getString() const override;
  90. virtual void setAlignment(TextHAlignment alignment);
  91. virtual void setWidth(float width);
  92. virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
  93. // RGBAProtocol
  94. virtual bool isOpacityModifyRGB() const override;
  95. virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
  96. void setFntFile(const std::string& fntFile, const Vec2& imageOffset = Vec2::ZERO);
  97. const std::string& getFntFile() const;
  98. virtual void setBlendFunc(const BlendFunc &blendFunc) override;
  99. virtual const BlendFunc &getBlendFunc() const override;
  100. virtual Sprite * getLetter(int ID);
  101. virtual Node * getChildByTag(int tag) const override;
  102. virtual void setColor(const Color3B& color) override;
  103. virtual const Size& getContentSize() const override;
  104. virtual Rect getBoundingBox() const override;
  105. virtual std::string getDescription() const override;
  106. #if CC_LABELBMFONT_DEBUG_DRAW
  107. virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
  108. #endif
  109. private:
  110. #if CC_LABELBMFONT_DEBUG_DRAW
  111. DrawNode *_debugDrawNode;
  112. #endif
  113. // name of fntFile
  114. std::string _fntFile;
  115. Label* _label;
  116. };
  117. // end of GUI group
  118. /// @}
  119. /// @}
  120. #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
  121. #pragma GCC diagnostic warning "-Wdeprecated-declarations"
  122. #elif _MSC_VER >= 1400 //vs 2005 or higher
  123. #pragma warning (pop)
  124. #endif
  125. NS_CC_END
  126. /// @endcond
  127. #endif //__CCBITMAP_FONT_ATLAS_H__