21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_UIKIT
34 UIKit_ShowingMessageBox(
void)
36 return s_showingMessageBox;
40 UIKit_WaitUntilMessageBoxClosed(
const SDL_MessageBoxData *messageboxdata,
int *clickedindex)
48 while ((*clickedindex) == messageboxdata->
numbuttons) {
49 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
56 UIKit_ShowMessageBoxAlertController(
const SDL_MessageBoxData *messageboxdata,
int *buttonid)
59 int __block clickedindex = messageboxdata->
numbuttons;
62 UIWindow *alertwindow = nil;
64 if (![UIAlertController
class]) {
68 UIAlertController *alert;
69 alert = [UIAlertController alertControllerWithTitle:@(messageboxdata->title)
70 message:@(messageboxdata->message)
71 preferredStyle:UIAlertControllerStyleAlert];
74 UIAlertAction *action;
75 UIAlertActionStyle style = UIAlertActionStyleDefault;
78 style = UIAlertActionStyleCancel;
81 action = [UIAlertAction actionWithTitle:@(buttons[i].text)
83 handler:^(UIAlertAction *action) {
86 [alert addAction:action];
89 if (messageboxdata->
window) {
90 SDL_WindowData *data = (__bridge SDL_WindowData *) messageboxdata->window->driverdata;
91 window = data.uiwindow;
95 alertwindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
96 alertwindow.rootViewController = [UIViewController new];
97 alertwindow.windowLevel = UIWindowLevelAlert;
101 [alertwindow makeKeyAndVisible];
104 [
window.rootViewController presentViewController:alert animated:YES completion:nil];
105 UIKit_WaitUntilMessageBoxClosed(messageboxdata, &clickedindex);
108 alertwindow.hidden = YES;
118 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
119 @interface SDLAlertViewDelegate : NSObject <UIAlertViewDelegate>
121 @property (nonatomic, assign)
int *clickedIndex;
125 @implementation SDLAlertViewDelegate
127 - (
void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
129 if (_clickedIndex !=
NULL) {
130 *_clickedIndex = (int) buttonIndex;
138 UIKit_ShowMessageBoxAlertView(
const SDL_MessageBoxData *messageboxdata,
int *buttonid)
141 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
143 int clickedindex = messageboxdata->
numbuttons;
145 UIAlertView *alert = [[UIAlertView alloc] init];
146 SDLAlertViewDelegate *delegate = [[SDLAlertViewDelegate alloc] init];
148 alert.delegate = delegate;
149 alert.title = @(messageboxdata->
title);
150 alert.message = @(messageboxdata->
message);
153 [alert addButtonWithTitle:@(buttons[i].text)];
156 delegate.clickedIndex = &clickedindex;
160 UIKit_WaitUntilMessageBoxClosed(messageboxdata, &clickedindex);
162 alert.delegate = nil;
177 success = UIKit_ShowMessageBoxAlertController(messageboxdata, buttonid);
179 success = UIKit_ShowMessageBoxAlertView(messageboxdata, buttonid);