CCLabelBMFont.h 5.5 KB

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