int DosShell() { int ok, w, h; grs_bitmap * save_bitmap; // Save the current graphics state. w = grd_curscreen->sc_canvas.cv_bitmap.bm_w; h = grd_curscreen->sc_canvas.cv_bitmap.bm_h; save_bitmap = gr_create_bitmap( w, h ); gr_bm_ubitblt(w, h, 0, 0, 0, 0, &(grd_curscreen->sc_canvas.cv_bitmap), save_bitmap ); gr_restore_mode(); printf( "\n\nType EXIT to return to Inferno" ); fflush(stdout); key_close(); ok = spawnl(P_WAIT,getenv("COMSPEC"), NULL ); key_init(); gr_set_mode(grd_curscreen->sc_mode); gr_bm_ubitblt(w, h, 0, 0, 0, 0, save_bitmap, &(grd_curscreen->sc_canvas.cv_bitmap)); gr_free_bitmap( save_bitmap ); //gr_pal_setblock( 0, 256, grd_curscreen->pal ); //gr_use_palette_table(); return 1; }
int DosShell() { int ok, w, h; grs_bitmap * save_bitmap; ok = 1; // Save the current graphics state. w = grd_curscreen->sc_canvas.cv_bitmap.bm_w; h = grd_curscreen->sc_canvas.cv_bitmap.bm_h; save_bitmap = gr_create_bitmap( w, h ); gr_bm_ubitblt(w, h, 0, 0, 0, 0, &(grd_curscreen->sc_canvas.cv_bitmap), save_bitmap ); // gr_set_mode( SM_ORIGINAL ); fflush(stdout); key_close(); #ifdef __MSDOS__ ok = spawnl(P_WAIT,getenv("COMSPEC"), NULL ); #endif key_init(); gr_set_mode(grd_curscreen->sc_mode); gr_bm_ubitblt(w, h, 0, 0, 0, 0, save_bitmap, &(grd_curscreen->sc_canvas.cv_bitmap)); gr_free_bitmap( save_bitmap ); //gr_pal_setblock( 0, 256, grd_curscreen->pal ); //gr_use_palette_table(); return ok; }
void ui_mouse_init() { int i, w,h; //mouse_init(); w = grd_curscreen->sc_w; h = grd_curscreen->sc_h; mouse_set_limits( 0,0, w-1, h-1 ); Mouse.x = w/2; Mouse.y = h/2; //mouse_set_pos( w/2, h/2 ); for (i=0; i < PTR_W*PTR_H; i++ ) { switch (ui_mouse_pointer[i]) { case '0': ui_converted_mouse_pointer[i]=255; break; case '1': ui_converted_mouse_pointer[i]=CBLACK; break; case '2': ui_converted_mouse_pointer[i]=CGREY; break; case '3': ui_converted_mouse_pointer[i]=CWHITE; break; case '4': ui_converted_mouse_pointer[i]=CBRIGHT; break; case '5': ui_converted_mouse_pointer[i]=CRED; break; } } default_pointer = gr_create_bitmap_raw( PTR_W, PTR_H, ui_converted_mouse_pointer ); Mouse.x = Mouse.y = 0; Mouse.backwards = 0; Mouse.hidden = 1; Mouse.b1_status = Mouse.b1_last_status = BUTTON_RELEASED; Mouse.b2_status = Mouse.b2_last_status = BUTTON_RELEASED; Mouse.b3_status = Mouse.b3_last_status = BUTTON_RELEASED; Mouse.bg_x = Mouse.bg_y = 0; Mouse.bg_saved = 0; Mouse.pointer = default_pointer; Mouse.background = gr_create_bitmap( Mouse.pointer->bm_w, Mouse.pointer->bm_h ); Mouse.time_lastpressed = 0; Mouse.moved = 0; }
void rle_cache_init() { int i; for (i = 0; i<MAX_CACHE_BITMAPS; i++) { rle_cache[i].rle_bitmap = NULL; rle_cache[i].expanded_bitmap = gr_create_bitmap(64, 64); rle_cache[i].last_used = 0; //Assert( rle_cache[i].expanded_bitmap != NULL ); } rle_cache_initialized = 1; atexit(rle_cache_close); }
void show_fullscr(grs_bitmap *bm) { grs_bitmap * const scr = &grd_curcanv->cv_bitmap; #ifdef OGL if(bm->bm_type == BM_LINEAR && scr->bm_type == BM_OGL && bm->bm_w <= grd_curscreen->sc_w && bm->bm_h <= grd_curscreen->sc_h) // only scale with OGL if bitmap is not bigger than screen size { ogl_ubitmapm_cs(0,0,-1,-1,bm,-1,F1_0);//use opengl to scale, faster and saves ram. -MPM return; } #endif if(scr->bm_type != BM_LINEAR) { grs_bitmap *tmp = gr_create_bitmap(scr->bm_w, scr->bm_h); gr_bitmap_scale_to(bm, tmp); gr_bitmap(0, 0, tmp); gr_free_bitmap(tmp); return; } gr_bitmap_scale_to(bm, scr); }
void menubar_init( char * file ) { int i,j, np; int aw, w, h; CFILE * infile; char buffer[200]; char buf1[200]; char buf2[200]; int menu, item; num_menus = state = 0; for (i=0; i < MAXMENUS; i++ ) { Menu[i].x = Menu[i].y = Menu[i].w = Menu[i].h = 0; Menu[i].ShowBar = 0; Menu[i].CurrentItem = 0; Menu[i].NumItems = 0; Menu[i].Displayed = 0; Menu[i].Background = 0; for (j=0; j< MAXITEMS; j++ ) { Menu[i].Item[j].x = Menu[i].Item[j].y = Menu[i].Item[j].w = Menu[i].Item[j].h = 0; Menu[i].Item[j].Text = NULL; Menu[i].Item[j].Hotkey = -1; Menu[i].Item[j].user_function = NULL; } } infile = cfopen( file, "rt" ); if (!infile) return; while ( cfgets( buffer, 200, infile) != NULL ) { if ( buffer[0] == ';' ) continue; //mprintf( 0, "%s\n", buffer ); CommaParse( 0, buf1, buffer ); menu = atoi( buf1 ); if (menu >= MAXMENUS) Error("Too many menus (%d).",menu); CommaParse( 1, buf1, buffer ); item = atoi(buf1 ); if (item >= MAXITEMS) Error("Too many items (%d) in menu %d.",item+1,menu); CommaParse( 2, buf1, buffer ); ul_xlate(buf1); if (buf1[0] != '-' ) { sprintf( buf2, " %s ", buf1 ); Menu[menu].Item[item].Text = d_strdup(buf2); } else Menu[menu].Item[item].Text = d_strdup(buf1); Menu[menu].Item[item].InactiveText = d_strdup(Menu[menu].Item[item].Text); j= 0; for (i=0; i<=strlen(Menu[menu].Item[item].Text); i++ ) { np = Menu[menu].Item[item].Text[i]; if (np != CC_UNDERLINE) Menu[menu].Item[item].InactiveText[j++] = np; } CommaParse( 3, buf1, buffer ); if (buf1[0]=='{' && buf1[1] =='}') Menu[menu].Item[item].Hotkey = -1; else { i = DecodeKeyText(buf1); if (i<1) { Error("Unknown key, %s, in %s\n", buf1, file ); } else { Menu[menu].Item[item].Hotkey = i; } } CommaParse( 4, buf1, buffer ); if (strlen(buf1)) { Menu[menu].Item[item].user_function = func_get(buf1, &np); // if (!strcmp(buf1,"do-wall-dialog")) { // mprintf( 0, "Found function %s\n", buf1); // mprintf( 0, "User function %s\n", Menu[menu].Item[item].user_function); // } if (Menu[menu].Item[item].user_function==NULL) { Error( "Unknown function, %s, in %s\n", buf1, file ); //ui_messagebox( -2, -2, 1, buffer, "Ok" ); } } Menu[menu].Item[item].x = Menu[menu].x; Menu[menu].Item[item].y = Menu[menu].y; if ( Menu[menu].Item[item].Text[0] == '-' ) { w = 1; h = 3; } else { gr_get_string_size( Menu[menu].Item[item].Text, &w, &h, &aw ); w += 2; h += 2; } if (menu==0) { Menu[0].h = h; Menu[0].Item[item].x = Menu[0].x + Menu[0].w; Menu[0].Item[item].y = Menu[0].y; Menu[item+1].x = Menu[0].x + Menu[0].w; Menu[item+1].y = Menu[0].h - 2; Menu[0].Item[item].w = w; Menu[0].Item[item].h = h; Menu[0].w += w; }else { if ( w > Menu[menu].w ) { Menu[menu].w = w; for (i=0; i< Menu[menu].NumItems; i++ ) Menu[menu].Item[i].w = Menu[menu].w; } Menu[menu].Item[item].w = Menu[menu].w; Menu[menu].Item[item].x = Menu[menu].x; Menu[menu].Item[item].y = Menu[menu].y+Menu[menu].h; Menu[menu].Item[item].h = h; Menu[menu].h += h; } if ( item >= Menu[menu].NumItems ) { Menu[menu].NumItems = item+1; } if ( menu >= num_menus ) num_menus = menu+1; } Menu[0].w = 700; cfclose( infile ); for (i=0; i<num_menus; i++ ) Menu[i].Background = gr_create_bitmap(Menu[i].w, Menu[i].h ); menubar_hid = 1; }
// --------------------------------------------------------------------------------------------------- //this function is the editor. called when editor mode selected. runs until //game mode or exit selected void editor(void) { int w,h; grs_bitmap * savedbitmap; editor_view *new_cv; static int padnum=0; vms_matrix MouseRotMat,tempm; //@@short camera_objnum; //a camera for viewing init_editor(); InitCurve(); restore_effect_bitmap_icons(); if (!set_screen_mode(SCREEN_EDITOR)) { set_screen_mode(SCREEN_GAME); Function_mode=FMODE_GAME; //force back into game return; } gr_set_current_canvas( NULL ); gr_set_curfont(editor_font); //Editor renders into full (320x200) game screen set_warn_func(med_show_warning); keyd_repeat = 1; // Allow repeat in editor // _MARK_("start of editor");//Nuked to compile -KRB ui_mouse_hide(); ui_reset_idle_seconds(); //@@ //create a camera for viewing in the editor. copy position from ConsoleObject //@@ camera_objnum = obj_create(OBJ_CAMERA,0,ConsoleObject->segnum,&ConsoleObject->pos,&ConsoleObject->orient,0); //@@ Viewer = &Objects[camera_objnum]; //@@ slew_init(Viewer); //camera is slewing Viewer = ConsoleObject; slew_init(ConsoleObject); Update_flags = UF_ALL; medlisp_update_screen(); //set the wire-frame window to be the current view current_view = &LargeView; if (faded_in==0) { faded_in = 1; //gr_pal_fade_in( grd_curscreen->pal ); } w = GameViewBox->canvas->cv_bitmap.bm_w; h = GameViewBox->canvas->cv_bitmap.bm_h; savedbitmap = gr_create_bitmap(w, h ); gr_bm_ubitblt( w, h, 0, 0, 0, 0, &GameViewBox->canvas->cv_bitmap, savedbitmap ); gr_set_current_canvas( GameViewBox->canvas ); gr_set_curfont(editor_font); //gr_setcolor( CBLACK ); //gr_deaccent_canvas(); //gr_grey_canvas(); ui_mouse_show(); gr_set_curfont(editor_font); ui_pad_goto(padnum); gamestate_restore_check(); while (Function_mode == FMODE_EDITOR) { gr_set_curfont(editor_font); info_display_all(EditorWindow); ModeFlag = 0; // Update the windows // Only update if there is no key waiting and we're not in // fast play mode. if (!key_peekkey()) //-- && (MacroStatus != UI_STATUS_FASTPLAY)) medlisp_update_screen(); //do editor stuff gr_set_curfont(editor_font); ui_mega_process(); last_keypress &= ~KEY_DEBUGGED; // mask off delete key bit which has no function in editor. ui_window_do_gadgets(EditorWindow); do_robot_window(); do_object_window(); do_wall_window(); do_trigger_window(); do_hostage_window(); do_centers_window(); check_wall_validity(); Assert(Num_walls>=0); if (Gameview_lockstep) { static segment *old_cursegp=NULL; static int old_curside=-1; if (old_cursegp!=Cursegp || old_curside!=Curside) { SetPlayerFromCursegMinusOne(); old_cursegp = Cursegp; old_curside = Curside; } } // mprintf((0, "%d ", ui_get_idle_seconds() )); if ( ui_get_idle_seconds() > COMPRESS_INTERVAL ) { med_compress_mine(); ui_reset_idle_seconds(); } // Commented out because it occupies about 25% of time in twirling the mine. // Removes some Asserts.... // med_check_all_vertices(); clear_editor_status(); // if enough time elapsed, clear editor status message TimedAutosave(mine_filename); set_editor_time_of_day(); gr_set_current_canvas( GameViewBox->canvas ); // Remove keys used for slew switch(last_keypress) { case KEY_PAD9: case KEY_PAD7: case KEY_PADPLUS: case KEY_PADMINUS: case KEY_PAD8: case KEY_PAD2: case KEY_LBRACKET: case KEY_RBRACKET: case KEY_PAD1: case KEY_PAD3: case KEY_PAD6: case KEY_PAD4: last_keypress = 0; } if ((last_keypress&0xff)==KEY_LSHIFT) last_keypress=0; if ((last_keypress&0xff)==KEY_RSHIFT) last_keypress=0; if ((last_keypress&0xff)==KEY_LCTRL) last_keypress=0; if ((last_keypress&0xff)==KEY_RCTRL) last_keypress=0; // if ((last_keypress&0xff)==KEY_LALT) last_keypress=0; // if ((last_keypress&0xff)==KEY_RALT) last_keypress=0; if ((last_keypress&0xff)==KEY_LMETA) last_keypress=0; if ((last_keypress&0xff)==KEY_RMETA) last_keypress=0; gr_set_curfont(editor_font); menubar_do( last_keypress ); //=================== DO FUNCTIONS ==================== if ( KeyFunction[ last_keypress ] != NULL ) { KeyFunction[last_keypress](); last_keypress = 0; } switch (last_keypress) { case 0: case KEY_Z: case KEY_G: case KEY_LALT: case KEY_RALT: case KEY_LCTRL: case KEY_RCTRL: case KEY_LSHIFT: case KEY_RSHIFT: case KEY_LAPOSTRO: break; case KEY_SHIFTED + KEY_L: ToggleLighting(); break; case KEY_F1: render_3d_in_big_window = !render_3d_in_big_window; Update_flags |= UF_ALL; break; default: { char kdesc[100]; GetKeyDescription( kdesc, last_keypress ); editor_status("Error: %s isn't bound to anything.", kdesc ); } } //================================================================ if (ModeFlag==1) { close_editor_screen(); Function_mode=FMODE_EXIT; gr_free_bitmap( savedbitmap ); break; } if (ModeFlag==2) //-- && MacroStatus==UI_STATUS_NORMAL ) { close_editor_screen(); Function_mode = FMODE_MENU; set_screen_mode(SCREEN_MENU); //put up menu screen gr_free_bitmap(savedbitmap); break; } if (ModeFlag==3) //-- && MacroStatus==UI_STATUS_NORMAL ) { // med_compress_mine(); //will be called anyways before game. close_editor_screen(); Function_mode=FMODE_GAME; //force back into game set_screen_mode(SCREEN_GAME); //put up game screen gr_free_bitmap( savedbitmap ); break; } // if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)GameViewBox) current_view=NULL; // if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)GroupViewBox) current_view=NULL; new_cv = current_view ; #if ORTHO_VIEWS if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)LargeViewBox) new_cv=&LargeView; if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)TopViewBox) new_cv=&TopView; if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)FrontViewBox) new_cv=&FrontView; if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)RightViewBox) new_cv=&RightView; #endif if (new_cv != current_view ) { current_view->ev_changed = 1; new_cv->ev_changed = 1; current_view = new_cv; } calc_frame_time(); if (slew_frame(0)) { //do movement and check keys Update_flags |= UF_GAME_VIEW_CHANGED; if (Gameview_lockstep) { Cursegp = &Segments[ConsoleObject->segnum]; med_create_new_segment_from_cursegp(); Update_flags |= UF_ED_STATE_CHANGED; } } // DO TEXTURE STUFF texpage_do(); objpage_do(); // Process selection of Cursegp using mouse. if (LargeViewBox->mouse_onme && LargeViewBox->b1_clicked && !render_3d_in_big_window) { int xcrd,ycrd; xcrd = LargeViewBox->b1_drag_x1; ycrd = LargeViewBox->b1_drag_y1; find_segments(xcrd,ycrd,LargeViewBox->canvas,&LargeView,Cursegp,Big_depth); // Sets globals N_found_segs, Found_segs // If shift is down, then add segment to found list if (keyd_pressed[ KEY_LSHIFT ] || keyd_pressed[ KEY_RSHIFT ]) subtract_found_segments_from_selected_list(); else add_found_segments_to_selected_list(); Found_seg_index = 0; if (N_found_segs > 0) { sort_seg_list(N_found_segs,Found_segs,&ConsoleObject->pos); Cursegp = &Segments[Found_segs[0]]; med_create_new_segment_from_cursegp(); if (Lock_view_to_cursegp) set_view_target_from_segment(Cursegp); } Update_flags |= UF_ED_STATE_CHANGED | UF_VIEWPOINT_MOVED; } if (GameViewBox->mouse_onme && GameViewBox->b1_dragging) { int x, y; x = GameViewBox->b1_drag_x2; y = GameViewBox->b1_drag_y2; ui_mouse_hide(); gr_set_current_canvas( GameViewBox->canvas ); gr_setcolor( 15 ); gr_rect( x-1, y-1, x+1, y+1 ); ui_mouse_show(); } // Set current segment and side by clicking on a polygon in game window. // If ctrl pressed, also assign current texture map to that side. //if (GameViewBox->mouse_onme && (GameViewBox->b1_done_dragging || GameViewBox->b1_clicked)) { if ((GameViewBox->mouse_onme && GameViewBox->b1_clicked && !render_3d_in_big_window) || (LargeViewBox->mouse_onme && LargeViewBox->b1_clicked && render_3d_in_big_window)) { int xcrd,ycrd; int seg,side,face,poly,tmap; if (render_3d_in_big_window) { xcrd = LargeViewBox->b1_drag_x1; ycrd = LargeViewBox->b1_drag_y1; } else { xcrd = GameViewBox->b1_drag_x1; ycrd = GameViewBox->b1_drag_y1; } //Int3(); if (find_seg_side_face(xcrd,ycrd,&seg,&side,&face,&poly)) { if (seg<0) { //found an object Cur_object_index = -seg-1; editor_status("Object %d selected.",Cur_object_index); Update_flags |= UF_ED_STATE_CHANGED; } else { // See if either shift key is down and, if so, assign texture map if (keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]) { Cursegp = &Segments[seg]; Curside = side; AssignTexture(); med_create_new_segment_from_cursegp(); editor_status("Texture assigned"); } else if (keyd_pressed[KEY_G]) { tmap = Segments[seg].sides[side].tmap_num; texpage_grab_current(tmap); editor_status( "Texture grabbed." ); } else if (keyd_pressed[ KEY_LAPOSTRO] ) { ui_mouse_hide(); move_object_to_mouse_click(); } else { Cursegp = &Segments[seg]; Curside = side; med_create_new_segment_from_cursegp(); editor_status("Curseg and curside selected"); } } Update_flags |= UF_ED_STATE_CHANGED; } else editor_status("Click on non-texture ingored"); } // Allow specification of LargeView using mouse if (keyd_pressed[ KEY_LCTRL ] || keyd_pressed[ KEY_RCTRL ]) { ui_mouse_hide(); if ( (Mouse.dx!=0) && (Mouse.dy!=0) ) { GetMouseRotation( Mouse.dx, Mouse.dy, &MouseRotMat ); vm_matrix_x_matrix(&tempm,&LargeView.ev_matrix,&MouseRotMat); LargeView.ev_matrix = tempm; LargeView.ev_changed = 1; Large_view_index = -1; // say not one of the orthogonal views } } else { ui_mouse_show(); } if ( keyd_pressed[ KEY_Z ] ) { ui_mouse_hide(); if ( Mouse.dy!=0 ) { current_view->ev_dist += Mouse.dy*10000; current_view->ev_changed = 1; } } else { ui_mouse_show(); } vid_update(); } // _MARK_("end of editor");//Nuked to compile -KRB clear_warn_func(med_show_warning); //kill our camera object Viewer = ConsoleObject; //reset viewer //@@obj_delete(camera_objnum); padnum = ui_pad_get_current(); close_editor(); ui_close(); }
int state_get_restore_file(char * fname, int multi ) { FILE * fp; int i, choice, version, nsaves; newmenu_item m[NUM_SAVES+1]; char filename[NUM_SAVES][64]; char desc[NUM_SAVES][DESC_LENGTH + 16]; char id[5]; int valid; nsaves=0; m[0].type = NM_TYPE_TEXT; m[0].text = "\n\n\n\n"; for (i=0;i<NUM_SAVES; i++ ) { sc_bmp[i] = NULL; if (!multi) sprintf( filename[i], ":Players:%s.sg%d", Players[Player_num].callsign, i ); else sprintf( filename[i], ":Players:%s.mg%d", Players[Player_num].callsign, i ); valid = 0; fp = fopen( filename[i], "rb" ); if ( fp ) { //Read id fread( id, sizeof(char)*4, 1, fp ); if ( !memcmp( id, dgss_id, 4 )) { //Read version fread( &version, sizeof(int), 1, fp ); if (version >= STATE_COMPATIBLE_VERSION) { // Read description fread( desc[i], sizeof(char)*DESC_LENGTH, 1, fp ); //rpad_string( desc[i], DESC_LENGTH-1 ); m[i+1].type = NM_TYPE_MENU; m[i+1].text = desc[i];; // Read thumbnail sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H ); if (sc_bmp[i]) fread( sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp ); else fseek( fp, THUMBNAIL_W * THUMBNAIL_H, SEEK_CUR ); nsaves++; valid = 1; } } fclose(fp); } if (!valid) { strcpy( desc[i], TXT_EMPTY ); //rpad_string( desc[i], DESC_LENGTH-1 ); m[i+1].type = NM_TYPE_TEXT; m[i+1].text = desc[i]; } } if ( nsaves < 1 ) { nm_messagebox( NULL, 1, "Ok", "No saved games were found!" ); return 0; } sc_last_item = -1; // choice = newmenu_do4( NULL, "Select Game to Restore", NUM_SAVES+1, m, state_callback, state_default_item+1, NULL, 380, -1, 1 ); choice = newmenu_do4( NULL, "Select Game to Restore", NUM_SAVES+1, m, state_callback, state_default_item+1, NULL, -1, -1, 1 ); for (i=0; i<NUM_SAVES; i++ ) { if ( sc_bmp[i] ) gr_free_bitmap( sc_bmp[i] ); } if (choice > 0) { strcpy( fname, filename[choice-1] ); state_default_item = choice - 1; return choice; } return 0; }
int state_get_restore_file(char * fname, int multi) { PHYSFS_file *fp; int i, choice, version, nsaves; newmenu_item m[NUM_SAVES+2]; char filename[NUM_SAVES+1][30]; char desc[NUM_SAVES+1][DESC_LENGTH + 16]; char id[5]; int valid; nsaves=0; m[0].type = NM_TYPE_TEXT; m[0].text = "\n\n\n\n"; for (i=0;i<NUM_SAVES+1; i++ ) { sc_bmp[i] = NULL; if (!multi) sprintf( filename[i], PLAYER_DIR "%s.sg%x", Players[Player_num].callsign, i ); else sprintf( filename[i], PLAYER_DIR "%s.mg%x", Players[Player_num].callsign, i ); valid = 0; fp = PHYSFSX_openReadBuffered(filename[i]); if ( fp ) { //Read id //FIXME: check for swapped file, react accordingly... PHYSFS_read(fp, id, sizeof(char) * 4, 1); if ( !memcmp( id, dgss_id, 4 )) { //Read version PHYSFS_read(fp, &version, sizeof(int), 1); if (version >= STATE_COMPATIBLE_VERSION) { // Read description PHYSFS_read(fp, desc[i], sizeof(char) * DESC_LENGTH, 1); //rpad_string( desc[i], DESC_LENGTH-1 ); m[i+1].type = NM_TYPE_MENU; m[i+1].text = desc[i]; // Read thumbnail sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H ); PHYSFS_read(fp, sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1); if (version >= 9) { ubyte pal[256*3]; PHYSFS_read(fp, pal, 3, 256); gr_remap_bitmap_good( sc_bmp[i], pal, -1, -1 ); } nsaves++; valid = 1; } } PHYSFS_close(fp); } if (!valid) { strcpy( desc[i], TXT_EMPTY ); //rpad_string( desc[i], DESC_LENGTH-1 ); m[i+1].type = NM_TYPE_TEXT; m[i+1].text = desc[i]; } } if ( nsaves < 1 ) { nm_messagebox( NULL, 1, "Ok", "No saved games were found!" ); return 0; } if (Current_display_mode == SM(640,400)) //restore menu won't fit on 640x400 VR_screen_flags ^= VRF_COMPATIBLE_MENUS; sc_last_item = -1; #ifdef NEWMENU_MOUSE Hack_DblClick_MenuMode = 1; #endif RestoringMenu=1; choice = newmenu_do3( NULL, "Select Game to Restore", NUM_SAVES+2, m, state_callback, state_default_item+1, NULL, 190, -1 ); RestoringMenu=0; #ifdef NEWMENU_MOUSE Hack_DblClick_MenuMode = 0; #endif if (Current_display_mode == SM(640,400)) //set flag back VR_screen_flags ^= VRF_COMPATIBLE_MENUS; for (i=0; i<NUM_SAVES+1; i++ ) { if ( sc_bmp[i] ) gr_free_bitmap( sc_bmp[i] ); } if (choice > 0) { strcpy( fname, filename[choice-1] ); if (choice != NUM_SAVES+1) //no new default when restore from autosave state_default_item = choice - 1; return choice; } return 0; }
UI_WINDOW * ui_open_window( short x, short y, short w, short h, int flags ) { UI_WINDOW * wnd; int sw, sh, req_w, req_h; wnd = (UI_WINDOW *)d_malloc(sizeof(UI_WINDOW)); if (wnd==NULL) Error("Could not create window: Out of memory"); W_NEXT = NULL; W_PREV = NULL; add_window_to_end( wnd ); sw = grd_curscreen->sc_w; sh = grd_curscreen->sc_h; // mouse_set_limits( 0,0, sw-1, sh-1 ); req_w = w; req_h = h; if (flags & WIN_BORDER) { x -= BORDER_WIDTH; y -= BORDER_WIDTH; w += 2*BORDER_WIDTH; h += 2*BORDER_WIDTH; } if ( x < 0 ) x = 0; if ( (x+w-1) >= sw ) x = sw - w; if ( y < 0 ) y = 0; if ( (y+h-1) >= sh ) y = sh - h; W_X = x; W_Y = y; W_WIDTH = w; W_HEIGHT = h; W_OLDCANVAS = grd_curcanv; W_GADGET = NULL; wnd->keyboard_focus_gadget = NULL; ui_mouse_hide(); if (flags & WIN_SAVE_BG) { W_BACKGROUND = gr_create_bitmap( w, h ); gr_bm_ubitblt(w, h, 0, 0, x, y, &(grd_curscreen->sc_canvas.cv_bitmap), W_BACKGROUND ); } else W_BACKGROUND = NULL; if (flags & WIN_BORDER) { W_CANVAS = gr_create_sub_canvas( &(grd_curscreen->sc_canvas), x+BORDER_WIDTH, y+BORDER_WIDTH, req_w, req_h ); gr_set_current_canvas( NULL ); ui_draw_frame( x, y, x+w-1, y+h-1 ); } else W_CANVAS = gr_create_sub_canvas( &(grd_curscreen->sc_canvas), x, y, req_w, req_h ); gr_set_current_canvas( W_CANVAS ); if (flags & WIN_FILLED) ui_draw_box_out( 0, 0, req_w-1, req_h-1 ); gr_set_fontcolor( CBLACK, CWHITE ); selected_gadget = NULL; W_TEXT_X = 0; W_TEXT_Y = 0; return wnd; }