SDL  2.0
SDL_uikitmessagebox.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #if SDL_VIDEO_DRIVER_UIKIT
24 
25 #include "SDL.h"
26 #include "SDL_uikitvideo.h"
27 #include "SDL_uikitwindow.h"
28 
29 /* Display a UIKit message box */
30 
31 static SDL_bool s_showingMessageBox = SDL_FALSE;
32 
34 UIKit_ShowingMessageBox(void)
35 {
36  return s_showingMessageBox;
37 }
38 
39 static void
40 UIKit_WaitUntilMessageBoxClosed(const SDL_MessageBoxData *messageboxdata, int *clickedindex)
41 {
42  *clickedindex = messageboxdata->numbuttons;
43 
44  @autoreleasepool {
45  /* Run the main event loop until the alert has finished */
46  /* Note that this needs to be done on the main thread */
47  s_showingMessageBox = SDL_TRUE;
48  while ((*clickedindex) == messageboxdata->numbuttons) {
49  [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
50  }
51  s_showingMessageBox = SDL_FALSE;
52  }
53 }
54 
55 static BOOL
56 UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messageboxdata, int *buttonid)
57 {
58  int i;
59  int __block clickedindex = messageboxdata->numbuttons;
60  UIWindow *window = nil;
61  UIWindow *alertwindow = nil;
62 
63  if (![UIAlertController class]) {
64  return NO;
65  }
66 
67  UIAlertController *alert;
68  alert = [UIAlertController alertControllerWithTitle:@(messageboxdata->title)
69  message:@(messageboxdata->message)
70  preferredStyle:UIAlertControllerStyleAlert];
71 
72  for (i = 0; i < messageboxdata->numbuttons; i++) {
73  UIAlertAction *action;
74  UIAlertActionStyle style = UIAlertActionStyleDefault;
75  const SDL_MessageBoxButtonData *sdlButton;
76 
77  if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
78  sdlButton = &messageboxdata->buttons[messageboxdata->numbuttons - 1 - i];
79  } else {
80  sdlButton = &messageboxdata->buttons[i];
81  }
82 
84  style = UIAlertActionStyleCancel;
85  }
86 
87  action = [UIAlertAction actionWithTitle:@(sdlButton->text)
88  style:style
89  handler:^(UIAlertAction *action) {
90  clickedindex = (int)(sdlButton - messageboxdata->buttons);
91  }];
92  [alert addAction:action];
93 
95  alert.preferredAction = action;
96  }
97  }
98 
99  if (messageboxdata->window) {
100  SDL_WindowData *data = (__bridge SDL_WindowData *) messageboxdata->window->driverdata;
101  window = data.uiwindow;
102  }
103 
104  if (window == nil || window.rootViewController == nil) {
105  alertwindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
106  alertwindow.rootViewController = [UIViewController new];
107  alertwindow.windowLevel = UIWindowLevelAlert;
108 
109  window = alertwindow;
110 
111  [alertwindow makeKeyAndVisible];
112  }
113 
114  [window.rootViewController presentViewController:alert animated:YES completion:nil];
115  UIKit_WaitUntilMessageBoxClosed(messageboxdata, &clickedindex);
116 
117  if (alertwindow) {
118  alertwindow.hidden = YES;
119  }
120 
122 
123  *buttonid = messageboxdata->buttons[clickedindex].buttonid;
124  return YES;
125 }
126 
127 /* UIAlertView is deprecated in iOS 8+ in favor of UIAlertController. */
128 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
129 @interface SDLAlertViewDelegate : NSObject <UIAlertViewDelegate>
130 
131 @property (nonatomic, assign) int *clickedIndex;
132 
133 @end
134 
135 @implementation SDLAlertViewDelegate
136 
137 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
138 {
139  if (_clickedIndex != NULL) {
140  *_clickedIndex = (int) buttonIndex;
141  }
142 }
143 
144 @end
145 #endif /* __IPHONE_OS_VERSION_MIN_REQUIRED < 80000 */
146 
147 static BOOL
148 UIKit_ShowMessageBoxAlertView(const SDL_MessageBoxData *messageboxdata, int *buttonid)
149 {
150  /* UIAlertView is deprecated in iOS 8+ in favor of UIAlertController. */
151 #if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
152  int i;
153  int clickedindex = messageboxdata->numbuttons;
154  const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
155  UIAlertView *alert = [[UIAlertView alloc] init];
156  SDLAlertViewDelegate *delegate = [[SDLAlertViewDelegate alloc] init];
157 
158  alert.delegate = delegate;
159  alert.title = @(messageboxdata->title);
160  alert.message = @(messageboxdata->message);
161 
162  for (i = 0; i < messageboxdata->numbuttons; i++) {
163  const SDL_MessageBoxButtonData *sdlButton;
164  if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
165  sdlButton = &messageboxdata->buttons[messageboxdata->numbuttons - 1 - i];
166  } else {
167  sdlButton = &messageboxdata->buttons[i];
168  }
169  [alert addButtonWithTitle:@(sdlButton->text)];
170  }
171 
172  delegate.clickedIndex = &clickedindex;
173 
174  [alert show];
175 
176  UIKit_WaitUntilMessageBoxClosed(messageboxdata, &clickedindex);
177 
178  alert.delegate = nil;
179 
180  if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
181  clickedindex = messageboxdata->numbuttons - 1 - clickedindex;
182  }
183  *buttonid = messageboxdata->buttons[clickedindex].buttonid;
184  return YES;
185 #else
186  return NO;
187 #endif /* __IPHONE_OS_VERSION_MIN_REQUIRED < 80000 */
188 }
189 
190 int
191 UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
192 {
193  BOOL success = NO;
194 
195  @autoreleasepool {
196  success = UIKit_ShowMessageBoxAlertController(messageboxdata, buttonid);
197  if (!success) {
198  success = UIKit_ShowMessageBoxAlertView(messageboxdata, buttonid);
199  }
200  }
201 
202  if (!success) {
203  return SDL_SetError("Could not show message box.");
204  }
205 
206  return 0;
207 }
208 
209 #endif /* SDL_VIDEO_DRIVER_UIKIT */
210 
211 /* vi: set ts=4 sw=4 expandtab: */
SDL.h
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
@ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
Definition: SDL_messagebox.h:52
SDL_uikitvideo.h
if
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Definition: pixman-arm-neon-asm.h:469
NULL
#define NULL
Definition: begin_code.h:167
SDL_MessageBoxData::title
const char * title
Definition: SDL_messagebox.h:98
SDL_MessageBoxButtonData::flags
Uint32 flags
Definition: SDL_messagebox.h:60
SDL_MessageBoxData::message
const char * message
Definition: SDL_messagebox.h:99
UIKit_ForceUpdateHomeIndicator
void UIKit_ForceUpdateHomeIndicator(void)
SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
@ SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
Definition: SDL_messagebox.h:43
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_MessageBoxData::flags
Uint32 flags
Definition: SDL_messagebox.h:96
SDL_MessageBoxData
MessageBox structure containing title, text, window, etc.
Definition: SDL_messagebox.h:95
SDL_MessageBoxData::window
SDL_Window * window
Definition: SDL_messagebox.h:97
SDL_MessageBoxButtonData
Individual button data.
Definition: SDL_messagebox.h:59
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_MessageBoxButtonData::buttonid
int buttonid
Definition: SDL_messagebox.h:61
SDL_uikitwindow.h
action
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF PF lsl PF PF PF else PF lsl PF lsl PF lsl PF endif SIZE macro preload_middle scratch_holds_offset if bpp if else PF PF endif endif endif endm macro preload_trailing base if bpp if bpp *pix_per_block PF PF lsl PF PF PF PF PF else PF lsl PF lsl PF PF PF PF PF base if bpp if narrow_case &&bpp<=dst_w_bpp) PF bic, WK0, base, #31 PF pld,[WK0] PF add, WK1, base, X, LSL #bpp_shift PF sub, WK1, WK1, #1 PF bic, WK1, WK1, #31 PF cmp, WK1, WK0 PF beq, 90f PF pld,[WK1]90:.else PF bic, WK0, base, #31 PF pld,[WK0] PF add, WK1, base, X, lsl #bpp_shift PF sub, WK1, WK1, #1 PF bic, WK1, WK1, #31 PF cmp, WK1, WK0 PF beq, 92f91:PF add, WK0, WK0, #32 PF cmp, WK0, WK1 PF pld,[WK0] PF bne, 91b92:.endif .endif.endm.macro conditional_process1_helper cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx process_head cond, numbytes, firstreg, unaligned_src, unaligned_mask, 0 .if decrementx sub &cond X, X, #8 *numbytes/dst_w_bpp .endif process_tail cond, numbytes, firstreg .if !((flags) &FLAG_PROCESS_DOES_STORE) pixst cond, numbytes, firstreg, DST .endif.endm.macro conditional_process1 cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx .if(flags) &FLAG_BRANCH_OVER .ifc cond, mi bpl 100f .endif .ifc cond, cs bcc 100f .endif .ifc cond, ne beq 100f .endif conditional_process1_helper, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx100:.else conditional_process1_helper cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx .endif.endm.macro conditional_process2 test, cond1, cond2, process_head, process_tail, numbytes1, numbytes2, firstreg1, firstreg2, unaligned_src, unaligned_mask, decrementx .if(flags) &(FLAG_DST_READWRITE|FLAG_BRANCH_OVER|FLAG_PROCESS_CORRUPTS_PSR|FLAG_PROCESS_DOES_STORE) test conditional_process1 cond1, process_head, process_tail, numbytes1, firstreg1, unaligned_src, unaligned_mask, decrementx .if(flags) &FLAG_PROCESS_CORRUPTS_PSR test .endif conditional_process1 cond2, process_head, process_tail, numbytes2, firstreg2, unaligned_src, unaligned_mask, decrementx .else test process_head cond1, numbytes1, firstreg1, unaligned_src, unaligned_mask, 0 process_head cond2, numbytes2, firstreg2, unaligned_src, unaligned_mask, 0 .if decrementx sub &cond1 X, X, #8 *numbytes1/dst_w_bpp sub &cond2 X, X, #8 *numbytes2/dst_w_bpp .endif process_tail cond1, numbytes1, firstreg1 process_tail cond2, numbytes2, firstreg2 pixst cond1, numbytes1, firstreg1, DST pixst cond2, numbytes2, firstreg2, DST .endif.endm.macro test_bits_1_0_ptr .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 movs SCRATCH, X, lsl #32-1 .else movs SCRATCH, WK0, lsl #32-1 .endif.endm.macro test_bits_3_2_ptr .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 movs SCRATCH, X, lsl #32-3 .else movs SCRATCH, WK0, lsl #32-3 .endif.endm.macro leading_15bytes process_head, process_tail .set DECREMENT_X, 1 .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 .set DECREMENT_X, 0 sub X, X, WK0, lsr #dst_bpp_shift str X,[sp, #LINE_SAVED_REG_COUNT *4] mov X, WK0 .endif .if dst_w_bpp==8 conditional_process2 test_bits_1_0_ptr, mi, cs, process_head, process_tail, 1, 2, 1, 2, 1, 1, DECREMENT_X .elseif dst_w_bpp==16 test_bits_1_0_ptr conditional_process1 cs, process_head, process_tail, 2, 2, 1, 1, DECREMENT_X .endif conditional_process2 test_bits_3_2_ptr, mi, cs, process_head, process_tail, 4, 8, 1, 2, 1, 1, DECREMENT_X .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 ldr X,[sp, #LINE_SAVED_REG_COUNT *4] .endif.endm.macro test_bits_3_2_pix movs SCRATCH, X, lsl #dst_bpp_shift+32-3.endm.macro test_bits_1_0_pix .if dst_w_bpp==8 movs SCRATCH, X, lsl #dst_bpp_shift+32-1 .else movs SCRATCH, X, lsr #1 .endif.endm.macro trailing_15bytes process_head, process_tail, unaligned_src, unaligned_mask conditional_process2 test_bits_3_2_pix, cs, mi, process_head, process_tail, 8, 4, 0, 2, unaligned_src, unaligned_mask, 0 .if dst_w_bpp==16 test_bits_1_0_pix conditional_process1 cs, process_head, process_tail, 2, 0, unaligned_src, unaligned_mask, 0 .elseif dst_w_bpp==8 conditional_process2 test_bits_1_0_pix, cs, mi, process_head, process_tail, 2, 1, 0, 1, unaligned_src, unaligned_mask, 0 .endif.endm.macro wide_case_inner_loop process_head, process_tail, unaligned_src, unaligned_mask, dst_alignment110:.set SUBBLOCK, 0 .rept pix_per_block *dst_w_bpp/128 process_head, 16, 0, unaligned_src, unaligned_mask, 1 .if(src_bpp > 0) &&(mask_bpp==0) &&((flags) &FLAG_PROCESS_PRESERVES_SCRATCH) preload_middle src_bpp, SRC, 1 .elseif(src_bpp==0) &&(mask_bpp > 0) &&((flags) &FLAG_PROCESS_PRESERVES_SCRATCH) preload_middle mask_bpp, MASK, 1 .else preload_middle src_bpp, SRC, 0 preload_middle mask_bpp, MASK, 0 .endif .if(dst_r_bpp > 0) &&((SUBBLOCK % 2)==0) &&(((flags) &FLAG_NO_PRELOAD_DST)==0) PF pld,[DST, #32 *prefetch_distance - dst_alignment] .endif process_tail, 16, 0 .if !((flags) &FLAG_PROCESS_DOES_STORE) pixst, 16, 0, DST .endif .set SUBBLOCK, SUBBLOCK+1 .endr subs X, X, #pix_per_block bhs 110b.endm.macro wide_case_inner_loop_and_trailing_pixels process_head, process_tail, process_inner_loop, exit_label, unaligned_src, unaligned_mask .if dst_r_bpp > tst bne process_inner_loop DST_PRELOAD_BIAS endif preload_trailing SRC preload_trailing MASK DST endif add medium_case_inner_loop_and_trailing_pixels unaligned_mask endm macro medium_case_inner_loop_and_trailing_pixels DST endif subs bhs tst beq exit_label trailing_15bytes unaligned_mask endm macro narrow_case_inner_loop_and_trailing_pixels unaligned_mask tst conditional_process1 trailing_15bytes unaligned_mask endm macro switch_on_alignment action
Definition: pixman-arm-simd-asm.h:510
SDL_MessageBoxData::buttons
const SDL_MessageBoxButtonData * buttons
Definition: SDL_messagebox.h:102
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
@ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
Definition: SDL_messagebox.h:51
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_MessageBoxButtonData::text
const char * text
Definition: SDL_messagebox.h:62
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
void
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:89
SDL_MessageBoxData::numbuttons
int numbuttons
Definition: SDL_messagebox.h:101
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50