Commit 315893bf authored by Kees Bakker's avatar Kees Bakker

Split off SDL_uikitviewcontroller in its own module

--HG--
extra : rebase_source : 9f436d0751280968fb49307fb522b0d6c72d4409
parent cfa202c1
......@@ -127,6 +127,8 @@
56EA86FC13E9EC2B002E47EB /* SDL_coreaudio.h in Headers */ = {isa = PBXBuildFile; fileRef = 56EA86FA13E9EC2B002E47EB /* SDL_coreaudio.h */; };
56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */; };
93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */; };
FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
FD3F495C0DEA5B2100C5B771 /* begin_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CC0DD52EB400FB1D6B /* begin_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
FD3F495D0DEA5B2100C5B771 /* close_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CD0DD52EB400FB1D6B /* close_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -382,6 +384,8 @@
56EA86FA13E9EC2B002E47EB /* SDL_coreaudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_coreaudio.h; path = coreaudio/SDL_coreaudio.h; sourceTree = "<group>"; };
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; };
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; };
93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitviewcontroller.h; sourceTree = "<group>"; };
93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitviewcontroller.m; sourceTree = "<group>"; };
FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; };
FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitkeyboard.h; sourceTree = "<group>"; };
FD3F4A700DEA620800C5B771 /* SDL_getenv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_getenv.c; sourceTree = "<group>"; };
......@@ -868,6 +872,8 @@
FD689F170E26E5D900F90B21 /* SDL_uikitopenglview.m */,
FD689FCD0E26E9D400F90B21 /* SDL_uikitappdelegate.h */,
FD689FCC0E26E9D400F90B21 /* SDL_uikitappdelegate.m */,
93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */,
93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */,
);
path = uikit;
sourceTree = "<group>";
......@@ -1245,6 +1251,7 @@
0417A516130C988500578583 /* SDL_keycode.h in Headers */,
22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */,
56EA86FC13E9EC2B002E47EB /* SDL_coreaudio.h in Headers */,
93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1474,6 +1481,7 @@
0402A85912FE70C600CECEE3 /* SDL_shaders_gles2.c in Sources */,
04BAC09D1300C1290055DE28 /* SDL_log.c in Sources */,
56EA86FB13E9EC2B002E47EB /* SDL_coreaudio.c in Sources */,
93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -22,6 +22,7 @@
#import <UIKit/UIKit.h>
#include "SDL_stdinc.h"
#include "SDL_events.h"
#import "SDL_uikitviewcontroller.h"
#define IPHONE_TOUCH_EFFICIENT_DANGEROUS
#define FIXED_MULTITOUCH
......@@ -30,16 +31,6 @@
#define MAX_SIMULTANEOUS_TOUCHES 5
#endif
@interface SDL_uikitviewcontroller : UIViewController {
@private
SDL_Window *window;
}
- (id)initWithSDLWindow:(SDL_Window *)_window;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
- (void)loadView;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
@end
/* *INDENT-OFF* */
#if SDL_IPHONE_KEYBOARD
@interface SDL_uikitview : UIView<UITextFieldDelegate> {
......
/*
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#import <UIKit/UIKit.h>
#include "SDL_video.h"
@interface SDL_uikitviewcontroller : UIViewController {
@private
SDL_Window *window;
}
- (id)initWithSDLWindow:(SDL_Window *)_window;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient;
- (void)loadView;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
@end
/*
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
#include "SDL_video.h"
#include "SDL_assert.h"
#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_events_c.h"
#include "SDL_uikitwindow.h"
#import "SDL_uikitviewcontroller.h"
@implementation SDL_uikitviewcontroller
- (id)initWithSDLWindow:(SDL_Window *)_window {
if ((self = [self init]) == nil) {
return nil;
}
self->window = _window;
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
const char *orientationsCString;
if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
BOOL rotate = NO;
NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
encoding:NSUTF8StringEncoding];
NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@" "]];
switch (orient) {
case UIInterfaceOrientationLandscapeLeft:
rotate = [orientations containsObject:@"LandscapeLeft"];
break;
case UIInterfaceOrientationLandscapeRight:
rotate = [orientations containsObject:@"LandscapeRight"];
break;
case UIInterfaceOrientationPortrait:
rotate = [orientations containsObject:@"Portrait"];
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotate = [orientations containsObject:@"PortraitUpsideDown"];
break;
default: break;
}
return rotate;
}
if (self->window->flags & SDL_WINDOW_RESIZABLE) {
return YES; // any orientation is okay.
}
// If not resizable, allow device to orient to other matching sizes
// (that is, let the user turn the device upside down...same screen
// dimensions, but it lets the user place the device where it's most
// comfortable in relation to its physical buttons, headphone jack, etc).
switch (orient) {
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
return (self->window->w >= self->window->h);
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
return (self->window->h >= self->window->w);
default: break;
}
return NO; // Nothing else is acceptable.
}
- (void)loadView {
// do nothing.
}
// Send a resized event when the orientation changes.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ((self->window->flags & SDL_WINDOW_RESIZABLE) == 0) {
return; // don't care, we're just flipping over in this case.
}
const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
SDL_WindowData *data = self->window->driverdata;
UIWindow *uiwindow = data->uiwindow;
UIScreen *uiscreen = [uiwindow screen];
const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
const CGSize size = frame.size;
int w, h;
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
w = (size.width < size.height) ? size.width : size.height;
h = (size.width > size.height) ? size.width : size.height;
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
w = (size.width > size.height) ? size.width : size.height;
h = (size.width < size.height) ? size.width : size.height;
break;
default:
SDL_assert(0 && "Unexpected interface orientation!");
return;
}
frame.size.width = w;
frame.size.height = h;
frame.origin.x = 0;
frame.origin.y = 0;
[uiwindow setFrame:frame];
[data->view updateFrame];
SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
}
@end
......@@ -38,119 +38,6 @@
#include <Foundation/Foundation.h>
@implementation SDL_uikitviewcontroller
- (id)initWithSDLWindow:(SDL_Window *)_window {
if ((self = [self init]) == nil) {
return nil;
}
self->window = _window;
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
const char *orientationsCString;
if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
BOOL rotate = NO;
NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
encoding:NSUTF8StringEncoding];
NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@" "]];
switch (orient) {
case UIInterfaceOrientationLandscapeLeft:
rotate = [orientations containsObject:@"LandscapeLeft"];
break;
case UIInterfaceOrientationLandscapeRight:
rotate = [orientations containsObject:@"LandscapeRight"];
break;
case UIInterfaceOrientationPortrait:
rotate = [orientations containsObject:@"Portrait"];
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotate = [orientations containsObject:@"PortraitUpsideDown"];
break;
default: break;
}
return rotate;
}
if (self->window->flags & SDL_WINDOW_RESIZABLE) {
return YES; // any orientation is okay.
}
// If not resizable, allow device to orient to other matching sizes
// (that is, let the user turn the device upside down...same screen
// dimensions, but it lets the user place the device where it's most
// comfortable in relation to its physical buttons, headphone jack, etc).
switch (orient) {
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
return (self->window->w >= self->window->h);
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
return (self->window->h >= self->window->w);
default: break;
}
return NO; // Nothing else is acceptable.
}
- (void)loadView {
// do nothing.
}
// Send a resized event when the orientation changes.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ((self->window->flags & SDL_WINDOW_RESIZABLE) == 0) {
return; // don't care, we're just flipping over in this case.
}
const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
SDL_WindowData *data = self->window->driverdata;
UIWindow *uiwindow = data->uiwindow;
UIScreen *uiscreen = [uiwindow screen];
const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
const CGSize size = frame.size;
int w, h;
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
w = (size.width < size.height) ? size.width : size.height;
h = (size.width > size.height) ? size.width : size.height;
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
w = (size.width > size.height) ? size.width : size.height;
h = (size.width < size.height) ? size.width : size.height;
break;
default:
SDL_assert(0 && "Unexpected interface orientation!");
return;
}
frame.size.width = w;
frame.size.height = h;
frame.origin.x = 0;
frame.origin.y = 0;
[uiwindow setFrame:frame];
[data->view updateFrame];
SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
}
@end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment