Cornell Cocos
Cornell Extensions to Cocos2d
All Classes Functions Variables Enumerations Enumerator Friends
CUTTFont.h
1 //
2 // CUTTFont.h
3 // Cornell Extensions to Cocos2D
4 //
5 // This method provides a platform-independent way of refering to a loaded True Type
6 // font asset. Depending on the need, Cocos2D asks you to refer to a True Type font
7 // by either its TTConfig information or its FontAtlas. This class abstracts both of
8 // these into a single package for uniform usage.
9 //
10 // Author: Walker White
11 // Version: 12/10/15
12 //
13 #ifndef __CU_TTFONT_H__
14 #define __CU_TTFONT_H__
15 
16 #include <cocos2d.h>
17 
18 NS_CC_BEGIN
19 
20 #pragma mark -
21 #pragma mark Font Class
22 
23 #define COMPUTE_NAME(source,size) (source+"::"+std::to_string(size))
24 
25 class FontLoader;
26 
38 class CC_DLL TTFont : public Ref {
39 private:
41  CC_DISALLOW_COPY_AND_ASSIGN(TTFont);
42 
43 protected:
45  std::string _ident;
46 
48  std::string _source;
49 
51  TTFConfig _config;
52 
54  FontAtlas* _atlas;
55 
56 
57 public:
58 #pragma mark Attributes
59 
67  const std::string& getName() const { return _ident; }
68 
74  const std::string& getSource() const { return _source; }
75 
84  float getSize() const { return _config.fontSize; }
85 
94  const TTFConfig& getTTF() const { return _config; }
95 
104  const FontAtlas* getAtlas() const { return _atlas; }
105 
106 
107 CC_CONSTRUCTOR_ACCESS:
108 #pragma mark Initializers
109 
112  TTFont() : Ref(), _ident(""), _source(""), _atlas(nullptr) {}
113 
119  ~TTFont() { CCASSERT(_atlas == nullptr, "Font asset was not unloaded"); }
120 
131  static TTFont* create(std::string source, float size);
132 
143  bool init(std::string source, float size);
144 
146  friend class FontLoader;
147 };
148 
149 NS_CC_END
150 
151 #endif /* defined(__CU_TTFONT_H__) */
const std::string & getSource() const
Definition: CUTTFont.h:74
~TTFont()
Definition: CUTTFont.h:119
float getSize() const
Definition: CUTTFont.h:84
const FontAtlas * getAtlas() const
Definition: CUTTFont.h:104
std::string _source
Definition: CUTTFont.h:48
Definition: CUFontLoader.h:62
std::string _ident
Definition: CUTTFont.h:45
const TTFConfig & getTTF() const
Definition: CUTTFont.h:94
TTFConfig _config
Definition: CUTTFont.h:51
Definition: CUTTFont.h:38
const std::string & getName() const
Definition: CUTTFont.h:67
FontAtlas * _atlas
Definition: CUTTFont.h:54