1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*
* cocos2d for iPhone: http://www.cocos2d-iphone.org
*
* Copyright (c) 2008-2010 Ricardo Quesada
* Copyright (c) 2011 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Portions of this code are based and inspired on:
* http://www.71squared.co.uk/2009/04/iphone-game-programming-tutorial-4-bitmap-font-class
* by Michael Daley
*
* Use any of these editors to generate BMFonts:
* http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
* http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
* http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
* http://www.angelcode.com/products/bmfont/ (Free, Windows only)
*/
#import "CCSpriteBatchNode.h"
#import "Support/uthash.h"
struct _KerningHashElement;
/** @struct ccBMFontDef
BMFont definition
*/
typedef struct _BMFontDef {
//! ID of the character
unsigned int charID;
//! origin and size of the font
CGRect rect;
//! The X amount the image should be offset when drawing the image (in pixels)
int xOffset;
//! The Y amount the image should be offset when drawing the image (in pixels)
int yOffset;
//! The amount to move the current position after drawing the character (in pixels)
int xAdvance;
} ccBMFontDef;
/** @struct ccBMFontPadding
BMFont padding
@since v0.8.2
*/
typedef struct _BMFontPadding {
/// padding left
int left;
/// padding top
int top;
/// padding right
int right;
/// padding bottom
int bottom;
} ccBMFontPadding;
enum {
// how many characters are supported
kCCBMFontMaxChars = 2048, //256,
};
/** CCBMFontConfiguration has parsed configuration of the the .fnt file
@since v0.8
*/
@interface CCBMFontConfiguration : NSObject
{
// XXX: Creating a public interface so that the bitmapFontArray[] is accesible
@public
// The characters building up the font
ccBMFontDef BMFontArray_[kCCBMFontMaxChars];
// FNTConfig: Common Height
NSUInteger commonHeight_;
// Padding
ccBMFontPadding padding_;
// atlas name
NSString *atlasName_;
// values for kerning
struct _KerningHashElement *kerningDictionary_;
}
/** allocates a CCBMFontConfiguration with a FNT file */
+(id) configurationWithFNTFile:(NSString*)FNTfile;
/** initializes a CCBMFontConfiguration with a FNT file */
-(id) initWithFNTfile:(NSString*)FNTfile;
@end
/** CCLabelBMFont is a subclass of CCSpriteBatchNode
Features:
- Treats each character like a CCSprite. This means that each individual character can be:
- rotated
- scaled
- translated
- tinted
- chage the opacity
- It can be used as part of a menu item.
- anchorPoint can be used to align the "label"
- Supports AngelCode text format
Limitations:
- All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it
because it might affect the rendering
CCLabelBMFont implements the protocol CCLabelProtocol, like CCLabel and CCLabelAtlas.
CCLabelBMFont has the flexibility of CCLabel, the speed of CCLabelAtlas and all the features of CCSprite.
If in doubt, use CCLabelBMFont instead of CCLabelAtlas / CCLabel.
Supported editors:
- http://www.n4te.com/hiero/hiero.jnlp
- http://slick.cokeandcode.com/demos/hiero.jnlp
- http://www.angelcode.com/products/bmfont/
@since v0.8
*/
@interface CCLabelBMFont : CCSpriteBatchNode <CCLabelProtocol, CCRGBAProtocol>
{
// string to render
NSString *string_;
CCBMFontConfiguration *configuration_;
// texture RGBA
GLubyte opacity_;
ccColor3B color_;
BOOL opacityModifyRGB_;
}
/** Purges the cached data.
Removes from memory the cached configurations and the atlas name dictionary.
@since v0.99.3
*/
+(void) purgeCachedData;
/** conforms to CCRGBAProtocol protocol */
@property (nonatomic,readwrite) GLubyte opacity;
/** conforms to CCRGBAProtocol protocol */
@property (nonatomic,readwrite) ccColor3B color;
/** creates a BMFont label with an initial string and the FNT file */
+(id) labelWithString:(NSString*)string fntFile:(NSString*)fntFile;
/** creates a BMFont label with an initial string and the FNT file
@deprecated Will be removed in 1.0.1. Use "labelWithString" instead.
*/
+(id) bitmapFontAtlasWithString:(NSString*)string fntFile:(NSString*)fntFile DEPRECATED_ATTRIBUTE;
/** init a BMFont label with an initial string and the FNT file */
-(id) initWithString:(NSString*)string fntFile:(NSString*)fntFile;
/** updates the font chars based on the string to render */
-(void) createFontChars;
@end
/** Free function that parses a FNT file a place it on the cache
*/
CCBMFontConfiguration * FNTConfigLoadFile( NSString *file );
/** Purges the FNT config cache
*/
void FNTConfigRemoveCache( void );
/** CCBitmapFontAtlas
@deprecated Use CCLabelBMFont instead. Will be removed 1.0.1
*/
DEPRECATED_ATTRIBUTE @interface CCBitmapFontAtlas : CCLabelBMFont
@end
|