⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rgui.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 3 页
字号:
   gfx_mode_dialog[GFX_BPP_LIST].flags = // 8 bpp      gfx_mode_dialog[GFX_BPP_LIST+1].flags= // 15     gfx_mode_dialog[GFX_BPP_LIST+2].flags= // 16     gfx_mode_dialog[GFX_BPP_LIST+3].flags= 0; // 32   if (display_cfg.bpp > 32 || display_cfg.bpp == 24) display_cfg.bpp = 32;   if (display_cfg.bpp < 8) display_cfg.bpp = 8;      switch(display_cfg.bpp) {   case 8 : gfx_mode_dialog[GFX_BPP_LIST+0].flags=D_SELECTED; break;   case 15: gfx_mode_dialog[GFX_BPP_LIST+1].flags=D_SELECTED; break;   case 16: gfx_mode_dialog[GFX_BPP_LIST+2].flags=D_SELECTED; break;   case 32: gfx_mode_dialog[GFX_BPP_LIST+3].flags=D_SELECTED; break;   }         gfx_mode_dialog[GFX_DRIVER_LIST].d1 = gfx_card_number(display_cfg.screen_type);   if(display_cfg.scanlines == 2) display_cfg.screen_y <<= 1;   switch_gfx_res_data(      gfx_card_number(display_cfg.screen_type),      display_cfg.screen_x,      display_cfg.screen_y   );   if(display_cfg.scanlines == 2) display_cfg.screen_y >>= 1;   // Do the selection   ret = raine_do_dialog(gfx_mode_dialog, GFX_DRIVER_LIST);   // Set the results   display_cfg.screen_type = gfx_card_id(gfx_mode_dialog[GFX_DRIVER_LIST].d1);   display_cfg.screen_x = res_data[gfx_mode_dialog[GFX_MODE_LIST].d1].w;   display_cfg.screen_y = res_data[gfx_mode_dialog[GFX_MODE_LIST].d1].h;   if((gfx_mode_dialog[GFX_SCAN_LIST].flags)&D_SELECTED){display_cfg.scanlines=0;};   if((gfx_mode_dialog[GFX_SCAN_LIST+1].flags)&D_SELECTED){display_cfg.scanlines=1;};   if((gfx_mode_dialog[GFX_SCAN_LIST+2].flags)&D_SELECTED){display_cfg.scanlines=2;};   display_cfg.frame_skip = gfx_mode_dialog[GFX_FSKIP_LIST].d1;   if((gfx_mode_dialog[GFX_VSYNC_LIST].flags)&D_SELECTED){display_cfg.vsync=0;};   if((gfx_mode_dialog[GFX_VSYNC_LIST+1].flags)&D_SELECTED){display_cfg.vsync=1;};   if((gfx_mode_dialog[GFX_SPEED_LIST].flags)&D_SELECTED){display_cfg.limit_speed=0;};   if((gfx_mode_dialog[GFX_SPEED_LIST+1].flags)&D_SELECTED){display_cfg.limit_speed=1;};   display_cfg.eagle_fx = 0;   display_cfg.pixel_double = 0;   switch(gfx_mode_dialog[GFX_EAGLE_LIST].d1){      case 1:         display_cfg.eagle_fx = 1;      break;      case 2:         display_cfg.pixel_double = 1;      break;      case 3:         display_cfg.pixel_double = 2;      break;   }   if((gfx_mode_dialog[GFX_TRIPLE_LIST].flags)&D_SELECTED){display_cfg.triple_buffer=0;};   if((gfx_mode_dialog[GFX_TRIPLE_LIST+1].flags)&D_SELECTED){display_cfg.triple_buffer=1;};   if((gfx_mode_dialog[GFX_BPP_LIST].flags)&D_SELECTED)     display_cfg.bpp=8;   else if((gfx_mode_dialog[GFX_BPP_LIST+1].flags)&D_SELECTED)     display_cfg.bpp=15;   else if((gfx_mode_dialog[GFX_BPP_LIST+2].flags)&D_SELECTED)     display_cfg.bpp=16;   else if((gfx_mode_dialog[GFX_BPP_LIST+3].flags)&D_SELECTED)     display_cfg.bpp=32;      if(ret==GFX_CANCEL){return(FALSE);}   else{return(TRUE);}}static DIALOG alert_dialog[] ={   /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key) (flags)  (d1)  (d2)  (dp) */   { d_raine_window_proc,0,   0,    0,    0,    255,  GUI_BOX_COL_MIDDLE,  0,    0,       0,    0,    NULL },   { x_ctext_proc,       0,   0,    0,    0,    254,  GUI_BOX_COL_MIDDLE,  0,    0,       0,    0,    NULL },   { x_ctext_proc,       0,   0,    0,    0,    254,  GUI_BOX_COL_MIDDLE,  0,    0,       0,    0,    NULL },   { x_ctext_proc,       0,   0,    0,    0,    254,  GUI_BOX_COL_MIDDLE,  0,    0,       0,    0,    NULL },   { d_raine_button_proc,0,   0,    0,    0,    255,  GUI_BOX_COL_MIDDLE,  0,    D_EXIT,  0,    0,    NULL },   { d_raine_button_proc,0,   0,    0,    0,    255,  GUI_BOX_COL_MIDDLE,  0,    D_EXIT,  0,    0,    NULL },   { d_raine_button_proc,0,   0,    0,    0,    255,  GUI_BOX_COL_MIDDLE,  0,    D_EXIT,  0,    0,    NULL },   { NULL }};#define A_T1  0#define A_S1  1#define A_S2  2#define A_S3  3#define A_B1  4#define A_B2  5#define A_B3  6// raine_alert3():// Displays a simple alert box, containing three lines of text (s1-s3),// and with either one, two, or three buttons. The text for these buttons // is passed in b1, b2, and b3 (NULL for buttons which are not used), and// the keyboard shortcuts in c1 and c2. Returns 1, 2, or 3 depending on // which button was selected.int raine_alert3(char *title, char *s1, char *s2, char *s3, char *b1, char *b2, char *b3, int c1, int c2, int c3){   int maxlen = 0;   int len1, len2, len3;   int avg_w = text_length(font, " ");   int avg_h = text_height(font);   int buttons = 0;   int b[3];   int c;   #define SORT_OUT_BUTTON(x) {                                            \      if (b##x) {                                                          \	 alert_dialog[A_B##x].flags &= ~D_HIDDEN;                          \	 alert_dialog[A_B##x].key = c##x;                                  \	 alert_dialog[A_B##x].dp = b##x;                                   \	 len##x = gui_strlen(b##x);                                        \	 b[buttons++] = A_B##x;                                            \      }                                                                    \      else {                                                               \	 alert_dialog[A_B##x].flags |= D_HIDDEN;                           \	 len##x = 0;                                                       \      }                                                                    \   }   alert_dialog[A_S1].dp = alert_dialog[A_S2].dp = alert_dialog[A_S3].dp = 			   alert_dialog[A_B1].dp = alert_dialog[A_B2].dp =                            alert_dialog[A_T1].dp = "";   if (s1) {      alert_dialog[A_S1].dp = s1;      maxlen = text_length(font, s1);   }   if (s2) {      alert_dialog[A_S2].dp = s2;      len1 = text_length(font, s2);      if (len1 > maxlen)	 maxlen = len1;   }   if (s3) {      alert_dialog[A_S3].dp = s3;      len1 = text_length(font, s3);      if (len1 > maxlen)	 maxlen = len1;   }   if (title) {      alert_dialog[A_T1].dp = title;      len1 = text_length(font, title);      if (len1 > maxlen)	 maxlen = len1;   }   SORT_OUT_BUTTON(1);   SORT_OUT_BUTTON(2);   SORT_OUT_BUTTON(3);   len1 = MAX(len1, MAX(len2, len3)) + avg_w*3;   if (len1*buttons > maxlen)      maxlen = len1*buttons;   maxlen += avg_w*4;   alert_dialog[0].w = maxlen;   alert_dialog[A_S1].x = alert_dialog[A_S2].x = alert_dialog[A_S3].x = 						alert_dialog[0].x + maxlen/2;   alert_dialog[A_B1].w = alert_dialog[A_B2].w = alert_dialog[A_B3].w = len1;   alert_dialog[A_B1].x = alert_dialog[A_B2].x = alert_dialog[A_B3].x = 				       alert_dialog[0].x + maxlen/2 - len1/2;   if (buttons == 3) {      alert_dialog[b[0]].x = alert_dialog[0].x + maxlen/2 - len1*3/2 - avg_w;      alert_dialog[b[2]].x = alert_dialog[0].x + maxlen/2 + len1/2 + avg_w;   }   else if (buttons == 2) {      alert_dialog[b[0]].x = alert_dialog[0].x + maxlen/2 - len1 - avg_w;      alert_dialog[b[1]].x = alert_dialog[0].x + maxlen/2 + avg_w;   }   alert_dialog[0].y += 10;   alert_dialog[0].h = 10 + avg_h*8;   alert_dialog[A_S1].y = alert_dialog[0].y + avg_h;   alert_dialog[A_S2].y = alert_dialog[0].y + avg_h*2;   alert_dialog[A_S3].y = alert_dialog[0].y + avg_h*3;   alert_dialog[A_S1].h = alert_dialog[A_S2].h = alert_dialog[A_S2].h = avg_h;   alert_dialog[A_B1].y = alert_dialog[A_B2].y = alert_dialog[A_B3].y = 						alert_dialog[0].y + avg_h*5;   alert_dialog[A_B1].h = alert_dialog[A_B2].h = alert_dialog[A_B3].h = avg_h*2;   alert_dialog[0].y -= 10;   centre_dialog(alert_dialog);   clear_keybuf();   while(gui_mouse_b()){      dialog_oxygen();   };   //c = raine_do_dialog(alert_dialog, A_B1);   c = raine_window_dialog(alert_dialog, A_B1);   if (c == A_B1)      return 1;   else if (c == A_B2)      return 2;   else      return 3;}// raine_alert():// Displays a simple alert box, containing three lines of text (s1-s3),// and with either one or two buttons. The text for these buttons is passed// in b1 and b2 (b2 may be null), and the keyboard shortcuts in c1 and c2.// Returns 1 or 2 depending on which button was selected.int raine_alert(char *title, char *s1, char *s2, char *s3, char *b1, char *b2, int c1, int c2){   int ret;   ret = raine_alert3(title, s1, s2, s3, b1, b2, NULL, c1, c2, 0);   if (ret > 2)      ret = 2;   return ret;}/* raine_do_dialog: *  The basic dialog manager. The list of dialog objects should be *  terminated by one with a null dialog procedure. Returns the index of  *  the object which caused it to exit. */#define BUFFER_GUI#ifdef BUFFER_GUIstatic BITMAP *screen_old;static BITMAP *screen_new;static int oxygen_level;#endif// prepare screen for displaying dialogs (bpp, mouse, etc...)void setup_gui_screen(int *kill) {#ifdef BUFFER_GUI   if(!(screen_new)){      show_mouse(NULL);      // This bitmap is used to draw the GUI.      // GUI colors are in 8bpp. If one day we decide to convert it to 16,      // then we will have to change this. But it is very unlikely !!!#ifdef RAINE_DEBUG      print_debug("allocated screen\n");#endif      screen_new = create_bitmap( display_cfg.screen_x,display_cfg.screen_y);      screen_old = screen;      screen     = screen_new;      *kill       = 1;      blit(screen_old,screen_new,0,0,0,0,display_cfg.screen_x,display_cfg.screen_y);   }   else{      *kill       = 0;   }#endif   show_mouse(screen);}void done_gui_screen(int *kill) {#ifdef BUFFER_GUI  if(*kill){#ifdef RAINE_DEBUG      print_debug("Freeing screen\n");#endif    show_mouse(NULL);    dialog_oxygen();    destroy_bitmap(screen_new);    screen     = screen_old;    screen_new = NULL;   }#endif}int raine_do_dialog(DIALOG *dialog, int focus_obj){   void *player;   int ta,kill;#ifdef RAINE_DEBUG   print_debug("raine_do_dialog(): setup_gui_screen\n");#endif   setup_gui_screen(&kill);#ifdef RAINE_DEBUG   print_debug("raine_do_dialog(): init_dialog focus %d\n",focus_obj);#endif   player = init_dialog(dialog, focus_obj);   oxygen_level=0;#ifdef RAINE_DEBUG   print_debug("raine_do_dialog(): loop update %x\n",player);   for (i=0; dialog[i].proc; i++){     print_debug("dlg %d x,y %d,%d\n",i,dialog[i].x,dialog[i].y);   }#endif   while(update_dialog(player)){      if(oxygen_level==0){		// Gasp! Ack!         dialog_oxygen();      }      oxygen_level=0;   }   //show_mouse(mouse_screen);   ta = shutdown_dialog(player);   done_gui_screen(&kill);   return ta;}	    // Stop the mouse freezing, when the game is loading and there// is no oxygen coming in.void mouse_on_real_screen(void){   show_mouse(NULL);   dialog_oxygen();   if (screen_old)     show_mouse(screen_old);}// Restore the mouse to the buffer screen, when oxygen supply// returns.void mouse_on_buffer_screen(void){   show_mouse(screen);   dialog_oxygen();}// Stop the dialog freezing, when the game is loading and there// is no oxygen coming in.void dialog_on_real_screen(void){  if (screen_old)    screen = screen_old;}// Restore the dialog to the buffer screen, when oxygen supply// returns.void dialog_on_buffer_screen(void){   screen = screen_new;}static void save_gui_screen(void){   UINT8 full_name[256];   UINT8 file_name[32];   raine_cfg.req_save_screen = 0;   /*   first try gui.pcx   */   sprintf(file_name, "%s.pcx", "gui");   sprintf(full_name, "%s%s", dir_cfg.screen_dir, file_name);   /*   otherwise, find the next gui_NNN.pcx (or guiNNN.pcx)   */   while( exists(full_name) ){      if(dir_cfg.last_screenshot_num > 999)         return;      if(dir_cfg.long_file_names)         sprintf(file_name, "%s_%03d.pcx", "gui", dir_cfg.last_screenshot_num++);      else         sprintf(file_name, "%.5s%03d.pcx", "gui", dir_cfg.last_screenshot_num++);      sprintf(full_name, "%s%s", dir_cfg.screen_dir, file_name);   };   save_pcx(full_name, screen, gui_pal);   //print_ingame(120, "Screen Saved to %s", file_name);}void dialog_oxygen(void){#ifdef BUFFER_GUI   static int z,z1,z2,z3;   int ta;   int x;   if(raine_cfg.hide){          oxygen_level=1;        }   else{          if(screen_new){		// Ahhhhhhh.... That's better :)       oxygen_level=1;              if(!raine_cfg.wibble){	 	 if (screen_old)	   blit(screen,screen_old,0,0,0,0,display_cfg.screen_x,display_cfg.screen_y);	 	 if(key[KEY_0]) {	   save_gui_screen();	 }	 	        }       else{	 /*	   for(ta=0;ta<display_cfg.screen_y;ta++){	   blit(screen,screen_old,0,ta,0,display_cfg.screen_y-(ta+1),display_cfg.screen_x,1);	   }	 */	 z++;	 	 z1=z/7;	 z1&=255;	 	 z2=z/5;	 z2&=255;	 	 z3=z/1;	 z3&=255;	 z3^=255;	 	 for(ta=0;ta<display_cfg.screen_y;ta++){	   x = fixtoi ( (fsin(itofix(ta+z1)) * 16) + (fsin(itofix(z2-(ta*16))) * 2) + (fsin(itofix(z3-(ta*3))) * 4));	   blit(screen,screen_old,0,ta,x,ta,display_cfg.screen_x,1);	 }	        }     }        }   #endif}/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -