├── .gitignore ├── Classes ├── GameConfig.h ├── HelloWorldScene.h ├── HelloWorldScene.m ├── RootViewController.h ├── RootViewController.m ├── TextBox.h ├── TextBoxLayer.h ├── TextBoxLayer.m ├── TextBoxLayerSampleAppDelegate.h ├── TextBoxLayerSampleAppDelegate.m ├── TextBoxView.h └── TextBoxView.m ├── LICENSE.cocos2d ├── LICENSE.cocosdenshion ├── README ├── Resources ├── Default.png ├── Icon-72.png ├── Icon-Small-50.png ├── Icon-Small.png ├── Icon-Small@2x.png ├── Icon.png ├── Icon@2x.png ├── Info.plist ├── ItunesArtwork ├── arial16-hd.fnt ├── arial16-hd.png ├── arial16.fnt ├── arial16.png └── fps_images.png ├── TextBoxLayerSample.xcodeproj ├── fabiorodella.mode1v3 ├── fabiorodella.pbxuser └── project.pbxproj ├── TextBoxLayerSample_Prefix.pch ├── libs ├── CocosDenshion │ ├── CDAudioManager.h │ ├── CDAudioManager.m │ ├── CDConfig.h │ ├── CDOpenALSupport.h │ ├── CDOpenALSupport.m │ ├── CocosDenshion.h │ ├── CocosDenshion.m │ ├── SimpleAudioEngine.h │ └── SimpleAudioEngine.m ├── FontLabel │ ├── FontLabel.h │ ├── FontLabel.m │ ├── FontLabelStringDrawing.h │ ├── FontLabelStringDrawing.m │ ├── FontManager.h │ ├── FontManager.m │ ├── ZAttributedString.h │ ├── ZAttributedString.m │ ├── ZAttributedStringPrivate.h │ ├── ZFont.h │ └── ZFont.m ├── README ├── TouchJSON │ ├── CDataScanner.h │ ├── CDataScanner.m │ ├── Extensions │ │ ├── CDataScanner_Extensions.h │ │ ├── CDataScanner_Extensions.m │ │ ├── NSCharacterSet_Extensions.h │ │ ├── NSCharacterSet_Extensions.m │ │ ├── NSDictionary_JSONExtensions.h │ │ ├── NSDictionary_JSONExtensions.m │ │ ├── NSScanner_Extensions.h │ │ └── NSScanner_Extensions.m │ └── JSON │ │ ├── CJSONDeserializer.h │ │ ├── CJSONDeserializer.m │ │ ├── CJSONScanner.h │ │ ├── CJSONScanner.m │ │ ├── CJSONSerializer.h │ │ └── CJSONSerializer.m ├── cocos2d │ ├── CCAction.h │ ├── CCAction.m │ ├── CCActionCamera.h │ ├── CCActionCamera.m │ ├── CCActionEase.h │ ├── CCActionEase.m │ ├── CCActionGrid.h │ ├── CCActionGrid.m │ ├── CCActionGrid3D.h │ ├── CCActionGrid3D.m │ ├── CCActionInstant.h │ ├── CCActionInstant.m │ ├── CCActionInterval.h │ ├── CCActionInterval.m │ ├── CCActionManager.h │ ├── CCActionManager.m │ ├── CCActionPageTurn3D.h │ ├── CCActionPageTurn3D.m │ ├── CCActionProgressTimer.h │ ├── CCActionProgressTimer.m │ ├── CCActionTiledGrid.h │ ├── CCActionTiledGrid.m │ ├── CCActionTween.h │ ├── CCActionTween.m │ ├── CCAnimation.h │ ├── CCAnimation.m │ ├── CCAnimationCache.h │ ├── CCAnimationCache.m │ ├── CCAtlasNode.h │ ├── CCAtlasNode.m │ ├── CCBlockSupport.h │ ├── CCBlockSupport.m │ ├── CCCamera.h │ ├── CCCamera.m │ ├── CCCompatibility.h │ ├── CCCompatibility.m │ ├── CCConfiguration.h │ ├── CCConfiguration.m │ ├── CCDirector.h │ ├── CCDirector.m │ ├── CCDrawingPrimitives.h │ ├── CCDrawingPrimitives.m │ ├── CCGrabber.h │ ├── CCGrabber.m │ ├── CCGrid.h │ ├── CCGrid.m │ ├── CCLabelAtlas.h │ ├── CCLabelAtlas.m │ ├── CCLabelBMFont.h │ ├── CCLabelBMFont.m │ ├── CCLabelTTF.h │ ├── CCLabelTTF.m │ ├── CCLayer.h │ ├── CCLayer.m │ ├── CCMenu.h │ ├── CCMenu.m │ ├── CCMenuItem.h │ ├── CCMenuItem.m │ ├── CCMotionStreak.h │ ├── CCMotionStreak.m │ ├── CCNode.h │ ├── CCNode.m │ ├── CCParallaxNode.h │ ├── CCParallaxNode.m │ ├── CCParticleExamples.h │ ├── CCParticleExamples.m │ ├── CCParticleSystem.h │ ├── CCParticleSystem.m │ ├── CCParticleSystemPoint.h │ ├── CCParticleSystemPoint.m │ ├── CCParticleSystemQuad.h │ ├── CCParticleSystemQuad.m │ ├── CCProgressTimer.h │ ├── CCProgressTimer.m │ ├── CCProtocols.h │ ├── CCRenderTexture.h │ ├── CCRenderTexture.m │ ├── CCRibbon.h │ ├── CCRibbon.m │ ├── CCScene.h │ ├── CCScene.m │ ├── CCScheduler.h │ ├── CCScheduler.m │ ├── CCSprite.h │ ├── CCSprite.m │ ├── CCSpriteBatchNode.h │ ├── CCSpriteBatchNode.m │ ├── CCSpriteFrame.h │ ├── CCSpriteFrame.m │ ├── CCSpriteFrameCache.h │ ├── CCSpriteFrameCache.m │ ├── CCSpriteSheet.h │ ├── CCSpriteSheet.m │ ├── CCTMXLayer.h │ ├── CCTMXLayer.m │ ├── CCTMXObjectGroup.h │ ├── CCTMXObjectGroup.m │ ├── CCTMXTiledMap.h │ ├── CCTMXTiledMap.m │ ├── CCTMXXMLParser.h │ ├── CCTMXXMLParser.m │ ├── CCTexture2D.h │ ├── CCTexture2D.m │ ├── CCTextureAtlas.h │ ├── CCTextureAtlas.m │ ├── CCTextureCache.h │ ├── CCTextureCache.m │ ├── CCTexturePVR.h │ ├── CCTexturePVR.m │ ├── CCTileMapAtlas.h │ ├── CCTileMapAtlas.m │ ├── CCTransition.h │ ├── CCTransition.m │ ├── CCTransitionPageTurn.h │ ├── CCTransitionPageTurn.m │ ├── CCTransitionRadial.h │ ├── CCTransitionRadial.m │ ├── Platforms │ │ ├── CCGL.h │ │ ├── CCNS.h │ │ ├── Mac │ │ │ ├── CCDirectorMac.h │ │ │ ├── CCDirectorMac.m │ │ │ ├── CCEventDispatcher.h │ │ │ ├── CCEventDispatcher.m │ │ │ ├── MacGLView.h │ │ │ └── MacGLView.m │ │ └── iOS │ │ │ ├── CCDirectorIOS.h │ │ │ ├── CCDirectorIOS.m │ │ │ ├── CCTouchDelegateProtocol.h │ │ │ ├── CCTouchDispatcher.h │ │ │ ├── CCTouchDispatcher.m │ │ │ ├── CCTouchHandler.h │ │ │ ├── CCTouchHandler.m │ │ │ ├── EAGLView.h │ │ │ ├── EAGLView.m │ │ │ ├── ES1Renderer.h │ │ │ ├── ES1Renderer.m │ │ │ ├── ESRenderer.h │ │ │ ├── glu.c │ │ │ └── glu.h │ ├── Support │ │ ├── CCArray.h │ │ ├── CCArray.m │ │ ├── CCFileUtils.h │ │ ├── CCFileUtils.m │ │ ├── CCProfiling.h │ │ ├── CCProfiling.m │ │ ├── CGPointExtension.h │ │ ├── CGPointExtension.m │ │ ├── OpenGL_Internal.h │ │ ├── TGAlib.h │ │ ├── TGAlib.m │ │ ├── TransformUtils.h │ │ ├── TransformUtils.m │ │ ├── ZipUtils.h │ │ ├── ZipUtils.m │ │ ├── base64.c │ │ ├── base64.h │ │ ├── ccCArray.h │ │ ├── ccUtils.c │ │ ├── ccUtils.h │ │ ├── uthash.h │ │ └── utlist.h │ ├── ccConfig.h │ ├── ccMacros.h │ ├── ccTypes.h │ ├── cocos2d.h │ └── cocos2d.m └── cocoslive │ ├── CLScoreServerPost.h │ ├── CLScoreServerPost.m │ ├── CLScoreServerRequest.h │ ├── CLScoreServerRequest.m │ ├── cocoslive.h │ └── cocoslive.m └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *~.nib 4 | 5 | xcuserdata/ 6 | 7 | *.mode1v3 8 | *.pbxuser 9 | build/ 10 | *.perspectivev3 11 | *.perspective 12 | 13 | *.xcuserstate 14 | 15 | *.mode2v3 16 | project.xcworkspace/ 17 | *.orig -------------------------------------------------------------------------------- /Classes/GameConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // GameConfig.h 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 1/19/11. 6 | // Copyright __MyCompanyName__ 2011. All rights reserved. 7 | // 8 | 9 | #ifndef __GAME_CONFIG_H 10 | #define __GAME_CONFIG_H 11 | 12 | // 13 | // Supported Autorotations: 14 | // None, 15 | // UIViewController, 16 | // CCDirector 17 | // 18 | #define kGameAutorotationNone 0 19 | #define kGameAutorotationCCDirector 1 20 | #define kGameAutorotationUIViewController 2 21 | 22 | // 23 | // Define here the type of autorotation that you want for your game 24 | // 25 | #define GAME_AUTOROTATION kGameAutorotationUIViewController 26 | 27 | 28 | #endif // __GAME_CONFIG_H -------------------------------------------------------------------------------- /Classes/HelloWorldScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // HelloWorldLayer.h 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 1/19/11. 6 | // Copyright __MyCompanyName__ 2011. All rights reserved. 7 | // 8 | 9 | 10 | // When you import this file, you import all the cocos2d classes 11 | #import "cocos2d.h" 12 | #import "TextBoxLayer.h" 13 | #import "TextBoxView.h" 14 | 15 | // HelloWorld Layer 16 | @interface HelloWorld : CCLayer 17 | { 18 | TextBoxLayer *textBox; 19 | TextBoxView *textBoxView; 20 | 21 | CCMenu *menu; 22 | 23 | BOOL isLayer; 24 | BOOL isView; 25 | } 26 | 27 | // returns a Scene that contains the HelloWorld as the only child 28 | +(id) scene; 29 | 30 | - (void)gameLoop:(ccTime) dT; 31 | 32 | - (void)onLayer:(id)sender; 33 | 34 | - (void)onView:(id)sender; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Classes/HelloWorldScene.m: -------------------------------------------------------------------------------- 1 | // 2 | // HelloWorldLayer.m 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 1/19/11. 6 | // Copyright __MyCompanyName__ 2011. All rights reserved. 7 | // 8 | 9 | // Import the interfaces 10 | #import "HelloWorldScene.h" 11 | 12 | // HelloWorld implementation 13 | @implementation HelloWorld 14 | 15 | +(id) scene 16 | { 17 | // 'scene' is an autorelease object. 18 | CCScene *scene = [CCScene node]; 19 | 20 | // 'layer' is an autorelease object. 21 | HelloWorld *layer = [HelloWorld node]; 22 | 23 | // add layer as a child to scene 24 | [scene addChild: layer]; 25 | 26 | [layer schedule:@selector(gameLoop:) interval:1/60.0f]; 27 | 28 | // return the scene 29 | return scene; 30 | } 31 | 32 | // on "init" you need to initialize your instance 33 | -(id) init 34 | { 35 | // always call "super" init 36 | // Apple recommends to re-assign "self" with the "super" return value 37 | if( (self=[super init] )) { 38 | 39 | isLayer = NO; 40 | isView = NO; 41 | 42 | // ask director the the window size 43 | CGSize size = [[CCDirector sharedDirector] winSize]; 44 | 45 | NSString *txt = @"This is a purposefully long text so as to test the wrapping functionality of the TextBoxLayer, as well as the multiple pages. That's it! This is the end, my only friend, the end."; 46 | 47 | textBox = [[TextBoxLayer alloc] initWithColor:[UIColor blueColor] width:200 height:80 padding:10 text:txt]; 48 | textBox.position = ccp( size.width /2 , size.height/2 ); 49 | textBox.delegate = self; 50 | 51 | textBoxView = [[TextBoxView alloc] initWithColor:[UIColor blueColor] width:200 height:80 padding:10 text:txt]; 52 | textBoxView.center = ccp( size.width /2 , size.height/2 ); 53 | textBoxView.delegate = self; 54 | 55 | CCMenuItemFont *itemLayer = [CCMenuItemFont itemFromString:@"Layer" target:self selector:@selector(onLayer:)]; 56 | CCMenuItemFont *itemView = [CCMenuItemFont itemFromString:@"View" target:self selector:@selector(onView:)]; 57 | 58 | menu = [CCMenu menuWithItems:itemLayer, itemView, nil]; 59 | [menu alignItemsHorizontallyWithPadding:20]; 60 | menu.position = ccp( size.width /2 , size.height/2 ); 61 | [self addChild:menu]; 62 | } 63 | return self; 64 | } 65 | 66 | // on "dealloc" you need to release all your retained objects 67 | - (void) dealloc 68 | { 69 | // in case you have something to dealloc, do it in this method 70 | // in this particular example nothing needs to be released. 71 | // cocos2d will automatically release all the children (Label) 72 | [textBox release]; 73 | [textBoxView release]; 74 | // don't forget to call "super dealloc" 75 | [super dealloc]; 76 | } 77 | 78 | - (void)gameLoop: (ccTime) dT { 79 | if (isLayer) { 80 | [textBox update:dT]; 81 | } 82 | 83 | if (isView) { 84 | [textBoxView update:dT]; 85 | } 86 | } 87 | 88 | - (void)onLayer:(id)sender { 89 | [self addChild:textBox]; 90 | isLayer = YES; 91 | [menu removeFromParentAndCleanup:YES]; 92 | } 93 | 94 | - (void)onView:(id)sender { 95 | [[CCDirector sharedDirector].openGLView addSubview:textBoxView]; 96 | isView = YES; 97 | [menu removeFromParentAndCleanup:YES]; 98 | } 99 | 100 | -(void) textBox:(id)tbox didFinishAllTextWithPageCount:(int)pc { 101 | if (isLayer) { 102 | [self removeChild:textBox cleanup:YES]; 103 | isLayer = NO; 104 | } 105 | 106 | if (isView) { 107 | [textBoxView removeFromSuperview]; 108 | isView = NO; 109 | } 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /Classes/RootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 1/19/11. 6 | // Copyright __MyCompanyName__ 2011. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface RootViewController : UIViewController { 13 | 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Classes/TextBox.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextBox.h 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 04/10/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define TEXT_SPEED 60 12 | #define TEXT_FONT_FILE @"arial16.fnt" 13 | 14 | @protocol TextBox 15 | 16 | - (id) initWithColor:(UIColor *)color 17 | width:(CGFloat)w 18 | height:(CGFloat)h 19 | padding:(CGFloat)padding 20 | text:(NSString *)txt; 21 | 22 | - (void)update:(float)dt; 23 | 24 | @end 25 | 26 | @protocol TextBoxDelegate 27 | 28 | - (void)textBox:(id)tbox didFinishAllTextWithPageCount:(int)pc; 29 | 30 | @optional 31 | - (void)textBox:(id)tbox didMoveToPage:(int)p; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Classes/TextBoxLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextBoxLayer.h 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 1/19/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "cocos2d.h" 11 | #import "TextBox.h" 12 | 13 | @interface TextBoxLayer : CCLayerColor { 14 | 15 | CCLabelBMFont *textLabel; 16 | 17 | NSString *text; 18 | NSMutableArray *lines; 19 | 20 | float progress; 21 | int linesPerPage; 22 | int currentPageIndex; 23 | NSMutableString *currentPage; 24 | int currentPageCharCount; 25 | 26 | int totalPages; 27 | 28 | id delegate; 29 | 30 | BOOL ended; 31 | } 32 | 33 | @property (readwrite,assign) id delegate; 34 | 35 | - (NSString *)nextPage; 36 | 37 | - (int)calculateStringSize:(NSString *)txt; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Classes/TextBoxLayerSampleAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextBoxLayerSampleAppDelegate.h 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 1/19/11. 6 | // Copyright __MyCompanyName__ 2011. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class RootViewController; 12 | 13 | @interface TextBoxLayerSampleAppDelegate : NSObject { 14 | UIWindow *window; 15 | RootViewController *viewController; 16 | } 17 | 18 | @property (nonatomic, retain) UIWindow *window; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Classes/TextBoxView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextBoxView.h 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 04/10/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TextBox.h" 11 | 12 | @interface TextBoxView : UIView { 13 | 14 | CGFloat width; 15 | CGFloat height; 16 | 17 | UILabel *label; 18 | NSString *text; 19 | float progress; 20 | 21 | int currentPage; 22 | 23 | NSMutableArray *pages; 24 | 25 | id delegate; 26 | } 27 | 28 | @property (readwrite,assign) id delegate; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Classes/TextBoxView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TextBoxView.m 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 04/10/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "TextBoxView.h" 10 | 11 | 12 | @implementation TextBoxView 13 | 14 | @synthesize delegate; 15 | 16 | - (id) initWithColor:(UIColor *)color width:(CGFloat)w height:(CGFloat)h padding:(CGFloat)padding text:(NSString *)txt { 17 | 18 | if ((self = [super initWithFrame:CGRectMake(0, 0, w + (padding * 2), h + (padding * 2))])) { 19 | self.backgroundColor = color; 20 | 21 | width = w; 22 | height = h; 23 | 24 | currentPage = 0; 25 | text = [txt retain]; 26 | 27 | label = [[UILabel alloc] initWithFrame:CGRectMake(padding, padding, w, h)]; 28 | label.text = @""; 29 | label.backgroundColor = [UIColor clearColor]; 30 | label.numberOfLines = 0; 31 | [self addSubview:label]; 32 | [label release]; 33 | 34 | NSArray *words = [txt componentsSeparatedByString:@" "]; 35 | 36 | NSString *curText = [words objectAtIndex:0]; 37 | int i = 1; 38 | 39 | pages = [[NSMutableArray alloc] init]; 40 | 41 | while (i < [words count]) { 42 | 43 | NSString *nextText = [curText stringByAppendingFormat:@" %@",[words objectAtIndex:i]]; 44 | CGSize size = [nextText sizeWithFont:label.font constrainedToSize:CGSizeMake(w, 99999) lineBreakMode:UILineBreakModeWordWrap]; 45 | 46 | if (size.height > h) { 47 | [pages addObject:curText]; 48 | curText = [words objectAtIndex:i]; 49 | } else { 50 | curText = nextText; 51 | } 52 | i++; 53 | } 54 | [pages addObject:curText]; 55 | } 56 | return self; 57 | } 58 | 59 | 60 | - (void)dealloc 61 | { 62 | [pages release]; 63 | [text release]; 64 | [super dealloc]; 65 | } 66 | 67 | - (void)update:(float)dt { 68 | 69 | NSString *page = [pages objectAtIndex:currentPage]; 70 | 71 | progress += (dt * TEXT_SPEED); 72 | 73 | int visible = progress; 74 | if (visible > [page length]) { 75 | visible = [page length]; 76 | } 77 | 78 | NSString *newTxt = [page substringToIndex:visible]; 79 | 80 | label.text = newTxt; 81 | label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, width, height); 82 | [label sizeToFit]; 83 | } 84 | 85 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 86 | 87 | NSString *page = [pages objectAtIndex:currentPage]; 88 | 89 | int visible = progress; 90 | if (visible >= [page length]) { 91 | 92 | if (currentPage == [pages count] - 1) { 93 | if ([delegate respondsToSelector:@selector(textBox:didFinishAllTextWithPageCount:)]) { 94 | [delegate textBox:(id) self didFinishAllTextWithPageCount:[pages count]]; 95 | } 96 | } else { 97 | currentPage++; 98 | progress = 0; 99 | 100 | if ([delegate respondsToSelector:@selector(textBox:didMoveToPage:)]) { 101 | [delegate textBox:(id) self didMoveToPage:currentPage]; 102 | } 103 | } 104 | 105 | } else { 106 | progress = [page length]; 107 | } 108 | } 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /LICENSE.cocos2d: -------------------------------------------------------------------------------- 1 | cocos2d for iPhone: http://www.cocos2d-iphone.org 2 | 3 | Copyright (c) 2008-2010 - Ricardo Quesada and contributors 4 | (see each file to see the different copyright owners) 5 | 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 | -------------------------------------------------------------------------------- /LICENSE.cocosdenshion: -------------------------------------------------------------------------------- 1 | CocosDenshion Sound Engine 2 | 3 | Copyright (c) 2010 Steve Oldmeadow 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | CCLayer subclass designed to handle RPG-like text boxes. Also included is an alternative implementation using UIKit instead. More information: http://www.crocodella.com.br/2011/01/rpg-like-text-box-with-cocos2d/ -------------------------------------------------------------------------------- /Resources/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/Default.png -------------------------------------------------------------------------------- /Resources/Icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/Icon-72.png -------------------------------------------------------------------------------- /Resources/Icon-Small-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/Icon-Small-50.png -------------------------------------------------------------------------------- /Resources/Icon-Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/Icon-Small.png -------------------------------------------------------------------------------- /Resources/Icon-Small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/Icon-Small@2x.png -------------------------------------------------------------------------------- /Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/Icon.png -------------------------------------------------------------------------------- /Resources/Icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/Icon@2x.png -------------------------------------------------------------------------------- /Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | Icon files 14 | 15 | Icon.png 16 | Icon@2x.png 17 | Icon-72.png 18 | Icon-Small-50.png 19 | Icon-Small.png 20 | Icon-Small@2x.png 21 | 22 | CFBundleIdentifier 23 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 24 | CFBundleInfoDictionaryVersion 25 | 6.0 26 | CFBundleName 27 | ${PRODUCT_NAME} 28 | CFBundlePackageType 29 | APPL 30 | CFBundleSignature 31 | ???? 32 | CFBundleVersion 33 | 1.0 34 | LSRequiresIPhoneOS 35 | 36 | UIPrerenderedIcon 37 | 38 | UIStatusBarHidden 39 | 40 | UIRequiredDeviceCapabilities 41 | 42 | accelerometer 43 | 44 | opengles-1 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Resources/ItunesArtwork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/ItunesArtwork -------------------------------------------------------------------------------- /Resources/arial16-hd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/arial16-hd.png -------------------------------------------------------------------------------- /Resources/arial16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/arial16.png -------------------------------------------------------------------------------- /Resources/fps_images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocodella/TextBoxLayerSample/18fd198ddee80b3e6019aa1924d39c411173d7c1/Resources/fps_images.png -------------------------------------------------------------------------------- /TextBoxLayerSample_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TextBoxLayerSample' target in the 'TextBoxLayerSample' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /libs/CocosDenshion/CDConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010 Steve Oldmeadow 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | $Id$ 23 | */ 24 | #define COCOSDENSHION_VERSION "Aphex.rc" 25 | 26 | 27 | /** 28 | If enabled code useful for debugging such as parameter check assertions will be performed. 29 | If you experience any problems you should enable this and test your code with a debug build. 30 | */ 31 | //#define CD_DEBUG 1 32 | 33 | /** 34 | The total number of sounds/buffers that can be loaded assuming memory is sufficient 35 | */ 36 | //Number of buffers slots that will be initially created 37 | #define CD_BUFFERS_START 64 38 | //Number of buffers that will be added 39 | #define CD_BUFFERS_INCREMENT 16 40 | 41 | /** 42 | If enabled, OpenAL code will use static buffers. When static buffers are used the audio 43 | data is managed outside of OpenAL, this eliminates a memcpy operation which leads to 44 | higher performance when loading sounds. 45 | 46 | However, the downside is that when the audio data is freed you must 47 | be certain that it is no longer being accessed otherwise your app will crash. Testing on OS 2.2.1 48 | and 3.1.2 has shown that this may occur if a buffer is being used by a source with state = AL_PLAYING 49 | when the buffer is deleted. If the data is freed too quickly after the source is stopped then 50 | a crash will occur. The implemented workaround is that when static buffers are used the unloadBuffer code will wait for 51 | any playing sources to finish playing before the associated buffer and data are deleted, however, this delay may negate any 52 | performance gains that are achieved during loading. 53 | 54 | Performance tests on a 1st gen iPod running OS 2.2.1 loading the CocosDenshionDemo sounds were ~0.14 seconds without 55 | static buffers and ~0.12 seconds when using static buffers. 56 | 57 | */ 58 | //#define CD_USE_STATIC_BUFFERS 1 59 | 60 | 61 | -------------------------------------------------------------------------------- /libs/CocosDenshion/CDOpenALSupport.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Disclaimer: IMPORTANT: This Apple software is supplied to you by 4 | Apple Inc. ("Apple") in consideration of your agreement to the 5 | following terms, and your use, installation, modification or 6 | redistribution of this Apple software constitutes acceptance of these 7 | terms. If you do not agree with these terms, please do not use, 8 | install, modify or redistribute this Apple software. 9 | 10 | In consideration of your agreement to abide by the following terms, and 11 | subject to these terms, Apple grants you a personal, non-exclusive 12 | license, under Apple's copyrights in this original Apple software (the 13 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 14 | Software, with or without modifications, in source and/or binary forms; 15 | provided that if you redistribute the Apple Software in its entirety and 16 | without modifications, you must retain this notice and the following 17 | text and disclaimers in all such redistributions of the Apple Software. 18 | Neither the name, trademarks, service marks or logos of Apple Inc. 19 | may be used to endorse or promote products derived from the Apple 20 | Software without specific prior written permission from Apple. Except 21 | as expressly stated in this notice, no other rights or licenses, express 22 | or implied, are granted by Apple herein, including but not limited to 23 | any patent rights that may be infringed by your derivative works or by 24 | other works in which the Apple Software may be incorporated. 25 | 26 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 27 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 28 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 29 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 30 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 31 | 32 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 33 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 36 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 37 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 38 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 39 | POSSIBILITY OF SUCH DAMAGE. 40 | 41 | Copyright (C) 2009 Apple Inc. All Rights Reserved. 42 | 43 | $Id$ 44 | */ 45 | 46 | /* 47 | This file contains code from version 1.1 and 1.4 of MyOpenALSupport.h taken from Apple's oalTouch version. 48 | The 1.4 version code is used for loading IMA4 files, however, this code causes very noticeable clicking 49 | when used to load wave files that are looped so the 1.1 version code is used specifically for loading 50 | wav files. 51 | */ 52 | 53 | #ifndef __CD_OPENAL_H 54 | #define __CD_OPENAL_H 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | 61 | #import 62 | #import 63 | #import 64 | 65 | 66 | //Taken from oalTouch MyOpenALSupport 1.1 67 | void* CDloadWaveAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate); 68 | void* CDloadCafAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate); 69 | void* CDGetOpenALAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | 77 | 78 | -------------------------------------------------------------------------------- /libs/FontLabel/FontLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // FontLabel.h 3 | // FontLabel 4 | // 5 | // Created by Kevin Ballard on 5/8/09. 6 | // Copyright © 2009 Zynga Game Networks 7 | // 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | 22 | #import 23 | #import 24 | 25 | @class ZFont; 26 | @class ZAttributedString; 27 | 28 | @interface FontLabel : UILabel { 29 | void *reserved; // works around a bug in UILabel 30 | ZFont *zFont; 31 | ZAttributedString *zAttributedText; 32 | } 33 | @property (nonatomic, setter=setCGFont:) CGFontRef cgFont __AVAILABILITY_INTERNAL_DEPRECATED; 34 | @property (nonatomic, assign) CGFloat pointSize __AVAILABILITY_INTERNAL_DEPRECATED; 35 | @property (nonatomic, retain, setter=setZFont:) ZFont *zFont; 36 | // if attributedText is nil, fall back on using the inherited UILabel properties 37 | // if attributedText is non-nil, the font/text/textColor 38 | // in addition, adjustsFontSizeToFitWidth does not work with attributed text 39 | @property (nonatomic, copy) ZAttributedString *zAttributedText; 40 | // -initWithFrame:fontName:pointSize: uses FontManager to look up the font name 41 | - (id)initWithFrame:(CGRect)frame fontName:(NSString *)fontName pointSize:(CGFloat)pointSize; 42 | - (id)initWithFrame:(CGRect)frame zFont:(ZFont *)font; 43 | - (id)initWithFrame:(CGRect)frame font:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; 44 | @end 45 | -------------------------------------------------------------------------------- /libs/FontLabel/FontManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // FontManager.h 3 | // FontLabel 4 | // 5 | // Created by Kevin Ballard on 5/5/09. 6 | // Copyright © 2009 Zynga Game Networks 7 | // 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | 22 | #import 23 | #import 24 | 25 | @class ZFont; 26 | 27 | @interface FontManager : NSObject { 28 | CFMutableDictionaryRef fonts; 29 | NSMutableDictionary *urls; 30 | } 31 | + (FontManager *)sharedManager; 32 | /*! 33 | @method 34 | @abstract Loads a TTF font from the main bundle 35 | @param filename The name of the font file to load (with or without extension). 36 | @return YES if the font was loaded, NO if an error occurred 37 | @discussion If the font has already been loaded, this method does nothing and returns YES. 38 | This method first attempts to load the font by appending .ttf to the filename. 39 | If that file does not exist, it tries the filename exactly as given. 40 | */ 41 | - (BOOL)loadFont:(NSString *)filename; 42 | /*! 43 | @method 44 | @abstract Loads a font from the given file URL 45 | @param url A file URL that points to a font file 46 | @return YES if the font was loaded, NO if an error occurred 47 | @discussion If the font has already been loaded, this method does nothing and returns YES. 48 | */ 49 | - (BOOL)loadFontURL:(NSURL *)url; 50 | /*! 51 | @method 52 | @abstract Returns the loaded font with the given filename 53 | @param filename The name of the font file that was given to -loadFont: 54 | @return A CGFontRef, or NULL if the specified font cannot be found 55 | @discussion If the font has not been loaded yet, -loadFont: will be 56 | called with the given name first. 57 | */ 58 | - (CGFontRef)fontWithName:(NSString *)filename __AVAILABILITY_INTERNAL_DEPRECATED; 59 | /*! 60 | @method 61 | @abstract Returns a ZFont object corresponding to the loaded font with the given filename and point size 62 | @param filename The name of the font file that was given to -loadFont: 63 | @param pointSize The point size of the font 64 | @return A ZFont, or NULL if the specified font cannot be found 65 | @discussion If the font has not been loaded yet, -loadFont: will be 66 | called with the given name first. 67 | */ 68 | - (ZFont *)zFontWithName:(NSString *)filename pointSize:(CGFloat)pointSize; 69 | /*! 70 | @method 71 | @abstract Returns a ZFont object corresponding to the loaded font with the given file URL and point size 72 | @param url A file URL that points to a font file 73 | @param pointSize The point size of the font 74 | @return A ZFont, or NULL if the specified font cannot be loaded 75 | @discussion If the font has not been loaded yet, -loadFontURL: will be called with the given URL first. 76 | */ 77 | - (ZFont *)zFontWithURL:(NSURL *)url pointSize:(CGFloat)pointSize; 78 | /*! 79 | @method 80 | @abstract Returns a CFArrayRef of all loaded CGFont objects 81 | @return A CFArrayRef of all loaded CGFont objects 82 | @description You are responsible for releasing the CFArrayRef 83 | */ 84 | - (CFArrayRef)copyAllFonts; 85 | @end 86 | -------------------------------------------------------------------------------- /libs/FontLabel/ZAttributedString.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZAttributedString.h 3 | // FontLabel 4 | // 5 | // Created by Kevin Ballard on 9/22/09. 6 | // Copyright 2009 Zynga Game Networks. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #if NS_BLOCKS_AVAILABLE 12 | #define Z_BLOCKS 1 13 | #else 14 | // set this to 1 if you are using PLBlocks 15 | #define Z_BLOCKS 0 16 | #endif 17 | 18 | #if Z_BLOCKS 19 | enum { 20 | ZAttributedStringEnumerationReverse = (1UL << 1), 21 | ZAttributedStringEnumerationLongestEffectiveRangeNotRequired = (1UL << 20) 22 | }; 23 | typedef NSUInteger ZAttributedStringEnumerationOptions; 24 | #endif 25 | 26 | @interface ZAttributedString : NSObject { 27 | NSMutableString *_buffer; 28 | NSMutableArray *_attributes; 29 | } 30 | @property (nonatomic, readonly) NSUInteger length; 31 | @property (nonatomic, readonly) NSString *string; 32 | - (id)initWithAttributedString:(ZAttributedString *)attr; 33 | - (id)initWithString:(NSString *)str; 34 | - (id)initWithString:(NSString *)str attributes:(NSDictionary *)attributes; 35 | - (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange; 36 | - (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit; 37 | - (ZAttributedString *)attributedSubstringFromRange:(NSRange)aRange; 38 | - (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange; 39 | - (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit; 40 | #if Z_BLOCKS 41 | - (void)enumerateAttribute:(NSString *)attrName inRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts 42 | usingBlock:(void (^)(id value, NSRange range, BOOL *stop))block; 43 | - (void)enumerateAttributesInRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts 44 | usingBlock:(void (^)(NSDictionary *attrs, NSRange range, BOOL *stop))block; 45 | #endif 46 | - (BOOL)isEqualToAttributedString:(ZAttributedString *)otherString; 47 | @end 48 | 49 | @interface ZMutableAttributedString : ZAttributedString { 50 | } 51 | - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range; 52 | - (void)addAttributes:(NSDictionary *)attributes range:(NSRange)range; 53 | - (void)appendAttributedString:(ZAttributedString *)str; 54 | - (void)deleteCharactersInRange:(NSRange)range; 55 | - (void)insertAttributedString:(ZAttributedString *)str atIndex:(NSUInteger)idx; 56 | - (void)removeAttribute:(NSString *)name range:(NSRange)range; 57 | - (void)replaceCharactersInRange:(NSRange)range withAttributedString:(ZAttributedString *)str; 58 | - (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str; 59 | - (void)setAttributedString:(ZAttributedString *)str; 60 | - (void)setAttributes:(NSDictionary *)attributes range:(NSRange)range; 61 | @end 62 | 63 | extern NSString * const ZFontAttributeName; 64 | extern NSString * const ZForegroundColorAttributeName; 65 | extern NSString * const ZBackgroundColorAttributeName; 66 | extern NSString * const ZUnderlineStyleAttributeName; 67 | 68 | enum { 69 | ZUnderlineStyleNone = 0x00, 70 | ZUnderlineStyleSingle = 0x01 71 | }; 72 | #define ZUnderlineStyleMask 0x00FF 73 | 74 | enum { 75 | ZUnderlinePatternSolid = 0x0000 76 | }; 77 | #define ZUnderlinePatternMask 0xFF00 78 | -------------------------------------------------------------------------------- /libs/FontLabel/ZAttributedStringPrivate.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZAttributedStringPrivate.h 3 | // FontLabel 4 | // 5 | // Created by Kevin Ballard on 9/23/09. 6 | // Copyright 2009 Zynga Game Networks. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ZAttributedString.h" 11 | 12 | @interface ZAttributeRun : NSObject { 13 | NSUInteger _index; 14 | NSMutableDictionary *_attributes; 15 | } 16 | @property (nonatomic, readonly) NSUInteger index; 17 | @property (nonatomic, readonly) NSMutableDictionary *attributes; 18 | + (id)attributeRunWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs; 19 | - (id)initWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs; 20 | @end 21 | 22 | @interface ZAttributedString (ZAttributedStringPrivate) 23 | @property (nonatomic, readonly) NSArray *attributes; 24 | @end 25 | -------------------------------------------------------------------------------- /libs/FontLabel/ZFont.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZFont.h 3 | // FontLabel 4 | // 5 | // Created by Kevin Ballard on 7/2/09. 6 | // Copyright © 2009 Zynga Game Networks 7 | // 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | 22 | #import 23 | #import 24 | 25 | @interface ZFont : NSObject { 26 | CGFontRef _cgFont; 27 | CGFloat _pointSize; 28 | CGFloat _ratio; 29 | NSString *_familyName; 30 | NSString *_fontName; 31 | NSString *_postScriptName; 32 | } 33 | @property (nonatomic, readonly) CGFontRef cgFont; 34 | @property (nonatomic, readonly) CGFloat pointSize; 35 | @property (nonatomic, readonly) CGFloat ascender; 36 | @property (nonatomic, readonly) CGFloat descender; 37 | @property (nonatomic, readonly) CGFloat leading; 38 | @property (nonatomic, readonly) CGFloat xHeight; 39 | @property (nonatomic, readonly) CGFloat capHeight; 40 | @property (nonatomic, readonly) NSString *familyName; 41 | @property (nonatomic, readonly) NSString *fontName; 42 | @property (nonatomic, readonly) NSString *postScriptName; 43 | + (ZFont *)fontWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize; 44 | + (ZFont *)fontWithUIFont:(UIFont *)uiFont; 45 | - (id)initWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize; 46 | - (ZFont *)fontWithSize:(CGFloat)fontSize; 47 | @end 48 | -------------------------------------------------------------------------------- /libs/README: -------------------------------------------------------------------------------- 1 | This directory contains the libraries used in cocos2d 2 | -------------------------------------------------------------------------------- /libs/TouchJSON/CDataScanner.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDataScanner.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 04/16/08. 6 | // Copyright (c) 2008 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | // NSScanner 33 | 34 | @interface CDataScanner : NSObject { 35 | NSData *data; 36 | 37 | u_int8_t *start; 38 | u_int8_t *end; 39 | u_int8_t *current; 40 | NSUInteger length; 41 | 42 | NSCharacterSet *doubleCharacters; 43 | } 44 | 45 | @property (readwrite, nonatomic, retain) NSData *data; 46 | @property (readwrite, nonatomic, assign) NSUInteger scanLocation; 47 | @property (readonly, nonatomic, assign) BOOL isAtEnd; 48 | 49 | + (id)scannerWithData:(NSData *)inData; 50 | 51 | - (unichar)currentCharacter; 52 | - (unichar)scanCharacter; 53 | - (BOOL)scanCharacter:(unichar)inCharacter; 54 | 55 | - (BOOL)scanUTF8String:(const char *)inString intoString:(NSString **)outValue; 56 | - (BOOL)scanString:(NSString *)inString intoString:(NSString **)outValue; 57 | - (BOOL)scanCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString **)outValue; // inSet must only contain 7-bit ASCII characters 58 | 59 | - (BOOL)scanUpToString:(NSString *)string intoString:(NSString **)outValue; 60 | - (BOOL)scanUpToCharactersFromSet:(NSCharacterSet *)set intoString:(NSString **)outValue; // inSet must only contain 7-bit ASCII characters 61 | 62 | - (BOOL)scanNumber:(NSNumber **)outValue; 63 | 64 | - (void)skipWhitespace; 65 | 66 | - (NSString *)remainingString; 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /libs/TouchJSON/Extensions/CDataScanner_Extensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDataScanner_Extensions.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CDataScanner.h" 31 | 32 | @interface CDataScanner (CDataScanner_Extensions) 33 | 34 | - (BOOL)scanCStyleComment:(NSString **)outComment; 35 | - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /libs/TouchJSON/Extensions/CDataScanner_Extensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSScanner_Extensions.m 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CDataScanner_Extensions.h" 31 | 32 | #import "NSCharacterSet_Extensions.h" 33 | 34 | @implementation CDataScanner (CDataScanner_Extensions) 35 | 36 | - (BOOL)scanCStyleComment:(NSString **)outComment 37 | { 38 | if ([self scanString:@"/*" intoString:NULL] == YES) 39 | { 40 | NSString *theComment = NULL; 41 | if ([self scanUpToString:@"*/" intoString:&theComment] == NO) 42 | [NSException raise:NSGenericException format:@"Started to scan a C style comment but it wasn't terminated."]; 43 | 44 | if ([theComment rangeOfString:@"/*"].location != NSNotFound) 45 | [NSException raise:NSGenericException format:@"C style comments should not be nested."]; 46 | 47 | if ([self scanString:@"*/" intoString:NULL] == NO) 48 | [NSException raise:NSGenericException format:@"C style comment did not end correctly."]; 49 | 50 | if (outComment != NULL) 51 | *outComment = theComment; 52 | 53 | return(YES); 54 | } 55 | else 56 | { 57 | return(NO); 58 | } 59 | } 60 | 61 | - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment 62 | { 63 | if ([self scanString:@"//" intoString:NULL] == YES) 64 | { 65 | NSString *theComment = NULL; 66 | [self scanUpToCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:&theComment]; 67 | [self scanCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:NULL]; 68 | 69 | if (outComment != NULL) 70 | *outComment = theComment; 71 | 72 | return(YES); 73 | } 74 | else 75 | { 76 | return(NO); 77 | } 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /libs/TouchJSON/Extensions/NSCharacterSet_Extensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSCharacterSet_Extensions.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface NSCharacterSet (NSCharacterSet_Extensions) 33 | 34 | + (NSCharacterSet *)linebreaksCharacterSet; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /libs/TouchJSON/Extensions/NSCharacterSet_Extensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSCharacterSet_Extensions.m 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "NSCharacterSet_Extensions.h" 31 | 32 | @implementation NSCharacterSet (NSCharacterSet_Extensions) 33 | 34 | #define LF 0x000a // Line Feed 35 | #define FF 0x000c // Form Feed 36 | #define CR 0x000d // Carriage Return 37 | #define NEL 0x0085 // Next Line 38 | #define LS 0x2028 // Line Separator 39 | #define PS 0x2029 // Paragraph Separator 40 | 41 | + (NSCharacterSet *)linebreaksCharacterSet 42 | { 43 | unichar theCharacters[] = { LF, FF, CR, NEL, LS, PS, }; 44 | 45 | return([NSCharacterSet characterSetWithCharactersInString:[NSString stringWithCharacters:theCharacters length:sizeof(theCharacters) / sizeof(*theCharacters)]]); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /libs/TouchJSON/Extensions/NSDictionary_JSONExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary_JSONExtensions.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 04/17/08. 6 | // Copyright (c) 2008 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface NSDictionary (NSDictionary_JSONExtensions) 33 | 34 | + (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /libs/TouchJSON/Extensions/NSDictionary_JSONExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary_JSONExtensions.m 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 04/17/08. 6 | // Copyright (c) 2008 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "NSDictionary_JSONExtensions.h" 31 | 32 | #import "CJSONDeserializer.h" 33 | 34 | @implementation NSDictionary (NSDictionary_JSONExtensions) 35 | 36 | + (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError 37 | { 38 | return([[CJSONDeserializer deserializer] deserialize:inData error:outError]); 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /libs/TouchJSON/Extensions/NSScanner_Extensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSScanner_Extensions.h 3 | // CocoaJSON 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface NSScanner (NSScanner_Extensions) 33 | 34 | - (NSString *)remainingString; 35 | 36 | - (unichar)currentCharacter; 37 | - (unichar)scanCharacter; 38 | - (BOOL)scanCharacter:(unichar)inCharacter; 39 | - (void)backtrack:(unsigned)inCount; 40 | 41 | - (BOOL)scanCStyleComment:(NSString **)outComment; 42 | - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /libs/TouchJSON/JSON/CJSONDeserializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONDeserializer.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/15/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | extern NSString *const kJSONDeserializerErrorDomain /* = @"CJSONDeserializerErrorDomain" */; 33 | 34 | @protocol CDeserializerProtocol 35 | 36 | - (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError; 37 | 38 | @end 39 | 40 | #pragma mark - 41 | 42 | @interface CJSONDeserializer : NSObject { 43 | 44 | } 45 | 46 | + (id)deserializer; 47 | 48 | - (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError; 49 | 50 | @end 51 | 52 | #pragma mark - 53 | 54 | @interface CJSONDeserializer (CJSONDeserializer_Deprecated) 55 | 56 | /// You should switch to using deserializeAsDictionary:error: instead. 57 | - (id)deserialize:(NSData *)inData error:(NSError **)outError; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /libs/TouchJSON/JSON/CJSONDeserializer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONDeserializer.m 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/15/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CJSONDeserializer.h" 31 | 32 | #import "CJSONScanner.h" 33 | #import "CDataScanner.h" 34 | 35 | NSString *const kJSONDeserializerErrorDomain = @"CJSONDeserializerErrorDomain"; 36 | 37 | @implementation CJSONDeserializer 38 | 39 | + (id)deserializer 40 | { 41 | return([[[self alloc] init] autorelease]); 42 | } 43 | 44 | - (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError; 45 | { 46 | if (inData == NULL || [inData length] == 0) 47 | { 48 | if (outError) 49 | *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL]; 50 | 51 | return(NULL); 52 | } 53 | CJSONScanner *theScanner = [CJSONScanner scannerWithData:inData]; 54 | NSDictionary *theDictionary = NULL; 55 | if ([theScanner scanJSONDictionary:&theDictionary error:outError] == YES) 56 | return(theDictionary); 57 | else 58 | return(NULL); 59 | } 60 | 61 | @end 62 | 63 | #pragma mark - 64 | 65 | @implementation CJSONDeserializer (CJSONDeserializer_Deprecated) 66 | 67 | - (id)deserialize:(NSData *)inData error:(NSError **)outError 68 | { 69 | if (inData == NULL || [inData length] == 0) 70 | { 71 | if (outError) 72 | *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL]; 73 | 74 | return(NULL); 75 | } 76 | CJSONScanner *theScanner = [CJSONScanner scannerWithData:inData]; 77 | id theObject = NULL; 78 | if ([theScanner scanJSONObject:&theObject error:outError] == YES) 79 | return(theObject); 80 | else 81 | return(NULL); 82 | } 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /libs/TouchJSON/JSON/CJSONScanner.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONScanner.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/07/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CDataScanner.h" 31 | 32 | @interface CJSONScanner : CDataScanner { 33 | } 34 | 35 | - (BOOL)scanJSONObject:(id *)outObject error:(NSError **)outError; 36 | - (BOOL)scanJSONDictionary:(NSDictionary **)outDictionary error:(NSError **)outError; 37 | - (BOOL)scanJSONArray:(NSArray **)outArray error:(NSError **)outError; 38 | - (BOOL)scanJSONStringConstant:(NSString **)outStringConstant error:(NSError **)outError; 39 | - (BOOL)scanJSONNumberConstant:(NSNumber **)outNumberConstant error:(NSError **)outError; 40 | 41 | @end 42 | 43 | extern NSString *const kJSONScannerErrorDomain /* = @"CJSONScannerErrorDomain" */; 44 | -------------------------------------------------------------------------------- /libs/TouchJSON/JSON/CJSONSerializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONSerializer.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 12/07/2005. 6 | // Copyright (c) 2005 Jonathan Wight 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface CJSONSerializer : NSObject { 33 | } 34 | 35 | + (id)serializer; 36 | 37 | - (NSString *)serializeObject:(id)inObject; 38 | 39 | - (NSString *)serializeNull:(NSNull *)inNull; 40 | - (NSString *)serializeNumber:(NSNumber *)inNumber; 41 | - (NSString *)serializeString:(NSString *)inString; 42 | - (NSString *)serializeArray:(NSArray *)inArray; 43 | - (NSString *)serializeDictionary:(NSDictionary *)inDictionary; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /libs/cocos2d/CCActionCamera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "CCActionInterval.h" 27 | 28 | @class CCCamera; 29 | 30 | /** Base class for CCCamera actions 31 | */ 32 | @interface CCActionCamera : CCActionInterval 33 | { 34 | float centerXOrig_; 35 | float centerYOrig_; 36 | float centerZOrig_; 37 | 38 | float eyeXOrig_; 39 | float eyeYOrig_; 40 | float eyeZOrig_; 41 | 42 | float upXOrig_; 43 | float upYOrig_; 44 | float upZOrig_; 45 | } 46 | @end 47 | 48 | /** CCOrbitCamera action 49 | Orbits the camera around the center of the screen using spherical coordinates 50 | */ 51 | @interface CCOrbitCamera : CCActionCamera 52 | { 53 | float radius_; 54 | float deltaRadius_; 55 | float angleZ_; 56 | float deltaAngleZ_; 57 | float angleX_; 58 | float deltaAngleX_; 59 | 60 | float radZ_; 61 | float radDeltaZ_; 62 | float radX_; 63 | float radDeltaX_; 64 | 65 | } 66 | /** creates a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ 67 | +(id) actionWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; 68 | /** initializes a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ 69 | -(id) initWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; 70 | /** positions the camera according to spherical coordinates */ 71 | -(void) sphericalRadius:(float*) r zenith:(float*) zenith azimuth:(float*) azimuth; 72 | @end 73 | -------------------------------------------------------------------------------- /libs/cocos2d/CCActionPageTurn3D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCActionGrid3D.h" 28 | 29 | /** 30 | * This action simulates a page turn from the bottom right hand corner of the screen 31 | * It's not much use by itself but is used by the PageTurnTransition. 32 | * 33 | * Based on an original paper by L Hong et al. 34 | * http://www.parc.com/publication/1638/turning-pages-of-3d-electronic-books.html 35 | * 36 | * @since v0.8.2 37 | */ 38 | @interface CCPageTurn3D : CCGrid3DAction 39 | { 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /libs/cocos2d/CCActionPageTurn3D.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "CCActionPageTurn3D.h" 27 | 28 | @implementation CCPageTurn3D 29 | 30 | /* 31 | * Update each tick 32 | * Time is the percentage of the way through the duration 33 | */ 34 | -(void)update:(ccTime)time 35 | { 36 | float tt = MAX( 0, time - 0.25f ); 37 | float deltaAy = ( tt * tt * 500); 38 | float ay = -100 - deltaAy; 39 | 40 | float deltaTheta = - (float) M_PI_2 * sqrtf( time) ; 41 | float theta = /*0.01f*/ + (float) M_PI_2 +deltaTheta; 42 | 43 | float sinTheta = sinf(theta); 44 | float cosTheta = cosf(theta); 45 | 46 | for( int i = 0; i <=gridSize_.x; i++ ) 47 | { 48 | for( int j = 0; j <= gridSize_.y; j++ ) 49 | { 50 | // Get original vertex 51 | ccVertex3F p = [self originalVertex:ccg(i,j)]; 52 | 53 | float R = sqrtf(p.x*p.x + (p.y - ay) * (p.y - ay)); 54 | float r = R * sinTheta; 55 | float alpha = asinf( p.x / R ); 56 | float beta = alpha / sinTheta; 57 | float cosBeta = cosf( beta ); 58 | 59 | // If beta > PI then we've wrapped around the cone 60 | // Reduce the radius to stop these points interfering with others 61 | if( beta <= M_PI) 62 | p.x = ( r * sinf(beta)); 63 | else 64 | { 65 | // Force X = 0 to stop wrapped 66 | // points 67 | p.x = 0; 68 | } 69 | 70 | p.y = ( R + ay - ( r*(1 - cosBeta)*sinTheta)); 71 | 72 | // We scale z here to avoid the animation being 73 | // too much bigger than the screen due to perspectve transform 74 | p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7; // "100" didn't work for 75 | 76 | // Stop z coord from dropping beneath underlying page in a transition 77 | // issue #751 78 | if( p.z<0.5f ) 79 | p.z = 0.5f; 80 | 81 | // Set new coords 82 | [self setVertex:ccg(i,j) vertex:p]; 83 | } 84 | } 85 | } 86 | @end 87 | -------------------------------------------------------------------------------- /libs/cocos2d/CCActionProgressTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (C) 2010 Lam Pham 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | #import "CCProgressTimer.h" 29 | #import "CCActionInterval.h" 30 | 31 | /** 32 | Progress to percentage 33 | @since v0.99.1 34 | */ 35 | @interface CCProgressTo : CCActionInterval 36 | { 37 | float to_; 38 | float from_; 39 | } 40 | /** Creates and initializes with a duration and a percent */ 41 | +(id) actionWithDuration:(ccTime)duration percent:(float)percent; 42 | /** Initializes with a duration and a percent */ 43 | -(id) initWithDuration:(ccTime)duration percent:(float)percent; 44 | @end 45 | 46 | /** 47 | Progress from a percentage to another percentage 48 | @since v0.99.1 49 | */ 50 | @interface CCProgressFromTo : CCActionInterval 51 | { 52 | float to_; 53 | float from_; 54 | } 55 | /** Creates and initializes the action with a duration, a "from" percentage and a "to" percentage */ 56 | +(id) actionWithDuration:(ccTime)duration from:(float)fromPercentage to:(float) toPercentage; 57 | /** Initializes the action with a duration, a "from" percentage and a "to" percentage */ 58 | -(id) initWithDuration:(ccTime)duration from:(float)fromPercentage to:(float) toPercentage; 59 | @end 60 | -------------------------------------------------------------------------------- /libs/cocos2d/CCActionProgressTimer.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (C) 2010 Lam Pham 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCActionProgressTimer.h" 28 | 29 | #define kProgressTimerCast CCProgressTimer* 30 | 31 | @implementation CCProgressTo 32 | +(id) actionWithDuration: (ccTime) t percent: (float) v 33 | { 34 | return [[[ self alloc] initWithDuration: t percent: v] autorelease]; 35 | } 36 | 37 | -(id) initWithDuration: (ccTime) t percent: (float) v 38 | { 39 | if( (self=[super initWithDuration: t] ) ) 40 | to_ = v; 41 | 42 | return self; 43 | } 44 | 45 | -(id) copyWithZone: (NSZone*) zone 46 | { 47 | CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:duration_ percent:to_]; 48 | return copy; 49 | } 50 | 51 | -(void) startWithTarget:(id) aTarget; 52 | { 53 | [super startWithTarget:aTarget]; 54 | from_ = [(kProgressTimerCast)target_ percentage]; 55 | 56 | // XXX: Is this correct ? 57 | // Adding it to support CCRepeat 58 | if( from_ == 100) 59 | from_ = 0; 60 | } 61 | 62 | -(void) update: (ccTime) t 63 | { 64 | [(kProgressTimerCast)target_ setPercentage: from_ + ( to_ - from_ ) * t]; 65 | } 66 | @end 67 | 68 | @implementation CCProgressFromTo 69 | +(id) actionWithDuration: (ccTime) t from:(float)fromPercentage to:(float) toPercentage 70 | { 71 | return [[[self alloc] initWithDuration: t from: fromPercentage to: toPercentage] autorelease]; 72 | } 73 | 74 | -(id) initWithDuration: (ccTime) t from:(float)fromPercentage to:(float) toPercentage 75 | { 76 | if( (self=[super initWithDuration: t] ) ){ 77 | to_ = toPercentage; 78 | from_ = fromPercentage; 79 | } 80 | return self; 81 | } 82 | 83 | -(id) copyWithZone: (NSZone*) zone 84 | { 85 | CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:duration_ from:from_ to:to_]; 86 | return copy; 87 | } 88 | 89 | - (CCActionInterval *) reverse 90 | { 91 | return [[self class] actionWithDuration:duration_ from:to_ to:from_]; 92 | } 93 | 94 | -(void) startWithTarget:(id) aTarget; 95 | { 96 | [super startWithTarget:aTarget]; 97 | } 98 | 99 | -(void) update: (ccTime) t 100 | { 101 | [(kProgressTimerCast)target_ setPercentage: from_ + ( to_ - from_ ) * t]; 102 | } 103 | @end 104 | -------------------------------------------------------------------------------- /libs/cocos2d/CCActionTween.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright 2009 lhunath (Maarten Billemont) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | #import "CCActionInterval.h" 29 | 30 | /** CCActionTween 31 | 32 | CCActionTween is an action that lets you update any property of an object. 33 | For example, if you want to modify the "width" property of a target from 200 to 300 in 2 senconds, then: 34 | 35 | id modifyWidth = [CCActionTween actionWithDuration:2 key:@"width" from:200 to:300]; 36 | [target runAction:modifyWidth]; 37 | 38 | 39 | Another example: CCScaleTo action could be rewriten using CCPropertyAction: 40 | 41 | // scaleA and scaleB are equivalents 42 | id scaleA = [CCScaleTo actionWithDuration:2 scale:3]; 43 | id scaleB = [CCActionTween actionWithDuration:2 key:@"scale" from:1 to:3]; 44 | 45 | 46 | @since v0.99.2 47 | */ 48 | @interface CCActionTween : CCActionInterval 49 | { 50 | NSString *key_; 51 | 52 | float from_, to_; 53 | float delta_; 54 | } 55 | 56 | /** creates an initializes the action with the property name (key), and the from and to parameters. */ 57 | + (id)actionWithDuration:(ccTime)aDuration key:(NSString *)key from:(float)from to:(float)to; 58 | 59 | /** initializes the action with the property name (key), and the from and to parameters. */ 60 | - (id)initWithDuration:(ccTime)aDuration key:(NSString *)key from:(float)from to:(float)to; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /libs/cocos2d/CCActionTween.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright 2009 lhunath (Maarten Billemont) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "CCActionTween.h" 27 | 28 | 29 | @implementation CCActionTween 30 | 31 | + (id)actionWithDuration:(ccTime)aDuration key:(NSString *)aKey from:(float)aFrom to:(float)aTo { 32 | 33 | return [[[[self class] alloc] initWithDuration:aDuration key:aKey from:aFrom to:aTo] autorelease]; 34 | } 35 | 36 | - (id)initWithDuration:(ccTime)aDuration key:(NSString *)key from:(float)from to:(float)to { 37 | 38 | if ((self = [super initWithDuration:aDuration])) { 39 | 40 | key_ = [key copy]; 41 | to_ = to; 42 | from_ = from; 43 | 44 | } 45 | 46 | return self; 47 | } 48 | 49 | - (void) dealloc 50 | { 51 | [key_ release]; 52 | [super dealloc]; 53 | } 54 | 55 | - (void)startWithTarget:aTarget 56 | { 57 | [super startWithTarget:aTarget]; 58 | delta_ = to_ - from_; 59 | } 60 | 61 | - (void) update:(ccTime) dt 62 | { 63 | [target_ setValue:[NSNumber numberWithFloat:to_ - delta_ * (1 - dt)] forKey:key_]; 64 | } 65 | 66 | - (CCActionInterval *) reverse 67 | { 68 | return [[self class] actionWithDuration:duration_ key:key_ from:to_ to:from_]; 69 | } 70 | 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /libs/cocos2d/CCAnimationCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import 27 | 28 | @class CCAnimation; 29 | 30 | /** Singleton that manages the Animations. 31 | It saves in a cache the animations. You should use this class if you want to save your animations in a cache. 32 | 33 | Before v0.99.5, the recommend way was to save them on the CCSprite. Since v0.99.5, you should use this class instead. 34 | 35 | @since v0.99.5 36 | */ 37 | @interface CCAnimationCache : NSObject 38 | { 39 | NSMutableDictionary *animations_; 40 | } 41 | 42 | /** Retruns ths shared instance of the Animation cache */ 43 | + (CCAnimationCache *) sharedAnimationCache; 44 | 45 | /** Purges the cache. It releases all the CCAnimation objects and the shared instance. 46 | */ 47 | +(void)purgeSharedAnimationCache; 48 | 49 | /** Adds a CCAnimation with a name. 50 | */ 51 | -(void) addAnimation:(CCAnimation*)animation name:(NSString*)name; 52 | 53 | /** Deletes a CCAnimation from the cache. 54 | */ 55 | -(void) removeAnimationByName:(NSString*)name; 56 | 57 | /** Returns a CCAnimation that was previously added. 58 | If the name is not found it will return nil. 59 | You should retain the returned copy if you are going to use it. 60 | */ 61 | -(CCAnimation*) animationByName:(NSString*)name; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /libs/cocos2d/CCAnimationCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "ccMacros.h" 27 | #import "CCAnimationCache.h" 28 | #import "CCAnimation.h" 29 | #import "CCSprite.h" 30 | 31 | 32 | @implementation CCAnimationCache 33 | 34 | #pragma mark CCAnimationCache - Alloc, Init & Dealloc 35 | 36 | static CCAnimationCache *sharedAnimationCache_=nil; 37 | 38 | + (CCAnimationCache *)sharedAnimationCache 39 | { 40 | if (!sharedAnimationCache_) 41 | sharedAnimationCache_ = [[CCAnimationCache alloc] init]; 42 | 43 | return sharedAnimationCache_; 44 | } 45 | 46 | +(id)alloc 47 | { 48 | NSAssert(sharedAnimationCache_ == nil, @"Attempted to allocate a second instance of a singleton."); 49 | return [super alloc]; 50 | } 51 | 52 | +(void)purgeSharedAnimationCache 53 | { 54 | [sharedAnimationCache_ release]; 55 | sharedAnimationCache_ = nil; 56 | } 57 | 58 | -(id) init 59 | { 60 | if( (self=[super init]) ) { 61 | animations_ = [[NSMutableDictionary alloc] initWithCapacity: 20]; 62 | } 63 | 64 | return self; 65 | } 66 | 67 | - (NSString*) description 68 | { 69 | return [NSString stringWithFormat:@"<%@ = %08X | num of animations = %i>", [self class], self, [animations_ count]]; 70 | } 71 | 72 | -(void) dealloc 73 | { 74 | CCLOGINFO(@"cocos2d: deallocing %@", self); 75 | 76 | [animations_ release]; 77 | [super dealloc]; 78 | } 79 | 80 | #pragma mark CCAnimationCache - load/get/del 81 | 82 | -(void) addAnimation:(CCAnimation*)animation name:(NSString*)name 83 | { 84 | [animations_ setObject:animation forKey:name]; 85 | } 86 | 87 | -(void) removeAnimationByName:(NSString*)name 88 | { 89 | if( ! name ) 90 | return; 91 | 92 | [animations_ removeObjectForKey:name]; 93 | } 94 | 95 | -(CCAnimation*) animationByName:(NSString*)name 96 | { 97 | return [animations_ objectForKey:name]; 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /libs/cocos2d/CCAtlasNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | #import "CCTextureAtlas.h" 27 | #import "CCNode.h" 28 | #import "CCProtocols.h" 29 | 30 | /** CCAtlasNode is a subclass of CCNode that implements the CCRGBAProtocol and 31 | CCTextureProtocol protocol 32 | 33 | It knows how to render a TextureAtlas object. 34 | If you are going to render a TextureAtlas consider subclassing CCAtlasNode (or a subclass of CCAtlasNode) 35 | 36 | All features from CCNode are valid, plus the following features: 37 | - opacity and RGB colors 38 | */ 39 | @interface CCAtlasNode : CCNode 40 | { 41 | // texture atlas 42 | CCTextureAtlas *textureAtlas_; 43 | 44 | // chars per row 45 | int itemsPerRow_; 46 | // chars per column 47 | int itemsPerColumn_; 48 | 49 | // width of each char 50 | int itemWidth_; 51 | // height of each char 52 | int itemHeight_; 53 | 54 | // blend function 55 | ccBlendFunc blendFunc_; 56 | 57 | // texture RGBA. 58 | GLubyte opacity_; 59 | ccColor3B color_; 60 | ccColor3B colorUnmodified_; 61 | BOOL opacityModifyRGB_; 62 | } 63 | 64 | /** conforms to CCTextureProtocol protocol */ 65 | @property (nonatomic,readwrite,retain) CCTextureAtlas *textureAtlas; 66 | 67 | /** conforms to CCTextureProtocol protocol */ 68 | @property (nonatomic,readwrite) ccBlendFunc blendFunc; 69 | 70 | /** conforms to CCRGBAProtocol protocol */ 71 | @property (nonatomic,readwrite) GLubyte opacity; 72 | /** conforms to CCRGBAProtocol protocol */ 73 | @property (nonatomic,readwrite) ccColor3B color; 74 | 75 | 76 | /** creates a CCAtlasNode with an Atlas file the width and height of each item measured in points and the quantity of items to render*/ 77 | +(id) atlasWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c; 78 | 79 | /** initializes an CCAtlasNode with an Atlas file the width and height of each item measured in points and the quantity of items to render*/ 80 | -(id) initWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c; 81 | 82 | /** updates the Atlas (indexed vertex array). 83 | * Shall be overriden in subclasses 84 | */ 85 | -(void) updateAtlasValues; 86 | @end 87 | -------------------------------------------------------------------------------- /libs/cocos2d/CCBlockSupport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Stuart Carnie 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | 29 | /** @file 30 | cocos2d blocks support 31 | */ 32 | 33 | // To comply with Apple Objective C runtime (this is defined in NSObjCRuntime.h) 34 | #if !defined(NS_BLOCKS_AVAILABLE) 35 | #if __BLOCKS__ 36 | #define NS_BLOCKS_AVAILABLE 1 37 | #else 38 | #define NS_BLOCKS_AVAILABLE 0 39 | #endif 40 | #endif 41 | 42 | #if NS_BLOCKS_AVAILABLE 43 | 44 | @interface NSObject(CCBlocksAdditions) 45 | 46 | - (void)ccCallbackBlock; 47 | - (void)ccCallbackBlockWithSender:(id)sender; 48 | 49 | @end 50 | 51 | #endif // NS_BLOCKS_AVAILABLE 52 | -------------------------------------------------------------------------------- /libs/cocos2d/CCBlockSupport.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Stuart Carnie 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCBlockSupport.h" 28 | 29 | #if NS_BLOCKS_AVAILABLE 30 | 31 | @implementation NSObject(CCBlocksAdditions) 32 | 33 | - (void)ccCallbackBlock { 34 | void (^block)(void) = (id)self; 35 | block(); 36 | } 37 | 38 | - (void)ccCallbackBlockWithSender:(id)sender { 39 | void (^block)(id) = (id)self; 40 | block(sender); 41 | } 42 | 43 | 44 | @end 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libs/cocos2d/CCCamera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | 27 | #import "CCNode.h" 28 | 29 | /** 30 | A CCCamera is used in every CCNode. 31 | Useful to look at the object from different views. 32 | The OpenGL gluLookAt() function is used to locate the 33 | camera. 34 | 35 | If the object is transformed by any of the scale, rotation or 36 | position attributes, then they will override the camera. 37 | 38 | IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both. 39 | World coordinates won't work if you use the camera. 40 | 41 | Limitations: 42 | 43 | - Some nodes, like CCParallaxNode, CCParticle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors) 44 | using the camera. 45 | 46 | - It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object. 47 | 48 | - It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate. 49 | 50 | */ 51 | 52 | @interface CCCamera : NSObject 53 | { 54 | float eyeX_; 55 | float eyeY_; 56 | float eyeZ_; 57 | 58 | float centerX_; 59 | float centerY_; 60 | float centerZ_; 61 | 62 | float upX_; 63 | float upY_; 64 | float upZ_; 65 | 66 | BOOL dirty_; 67 | } 68 | 69 | /** whether of not the camera is dirty */ 70 | @property (nonatomic,readwrite) BOOL dirty; 71 | 72 | /** returns the Z eye */ 73 | +(float) getZEye; 74 | 75 | /** sets the camera in the defaul position */ 76 | -(void) restore; 77 | /** Sets the camera using gluLookAt using its eye, center and up_vector */ 78 | -(void) locate; 79 | /** sets the eye values in points */ 80 | -(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z; 81 | /** sets the center values in points */ 82 | -(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z; 83 | /** sets the up values */ 84 | -(void) setUpX: (float)x upY:(float)y upZ:(float)z; 85 | 86 | /** get the eye vector values in points */ 87 | -(void) eyeX:(float*)x eyeY:(float*)y eyeZ:(float*)z; 88 | /** get the center vector values in points */ 89 | -(void) centerX:(float*)x centerY:(float*)y centerZ:(float*)z; 90 | /** get the up vector values */ 91 | -(void) upX:(float*)x upY:(float*)y upZ:(float*)z; 92 | 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /libs/cocos2d/CCCamera.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | #import "Platforms/CCGL.h" 27 | #import "CCCamera.h" 28 | #import "ccMacros.h" 29 | #import "CCDrawingPrimitives.h" 30 | 31 | @implementation CCCamera 32 | 33 | @synthesize dirty = dirty_; 34 | 35 | -(id) init 36 | { 37 | if( (self=[super init]) ) 38 | [self restore]; 39 | 40 | return self; 41 | } 42 | 43 | - (NSString*) description 44 | { 45 | return [NSString stringWithFormat:@"<%@ = %08X | center = (%.2f,%.2f,%.2f)>", [self class], self, centerX_, centerY_, centerZ_]; 46 | } 47 | 48 | 49 | - (void) dealloc 50 | { 51 | CCLOGINFO(@"cocos2d: deallocing %@", self); 52 | [super dealloc]; 53 | } 54 | 55 | -(void) restore 56 | { 57 | eyeX_ = eyeY_ = 0; 58 | eyeZ_ = [CCCamera getZEye]; 59 | 60 | centerX_ = centerY_ = centerZ_ = 0; 61 | 62 | upX_ = 0.0f; 63 | upY_ = 1.0f; 64 | upZ_ = 0.0f; 65 | 66 | dirty_ = NO; 67 | } 68 | 69 | -(void) locate 70 | { 71 | if( dirty_ ) 72 | gluLookAt( eyeX_, eyeY_, eyeZ_, 73 | centerX_, centerY_, centerZ_, 74 | upX_, upY_, upZ_ 75 | ); 76 | } 77 | 78 | +(float) getZEye 79 | { 80 | return FLT_EPSILON; 81 | // CGSize s = [[CCDirector sharedDirector] displaySize]; 82 | // return ( s.height / 1.1566f ); 83 | } 84 | 85 | -(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z 86 | { 87 | eyeX_ = x * CC_CONTENT_SCALE_FACTOR(); 88 | eyeY_ = y * CC_CONTENT_SCALE_FACTOR(); 89 | eyeZ_ = z * CC_CONTENT_SCALE_FACTOR(); 90 | dirty_ = YES; 91 | } 92 | 93 | -(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z 94 | { 95 | centerX_ = x * CC_CONTENT_SCALE_FACTOR(); 96 | centerY_ = y * CC_CONTENT_SCALE_FACTOR(); 97 | centerZ_ = z * CC_CONTENT_SCALE_FACTOR(); 98 | dirty_ = YES; 99 | } 100 | 101 | -(void) setUpX: (float)x upY:(float)y upZ:(float)z 102 | { 103 | upX_ = x; 104 | upY_ = y; 105 | upZ_ = z; 106 | dirty_ = YES; 107 | } 108 | 109 | -(void) eyeX: (float*)x eyeY:(float*)y eyeZ:(float*)z 110 | { 111 | *x = eyeX_ / CC_CONTENT_SCALE_FACTOR(); 112 | *y = eyeY_ / CC_CONTENT_SCALE_FACTOR(); 113 | *z = eyeZ_ / CC_CONTENT_SCALE_FACTOR(); 114 | } 115 | 116 | -(void) centerX: (float*)x centerY:(float*)y centerZ:(float*)z 117 | { 118 | *x = centerX_ / CC_CONTENT_SCALE_FACTOR(); 119 | *y = centerY_ / CC_CONTENT_SCALE_FACTOR(); 120 | *z = centerZ_ / CC_CONTENT_SCALE_FACTOR(); 121 | } 122 | 123 | -(void) upX: (float*)x upY:(float*)y upZ:(float*)z 124 | { 125 | *x = upX_; 126 | *y = upY_; 127 | *z = upZ_; 128 | } 129 | 130 | @end 131 | -------------------------------------------------------------------------------- /libs/cocos2d/CCDrawingPrimitives.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | #ifndef __CC_DRAWING_PRIMITIVES_H 27 | #define __CC_DRAWING_PRIMITIVES_H 28 | 29 | #import 30 | #import 31 | 32 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 33 | #import // for CGPoint 34 | #endif 35 | 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** 42 | @file 43 | Drawing OpenGL ES primitives. 44 | - ccDrawPoint 45 | - ccDrawLine 46 | - ccDrawPoly 47 | - ccDrawCircle 48 | - ccDrawQuadBezier 49 | - ccDrawCubicBezier 50 | 51 | You can change the color, width and other property by calling the 52 | glColor4ub(), glLineWitdh(), glPointSize(). 53 | 54 | @warning These functions draws the Line, Point, Polygon, immediately. They aren't batched. If you are going to make a game that depends on these primitives, I suggest creating a batch. 55 | */ 56 | 57 | 58 | /** draws a point given x and y coordinate measured in points. */ 59 | void ccDrawPoint( CGPoint point ); 60 | 61 | /** draws an array of points. 62 | @since v0.7.2 63 | */ 64 | void ccDrawPoints( const CGPoint *points, NSUInteger numberOfPoints ); 65 | 66 | /** draws a line given the origin and destination point measured in points. */ 67 | void ccDrawLine( CGPoint origin, CGPoint destination ); 68 | 69 | /** draws a poligon given a pointer to CGPoint coordiantes and the number of vertices measured in points. 70 | The polygon can be closed or open 71 | */ 72 | void ccDrawPoly( const CGPoint *vertices, NSUInteger numOfVertices, BOOL closePolygon ); 73 | 74 | /** draws a circle given the center, radius and number of segments measured in points */ 75 | void ccDrawCircle( CGPoint center, float radius, float angle, NSUInteger segments, BOOL drawLineToCenter); 76 | 77 | /** draws a quad bezier path measured in points. 78 | @since v0.8 79 | */ 80 | void ccDrawQuadBezier(CGPoint origin, CGPoint control, CGPoint destination, NSUInteger segments); 81 | 82 | /** draws a cubic bezier path measured in points. 83 | @since v0.8 84 | */ 85 | void ccDrawCubicBezier(CGPoint origin, CGPoint control1, CGPoint control2, CGPoint destination, NSUInteger segments); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif // __CC_DRAWING_PRIMITIVES_H 92 | -------------------------------------------------------------------------------- /libs/cocos2d/CCGrabber.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 On-Core 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "Platforms/CCGL.h" 28 | #import 29 | 30 | @class CCTexture2D; 31 | 32 | /** FBO class that grabs the the contents of the screen */ 33 | @interface CCGrabber : NSObject 34 | { 35 | GLuint fbo; 36 | GLint oldFBO; 37 | } 38 | 39 | -(void)grab:(CCTexture2D*)texture; 40 | -(void)beforeRender:(CCTexture2D*)texture; 41 | -(void)afterRender:(CCTexture2D*)texture; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /libs/cocos2d/CCGrabber.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 On-Core 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "Platforms/CCGL.h" 28 | #import "CCGrabber.h" 29 | #import "ccMacros.h" 30 | #import "CCTexture2D.h" 31 | #import "Support/OpenGL_Internal.h" 32 | 33 | @implementation CCGrabber 34 | 35 | -(id) init 36 | { 37 | if(( self = [super init] )) { 38 | // generate FBO 39 | ccglGenFramebuffers(1, &fbo); 40 | } 41 | return self; 42 | } 43 | 44 | -(void)grab:(CCTexture2D*)texture 45 | { 46 | glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &oldFBO); 47 | 48 | // bind 49 | ccglBindFramebuffer(CC_GL_FRAMEBUFFER, fbo); 50 | 51 | // associate texture with FBO 52 | ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.name, 0); 53 | 54 | // check if it worked (probably worth doing :) ) 55 | GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); 56 | if (status != CC_GL_FRAMEBUFFER_COMPLETE) 57 | [NSException raise:@"Frame Grabber" format:@"Could not attach texture to framebuffer"]; 58 | 59 | ccglBindFramebuffer(CC_GL_FRAMEBUFFER, oldFBO); 60 | } 61 | 62 | -(void)beforeRender:(CCTexture2D*)texture 63 | { 64 | glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &oldFBO); 65 | ccglBindFramebuffer(CC_GL_FRAMEBUFFER, fbo); 66 | 67 | // BUG XXX: doesn't work with RGB565. 68 | 69 | 70 | glClearColor(0,0,0,0); 71 | 72 | // BUG #631: To fix #631, uncomment the lines with #631 73 | // Warning: But it CCGrabber won't work with 2 effects at the same time 74 | // glClearColor(0.0f,0.0f,0.0f,1.0f); // #631 75 | 76 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 77 | 78 | // glColorMask(TRUE, TRUE, TRUE, FALSE); // #631 79 | 80 | } 81 | 82 | -(void)afterRender:(CCTexture2D*)texture 83 | { 84 | ccglBindFramebuffer(CC_GL_FRAMEBUFFER, oldFBO); 85 | // glColorMask(TRUE, TRUE, TRUE, TRUE); // #631 86 | } 87 | 88 | - (void) dealloc 89 | { 90 | CCLOGINFO(@"cocos2d: deallocing %@", self); 91 | ccglDeleteFramebuffers(1, &fbo); 92 | [super dealloc]; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /libs/cocos2d/CCLabelAtlas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCAtlasNode.h" 28 | #import "CCTextureAtlas.h" 29 | 30 | /** CCLabelAtlas is a subclass of CCAtlasNode. 31 | 32 | It can be as a replacement of CCLabel since it is MUCH faster. 33 | 34 | CCLabelAtlas versus CCLabel: 35 | - CCLabelAtlas is MUCH faster than CCLabel 36 | - CCLabelAtlas "characters" have a fixed height and width 37 | - CCLabelAtlas "characters" can be anything you want since they are taken from an image file 38 | 39 | A more flexible class is CCBitmapFontAtlas. It supports variable width characters and it also has a nice editor. 40 | */ 41 | @interface CCLabelAtlas : CCAtlasNode 42 | { 43 | // string to render 44 | NSString *string_; 45 | 46 | // the first char in the charmap 47 | char mapStartChar; 48 | } 49 | 50 | 51 | /** creates the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element in points and the starting char of the atlas */ 52 | +(id) labelWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c; 53 | 54 | /** creates the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element in points and the starting char of the atlas. 55 | @deprecated Will be removed in 1.0.1. Use "labelWithString:" instead 56 | */ 57 | +(id) labelAtlasWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c DEPRECATED_ATTRIBUTE; 58 | 59 | /** initializes the CCLabelAtlas with a string, a char map file(the atlas), the width and height in points of each element and the starting char of the atlas */ 60 | -(id) initWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c; 61 | @end 62 | -------------------------------------------------------------------------------- /libs/cocos2d/CCLabelTTF.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCTexture2D.h" 28 | #import "CCSprite.h" 29 | #import "Platforms/CCNS.h" 30 | 31 | 32 | /** CCLabel is a subclass of CCTextureNode that knows how to render text labels 33 | * 34 | * All features from CCTextureNode are valid in CCLabel 35 | * 36 | * CCLabel objects are slow. Consider using CCLabelAtlas or CCBitmapFontAtlas instead. 37 | */ 38 | 39 | @interface CCLabelTTF : CCSprite 40 | { 41 | CGSize dimensions_; 42 | CCTextAlignment alignment_; 43 | NSString * fontName_; 44 | CGFloat fontSize_; 45 | NSString *string_; 46 | } 47 | 48 | /** creates a CCLabel from a fontname, alignment, dimension in points and font size in points*/ 49 | + (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; 50 | /** creates a CCLabel from a fontname and font size in points*/ 51 | + (id) labelWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; 52 | /** initializes the CCLabel with a font name, alignment, dimension in points and font size in points */ 53 | - (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; 54 | /** initializes the CCLabel with a font name and font size in points */ 55 | - (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; 56 | 57 | /** changes the string to render 58 | * @warning Changing the string is as expensive as creating a new CCLabel. To obtain better performance use CCLabelAtlas 59 | */ 60 | - (void) setString:(NSString*)str; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /libs/cocos2d/CCMenu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCMenuItem.h" 28 | #import "CCLayer.h" 29 | 30 | typedef enum { 31 | kCCMenuStateWaiting, 32 | kCCMenuStateTrackingTouch 33 | } tCCMenuState; 34 | 35 | enum { 36 | //* priority used by the menu 37 | kCCMenuTouchPriority = -128, 38 | }; 39 | 40 | /** A CCMenu 41 | * 42 | * Features and Limitation: 43 | * - You can add MenuItem objects in runtime using addChild: 44 | * - But the only accecpted children are MenuItem objects 45 | */ 46 | @interface CCMenu : CCLayer 47 | { 48 | tCCMenuState state_; 49 | CCMenuItem *selectedItem_; 50 | GLubyte opacity_; 51 | ccColor3B color_; 52 | } 53 | 54 | /** creates a CCMenu with it's items */ 55 | + (id) menuWithItems: (CCMenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION; 56 | 57 | /** initializes a CCMenu with it's items */ 58 | - (id) initWithItems: (CCMenuItem*) item vaList: (va_list) args; 59 | 60 | /** align items vertically */ 61 | -(void) alignItemsVertically; 62 | /** align items vertically with padding 63 | @since v0.7.2 64 | */ 65 | -(void) alignItemsVerticallyWithPadding:(float) padding; 66 | 67 | /** align items horizontally */ 68 | -(void) alignItemsHorizontally; 69 | /** align items horizontally with padding 70 | @since v0.7.2 71 | */ 72 | -(void) alignItemsHorizontallyWithPadding: (float) padding; 73 | 74 | 75 | /** align items in rows of columns */ 76 | -(void) alignItemsInColumns: (NSNumber *) columns, ... NS_REQUIRES_NIL_TERMINATION; 77 | -(void) alignItemsInColumns: (NSNumber *) columns vaList: (va_list) args; 78 | 79 | /** align items in columns of rows */ 80 | -(void) alignItemsInRows: (NSNumber *) rows, ... NS_REQUIRES_NIL_TERMINATION; 81 | -(void) alignItemsInRows: (NSNumber *) rows vaList: (va_list) args; 82 | 83 | 84 | /** conforms to CCRGBAProtocol protocol */ 85 | @property (nonatomic,readonly) GLubyte opacity; 86 | /** conforms to CCRGBAProtocol protocol */ 87 | @property (nonatomic,readonly) ccColor3B color; 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /libs/cocos2d/CCMotionStreak.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008, 2009 Jason Booth 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import 27 | #import "CCNode.h" 28 | #import "CCRibbon.h" 29 | 30 | /** 31 | * CCMotionStreak manages a Ribbon based on it's motion in absolute space. 32 | * You construct it with a fadeTime, minimum segment size, texture path, texture 33 | * length and color. The fadeTime controls how long it takes each vertex in 34 | * the streak to fade out, the minimum segment size it how many pixels the 35 | * streak will move before adding a new ribbon segement, and the texture 36 | * length is the how many pixels the texture is stretched across. The texture 37 | * is vertically aligned along the streak segemnts. 38 | * 39 | * Limitations: 40 | * CCMotionStreak, by default, will use the GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA blending function. 41 | * This blending function might not be the correct one for certain textures. 42 | * But you can change it by using: 43 | * [obj setBlendFunc: (ccBlendfunc) {new_src_blend_func, new_dst_blend_func}]; 44 | * 45 | * @since v0.8.1 46 | */ 47 | @interface CCMotionStreak : CCNode 48 | { 49 | CCRibbon* ribbon_; 50 | float segThreshold_; 51 | float width_; 52 | CGPoint lastLocation_; 53 | } 54 | 55 | /** Ribbon used by MotionStreak (weak reference) */ 56 | @property (nonatomic,readonly) CCRibbon *ribbon; 57 | 58 | /** creates the a MotionStreak. The image will be loaded using the TextureMgr. */ 59 | +(id)streakWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color; 60 | 61 | /** initializes a MotionStreak. The file will be loaded using the TextureMgr. */ 62 | -(id)initWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color; 63 | 64 | /** polling function */ 65 | -(void)update:(ccTime)delta; 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /libs/cocos2d/CCMotionStreak.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008, 2009 Jason Booth 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * 25 | ********************************************************* 26 | * 27 | * Motion Streak manages a Ribbon based on it's motion in absolute space. 28 | * You construct it with a fadeTime, minimum segment size, texture path, texture 29 | * length and color. The fadeTime controls how long it takes each vertex in 30 | * the streak to fade out, the minimum segment size it how many pixels the 31 | * streak will move before adding a new ribbon segement, and the texture 32 | * length is the how many pixels the texture is stretched across. The texture 33 | * is vertically aligned along the streak segemnts. 34 | */ 35 | 36 | #import "CCMotionStreak.h" 37 | #import "Support/CGPointExtension.h" 38 | 39 | @implementation CCMotionStreak 40 | 41 | @synthesize ribbon = ribbon_; 42 | 43 | +(id)streakWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color 44 | { 45 | return [[[self alloc] initWithFade:(float)fade minSeg:seg image:path width:width length:length color:color] autorelease]; 46 | } 47 | 48 | -(id)initWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color 49 | { 50 | if( (self=[super init])) { 51 | segThreshold_ = seg; 52 | width_ = width; 53 | lastLocation_ = CGPointZero; 54 | ribbon_ = [CCRibbon ribbonWithWidth:width_ image:path length:length color:color fade:fade]; 55 | [self addChild:ribbon_]; 56 | 57 | // update ribbon position 58 | [self scheduleUpdate]; 59 | } 60 | return self; 61 | } 62 | 63 | -(void)update:(ccTime)delta 64 | { 65 | CGPoint location = [self convertToWorldSpace:CGPointZero]; 66 | [ribbon_ setPosition:ccp(-1*location.x, -1*location.y)]; 67 | float len = ccpLength(ccpSub(lastLocation_, location)); 68 | if (len > segThreshold_) 69 | { 70 | [ribbon_ addPointAt:location width:width_]; 71 | lastLocation_ = location; 72 | } 73 | [ribbon_ update:delta]; 74 | } 75 | 76 | 77 | -(void)dealloc 78 | { 79 | [super dealloc]; 80 | } 81 | 82 | #pragma mark MotionStreak - CocosNodeTexture protocol 83 | 84 | -(void) setTexture:(CCTexture2D*) texture 85 | { 86 | [ribbon_ setTexture: texture]; 87 | } 88 | 89 | -(CCTexture2D*) texture 90 | { 91 | return [ribbon_ texture]; 92 | } 93 | 94 | -(ccBlendFunc) blendFunc 95 | { 96 | return [ribbon_ blendFunc]; 97 | } 98 | 99 | -(void) setBlendFunc:(ccBlendFunc)blendFunc 100 | { 101 | [ribbon_ setBlendFunc:blendFunc]; 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /libs/cocos2d/CCParallaxNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "CCNode.h" 27 | #import "Support/ccCArray.h" 28 | 29 | /** CCParallaxNode: A node that simulates a parallax scroller 30 | 31 | The children will be moved faster / slower than the parent according the the parallax ratio. 32 | 33 | */ 34 | @interface CCParallaxNode : CCNode 35 | { 36 | ccArray *parallaxArray_; 37 | CGPoint lastPosition; 38 | } 39 | 40 | /** array that holds the offset / ratio of the children */ 41 | @property (nonatomic,readwrite) ccArray * parallaxArray; 42 | 43 | /** Adds a child to the container with a z-order, a parallax ratio and a position offset 44 | It returns self, so you can chain several addChilds. 45 | @since v0.8 46 | */ 47 | -(void) addChild: (CCNode*)node z:(int)z parallaxRatio:(CGPoint)c positionOffset:(CGPoint)positionOffset; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /libs/cocos2d/CCParticleExamples.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | 29 | #import "CCParticleSystemPoint.h" 30 | #import "CCParticleSystemQuad.h" 31 | 32 | // build each architecture with the optimal particle system 33 | 34 | // ARMv7, Mac or Simulator use "Quad" particle 35 | #if defined(__ARM_NEON__) || defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || TARGET_IPHONE_SIMULATOR 36 | #define ARCH_OPTIMAL_PARTICLE_SYSTEM CCParticleSystemQuad 37 | 38 | // ARMv6 use "Point" particle 39 | #elif __arm__ 40 | #define ARCH_OPTIMAL_PARTICLE_SYSTEM CCParticleSystemPoint 41 | #else 42 | #error(unknown architecture) 43 | #endif 44 | 45 | 46 | //! A fire particle system 47 | @interface CCParticleFire: ARCH_OPTIMAL_PARTICLE_SYSTEM 48 | { 49 | } 50 | @end 51 | 52 | //! A fireworks particle system 53 | @interface CCParticleFireworks : ARCH_OPTIMAL_PARTICLE_SYSTEM 54 | { 55 | } 56 | @end 57 | 58 | //! A sun particle system 59 | @interface CCParticleSun : ARCH_OPTIMAL_PARTICLE_SYSTEM 60 | { 61 | } 62 | @end 63 | 64 | //! A galaxy particle system 65 | @interface CCParticleGalaxy : ARCH_OPTIMAL_PARTICLE_SYSTEM 66 | { 67 | } 68 | @end 69 | 70 | //! A flower particle system 71 | @interface CCParticleFlower : ARCH_OPTIMAL_PARTICLE_SYSTEM 72 | { 73 | } 74 | @end 75 | 76 | //! A meteor particle system 77 | @interface CCParticleMeteor : ARCH_OPTIMAL_PARTICLE_SYSTEM 78 | { 79 | } 80 | @end 81 | 82 | //! An spiral particle system 83 | @interface CCParticleSpiral : ARCH_OPTIMAL_PARTICLE_SYSTEM 84 | { 85 | } 86 | @end 87 | 88 | //! An explosion particle system 89 | @interface CCParticleExplosion : ARCH_OPTIMAL_PARTICLE_SYSTEM 90 | { 91 | } 92 | @end 93 | 94 | //! An smoke particle system 95 | @interface CCParticleSmoke : ARCH_OPTIMAL_PARTICLE_SYSTEM 96 | { 97 | } 98 | @end 99 | 100 | //! An snow particle system 101 | @interface CCParticleSnow : ARCH_OPTIMAL_PARTICLE_SYSTEM 102 | { 103 | } 104 | @end 105 | 106 | //! A rain particle system 107 | @interface CCParticleRain : ARCH_OPTIMAL_PARTICLE_SYSTEM 108 | { 109 | } 110 | @end 111 | -------------------------------------------------------------------------------- /libs/cocos2d/CCParticleSystemPoint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | #import "CCParticleSystem.h" 29 | 30 | #define CC_MAX_PARTICLE_SIZE 64 31 | 32 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 33 | 34 | /** CCParticleSystemPoint is a subclass of CCParticleSystem 35 | Attributes of a Particle System: 36 | * All the attributes of Particle System 37 | 38 | Features: 39 | * consumes small memory: uses 1 vertex (x,y) per particle, no need to assign tex coordinates 40 | * size can't be bigger than 64 41 | * the system can't be scaled since the particles are rendered using GL_POINT_SPRITE 42 | 43 | Limitations: 44 | * On 3rd gen iPhone devices and iPads, this node performs MUCH slower than CCParticleSystemQuad. 45 | */ 46 | @interface CCParticleSystemPoint : CCParticleSystem 47 | { 48 | // Array of (x,y,size) 49 | ccPointSprite *vertices; 50 | // vertices buffer id 51 | #if CC_USES_VBO 52 | GLuint verticesID; 53 | #endif 54 | } 55 | @end 56 | 57 | #elif __MAC_OS_X_VERSION_MAX_ALLOWED 58 | 59 | #import "CCParticleSystemQuad.h" 60 | 61 | @interface CCParticleSystemPoint : CCParticleSystemQuad 62 | @end 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /libs/cocos2d/CCParticleSystemQuad.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * Copyright (c) 2009 Leonardo Kasperavičius 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 | 28 | #import "CCParticleSystem.h" 29 | #import "ccConfig.h" 30 | 31 | @class CCSpriteFrame; 32 | 33 | /** CCParticleSystemQuad is a subclass of CCParticleSystem 34 | 35 | It includes all the features of ParticleSystem. 36 | 37 | Special features and Limitations: 38 | - Particle size can be any float number. 39 | - The system can be scaled 40 | - The particles can be rotated 41 | - On 1st and 2nd gen iPhones: It is only a bit slower that CCParticleSystemPoint 42 | - On 3rd gen iPhone and iPads: It is MUCH faster than CCParticleSystemPoint 43 | - It consumes more RAM and more GPU memory than CCParticleSystemPoint 44 | - It supports subrects 45 | @since v0.8 46 | */ 47 | @interface CCParticleSystemQuad : CCParticleSystem 48 | { 49 | ccV2F_C4F_T2F_Quad *quads_; // quads to be rendered 50 | GLushort *indices_; // indices 51 | #if CC_USES_VBO 52 | GLuint quadsID_; // VBO id 53 | #endif 54 | } 55 | 56 | /** initialices the indices for the vertices */ 57 | -(void) initIndices; 58 | 59 | /** initilizes the texture with a rectangle measured Points */ 60 | -(void) initTexCoordsWithRect:(CGRect)rect; 61 | 62 | /** Sets a new CCSpriteFrame as particle. 63 | WARNING: this method is experimental. Use setTexture:withRect instead. 64 | @since v0.99.4 65 | */ 66 | -(void)setDisplayFrame:(CCSpriteFrame*)spriteFrame; 67 | 68 | /** Sets a new texture with a rect. The rect is in Points. 69 | @since v0.99.4 70 | */ 71 | -(void) setTexture:(CCTexture2D *)texture withRect:(CGRect)rect; 72 | 73 | @end 74 | 75 | -------------------------------------------------------------------------------- /libs/cocos2d/CCProgressTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Lam Pham 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import 27 | #import "CCSprite.h" 28 | 29 | /** Types of progress 30 | @since v0.99.1 31 | */ 32 | typedef enum { 33 | /// Radial Counter-Clockwise 34 | kCCProgressTimerTypeRadialCCW, 35 | /// Radial ClockWise 36 | kCCProgressTimerTypeRadialCW, 37 | /// Horizontal Left-Right 38 | kCCProgressTimerTypeHorizontalBarLR, 39 | /// Horizontal Right-Left 40 | kCCProgressTimerTypeHorizontalBarRL, 41 | /// Vertical Bottom-top 42 | kCCProgressTimerTypeVerticalBarBT, 43 | /// Vertical Top-Bottom 44 | kCCProgressTimerTypeVerticalBarTB, 45 | } CCProgressTimerType; 46 | 47 | /** 48 | CCProgresstimer is a subclass of CCNode. 49 | It renders the inner sprite according to the percentage. 50 | The progress can be Radial, Horizontal or vertical. 51 | @since v0.99.1 52 | */ 53 | @interface CCProgressTimer : CCNode 54 | { 55 | CCProgressTimerType type_; 56 | float percentage_; 57 | CCSprite *sprite_; 58 | 59 | int vertexDataCount_; 60 | ccV2F_C4F_T2F *vertexData_; 61 | } 62 | 63 | /** Change the percentage to change progress. */ 64 | @property (nonatomic, readwrite) CCProgressTimerType type; 65 | 66 | /** Percentages are from 0 to 100 */ 67 | @property (nonatomic, readwrite) float percentage; 68 | 69 | /** The image to show the progress percentage */ 70 | @property (nonatomic, readwrite, retain) CCSprite *sprite; 71 | 72 | 73 | /** Creates a progress timer with an image filename as the shape the timer goes through */ 74 | + (id) progressWithFile:(NSString*) filename; 75 | /** Initializes a progress timer with an image filename as the shape the timer goes through */ 76 | - (id) initWithFile:(NSString*) filename; 77 | 78 | /** Creates a progress timer with the texture as the shape the timer goes through */ 79 | + (id) progressWithTexture:(CCTexture2D*) texture; 80 | /** Creates a progress timer with the texture as the shape the timer goes through */ 81 | - (id) initWithTexture:(CCTexture2D*) texture; 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /libs/cocos2d/CCScene.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCNode.h" 28 | 29 | /** CCScene is a subclass of CCNode that is used only as an abstract concept. 30 | 31 | CCScene an CCNode are almost identical with the difference that CCScene has it's 32 | anchor point (by default) at the center of the screen. 33 | 34 | For the moment CCScene has no other logic than that, but in future releases it might have 35 | additional logic. 36 | 37 | It is a good practice to use and CCScene as the parent of all your nodes. 38 | */ 39 | @interface CCScene : CCNode 40 | { 41 | } 42 | @end 43 | -------------------------------------------------------------------------------- /libs/cocos2d/CCScene.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCScene.h" 28 | #import "Support/CGPointExtension.h" 29 | #import "CCDirector.h" 30 | 31 | 32 | @implementation CCScene 33 | -(id) init 34 | { 35 | if( (self=[super init]) ) { 36 | CGSize s = [[CCDirector sharedDirector] winSize]; 37 | self.isRelativeAnchorPoint = NO; 38 | anchorPoint_ = ccp(0.5f, 0.5f); 39 | [self setContentSize:s]; 40 | } 41 | 42 | return self; 43 | } 44 | @end 45 | -------------------------------------------------------------------------------- /libs/cocos2d/CCSpriteFrame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import 27 | #import "CCNode.h" 28 | #import "CCProtocols.h" 29 | 30 | /** A CCSpriteFrame has: 31 | - texture: A CCTexture2D that will be used by the CCSprite 32 | - rectangle: A rectangle of the texture 33 | 34 | 35 | You can modify the frame of a CCSprite by doing: 36 | 37 | CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect offset:offset]; 38 | [sprite setDisplayFrame:frame]; 39 | */ 40 | @interface CCSpriteFrame : NSObject 41 | { 42 | CGRect rect_; 43 | CGRect rectInPixels_; 44 | BOOL rotated_; 45 | CGPoint offsetInPixels_; 46 | CGSize originalSizeInPixels_; 47 | CCTexture2D *texture_; 48 | } 49 | /** rect of the frame in points */ 50 | @property (nonatomic,readwrite) CGRect rect; 51 | 52 | /** rect of the frame in pixels */ 53 | @property (nonatomic,readwrite) CGRect rectInPixels; 54 | 55 | /** whether or not the rect of the frame is rotated ( x = x+width, y = y+height, width = height, height = width ) */ 56 | @property (nonatomic,readwrite) BOOL rotated; 57 | 58 | /** offset of the frame in pixels */ 59 | @property (nonatomic,readwrite) CGPoint offsetInPixels; 60 | 61 | /** original size of the trimmed image in pixels */ 62 | @property (nonatomic,readwrite) CGSize originalSizeInPixels; 63 | 64 | /** texture of the frame */ 65 | @property (nonatomic, retain, readwrite) CCTexture2D *texture; 66 | 67 | /** Create a CCSpriteFrame with a texture, rect in points. 68 | It is assumed that the frame was not trimmed. 69 | */ 70 | +(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; 71 | 72 | /** Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. 73 | The originalSize is the size in points of the frame before being trimmed. 74 | */ 75 | +(id) frameWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize; 76 | 77 | 78 | /** Initializes a CCSpriteFrame with a texture, rect in points; 79 | It is assumed that the frame was not trimmed. 80 | */ 81 | -(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect; 82 | 83 | /** Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. 84 | The originalSize is the size in points of the frame before being trimmed. 85 | */ 86 | -(id) initWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize; 87 | 88 | @end 89 | 90 | -------------------------------------------------------------------------------- /libs/cocos2d/CCSpriteFrame.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCTextureCache.h" 28 | #import "CCSpriteFrame.h" 29 | #import "ccMacros.h" 30 | 31 | @implementation CCSpriteFrame 32 | @synthesize rect = rect_, rectInPixels=rectInPixels_; 33 | @synthesize rotated = rotated_, offsetInPixels = offsetInPixels_, texture = texture_; 34 | @synthesize originalSizeInPixels=originalSizeInPixels_; 35 | 36 | +(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect 37 | { 38 | return [[[self alloc] initWithTexture:texture rect:rect] autorelease]; 39 | } 40 | 41 | +(id) frameWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize 42 | { 43 | return [[[self alloc] initWithTexture:texture rectInPixels:rect rotated:rotated offset:offset originalSize:originalSize] autorelease]; 44 | } 45 | 46 | -(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect 47 | { 48 | CGRect rectInPixels = CC_RECT_POINTS_TO_PIXELS( rect ); 49 | return [self initWithTexture:texture rectInPixels:rectInPixels rotated:NO offset:CGPointZero originalSize:rectInPixels.size]; 50 | } 51 | 52 | -(id) initWithTexture:(CCTexture2D*)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize 53 | { 54 | if( (self=[super init]) ) { 55 | self.texture = texture; 56 | rectInPixels_ = rect; 57 | rect_ = CC_RECT_PIXELS_TO_POINTS( rect ); 58 | rotated_ = rotated; 59 | offsetInPixels_ = offset; 60 | originalSizeInPixels_ = originalSize; 61 | } 62 | return self; 63 | } 64 | 65 | - (NSString*) description 66 | { 67 | return [NSString stringWithFormat:@"<%@ = %08X | TextureName=%d, Rect = (%.2f,%.2f,%.2f,%.2f)>", [self class], self, 68 | texture_.name, 69 | rect_.origin.x, 70 | rect_.origin.y, 71 | rect_.size.width, 72 | rect_.size.height]; 73 | } 74 | 75 | - (void) dealloc 76 | { 77 | CCLOGINFO( @"cocos2d: deallocing %@",self); 78 | [texture_ release]; 79 | [super dealloc]; 80 | } 81 | 82 | -(id) copyWithZone: (NSZone*) zone 83 | { 84 | CCSpriteFrame *copy = [[[self class] allocWithZone: zone] initWithTexture:texture_ rectInPixels:rectInPixels_ rotated:rotated_ offset:offsetInPixels_ originalSize:originalSizeInPixels_]; 85 | return copy; 86 | } 87 | @end 88 | -------------------------------------------------------------------------------- /libs/cocos2d/CCSpriteSheet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009-2010 Ricardo Quesada 5 | * Copyright (C) 2009 Matt Oswald 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 | 28 | #import "CCSpriteBatchNode.h" 29 | 30 | #pragma mark CCSpriteSheet 31 | 32 | 33 | /* Added only to prevent GCC compile warnings 34 | Will be removed in v1.1 35 | */ 36 | @interface CCSpriteSheetInternalOnly : CCSpriteBatchNode 37 | { 38 | } 39 | @end 40 | 41 | /** CCSpriteSheet is like a batch node: if it contains children, it will draw them in 1 single OpenGL call 42 | * (often known as "batch draw"). 43 | * 44 | * A CCSpriteSheet can reference one and only one texture (one image file, one texture atlas). 45 | * Only the CCSprites that are contained in that texture can be added to the CCSpriteSheet. 46 | * All CCSprites added to a CCSpriteSheet are drawn in one OpenGL ES draw call. 47 | * If the CCSprites are not added to a CCSpriteSheet then an OpenGL ES draw call will be needed for each one, which is less efficient. 48 | * 49 | * 50 | * Limitations: 51 | * - The only object that is accepted as child (or grandchild, grand-grandchild, etc...) is CCSprite or any subclass of CCSprite. eg: particles, labels and layer can't be added to a CCSpriteSheet. 52 | * - Either all its children are Aliased or Antialiased. It can't be a mix. This is because "alias" is a property of the texture, and all the sprites share the same texture. 53 | * 54 | * @since v0.7.1 55 | * 56 | * @deprecated Use CCSpriteBatchNode instead. This class will be removed in v1.1 57 | */ 58 | DEPRECATED_ATTRIBUTE @interface CCSpriteSheet : CCSpriteSheetInternalOnly 59 | { 60 | } 61 | @end 62 | -------------------------------------------------------------------------------- /libs/cocos2d/CCSpriteSheet.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009-2010 Ricardo Quesada 5 | * Copyright (C) 2009 Matt Oswald 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 | 28 | #import "CCSpriteSheet.h" 29 | 30 | #pragma mark - 31 | #pragma mark CCSpriteSheet 32 | 33 | @implementation CCSpriteSheetInternalOnly 34 | @end 35 | 36 | @implementation CCSpriteSheet 37 | @end 38 | -------------------------------------------------------------------------------- /libs/cocos2d/CCTMXObjectGroup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * Copyright (c) 2010 Neophit 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 | * TMX Tiled Map support: 27 | * http://www.mapeditor.org 28 | * 29 | */ 30 | 31 | #import "CCSpriteSheet.h" 32 | 33 | 34 | @class CCTMXObjectGroup; 35 | 36 | 37 | /** CCTMXObjectGroup represents the TMX object group. 38 | @since v0.99.0 39 | */ 40 | @interface CCTMXObjectGroup : NSObject 41 | { 42 | NSString *groupName_; 43 | CGPoint positionOffset_; 44 | NSMutableArray *objects_; 45 | NSMutableDictionary *properties_; 46 | } 47 | 48 | /** name of the group */ 49 | @property (nonatomic,readwrite,retain) NSString *groupName; 50 | /** offset position of child objects */ 51 | @property (nonatomic,readwrite,assign) CGPoint positionOffset; 52 | /** array of the objects */ 53 | @property (nonatomic,readwrite,retain) NSMutableArray *objects; 54 | /** list of properties stored in a dictionary */ 55 | @property (nonatomic,readwrite,retain) NSMutableDictionary *properties; 56 | 57 | /** return the value for the specific property name */ 58 | -(id) propertyNamed:(NSString *)propertyName; 59 | 60 | /** return the dictionary for the specific object name. 61 | It will return the 1st object found on the array for the given name. 62 | */ 63 | -(NSMutableDictionary*) objectNamed:(NSString *)objectName; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /libs/cocos2d/CCTMXObjectGroup.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * Copyright (c) 2010 Neophit 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 | * TMX Tiled Map support: 27 | * http://www.mapeditor.org 28 | * 29 | */ 30 | 31 | #import "CCTMXObjectGroup.h" 32 | #import "CCTMXXMLParser.h" 33 | #import "Support/CGPointExtension.h" 34 | 35 | 36 | #pragma mark - 37 | #pragma mark TMXObjectGroup 38 | 39 | @implementation CCTMXObjectGroup 40 | 41 | @synthesize groupName = groupName_; 42 | @synthesize objects = objects_; 43 | @synthesize positionOffset = positionOffset_; 44 | @synthesize properties = properties_; 45 | 46 | -(id) init 47 | { 48 | if (( self=[super init] )) { 49 | self.groupName = nil; 50 | self.positionOffset = CGPointZero; 51 | self.objects = [NSMutableArray arrayWithCapacity:10]; 52 | self.properties = [NSMutableDictionary dictionaryWithCapacity:5]; 53 | } 54 | return self; 55 | } 56 | 57 | -(void) dealloc 58 | { 59 | CCLOGINFO( @"cocos2d: deallocing %@", self ); 60 | 61 | [groupName_ release]; 62 | [objects_ release]; 63 | [properties_ release]; 64 | [super dealloc]; 65 | } 66 | 67 | -(NSMutableDictionary*) objectNamed:(NSString *)objectName 68 | { 69 | for( id object in objects_ ) { 70 | if( [[object valueForKey:@"name"] isEqual:objectName] ) 71 | return object; 72 | } 73 | 74 | // object not found 75 | return nil; 76 | } 77 | 78 | -(id) propertyNamed:(NSString *)propertyName 79 | { 80 | return [properties_ valueForKey:propertyName]; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /libs/cocos2d/CCTileMapAtlas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "CCTextureAtlas.h" 27 | #import "CCAtlasNode.h" 28 | #import "Support/TGAlib.h" 29 | 30 | /** CCTileMapAtlas is a subclass of CCAtlasNode. 31 | 32 | It knows how to render a map based of tiles. 33 | The tiles must be in a .PNG format while the map must be a .TGA file. 34 | 35 | For more information regarding the format, please see this post: 36 | http://www.cocos2d-iphone.org/archives/27 37 | 38 | All features from CCAtlasNode are valid in CCTileMapAtlas 39 | 40 | IMPORTANT: 41 | This class is deprecated. It is maintained for compatibility reasons only. 42 | You SHOULD not use this class. 43 | Instead, use the newer TMX file format: CCTMXTiledMap 44 | */ 45 | @interface CCTileMapAtlas : CCAtlasNode 46 | { 47 | 48 | /// info about the map file 49 | tImageTGA *tgaInfo; 50 | 51 | /// x,y to altas dicctionary 52 | NSMutableDictionary *posToAtlasIndex; 53 | 54 | /// numbers of tiles to render 55 | int itemsToRender; 56 | } 57 | 58 | /** TileMap info */ 59 | @property (nonatomic,readonly) tImageTGA *tgaInfo; 60 | 61 | /** creates a CCTileMap with a tile file (atlas) with a map file and the width and height of each tile in points. 62 | The tile file will be loaded using the TextureMgr. 63 | */ 64 | +(id) tileMapAtlasWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; 65 | 66 | /** initializes a CCTileMap with a tile file (atlas) with a map file and the width and height of each tile in points. 67 | The file will be loaded using the TextureMgr. 68 | */ 69 | -(id) initWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; 70 | 71 | /** returns a tile from position x,y. 72 | For the moment only channel R is used 73 | */ 74 | -(ccColor3B) tileAt: (ccGridSize) position; 75 | 76 | /** sets a tile at position x,y. 77 | For the moment only channel R is used 78 | */ 79 | -(void) setTile:(ccColor3B)tile at:(ccGridSize)position; 80 | /** dealloc the map from memory */ 81 | -(void) releaseMap; 82 | @end 83 | -------------------------------------------------------------------------------- /libs/cocos2d/CCTransitionPageTurn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCTransition.h" 28 | 29 | /** CCTransitionPageTurn transition. 30 | * A transition which peels back the bottom right hand corner of a scene 31 | * to transition to the scene beneath it simulating a page turn 32 | * 33 | * This uses a 3DAction so it's strongly recommended that depth buffering 34 | * is turned on in CCDirector using: 35 | * 36 | * [[CCDirector sharedDirector] setDepthBufferFormat:kCCDepthBuffer16]; 37 | * 38 | * @since v0.8.2 39 | */ 40 | @interface CCTransitionPageTurn : CCTransitionScene 41 | { 42 | BOOL back_; 43 | } 44 | /** 45 | * creates a base transition with duration and incoming scene 46 | * if back is TRUE then the effect is reversed to appear as if the incoming 47 | * scene is being turned from left over the outgoing scene 48 | */ 49 | +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back; 50 | 51 | /** 52 | * creates a base transition with duration and incoming scene 53 | * if back is TRUE then the effect is reversed to appear as if the incoming 54 | * scene is being turned from left over the outgoing scene 55 | */ 56 | -(id) initWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back; 57 | 58 | -(CCActionInterval*) actionWithSize:(ccGridSize) vector; 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /libs/cocos2d/CCTransitionPageTurn.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "CCTransitionPageTurn.h" 28 | #import "CCActionPageTurn3D.h" 29 | #import "CCDirector.h" 30 | 31 | @implementation CCTransitionPageTurn 32 | 33 | /** creates a base transition with duration and incoming scene */ 34 | +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back 35 | { 36 | return [[[self alloc] initWithDuration:t scene:s backwards:back] autorelease]; 37 | } 38 | 39 | /** initializes a transition with duration and incoming scene */ 40 | -(id) initWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back 41 | { 42 | // XXX: needed before [super init] 43 | back_ = back; 44 | 45 | if( ( self = [super initWithDuration:t scene:s] ) ) 46 | { 47 | // do something 48 | } 49 | return self; 50 | } 51 | 52 | -(void) sceneOrder 53 | { 54 | inSceneOnTop_ = back_; 55 | } 56 | 57 | // 58 | -(void) onEnter 59 | { 60 | [super onEnter]; 61 | 62 | CGSize s = [[CCDirector sharedDirector] winSize]; 63 | int x, y; 64 | if( s.width > s.height) 65 | { 66 | x = 16; 67 | y = 12; 68 | } 69 | else 70 | { 71 | x = 12; 72 | y = 16; 73 | } 74 | 75 | id action = [self actionWithSize:ccg(x,y)]; 76 | 77 | if(! back_ ) 78 | { 79 | [outScene_ runAction: [CCSequence actions: 80 | action, 81 | [CCCallFunc actionWithTarget:self selector:@selector(finish)], 82 | [CCStopGrid action], 83 | nil] 84 | ]; 85 | } 86 | else 87 | { 88 | // to prevent initial flicker 89 | inScene_.visible = NO; 90 | [inScene_ runAction: [CCSequence actions: 91 | [CCShow action], 92 | action, 93 | [CCCallFunc actionWithTarget:self selector:@selector(finish)], 94 | [CCStopGrid action], 95 | nil] 96 | ]; 97 | } 98 | 99 | } 100 | 101 | -(CCActionInterval*) actionWithSize: (ccGridSize) v 102 | { 103 | if( back_ ) 104 | { 105 | // Get hold of the PageTurn3DAction 106 | return [CCReverseTime actionWithAction: 107 | [CCPageTurn3D actionWithSize:v duration:duration_]]; 108 | } 109 | else 110 | { 111 | // Get hold of the PageTurn3DAction 112 | return [CCPageTurn3D actionWithSize:v duration:duration_]; 113 | } 114 | } 115 | 116 | @end 117 | 118 | -------------------------------------------------------------------------------- /libs/cocos2d/CCTransitionRadial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Lam Pham 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "CCTransition.h" 27 | #import "CCProgressTimer.h" 28 | #import "CCActionProgressTimer.h" 29 | 30 | /** CCTransitionRadialCCW transition. 31 | A counter colock-wise radial transition to the next scene 32 | */ 33 | @interface CCTransitionRadialCCW : CCTransitionScene 34 | @end 35 | 36 | /** CCTransitionRadialCW transition. 37 | A counter colock-wise radial transition to the next scene 38 | */ 39 | @interface CCTransitionRadialCW : CCTransitionRadialCCW 40 | @end 41 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/CCGL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | // 26 | // Common layer for OpenGL stuff 27 | // 28 | 29 | #import 30 | 31 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 32 | #import 33 | #import 34 | #import 35 | #import "iOS/glu.h" 36 | #import "iOS/EAGLView.h" 37 | 38 | #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) 39 | #import 40 | #import 41 | #import // needed for NSOpenGLView 42 | #import "Mac/MacGLView.h" 43 | #endif 44 | 45 | 46 | // iOS 47 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 48 | #define CC_GLVIEW EAGLView 49 | #define ccglOrtho glOrthof 50 | #define ccglClearDepth glClearDepthf 51 | #define ccglGenerateMipmap glGenerateMipmapOES 52 | #define ccglGenFramebuffers glGenFramebuffersOES 53 | #define ccglBindFramebuffer glBindFramebufferOES 54 | #define ccglFramebufferTexture2D glFramebufferTexture2DOES 55 | #define ccglDeleteFramebuffers glDeleteFramebuffersOES 56 | #define ccglCheckFramebufferStatus glCheckFramebufferStatusOES 57 | #define ccglTranslate glTranslatef 58 | 59 | #define CC_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES 60 | #define CC_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES 61 | #define CC_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES 62 | #define CC_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES 63 | 64 | // Mac 65 | #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) 66 | #define CC_GLVIEW MacGLView 67 | #define ccglOrtho glOrtho 68 | #define ccglClearDepth glClearDepth 69 | #define ccglGenerateMipmap glGenerateMipmap 70 | #define ccglGenFramebuffers glGenFramebuffers 71 | #define ccglBindFramebuffer glBindFramebuffer 72 | #define ccglFramebufferTexture2D glFramebufferTexture2D 73 | #define ccglDeleteFramebuffers glDeleteFramebuffers 74 | #define ccglCheckFramebufferStatus glCheckFramebufferStatus 75 | #define ccglTranslate glTranslated 76 | 77 | #define CC_GL_FRAMEBUFFER GL_FRAMEBUFFER 78 | #define CC_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING 79 | #define CC_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0 80 | #define CC_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/CCNS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | // 26 | // Common layer for NS (Next-Step) stuff 27 | // 28 | 29 | #import 30 | 31 | #import // for NSObject 32 | 33 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 34 | 35 | #define CCRectFromString(__r__) CGRectFromString(__r__) 36 | #define CCPointFromString(__p__) CGPointFromString(__p__) 37 | #define CCSizeFromString(__s__) CGSizeFromString(__s__) 38 | #define CCNSSizeToCGSize 39 | #define CCNSRectToCGRect 40 | #define CCNSPointToCGPoint 41 | #define CCTextAlignment UITextAlignment 42 | #define CCTextAlignmentCenter UITextAlignmentCenter 43 | #define CCTextAlignmentLeft UITextAlignmentLeft 44 | #define CCTextAlignmentRight UITextAlignmentRight 45 | 46 | 47 | #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) 48 | 49 | #define CCRectFromString(__r__) NSRectToCGRect( NSRectFromString(__r__) ) 50 | #define CCPointFromString(__p__) NSPointToCGPoint( NSPointFromString(__p__) ) 51 | #define CCSizeFromString(__s__) NSSizeToCGSize( NSSizeFromString(__s__) ) 52 | #define CCNSSizeToCGSize NSSizeToCGSize 53 | #define CCNSRectToCGRect NSRectToCGRect 54 | #define CCNSPointToCGPoint NSPointToCGPoint 55 | #define CCTextAlignment NSTextAlignment 56 | #define CCTextAlignmentCenter NSCenterTextAlignment 57 | #define CCTextAlignmentLeft NSLeftTextAlignment 58 | #define CCTextAlignmentRight NSRightTextAlignment 59 | 60 | #endif 61 | 62 | 63 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/Mac/CCDirectorMac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | // Only compile this code on Mac. These files should not be included on your iOS project. 27 | // But in case they are included, it won't be compiled. 28 | #import 29 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 30 | #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) 31 | 32 | #import 33 | #import "../../CCDirector.h" 34 | 35 | enum { 36 | /// If the window is resized, it won't be autoscaled 37 | kCCDirectorResize_NoScale, 38 | /// If the window is resized, it will be autoscaled (default behavior) 39 | kCCDirectorResize_AutoScale, 40 | }; 41 | 42 | @interface CCDirector (MacExtension) 43 | /** converts an NSEvent to GL coordinates */ 44 | -(CGPoint) convertEventToGL:(NSEvent*)event; 45 | @end 46 | 47 | /** Base class of Mac directors 48 | @since v0.99.5 49 | */ 50 | @interface CCDirectorMac : CCDirector 51 | { 52 | BOOL isFullScreen_; 53 | int resizeMode_; 54 | CGPoint winOffset_; 55 | CGSize originalWinSize_; 56 | 57 | MacGLView *fullScreenGLView_; 58 | NSWindow *fullScreenWindow_; 59 | 60 | // cache 61 | MacGLView *windowGLView_; 62 | } 63 | 64 | // whether or not the view is in fullscreen mode 65 | @property (nonatomic, readonly) BOOL isFullScreen; 66 | 67 | // resize mode: with or without scaling 68 | @property (nonatomic, readwrite) int resizeMode; 69 | 70 | /** Sets the view in fullscreen or window mode */ 71 | - (void) setFullScreen:(BOOL)fullscreen; 72 | 73 | /** Converts window size coordiantes to logical coordinates. 74 | Useful only if resizeMode is kCCDirectorResize_Scale. 75 | If resizeMode is kCCDirectorResize_NoScale, then no conversion will be done. 76 | */ 77 | - (CGPoint) convertToLogicalCoordinates:(CGPoint)coordinates; 78 | @end 79 | 80 | 81 | /** DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display. 82 | * 83 | * Features and Limitations: 84 | * - Only available on 3.1+ 85 | * - Scheduled timers & drawing are synchronizes with the refresh rate of the display 86 | * - Only supports animation intervals of 1/60 1/30 & 1/15 87 | * 88 | * It is the recommended Director if the SDK is 3.1 or newer 89 | * 90 | * @since v0.8.2 91 | */ 92 | @interface CCDirectorDisplayLink : CCDirectorMac 93 | { 94 | CVDisplayLinkRef displayLink; 95 | } 96 | @end 97 | 98 | #endif // __MAC_OS_X_VERSION_MAX_ALLOWED 99 | 100 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/Mac/MacGLView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | // Only compile this code on Mac. These files should not be included on your iOS project. 26 | // But in case they are included, it won't be compiled. 27 | #import 28 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 29 | #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) 30 | 31 | #import 32 | 33 | #import "../../ccConfig.h" 34 | 35 | //PROTOCOLS: 36 | 37 | @protocol MacEventDelegate 38 | // Mouse 39 | - (void)mouseDown:(NSEvent *)theEvent; 40 | - (void)mouseUp:(NSEvent *)theEvent; 41 | - (void)mouseMoved:(NSEvent *)theEvent; 42 | - (void)mouseDragged:(NSEvent *)theEvent; 43 | - (void)rightMouseDown:(NSEvent*)event; 44 | - (void)rightMouseDragged:(NSEvent*)event; 45 | - (void)rightMouseUp:(NSEvent*)event; 46 | - (void)otherMouseDown:(NSEvent*)event; 47 | - (void)otherMouseDragged:(NSEvent*)event; 48 | - (void)otherMouseUp:(NSEvent*)event; 49 | - (void)scrollWheel:(NSEvent *)theEvent; 50 | - (void)mouseEntered:(NSEvent *)theEvent; 51 | - (void)mouseExited:(NSEvent *)theEvent; 52 | 53 | 54 | // Keyboard 55 | - (void)keyDown:(NSEvent *)theEvent; 56 | - (void)keyUp:(NSEvent *)theEvent; 57 | - (void)flagsChanged:(NSEvent *)theEvent; 58 | 59 | // Touches 60 | - (void)touchesBeganWithEvent:(NSEvent *)event; 61 | - (void)touchesMovedWithEvent:(NSEvent *)event; 62 | - (void)touchesEndedWithEvent:(NSEvent *)event; 63 | - (void)touchesCancelledWithEvent:(NSEvent *)event; 64 | 65 | #if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD 66 | - (void)queueEvent:(NSEvent*)event selector:(SEL)selector; 67 | #endif 68 | 69 | @end 70 | 71 | /** MacGLView 72 | 73 | Only available for Mac OS X 74 | */ 75 | @interface MacGLView : NSOpenGLView { 76 | id eventDelegate_; 77 | } 78 | 79 | @property (nonatomic, readwrite, assign) id eventDelegate; 80 | 81 | // initializes the MacGLView with a frame rect and an OpenGL context 82 | - (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context; 83 | 84 | // private 85 | +(void) load_; 86 | @end 87 | 88 | #endif // __MAC_OS_X_VERSION_MAX_ALLOWED -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/iOS/CCTouchDelegateProtocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Valentin Milea 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | // Only compile this code on iOS. These files should NOT be included on your Mac project. 27 | // But in case they are included, it won't be compiled. 28 | #import 29 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 30 | 31 | #import 32 | 33 | /** 34 | CCTargetedTouchDelegate. 35 | 36 | Using this type of delegate results in two benefits: 37 | 1. You don't need to deal with NSSets, the dispatcher does the job of splitting 38 | them. You get exactly one UITouch per call. 39 | 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed 40 | touches are sent only to the delegate(s) that claimed them. So if you get a move/ 41 | ended/cancelled update you're sure it's your touch. This frees you from doing a 42 | lot of checks when doing multi-touch. 43 | 44 | (The name TargetedTouchDelegate relates to updates "targeting" their specific 45 | handler, without bothering the other handlers.) 46 | @since v0.8 47 | */ 48 | @protocol CCTargetedTouchDelegate 49 | 50 | /** Return YES to claim the touch. 51 | @since v0.8 52 | */ 53 | - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event; 54 | @optional 55 | // touch updates: 56 | - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event; 57 | - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event; 58 | - (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event; 59 | @end 60 | 61 | /** 62 | CCStandardTouchDelegate. 63 | 64 | This type of delegate is the same one used by CocoaTouch. You will receive all the events (Began,Moved,Ended,Cancelled). 65 | @since v0.8 66 | */ 67 | @protocol CCStandardTouchDelegate 68 | @optional 69 | - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 70 | - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 71 | - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 72 | - (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; 73 | @end 74 | 75 | #endif // __IPHONE_OS_VERSION_MAX_ALLOWED 76 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/iOS/ES1Renderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * 25 | * File autogenerated with Xcode. Adapted for cocos2d needs. 26 | */ 27 | 28 | // Only compile this code on iOS. These files should NOT be included on your Mac project. 29 | // But in case they are included, it won't be compiled. 30 | #import 31 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 32 | 33 | 34 | #import "ESRenderer.h" 35 | 36 | #import 37 | #import 38 | 39 | @interface ES1Renderer : NSObject 40 | { 41 | // The pixel dimensions of the CAEAGLLayer 42 | GLint backingWidth_; 43 | GLint backingHeight_; 44 | 45 | unsigned int samplesToUse_; 46 | BOOL multiSampling_; 47 | 48 | unsigned int depthFormat_; 49 | unsigned int pixelFormat_; 50 | 51 | // The OpenGL ES names for the framebuffer and renderbuffer used to render to this view 52 | GLuint defaultFramebuffer_; 53 | GLuint colorRenderbuffer_; 54 | GLuint depthBuffer_; 55 | 56 | 57 | //buffers for MSAA 58 | GLuint msaaFramebuffer_; 59 | GLuint msaaColorbuffer_; 60 | 61 | EAGLContext *context_; 62 | } 63 | 64 | /** EAGLContext */ 65 | @property (nonatomic,readonly) EAGLContext* context; 66 | 67 | - (BOOL)resizeFromLayer:(CAEAGLLayer *)layer; 68 | 69 | @end 70 | 71 | #endif // __IPHONE_OS_VERSION_MAX_ALLOWED 72 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/iOS/ESRenderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * 25 | * File autogenerated with Xcode. Adapted for cocos2d needs. 26 | */ 27 | 28 | // Only compile this code on iOS. These files should NOT be included on your Mac project. 29 | // But in case they are included, it won't be compiled. 30 | #import 31 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 32 | 33 | #import 34 | 35 | #import 36 | #import 37 | 38 | @protocol ESRenderer 39 | 40 | - (id) initWithDepthFormat:(unsigned int)depthFormat withPixelFormat:(unsigned int)pixelFormat withSharegroup:(EAGLSharegroup*)sharegroup withMultiSampling:(BOOL) multiSampling withNumberOfSamples:(unsigned int) requestedSamples; 41 | 42 | - (BOOL) resizeFromLayer:(CAEAGLLayer *)layer; 43 | 44 | - (EAGLContext*) context; 45 | - (CGSize) backingSize; 46 | 47 | - (unsigned int) colorRenderBuffer; 48 | - (unsigned int) defaultFrameBuffer; 49 | - (unsigned int) msaaFrameBuffer; 50 | - (unsigned int) msaaColorBuffer; 51 | @end 52 | 53 | #endif // __IPHONE_OS_VERSION_MAX_ALLOWED 54 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/iOS/glu.c: -------------------------------------------------------------------------------- 1 | // 2 | // cocos2d (incomplete) GLU implementation 3 | // 4 | // gluLookAt and gluPerspective from: 5 | // http://jet.ro/creations (San Angeles Observation) 6 | // 7 | // 8 | 9 | // Only compile this code on iOS. These files should NOT be included on your Mac project. 10 | // But in case they are included, it won't be compiled. 11 | #import 12 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 13 | 14 | #import 15 | #import 16 | #import "../../Support/OpenGL_Internal.h" 17 | #include "glu.h" 18 | 19 | void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) 20 | { 21 | GLfloat xmin, xmax, ymin, ymax; 22 | 23 | ymax = zNear * (GLfloat)tanf(fovy * (float)M_PI / 360); 24 | ymin = -ymax; 25 | xmin = ymin * aspect; 26 | xmax = ymax * aspect; 27 | 28 | glFrustumf(xmin, xmax, 29 | ymin, ymax, 30 | zNear, zFar); 31 | } 32 | 33 | void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, 34 | GLfloat centerx, GLfloat centery, GLfloat centerz, 35 | GLfloat upx, GLfloat upy, GLfloat upz) 36 | { 37 | GLfloat m[16]; 38 | GLfloat x[3], y[3], z[3]; 39 | GLfloat mag; 40 | 41 | /* Make rotation matrix */ 42 | 43 | /* Z vector */ 44 | z[0] = eyex - centerx; 45 | z[1] = eyey - centery; 46 | z[2] = eyez - centerz; 47 | mag = (float)sqrtf(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]); 48 | if (mag) { 49 | z[0] /= mag; 50 | z[1] /= mag; 51 | z[2] /= mag; 52 | } 53 | 54 | /* Y vector */ 55 | y[0] = upx; 56 | y[1] = upy; 57 | y[2] = upz; 58 | 59 | /* X vector = Y cross Z */ 60 | x[0] = y[1] * z[2] - y[2] * z[1]; 61 | x[1] = -y[0] * z[2] + y[2] * z[0]; 62 | x[2] = y[0] * z[1] - y[1] * z[0]; 63 | 64 | /* Recompute Y = Z cross X */ 65 | y[0] = z[1] * x[2] - z[2] * x[1]; 66 | y[1] = -z[0] * x[2] + z[2] * x[0]; 67 | y[2] = z[0] * x[1] - z[1] * x[0]; 68 | 69 | /* cross product gives area of parallelogram, which is < 1.0 for 70 | * non-perpendicular unit-length vectors; so normalize x, y here 71 | */ 72 | 73 | mag = (float)sqrtf(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); 74 | if (mag) { 75 | x[0] /= mag; 76 | x[1] /= mag; 77 | x[2] /= mag; 78 | } 79 | 80 | mag = (float)sqrtf(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]); 81 | if (mag) { 82 | y[0] /= mag; 83 | y[1] /= mag; 84 | y[2] /= mag; 85 | } 86 | 87 | #define M(row,col) m[col*4+row] 88 | M(0, 0) = x[0]; 89 | M(0, 1) = x[1]; 90 | M(0, 2) = x[2]; 91 | M(0, 3) = 0.0f; 92 | M(1, 0) = y[0]; 93 | M(1, 1) = y[1]; 94 | M(1, 2) = y[2]; 95 | M(1, 3) = 0.0f; 96 | M(2, 0) = z[0]; 97 | M(2, 1) = z[1]; 98 | M(2, 2) = z[2]; 99 | M(2, 3) = 0.0f; 100 | M(3, 0) = 0.0f; 101 | M(3, 1) = 0.0f; 102 | M(3, 2) = 0.0f; 103 | M(3, 3) = 1.0f; 104 | #undef M 105 | 106 | glMultMatrixf(m); 107 | 108 | 109 | /* Translate Eye to Origin */ 110 | glTranslatef(-eyex, -eyey, -eyez); 111 | } 112 | 113 | #endif // __IPHONE_OS_VERSION_MAX_ALLOWED 114 | -------------------------------------------------------------------------------- /libs/cocos2d/Platforms/iOS/glu.h: -------------------------------------------------------------------------------- 1 | // 2 | // cocos2d GLU implementation 3 | // 4 | // implementation of GLU functions 5 | // 6 | #ifndef __COCOS2D_GLU_H 7 | #define __COCOS2D_GLU_H 8 | 9 | // Only compile this code on iOS. These files should NOT be included on your Mac project. 10 | // But in case they are included, it won't be compiled. 11 | #import 12 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 13 | 14 | #import 15 | 16 | /** 17 | @file 18 | cocos2d OpenGL GLU implementation 19 | */ 20 | 21 | /** OpenGL gluLookAt implementation */ 22 | void gluLookAt(float eyeX, float eyeY, float eyeZ, float lookAtX, float lookAtY, float lookAtZ, float upX, float upY, float upZ); 23 | /** OpenGL gluPerspective implementation */ 24 | void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar); 25 | 26 | #endif // __IPHONE_OS_VERSION_MAX_ALLOWED 27 | 28 | #endif /* __COCOS2D_GLU_H */ 29 | 30 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/CCArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Abstraction Works. http://www.abstractionworks.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | #import "ccCArray.h" 27 | 28 | 29 | /** A faster alternative of NSArray. 30 | CCArray uses internally a c-array. 31 | @since v0.99.4 32 | */ 33 | 34 | 35 | /** @def CCARRAY_FOREACH 36 | A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface. 37 | @since v0.99.4 38 | */ 39 | 40 | #define CCARRAY_FOREACH(__array__, __object__) \ 41 | if (__array__ && __array__->data->num > 0) \ 42 | for(id *arr = __array__->data->arr, *end = __array__->data->arr + __array__->data->num-1; \ 43 | arr <= end && ((__object__ = *arr) != nil || true); \ 44 | arr++) 45 | 46 | @interface CCArray : NSObject 47 | { 48 | @public ccArray *data; 49 | } 50 | 51 | + (id) array; 52 | + (id) arrayWithCapacity:(NSUInteger)capacity; 53 | + (id) arrayWithArray:(CCArray*)otherArray; 54 | + (id) arrayWithNSArray:(NSArray*)otherArray; 55 | 56 | 57 | - (id) initWithCapacity:(NSUInteger)capacity; 58 | - (id) initWithArray:(CCArray*)otherArray; 59 | - (id) initWithNSArray:(NSArray*)otherArray; 60 | 61 | 62 | - (NSUInteger) count; 63 | - (NSUInteger) capacity; 64 | - (NSUInteger) indexOfObject:(id)object; 65 | - (id) objectAtIndex:(NSUInteger)index; 66 | - (id) lastObject; 67 | - (id) randomObject; 68 | - (BOOL) containsObject:(id)object; 69 | 70 | #pragma mark Adding Objects 71 | 72 | - (void) addObject:(id)object; 73 | - (void) addObjectsFromArray:(CCArray*)otherArray; 74 | - (void) addObjectsFromNSArray:(NSArray*)otherArray; 75 | - (void) insertObject:(id)object atIndex:(NSUInteger)index; 76 | 77 | #pragma mark Removing Objects 78 | 79 | - (void) removeLastObject; 80 | - (void) removeObject:(id)object; 81 | - (void) removeObjectAtIndex:(NSUInteger)index; 82 | - (void) removeObjectsInArray:(CCArray*)otherArray; 83 | - (void) removeAllObjects; 84 | - (void) fastRemoveObject:(id)object; 85 | - (void) fastRemoveObjectAtIndex:(NSUInteger)index; 86 | 87 | - (void) makeObjectsPerformSelector:(SEL)aSelector; 88 | - (void) makeObjectsPerformSelector:(SEL)aSelector withObject:(id)object; 89 | 90 | - (NSArray*) getNSArray; 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/CCFileUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | 29 | 30 | /** Helper class to handle file operations */ 31 | @interface CCFileUtils : NSObject 32 | { 33 | } 34 | 35 | /** Returns the fullpath of an filename. 36 | 37 | If this method is when Retina Display is enabled, then the 38 | Retina Display suffix will be appended to the file (See ccConfig.h). 39 | 40 | If the Retina Display image doesn't exist, then it will return the "non-Retina Display" image 41 | 42 | */ 43 | +(NSString*) fullPathFromRelativePath:(NSString*) relPath; 44 | @end 45 | 46 | /** loads a file into memory. 47 | the caller should release the allocated buffer. 48 | 49 | @returns the size of the allocated buffer 50 | @since v0.99.5 51 | */ 52 | int ccLoadFileIntoMemory(const char *filename, unsigned char **out); 53 | 54 | 55 | /** removes the HD suffix from a path 56 | 57 | @returns NSString * without the HD suffix 58 | @since v0.99.5 59 | */ 60 | NSString *ccRemoveHDSuffixFromFile( NSString *path ); 61 | 62 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/CCProfiling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Stuart Carnie 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | #import 29 | 30 | @class CCProfilingTimer; 31 | 32 | @interface CCProfiler : NSObject { 33 | NSMutableArray* activeTimers; 34 | } 35 | 36 | + (CCProfiler*)sharedProfiler; 37 | + (CCProfilingTimer*)timerWithName:(NSString*)timerName andInstance:(id)instance; 38 | + (void)releaseTimer:(CCProfilingTimer*)timer; 39 | - (void)displayTimers; 40 | 41 | @end 42 | 43 | 44 | @interface CCProfilingTimer : NSObject { 45 | NSString* name; 46 | struct timeval startTime; 47 | double averageTime; 48 | } 49 | 50 | @end 51 | 52 | extern void CCProfilingBeginTimingBlock(CCProfilingTimer* timer); 53 | extern void CCProfilingEndTimingBlock(CCProfilingTimer* timer); 54 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/CCProfiling.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2010 Stuart Carnie 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import "../ccConfig.h" 27 | 28 | #if CC_ENABLE_PROFILERS 29 | 30 | #import "CCProfiling.h" 31 | 32 | @interface CCProfilingTimer() 33 | - (id)initWithName:(NSString*)timerName andInstance:(id)instance; 34 | @end 35 | 36 | @implementation CCProfiler 37 | 38 | static CCProfiler* g_sharedProfiler; 39 | 40 | + (CCProfiler*)sharedProfiler { 41 | if (!g_sharedProfiler) 42 | g_sharedProfiler = [[CCProfiler alloc] init]; 43 | 44 | return g_sharedProfiler; 45 | } 46 | 47 | + (CCProfilingTimer*)timerWithName:(NSString*)timerName andInstance:(id)instance { 48 | CCProfiler* p = [CCProfiler sharedProfiler]; 49 | CCProfilingTimer* t = [[CCProfilingTimer alloc] initWithName:timerName andInstance:instance]; 50 | [p->activeTimers addObject:t]; 51 | [t release]; 52 | return t; 53 | } 54 | 55 | + (void)releaseTimer:(CCProfilingTimer*)timer { 56 | CCProfiler* p = [CCProfiler sharedProfiler]; 57 | [p->activeTimers removeObject:timer]; 58 | } 59 | 60 | - (id)init { 61 | if (!(self = [super init])) return nil; 62 | 63 | activeTimers = [[NSMutableArray alloc] init]; 64 | 65 | return self; 66 | } 67 | 68 | - (void)dealloc { 69 | [activeTimers release]; 70 | [super dealloc]; 71 | } 72 | 73 | - (void)displayTimers { 74 | for (id timer in activeTimers) { 75 | printf("%s\n", [[timer description] cStringUsingEncoding:[NSString defaultCStringEncoding]]); 76 | } 77 | } 78 | 79 | @end 80 | 81 | @implementation CCProfilingTimer 82 | 83 | - (id)initWithName:(NSString*)timerName andInstance:(id)instance { 84 | if (!(self = [super init])) return nil; 85 | 86 | name = [[NSString stringWithFormat:@"%@ (0x%.8x)", timerName, instance] retain]; 87 | 88 | return self; 89 | } 90 | 91 | - (void)dealloc { 92 | [name release]; 93 | [super dealloc]; 94 | } 95 | 96 | - (NSString*)description { 97 | return [NSString stringWithFormat:@"%@ : avg time, %fms", name, averageTime]; 98 | } 99 | 100 | void CCProfilingBeginTimingBlock(CCProfilingTimer* timer) { 101 | gettimeofday(&timer->startTime, NULL); 102 | } 103 | 104 | typedef unsigned int uint32; 105 | void CCProfilingEndTimingBlock(CCProfilingTimer* timer) { 106 | struct timeval currentTime; 107 | gettimeofday(¤tTime, NULL); 108 | timersub(¤tTime, &timer->startTime, ¤tTime); 109 | double duration = currentTime.tv_sec * 1000.0 + currentTime.tv_usec / 1000.0; 110 | 111 | // return in milliseconds 112 | timer->averageTime = (timer->averageTime + duration) / 2.0f; 113 | } 114 | 115 | @end 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/TGAlib.h: -------------------------------------------------------------------------------- 1 | // 2 | // TGA lib for cocos2d-iphone 3 | // 4 | // sources from: http://www.lighthouse3d.com/opengl/terrain/index.php3?tgasource 5 | // 6 | 7 | //#ifndef TGA_LIB 8 | //#define TGA_LIB 9 | 10 | /** 11 | @file 12 | TGA image support 13 | */ 14 | 15 | enum { 16 | TGA_OK, 17 | TGA_ERROR_FILE_OPEN, 18 | TGA_ERROR_READING_FILE, 19 | TGA_ERROR_INDEXED_COLOR, 20 | TGA_ERROR_MEMORY, 21 | TGA_ERROR_COMPRESSED_FILE, 22 | }; 23 | 24 | /** TGA format */ 25 | typedef struct sImageTGA { 26 | int status; 27 | unsigned char type, pixelDepth; 28 | 29 | /** map width */ 30 | short int width; 31 | 32 | /** map height */ 33 | short int height; 34 | 35 | /** raw data */ 36 | unsigned char *imageData; 37 | int flipped; 38 | } tImageTGA; 39 | 40 | /// load the image header fields. We only keep those that matter! 41 | void tgaLoadHeader(FILE *file, tImageTGA *info); 42 | 43 | /// loads the image pixels. You shouldn't call this function directly 44 | void tgaLoadImageData(FILE *file, tImageTGA *info); 45 | 46 | /// this is the function to call when we want to load an image 47 | tImageTGA * tgaLoad(const char *filename); 48 | 49 | // /converts RGB to greyscale 50 | void tgaRGBtogreyscale(tImageTGA *info); 51 | 52 | /// releases the memory used for the image 53 | void tgaDestroy(tImageTGA *info); 54 | 55 | //#endif // TGA_LIB 56 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/TransformUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Valentin Milea 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #import 27 | 28 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED 29 | #import 30 | #import 31 | #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) 32 | #import 33 | #import 34 | #endif 35 | 36 | void CGAffineToGL(const CGAffineTransform *t, GLfloat *m); 37 | void GLToCGAffine(const GLfloat *m, CGAffineTransform *t); 38 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/TransformUtils.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2009 Valentin Milea 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import "TransformUtils.h" 28 | 29 | void CGAffineToGL(const CGAffineTransform *t, GLfloat *m) 30 | { 31 | // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx | 32 | // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty | 33 | // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 | 34 | // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 | 35 | 36 | m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f; 37 | m[10] = m[15] = 1.0f; 38 | m[0] = t->a; m[4] = t->c; m[12] = t->tx; 39 | m[1] = t->b; m[5] = t->d; m[13] = t->ty; 40 | } 41 | 42 | void GLToCGAffine(const GLfloat *m, CGAffineTransform *t) 43 | { 44 | t->a = m[0]; t->c = m[4]; t->tx = m[12]; 45 | t->b = m[1]; t->d = m[5]; t->ty = m[13]; 46 | } 47 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/ZipUtils.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * 6 | * inflateMemory_ based on zlib example code 7 | * http://www.zlib.net 8 | * 9 | * Some ideas were taken from: 10 | * http://themanaworld.org/ 11 | * from the mapreader.cpp file 12 | * 13 | */ 14 | 15 | #ifndef __CC_ZIP_UTILS_H 16 | #define __CC_ZIP_UTILS_H 17 | 18 | #import 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* XXX: pragma pack ??? */ 25 | /** @struct CCZHeader 26 | */ 27 | struct CCZHeader { 28 | uint8_t sig[4]; // signature. Should be 'CCZ!' 4 bytes 29 | uint16_t compression_type; // should 0 30 | uint16_t version; // should be 2 (although version type==1 is also supported) 31 | uint32_t reserved; // Reserverd for users. 32 | uint32_t len; // size of the uncompressed file 33 | }; 34 | 35 | enum { 36 | CCZ_COMPRESSION_ZLIB, // zlib format. 37 | CCZ_COMPRESSION_BZIP2, // bzip2 format (not supported yet) 38 | CCZ_COMPRESSION_GZIP, // gzip format (not supported yet) 39 | CCZ_COMPRESSION_NONE, // plain (not supported yet) 40 | }; 41 | 42 | /** @file 43 | * Zip helper functions 44 | */ 45 | 46 | /** 47 | * Inflates either zlib or gzip deflated memory. The inflated memory is 48 | * expected to be freed by the caller. 49 | * 50 | * @returns the length of the deflated buffer 51 | * 52 | @since v0.8.1 53 | */ 54 | int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out); 55 | 56 | 57 | /** inflates a GZip file into memory 58 | * 59 | * @returns the length of the deflated buffer 60 | * 61 | * @since v0.99.5 62 | */ 63 | int ccInflateGZipFile(const char *filename, unsigned char **out); 64 | 65 | /** inflates a CCZ file into memory 66 | * 67 | * @returns the length of the deflated buffer 68 | * 69 | * @since v0.99.5 70 | */ 71 | int ccInflateCCZFile(const char *filename, unsigned char **out); 72 | 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif // __CC_ZIP_UTILS_H 79 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/base64.c: -------------------------------------------------------------------------------- 1 | /* 2 | public domain BASE64 code 3 | 4 | modified for cocos2d-iphone: http://www.cocos2d-iphone.org 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | unsigned char alphabet[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 11 | 12 | int _base64Decode( unsigned char *input, unsigned int input_len, unsigned char *output, unsigned int *output_len ) 13 | { 14 | static char inalphabet[256], decoder[256]; 15 | int i, bits, c, char_count, errors = 0; 16 | unsigned int input_idx = 0; 17 | unsigned int output_idx = 0; 18 | 19 | for (i = (sizeof alphabet) - 1; i >= 0 ; i--) { 20 | inalphabet[alphabet[i]] = 1; 21 | decoder[alphabet[i]] = i; 22 | } 23 | 24 | char_count = 0; 25 | bits = 0; 26 | for( input_idx=0; input_idx < input_len ; input_idx++ ) { 27 | c = input[ input_idx ]; 28 | if (c == '=') 29 | break; 30 | if (c > 255 || ! inalphabet[c]) 31 | continue; 32 | bits += decoder[c]; 33 | char_count++; 34 | if (char_count == 4) { 35 | output[ output_idx++ ] = (bits >> 16); 36 | output[ output_idx++ ] = ((bits >> 8) & 0xff); 37 | output[ output_idx++ ] = ( bits & 0xff); 38 | bits = 0; 39 | char_count = 0; 40 | } else { 41 | bits <<= 6; 42 | } 43 | } 44 | 45 | if( c == '=' ) { 46 | switch (char_count) { 47 | case 1: 48 | fprintf(stderr, "base64Decode: encoding incomplete: at least 2 bits missing"); 49 | errors++; 50 | break; 51 | case 2: 52 | output[ output_idx++ ] = ( bits >> 10 ); 53 | break; 54 | case 3: 55 | output[ output_idx++ ] = ( bits >> 16 ); 56 | output[ output_idx++ ] = (( bits >> 8 ) & 0xff); 57 | break; 58 | } 59 | } else if ( input_idx < input_len ) { 60 | if (char_count) { 61 | fprintf(stderr, "base64 encoding incomplete: at least %d bits truncated", 62 | ((4 - char_count) * 6)); 63 | errors++; 64 | } 65 | } 66 | 67 | *output_len = output_idx; 68 | return errors; 69 | } 70 | 71 | int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out) 72 | { 73 | unsigned int outLength = 0; 74 | 75 | //should be enough to store 6-bit buffers in 8-bit buffers 76 | *out = malloc( inLength * 3.0f / 4.0f + 1 ); 77 | if( *out ) { 78 | int ret = _base64Decode(in, inLength, *out, &outLength); 79 | 80 | if (ret > 0 ) 81 | { 82 | printf("Base64Utils: error decoding"); 83 | free(*out); 84 | *out = NULL; 85 | outLength = 0; 86 | } 87 | } 88 | return outLength; 89 | } 90 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | public domain BASE64 code 3 | 4 | modified for cocos2d-iphone: http://www.cocos2d-iphone.org 5 | */ 6 | 7 | #ifndef __CC_BASE64_DECODE_H 8 | #define __CC_BASE64_DECODE_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | 15 | /** @file 16 | base64 helper functions 17 | */ 18 | 19 | /** 20 | * Decodes a 64base encoded memory. The decoded memory is 21 | * expected to be freed by the caller. 22 | * 23 | * @returns the length of the out buffer 24 | * 25 | @since v0.8.1 26 | */ 27 | int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif // __CC_BASE64_DECODE_H 34 | -------------------------------------------------------------------------------- /libs/cocos2d/Support/ccUtils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | */ 5 | 6 | /* 7 | ccNextPOT function is licensed under the same license that is used in CCTexture2D.m. 8 | */ 9 | #include "ccUtils.h" 10 | 11 | unsigned int ccNextPOT(unsigned int x) 12 | { 13 | x = x - 1; 14 | x = x | (x >> 1); 15 | x = x | (x >> 2); 16 | x = x | (x >> 4); 17 | x = x | (x >> 8); 18 | x = x | (x >>16); 19 | return x + 1; 20 | } -------------------------------------------------------------------------------- /libs/cocos2d/Support/ccUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | */ 5 | 6 | #ifndef __CC_UTILS_H 7 | #define __CC_UTILS_H 8 | 9 | /** @file ccUtils.h 10 | Misc free functions 11 | */ 12 | 13 | /* 14 | ccNextPOT function is licensed under the same license that is used in CCTexture2D.m. 15 | */ 16 | 17 | /** returns the Next Power of Two value. 18 | 19 | Examples: 20 | - If "value" is 15, it will return 16. 21 | - If "value" is 16, it will return 16. 22 | - If "value" is 17, it will return 32. 23 | 24 | @since v0.99.5 25 | */ 26 | 27 | unsigned int ccNextPOT( unsigned int value ); 28 | 29 | #endif // ! __CC_UTILS_H 30 | -------------------------------------------------------------------------------- /libs/cocos2d/cocos2d.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | #import 27 | 28 | static NSString *version = @"cocos2d v0.99.5"; 29 | 30 | NSString *cocos2dVersion() 31 | { 32 | return version; 33 | } 34 | -------------------------------------------------------------------------------- /libs/cocoslive/cocoslive.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | 28 | // 0x00 HI ME LO 29 | // 00 00 03 02 30 | #define COCOSLIVE_VERSION 0x00000302 31 | 32 | // to use localserver. DEBUG ONLY 33 | //#define USE_LOCAL_SERVER 1 34 | 35 | // all cocos live include files 36 | // 37 | #import "CLScoreServerPost.h" 38 | #import "CLScoreServerRequest.h" 39 | 40 | 41 | // free functions 42 | NSString * cocos2dVersion(void); 43 | -------------------------------------------------------------------------------- /libs/cocoslive/cocoslive.m: -------------------------------------------------------------------------------- 1 | /* 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org 3 | * 4 | * Copyright (c) 2008-2010 Ricardo Quesada 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #import 28 | 29 | static NSString *version = @"cocoslive v0.3.2"; 30 | 31 | NSString *cocosLiveVersion() 32 | { 33 | return version; 34 | } 35 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TextBoxLayerSample 4 | // 5 | // Created by Fabio Rodella on 1/19/11. 6 | // Copyright __MyCompanyName__ 2011. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | NSAutoreleasePool *pool = [NSAutoreleasePool new]; 13 | int retVal = UIApplicationMain(argc, argv, nil, @"TextBoxLayerSampleAppDelegate"); 14 | [pool release]; 15 | return retVal; 16 | } 17 | --------------------------------------------------------------------------------