X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: degoble AT gtech (David. E. Goble) Newsgroups: comp.os.linux.development.apps,comp.os.msdos.djgpp Subject: help with allegro - no idea Date: Mon, 03 Dec 2001 00:13:23 GMT Organization: Gtech.Computing Message-ID: <3c09dcd6.14872259@gtech> X-Newsreader: Forte Free Agent 1.21/32.243 NNTP-Posting-Host: 203.48.5.216 X-Trace: 4 Dec 2001 12:31:58 +1050, 203.48.5.216 Lines: 220 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi All; I have no idea what Iam doing, so if you could help me, please. Why is the code not working. What I want is the horziontal menu to be displayed until the user selects file|quit and not to quit when the user selects @|about. I have looked at the allegro docs, but as I said, I have no idea what Iam doing. /* test of using allegro lib gcc foo.c -o foo.exe -lalleg */ #include #include #include "allegro.h" #include "example.h" #define BLUE 4 #define PINK 5 #define LT_BLUE 6 #define GREY 7 #define LT_GREY 8 #define BLACK 255 #define WHITE 0 #define FG LT_BLUE #define BG BLUE /* we need to load example.dat to access the big font */ DATAFILE *datafile; /* index of the listbox object in the dialog array */ #define LISTBOX_OBJECT 4 /* for the d_edit_proc() object */ char the_string[32] = "Change Me!"; /* since we change the font, we need to store a copy of the original one */ FONT *original_font; /* A custom dialog procedure for the 'change font' button. This uses a * simple form of inheritance: it calls d_button_proc() to do most of * the work, so it behaves exactly like any other button, but when the * button is clicked and d_button_proc() returns D_CLOSE, it intercepts * the message and changes the font instead. */ int change_font_proc(int msg, DIALOG *d, int c) { int ret; /* call the parent object */ ret=d_button_proc(msg, d, c); /* trap the close return value and change the font */ if (ret==D_CLOSE) { if(font==original_font) font=datafile[BIG_FONT].dat; else font=original_font; return D_REDRAW; } /* otherwise just return */ return ret; } /* callback function to specify the contents of the listbox */ char *listbox_getter(int index, int *list_size) { static char *strings[]= { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" }; if(index<0) { *list_size=11; return NULL; } else return strings[index]; } int credits_proc(void) { char buf1[256], buf2[80], buf3[80]; /* set text lines for alert */ sprintf(buf3, "Writtren By David. E. Goble"); sprintf(buf2, ""); sprintf(buf1, "Kangaroo Island Pistol Club"); /* display alert */ alert(buf1, buf2, buf3, "OK", NULL, 0, 0); return 999; } int quit_proc(void) { return D_CLOSE; } MENU apple_menu[]= { {"&About", credits_proc, NULL, 0, NULL}, {"", NULL, NULL, 0, NULL}, {NULL, NULL, NULL, 0, NULL} }; MENU file_menu[]= { {"&New", NULL, NULL, 0, NULL}, {"&Open", NULL, NULL, 0, NULL}, {"&Save", NULL, NULL, 0, NULL}, {"Save &As", NULL, NULL, 0, NULL}, {"", NULL, NULL, 0, NULL}, {"&Quit", quit_proc, NULL, 0, NULL}, {NULL, NULL, NULL, 0, NULL} }; MENU edit_menu[]= { {"&Undo", NULL, NULL, 0, NULL}, {"", NULL, NULL, 0, NULL}, {"Cu&t", NULL, NULL, 0, NULL}, {"&Copy", NULL, NULL, 0, NULL}, {"&Paste", NULL, NULL, 0, NULL}, {"De&lete", NULL, NULL, 0, NULL}, {NULL, NULL, NULL, 0, NULL} }; MENU menu[]= { {"@", NULL, apple_menu, 0, NULL}, {"&File", NULL, file_menu, 0, NULL}, {"&Edit", NULL, edit_menu, 0, NULL}, {NULL, NULL, NULL, 0, NULL} }; DIALOG the_dialog[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ { d_clear_proc, 0, 0, 0, 0, FG, BG, 0, 0, 0, 0, NULL, NULL, NULL }, { d_menu_proc, 0, 0, 0, 0, FG, BG, 0, 0, 0, 0, menu, NULL, NULL }, /* { d_edit_proc, 80, 32, 512, 48, FG, BG, 0, 0, sizeof(the_string)-1, 0, the_string, NULL, NULL }, { d_button_proc, 80, 132, 160, 48, FG, BG, 't', 0, 0, 0, "&Toggle Me", NULL, NULL }, { d_list_proc, 360, 100, 206, 206, FG, BG, 0, 0, 0, 0, listbox_getter, NULL, NULL }, { change_font_proc, 80, 232, 160, 48, FG, BG, 'f', D_EXIT, 0, 0, "Change &Font", NULL, NULL }, */ { NULL, 0, 0, 0, 0, FG, BG, 0, 0, 0, 0, NULL, NULL, NULL } }; int main(int argc, char *argv[]) { char buf1[256], buf2[80], buf3[80]; int ret; /* initialise everything */ allegro_init(); install_keyboard(); install_mouse(); install_timer(); /* set the colors */ gui_fg_color=FG; gui_bg_color=BG; set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); set_palette(desktop_pallete); /* load the datafile */ replace_filename(buf1, argv[0], "example.dat", sizeof(buf1)); datafile=load_datafile(buf1); if(!datafile) { allegro_exit(); printf("Error loading %s!\n\n", buf1); return 1; } /* store a copy of the default font */ original_font=font; do { ret=do_dialog(the_dialog, -1); printf("in loop ret=%d\n",ret); } while(ret!=D_CLOSE); printf("out of loop ret=%d\n",ret); /* set text lines for alert */ /* sprintf(buf1, "do_dialog() returned %d", ret); sprintf(buf2, "string is '%s'", the_string); sprintf(buf3, "listbox selection is %d", the_dialog[LISTBOX_OBJECT].d1); */ /* display alert */ /* alert(buf1, buf2, buf3, "OK", NULL, 0, 0); */ unload_datafile(datafile); return 0; } END_OF_MAIN();