Don't run the game loop while a messagebox is up
authorSam Lantinga <slouken@libsdl.org>
Sun, 25 Nov 2012 10:03:22 -0800
changeset 6686 45014250760c
parent 6685 8faee8f46165
child 6687 d229ad942c89
Don't run the game loop while a messagebox is up
src/video/uikit/SDL_uikitmessagebox.h
src/video/uikit/SDL_uikitmessagebox.m
src/video/uikit/SDL_uikitopenglview.m
--- a/src/video/uikit/SDL_uikitmessagebox.h	Mon Jul 23 00:14:07 2012 -0400
+++ b/src/video/uikit/SDL_uikitmessagebox.h	Sun Nov 25 10:03:22 2012 -0800
@@ -22,6 +22,8 @@
 
 #if SDL_VIDEO_DRIVER_UIKIT
 
+extern SDL_bool UIKit_ShowingMessageBox();
+
 extern int UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
 
 #endif /* SDL_VIDEO_DRIVER_UIKIT */
--- a/src/video/uikit/SDL_uikitmessagebox.m	Mon Jul 23 00:14:07 2012 -0400
+++ b/src/video/uikit/SDL_uikitmessagebox.m	Sun Nov 25 10:03:22 2012 -0800
@@ -28,6 +28,7 @@
 
 /* Display a UIKit message box */
 
+static SDL_bool s_showingMessageBox = SDL_FALSE;
 
 @interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate> {
 @private
@@ -60,6 +61,12 @@
 @end // UIKit_UIAlertViewDelegate
 
 
+SDL_bool
+UIKit_ShowingMessageBox()
+{
+    return s_showingMessageBox;
+}
+
 int
 UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
 {
@@ -86,9 +93,12 @@
     
     // Run the main event loop until the alert has finished
     // Note that this needs to be done on the main thread
+    s_showingMessageBox = SDL_TRUE;
     while (clicked == messageboxdata->numbuttons) {
         [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
     }
+    s_showingMessageBox = SDL_FALSE;
+
     *buttonid = messageboxdata->buttons[clicked].buttonid;
 
     [pool release];
--- a/src/video/uikit/SDL_uikitopenglview.m	Mon Jul 23 00:14:07 2012 -0400
+++ b/src/video/uikit/SDL_uikitopenglview.m	Sun Nov 25 10:03:22 2012 -0800
@@ -22,9 +22,10 @@
 
 #if SDL_VIDEO_DRIVER_UIKIT
 
-#import <QuartzCore/QuartzCore.h>
-#import <OpenGLES/EAGLDrawable.h>
-#import "SDL_uikitopenglview.h"
+#include <QuartzCore/QuartzCore.h>
+#include <OpenGLES/EAGLDrawable.h>
+#include "SDL_uikitopenglview.h"
+#include "SDL_uikitmessagebox.h"
 
 
 @implementation SDL_uikitopenglview
@@ -180,7 +181,10 @@
 
 - (void)doLoop:(id)sender
 {
-    animationCallback(animationCallbackParam);
+    // Don't run the game loop while a messagebox is up
+    if (!UIKit_ShowingMessageBox()) {
+        animationCallback(animationCallbackParam);
+    }
 }
 
 - (void)setCurrentContext