Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro GUI: custom button callback

Credits go to Tobias Dammers for helping out!
This thread is locked; no one can reply to it. rss feed Print
Allegro GUI: custom button callback
ngiacomelli
Member #5,114
October 2004

I've spent the past hour searching through (ancient) forum posts regarding the Allegro GUI routines. Before I state my problem, I would like to ask that people please refrain from telling me to try a new GUI system. I'm quite happy with the Allegro solution!

Now, as previously stated, I'm trying to write a custom button callback. I have, however, run into some difficulties! Below is the code in question. When the dialog is displayed, the editor_button_proc simply isn't rendered (or registered). I've even tried using the 'f' hotkey (which I assigned it), to no avail.

While browsing the code, if you can see that I've made some silly mistake, please don't hesitate to tell me. I've never actually used the Allegro GUI to any great extent before.

1int editor_button_proc(DIALOG *d, int msg, int c);
2int editor_store_tile_data(void);
3 
4DIALOG tile_options[] =
5{
6 { d_box_proc, 0, 0, 500, 125, 0, 16777215, 0, 0, 0, 0, NULL, NULL, NULL },
7 { d_check_proc, 15, 5, 175, 25, 0, 16777215, 'c', 0, 0, 0, "Block Player &Camera?", NULL, NULL },
8 { d_check_proc, 220, 5, 175, 25, 0, 16777215, 'm', 0, 0, 0, "Block &Monsters?", NULL, NULL },
9 { d_check_proc, 15, 35, 175, 25, 0, 16777215, 'p', 0, 0, 0, "Mark as Walk &Path?", NULL, NULL },
10 { d_check_proc, 220, 35, 175, 25, 0, 16777215, 'b', 0, 0, 0, "Mark as &Build Spot", NULL, NULL },
11 
12 { editor_button_proc, 15, 80, 175, 25, 0, 16777215, 'f', D_EXIT, 0, 0, "&Finished", NULL, (void *)editor_store_tile_data },
13 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14};
15 
16int editor_button_proc(DIALOG *d, int msg, int c){
17 
18 int ret = d_button_proc(msg, d, c);
19
20 if (ret == D_CLOSE && d->dp3)
21 return ((int (*)(void))d->dp3)();
22
23 return ret;
24
25}
26 
27int editor_store_tile_data(void) {
28 
29 allegro_message( "Option: %i", tile_options[3].d1 );
30 return D_O_K;
31
32}
33 
34void show_tile_options(void) {
35
36 do_dialog( tile_options, -1 );
37
38}

Tobias Dammers
Member #2,604
August 2002
avatar

Why do you have to implement this as a callback? Can't you just check which button was used to terminate the dialog, and then do the appropriate thing?

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

ngiacomelli
Member #5,114
October 2004

I wasn't aware that do_dialog returned the exit objects index! D'Oh!

I'll give cookies, but I'd still like to know how to achieve the callback, for future reference.

Peter Wang
Member #23
April 2000

Here's the code from AGUP:

1int d_aalg_push_proc(int msg, DIALOG *d, int c)
2{
3 int ret = D_O_K;
4 
5 d->flags |= D_EXIT;
6 
7 ret |= d_button_proc(msg, d, c);
8 
9 if (ret & D_CLOSE) {
10 ret &= ~D_CLOSE;
11 ret |= D_REDRAWME;
12 
13 if (d->dp3)
14 ret |= ((int (*)(DIALOG *))d->dp3)(d);
15 }
16 
17 return ret;
18}

ngiacomelli
Member #5,114
October 2004

Thank you! I have one last Allegro GUI question... non-blocking menus. I've done some forum searching but have run into a few problems. Here's the necessary code:

editor_gui.c

1MENU file_menu[] =
2{
3
4 { "&New Map", NULL, NULL, 0, NULL },
5 { "&Load Map", NULL, NULL, 0, NULL },
6 { "&Save Map", NULL, NULL, 0, NULL },
7 { "&Exit", NULL, NULL, 0, NULL },
8 { NULL, NULL, NULL, 0, NULL }
9
10};
11 
12MENU_PLAYER *file_control;
13 
14void editor_setup_gui(void) {
15
16 file_control = init_menu( file_menu, 0, 0 );
17 gui_set_screen( buffer );
18
19}
20 
21void editor_update_gui(void) {
22
23 update_menu( file_control );
24
25}
26 
27void editor_shutdown_gui(void) {
28
29 shutdown_menu( file_control );
30
31}

Now, I've tried calling update_menu with both my logic and rendering code, but nothing seems to work. Is update_menu actually rendering anything, or just updating the menus logic/state? The manual is slightly unclear on this. I've set the render bitmap to my buffer, but how can I specify when it's rendered?

Go to: