allegro GUI message box实例

来源:互联网 发布:文艺青年 大师 知乎 编辑:程序博客网 时间:2024/06/16 04:12
#include "allegro5/allegro.h"#include "allegro5/allegro_image.h"#include <allegro5/allegro_primitives.h>#include <allegro5/allegro_native_dialog.h> int showbox(const char* wt, const char* ct, const char* em){int result=al_show_native_message_box(al_get_current_display(),wt,ct,em,NULL,ALLEGRO_MESSAGEBOX_YES_NO);return result;}ALLEGRO_BITMAP *make_err_ima(ALLEGRO_DISPLAY *T_disp){    ALLEGRO_BITMAP *T_img = al_create_bitmap(32,32);   if(!T_img)return 0;   al_set_target_bitmap(T_img);   al_clear_to_color(al_map_rgb(255, 0, 0));   al_draw_line( 0,  0, 32, 32, al_map_rgb(255, 255, 255), 1.5);   al_draw_line(32,  0,  0, 32, al_map_rgb(255, 255, 255), 1.5);   al_set_target_bitmap(al_get_backbuffer(T_disp));   return T_img; }ALLEGRO_BITMAP *smart_ima_loader(const char *image_name){    ALLEGRO_BITMAP *T_img = NULL;   T_img = al_load_bitmap(image_name);    if(!T_img)   {   int flag=showbox("There is a proble when loading an image", "would you like to continue anyway?", image_name);   if(flag==1)   return make_err_ima(al_get_current_display());   else   return NULL;   }   else      return T_img;}int main(){    ALLEGRO_DISPLAY *display = NULL;   ALLEGRO_BITMAP  *image   = NULL;    if(!al_init()){      showbox("Problems when initilizing Allegro","bitch","shit");   }    if(!al_init_image_addon()){      showbox("Problems when initilizing Allegro","bitch","shit");   }    if(!al_init_primitives_addon()){      showbox("Problems when initilizing Allegro","bitch","shit");   }    display = al_create_display(800,600);    if(!display){      showbox("Problems when initilizing Allegro","bitch","shit");   }   //Since all this initializations are very necessary, there is no much we can do in case they fail    image = smart_ima_loader("image.png");    if(!image){      return 0;   }    al_draw_bitmap(image, 200, 200, 0);    al_flip_display();    al_rest(2);    al_destroy_bitmap(image);    return 0;}


原创粉丝点击