mirror of https://github.com/encounter/SDL.git
Minor Objective-C code tweaks.
This commit is contained in:
parent
6df55c6608
commit
bc4b6f061b
|
@ -58,7 +58,8 @@ UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
void
|
||||||
|
UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
||||||
|
@ -157,16 +158,15 @@ UIKit_GL_CreateContext(_THIS, SDL_Window * window)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
view.sdlwindow = window;
|
||||||
data.view = view;
|
data.view = view;
|
||||||
view.viewcontroller = data.viewcontroller;
|
data.viewcontroller.view = view;
|
||||||
if (view.viewcontroller != nil) {
|
|
||||||
view.viewcontroller.view = view;
|
|
||||||
}
|
|
||||||
[uiwindow addSubview:view];
|
|
||||||
|
|
||||||
/* The view controller needs to be the root in order to control rotation on iOS 6.0 */
|
/* The view controller needs to be the root in order to control rotation */
|
||||||
if (uiwindow.rootViewController == nil) {
|
if (uiwindow.rootViewController == nil) {
|
||||||
uiwindow.rootViewController = view.viewcontroller;
|
uiwindow.rootViewController = data.viewcontroller;
|
||||||
|
} else {
|
||||||
|
[uiwindow addSubview:view];
|
||||||
}
|
}
|
||||||
|
|
||||||
EAGLContext *context = view.context;
|
EAGLContext *context = view.context;
|
||||||
|
@ -199,17 +199,17 @@ UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
|
||||||
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
|
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
|
||||||
SDL_uikitopenglview *view = data.view;
|
SDL_uikitopenglview *view = data.view;
|
||||||
if (view.context == eaglcontext) {
|
if (view.context == eaglcontext) {
|
||||||
/* the delegate has retained the view, this will release him */
|
/* the view controller has retained the view */
|
||||||
if (view.viewcontroller) {
|
if (data.viewcontroller) {
|
||||||
UIWindow *uiwindow = (UIWindow *)view.superview;
|
UIWindow *uiwindow = (UIWindow *)view.superview;
|
||||||
if (uiwindow.rootViewController == view.viewcontroller) {
|
if (uiwindow.rootViewController == data.viewcontroller) {
|
||||||
uiwindow.rootViewController = nil;
|
uiwindow.rootViewController = nil;
|
||||||
}
|
}
|
||||||
view.viewcontroller.view = nil;
|
data.viewcontroller.view = nil;
|
||||||
view.viewcontroller = nil;
|
|
||||||
}
|
}
|
||||||
[view removeFromSuperview];
|
|
||||||
|
|
||||||
|
[view removeFromSuperview];
|
||||||
|
view.sdlwindow = NULL;
|
||||||
data.view = nil;
|
data.view = nil;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,8 @@ UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SDL_iPhoneGetViewRenderbuffer(SDL_Window * window)
|
Uint32
|
||||||
|
SDL_iPhoneGetViewRenderbuffer(SDL_Window * window)
|
||||||
{
|
{
|
||||||
if (!window) {
|
if (!window) {
|
||||||
SDL_SetError("Invalid window");
|
SDL_SetError("Invalid window");
|
||||||
|
@ -234,7 +235,8 @@ Uint32 SDL_iPhoneGetViewRenderbuffer(SDL_Window * window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 SDL_iPhoneGetViewFramebuffer(SDL_Window * window)
|
Uint32
|
||||||
|
SDL_iPhoneGetViewFramebuffer(SDL_Window * window)
|
||||||
{
|
{
|
||||||
if (!window) {
|
if (!window) {
|
||||||
SDL_SetError("Invalid window");
|
SDL_SetError("Invalid window");
|
||||||
|
|
|
@ -46,7 +46,6 @@
|
||||||
int animationInterval;
|
int animationInterval;
|
||||||
void (*animationCallback)(void*);
|
void (*animationCallback)(void*);
|
||||||
void *animationCallbackParam;
|
void *animationCallbackParam;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@synthesize context;
|
@synthesize context;
|
||||||
|
|
|
@ -75,6 +75,7 @@ UIKit_CreateDevice(int devindex)
|
||||||
device->SetDisplayMode = UIKit_SetDisplayMode;
|
device->SetDisplayMode = UIKit_SetDisplayMode;
|
||||||
device->PumpEvents = UIKit_PumpEvents;
|
device->PumpEvents = UIKit_PumpEvents;
|
||||||
device->CreateWindow = UIKit_CreateWindow;
|
device->CreateWindow = UIKit_CreateWindow;
|
||||||
|
device->SetWindowTitle = UIKit_SetWindowTitle;
|
||||||
device->ShowWindow = UIKit_ShowWindow;
|
device->ShowWindow = UIKit_ShowWindow;
|
||||||
device->HideWindow = UIKit_HideWindow;
|
device->HideWindow = UIKit_HideWindow;
|
||||||
device->RaiseWindow = UIKit_RaiseWindow;
|
device->RaiseWindow = UIKit_RaiseWindow;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import "SDL_uikitviewcontroller.h"
|
#include "../SDL_sysvideo.h"
|
||||||
|
|
||||||
#include "SDL_touch.h"
|
#include "SDL_touch.h"
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
@interface SDL_uikitview : UIView
|
@interface SDL_uikitview : UIView
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@property (nonatomic, weak) SDL_uikitviewcontroller *viewcontroller;
|
@property (nonatomic, assign) SDL_Window *sdlwindow;
|
||||||
|
|
||||||
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
|
- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@synthesize viewcontroller;
|
@synthesize sdlwindow;
|
||||||
|
|
||||||
- (id)initWithFrame:(CGRect)frame
|
- (id)initWithFrame:(CGRect)frame
|
||||||
{
|
{
|
||||||
|
@ -92,10 +92,10 @@
|
||||||
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(sdlwindow, 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(sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||||
|
|
||||||
leftFingerDown = touch;
|
leftFingerDown = touch;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
for (UITouch *touch in touches) {
|
for (UITouch *touch in touches) {
|
||||||
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(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||||
leftFingerDown = nil;
|
leftFingerDown = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
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(sdlwindow, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
||||||
|
|
|
@ -73,11 +73,7 @@
|
||||||
|
|
||||||
- (BOOL)prefersStatusBarHidden
|
- (BOOL)prefersStatusBarHidden
|
||||||
{
|
{
|
||||||
if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
|
return (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0;
|
||||||
return YES;
|
|
||||||
} else {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIStatusBarStyle)preferredStatusBarStyle
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#import "SDL_uikitviewcontroller.h"
|
#import "SDL_uikitviewcontroller.h"
|
||||||
|
|
||||||
extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
|
extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
|
||||||
|
extern void UIKit_SetWindowTitle(_THIS, SDL_Window * window);
|
||||||
extern void UIKit_ShowWindow(_THIS, SDL_Window * window);
|
extern void UIKit_ShowWindow(_THIS, SDL_Window * window);
|
||||||
extern void UIKit_HideWindow(_THIS, SDL_Window * window);
|
extern void UIKit_HideWindow(_THIS, SDL_Window * window);
|
||||||
extern void UIKit_RaiseWindow(_THIS, SDL_Window * window);
|
extern void UIKit_RaiseWindow(_THIS, SDL_Window * window);
|
||||||
|
|
|
@ -55,7 +55,6 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
|
||||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||||
SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
|
SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
|
||||||
|
|
||||||
/* Allocate the window data */
|
|
||||||
SDL_WindowData *data = [[SDL_WindowData alloc] init];
|
SDL_WindowData *data = [[SDL_WindowData alloc] init];
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
|
@ -67,7 +66,6 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
|
||||||
{
|
{
|
||||||
CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
|
CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
|
||||||
|
|
||||||
/* Get frame dimensions */
|
|
||||||
int width = (int) frame.size.width;
|
int width = (int) frame.size.width;
|
||||||
int height = (int) frame.size.height;
|
int height = (int) frame.size.height;
|
||||||
|
|
||||||
|
@ -114,7 +112,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
|
||||||
* appropriate.
|
* appropriate.
|
||||||
*/
|
*/
|
||||||
data.viewcontroller = [[SDL_uikitviewcontroller alloc] initWithSDLWindow:window];
|
data.viewcontroller = [[SDL_uikitviewcontroller alloc] initWithSDLWindow:window];
|
||||||
data.viewcontroller.title = @"SDL App"; /* !!! FIXME: hook up SDL_SetWindowTitle() */
|
data.viewcontroller.title = @"";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -186,11 +184,9 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
|
||||||
} else {
|
} else {
|
||||||
if (!(orientations & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown))) {
|
if (!(orientations & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown))) {
|
||||||
UIInterfaceOrientation orient = UIInterfaceOrientationLandscapeLeft;
|
UIInterfaceOrientation orient = UIInterfaceOrientationLandscapeLeft;
|
||||||
|
|
||||||
if (orientations & UIInterfaceOrientationMaskLandscapeRight) {
|
if (orientations & UIInterfaceOrientationMaskLandscapeRight) {
|
||||||
orient = UIInterfaceOrientationLandscapeRight;
|
orient = UIInterfaceOrientationLandscapeRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
[app setStatusBarOrientation:orient animated:NO];
|
[app setStatusBarOrientation:orient animated:NO];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,12 +208,24 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
|
||||||
if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
|
if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UIKit_SetWindowTitle(_THIS, SDL_Window * window)
|
||||||
|
{
|
||||||
|
@autoreleasepool {
|
||||||
|
SDL_uikitviewcontroller *vc = ((__bridge SDL_WindowData *) window->driverdata).viewcontroller;
|
||||||
|
if (window->title) {
|
||||||
|
vc.title = @(window->title);
|
||||||
|
} else {
|
||||||
|
vc.title = @"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UIKit_ShowWindow(_THIS, SDL_Window * window)
|
UIKit_ShowWindow(_THIS, SDL_Window * window)
|
||||||
{
|
{
|
||||||
|
@ -275,16 +283,16 @@ UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
|
||||||
[windowdata.view layoutIfNeeded];
|
[windowdata.view layoutIfNeeded];
|
||||||
|
|
||||||
/* Get frame dimensions */
|
/* Get frame dimensions */
|
||||||
int width = (int) frame.size.width;
|
int w = (int) frame.size.width;
|
||||||
int height = (int) frame.size.height;
|
int h = (int) frame.size.height;
|
||||||
|
|
||||||
/* We can pick either width or height here and we'll rotate the
|
/* We can pick either width or height here and we'll rotate the
|
||||||
screen to match, so we pick the closest to what we wanted.
|
screen to match, so we pick the closest to what we wanted.
|
||||||
*/
|
*/
|
||||||
if (window->w >= window->h) {
|
if (window->w >= window->h) {
|
||||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_max(width, height), SDL_min(width, height));
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_max(w, h), SDL_min(w, h));
|
||||||
} else {
|
} else {
|
||||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_min(width, height), SDL_max(width, height));
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_min(w, h), SDL_max(w, h));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +320,6 @@ UIKit_DestroyWindow(_THIS, SDL_Window * window)
|
||||||
CFRelease(window->driverdata);
|
CFRelease(window->driverdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window->driverdata = NULL;
|
window->driverdata = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue