AGUL Dialog question
Raf Vermeulen

My program uses AGUL for the GUI part, and it draws just fine. What I want it to do, though, is to draw a different dialog when the user's made a choice, which, when finished, returns to the first dialog again.

What I got, is that the main dialog appears properly. The user can go to another one just fine, but when that one finishes, it doesn't clear the dialog and places the main one again, but instead, after pressing Escape, places the main one, parts of it only appearing when you hover the mouse over it.

Anybody know why this happens? Here's the code for the main one:

1DIALOG main_dlg[] =
2{
3 /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
4
5 /* this element just clears the screen, therefore it should come before the others */
6 { d_agup_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7
8 
9 
10// Add/Edit record
11 { d_agup_edit_proc, 100, 75, 100, 8, 0, 0, 0, 0, LENGTH, 0, word_1, NULL, word_1 },
12 { d_agup_edit_proc, 226, 75, 100, 8, 0, 0, 0, 0, LENGTH, 0, word_2, NULL, word_2 },
13 { d_agup_push_proc, 110, 95, 100, 18, 0, 0, 0, 0, 0, 0, (void*)"Add", 0, (void*)add_to_database },
14 { d_agup_push_proc, 215, 95, 100, 18, 0, 0, 0, 0, 0, 0, (void*)"Edit", 0, (void*)edit },
15 
16 
17// Translate
18 { d_agup_edit_proc, 163, 155, 100, 8, 0, 0, 0, 0, LENGTH, 0, trans, NULL, trans },
19 { d_agup_push_proc, 163, 175, 100, 18, 0, 0, 0, 0, 0, 0, (void*)"Translate", 0, (void*)translate },
20 { quit_proc, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0 },
21
22 /* the next two elements don't draw anything */
23 { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
24 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
25};
26 
27 
28int main(int argc, char *argv[])
29{
30 /* initialise everything */
31 if (allegro_init() != 0)
32 return 1;
33 
34 install_keyboard();
35 install_mouse();
36 install_timer();
37 /* End of initialise everything */
38 
39 /* Sets graphics mode */
40 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) {
41 if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
42 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
43 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
44 return 1;
45 }
46 }
47 /* End of sets graphics mode */
48 
49 
50 /* GUI theme + x-button */
51 set_close_button_callback (closebutton);
52 agup_init(agtk_theme);
53 /* End of GUI theme + x-button */
54 
55 set_gui(main_dlg);
56 
57 
58 agup_shutdown ();
59 return 0;
60}
61END_OF_MAIN()

And here's the code for the one giving trouble:

1int edit() {
2 int answer;
3 answer = alert("Edit record?", 0, 0, "&Yes", "&No", 'y', 'n');
4 
5 if(answer == 1) {
6 DIALOG edit_dlg[] =
7 {
8 /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
9
10 /* this element just clears the screen, therefore it should come before the others */
11 { d_agup_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12 
13 // Add/Edit record
14 { d_agup_edit_proc, 75, 75, 100, 8, 0, 0, 0, 0, LENGTH, 0, word_1, NULL, word_1 },
15 { d_agup_edit_proc, 200, 75, 100, 8, 0, 0, 0, 0, LENGTH, 0, new_word_1, NULL, new_word_1 },
16 { d_agup_edit_proc, 75, 95, 100, 8, 0, 0, 0, 0, LENGTH, 0, word_2, NULL, word_2 },
17 { d_agup_edit_proc, 200, 95, 100, 8, 0, 0, 0, 0, LENGTH, 0, new_word_2, NULL, new_word_2 },
18 { d_agup_push_proc, 137, 115, 100, 18, 0, 0, 0, 0, 0, 0, (void*)"Edit", 0, (void*)edit_record },
19 };
20 
21 set_gui(edit_dlg);
22 
23 }
24 return D_O_K;
25}

Kitty Cat

A dialog is a bit too big to put into the stack. You should probably make it global or static. Also, you're missing the last NULL entry, so you're lucky it's not crashing.

The problem is, though, that you're returning D_O_K instead of D_REDRAW. :)

Raf Vermeulen

Humm... which NULL'm I missing? the D_REDRAW did the trick. Thanks alot :) Now to get rid of the pressing ESC thing and it all works smoothly:)

Kitty Cat

A DIALOG array should end with a NULL proc, just like you have in main_dlg. edit_dlg is missing it and risks overrunning the memory.

Raf Vermeulen

Oops:-X It's added now, along with the yield proc. Thanks for pointing that out.

Thread #581976. Printed from Allegro.cc