Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
549 lines (419 sloc) 12.8 KB
/*
* CocosBuilder: http://www.cocosbuilder.com
*
* Copyright (c) 2012 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "ResolutionSetting.h"
#define DESIGN_WIDTH 1200
#define DESIGN_HEIGHT 800
@implementation ResolutionSetting
@synthesize enabled;
@synthesize name;
@synthesize width;
@synthesize height;
@synthesize ext;
@synthesize scale;
@synthesize centeredOrigin;
@synthesize exts;
- (id) init
{
self = [super init];
if (!self) return NULL;
enabled = NO;
self.name = @"Custom";
self.width = 1000;
self.height = 1000;
self.ext = @" ";
self.scale = 1;
return self;
}
- (id) initWithSerialization:(id)serialization
{
self = [self init];
if (!self) return NULL;
self.enabled = YES;
self.name = [serialization objectForKey:@"name"];
self.width = [[serialization objectForKey:@"width"] intValue];
self.height = [[serialization objectForKey:@"height"] intValue];
self.ext = [serialization objectForKey:@"ext"];
self.scale = [[serialization objectForKey:@"scale"] floatValue];
self.centeredOrigin = [[serialization objectForKey:@"centeredOrigin"] boolValue];
return self;
}
- (id) serialize
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[dict setObject:name forKey:@"name"];
[dict setObject:[NSNumber numberWithInt:width] forKey:@"width"];
[dict setObject:[NSNumber numberWithInt:height] forKey:@"height"];
[dict setObject:ext forKey:@"ext"];
[dict setObject:[NSNumber numberWithFloat:scale] forKey:@"scale"];
[dict setObject:[NSNumber numberWithBool:centeredOrigin] forKey:@"centeredOrigin"];
return dict;
}
- (void) setExt:(NSString *)e
{
[ext release];
[exts release];
ext = [e copy];
if (!e || [e isEqualToString:@" "] || [e isEqualToString:@""])
{
exts = [[NSArray alloc] init];
}
else
{
exts = [[e componentsSeparatedByString:@" "] retain];
}
}
- (void) dealloc
{
self.name = NULL;
self.ext = NULL;
[exts release];
[super dealloc];
}
+ (ResolutionSetting*) settingDesign
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"Design";
setting.width = DESIGN_WIDTH;
setting.height = DESIGN_HEIGHT;
setting.ext = @"design";
setting.scale = 1;
return setting;
}
+ (ResolutionSetting*) settingIPhone
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"iPhone";
setting.width = 0;
setting.height = 0;
setting.ext = @"iphone";
setting.scale = 1;
return setting;
}
+ (ResolutionSetting*) settingIPhoneLandscape
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone Landscape";
setting.width = 480;
setting.height = 320;
setting.scale = (float)setting.height / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingIPhonePortrait
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone Portrait";
setting.width = 320;
setting.height = 480;
setting.scale = (float)setting.height / DESIGN_WIDTH;
return setting;
}
+ (ResolutionSetting*) settingIPhone4Landscape
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone4 Landscape";
setting.width = 960;
setting.height = 640;
setting.scale = (float)setting.height / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingIPhone4Portrait
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone4 Portrait";
setting.width = 640;
setting.height = 960;
setting.scale = (float)setting.height / DESIGN_WIDTH;
return setting;
}
+ (ResolutionSetting*) settingIPhone5Landscape
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone 5 Landscape";
setting.width = 1136;
setting.height = 640;
setting.scale = (float)setting.height / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingIPhone5Portrait
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone 5 Portrait";
setting.width = 640;
setting.height = 1136;
setting.scale = (float)setting.height / DESIGN_WIDTH;
return setting;
}
+ (ResolutionSetting*) settingIPhone6Landscape
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone 6 Landscape";
setting.width = 1334;
setting.height = 750;
setting.scale = (float)setting.height / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingIPhone6Portrait
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone 6 Portrait";
setting.width = 750;
setting.height = 1334;
setting.scale = (float)setting.height / DESIGN_WIDTH;
return setting;
}
+ (ResolutionSetting*) settingIPhone6PlusLandscape
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone 6 Plus Landscape";
setting.width = 2208;
setting.height = 1242;
setting.scale = (float)setting.height / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingIPhone6PlusPortrait
{
ResolutionSetting* setting = [self settingIPhone];
setting.name = @"iPhone 6 Plus Portrait";
setting.width = 1242;
setting.height = 2208;
setting.scale = (float)setting.height / DESIGN_WIDTH;
return setting;
}
+ (ResolutionSetting*) settingIPad
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"iPad";
setting.width = 0;
setting.height = 0;
setting.ext = @"ipad iphonehd";
setting.scale = 768.0f / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingIPadLandscape
{
ResolutionSetting* setting = [self settingIPad];
setting.name = @"iPad Landscape";
setting.width = 1024;
setting.height = 768;
return setting;
}
+ (ResolutionSetting*) settingIPadPortrait
{
ResolutionSetting* setting = [self settingIPad];
setting.name = @"iPad Portrait";
setting.width = 768;
setting.height = 1024;
return setting;
}
+ (ResolutionSetting*) settingIPad3Landscape
{
ResolutionSetting* setting = [self settingIPad];
setting.name = @"iPad3 Landscape";
setting.width = 2048;
setting.height = 1536;
setting.scale = setting.scale * 2;
return setting;
}
+ (ResolutionSetting*) settingIPad3Portrait
{
ResolutionSetting* setting = [self settingIPad];
setting.name = @"iPad3 Portrait";
setting.width = 1536;
setting.height = 2048;
setting.scale = setting.scale * 2;
return setting;
}
+ (ResolutionSetting*) settingAndroidXSmall
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"Android X-Small";
setting.width = 0;
setting.height = 0;
setting.ext = @"xsmall";
setting.scale = 240.0f / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingAndroidXSmallLandscape
{
ResolutionSetting* setting = [self settingAndroidXSmall];
setting.name = @"Android X-Small Landscape";
setting.width = 320;
setting.height = 240;
return setting;
}
+ (ResolutionSetting*) settingAndroidXSmallPortrait
{
ResolutionSetting* setting = [self settingAndroidXSmall];
setting.name = @"Android X-Small Portrait";
setting.width = 240;
setting.height = 320;
return setting;
}
+ (ResolutionSetting*) settingAndroidSmall
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"Android Small";
setting.width = 0;
setting.height = 0;
setting.ext = @"small";
setting.scale = 340.0f / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingAndroidSmallLandscape
{
ResolutionSetting* setting = [self settingAndroidSmall];
setting.name = @"Android Small Landscape";
setting.width = 480;
setting.height = 340;
return setting;
}
+ (ResolutionSetting*) settingAndroidSmallPortrait
{
ResolutionSetting* setting = [self settingAndroidSmall];
setting.name = @"Android Small Portrait";
setting.width = 340;
setting.height = 480;
return setting;
}
+ (ResolutionSetting*) settingAndroidMedium
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"Android Medium";
setting.width = 0;
setting.height = 0;
setting.ext = @"medium";
setting.scale = 480.0f / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingAndroidMediumLandscape
{
ResolutionSetting* setting = [self settingAndroidMedium];
setting.name = @"Android Medium Landscape";
setting.width = 800;
setting.height = 480;
return setting;
}
+ (ResolutionSetting*) settingAndroidMediumPortrait
{
ResolutionSetting* setting = [self settingAndroidMedium];
setting.name = @"Android Medium Portrait";
setting.width = 480;
setting.height = 800;
return setting;
}
+ (ResolutionSetting*) settingAndroidLarge
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"Android Large";
setting.width = 0;
setting.height = 0;
setting.ext = @"large";
setting.scale = 800.0f / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingAndroidLargeLandscape
{
ResolutionSetting* setting = [self settingAndroidLarge];
setting.name = @"Android Large Landscape";
setting.width = 1280;
setting.height = 800;
return setting;
}
+ (ResolutionSetting*) settingAndroidLargePortrait
{
ResolutionSetting* setting = [self settingAndroidLarge];
setting.name = @"Android Large Portrait";
setting.width = 800;
setting.height = 1280;
return setting;
}
+ (ResolutionSetting*) settingAndroidXLarge
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"Android X-Large";
setting.width = 0;
setting.height = 0;
setting.ext = @"xlarge";
setting.scale = 1536.0f / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingAndroidXLargeLandscape
{
ResolutionSetting* setting = [self settingAndroidXLarge];
setting.name = @"Android X-Large Landscape";
setting.width = 2048;
setting.height = 1536;
return setting;
}
+ (ResolutionSetting*) settingAndroidXLargePortrait
{
ResolutionSetting* setting = [self settingAndroidXLarge];
setting.name = @"Android X-Large Portrait";
setting.width = 1536;
setting.height = 2048;
return setting;
}
+ (ResolutionSetting*) settingHTML5
{
ResolutionSetting* setting = [[[ResolutionSetting alloc] init] autorelease];
setting.name = @"HTML 5";
setting.width = 0;
setting.height = 0;
setting.ext = @"html5";
setting.scale = 768.0f / DESIGN_HEIGHT;
return setting;
}
+ (ResolutionSetting*) settingHTML5Landscape
{
ResolutionSetting* setting = [self settingHTML5];
setting.name = @"HTML 5 Landscape";
setting.width = 1024;
setting.height = 768;
return setting;
}
+ (ResolutionSetting*) settingHTML5Portrait
{
ResolutionSetting* setting = [self settingHTML5];
setting.name = @"HTML 5 Portrait";
setting.width = 768;
setting.height = 1024;
return setting;
}
- (NSString *) description
{
return [NSString stringWithFormat:@"%@ <0x%x> (%d x %d)", NSStringFromClass([self class]), (unsigned int)self, width, height];
}
- (id) copyWithZone:(NSZone*)zone
{
ResolutionSetting* copy = [[ResolutionSetting alloc] init];
copy.enabled = enabled;
copy.name = name;
copy.width = width;
copy.height = height;
copy.ext = ext;
copy.scale = scale;
copy.centeredOrigin = centeredOrigin;
return copy;
}
@end