|
cocos2d for iPhone 1.0.0
2D engine for iOS and OS X
|
00001 /* 00002 * cocos2d for iPhone: http://www.cocos2d-iphone.org 00003 * 00004 * Copyright (c) 2008-2011 Ricardo Quesada 00005 * Copyright (c) 2011 Zynga Inc. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 * 00025 */ 00026 00027 #import "CCBlockSupport.h" 00028 00029 #import "CCNode.h" 00030 #import "CCProtocols.h" 00031 00032 @class CCSprite; 00033 00034 #define kCCItemSize 32 00035 00036 #pragma mark - 00037 #pragma mark CCMenuItem 00038 00042 @interface CCMenuItem : CCNode 00043 { 00044 NSInvocation *invocation_; 00045 #if NS_BLOCKS_AVAILABLE 00046 // used for menu items using a block 00047 void (^block_)(id sender); 00048 #endif 00049 00050 BOOL isEnabled_; 00051 BOOL isSelected_; 00052 } 00053 00057 @property (nonatomic,readonly) BOOL isSelected; 00058 00060 +(id) itemWithTarget:(id)target selector:(SEL)selector; 00061 00063 -(id) initWithTarget:(id)target selector:(SEL)selector; 00064 00065 #if NS_BLOCKS_AVAILABLE 00066 00069 +(id) itemWithBlock:(void(^)(id sender))block; 00070 00074 -(id) initWithBlock:(void(^)(id sender))block; 00075 #endif 00076 00078 -(CGRect) rect; 00079 00081 -(void) activate; 00082 00084 -(void) selected; 00085 00087 -(void) unselected; 00088 00090 -(void) setIsEnabled:(BOOL)enabled; 00092 -(BOOL) isEnabled; 00093 @end 00094 00095 #pragma mark - 00096 #pragma mark CCMenuItemLabel 00097 00105 @interface CCMenuItemLabel : CCMenuItem <CCRGBAProtocol> 00106 { 00107 CCNode<CCLabelProtocol, CCRGBAProtocol> *label_; 00108 ccColor3B colorBackup; 00109 ccColor3B disabledColor_; 00110 float originalScale_; 00111 } 00112 00114 @property (nonatomic,readwrite) ccColor3B disabledColor; 00115 00117 @property (nonatomic,readwrite,assign) CCNode<CCLabelProtocol, CCRGBAProtocol>* label; 00118 00120 +(id) itemWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label; 00121 00123 +(id) itemWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label target:(id)target selector:(SEL)selector; 00124 00126 -(id) initWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label target:(id)target selector:(SEL)selector; 00127 00128 #if NS_BLOCKS_AVAILABLE 00129 00132 +(id) itemWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label block:(void(^)(id sender))block; 00133 00137 -(id) initWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol>*)label block:(void(^)(id sender))block; 00138 #endif 00139 00141 -(void) setString:(NSString*)label; 00142 00146 -(void) setIsEnabled: (BOOL)enabled; 00147 @end 00148 00149 #pragma mark - 00150 #pragma mark CCMenuItemAtlasFont 00151 00155 @interface CCMenuItemAtlasFont : CCMenuItemLabel 00156 { 00157 } 00158 00160 +(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap; 00161 00163 +(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb; 00164 00166 -(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap target:(id) rec selector:(SEL) cb; 00167 00168 #if NS_BLOCKS_AVAILABLE 00169 00172 +(id) itemFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block; 00173 00177 -(id) initFromString: (NSString*) value charMapFile:(NSString*) charMapFile itemWidth:(int)itemWidth itemHeight:(int)itemHeight startCharMap:(char)startCharMap block:(void(^)(id sender))block; 00178 #endif 00179 00180 @end 00181 00182 #pragma mark - 00183 #pragma mark CCMenuItemFont 00184 00188 @interface CCMenuItemFont : CCMenuItemLabel 00189 { 00190 NSUInteger fontSize_; 00191 NSString *fontName_; 00192 } 00194 +(void) setFontSize: (NSUInteger) s; 00195 00197 +(NSUInteger) fontSize; 00198 00200 +(void) setFontName: (NSString*) n; 00201 00203 +(NSString*) fontName; 00204 00206 +(id) itemFromString: (NSString*) value; 00207 00209 +(id) itemFromString: (NSString*) value target:(id) r selector:(SEL) s; 00210 00212 -(id) initFromString: (NSString*) value target:(id) r selector:(SEL) s; 00213 00215 -(void) setFontSize: (NSUInteger) s; 00216 00218 -(NSUInteger) fontSize; 00219 00221 -(void) setFontName: (NSString*) n; 00222 00224 -(NSString*) fontName; 00225 00226 #if NS_BLOCKS_AVAILABLE 00227 00230 +(id) itemFromString: (NSString*) value block:(void(^)(id sender))block; 00231 00235 -(id) initFromString: (NSString*) value block:(void(^)(id sender))block; 00236 #endif 00237 @end 00238 00239 #pragma mark - 00240 #pragma mark CCMenuItemSprite 00241 00250 @interface CCMenuItemSprite : CCMenuItem <CCRGBAProtocol> 00251 { 00252 CCNode<CCRGBAProtocol> *normalImage_, *selectedImage_, *disabledImage_; 00253 } 00254 00255 // weak references 00256 00258 @property (nonatomic,readwrite,assign) CCNode<CCRGBAProtocol> *normalImage; 00260 @property (nonatomic,readwrite,assign) CCNode<CCRGBAProtocol> *selectedImage; 00262 @property (nonatomic,readwrite,assign) CCNode<CCRGBAProtocol> *disabledImage; 00263 00265 +(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite; 00267 +(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite target:(id)target selector:(SEL)selector; 00269 +(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite target:(id)target selector:(SEL)selector; 00271 -(id) initFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite target:(id)target selector:(SEL)selector; 00272 00273 #if NS_BLOCKS_AVAILABLE 00274 00277 +(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite block:(void(^)(id sender))block; 00281 +(id) itemFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite block:(void(^)(id sender))block; 00285 -(id) initFromNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite block:(void(^)(id sender))block; 00286 #endif 00287 00288 @end 00289 00290 #pragma mark - 00291 #pragma mark CCMenuItemImage 00292 00301 @interface CCMenuItemImage : CCMenuItemSprite 00302 { 00303 } 00304 00306 +(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2; 00308 +(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) r selector:(SEL) s; 00310 +(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s; 00312 -(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s; 00313 #if NS_BLOCKS_AVAILABLE 00314 00317 +(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 block:(void(^)(id sender))block; 00321 +(id) itemFromNormalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block; 00325 -(id) initFromNormalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block; 00326 #endif 00327 @end 00328 00329 #pragma mark - 00330 #pragma mark CCMenuItemToggle 00331 00336 @interface CCMenuItemToggle : CCMenuItem <CCRGBAProtocol> 00337 { 00338 NSUInteger selectedIndex_; 00339 NSMutableArray* subItems_; 00340 GLubyte opacity_; 00341 ccColor3B color_; 00342 } 00343 00345 @property (nonatomic,readonly) GLubyte opacity; 00347 @property (nonatomic,readonly) ccColor3B color; 00348 00350 @property (nonatomic,readwrite) NSUInteger selectedIndex; 00354 @property (nonatomic,readwrite,retain) NSMutableArray *subItems; 00355 00357 +(id) itemWithTarget:(id)t selector:(SEL)s items:(CCMenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION; 00358 00360 -(id) initWithTarget:(id)t selector:(SEL)s items:(CCMenuItem*) item vaList:(va_list) args; 00361 00362 #if NS_BLOCKS_AVAILABLE 00363 00366 +(id) itemWithBlock:(void(^)(id sender))block items:(CCMenuItem*)item, ... NS_REQUIRES_NIL_TERMINATION; 00367 00371 -(id) initWithBlock:(void (^)(id))block items:(CCMenuItem*)item vaList:(va_list)args; 00372 #endif 00373 00375 -(CCMenuItem*) selectedItem; 00376 @end 00377