zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_uikitmessagebox.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 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_config.h"
22 
23 #if SDL_VIDEO_DRIVER_UIKIT
24 
25 #include "SDL.h"
26 #include "SDL_uikitvideo.h"
27 
28 
29 /* Display a UIKit message box */
30 
31 static SDL_bool s_showingMessageBox = SDL_FALSE;
32 
33 @interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate> {
34 @private
35  int *clickedButtonIndex;
36 }
37 
38 - (id)initWithButtonIndex:(int *)_buttonIndex;
39 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
40 
41 @end
42 
43 @implementation UIKit_UIAlertViewDelegate
44 
45 - (id)initWithButtonIndex:(int *)buttonIndex
46 {
47  self = [self init];
48  if (self == nil) {
49  return nil;
50  }
51  self->clickedButtonIndex = buttonIndex;
52 
53  return self;
54 }
55 
56 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
57 {
58  *clickedButtonIndex = buttonIndex;
59 }
60 
61 @end /* UIKit_UIAlertViewDelegate */
62 
63 
65 UIKit_ShowingMessageBox()
66 {
67  return s_showingMessageBox;
68 }
69 
70 int
71 UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
72 {
73  int clicked;
74 
75  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
76 
77  UIAlertView* alert = [[UIAlertView alloc] init];
78 
79  alert.title = [NSString stringWithUTF8String:messageboxdata->title];
80  alert.message = [NSString stringWithUTF8String:messageboxdata->message];
81  alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
82 
83  const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
84  int i;
85  for (i = 0; i < messageboxdata->numbuttons; ++i) {
86  [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
87  }
88 
89  /* Set up for showing the alert */
90  clicked = messageboxdata->numbuttons;
91 
92  [alert show];
93 
94  /* Run the main event loop until the alert has finished */
95  /* Note that this needs to be done on the main thread */
96  s_showingMessageBox = SDL_TRUE;
97  while (clicked == messageboxdata->numbuttons) {
98  [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
99  }
100  s_showingMessageBox = SDL_FALSE;
101 
102  *buttonid = messageboxdata->buttons[clicked].buttonid;
103 
104  [alert.delegate release];
105  [alert release];
106 
107  [pool release];
108 
109  return 0;
110 }
111 
112 #endif /* SDL_VIDEO_DRIVER_UIKIT */
113 
114 /* vi: set ts=4 sw=4 expandtab: */
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1824
SDL_bool
Definition: SDL_stdinc.h:116
GLuint id
Definition: gl2ext.h:1142
Individual button data.
const SDL_MessageBoxButtonData * buttons
MessageBox structure containing title, text, window, etc.
int i
Definition: pngrutil.c:1377