summary refs log tree commit diff stats
path: root/libs/cocos2d/CCMenuItem.h
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/CCMenuItem.h
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/CCMenuItem.h')
-rwxr-xr-xlibs/cocos2d/CCMenuItem.h377
1 files changed, 377 insertions, 0 deletions
diff --git a/libs/cocos2d/CCMenuItem.h b/libs/cocos2d/CCMenuItem.h new file mode 100755 index 0000000..2437394 --- /dev/null +++ b/libs/cocos2d/CCMenuItem.h
@@ -0,0 +1,377 @@
1/*
2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
3 *
4 * Copyright (c) 2008-2011 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 */
26
27#import "CCBlockSupport.h"
28
29#import "CCNode.h"
30#import "CCProtocols.h"
31
32@class CCSprite;
33
34#define kCCItemSize 32
35
36#pragma mark -
37#pragma mark CCMenuItem
38/** CCMenuItem base class
39 *
40 * Subclass CCMenuItem (or any subclass) to create your custom CCMenuItem objects.
41 */
42@interface CCMenuItem : CCNode
43{
44 NSInvocation *invocation_;
45#if NS_BLOCKS_AVAILABLE
46 // used for menu items using a block
47 void (^block_)(id sender);
48#endif
49
50 BOOL isEnabled_;
51 BOOL isSelected_;
52}
53
54/** returns whether or not the item is selected
55@since v0.8.2
56*/
57@property (nonatomic,readonly) BOOL isSelected;
58
59/** Creates a CCMenuItem with a target/selector */
60+(id) itemWithTarget:(id)target selector:(SEL)selector;
61
62/** Initializes a CCMenuItem with a target/selector */
63-(id) initWithTarget:(id)target selector:(SEL)selector;
64
65#if NS_BLOCKS_AVAILABLE
66/** Creates a CCMenuItem with the specified block.
67 The block will be "copied".
68 */
69+(id) itemWithBlock:(void(^)(id sender))block;
70
71/** Initializes a CCMenuItem with the specified block.
72 The block will be "copied".
73*/
74-(id) initWithBlock:(void(^)(id sender))block;
75#endif
76
77/** Returns the outside box in points */
78-(CGRect) rect;
79
80/** Activate the item */
81-(void) activate;
82
83/** The item was selected (not activated), similar to "mouse-over" */
84-(void) selected;
85
86/** The item was unselected */
87-(void) unselected;
88
89/** Enable or disabled the CCMenuItem */
90-(void) setIsEnabled:(BOOL)enabled;
91/** Returns whether or not the CCMenuItem is enabled */
92-(BOOL) isEnabled;
93@end
94
95#pragma mark -
96#pragma mark CCMenuItemLabel
97
98/** An abstract class for "label" CCMenuItemLabel items
99 Any CCNode that supports the CCLabelProtocol protocol can be added.
100 Supported nodes:
101 - CCLabelBMFont
102 - CCLabelAtlas
103 - CCLabelTTF
104 */
105@interface CCMenuItemLabel : CCMenuItem <CCRGBAProtocol>
106{
107 CCNode<CCLabelProtocol, CCRGBAProtocol> *label_;
108 ccColor3B colorBackup;
109 ccColor3B disabledColor_;
110 float originalScale_;
111}
112
113/** the color that will be used to disable the item */
114@property (nonatomic,readwrite) ccColor3B disabledColor;
115
116/** Label that is rendered. It can be any CCNode that implements the CCLabelProtocol */
117@property (nonatomic,readwrite,assign) CCNode<CCLabelProtocol, CCRGBAProtocol>* label;
118
119/** creates a CCMenuItemLabel with a Label. Target and selector will be nill */
120+(id) itemWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label;
121
122/** creates a CCMenuItemLabel with a Label, target and selector */
123+(id) itemWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label target:(id)target selector:(SEL)selector;
124
125/** initializes a CCMenuItemLabel with a Label, target and selector */
126-(id) initWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label target:(id)target selector:(SEL)selector;
127
128#if NS_BLOCKS_AVAILABLE
129/** creates a CCMenuItemLabel with a Label and a block to execute.
130 The block will be "copied".
131 */
132+(id) itemWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label block:(void(^)(id sender))block;
133
134/** initializes a CCMenuItemLabel with a Label and a block to execute.
135 The block will be "copied".
136 */
137-(id) initWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label block:(void(^)(id sender))block;
138#endif
139
140/** sets a new string to the inner label */
141-(void) setString:(NSString*)label;
142
143/** Enable or disabled the CCMenuItemFont
144 @warning setIsEnabled changes the RGB color of the font
145 */
146-(void) setIsEnabled: (BOOL)enabled;
147@end
148
149#pragma mark -
150#pragma mark CCMenuItemAtlasFont
151
152/** A CCMenuItemAtlasFont
153 Helper class that creates a MenuItemLabel class with a LabelAtlas
154 */
155@interface CCMenuItemAtlasFont : CCMenuItemLabel
156{
157}
158
159/** creates a menu item from a string and atlas with a target/selector */
160+(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap;
161
162/** creates a menu item from a string and atlas. Use it with MenuItemToggle */
163+(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb;
164
165/** initializes a menu item from a string and atlas with a target/selector */
166-(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb;
167
168#if NS_BLOCKS_AVAILABLE
169/** creates a menu item from a string and atlas. Use it with MenuItemToggle.
170 The block will be "copied".
171 */
172+(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block;
173
174/** initializes a menu item from a string and atlas with a block.
175 The block will be "copied".
176 */
177-(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block;
178#endif
179
180@end
181
182#pragma mark -
183#pragma mark CCMenuItemFont
184
185/** A CCMenuItemFont
186 Helper class that creates a CCMenuItemLabel class with a Label
187 */
188@interface CCMenuItemFont : CCMenuItemLabel
189{
190 NSUInteger fontSize_;
191 NSString *fontName_;
192}
193/** set default font size */
194+(void) setFontSize: (NSUInteger) s;
195
196/** get default font size */
197+(NSUInteger) fontSize;
198
199/** set default font name */
200+(void) setFontName: (NSString*) n;
201
202/** get default font name */
203+(NSString*) fontName;
204
205/** creates a menu item from a string without target/selector. To be used with CCMenuItemToggle */
206+(id) itemFromString: (NSString*) value;
207
208/** creates a menu item from a string with a target/selector */
209+(id) itemFromString: (NSString*) value target:(id) r selector:(SEL) s;
210
211/** initializes a menu item from a string with a target/selector */
212-(id) initFromString: (NSString*) value target:(id) r selector:(SEL) s;
213
214/** set font size */
215-(void) setFontSize: (NSUInteger) s;
216
217/** get font size */
218-(NSUInteger) fontSize;
219
220/** set the font name */
221-(void) setFontName: (NSString*) n;
222
223/** get the font name */
224-(NSString*) fontName;
225
226#if NS_BLOCKS_AVAILABLE
227/** creates a menu item from a string with the specified block.
228 The block will be "copied".
229 */
230+(id) itemFromString: (NSString*) value block:(void(^)(id sender))block;
231
232/** initializes a menu item from a string with the specified block.
233 The block will be "copied".
234 */
235-(id) initFromString: (NSString*) value block:(void(^)(id sender))block;
236#endif
237@end
238
239#pragma mark -
240#pragma mark CCMenuItemSprite
241
242/** CCMenuItemSprite accepts CCNode<CCRGBAProtocol> objects as items.
243 The images has 3 different states:
244 - unselected image
245 - selected image
246 - disabled image
247
248 @since v0.8.0
249 */
250@interface CCMenuItemSprite : CCMenuItem <CCRGBAProtocol>
251{
252 CCNode<CCRGBAProtocol> *normalImage_, *selectedImage_, *disabledImage_;
253}
254
255// weak references
256
257/** the image used when the item is not selected */
258@property (nonatomic,readwrite,assign) CCNode<CCRGBAProtocol> *normalImage;
259/** the image used when the item is selected */
260@property (nonatomic,readwrite,assign) CCNode<CCRGBAProtocol> *selectedImage;
261/** the image used when the item is disabled */
262@property (nonatomic,readwrite,assign) CCNode<CCRGBAProtocol> *disabledImage;
263
264/** creates a menu item with a normal and selected image*/
265+(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite;
266/** creates a menu item with a normal and selected image with target/selector */
267+(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite target:(id)target selector:(SEL)selector;
268/** creates a menu item with a normal,selected and disabled image with target/selector */
269+(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite target:(id)target selector:(SEL)selector;
270/** initializes a menu item with a normal, selected and disabled image with target/selector */
271-(id) initFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite target:(id)target selector:(SEL)selector;
272
273#if NS_BLOCKS_AVAILABLE
274/** creates a menu item with a normal and selected image with a block.
275 The block will be "copied".
276 */
277+(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite block:(void(^)(id sender))block;
278/** creates a menu item with a normal,selected and disabled image with a block.
279 The block will be "copied".
280 */
281+(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite block:(void(^)(id sender))block;
282/** initializes a menu item with a normal, selected and disabled image with a block.
283 The block will be "copied".
284 */
285-(id) initFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite block:(void(^)(id sender))block;
286#endif
287
288@end
289
290#pragma mark -
291#pragma mark CCMenuItemImage
292
293/** CCMenuItemImage accepts images as items.
294 The images has 3 different states:
295 - unselected image
296 - selected image
297 - disabled image
298
299 For best results try that all images are of the same size
300 */
301@interface CCMenuItemImage : CCMenuItemSprite
302{
303}
304
305/** creates a menu item with a normal and selected image*/
306+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2;
307/** creates a menu item with a normal and selected image with target/selector */
308+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) r selector:(SEL) s;
309/** creates a menu item with a normal,selected and disabled image with target/selector */
310+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s;
311/** initializes a menu item with a normal, selected and disabled image with target/selector */
312-(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s;
313#if NS_BLOCKS_AVAILABLE
314/** creates a menu item with a normal and selected image with a block.
315 The block will be "copied".
316 */
317+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 block:(void(^)(id sender))block;
318/** creates a menu item with a normal,selected and disabled image with a block.
319 The block will be "copied".
320*/
321+(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block;
322/** initializes a menu item with a normal, selected and disabled image with a block.
323 The block will be "copied".
324*/
325-(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block;
326#endif
327@end
328
329#pragma mark -
330#pragma mark CCMenuItemToggle
331
332/** A CCMenuItemToggle
333 A simple container class that "toggles" it's inner items
334 The inner itmes can be any MenuItem
335 */
336@interface CCMenuItemToggle : CCMenuItem <CCRGBAProtocol>
337{
338 NSUInteger selectedIndex_;
339 NSMutableArray* subItems_;
340 GLubyte opacity_;
341 ccColor3B color_;
342}
343
344/** conforms with CCRGBAProtocol protocol */
345@property (nonatomic,readonly) GLubyte opacity;
346/** conforms with CCRGBAProtocol protocol */
347@property (nonatomic,readonly) ccColor3B color;
348
349/** returns the selected item */
350@property (nonatomic,readwrite) NSUInteger selectedIndex;
351/** NSMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
352 @since v0.7.2
353 */
354@property (nonatomic,readwrite,retain) NSMutableArray *subItems;
355
356/** creates a menu item from a list of items with a target/selector */
357+(id) itemWithTarget:(id)t selector:(SEL)s items:(CCMenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION;
358
359/** initializes a menu item from a list of items with a target selector */
360-(id) initWithTarget:(id)t selector:(SEL)s items:(CCMenuItem*) item vaList:(va_list) args;
361
362#if NS_BLOCKS_AVAILABLE
363/** creates a menu item from a list of items and executes the given block when the item is selected.
364 The block will be "copied".
365 */
366+(id) itemWithBlock:(void(^)(id sender))block items:(CCMenuItem*)item, ... NS_REQUIRES_NIL_TERMINATION;
367
368/** initializes a menu item from a list of items with a block.
369 The block will be "copied".
370 */
371-(id) initWithBlock:(void (^)(id))block items:(CCMenuItem*)item vaList:(va_list)args;
372#endif
373
374/** return the selected item */
375-(CCMenuItem*) selectedItem;
376@end
377