File: iphone_dialog.m

package info (click to toggle)
allegro5 2%3A5.2.6.0-3%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 24,212 kB
  • sloc: ansic: 125,319; cpp: 15,781; objc: 4,579; python: 2,802; java: 2,254; javascript: 1,204; sh: 1,002; makefile: 51; perl: 37; xml: 25; pascal: 24
file content (168 lines) | stat: -rw-r--r-- 4,016 bytes parent folder | download | duplicates (5)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "allegro5/allegro.h"
#include "allegro5/allegro_native_dialog.h"
#include "allegro5/internal/aintern_native_dialog.h"

#include <UIKit/UIAlertView.h>

#include "allegro5/allegro_iphone_objc.h"

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:(NSArray*)array {
    UIView *view = [array objectAtIndex:0];
    UIAlertView *alert = [array objectAtIndex:1];
    [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();
    
    // This needs to be done on the thread with the display due to TLS.
    UIView *view = al_iphone_get_view(al_get_current_display());

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:title
                          message:message
                          delegate:delegate
                          cancelButtonTitle:ok
                          otherButtonTitles:nil];

    [delegate performSelectorOnMainThread:@selector(createAlert:)
                               withObject:@[view,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;
}

bool _al_init_menu(ALLEGRO_MENU *menu)
{
    (void) menu;
    return false;
}

bool _al_init_popup_menu(ALLEGRO_MENU *menu)
{
    (void) menu;
    return false;
}

bool _al_insert_menu_item_at(ALLEGRO_MENU_ITEM *item, int i)
{
    (void) item;
    (void) i;
    return false;
}

bool _al_destroy_menu_item_at(ALLEGRO_MENU_ITEM *item, int i)
{
    (void) item;
    (void) i;
    return false;
}

bool _al_update_menu_item_at(ALLEGRO_MENU_ITEM *item, int i)
{
    (void) item;
    (void) i;
    return false;
}

bool _al_show_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu)
{
    (void) display;
    (void) menu;
    return false;
}

bool _al_hide_display_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu)
{
    (void) display;
    (void) menu;
    return false;
}

bool _al_show_popup_menu(ALLEGRO_DISPLAY *display, ALLEGRO_MENU *menu)
{
    (void) display;
    (void) menu;
    return false;
}

int _al_get_menu_display_height(void)
{
   return 0;
}