My code is
| 1 | #include <allegro.h> |
| 2 | #define _WINSOCKAPI_ |
| 3 | #include <winalleg.h> |
| 4 | |
| 5 | char text_1[400]="Welcome to this gui thingy!\n\n"; |
| 6 | char edit_1[50]; |
| 7 | |
| 8 | //adds edit_1 to the end of text_1 |
| 9 | int ptext(void) { |
| 10 | ustrcat(text_1,"\n"); |
| 11 | ustrcat(text_1,edit_1); |
| 12 | ustrcpy(edit_1,""); |
| 13 | return D_O_K; |
| 14 | }; |
| 15 | |
| 16 | int func1(void) { |
| 17 | //alert goes here |
| 18 | return D_O_K; |
| 19 | }; |
| 20 | |
| 21 | DIALOG the_dialog[]={ |
| 22 | /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ |
| 23 | { d_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL }, |
| 24 | { d_textbox_proc, 5, 20, 630, 320, 0, 0, 0,D_SELECTED, 0, 0, text_1, NULL, NULL }, |
| 25 | { d_edit_proc, 5, 342, 300, 13, 0, 0, 0, 0, 49, 0, edit_1, NULL, NULL }, |
| 26 | |
| 27 | /* keyboard intakes */ |
| 28 | { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0,KEY_ENTER, 0, (void*)ptext, NULL, NULL }, |
| 29 | { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void*)func1, NULL, NULL }, |
| 30 | |
| 31 | /* system */ |
| 32 | { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, |
| 33 | { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } |
| 34 | }; |
| 35 | |
| 36 | int main(int argc, char* argv[]) { |
| 37 | allegro_init(); |
| 38 | install_keyboard(); install_timer(); |
| 39 | install_mouse(); |
| 40 | set_color_depth(32); |
| 41 | set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0); |
| 42 | font=load_font("pcx/verdana.pcx",0,0); //one of my fonts |
| 43 | |
| 44 | gui_set_screen(screen); |
| 45 | gui_fg_color=makecol(88,132,176); |
| 46 | gui_mg_color=makecol(0,0,0); |
| 47 | gui_bg_color=makecol(31,47,63); |
| 48 | set_dialog_color(the_dialog,gui_fg_color,gui_bg_color); |
| 49 | |
| 50 | do_dialog(the_dialog,2); |
| 51 | |
| 52 | allegro_exit(); |
| 53 | }END_OF_MAIN() |
The problem is whenever...say...I type something into 'd_edit_proc' and press enter, I have to press another key or hover over the text box to tell it to update. By update I mean show that edit_1 is empty and that text_1 has been added to. How can I fix this?
Sorry for the bad explanation, but I'm not sure how else to explain it =/
I believe the problem is that your edit box captures the ENTER. Why don't you create your own edit box that, if you got an ENTER, raises it to the dialog?
Hmm... can you give me a more detailed explination of what creating my 'own edit box' would consist of?
Like what you mean exactly... This?
Should I use the DIALOG_PLAYER stuff? Well, I guess I'd have to use my method above.
The easiest way is to make your ptext function return D_REDRAW_ALL instead of D_O_K. And, if the user presses ENTER in the edit box, to call ptext.
See here (I deleted a few lines because I am on Linux):
| 1 | #include <allegro.h> |
| 2 | |
| 3 | char text_1[400]="Welcome to this gui thingy!\n\n"; |
| 4 | char edit_1[50]; |
| 5 | |
| 6 | //adds edit_1 to the end of text_1 |
| 7 | int ptext(void) { |
| 8 | ustrcat(text_1,"\n"); |
| 9 | ustrcat(text_1,edit_1); |
| 10 | ustrcpy(edit_1,""); |
| 11 | |
| 12 | return D_REDRAW_ALL; |
| 13 | }; |
| 14 | |
| 15 | int func1(void) { |
| 16 | //alert goes here |
| 17 | return D_O_K; |
| 18 | }; |
| 19 | |
| 20 | DIALOG the_dialog[]; |
| 21 | |
| 22 | int d_myedit_proc(int msg, DIALOG *d, int c) { |
| 23 | if (msg == MSG_CHAR && (c >> 8) == KEY_ENTER) { |
| 24 | ptext(); |
| 25 | return D_O_K; |
| 26 | } |
| 27 | else |
| 28 | return d_edit_proc(msg, d, c); |
| 29 | } |
| 30 | |
| 31 | DIALOG the_dialog[]={ |
| 32 | /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ |
| 33 | { d_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL }, |
| 34 | { d_textbox_proc, 5, 20, 630, 320, 0, 0, 0,D_SELECTED, 0, 0, text_1, NULL, NULL }, |
| 35 | { d_myedit_proc, 5, 342, 300, 13, 0, 0, 0, 0, 49, 0, edit_1, NULL, NULL }, |
| 36 | |
| 37 | /* keyboard intakes */ |
| 38 | { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0,KEY_ENTER, 0, (void*)ptext, NULL, NULL }, |
| 39 | { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void*)func1, NULL, NULL }, |
| 40 | |
| 41 | /* system */ |
| 42 | { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, |
| 43 | { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } |
| 44 | }; |
| 45 | |
| 46 | int main(int argc, char* argv[]) { |
| 47 | allegro_init(); |
| 48 | install_keyboard(); install_timer(); |
| 49 | install_mouse(); |
| 50 | set_color_depth(32); |
| 51 | set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0); |
| 52 | |
| 53 | gui_set_screen(screen); |
| 54 | gui_fg_color=makecol(88,132,176); |
| 55 | gui_mg_color=makecol(0,0,0); |
| 56 | gui_bg_color=makecol(31,47,63); |
| 57 | set_dialog_color(the_dialog,gui_fg_color,gui_bg_color); |
| 58 | |
| 59 | do_dialog(the_dialog,2); |
| 60 | |
| 61 | allegro_exit(); |
| 62 | }END_OF_MAIN() |
A better solution should be to have ptext send a message to the textbox to redraw, so that there is only one redraw. But that is homework for you
Oh wow! Thanks a whole lot! =D