Split off SDL_uikitviewcontroller in its own module
authorKees Bakker <kees@tweeler.com>
Wed, 17 Aug 2011 23:26:58 +0200
changeset 564004b5b11985c8
parent 5638 198383360618
child 5641 7b94c53df15c
Split off SDL_uikitviewcontroller in its own module
Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitviewcontroller.h
src/video/uikit/SDL_uikitviewcontroller.m
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Tue Aug 23 03:12:27 2011 -0400
     1.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Wed Aug 17 23:26:58 2011 +0200
     1.3 @@ -127,6 +127,8 @@
     1.4  		56EA86FC13E9EC2B002E47EB /* SDL_coreaudio.h in Headers */ = {isa = PBXBuildFile; fileRef = 56EA86FA13E9EC2B002E47EB /* SDL_coreaudio.h */; };
     1.5  		56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
     1.6  		56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
     1.7 +		93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */; };
     1.8 +		93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */; };
     1.9  		FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
    1.10  		FD3F495C0DEA5B2100C5B771 /* begin_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CC0DD52EB400FB1D6B /* begin_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
    1.11  		FD3F495D0DEA5B2100C5B771 /* close_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CD0DD52EB400FB1D6B /* close_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
    1.12 @@ -382,6 +384,8 @@
    1.13  		56EA86FA13E9EC2B002E47EB /* SDL_coreaudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_coreaudio.h; path = coreaudio/SDL_coreaudio.h; sourceTree = "<group>"; };
    1.14  		56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_power.c; path = ../../src/power/SDL_power.c; sourceTree = SOURCE_ROOT; };
    1.15  		56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_syspower.m; path = ../../src/power/uikit/SDL_syspower.m; sourceTree = SOURCE_ROOT; };
    1.16 +		93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitviewcontroller.h; sourceTree = "<group>"; };
    1.17 +		93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitviewcontroller.m; sourceTree = "<group>"; };
    1.18  		FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; };
    1.19  		FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitkeyboard.h; sourceTree = "<group>"; };
    1.20  		FD3F4A700DEA620800C5B771 /* SDL_getenv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_getenv.c; sourceTree = "<group>"; };
    1.21 @@ -868,6 +872,8 @@
    1.22  				FD689F170E26E5D900F90B21 /* SDL_uikitopenglview.m */,
    1.23  				FD689FCD0E26E9D400F90B21 /* SDL_uikitappdelegate.h */,
    1.24  				FD689FCC0E26E9D400F90B21 /* SDL_uikitappdelegate.m */,
    1.25 +				93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */,
    1.26 +				93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */,
    1.27  			);
    1.28  			path = uikit;
    1.29  			sourceTree = "<group>";
    1.30 @@ -1245,6 +1251,7 @@
    1.31  				0417A516130C988500578583 /* SDL_keycode.h in Headers */,
    1.32  				22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */,
    1.33  				56EA86FC13E9EC2B002E47EB /* SDL_coreaudio.h in Headers */,
    1.34 +				93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */,
    1.35  			);
    1.36  			runOnlyForDeploymentPostprocessing = 0;
    1.37  		};
    1.38 @@ -1474,6 +1481,7 @@
    1.39  				0402A85912FE70C600CECEE3 /* SDL_shaders_gles2.c in Sources */,
    1.40  				04BAC09D1300C1290055DE28 /* SDL_log.c in Sources */,
    1.41  				56EA86FB13E9EC2B002E47EB /* SDL_coreaudio.c in Sources */,
    1.42 +				93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */,
    1.43  			);
    1.44  			runOnlyForDeploymentPostprocessing = 0;
    1.45  		};
     2.1 --- a/src/video/uikit/SDL_uikitview.h	Tue Aug 23 03:12:27 2011 -0400
     2.2 +++ b/src/video/uikit/SDL_uikitview.h	Wed Aug 17 23:26:58 2011 +0200
     2.3 @@ -22,6 +22,7 @@
     2.4  #import <UIKit/UIKit.h>
     2.5  #include "SDL_stdinc.h"
     2.6  #include "SDL_events.h"
     2.7 +#import "SDL_uikitviewcontroller.h"
     2.8  
     2.9  #define IPHONE_TOUCH_EFFICIENT_DANGEROUS
    2.10  #define FIXED_MULTITOUCH
    2.11 @@ -30,16 +31,6 @@
    2.12  #define MAX_SIMULTANEOUS_TOUCHES 5
    2.13  #endif
    2.14  
    2.15 -@interface SDL_uikitviewcontroller : UIViewController {
    2.16 -@private
    2.17 -    SDL_Window *window;
    2.18 -}
    2.19 -- (id)initWithSDLWindow:(SDL_Window *)_window;
    2.20 -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
    2.21 -- (void)loadView;
    2.22 -- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
    2.23 -@end
    2.24 -
    2.25  /* *INDENT-OFF* */
    2.26  #if SDL_IPHONE_KEYBOARD
    2.27  @interface SDL_uikitview : UIView<UITextFieldDelegate> {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.h	Wed Aug 17 23:26:58 2011 +0200
     3.3 @@ -0,0 +1,35 @@
     3.4 +/*
     3.5 + Simple DirectMedia Layer
     3.6 + Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3.7 + 
     3.8 + This software is provided 'as-is', without any express or implied
     3.9 + warranty.  In no event will the authors be held liable for any damages
    3.10 + arising from the use of this software.
    3.11 + 
    3.12 + Permission is granted to anyone to use this software for any purpose,
    3.13 + including commercial applications, and to alter it and redistribute it
    3.14 + freely, subject to the following restrictions:
    3.15 + 
    3.16 + 1. The origin of this software must not be misrepresented; you must not
    3.17 + claim that you wrote the original software. If you use this software
    3.18 + in a product, an acknowledgment in the product documentation would be
    3.19 + appreciated but is not required.
    3.20 + 2. Altered source versions must be plainly marked as such, and must not be
    3.21 + misrepresented as being the original software.
    3.22 + 3. This notice may not be removed or altered from any source distribution.
    3.23 + */
    3.24 +
    3.25 +#import <UIKit/UIKit.h>
    3.26 +
    3.27 +#include "SDL_video.h"
    3.28 +
    3.29 +
    3.30 +@interface SDL_uikitviewcontroller : UIViewController {
    3.31 +@private
    3.32 +    SDL_Window *window;
    3.33 +}
    3.34 +- (id)initWithSDLWindow:(SDL_Window *)_window;
    3.35 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
    3.36 +- (void)loadView;
    3.37 +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
    3.38 +@end
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Wed Aug 17 23:26:58 2011 +0200
     4.3 @@ -0,0 +1,146 @@
     4.4 +/*
     4.5 + Simple DirectMedia Layer
     4.6 + Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     4.7 + 
     4.8 + This software is provided 'as-is', without any express or implied
     4.9 + warranty.  In no event will the authors be held liable for any damages
    4.10 + arising from the use of this software.
    4.11 + 
    4.12 + Permission is granted to anyone to use this software for any purpose,
    4.13 + including commercial applications, and to alter it and redistribute it
    4.14 + freely, subject to the following restrictions:
    4.15 + 
    4.16 + 1. The origin of this software must not be misrepresented; you must not
    4.17 + claim that you wrote the original software. If you use this software
    4.18 + in a product, an acknowledgment in the product documentation would be
    4.19 + appreciated but is not required.
    4.20 + 2. Altered source versions must be plainly marked as such, and must not be
    4.21 + misrepresented as being the original software.
    4.22 + 3. This notice may not be removed or altered from any source distribution.
    4.23 + */
    4.24 +#include "SDL_config.h"
    4.25 +
    4.26 +#include "SDL_video.h"
    4.27 +#include "SDL_assert.h"
    4.28 +#include "SDL_hints.h"
    4.29 +#include "../SDL_sysvideo.h"
    4.30 +#include "../../events/SDL_events_c.h"
    4.31 +
    4.32 +#include "SDL_uikitwindow.h"
    4.33 +
    4.34 +#import "SDL_uikitviewcontroller.h"
    4.35 +
    4.36 +
    4.37 +@implementation SDL_uikitviewcontroller
    4.38 +
    4.39 +- (id)initWithSDLWindow:(SDL_Window *)_window {
    4.40 +    if ((self = [self init]) == nil) {
    4.41 +        return nil;
    4.42 +    }
    4.43 +    self->window = _window;
    4.44 +    return self;
    4.45 +}
    4.46 +
    4.47 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
    4.48 +    const char *orientationsCString;
    4.49 +    if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
    4.50 +        BOOL rotate = NO;
    4.51 +        NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
    4.52 +                                                            encoding:NSUTF8StringEncoding];
    4.53 +        NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
    4.54 +                                 [NSCharacterSet characterSetWithCharactersInString:@" "]];
    4.55 +        
    4.56 +        switch (orient) {
    4.57 +            case UIInterfaceOrientationLandscapeLeft:
    4.58 +                rotate = [orientations containsObject:@"LandscapeLeft"];
    4.59 +                break;
    4.60 +                
    4.61 +            case UIInterfaceOrientationLandscapeRight:
    4.62 +                rotate = [orientations containsObject:@"LandscapeRight"];
    4.63 +                break;
    4.64 +                
    4.65 +            case UIInterfaceOrientationPortrait:
    4.66 +                rotate = [orientations containsObject:@"Portrait"];
    4.67 +                break;
    4.68 +                
    4.69 +            case UIInterfaceOrientationPortraitUpsideDown:
    4.70 +                rotate = [orientations containsObject:@"PortraitUpsideDown"];
    4.71 +                break;
    4.72 +                
    4.73 +            default: break;
    4.74 +        }
    4.75 +        
    4.76 +        return rotate;
    4.77 +    }
    4.78 +    
    4.79 +    if (self->window->flags & SDL_WINDOW_RESIZABLE) {
    4.80 +        return YES;  // any orientation is okay.
    4.81 +    }
    4.82 +    
    4.83 +    // If not resizable, allow device to orient to other matching sizes
    4.84 +    //  (that is, let the user turn the device upside down...same screen
    4.85 +    //   dimensions, but it lets the user place the device where it's most
    4.86 +    //   comfortable in relation to its physical buttons, headphone jack, etc).
    4.87 +    switch (orient) {
    4.88 +        case UIInterfaceOrientationLandscapeLeft:
    4.89 +        case UIInterfaceOrientationLandscapeRight:
    4.90 +            return (self->window->w >= self->window->h);
    4.91 +            
    4.92 +        case UIInterfaceOrientationPortrait:
    4.93 +        case UIInterfaceOrientationPortraitUpsideDown:
    4.94 +            return (self->window->h >= self->window->w);
    4.95 +            
    4.96 +        default: break;
    4.97 +    }
    4.98 +    
    4.99 +    return NO;  // Nothing else is acceptable.
   4.100 +}
   4.101 +
   4.102 +- (void)loadView  {
   4.103 +    // do nothing.
   4.104 +}
   4.105 +
   4.106 +// Send a resized event when the orientation changes.
   4.107 +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
   4.108 +    if ((self->window->flags & SDL_WINDOW_RESIZABLE) == 0) {
   4.109 +        return;   // don't care, we're just flipping over in this case.
   4.110 +    }
   4.111 +    
   4.112 +    const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
   4.113 +    SDL_WindowData *data = self->window->driverdata;
   4.114 +    UIWindow *uiwindow = data->uiwindow;
   4.115 +    UIScreen *uiscreen = [uiwindow screen];
   4.116 +    const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
   4.117 +    CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
   4.118 +    const CGSize size = frame.size;
   4.119 +    int w, h;
   4.120 +    
   4.121 +    switch (toInterfaceOrientation) {
   4.122 +        case UIInterfaceOrientationPortrait:
   4.123 +        case UIInterfaceOrientationPortraitUpsideDown:
   4.124 +            w = (size.width < size.height) ? size.width : size.height;
   4.125 +            h = (size.width > size.height) ? size.width : size.height;
   4.126 +            break;
   4.127 +            
   4.128 +        case UIInterfaceOrientationLandscapeLeft:
   4.129 +        case UIInterfaceOrientationLandscapeRight:
   4.130 +            w = (size.width > size.height) ? size.width : size.height;
   4.131 +            h = (size.width < size.height) ? size.width : size.height;
   4.132 +            break;
   4.133 +            
   4.134 +        default:
   4.135 +            SDL_assert(0 && "Unexpected interface orientation!");
   4.136 +            return;
   4.137 +    }
   4.138 +    
   4.139 +    frame.size.width = w;
   4.140 +    frame.size.height = h;
   4.141 +    frame.origin.x = 0;
   4.142 +    frame.origin.y = 0;
   4.143 +    
   4.144 +    [uiwindow setFrame:frame];
   4.145 +    [data->view updateFrame];
   4.146 +    SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
   4.147 +}
   4.148 +
   4.149 +@end
     5.1 --- a/src/video/uikit/SDL_uikitwindow.m	Tue Aug 23 03:12:27 2011 -0400
     5.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Wed Aug 17 23:26:58 2011 +0200
     5.3 @@ -38,119 +38,6 @@
     5.4  
     5.5  #include <Foundation/Foundation.h>
     5.6  
     5.7 -@implementation SDL_uikitviewcontroller
     5.8 -
     5.9 -- (id)initWithSDLWindow:(SDL_Window *)_window {
    5.10 -    if ((self = [self init]) == nil) {
    5.11 -        return nil;
    5.12 -    }
    5.13 -    self->window = _window;
    5.14 -    return self;
    5.15 -}
    5.16 -
    5.17 -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
    5.18 -    const char *orientationsCString;
    5.19 -    if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
    5.20 -        BOOL rotate = NO;
    5.21 -        NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
    5.22 -                                                            encoding:NSUTF8StringEncoding];
    5.23 -        NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
    5.24 -                                 [NSCharacterSet characterSetWithCharactersInString:@" "]];
    5.25 -        
    5.26 -        switch (orient) {
    5.27 -            case UIInterfaceOrientationLandscapeLeft:
    5.28 -                rotate = [orientations containsObject:@"LandscapeLeft"];
    5.29 -                break;
    5.30 -                
    5.31 -            case UIInterfaceOrientationLandscapeRight:
    5.32 -                rotate = [orientations containsObject:@"LandscapeRight"];
    5.33 -                break;
    5.34 -                
    5.35 -            case UIInterfaceOrientationPortrait:
    5.36 -                rotate = [orientations containsObject:@"Portrait"];
    5.37 -                break;
    5.38 -                
    5.39 -            case UIInterfaceOrientationPortraitUpsideDown:
    5.40 -                rotate = [orientations containsObject:@"PortraitUpsideDown"];
    5.41 -                break;
    5.42 -                
    5.43 -            default: break;
    5.44 -        }
    5.45 -        
    5.46 -        return rotate;
    5.47 -    }
    5.48 -
    5.49 -    if (self->window->flags & SDL_WINDOW_RESIZABLE) {
    5.50 -        return YES;  // any orientation is okay.
    5.51 -    }
    5.52 -
    5.53 -    // If not resizable, allow device to orient to other matching sizes
    5.54 -    //  (that is, let the user turn the device upside down...same screen
    5.55 -    //   dimensions, but it lets the user place the device where it's most
    5.56 -    //   comfortable in relation to its physical buttons, headphone jack, etc).
    5.57 -    switch (orient) {
    5.58 -        case UIInterfaceOrientationLandscapeLeft:
    5.59 -        case UIInterfaceOrientationLandscapeRight:
    5.60 -            return (self->window->w >= self->window->h);
    5.61 -
    5.62 -        case UIInterfaceOrientationPortrait:
    5.63 -        case UIInterfaceOrientationPortraitUpsideDown:
    5.64 -            return (self->window->h >= self->window->w);
    5.65 -
    5.66 -        default: break;
    5.67 -    }
    5.68 -
    5.69 -    return NO;  // Nothing else is acceptable.
    5.70 -}
    5.71 -
    5.72 -- (void)loadView  {
    5.73 -    // do nothing.
    5.74 -}
    5.75 -
    5.76 -// Send a resized event when the orientation changes.
    5.77 -- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    5.78 -    if ((self->window->flags & SDL_WINDOW_RESIZABLE) == 0) {
    5.79 -        return;   // don't care, we're just flipping over in this case.
    5.80 -    }
    5.81 -
    5.82 -    const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
    5.83 -    SDL_WindowData *data = self->window->driverdata;
    5.84 -    UIWindow *uiwindow = data->uiwindow;
    5.85 -    UIScreen *uiscreen = [uiwindow screen];
    5.86 -    const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
    5.87 -    CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
    5.88 -    const CGSize size = frame.size;
    5.89 -    int w, h;
    5.90 -
    5.91 -    switch (toInterfaceOrientation) {
    5.92 -        case UIInterfaceOrientationPortrait:
    5.93 -        case UIInterfaceOrientationPortraitUpsideDown:
    5.94 -            w = (size.width < size.height) ? size.width : size.height;
    5.95 -            h = (size.width > size.height) ? size.width : size.height;
    5.96 -            break;
    5.97 -
    5.98 -        case UIInterfaceOrientationLandscapeLeft:
    5.99 -        case UIInterfaceOrientationLandscapeRight:
   5.100 -            w = (size.width > size.height) ? size.width : size.height;
   5.101 -            h = (size.width < size.height) ? size.width : size.height;
   5.102 -            break;
   5.103 -
   5.104 -        default:
   5.105 -            SDL_assert(0 && "Unexpected interface orientation!");
   5.106 -            return;
   5.107 -    }
   5.108 -
   5.109 -    frame.size.width = w;
   5.110 -    frame.size.height = h;
   5.111 -    frame.origin.x = 0;
   5.112 -    frame.origin.y = 0;
   5.113 -
   5.114 -    [uiwindow setFrame:frame];
   5.115 -    [data->view updateFrame];
   5.116 -    SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
   5.117 -}
   5.118 -
   5.119 -@end
   5.120  
   5.121  
   5.122