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