Difference for main/newmenu.c from version 1.4 to 1.5


version 1.4 version 1.5
Line 19
 
Line 19
  * Routines for menus.   * Routines for menus.
  *    *
  * $Log$   * $Log$
    * Revision 1.5  1999/11/20 10:05:18  donut
    * variable size menu patch from Jan Bobrowski.  Variable menu font size support and a bunch of fixes for menus that didn't work quite right, by me (MPM).
    *
  * Revision 1.4  1999/09/30 23:02:27  donut   * Revision 1.4  1999/09/30 23:02:27  donut
  * opengl direct support for ingame and normal menus, fonts as textures, and automap support   * opengl direct support for ingame and normal menus, fonts as textures, and automap support
  *   *
Line 554
 
Line 557
  grs_canvas * menu_canvas;   grs_canvas * menu_canvas;
  grs_bitmap * saved; // The background under the menu.   grs_bitmap * saved; // The background under the menu.
  grs_bitmap * background;   grs_bitmap * background;
    int background_is_sub;
 } bkg;  } bkg;
   
 grs_bitmap nm_background;  grs_bitmap nm_background;
Line 571
 
Line 575
 void nm_draw_background1(char * filename)  void nm_draw_background1(char * filename)
 {  {
  int pcx_error;   int pcx_error;
  grs_bitmap *bmp;  
  int x, y;  
   
  gr_clear_canvas( BM_XRGB(0,0,0) );   gr_clear_canvas( BM_XRGB(0,0,0) );
  x = (grd_curcanv->cv_bitmap.bm_w - 320) / 2;   pcx_error = pcx_read_fullscr(filename, NULL);
  y = (grd_curcanv->cv_bitmap.bm_h - 200) / 2;  
  bmp = gr_create_sub_bitmap( &grd_curcanv->cv_bitmap, x, y, 320, 200 );  
  pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,NULL);  
  Assert(pcx_error == PCX_ERROR_NONE);   Assert(pcx_error == PCX_ERROR_NONE);
    
  gr_free_sub_bitmap(bmp);  
 }  }
   
 void nm_draw_background(int x1, int y1, int x2, int y2 )  void nm_draw_background(int x1, int y1, int x2, int y2 )
Line 607
 
Line 603
  w = x2-x1+1;   w = x2-x1+1;
  h = y2-y1+1;   h = y2-y1+1;
   
  if ( w > nm_background.bm_w ) w = nm_background.bm_w;  // if ( w > nm_background.bm_w ) w = nm_background.bm_w;
  if ( h > nm_background.bm_h ) h = nm_background.bm_h;  // if ( h > nm_background.bm_h ) h = nm_background.bm_h;
    // x2 = x1 + w - 1;
  x2 = x1 + w - 1;  // y2 = y1 + h - 1;
  y2 = y1 + h - 1;  
    if ( w > nm_background.bm_w || h > nm_background.bm_h ){//Resize background to fit.  Perhaps it should resize so that the original aspect is preserved, but this looks fine. -MPM
    grs_canvas *tmp,*old;
    old=grd_curcanv;
    tmp=gr_create_sub_canvas(old,x1,y1,w,h);
    gr_set_current_canvas(tmp);
    show_fullscr( &nm_background );
    gr_set_current_canvas(old);
    gr_free_sub_canvas(tmp);
    }else{
  gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );   gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
    }
   
  Gr_scanline_darkening_level = 2*7;   Gr_scanline_darkening_level = 2*7;
   
Line 1119
 
Line 1124
  w += 30;   w += 30;
  h += 30;   h += 30;
   
  if ( w > 320 ) w = 320;   if ( w > SWIDTH ) w = SWIDTH;
  if ( h > 200 ) h = 200;   if ( h > SHEIGHT ) h = SHEIGHT;
   
         x = (grd_curcanv->cv_bitmap.bm_w-w)/2;   x = (GWIDTH-w)/2;
  y = (grd_curcanv->cv_bitmap.bm_h-h)/2;   y = (GHEIGHT-h)/2;
   
  if ( x < 0 ) x = 0;   if ( x < 0 ) x = 0;
  if ( y < 0 ) y = 0;   if ( y < 0 ) y = 0;
Line 1161
 
Line 1166
 #endif  #endif
 //end changes - adb  //end changes - adb
  nm_draw_background(x,y,x+w-1,y+h-1);   nm_draw_background(x,y,x+w-1,y+h-1);
    if (w > nm_background.bm_w || h > nm_background.bm_h){
    bg.background=gr_create_bitmap(w,h);
    gr_bitmap_scale_to(&nm_background,bg.background);
    bg.background_is_sub=0;
    }else{
  bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);   bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
    bg.background_is_sub=1;
    }
  gr_set_current_canvas( bg.menu_canvas );   gr_set_current_canvas( bg.menu_canvas );
  } else {   } else {
  bg.saved = NULL;   bg.saved = NULL;
Line 1181
 
Line 1193
 //end this section change - VR  //end this section change - VR
         {          {
          int sw,sh,aw;           int sw,sh,aw;
    grs_canvas *saved_canvas = grd_curcanv;
    grd_curcanv = &grd_curscreen->sc_canvas;
           grd_curcanv->cv_font = GAME_FONT;            grd_curcanv->cv_font = GAME_FONT;
           gr_get_string_size(DESCENT_VERSION,&sw,&sh,&aw);            gr_get_string_size(DESCENT_VERSION,&sw,&sh,&aw);
           gr_set_fontcolor( GR_GETCOLOR(25,0,0), -1);            gr_set_fontcolor( GR_GETCOLOR(25,0,0), -1);
           gr_printf(grd_curcanv->cv_bitmap.bm_w-sw,grd_curcanv->cv_bitmap.bm_h-sh,DESCENT_VERSION);            gr_printf(GWIDTH-sw,GHEIGHT-sh,DESCENT_VERSION);
      grd_curcanv = saved_canvas;
           Menu_Special = 0;            Menu_Special = 0;
         }          }
         //end this section addition - VR          //end this section addition - VR
   
   
   
  if ( title ) {   if ( title ) {
  grd_curcanv->cv_font = TITLE_FONT;   grd_curcanv->cv_font = TITLE_FONT;
  gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );   gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
Line 1527
 
Line 1541
  // Save the background under the menu...   // Save the background under the menu...
  gr_bitmap(0, 0, bg.saved);    gr_bitmap(0, 0, bg.saved);
  gr_free_bitmap(bg.saved);   gr_free_bitmap(bg.saved);
  free( bg.background );   if (bg.background_is_sub)
    gr_free_sub_bitmap( bg.background );
    else
    gr_free_bitmap( bg.background );
   // free( bg.background );
  } else {   } else {
  gr_bitmap(0, 0, bg.background);    gr_bitmap(0, 0, bg.background);
  gr_free_bitmap(bg.background);   gr_free_bitmap(bg.background);
Line 1663
 
Line 1681
  int demos_deleted=0;   int demos_deleted=0;
  int initialized = 0;   int initialized = 0;
  int exit_value = 0;   int exit_value = 0;
         int w_x, w_y=0, w_w, w_h;   int w_x, w_y=0, w_w, w_h, x=0,blank_w=120;
    int font_height=Gamefonts[GFONT_MEDIUM_1]->ft_h+2, font_height1=font_height-1;
   
  filenames = malloc( MAX_FILES * 14 );   filenames = malloc( MAX_FILES * 14 );
  if (filenames==NULL) return 0;   if (filenames==NULL) return 0;
Line 1693
 
Line 1712
  strncpy(&filenames[NumFiles*14], glob_ret.gl_pathv[j], 13);   strncpy(&filenames[NumFiles*14], glob_ret.gl_pathv[j], 13);
  if (player_mode) {   if (player_mode) {
  char *p;   char *p;
  p = strchr(&filenames[NumFiles*14], '.');   p = strrchr(&filenames[NumFiles*14], '.');
  if (p) *p = '\0';   if (p) *p = '\0';
  }   }
  NumFiles++;   NumFiles++;
Line 1751
 
Line 1770
  set_screen_mode(SCREEN_MENU);   set_screen_mode(SCREEN_MENU);
  gr_set_current_canvas(NULL);   gr_set_current_canvas(NULL);
   
  w_w = 230 - 90 + 1 + 30;  
  w_h = 170 - 30 + 1 + 30;  
    
  if ( w_w > 320 ) w_w = 320;  // w_w = 230 - 90 + 1 + 30;
  if ( w_h > 200 ) w_h = 200;  // w_h = 170 - 30 + 1 + 30;
   
    w_w = GWIDTH - 180*GWIDTH/320 + 1 + 30;
    w_h = GHEIGHT - 60*GHEIGHT/200 + 1 + 30;
    blank_w = 120*GWIDTH/320;
   
    if ( w_w > GWIDTH ) w_w = GWIDTH;//was 320
    if ( w_h > GHEIGHT ) w_h = GHEIGHT;//was 200
    
  w_x = (grd_curcanv->cv_bitmap.bm_w-w_w)/2;   w_x = (GWIDTH-w_w)/2;
  w_y = (grd_curcanv->cv_bitmap.bm_h-w_h)/2;   w_y = (GHEIGHT-w_h)/2;
    
  if ( w_x < 0 ) w_x = 0;   if ( w_x < 0 ) w_x = 0;
  if ( w_y < 0 ) w_y = 0;   if ( w_y < 0 ) w_y = 0;
   
  gr_bm_bitblt(320, 200, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_menu->cv_bitmap) );   gr_bm_bitblt(
    GWIDTH, GHEIGHT,
    0, 0, 0, 0,
    &grd_curcanv->cv_bitmap,
    &VR_offscreen_menu->cv_bitmap
    );
  nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );   nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
   
    x = w_x + (w_w-blank_w)/2;//was +24
   
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_3];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_3];
  gr_string( 0x8000, w_y+10, title );   gr_string( 0x8000, w_y+10, title );
  initialized = 1;   initialized = 1;
Line 1904
 
Line 1935
  gr_setcolor( BM_XRGB( 0,0,0)  );   gr_setcolor( BM_XRGB( 0,0,0)  );
  for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {   for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
  int w, h, aw, y;   int w, h, aw, y;
  y = (i-first_item)*12+w_y+45;   y = (i-first_item)*font_height+w_y+9+font_height*3;//was *12+..+45
  if ( i >= NumFiles ) {   if ( i >= NumFiles ) {
  gr_setcolor( BM_XRGB(0,0,0));   gr_setcolor( BM_XRGB(0,0,0));
  gr_rect( 100, y-1, 220, y+11 );   gr_rect( x, y-1, x+blank_w, y+font_height1 );//was +11
  } else {   } else {
  if ( i == citem )    if ( i == citem )
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];
  else    else
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];
  gr_get_string_size(&filenames[i*14], &w, &h, &aw  );   gr_get_string_size(&filenames[i*14], &w, &h, &aw  );
  gr_rect( 100, y-1, 220, y+11 );   gr_rect( x, y-1, x+blank_w, y+font_height1);//was +11
  gr_string( 105, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0)  );   gr_string( x+5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0)  );
  }   }
  }    }
  } else if ( citem != ocitem ) {   } else if ( citem != ocitem ) {
Line 1923
 
Line 1954
   
  i = ocitem;   i = ocitem;
  if ( (i>=0) && (i<NumFiles) ) {   if ( (i>=0) && (i<NumFiles) ) {
  y = (i-first_item)*12+w_y+45;   y = (i-first_item)*font_height+w_y+9+font_height*3;//was *12+...+45
  if ( i == citem )    if ( i == citem )
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];
  else    else
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];
  gr_get_string_size(&filenames[i*14], &w, &h, &aw  );   gr_get_string_size(&filenames[i*14], &w, &h, &aw  );
  gr_rect( 100, y-1, 220, y+11 );   gr_rect( x, y-1, x+blank_w, y+font_height1 );//was +11
  gr_string( 105, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0)  );   gr_string( x+5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0)  );
  }   }
  i = citem;   i = citem;
  if ( (i>=0) && (i<NumFiles) ) {   if ( (i>=0) && (i<NumFiles) ) {
  y = (i-first_item)*12+w_y+45;   y = (i-first_item)*font_height+w_y+9+font_height*3;//was *12+...+45
  if ( i == citem )    if ( i == citem )
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];
  else    else
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];
  gr_get_string_size(&filenames[i*14], &w, &h, &aw  );   gr_get_string_size(&filenames[i*14], &w, &h, &aw  );
  gr_rect( 100, y-1, 220, y+11 );   gr_rect( x, y-1, x+blank_w, y+font_height1 );//was +11
  gr_string( 105, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0)  );   gr_string( x+5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0)  );
  }   }
  }   }
   
Line 1962
 
Line 1993
  keyd_repeat = old_keyd_repeat;   keyd_repeat = old_keyd_repeat;
   
  if ( initialized ) {   if ( initialized ) {
  gr_bm_bitblt(320, 200, 0, 0, 0, 0, &(VR_offscreen_menu->cv_bitmap), &(grd_curcanv->cv_bitmap) );   gr_bitmap(0, 0, &VR_offscreen_menu->cv_bitmap);
  }   }
   
  if ( filenames )   if ( filenames )
Line 2007
 
Line 2038
  int done, ocitem,citem, ofirst_item, first_item, key, redraw;   int done, ocitem,citem, ofirst_item, first_item, key, redraw;
  int old_keyd_repeat = keyd_repeat;   int old_keyd_repeat = keyd_repeat;
  int width, height, wx, wy, title_height;   int width, height, wx, wy, title_height;
    int font_height,font_height1;
  keyd_repeat = 1;   keyd_repeat = 1;
   
  set_screen_mode(SCREEN_MENU);   set_screen_mode(SCREEN_MENU);
Line 2020
 
Line 2052
  if ( w > width )   if ( w > width )
  width = w;   width = w;
  }   }
  height = 12 * LB_ITEMS_ON_SCREEN;   font_height=Gamefonts[GFONT_MEDIUM_1]->ft_h+2;
    font_height1=font_height-1;
    height = font_height * LB_ITEMS_ON_SCREEN; // was 12*
   
  {   {
  int w, h, aw;   int w, h, aw;
Line 2031
 
Line 2065
  }   }
    
  width += 10;   width += 10;
  if ( width > 320 - 30 )   if ( width > grd_curcanv->cv_bitmap.bm_w - 30 )//was 320 -
  width = 320 - 30;   width = grd_curcanv->cv_bitmap.bm_w - 30;
    
  wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;   wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
  wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;   wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
  if ( wy < title_height )   if ( wy < title_height )
  wy = title_height;   wy = title_height;
   
  gr_bm_bitblt(320, 200, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_menu->cv_bitmap) );   gr_bm_bitblt(grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_menu->cv_bitmap) );
  nm_draw_background( wx-15,wy-title_height-15,wx+width+15,wy+height+15 );   nm_draw_background( wx-15,wy-title_height-15,wx+width+15,wy+height+15 );
   
  gr_string( 0x8000, wy - title_height, title );   gr_string( 0x8000, wy - title_height, title );
Line 2152
 
Line 2186
  gr_setcolor( BM_XRGB( 0,0,0)  );   gr_setcolor( BM_XRGB( 0,0,0)  );
  for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {   for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
  int w, h, aw, y;   int w, h, aw, y;
  y = (i-first_item)*12+wy;   y = (i-first_item)*font_height+wy;//was *12
  if ( i >= nitems ) {   if ( i >= nitems ) {
  gr_setcolor( BM_XRGB(0,0,0));   gr_setcolor( BM_XRGB(0,0,0));
  gr_rect( wx, y-1, wx+width-1, y+11 );   gr_rect( wx, y-1, wx+width-1, y+font_height1 );//was +11
  } else {   } else {
  if ( i == citem )    if ( i == citem )
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];
  else    else
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];
  gr_get_string_size(items[i], &w, &h, &aw  );   gr_get_string_size(items[i], &w, &h, &aw  );
  gr_rect( wx, y-1, wx+width-1, y+11 );   gr_rect( wx, y-1, wx+width-1, y+font_height1 );//was +11
  gr_string( wx+5, y, items[i]  );   gr_string( wx+5, y, items[i]  );
  }   }
  }    }
Line 2174
 
Line 2208
   
  i = ocitem;   i = ocitem;
  if ( (i>=0) && (i<nitems) ) {   if ( (i>=0) && (i<nitems) ) {
  y = (i-first_item)*12+wy;   y = (i-first_item)*font_height+wy;//was *12
  if ( i == citem )    if ( i == citem )
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];
  else    else
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];
  gr_get_string_size(items[i], &w, &h, &aw  );   gr_get_string_size(items[i], &w, &h, &aw  );
  gr_rect( wx, y-1, wx+width-1, y+11 );   gr_rect( wx, y-1, wx+width-1, y+font_height1 );//was +11
  gr_string( wx+5, y, items[i]  );   gr_string( wx+5, y, items[i]  );
  }   }
  i = citem;   i = citem;
  if ( (i>=0) && (i<nitems) ) {   if ( (i>=0) && (i<nitems) ) {
  y = (i-first_item)*12+wy;   y = (i-first_item)*font_height+wy;//was *12
  if ( i == citem )    if ( i == citem )
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_2];
  else    else
  grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];   grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_1];
  gr_get_string_size( items[i], &w, &h, &aw  );   gr_get_string_size( items[i], &w, &h, &aw  );
  gr_rect( wx, y-1, wx+width-1, y+11 );   gr_rect( wx, y-1, wx+width-1, y+font_height1 );//was +11
  gr_string( wx+5, y, items[i]  );   gr_string( wx+5, y, items[i]  );
                                 //added on 9/13/98 by adb to make update-needing arch's work                                  //added on 9/13/98 by adb to make update-needing arch's work
                                 gr_update();                                  gr_update();
Line 2202
 
Line 2236
  }   }
  keyd_repeat = old_keyd_repeat;   keyd_repeat = old_keyd_repeat;
   
  gr_bm_bitblt(320, 200, 0, 0, 0, 0, &(VR_offscreen_menu->cv_bitmap), &(grd_curcanv->cv_bitmap) );   gr_bm_bitblt(grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h, 0, 0, 0, 0, &(VR_offscreen_menu->cv_bitmap), &(grd_curcanv->cv_bitmap) );
   
  return citem;   return citem;
 }  }
Line 2437
 
Line 2471
  gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );   gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
  gr_set_current_canvas( NULL );   gr_set_current_canvas( NULL );
  nm_draw_background(x,y,x+w-1,y+h-1);   nm_draw_background(x,y,x+w-1,y+h-1);
    if (w > nm_background.bm_w || h > nm_background.bm_h){
    bg.background=gr_create_bitmap(w,h);
    gr_bitmap_scale_to(&nm_background,bg.background);
    bg.background_is_sub=0;
    }else{
  bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);   bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
    bg.background_is_sub=1;
    }
  gr_set_current_canvas( bg.menu_canvas );   gr_set_current_canvas( bg.menu_canvas );
  } else {   } else {
  bg.saved = NULL;   bg.saved = NULL;
Line 2786
 
Line 2827
  // Save the background under the menu...   // Save the background under the menu...
  gr_bitmap(0, 0, bg.saved);    gr_bitmap(0, 0, bg.saved);
  gr_free_bitmap(bg.saved);   gr_free_bitmap(bg.saved);
  free( bg.background );   if (bg.background_is_sub)
    gr_free_sub_bitmap( bg.background );
    else
    gr_free_bitmap( bg.background );
   // free( bg.background );
  } else {   } else {
  gr_bitmap(0, 0, bg.background);    gr_bitmap(0, 0, bg.background);
  gr_free_bitmap(bg.background);   gr_free_bitmap(bg.background);

Legend:
line(s) removed in v.1.4 
line(s) changed
 line(s) added in v.1.5