[Commits] SDL: Added support for mixing Qt and SDL on iOS

libsdl.org revision control commits-owner at libsdl.org
Tue May 9 10:10:51 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/b2a06697db74
changeset: 10995:b2a06697db74
user:      Sam Lantinga <slouken at libsdl.org>
date:      Tue May 09 10:10:42 2017 -0700
description:
Added support for mixing Qt and SDL on iOS

You should call SDL_SetMainReady(), and then customize the QIOSApplicationDelegate like this, in your application code:

/* Additional support for applications mixing Qt and SDL */
@interface QIOSApplicationDelegate : UIResponder <UIApplicationDelegate>
@end

extern "C"
{
void SDL_OnApplicationWillResignActive();
void SDL_OnApplicationDidEnterBackground();
void SDL_OnApplicationWillEnterForeground();
void SDL_OnApplicationDidBecomeActive();
}

@interface QIOSApplicationDelegate (SDL)

- (void)applicationWillResignActive:(UIApplication*)application;
- (void)applicationDidEnterBackground:(UIApplication*)application;
- (void)applicationWillEnterForeground:(UIApplication*)application;
- (void)applicationDidBecomeActive:(UIApplication*)application;

@end

@implementation QIOSApplicationDelegate (SDL)

- (void)applicationWillResignActive:(UIApplication*)application
{
    SDL_OnApplicationWillResignActive();
}

- (void)applicationDidEnterBackground:(UIApplication*)application
{
    SDL_OnApplicationDidEnterBackground();
}

- (void)applicationWillEnterForeground:(UIApplication*)application
{
    SDL_OnApplicationWillEnterForeground();
}

- (void)applicationDidBecomeActive:(UIApplication*)application
{
    SDL_OnApplicationDidBecomeActive();
}

@end // QIOSApplicationDelegate

diffstat:

 src/video/SDL_sysvideo.h               |   7 +++++
 src/video/SDL_video.c                  |  47 ++++++++++++++++++++++++++++++++++
 src/video/uikit/SDL_uikitappdelegate.m |  45 ++++++++++----------------------
 3 files changed, 68 insertions(+), 31 deletions(-)

diffs (148 lines):

diff -r 50ffb2b7ee1c -r b2a06697db74 src/video/SDL_sysvideo.h
--- a/src/video/SDL_sysvideo.h	Sun May 07 21:02:46 2017 +0200
+++ b/src/video/SDL_sysvideo.h	Tue May 09 10:10:42 2017 -0700
@@ -418,6 +418,13 @@
 
 extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
 
+extern void SDL_OnApplicationWillTerminate();
+extern void SDL_OnApplicationDidReceiveMemoryWarning();
+extern void SDL_OnApplicationWillResignActive();
+extern void SDL_OnApplicationDidEnterBackground();
+extern void SDL_OnApplicationWillEnterForeground();
+extern void SDL_OnApplicationDidBecomeActive();
+
 #endif /* SDL_sysvideo_h_ */
 
 /* vi: set ts=4 sw=4 expandtab: */
diff -r 50ffb2b7ee1c -r b2a06697db74 src/video/SDL_video.c
--- a/src/video/SDL_video.c	Sun May 07 21:02:46 2017 +0200
+++ b/src/video/SDL_video.c	Tue May 09 10:10:42 2017 -0700
@@ -3857,4 +3857,51 @@
 				   SDL_sqrt((double)den2));
 }
 
+void SDL_OnApplicationWillTerminate()
+{
+    SDL_SendAppEvent(SDL_APP_TERMINATING);
+}
+
+void SDL_OnApplicationDidReceiveMemoryWarning()
+{
+    SDL_SendAppEvent(SDL_APP_LOWMEMORY);
+}
+
+void SDL_OnApplicationWillResignActive()
+{
+    SDL_VideoDevice *_this = SDL_GetVideoDevice();
+    if (_this) {
+        SDL_Window *window;
+        for (window = _this->windows; window != NULL; window = window->next) {
+            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
+            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+        }
+    }
+    SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
+}
+
+void SDL_OnApplicationDidEnterBackground()
+{
+    SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
+}
+
+void SDL_OnApplicationWillEnterForeground()
+{
+    SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
+}
+
+void SDL_OnApplicationDidBecomeActive()
+{
+    SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
+
+    SDL_VideoDevice *_this = SDL_GetVideoDevice();
+    if (_this) {
+        SDL_Window *window;
+        for (window = _this->windows; window != NULL; window = window->next) {
+            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
+            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+        }
+    }
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
diff -r 50ffb2b7ee1c -r b2a06697db74 src/video/uikit/SDL_uikitappdelegate.m
--- a/src/video/uikit/SDL_uikitappdelegate.m	Sun May 07 21:02:46 2017 +0200
+++ b/src/video/uikit/SDL_uikitappdelegate.m	Tue May 09 10:10:42 2017 -0700
@@ -442,16 +442,6 @@
     /* Do nothing. */
 }
 
-- (void)applicationWillTerminate:(UIApplication *)application
-{
-    SDL_SendAppEvent(SDL_APP_TERMINATING);
-}
-
-- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
-{
-    SDL_SendAppEvent(SDL_APP_LOWMEMORY);
-}
-
 #if !TARGET_OS_TV
 - (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
 {
@@ -482,41 +472,34 @@
 }
 #endif
 
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+    SDL_OnApplicationWillTerminate();
+}
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
+{
+    SDL_OnApplicationDidReceiveMemoryWarning();
+}
+
 - (void)applicationWillResignActive:(UIApplication*)application
 {
-    SDL_VideoDevice *_this = SDL_GetVideoDevice();
-    if (_this) {
-        SDL_Window *window;
-        for (window = _this->windows; window != NULL; window = window->next) {
-            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
-            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
-        }
-    }
-    SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
+    SDL_OnApplicationWillResignActive();
 }
 
 - (void)applicationDidEnterBackground:(UIApplication*)application
 {
-    SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
+    SDL_OnApplicationDidEnterBackground();
 }
 
 - (void)applicationWillEnterForeground:(UIApplication*)application
 {
-    SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
+    SDL_OnApplicationWillEnterForeground();
 }
 
 - (void)applicationDidBecomeActive:(UIApplication*)application
 {
-    SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
-
-    SDL_VideoDevice *_this = SDL_GetVideoDevice();
-    if (_this) {
-        SDL_Window *window;
-        for (window = _this->windows; window != nil; window = window->next) {
-            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
-            SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
-        }
-    }
+    SDL_OnApplicationDidBecomeActive();
 }
 
 - (void)sendDropFileForURL:(NSURL *)url


More information about the commits mailing list