mirror of https://github.com/encounter/SDL.git
Misc. iOS code improvements.
- Use @autoreleasepool instead of NSAutoReleasePool. - Code style fixups.
This commit is contained in:
parent
96b613eab3
commit
734b523302
|
@ -8,6 +8,9 @@ Makefile
|
||||||
sdl-config
|
sdl-config
|
||||||
SDL2.spec
|
SDL2.spec
|
||||||
build
|
build
|
||||||
|
Build
|
||||||
|
*xcuserdata*
|
||||||
|
*xcworkspacedata*
|
||||||
|
|
||||||
# for Xcode
|
# for Xcode
|
||||||
*.orig
|
*.orig
|
||||||
|
|
|
@ -208,13 +208,21 @@ struct SDL_SysWMinfo
|
||||||
#if defined(SDL_VIDEO_DRIVER_COCOA)
|
#if defined(SDL_VIDEO_DRIVER_COCOA)
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
#if defined(__OBJC__) && __has_feature(objc_arc)
|
||||||
|
NSWindow __unsafe_unretained *window; /* The Cocoa window */
|
||||||
|
#else
|
||||||
NSWindow *window; /* The Cocoa window */
|
NSWindow *window; /* The Cocoa window */
|
||||||
|
#endif
|
||||||
} cocoa;
|
} cocoa;
|
||||||
#endif
|
#endif
|
||||||
#if defined(SDL_VIDEO_DRIVER_UIKIT)
|
#if defined(SDL_VIDEO_DRIVER_UIKIT)
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
#if defined(__OBJC__) && __has_feature(objc_arc)
|
||||||
|
UIWindow __unsafe_unretained *window; /* The UIKit window */
|
||||||
|
#else
|
||||||
UIWindow *window; /* The UIKit window */
|
UIWindow *window; /* The UIKit window */
|
||||||
|
#endif
|
||||||
} uikit;
|
} uikit;
|
||||||
#endif
|
#endif
|
||||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
|
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
|
||||||
|
|
|
@ -41,9 +41,7 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
|
||||||
return fopen(file, mode);
|
return fopen(file, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
|
@autoreleasepool {
|
||||||
|
|
||||||
|
|
||||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||||
NSString* resource_path = [[NSBundle mainBundle] resourcePath];
|
NSString* resource_path = [[NSBundle mainBundle] resourcePath];
|
||||||
|
|
||||||
|
@ -56,12 +54,11 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
|
||||||
else {
|
else {
|
||||||
fp = fopen(file, mode);
|
fp = fopen(file, mode);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
[autorelease_pool drain];
|
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __MACOSX__ */
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -36,11 +36,12 @@
|
||||||
char *
|
char *
|
||||||
SDL_GetBasePath(void)
|
SDL_GetBasePath(void)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
char *retval = NULL;
|
||||||
|
|
||||||
|
@autoreleasepool {
|
||||||
|
const char *base = NULL;
|
||||||
NSBundle *bundle = [NSBundle mainBundle];
|
NSBundle *bundle = [NSBundle mainBundle];
|
||||||
const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
|
const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
|
||||||
const char *base = NULL;
|
|
||||||
char *retval = NULL;
|
|
||||||
if (baseType == NULL) {
|
if (baseType == NULL) {
|
||||||
baseType = "resource";
|
baseType = "resource";
|
||||||
}
|
}
|
||||||
|
@ -52,6 +53,7 @@ SDL_GetBasePath(void)
|
||||||
/* this returns the exedir for non-bundled and the resourceDir for bundled apps */
|
/* this returns the exedir for non-bundled and the resourceDir for bundled apps */
|
||||||
base = [[bundle resourcePath] fileSystemRepresentation];
|
base = [[bundle resourcePath] fileSystemRepresentation];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base) {
|
if (base) {
|
||||||
const size_t len = SDL_strlen(base) + 2;
|
const size_t len = SDL_strlen(base) + 2;
|
||||||
retval = (char *) SDL_malloc(len);
|
retval = (char *) SDL_malloc(len);
|
||||||
|
@ -61,18 +63,19 @@ SDL_GetBasePath(void)
|
||||||
SDL_snprintf(retval, len, "%s/", base);
|
SDL_snprintf(retval, len, "%s/", base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[pool release];
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
SDL_GetPrefPath(const char *org, const char *app)
|
SDL_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
|
|
||||||
|
@autoreleasepool {
|
||||||
|
NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||||
|
|
||||||
if ([array count] > 0) { /* we only want the first item in the list. */
|
if ([array count] > 0) { /* we only want the first item in the list. */
|
||||||
NSString *str = [array objectAtIndex:0];
|
NSString *str = [array objectAtIndex:0];
|
||||||
const char *base = [str fileSystemRepresentation];
|
const char *base = [str fileSystemRepresentation];
|
||||||
|
@ -95,8 +98,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
[pool release];
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ static UIWindow *launch_window;
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
|
|
||||||
/* store arguments */
|
/* store arguments */
|
||||||
forward_argc = argc;
|
forward_argc = argc;
|
||||||
|
@ -56,7 +55,9 @@ int main(int argc, char **argv)
|
||||||
forward_argv[i] = NULL;
|
forward_argv[i] = NULL;
|
||||||
|
|
||||||
/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
|
/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
|
||||||
|
@autoreleasepool {
|
||||||
UIApplicationMain(argc, argv, NULL, [SDLUIKitDelegate getAppDelegateClassName]);
|
UIApplicationMain(argc, argv, NULL, [SDLUIKitDelegate getAppDelegateClassName]);
|
||||||
|
}
|
||||||
|
|
||||||
/* free the memory we used to hold copies of argc and argv */
|
/* free the memory we used to hold copies of argc and argv */
|
||||||
for (i = 0; i < forward_argc; i++) {
|
for (i = 0; i < forward_argc; i++) {
|
||||||
|
@ -64,7 +65,6 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
free(forward_argv);
|
free(forward_argv);
|
||||||
|
|
||||||
[pool release];
|
|
||||||
return exit_status;
|
return exit_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,8 +151,8 @@ SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldVa
|
||||||
} else {
|
} else {
|
||||||
image = self->splashPortrait;
|
image = self->splashPortrait;
|
||||||
}
|
}
|
||||||
if (image)
|
|
||||||
{
|
if (image) {
|
||||||
splash.image = image;
|
splash.image = image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldVa
|
||||||
/* convenience method */
|
/* convenience method */
|
||||||
+ (id) sharedAppDelegate
|
+ (id) sharedAppDelegate
|
||||||
{
|
{
|
||||||
/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
|
/* the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method */
|
||||||
return [[UIApplication sharedApplication] delegate];
|
return [[UIApplication sharedApplication] delegate];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,9 @@ SDL_iPhoneSetEventPump(SDL_bool enabled)
|
||||||
void
|
void
|
||||||
UIKit_PumpEvents(_THIS)
|
UIKit_PumpEvents(_THIS)
|
||||||
{
|
{
|
||||||
if (!UIKit_EventPumpEnabled)
|
if (!UIKit_EventPumpEnabled) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Let the run loop run for a short amount of time: long enough for
|
/* Let the run loop run for a short amount of time: long enough for
|
||||||
touch events to get processed (which is important to get certain
|
touch events to get processed (which is important to get certain
|
||||||
|
|
|
@ -71,17 +71,16 @@ int
|
||||||
UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||||
{
|
{
|
||||||
int clicked;
|
int clicked;
|
||||||
|
int i;
|
||||||
|
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||||
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
@autoreleasepool {
|
||||||
|
|
||||||
UIAlertView* alert = [[UIAlertView alloc] init];
|
UIAlertView* alert = [[UIAlertView alloc] init];
|
||||||
|
|
||||||
alert.title = [NSString stringWithUTF8String:messageboxdata->title];
|
alert.title = [NSString stringWithUTF8String:messageboxdata->title];
|
||||||
alert.message = [NSString stringWithUTF8String:messageboxdata->message];
|
alert.message = [NSString stringWithUTF8String:messageboxdata->message];
|
||||||
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
|
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
|
||||||
|
|
||||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
||||||
[alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
|
[alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
|
||||||
}
|
}
|
||||||
|
@ -103,8 +102,7 @@ UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||||
|
|
||||||
[alert.delegate release];
|
[alert.delegate release];
|
||||||
[alert release];
|
[alert release];
|
||||||
|
}
|
||||||
[pool release];
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ void _uikit_keyboard_init() ;
|
||||||
CGPoint point = [touch locationInView: self];
|
CGPoint point = [touch locationInView: self];
|
||||||
|
|
||||||
/* Get the display scale and apply that to the input coordinates */
|
/* Get the display scale and apply that to the input coordinates */
|
||||||
SDL_Window *window = self->viewcontroller.window;
|
SDL_Window *window = viewcontroller.window;
|
||||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||||
SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
|
SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
|
||||||
|
|
||||||
|
@ -83,18 +83,15 @@ void _uikit_keyboard_init() ;
|
||||||
|
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
for (UITouch *touch in touches) {
|
||||||
UITouch *touch = (UITouch*)[enumerator nextObject];
|
|
||||||
|
|
||||||
while (touch) {
|
|
||||||
if (!leftFingerDown) {
|
if (!leftFingerDown) {
|
||||||
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
||||||
|
|
||||||
/* send moved event */
|
/* send moved event */
|
||||||
SDL_SendMouseMotion(self->viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
SDL_SendMouseMotion(viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
||||||
|
|
||||||
/* send mouse down event */
|
/* send mouse down event */
|
||||||
SDL_SendMouseButton(self->viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
SDL_SendMouseButton(viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||||
|
|
||||||
leftFingerDown = touch;
|
leftFingerDown = touch;
|
||||||
}
|
}
|
||||||
|
@ -118,19 +115,15 @@ void _uikit_keyboard_init() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
touch = (UITouch*)[enumerator nextObject];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
for (UITouch *touch in touches) {
|
||||||
UITouch *touch = (UITouch*)[enumerator nextObject];
|
|
||||||
|
|
||||||
while(touch) {
|
|
||||||
if (touch == leftFingerDown) {
|
if (touch == leftFingerDown) {
|
||||||
/* send mouse up */
|
/* send mouse up */
|
||||||
SDL_SendMouseButton(self->viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
SDL_SendMouseButton(viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||||
leftFingerDown = nil;
|
leftFingerDown = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +142,6 @@ void _uikit_keyboard_init() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
touch = (UITouch*)[enumerator nextObject];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,15 +157,12 @@ void _uikit_keyboard_init() ;
|
||||||
|
|
||||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
for (UITouch *touch in touches) {
|
||||||
UITouch *touch = (UITouch*)[enumerator nextObject];
|
|
||||||
|
|
||||||
while (touch) {
|
|
||||||
if (touch == leftFingerDown) {
|
if (touch == leftFingerDown) {
|
||||||
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
||||||
|
|
||||||
/* send moved event */
|
/* send moved event */
|
||||||
SDL_SendMouseMotion(self->viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
SDL_SendMouseMotion(viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
||||||
|
@ -190,7 +179,6 @@ void _uikit_keyboard_init() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
touch = (UITouch*)[enumerator nextObject];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue