Skip to content
Permalink
Browse files

Updated the iOS backend code to use Objective-C's automatic reference…

… counting (ARC).
  • Loading branch information
slime73 committed Aug 6, 2014
1 parent 3628997 commit f5543f93b3f75c11f3a40bb4a9a7411caa9b1db7
@@ -1274,8 +1274,14 @@
FD6526640DE8FCCB002AD96B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
COPY_PHASE_STRIP = NO;
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
PRODUCT_NAME = SDL2;
SKIP_INSTALL = YES;
};
@@ -1284,8 +1290,14 @@
FD6526650DE8FCCB002AD96B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
COPY_PHASE_STRIP = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
PRODUCT_NAME = SDL2;
SKIP_INSTALL = YES;
};
@@ -209,19 +209,19 @@ struct SDL_SysWMinfo
struct
{
#if defined(__OBJC__) && __has_feature(objc_arc)
NSWindow __unsafe_unretained *window; /* The Cocoa window */
NSWindow * __unsafe_unretained window; /* The Cocoa window */
#else
NSWindow *window; /* The Cocoa window */
NSWindow *window; /* The Cocoa window */
#endif
} cocoa;
#endif
#if defined(SDL_VIDEO_DRIVER_UIKIT)
struct
{
#if defined(__OBJC__) && __has_feature(objc_arc)
UIWindow __unsafe_unretained *window; /* The UIKit window */
UIWindow * __unsafe_unretained window; /* The UIKit window */
#else
UIWindow *window; /* The UIKit window */
UIWindow *window; /* The UIKit window */
#endif
} uikit;
#endif
@@ -50,8 +50,7 @@
NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
if([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
}
else {
} else {
fp = fopen(file, mode);
}
}
@@ -176,10 +176,7 @@ static void SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
SDL_SYS_JoystickQuit(void)
{
@autoreleasepool {
if (motionManager != nil) {
[motionManager release];
motionManager = nil;
}
motionManager = nil;
}

numjoysticks = 0;
@@ -56,7 +56,7 @@ int main(int argc, char **argv)

/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
@autoreleasepool {
UIApplicationMain(argc, argv, NULL, [SDLUIKitDelegate getAppDelegateClassName]);
UIApplicationMain(argc, argv, nil, [SDLUIKitDelegate getAppDelegateClassName]);
}

/* free the memory we used to hold copies of argc and argv */
@@ -94,26 +94,20 @@ - (id)init
return nil;
}

self->splash = [[UIImageView alloc] init];
[self setView:self->splash];
splash = [[UIImageView alloc] init];
self.view = splash;

CGSize size = [UIScreen mainScreen].bounds.size;
float height = SDL_max(size.width, size.height);
self->splashPortrait = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%dh.png", (int)height]];
if (!self->splashPortrait) {
self->splashPortrait = [UIImage imageNamed:@"Default.png"];
splashPortrait = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%dh.png", (int)height]];
if (!splashPortrait) {
splashPortrait = [UIImage imageNamed:@"Default.png"];
}
self->splashLandscape = [UIImage imageNamed:@"Default-Landscape.png"];
if (!self->splashLandscape && self->splashPortrait) {
self->splashLandscape = [[UIImage alloc] initWithCGImage: self->splashPortrait.CGImage
scale: 1.0
orientation: UIImageOrientationRight];
}
if (self->splashPortrait) {
[self->splashPortrait retain];
}
if (self->splashLandscape) {
[self->splashLandscape retain];
splashLandscape = [UIImage imageNamed:@"Default-Landscape.png"];
if (!splashLandscape && splashPortrait) {
splashLandscape = [[UIImage alloc] initWithCGImage: splashPortrait.CGImage
scale: 1.0
orientation: UIImageOrientationRight];
}

[self updateSplashImage:[[UIApplication sharedApplication] statusBarOrientation]];
@@ -148,9 +142,9 @@ - (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation
UIImage *image;

if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
image = self->splashLandscape;
image = splashLandscape;
} else {
image = self->splashPortrait;
image = splashPortrait;
}

if (image) {
@@ -192,8 +186,7 @@ - (void)postFinishLaunch

/* If we showed a splash image, clean it up */
if (launch_window) {
[launch_window release];
launch_window = NULL;
launch_window = nil;
}

/* exit, passing the return status from the user's application */
@@ -76,13 +76,14 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)

@autoreleasepool {
UIAlertView* alert = [[UIAlertView alloc] init];
UIKit_UIAlertViewDelegate *delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];

alert.title = @(messageboxdata->title);
alert.message = @(messageboxdata->message);
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
alert.delegate = delegate;

for (i = 0; i < messageboxdata->numbuttons; ++i) {
[alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
[alert addButtonWithTitle:@(buttons[i].text)];
}

/* Set up for showing the alert */
@@ -100,8 +101,7 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)

*buttonid = messageboxdata->buttons[clicked].buttonid;

[alert.delegate release];
[alert release];
alert.delegate = nil;
}

return 0;
@@ -25,15 +25,17 @@

#include "SDL_uikitvideo.h"

typedef struct
{
UIScreen *uiscreen;
} SDL_DisplayData;

typedef struct
{
UIScreenMode *uiscreenmode;
} SDL_DisplayModeData;
@interface SDL_DisplayData : NSObject

@property (nonatomic, strong) UIScreen *uiscreen;

@end

@interface SDL_DisplayModeData : NSObject

@property (nonatomic, strong) UIScreenMode *uiscreenmode;

@end

extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen);

@@ -25,25 +25,36 @@
#include "SDL_assert.h"
#include "SDL_uikitmodes.h"

@implementation SDL_DisplayData

@synthesize uiscreen;

@end

@implementation SDL_DisplayModeData

@synthesize uiscreenmode;

@end


static int
UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
UIScreenMode * uiscreenmode)
{
SDL_DisplayModeData *data = NULL;
SDL_DisplayModeData *data = nil;

if (uiscreenmode != nil) {
/* Allocate the display mode data */
data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
data = [[SDL_DisplayModeData alloc] init];
if (!data) {
return SDL_OutOfMemory();
}

data->uiscreenmode = uiscreenmode;
[data->uiscreenmode retain];
data.uiscreenmode = uiscreenmode;
}

mode->driverdata = data;
mode->driverdata = (void *) CFBridgingRetain(data);

return 0;
}
@@ -52,9 +63,7 @@
UIKit_FreeDisplayModeData(SDL_DisplayMode * mode)
{
if (mode->driverdata != NULL) {
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
[data->uiscreenmode release];
SDL_free(data);
CFRelease(mode->driverdata);
mode->driverdata = NULL;
}
}
@@ -130,18 +139,18 @@
display.current_mode = mode;

/* Allocate the display data */
SDL_DisplayData *data = (SDL_DisplayData *) SDL_malloc(sizeof(*data));
SDL_DisplayData *data = [[SDL_DisplayData alloc] init];
if (!data) {
UIKit_FreeDisplayModeData(&display.desktop_mode);
return SDL_OutOfMemory();
}

[uiscreen retain];
data->uiscreen = uiscreen;
data.uiscreen = uiscreen;

display.driverdata = data;
display.driverdata = (void *) CFBridgingRetain(data);
SDL_AddVideoDisplay(&display);


return 0;
}

@@ -173,14 +182,14 @@
void
UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;

@autoreleasepool {
SDL_bool isLandscape = UIKit_IsDisplayLandscape(data->uiscreen);
SDL_bool addRotation = (data->uiscreen == [UIScreen mainScreen]);
CGFloat scale = data->uiscreen.scale;
SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;

SDL_bool isLandscape = UIKit_IsDisplayLandscape(data.uiscreen);
SDL_bool addRotation = (data.uiscreen == [UIScreen mainScreen]);
CGFloat scale = data.uiscreen.scale;

for (UIScreenMode *uimode in [data->uiscreen availableModes]) {
for (UIScreenMode *uimode in [data.uiscreen availableModes]) {
/* The size of a UIScreenMode is in pixels, but we deal exclusively in
* points (except in SDL_GL_GetDrawableSize.) */
CGSize size = [uimode size];
@@ -203,19 +212,19 @@
int
UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;

@autoreleasepool {
[data->uiscreen setCurrentMode:modedata->uiscreenmode];
SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)mode->driverdata;

[data.uiscreen setCurrentMode:modedata.uiscreenmode];

if (data->uiscreen == [UIScreen mainScreen]) {
if (data.uiscreen == [UIScreen mainScreen]) {
if (mode->w > mode->h) {
if (!UIKit_IsDisplayLandscape(data->uiscreen)) {
if (!UIKit_IsDisplayLandscape(data.uiscreen)) {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
}
} else if (mode->w < mode->h) {
if (UIKit_IsDisplayLandscape(data->uiscreen)) {
if (UIKit_IsDisplayLandscape(data.uiscreen)) {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
}
@@ -240,10 +249,10 @@
UIKit_FreeDisplayModeData(mode);
}

SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
[data->uiscreen release];
SDL_free(data);
display->driverdata = NULL;
if (display->driverdata != NULL) {
CFRelease(display->driverdata);
display->driverdata = NULL;
}
}
}
}

0 comments on commit f5543f9

Please sign in to comment.