📄 rgui.c
字号:
/* Normally this should be done by allegro... */ // Call this BEFORE allegro_init. It seems to crash ModeX in allegro. int i; int nb = 0; char name[10]; vga_modeinfo *info; if (!x_display && !fbcon_enabled) { // Where it is needed... // How many modes... for (i = G320x200x16; i <= GLASTMODE; i++) { if (vga_hasmode(i) && vga_getmodeinfo(i)->bytesperpixel == 1){ nb++; } } if (nb) { gfx_mode_data_svga = malloc(sizeof(GFX_MODE_DATA)*(nb+1)); nb = 0; for (i = G320x200x16; i <= GLASTMODE; i++) { if (vga_hasmode(i) && vga_getmodeinfo(i)->bytesperpixel == 1) { info = vga_getmodeinfo(i); gfx_mode_data_svga[nb].w = info->width; gfx_mode_data_svga[nb].h = info->height; sprintf(name,"%dx%d",info->width,info->height); gfx_mode_data_svga[nb].s = strdup(name); // This allocation is freed implicitly when the program quits nb++; } } gfx_mode_data_svga[nb].w = gfx_mode_data_svga[nb].h = 0; gfx_mode_data_svga[nb].s = NULL; // The array must be sorted for the auto-change res... qsort(gfx_mode_data_svga,nb,sizeof(GFX_MODE_DATA),qsort_modes); gfx_card_getter(-1,&nb); // Get the number of drivers for(i=0; i < nb; i++) if (gfx_card_data[i].id == GFX_SVGALIB) gfx_card_data[i].res_list = gfx_mode_data_svga; } }}#endif#ifdef GFX_FBCON// This is taken directly from fbcon.c (allegro)// I just modify it to store its info in an array instead of opening the file// for EVERY mode change. What are they thinking about ???/* helper to read the relevant parts of a line from fb.modes */static char *get_line (FILE *file){ static char buffer[1024]; char *ch; if (feof (file)) return NULL; fgets (buffer, sizeof buffer, file); if (!strchr (buffer, '\n') && !feof(file)) { do { fgets (buffer, sizeof buffer, file); } while (!strchr (buffer, '\n')); return NULL; } ch = strchr (buffer, '#'); if (ch) *ch = '\0'; ch = strchr (buffer, '\n'); if (ch) *ch = '\0'; ch = buffer; while (uisspace(*ch)) ch++; return ch;}/* read_fbmodes_file: * Assigns timing settings from the fbmodes file or returns 0. */static void read_fbmodes_file (){ char *mode_id = NULL; char *geometry = NULL; char *timings = NULL; int sync = 0; char *s, *t; FILE *fbmodes; int nb=0,i,trouve; char name[10]; fbmodes = fopen ("/etc/fb.modes", "r"); if (!fbmodes) return; do { s = get_line (fbmodes); if (!s) break; t = strchr (s, ' '); if (t) { *t++ = '\0'; while (uisspace(*t)) t++; } else { t = strchr (s, '\0'); } if (!strcmp (s, "mode")) { free (mode_id); free (geometry); free (timings); mode_id = strdup (t); geometry = timings = NULL; sync = 0; } else if (!strcmp (s, "endmode")) { if (geometry && timings) { int mw, mh; sscanf (geometry, "%d %d", &mw, &mh); if (mw < 2000) { // There is a 10224x768 mode in my config !!! trouve = 0; for(i=0; i<nb; i++) if (gfx_mode_data_fb[i].w == mw && gfx_mode_data_fb[i].h == mh) trouve = 1; if (!trouve && nb < MAX_FBMODES) { sprintf(name, "%dx%d",mw,mh); gfx_mode_data_fb[nb].w = mw; gfx_mode_data_fb[nb].h = mh; gfx_mode_data_fb[nb].s = strdup(name); nb++; } } free (mode_id); free (geometry); free (timings); mode_id = geometry = timings = NULL; } } else if (!strcmp (s, "geometry")) { free (geometry); geometry = strdup (t); } else if (!strcmp (s, "timings")) { free (timings); timings = strdup (t); } } while (s); free (mode_id); free (geometry); free (timings); fclose (fbmodes); gfx_mode_data_fb[nb].w = gfx_mode_data_fb[nb].h = 0; gfx_mode_data_fb[nb].s = NULL;}void setup_fb_modes() {// Frame buffer does not like other modes :-( gfx_card_data[0].id = GFX_FBCON; gfx_card_data[0].name = "Frame buffer"; gfx_card_data[0].res_list = gfx_mode_data_fb; // I read ONLY the /etc/fb.modes file. // I don't bother with the allegro config file. read_fbmodes_file(); fbcon_enabled = 1;}#endif// Sadly, I have to make this because I can't switch res as soon as I want.// I have to indicate to the game being loading the mode it will work in// but wait for the gui to be redrawn before switching the res for real...// Note also that the default values are 0 (no change)int bestw,besth; //bestbpp;int switch_res(VIDEO_INFO *vid){ // Try to switch resolution for the game int ta; int w,h,i; GFX_MODE_DATA *res_data; w = vid->screen_x; h = vid->screen_y; if (vid->flags & VIDEO_ROTATE_90 || vid->flags & VIDEO_ROTATE_270) { ta = w; w = h; h = ta; // vertiacal inversion... } //if (w<320) w=320; //if (h<240) h=240; bestw = besth = 9999; // It's quite dangerous to change the type of driver... // For what I know, we could fall in Arcade Monitor mode !!! // Let's stuck to the driver we use now... ta = gfx_card_number(display_cfg.screen_type);#ifdef RAINE_UNIX if (x_display) res_data = gfx_card_data_xfree[ta].res_list; else#endif res_data = gfx_card_data[ta].res_list;#ifdef RAINE_UNIX if (display_cfg.screen_type == GFX_XWINDOWS || display_cfg.screen_type == 0){ bestw = w; besth = h; // EVERY mode is available for a window } else#else#ifdef RAINE_WIN32 if (display_cfg.screen_type == GFX_DIRECTX_WIN || display_cfg.screen_type == GFX_GDI){ bestw = w; besth = h; // same thing for windows ! } else#endif #endif for(i=0; res_data[i].s; i++){ if((res_data[i].w<w)||(res_data[i].h < h)) continue; if (res_data[i].w<bestw || res_data[i].h<besth){ bestw = res_data[i].w; besth = res_data[i].h; } break; // No need to go further... } memcpy(&prev_display_cfg, &display_cfg, sizeof(DISPLAY_CFG));#if 0 // Eventually set the bpp here... if (vid->flags & VIDEO_NEEDS_16BPP) { bestbpp = 16; } else { bestbpp = 8; }#endif if (display_cfg.screen_x != bestw || display_cfg.screen_y != besth) //|| display_cfg.bpp != (UINT32)bestbpp) return 1; bestw = besth = 0; // No change !!! (= bestbpp) return 0;}// gfx_card_name():// Get card name for card IDchar *gfx_card_name(UINT32 index){ int ta,tb;#ifdef RAINE_UNIX if (x_display) { tb = (sizeof(gfx_card_data_xfree) / sizeof(GFX_CARD_DATA)); for(ta=0;ta<tb;ta++){ if(gfx_card_data_xfree[ta].id == index){ return gfx_card_data_xfree[ta].name; } } return gfx_card_data_xfree[0].name; // Autodetect }#endif tb = (sizeof(gfx_card_data) / sizeof(GFX_CARD_DATA)); for(ta=0;ta<tb;ta++){ if(gfx_card_data[ta].id == index){ return gfx_card_data[ta].name; } } return gfx_card_data[0].name; // Autodetect}// gfx_card_number():// Get card number for card IDint gfx_card_number(UINT32 index){ int ta,tb;#ifdef RAINE_UNIX if (x_display) { tb = (sizeof(gfx_card_data_xfree) / sizeof(GFX_CARD_DATA)); for(ta=0;ta<tb;ta++){ if(gfx_card_data_xfree[ta].id == index){ return ta; } } } else {#endif tb = (sizeof(gfx_card_data) / sizeof(GFX_CARD_DATA)); for(ta=0;ta<tb;ta++){ if(gfx_card_data[ta].id == index){ return ta; } }#ifdef RAINE_UNIX } #endif return 0; // Autodetect}// gfx_card_id():// Get card ID for card numberint gfx_card_id(int index){#ifdef RAINE_UNIX if (x_display) { if((index>=0)&&(index<(sizeof(gfx_card_data_xfree) / sizeof(GFX_CARD_DATA)))){ return gfx_card_data_xfree[index].id; } return gfx_card_data_xfree[0].id; // XWindows (default) }#endif if((index>=0)&&(index<(sizeof(gfx_card_data) / sizeof(GFX_CARD_DATA)))){ return gfx_card_data[index].id; } return gfx_card_data[0].id; // Autodetect }static char *frame_skip_getter(int index, int *list_size){ static char *list_data[] = { "Automatic", "1", "2", "3", "4", "5", "6", "7", "8", "9", }; if(index == -1){ if(list_size) *list_size = 10; return NULL; } if(index >= 0) return raine_translate_text(list_data[index]); else return NULL;}static char *screen_effect_getter(int index, int *list_size){ static char *list_data[] = { "None", "Eagle", "Pixel Double", "Double Width", }; if(index == -1){ if(list_size) *list_size = sizeof(list_data) / sizeof(char *); return NULL; } if(index >= 0) return raine_translate_text(list_data[index]); else return NULL;}int screen_radio_proc(int msg, DIALOG *d, int c);int screen_def_edit_proc(int msg, DIALOG *d, int c);DIALOG gfx_mode_dialog[] ={ /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp1) (dp2) (dp3) */ { d_raine_window_proc, 0, 0, 310, 224-20, 255, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Screen Setup", NULL, NULL}, { x_text_proc, 8, 16, 1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Screen Mode:", NULL, NULL}, { x_raine_button_proc, 8, 200-20, 48, 16, 255, GUI_BOX_COL_MIDDLE, 'O', D_EXIT, 0, 0, "&Okay", NULL, NULL}, { x_raine_button_proc, 64, 200-20, 48, 16, 255, GUI_BOX_COL_MIDDLE, 'C', D_EXIT, 0, 0, "&Cancel", NULL, NULL}, { d_raine_list_proc, 8, 28, 140, 68, 255, GUI_BOX_COL_MIDDLE, 0, D_EXIT, 0, 0, gfx_card_getter, NULL, NULL}, { d_raine_list_proc, 156, 28, 140, 68, 255, GUI_BOX_COL_MIDDLE, 0, D_EXIT, 3, 0, gfx_mode_getter, NULL, NULL}, { x_text_proc, 196, 132+4,1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Scanlines:", NULL, NULL}, { x_raine_radio_proc, 196, 142+4,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 0, 1, "Off", NULL, NULL}, { x_raine_radio_proc, 196, 152+4,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 0, 1, "Fullheight", NULL, NULL}, { x_raine_radio_proc, 196, 162+4,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 0, 1, "Halfheight", NULL, NULL}, { x_text_proc, 8, 102, 1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Frame Skip:", NULL, NULL}, { d_raine_list_proc, 8, 112, 80, 20, 255, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, frame_skip_getter, NULL, NULL}, { x_text_proc, 196, 102, 1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "VSync Palette:", NULL, NULL}, { x_raine_radio_proc, 196, 112, 64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 2, 1, "Off", NULL, NULL}, { x_raine_radio_proc, 196, 122, 64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 2, 1, "On", NULL, NULL}, { x_text_proc, 106, 102, 1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Limit Speed:", NULL, NULL}, { x_raine_radio_proc, 106, 112, 64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 3, 1, "Off", NULL, NULL}, { x_raine_radio_proc, 106, 122, 64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 3, 1, "On", NULL, NULL}, { x_text_proc, 106, 132+4,1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Screen Effect:", NULL, NULL}, { d_raine_list_proc, 106, 142+4,64, 20, 255, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, screen_effect_getter, NULL, NULL}, { x_text_proc, 8, 132+4,1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Triple Buffer:", NULL, NULL}, { x_raine_radio_proc, 8, 142+4,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 5, 1, "Off", NULL, NULL}, { x_raine_radio_proc, 8, 152+4,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 5, 1, "On", NULL, NULL}, { x_text_proc, 156, 16, 1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Screen Size:", NULL, NULL}, { x_text_proc, 275, 102,1, 1, 254, GUI_BOX_COL_MIDDLE, 0, 0, 0, 0, "Bpp:", NULL, NULL}, { x_raine_radio_proc, 275, 112,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 6, 1, "8", NULL, NULL}, { x_raine_radio_proc, 275, 122,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 6, 1, "15", NULL, NULL}, { x_raine_radio_proc, 275, 132,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 6, 1, "16", NULL, NULL}, { x_raine_radio_proc, 275, 142,64, 9, 255, GUI_BOX_COL_MIDDLE, 0, 0, 6, 1, "32", NULL, NULL}, { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }};// raine_gfx_mode_select():// Displays the Allegro graphics mode selection dialog, which allows the// user to select a screen mode and graphics card. Stores the selection// in the three variables, and returns zero if it was closed with the // Cancel button, or non-zero if it was OK'd.int raine_gfx_mode_select(void){ int ret; //i; // Wait for user clear_keybuf(); while(gui_mouse_b()){ dialog_oxygen(); }; // Init stuff if(display_cfg.scanlines>2)display_cfg.scanlines=2; gfx_mode_dialog[GFX_SCAN_LIST].flags=0; gfx_mode_dialog[GFX_SCAN_LIST+1].flags=0; gfx_mode_dialog[GFX_SCAN_LIST+2].flags=0; gfx_mode_dialog[GFX_SCAN_LIST+display_cfg.scanlines].flags=D_SELECTED; if(display_cfg.frame_skip>9) display_cfg.frame_skip = 0; gfx_mode_dialog[GFX_FSKIP_LIST].d1 = display_cfg.frame_skip; if(display_cfg.vsync>1)display_cfg.vsync=0; gfx_mode_dialog[GFX_VSYNC_LIST].flags=0; gfx_mode_dialog[GFX_VSYNC_LIST+1].flags=0; gfx_mode_dialog[GFX_VSYNC_LIST+display_cfg.vsync].flags=D_SELECTED; if(display_cfg.limit_speed>1) display_cfg.limit_speed=1; gfx_mode_dialog[GFX_SPEED_LIST].flags=0; gfx_mode_dialog[GFX_SPEED_LIST+1].flags=0; gfx_mode_dialog[GFX_SPEED_LIST+display_cfg.limit_speed].flags=D_SELECTED; gfx_mode_dialog[GFX_EAGLE_LIST].d1 = 0; if(display_cfg.eagle_fx) gfx_mode_dialog[GFX_EAGLE_LIST].d1 = 1; if(display_cfg.pixel_double==1) gfx_mode_dialog[GFX_EAGLE_LIST].d1 = 2; if(display_cfg.pixel_double==2) gfx_mode_dialog[GFX_EAGLE_LIST].d1 = 3; if(display_cfg.triple_buffer>1)display_cfg.triple_buffer=1; gfx_mode_dialog[GFX_TRIPLE_LIST].flags = gfx_mode_dialog[GFX_TRIPLE_LIST+1].flags=0; gfx_mode_dialog[GFX_TRIPLE_LIST+display_cfg.triple_buffer].flags=D_SELECTED;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -