1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include "allegro5/allegro.h"
#include "allegro5/allegro_native_dialog.h"
#include "allegro5/internal/aintern_native_dialog.h"
#include <UIKit/UIAlertView.h>
#include "allegro5/internal/aintern_iphone.h"
/* In 5.1 this is exposed but not in 5.0 */
UIView *_al_iphone_get_view(void);
bool _al_init_native_dialog_addon(void)
{
return true;
}
void _al_shutdown_native_dialog_addon(void)
{
}
bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display,
ALLEGRO_NATIVE_DIALOG *fd)
{
(void)display;
(void)fd;
return false;
}
@interface AlertDelegate : NSObject<UIAlertViewDelegate> {
ALLEGRO_MUTEX *mutex;
ALLEGRO_COND *button_pressed;
}
@property ALLEGRO_MUTEX *mutex;
@property ALLEGRO_COND *button_pressed;
@end
@implementation AlertDelegate
@synthesize mutex;
@synthesize button_pressed;
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)bindex {
(void)alert;
(void)bindex;
al_lock_mutex(mutex);
al_signal_cond(button_pressed);
al_unlock_mutex(mutex);
}
-(void) createAlert:(id)alert {
[_al_iphone_get_view() addSubview:alert];
[alert show];
[alert release];
}
@end
int _al_show_native_message_box(ALLEGRO_DISPLAY *display,
ALLEGRO_NATIVE_DIALOG *nd)
{
(void)display;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSString *title = [NSString stringWithUTF8String:al_cstr(nd->title)];
NSString *heading = [NSString stringWithUTF8String:al_cstr(nd->mb_heading)];
NSString *text = [NSString stringWithUTF8String:al_cstr(nd->mb_text)];
NSString *ok = [NSString stringWithUTF8String:"Ok"];
NSString *message = [NSString stringWithFormat:@"%@\n\n%@", heading, text];
AlertDelegate *delegate = [[AlertDelegate alloc]init];
delegate.mutex = al_create_mutex();
delegate.button_pressed = al_create_cond();
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:ok
otherButtonTitles:nil];
[delegate performSelectorOnMainThread:@selector(createAlert:)
withObject:alert
waitUntilDone:YES];
al_lock_mutex(delegate.mutex);
al_wait_cond(delegate.button_pressed, delegate.mutex);
al_unlock_mutex(delegate.mutex);
al_destroy_cond(delegate.button_pressed);
al_destroy_mutex(delegate.mutex);
[delegate release];
[pool drain];
return 0;
}
bool _al_open_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog)
{
(void)textlog;
return false;
}
void _al_close_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog)
{
(void) textlog;
}
void _al_append_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog)
{
(void) textlog;
}
|