| 1 |
#include "allegro5/allegro.h" |
| 2 |
#include "allegro5/allegro_native_dialog.h" |
| 3 |
#include "allegro5/internal/aintern_native_dialog.h" |
| 4 |
|
| 5 |
#include <UIKit/UIAlertView.h> |
| 6 |
|
| 7 |
#include "allegro5/allegro_iphone_objc.h" |
| 8 |
|
| 9 |
bool _al_init_native_dialog_addon(void) |
| 10 |
{ |
| 11 |
return true; |
| 12 |
} |
| 13 |
|
| 14 |
void _al_shutdown_native_dialog_addon(void) |
| 15 |
{ |
| 16 |
} |
| 17 |
|
| 18 |
bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display, |
| 19 |
ALLEGRO_NATIVE_DIALOG *fd) |
| 20 |
{ |
| 21 |
(void)display; |
| 22 |
(void)fd; |
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
@interface AlertDelegate : NSObject<UIAlertViewDelegate> { |
| 27 |
ALLEGRO_MUTEX *mutex; |
| 28 |
ALLEGRO_COND *button_pressed; |
| 29 |
} |
| 30 |
@property ALLEGRO_MUTEX *mutex; |
| 31 |
@property ALLEGRO_COND *button_pressed; |
| 32 |
@end |
| 33 |
|
| 34 |
@implementation AlertDelegate |
| 35 |
@synthesize mutex; |
| 36 |
@synthesize button_pressed; |
| 37 |
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)bindex { |
| 38 |
(void)alert; |
| 39 |
(void)bindex; |
| 40 |
al_lock_mutex(mutex); |
| 41 |
al_signal_cond(button_pressed); |
| 42 |
al_unlock_mutex(mutex); |
| 43 |
} |
| 44 |
- (void) createAlert:(NSArray*)array { |
| 45 |
UIView *view = [array objectAtIndex:0]; |
| 46 |
UIAlertView *alert = [array objectAtIndex:1]; |
| 47 |
[view addSubview:alert]; |
| 48 |
[alert show]; |
| 49 |
[alert release]; |
| 50 |
} |
| 51 |
|
| 52 |
@end |
| 53 |
|
| 54 |
int _al_show_native_message_box(ALLEGRO_DISPLAY *display, |
| 55 |
ALLEGRO_NATIVE_DIALOG *nd) |
| 56 |
{ |
| 57 |
(void)display; |
| 58 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; |
| 59 |
NSString *title = [NSString stringWithUTF8String:al_cstr(nd->title)]; |
| 60 |
NSString *heading = [NSString stringWithUTF8String:al_cstr(nd->mb_heading)]; |
| 61 |
NSString *text = [NSString stringWithUTF8String:al_cstr(nd->mb_text)]; |
| 62 |
NSString *ok = [NSString stringWithUTF8String:"Ok"]; |
| 63 |
NSString *message = [NSString stringWithFormat:@"%@\n\n%@", heading, text]; |
| 64 |
|
| 65 |
AlertDelegate *delegate = [[AlertDelegate alloc]init]; |
| 66 |
delegate.mutex = al_create_mutex(); |
| 67 |
delegate.button_pressed = al_create_cond(); |
| 68 |
|
| 69 |
// This needs to be done on the thread with the display due to TLS. |
| 70 |
UIView *view = al_iphone_get_view(al_get_current_display()); |
| 71 |
|
| 72 |
UIAlertView *alert = [[UIAlertView alloc] |
| 73 |
initWithTitle:title |
| 74 |
message:message |
| 75 |
delegate:delegate |
| 76 |
cancelButtonTitle:ok |
| 77 |
otherButtonTitles:nil]; |
| 78 |
|
| 79 |
[delegate performSelectorOnMainThread:@selector(createAlert:) |
| 80 |
withObject:@[view,alert] |
| 81 |
waitUntilDone:YES]; |
| 82 |
|
| 83 |
al_lock_mutex(delegate.mutex); |
| 84 |
al_wait_cond(delegate.button_pressed, delegate.mutex); |
| 85 |
al_unlock_mutex(delegate.mutex); |
| 86 |
al_destroy_cond(delegate.button_pressed); |
| 87 |
al_destroy_mutex(delegate.mutex); |
| 88 |
|
| 89 |
[delegate release]; |
| 90 |
|
| 91 |
[pool drain]; |
| 92 |
return 0; |
| 93 |
} |
| 94 |
|
| 95 |
bool _al_open_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog) |
| 96 |
{ |
| 97 |
(void)textlog; |
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
void _al_close_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog) |
| 102 |
{ |
| 103 |
(void) textlog; |
| 104 |
} |
| 105 |
|
| 106 |
void _al_append_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog) |
| 107 |
{ |
| 108 |
(void) textlog; |
| 109 |
} |
| 110 |
|
| 111 |
bool _al_init_menu(ALLEGRO_MENU *menu) |
| 112 |
{ |
| 113 |
(void) menu; |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
bool _al_init_popup_menu(ALLEGRO_MENU *menu) |
| 118 |
{ |
| 119 |
(void) menu; |
| 120 |
return false; |
| 121 |
} |
| 122 |
|
| 123 |
bool _al_insert_menu_item_at(ALLEGRO_MENU_ITEM *item, int i) |
| 124 |
{ |
| 125 |
(void) item; |
| 126 |
(void) i; |
| 127 |
return false; |
| 128 |
} |
| 129 |
|
| 130 |
bool _al_destroy_menu_item_at(ALLEGRO_MENU_ITEM *item, int i) |
| 131 |
{ |
| 132 |
(void) item; |
| 133 |
(void) i; |
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
bool _al_update_menu_item_at(ALLEGRO_MENU_ITEM *item, int i) |
| 138 |
{ |
| 139 |
(void) item; |
| 140 |
(void) i; |
| 141 |
return false; |
| 142 |
} |
| 143 |
|
| 144 |
bool _al_show_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu) |
| 145 |
{ |
| 146 |
(void) display; |
| 147 |
(void) menu; |
| 148 |
return false; |
| 149 |
} |
| 150 |
|
| 151 |
bool _al_hide_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu) |
| 152 |
{ |
| 153 |
(void) display; |
| 154 |
(void) menu; |
| 155 |
return false; |
| 156 |
} |
| 157 |
|
| 158 |
bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu) |
| 159 |
{ |
| 160 |
(void) display; |
| 161 |
(void) menu; |
| 162 |
return false; |
| 163 |
} |
| 164 |
|
| 165 |
int _al_get_menu_display_height(void) |
| 166 |
{ |
| 167 |
return 0; |
| 168 |
} |