2011-08-17 23:26:58 +02:00
|
|
|
/*
|
2011-10-31 05:56:58 -04:00
|
|
|
Simple DirectMedia Layer
|
2017-01-01 18:33:28 -08:00
|
|
|
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
|
2011-10-31 05:56:58 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-24 23:56:17 -05:00
|
|
|
#include "../../SDL_internal.h"
|
2011-08-17 23:26:58 +02:00
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#if SDL_VIDEO_DRIVER_UIKIT
|
|
|
|
|
2011-08-17 23:26:58 +02:00
|
|
|
#include "SDL_video.h"
|
|
|
|
#include "SDL_assert.h"
|
|
|
|
#include "SDL_hints.h"
|
|
|
|
#include "../SDL_sysvideo.h"
|
|
|
|
#include "../../events/SDL_events_c.h"
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
#import "SDL_uikitviewcontroller.h"
|
|
|
|
#import "SDL_uikitmessagebox.h"
|
2011-11-27 23:30:02 -05:00
|
|
|
#include "SDL_uikitvideo.h"
|
2012-09-29 17:23:40 -07:00
|
|
|
#include "SDL_uikitmodes.h"
|
|
|
|
#include "SDL_uikitwindow.h"
|
2016-04-02 13:21:01 -03:00
|
|
|
#include "SDL_uikitopengles.h"
|
2012-09-29 17:23:40 -07:00
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
#if SDL_IPHONE_KEYBOARD
|
|
|
|
#include "keyinfotable.h"
|
|
|
|
#endif
|
2011-08-17 23:26:58 +02:00
|
|
|
|
2016-09-13 22:18:06 -03:00
|
|
|
#if TARGET_OS_TV
|
2017-08-14 06:28:21 -07:00
|
|
|
static void SDLCALL
|
2016-09-13 22:18:06 -03:00
|
|
|
SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
|
|
|
|
viewcontroller.controllerUserInteractionEnabled = hint && (*hint != '0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
@implementation SDL_uikitviewcontroller {
|
|
|
|
CADisplayLink *displayLink;
|
|
|
|
int animationInterval;
|
|
|
|
void (*animationCallback)(void*);
|
|
|
|
void *animationCallbackParam;
|
|
|
|
|
|
|
|
#if SDL_IPHONE_KEYBOARD
|
|
|
|
UITextField *textField;
|
2016-12-02 02:21:35 -08:00
|
|
|
BOOL rotatingOrientation;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
#endif
|
|
|
|
}
|
2011-08-17 23:26:58 +02:00
|
|
|
|
2011-09-28 21:42:02 +02:00
|
|
|
@synthesize window;
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
- (instancetype)initWithSDLWindow:(SDL_Window *)_window
|
2011-09-27 22:51:26 +02:00
|
|
|
{
|
2014-07-29 00:05:48 -03:00
|
|
|
if (self = [super initWithNibName:nil bundle:nil]) {
|
|
|
|
self.window = _window;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
|
|
|
|
#if SDL_IPHONE_KEYBOARD
|
|
|
|
[self initKeyboard];
|
2016-12-02 02:21:35 -08:00
|
|
|
rotatingOrientation = FALSE;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
#endif
|
2016-09-13 22:18:06 -03:00
|
|
|
|
|
|
|
#if TARGET_OS_TV
|
|
|
|
SDL_AddHintCallback(SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS,
|
|
|
|
SDL_AppleTVControllerUIHintChanged,
|
|
|
|
(__bridge void *) self);
|
|
|
|
#endif
|
2011-08-17 23:26:58 +02:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
#if SDL_IPHONE_KEYBOARD
|
|
|
|
[self deinitKeyboard];
|
|
|
|
#endif
|
2016-09-13 22:18:06 -03:00
|
|
|
|
|
|
|
#if TARGET_OS_TV
|
|
|
|
SDL_DelHintCallback(SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS,
|
|
|
|
SDL_AppleTVControllerUIHintChanged,
|
|
|
|
(__bridge void *) self);
|
|
|
|
#endif
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAnimationCallback:(int)interval
|
|
|
|
callback:(void (*)(void*))callback
|
|
|
|
callbackParam:(void*)callbackParam
|
|
|
|
{
|
|
|
|
[self stopAnimation];
|
|
|
|
|
|
|
|
animationInterval = interval;
|
|
|
|
animationCallback = callback;
|
|
|
|
animationCallbackParam = callbackParam;
|
|
|
|
|
|
|
|
if (animationCallback) {
|
|
|
|
[self startAnimation];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startAnimation
|
|
|
|
{
|
|
|
|
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
|
2017-07-15 17:41:58 -03:00
|
|
|
|
|
|
|
#ifdef __IPHONE_10_3
|
|
|
|
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
|
|
|
|
|
|
|
|
if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)]
|
|
|
|
&& data != nil && data.uiwindow != nil
|
|
|
|
&& [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
|
|
|
|
displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300
|
|
|
|
[displayLink setFrameInterval:animationInterval];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopAnimation
|
|
|
|
{
|
|
|
|
[displayLink invalidate];
|
|
|
|
displayLink = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)doLoop:(CADisplayLink*)sender
|
|
|
|
{
|
|
|
|
/* Don't run the game loop while a messagebox is up */
|
|
|
|
if (!UIKit_ShowingMessageBox()) {
|
2016-04-02 13:21:01 -03:00
|
|
|
/* See the comment in the function definition. */
|
|
|
|
UIKit_GL_RestoreCurrentContext();
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
animationCallback(animationCallbackParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 23:13:35 -07:00
|
|
|
- (void)loadView
|
|
|
|
{
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
/* Do nothing. */
|
2012-09-18 23:13:35 -07:00
|
|
|
}
|
|
|
|
|
2012-09-23 03:46:49 -07:00
|
|
|
- (void)viewDidLayoutSubviews
|
2012-09-18 23:13:35 -07:00
|
|
|
{
|
2014-07-29 00:05:48 -03:00
|
|
|
const CGSize size = self.view.bounds.size;
|
2014-07-17 18:05:12 -03:00
|
|
|
int w = (int) size.width;
|
|
|
|
int h = (int) size.height;
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2014-07-17 18:05:12 -03:00
|
|
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
|
2012-09-18 23:13:35 -07:00
|
|
|
}
|
|
|
|
|
2016-09-13 22:18:06 -03:00
|
|
|
#if !TARGET_OS_TV
|
2012-09-23 03:46:49 -07:00
|
|
|
- (NSUInteger)supportedInterfaceOrientations
|
2011-09-27 22:51:26 +02:00
|
|
|
{
|
2014-11-20 17:19:26 -04:00
|
|
|
return UIKit_GetSupportedOrientations(window);
|
2011-08-17 23:26:58 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 17:41:58 -03:00
|
|
|
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
|
2012-09-23 03:46:49 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
|
2011-09-27 22:51:26 +02:00
|
|
|
{
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
return ([self supportedInterfaceOrientations] & (1 << orient)) != 0;
|
2011-08-17 23:26:58 +02:00
|
|
|
}
|
2017-07-15 17:41:58 -03:00
|
|
|
#endif
|
2011-08-17 23:26:58 +02:00
|
|
|
|
2013-10-20 23:05:53 -07:00
|
|
|
- (BOOL)prefersStatusBarHidden
|
|
|
|
{
|
2014-11-27 20:25:54 -04:00
|
|
|
return (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0;
|
2013-10-20 23:05:53 -07:00
|
|
|
}
|
2016-09-13 22:18:06 -03:00
|
|
|
#endif
|
2013-10-20 23:05:53 -07:00
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
/*
|
|
|
|
---- Keyboard related functionality below this line ----
|
|
|
|
*/
|
|
|
|
#if SDL_IPHONE_KEYBOARD
|
|
|
|
|
|
|
|
@synthesize textInputRect;
|
|
|
|
@synthesize keyboardHeight;
|
|
|
|
@synthesize keyboardVisible;
|
|
|
|
|
|
|
|
/* Set ourselves up as a UITextFieldDelegate */
|
|
|
|
- (void)initKeyboard
|
|
|
|
{
|
|
|
|
textField = [[UITextField alloc] initWithFrame:CGRectZero];
|
|
|
|
textField.delegate = self;
|
|
|
|
/* placeholder so there is something to delete! */
|
|
|
|
textField.text = @" ";
|
|
|
|
|
|
|
|
/* set UITextInputTrait properties, mostly to defaults */
|
|
|
|
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
|
|
|
|
textField.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
|
|
textField.enablesReturnKeyAutomatically = NO;
|
|
|
|
textField.keyboardAppearance = UIKeyboardAppearanceDefault;
|
|
|
|
textField.keyboardType = UIKeyboardTypeDefault;
|
|
|
|
textField.returnKeyType = UIReturnKeyDefault;
|
|
|
|
textField.secureTextEntry = NO;
|
|
|
|
|
|
|
|
textField.hidden = YES;
|
|
|
|
keyboardVisible = NO;
|
|
|
|
|
2016-09-13 22:18:06 -03:00
|
|
|
#if !TARGET_OS_TV
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
|
|
|
[center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
|
|
|
[center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
2016-09-13 22:18:06 -03:00
|
|
|
#endif
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setView:(UIView *)view
|
|
|
|
{
|
|
|
|
[super setView:view];
|
|
|
|
|
|
|
|
[view addSubview:textField];
|
|
|
|
|
|
|
|
if (keyboardVisible) {
|
|
|
|
[self showKeyboard];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 02:21:35 -08:00
|
|
|
/* willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation are deprecated in iOS 8+ in favor of viewWillTransitionToSize */
|
|
|
|
#if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
|
|
|
|
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
|
|
|
{
|
|
|
|
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
|
|
|
rotatingOrientation = TRUE;
|
|
|
|
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
|
|
|
|
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
|
|
|
rotatingOrientation = FALSE;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
|
|
|
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
|
|
|
|
rotatingOrientation = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
|
|
|
|
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
|
|
|
|
rotatingOrientation = FALSE;
|
|
|
|
}
|
|
|
|
#endif /* TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 */
|
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
- (void)deinitKeyboard
|
|
|
|
{
|
2016-09-13 22:18:06 -03:00
|
|
|
#if !TARGET_OS_TV
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
|
|
|
[center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
|
|
|
|
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
|
2016-09-13 22:18:06 -03:00
|
|
|
#endif
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reveal onscreen virtual keyboard */
|
|
|
|
- (void)showKeyboard
|
|
|
|
{
|
|
|
|
keyboardVisible = YES;
|
|
|
|
if (textField.window) {
|
|
|
|
[textField becomeFirstResponder];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hide onscreen virtual keyboard */
|
|
|
|
- (void)hideKeyboard
|
|
|
|
{
|
|
|
|
keyboardVisible = NO;
|
|
|
|
[textField resignFirstResponder];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyboardWillShow:(NSNotification *)notification
|
|
|
|
{
|
2016-09-13 22:18:06 -03:00
|
|
|
#if !TARGET_OS_TV
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
CGRect kbrect = [[notification userInfo][UIKeyboardFrameBeginUserInfoKey] CGRectValue];
|
|
|
|
|
2015-05-05 16:20:11 -03:00
|
|
|
/* The keyboard rect is in the coordinate space of the screen/window, but we
|
|
|
|
* want its height in the coordinate space of the view. */
|
|
|
|
kbrect = [self.view convertRect:kbrect fromView:nil];
|
|
|
|
|
|
|
|
[self setKeyboardHeight:(int)kbrect.size.height];
|
2016-09-13 22:18:06 -03:00
|
|
|
#endif
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyboardWillHide:(NSNotification *)notification
|
|
|
|
{
|
2017-08-18 23:23:30 -03:00
|
|
|
if (!rotatingOrientation) {
|
2016-12-02 02:21:35 -08:00
|
|
|
SDL_StopTextInput();
|
2017-08-18 23:23:30 -03:00
|
|
|
}
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
[self setKeyboardHeight:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateKeyboard
|
|
|
|
{
|
|
|
|
CGAffineTransform t = self.view.transform;
|
|
|
|
CGPoint offset = CGPointMake(0.0, 0.0);
|
2015-05-05 16:20:11 -03:00
|
|
|
CGRect frame = UIKit_ComputeViewFrame(window, self.view.window.screen);
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
|
|
|
|
if (self.keyboardHeight) {
|
2015-05-05 16:20:11 -03:00
|
|
|
int rectbottom = self.textInputRect.y + self.textInputRect.h;
|
|
|
|
int keybottom = self.view.bounds.size.height - self.keyboardHeight;
|
|
|
|
if (keybottom < rectbottom) {
|
|
|
|
offset.y = keybottom - rectbottom;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 16:20:11 -03:00
|
|
|
/* Apply this view's transform (except any translation) to the offset, in
|
|
|
|
* order to orient it correctly relative to the frame's coordinate space. */
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
t.tx = 0.0;
|
|
|
|
t.ty = 0.0;
|
|
|
|
offset = CGPointApplyAffineTransform(offset, t);
|
|
|
|
|
2015-05-05 16:20:11 -03:00
|
|
|
/* Apply the updated offset to the view's frame. */
|
|
|
|
frame.origin.x += offset.x;
|
|
|
|
frame.origin.y += offset.y;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
|
2015-05-05 16:20:11 -03:00
|
|
|
self.view.frame = frame;
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setKeyboardHeight:(int)height
|
|
|
|
{
|
|
|
|
keyboardVisible = height > 0;
|
|
|
|
keyboardHeight = height;
|
|
|
|
[self updateKeyboard];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UITextFieldDelegate method. Invoked when user types something. */
|
|
|
|
- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
|
|
|
{
|
|
|
|
NSUInteger len = string.length;
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
/* it wants to replace text with nothing, ie a delete */
|
|
|
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
|
|
|
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
|
|
|
|
} else {
|
|
|
|
/* go through all the characters in the string we've been sent and
|
|
|
|
* convert them to key presses */
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
unichar c = [string characterAtIndex:i];
|
|
|
|
Uint16 mod = 0;
|
|
|
|
SDL_Scancode code;
|
|
|
|
|
|
|
|
if (c < 127) {
|
|
|
|
/* figure out the SDL_Scancode and SDL_keymod for this unichar */
|
|
|
|
code = unicharToUIKeyInfoTable[c].code;
|
|
|
|
mod = unicharToUIKeyInfoTable[c].mod;
|
|
|
|
} else {
|
|
|
|
/* we only deal with ASCII right now */
|
|
|
|
code = SDL_SCANCODE_UNKNOWN;
|
|
|
|
mod = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mod & KMOD_SHIFT) {
|
|
|
|
/* If character uses shift, press shift down */
|
|
|
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send a keydown and keyup even for the character */
|
|
|
|
SDL_SendKeyboardKey(SDL_PRESSED, code);
|
|
|
|
SDL_SendKeyboardKey(SDL_RELEASED, code);
|
|
|
|
|
|
|
|
if (mod & KMOD_SHIFT) {
|
|
|
|
/* If character uses shift, press shift back up */
|
|
|
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_SendKeyboardText([string UTF8String]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO; /* don't allow the edit! (keep placeholder text there) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminates the editing session */
|
|
|
|
- (BOOL)textFieldShouldReturn:(UITextField*)_textField
|
|
|
|
{
|
|
|
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
|
|
|
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
|
|
|
|
SDL_StopTextInput();
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-08-17 23:26:58 +02:00
|
|
|
@end
|
2012-09-18 23:13:35 -07:00
|
|
|
|
Several improvements to the iOS backend:
- Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist.
The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior.
It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0.
- A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window.
- Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called.
- SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust.
- Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes.
- Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions.
- Some code style cleanup.
--HG--
branch : iOS-improvements
2015-01-15 01:06:14 -04:00
|
|
|
/* iPhone keyboard addition functions */
|
|
|
|
#if SDL_IPHONE_KEYBOARD
|
|
|
|
|
|
|
|
static SDL_uikitviewcontroller *
|
|
|
|
GetWindowViewController(SDL_Window * window)
|
|
|
|
{
|
|
|
|
if (!window || !window->driverdata) {
|
|
|
|
SDL_SetError("Invalid window");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
|
|
|
|
|
|
|
|
return data.viewcontroller;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_bool
|
|
|
|
UIKit_HasScreenKeyboardSupport(_THIS)
|
|
|
|
{
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
SDL_uikitviewcontroller *vc = GetWindowViewController(window);
|
|
|
|
[vc showKeyboard];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UIKit_HideScreenKeyboard(_THIS, SDL_Window *window)
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
SDL_uikitviewcontroller *vc = GetWindowViewController(window);
|
|
|
|
[vc hideKeyboard];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_bool
|
|
|
|
UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
SDL_uikitviewcontroller *vc = GetWindowViewController(window);
|
|
|
|
if (vc != nil) {
|
|
|
|
return vc.isKeyboardVisible;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
|
|
|
|
{
|
|
|
|
if (!rect) {
|
|
|
|
SDL_InvalidParamError("rect");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
@autoreleasepool {
|
|
|
|
SDL_uikitviewcontroller *vc = GetWindowViewController(SDL_GetFocusWindow());
|
|
|
|
if (vc != nil) {
|
|
|
|
vc.textInputRect = *rect;
|
|
|
|
|
|
|
|
if (vc.keyboardVisible) {
|
|
|
|
[vc updateKeyboard];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SDL_IPHONE_KEYBOARD */
|
|
|
|
|
2012-09-23 03:46:49 -07:00
|
|
|
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
|
|
|
|
2012-09-18 23:13:35 -07:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|