[go: up one dir, main page]

Menu

[r102]: / trunk / examp.c  Maximize  Restore  History

Download this file

398 lines (322 with data), 13.5 kB

  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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/* examp.c
*
* This file is part of the Allegro GUI Un-uglification Project.
* It is a cheap demonstration of how pretty we are.
*
* Peter Wang <tjaden@users.sourceforge.net>
*/
#include <allegro.h>
#include <string.h>
#include <stdio.h>
#include "agup.h"
/*----------------------------------------------------------------------*/
/* Main dialog stuff */
/*----------------------------------------------------------------------*/
extern DIALOG main_dlg[];
extern MENU menu_theme[];
extern MENU menu_font[];
FONT *oldfont, *newfont;
int select_theme(void)
{
int c;
AGUP_THEME const *theme = agup_theme_by_name (active_menu->dp);
if (!theme)
return D_O_K;
agup_shutdown();
agup_init(theme);
/* Clear all theme menu selections. */
for (c=0; menu_theme[c].proc; c++)
menu_theme[c].flags &=~ D_SELECTED;
/* Select the current theme. */
active_menu->flags |= D_SELECTED;
/* Set the dialog color (useful for the Allegro theme only). */
gui_fg_color = agup_fg_color;
gui_bg_color = agup_bg_color;
set_dialog_color(main_dlg, gui_fg_color, gui_bg_color);
return D_REDRAW;
}
int select_font(void)
{
int i;
/* Clear all theme menu selections. */
for (i = 0; menu_font[i].proc; i++)
menu_font[i].flags &=~ D_SELECTED;
/* Select the current theme. */
active_menu->flags |= D_SELECTED;
if (!strcmp (active_menu->text, "&Allegro"))
font = oldfont;
else
font = newfont;
return D_REDRAW;
}
int file_selector(void)
{
char path[1024] = "";
file_select_ex("Testing...", path, NULL, sizeof path, 0, 0);
return D_REDRAW;
}
int demo_windows(void)
{
DIALOG dlg[] =
{
{ d_agup_window_proc, 0, 0, 300, 200, agup_fg_color, agup_bg_color, 0, 0, 0, 0, (void *)"A window", NULL, NULL },
{ d_ctext_proc, 160, 100, 0, 0, agup_fg_color, agup_bg_color, 0, 0, 0, 0, (void *)"Press ESC.", NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
centre_dialog(dlg);
do_dialog(dlg, -1);
return D_REDRAW;
}
int surprise()
{
alert("You pushed my button!", "Isn't this a useful feature?", 0,
"&Yes", "&Definitely", 'y', 'd');
return D_O_K;
}
int quit_proc(int msg, DIALOG *d, int c)
{
(void)d;
(void)c;
return (((msg == MSG_KEY) || (msg == MSG_XCHAR && c == KEY_F10 << 8))
&& alert(0, "Quit?", 0, "Ok", "Cancel", 0, 0) == 1 ? D_CLOSE : D_O_K);
}
char *lister(int index, int *list_size)
{
static char items[10][32] = {"box", "text", "input", "button", "menu",
"selection", "slider", "scrollbar", "list", "window"};
if (index >= 0) {
return items[index];
}
else {
index = 10;
*list_size = index;
}
return NULL;
}
int toggle_focus(void)
{
gui_mouse_focus ^= 1;
if (gui_mouse_focus)
active_menu->flags |= D_SELECTED;
else
active_menu->flags &= ~D_SELECTED;
return D_O_K;
}
char version[1024];
char sel[10];
char sel2[10];
char buf[101] = "101";
char buf2[101] = "dalmations";
char buf3[1024] = " AGUP\n"
"__________\n"
"\n"
" Allegro\n"
" GUI\n"
" Un-ugli-\n"
" fication\n"
" Project\n"
"\n\n"
" Widget\n"
" Sets\n"
"__________\n"
"\n"
"- Allegro\n"
"- GTK\n"
"- BeOS\n"
"- Photon\n"
"- Win95\n"
"- NeXTStep\n"
"- ASE\n"
"\n\n"
" By\n"
"__________\n"
"\n"
"Shawn Hargreaves\n\n"
"Peter Wang\n\n"
"Elias Pschernig\n\n"
"Eric Botcazou\n\n"
"Robert Ohannessian\n\n"
"Joao Neves\n\n"
"David A. Capello\n\n"
"__________";
MENU menu12[] =
{
/* text proc child flags dp */
{ "Submenu", 0, 0, 0, 0 },
{ "", 0, 0, 0, 0 },
{ "Checked", 0, 0, D_SELECTED, 0 },
{ "Disabled", 0, 0, D_DISABLED, 0 },
{ NULL, 0, 0, 0, 0 },
};
MENU menu1[] =
{
/* text proc child flags dp */
{ "&File selector", file_selector, 0, 0, 0 },
{ "&Window frames", demo_windows, 0, 0, 0 },
{ "Test &1", 0, 0, 0, 0 },
{ "Test &2", 0, menu12, 0, 0 },
{ "Test &3\thi", 0, 0, 0, 0 },
{ NULL, 0, 0, 0, 0 },
};
MENU menu_theme[] =
{
/* text proc child flags dp */
{ "&GTK", select_theme, 0, D_SELECTED, "GTK" },
{ "&Photon", select_theme, 0, 0, "Photon" },
{ "&Win95", select_theme, 0, 0, "Win95" },
{ "&ASE", select_theme, 0, 0, "ASE" },
{ "&BeOS", select_theme, 0, 0, "BeOS" },
{ "&NeXTStep", select_theme, 0, 0, "NeXTStep" },
{ "A&llegro", select_theme, 0, 0, "Allegro" },
{ "Bl&ue", select_theme, 0, D_DISABLED, "Blue" },
{ "&Fleur de Lis", select_theme, 0, D_DISABLED, "Fleur de Lis" },
{ "&Mud", select_theme, 0, D_DISABLED, "Mud" },
{ "", NULL, 0, 0, NULL },
{ "&Focus Follow Mouse", toggle_focus, 0, 0, NULL},
{ NULL, 0, 0, 0, NULL},
};
MENU menu_font[] =
{
/* text proc child flags dp */
{ "&Allegro", select_font, 0, 0, NULL },
{ "&Clean", select_font, 0, D_SELECTED, NULL },
{ NULL, 0, 0, 0, NULL },
};
MENU menubar[] =
{
/* text proc child flags dp */
{ "&Menu 1", 0, menu1, 0, 0 },
{ "&Theme", 0, menu_theme, 0, 0 },
{ "&Font", 0, menu_font, 0, 0 },
{ NULL, 0, 0, 0, 0 },
};
#define DIS D_DISABLED
#define SEL D_SELECTED
DIALOG main_dlg[] =
{
/* proc x y w h fg bg key flags d1 d2 dp dp2 dp3 */
{ d_agup_clear_proc, 0, 0, 320, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* First column */
{ d_agup_check_proc, 5, 25, 100, 12, 0, 0, 0, SEL, 0, 0, (void *)"check box", 0, 0 },
{ d_agup_radio_proc, 5, 50, 100, 12, 0, 0, 0, SEL, 1, 0, (void *)"radio 1", 0, 0 },
{ d_agup_radio_proc, 5, 75, 100, 12, 0, 0, 0, 0, 1, 0, (void *)"radio 2", 0, 0 },
{ d_agup_shadow_box_proc, 5, 100, 100, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ d_agup_slider_proc, 5, 125, 100, 12, 0, 0, 0, 0, 100, 50, 0, 0, 0 },
{ d_agup_edit_proc, 5, 150, 100, 14, 0, 0, 0, 0, 100, 0, buf2, 0, 0 },
{ d_agup_list_proc, 5, 175, 100, 50, 0, 0, 0, 0, 2, 0, lister, sel2, 0 },
/* Buttons */
{ d_agup_button_proc, 110, 25, 100, 20, 0, 0, 0, 0, 0, 0, (void *)"button", 0, 0 },
{ d_agup_push_proc, 110, 50, 100, 20, 0, 0, 0, 0, 0, 0, (void *)"button", 0, surprise },
{ d_agup_button_proc, 215, 25, 100, 20, 0, 0, 0, DIS, 0, 0, (void *)"button", 0, 0 },
{ d_agup_button_proc, 215, 50, 100, 20, 0, 0, 0, DIS|SEL, 0, 0, (void *)"button", 0, 0 },
/* Misc */
#define ICON_DIALOG 12
{ d_agup_icon_proc, 240, 75, 50, 50, 0, 0, 0, 0, 2, 2, 0, 0, 0 },
{ d_agup_text_proc, 240, 130, 75, 12, 0, 0, 0, 0, 0, 0, (void *)"A", 0, 0 },
{ d_agup_ctext_proc, 240, 150, 75, 12, 0, 0, 0, 0, 0, 0, (void *)"B", 0, 0 },
{ d_agup_rtext_proc, 240, 170, 75, 12, 0, 0, 0, 0, 0, 0, (void *)"C", 0, 0 },
{ d_agup_textbox_proc, 110, 75, 100, 150, 0, 0, 0, 0, 0, 0, buf3, 0, 0 },
{ d_agup_slider_proc, 215, 75, 12, 100, 0, 0, 0, 0, 100, 50, 0, 0, 0 },
{ d_agup_box_proc, 215, 185, 100, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ d_agup_slider_proc, 215, 213, 100, 12, 0, 0, 0, DIS, 100, 0, 0, 0, 0 },
{ d_agup_menu_proc, 5, 5, 310, 12, 0, 0, 0, 0, 0, 0, menubar, 0, 0 },
{ quit_proc, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0 },
{ d_agup_text_proc, 0, 232, 320, 8, 0, 0, 0, 0, 0, 0, version, 0, 0 },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
static int work_around_fsel_bug = 0;
/* The AGUP d_agup_edit_proc isn't exactly compatible to Allegro's stock
* d_edit_proc, which has no border at all. Therefore we resort to this little
* hack.
*/
int d_hackish_edit_proc (int msg, DIALOG *d, int c)
{
if (msg == MSG_START && !work_around_fsel_bug)
{
/* Adjust position/dimension so it is the same as AGUP's. */
d->y -= 3;
d->h += 6;
/* The Allegro GUI has a bug where it repeatedely sends MSG_START to a
* custom GUI procedure. We need to work around that.
*/
work_around_fsel_bug = 1;
}
if (msg == MSG_END && work_around_fsel_bug)
{
d->y += 3;
d->h -= 6;
work_around_fsel_bug = 0;
}
return d_agup_edit_proc (msg, d, c);
}
void do_main_dialog()
{
BITMAP *icon;
agup_init(agtk_theme);
/* Make Allegro's dialogs also use AGUP. See the Allegro docs for
* details.
*/
gui_fg_color = agup_fg_color;
gui_bg_color = agup_bg_color;
gui_mg_color = agup_mg_color;
gui_shadow_box_proc = d_agup_shadow_box_proc;
gui_button_proc = d_agup_button_proc;
gui_ctext_proc = d_agup_ctext_proc;
gui_text_list_proc = d_agup_text_list_proc;
/* The file selector has a very small edit proc. This is a small hack
* to make the edit box enlarge itself.
*/
gui_edit_proc = d_hackish_edit_proc;
if (agup_load_bitmap_theme ("themes/blue/agup.cfg", NULL))
menu_theme[7].flags = 0;
if (agup_load_bitmap_theme ("themes/fdl/agup.cfg", NULL))
menu_theme[8].flags = 0;
if (agup_load_bitmap_theme ("themes/mud/agup.cfg", NULL))
menu_theme[9].flags = 0;
icon = load_bitmap("alex.pcx", 0);
main_dlg[ICON_DIALOG].dp = icon;
set_dialog_color(main_dlg, gui_fg_color, gui_bg_color);
gui_mouse_focus = 0;
do_dialog(main_dlg, -1);
destroy_bitmap(icon);
agup_shutdown();
}
/*----------------------------------------------------------------------*/
/* Main */
/*----------------------------------------------------------------------*/
void closebutton (void)
{
simulate_keypress ((KEY_ESC << 8) | scancode_to_ascii (KEY_ESC));
}
int init()
{
allegro_init();
install_timer();
install_keyboard();
install_mouse();
set_window_title("Widgets test");
set_color_depth(desktop_color_depth());
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 240, 0, 0) < 0) {
if (set_gfx_mode(GFX_SAFE, 320, 240, 0, 0) < 0) {
allegro_message("Could not set graphics mode.\n");
return -1;
}
}
set_close_button_callback (closebutton);
snprintf (version, sizeof(version), "AGUP %s, Allegro %s", AGUP_VERSION, ALLEGRO_VERSION_STR);
return 0;
}
int main(void)
{
if (init() < 0)
return 1;
enable_hardware_cursor();
show_mouse(screen);
oldfont = font;
font = newfont = load_font ("clean8.pcx", NULL, NULL);
do_main_dialog();
font = oldfont;
return 0;
}
END_OF_MAIN()