From 03f8528315fa46c95991a34f3325d7b33ae5538c Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Sat, 02 May 2020 21:48:36 +0000
Subject: [PATCH] Update source to SDL2 2.0.12

---
 source/src/video/uikit/SDL_uikitmessagebox.m |   49 ++++++++++++++++++++++++++-----------------------
 1 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/source/src/video/uikit/SDL_uikitmessagebox.m b/source/src/video/uikit/SDL_uikitmessagebox.m
index cf2a8f3..d5c0309 100644
--- a/source/src/video/uikit/SDL_uikitmessagebox.m
+++ b/source/src/video/uikit/SDL_uikitmessagebox.m
@@ -1,6 +1,6 @@
 /*
   Simple DirectMedia Layer
-  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2020 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
@@ -55,10 +55,8 @@
 static BOOL
 UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messageboxdata, int *buttonid)
 {
-#ifdef __IPHONE_8_0
     int i;
     int __block clickedindex = messageboxdata->numbuttons;
-    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
     UIWindow *window = nil;
     UIWindow *alertwindow = nil;
 
@@ -74,17 +72,28 @@
     for (i = 0; i < messageboxdata->numbuttons; i++) {
         UIAlertAction *action;
         UIAlertActionStyle style = UIAlertActionStyleDefault;
+        const SDL_MessageBoxButtonData *sdlButton;
 
-        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
+        if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
+            sdlButton = &messageboxdata->buttons[messageboxdata->numbuttons - 1 - i];
+        } else {
+            sdlButton = &messageboxdata->buttons[i];
+        }
+
+        if (sdlButton->flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
             style = UIAlertActionStyleCancel;
         }
 
-        action = [UIAlertAction actionWithTitle:@(buttons[i].text)
+        action = [UIAlertAction actionWithTitle:@(sdlButton->text)
                                           style:style
                                         handler:^(UIAlertAction *action) {
-                                            clickedindex = i;
+				                            clickedindex = (int)(sdlButton - messageboxdata->buttons);
                                         }];
         [alert addAction:action];
+
+        if (sdlButton->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
+            alert.preferredAction = action;
+        }
     }
 
     if (messageboxdata->window) {
@@ -109,25 +118,10 @@
         alertwindow.hidden = YES;
     }
 
-#if !TARGET_OS_TV
-    /* Force the main SDL window to re-evaluate home indicator state */
-    SDL_Window *focus = SDL_GetFocusWindow();
-    if (focus) {
-        SDL_WindowData *data = (__bridge SDL_WindowData *) focus->driverdata;
-        if (data != nil) {
-            if (@available(iOS 11.0, *)) {
-                [data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfHomeIndicatorAutoHidden) withObject:nil waitUntilDone:NO];
-                [data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfScreenEdgesDeferringSystemGestures) withObject:nil waitUntilDone:NO];
-            }
-        }
-    }
-#endif /* !TARGET_OS_TV */
+    UIKit_ForceUpdateHomeIndicator();
 
     *buttonid = messageboxdata->buttons[clickedindex].buttonid;
     return YES;
-#else
-    return NO;
-#endif /* __IPHONE_8_0 */
 }
 
 /* UIAlertView is deprecated in iOS 8+ in favor of UIAlertController. */
@@ -166,7 +160,13 @@
     alert.message = @(messageboxdata->message);
 
     for (i = 0; i < messageboxdata->numbuttons; i++) {
-        [alert addButtonWithTitle:@(buttons[i].text)];
+        const SDL_MessageBoxButtonData *sdlButton;
+        if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
+            sdlButton = &messageboxdata->buttons[messageboxdata->numbuttons - 1 - i];
+        } else {
+            sdlButton = &messageboxdata->buttons[i];
+        }
+        [alert addButtonWithTitle:@(sdlButton->text)];
     }
 
     delegate.clickedIndex = &clickedindex;
@@ -177,6 +177,9 @@
 
     alert.delegate = nil;
 
+	if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
+		clickedindex = messageboxdata->numbuttons - 1 - clickedindex;
+	}
     *buttonid = messageboxdata->buttons[clickedindex].buttonid;
     return YES;
 #else

--
Gitblit v1.9.3