From c1d184240d9b620a504b32e84eee7a6d03dac684 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 20 Jul 2014 03:48:27 +0000 Subject: [PATCH] Use unique_ptr to manage fonts --- common/include/editor/editor.h | 2 +- common/include/gr.h | 23 ++++++++++-- common/include/physfsx.h | 11 ++++++ common/include/ui.h | 2 +- common/main/gamefont.h | 2 +- common/main/newmenu.h | 4 +- common/ui/icon.cpp | 2 +- common/ui/keypad.cpp | 34 ++++++++--------- common/ui/message.cpp | 4 +- common/ui/ui.cpp | 9 ++--- similar/2d/font.cpp | 69 ++++++++++++++++------------------ similar/editor/med.cpp | 8 ++-- similar/editor/texpage.cpp | 2 +- similar/main/gamefont.cpp | 7 ++-- similar/main/kconfig.cpp | 7 ++-- similar/main/kmatrix.cpp | 10 ++--- similar/main/net_udp.cpp | 8 ++-- similar/main/newmenu.cpp | 3 +- similar/main/scores.cpp | 8 +--- 19 files changed, 112 insertions(+), 103 deletions(-) diff --git a/common/include/editor/editor.h b/common/include/editor/editor.h index beb20b355..831a371ba 100644 --- a/common/include/editor/editor.h +++ b/common/include/editor/editor.h @@ -169,7 +169,7 @@ extern int Large_view_index; extern UI_GADGET_USERBOX * LargeViewBox; extern int Found_seg_index; // Index in Found_segs corresponding to Cursegp extern int gamestate_not_restored; -extern grs_font *editor_font; +extern grs_font_ptr editor_font; extern vms_vector Ed_view_target; // what editor is looking at diff --git a/common/include/gr.h b/common/include/gr.h index 5b3f6d3b2..aaf155431 100644 --- a/common/include/gr.h +++ b/common/include/gr.h @@ -27,6 +27,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define _GR_H #include +#include #include "pstypes.h" #include "maths.h" #include "palette.h" @@ -148,7 +149,7 @@ struct grs_font : public prohibit_void_ptr struct grs_canvas : public prohibit_void_ptr { grs_bitmap cv_bitmap; // the bitmap for this canvas - grs_font * cv_font; // the currently selected font + const grs_font * cv_font; // the currently selected font short cv_color; // current color short cv_drawmode; // fill,XOR,etc. short cv_font_fg_color; // current font foreground color (-1==Invisible) @@ -315,10 +316,20 @@ void gr_ubox(int left,int top,int right,int bot); void gr_scanline( int x1, int x2, int y ); void gr_uscanline( int x1, int x2, int y ); +void gr_close_font(std::unique_ptr font); + +struct font_delete +{ + void operator()(grs_font *p) const + { + gr_close_font(std::unique_ptr(p)); + } +}; + +typedef std::unique_ptr grs_font_ptr; // Reads in a font file... current font set to this one. -grs_font * gr_init_font( const char * fontfile ); -void gr_close_font( grs_font * font ); +grs_font_ptr gr_init_font( const char * fontfile ); #if defined(DXX_BUILD_DESCENT_I) #define DXX_SDL_WINDOW_CAPTION "Descent" @@ -337,7 +348,11 @@ void gr_remap_mono_fonts(); #endif // Writes a string using current font. Returns the next column after last char. -void gr_set_curfont( grs_font * ); +void gr_set_curfont(const grs_font *); +static inline void gr_set_curfont(const grs_font_ptr &p) +{ + gr_set_curfont(p.get()); +} void gr_set_fontcolor( int fg_color, int bg_color ); void gr_string(int x, int y, const char *s ); void gr_ustring(int x, int y, const char *s ); diff --git a/common/include/physfsx.h b/common/include/physfsx.h index 7613b102f..dbc87cece 100644 --- a/common/include/physfsx.h +++ b/common/include/physfsx.h @@ -15,6 +15,7 @@ #define PHYSFSX_H #include +#include #include #include @@ -100,6 +101,16 @@ static inline PHYSFS_sint64 PHYSFSX_check_read(PHYSFS_file *file, array &v return PHYSFSX_check_read(file, &v[0], S, C); } +template +static inline PHYSFS_sint64 PHYSFSX_check_read(PHYSFS_file *file, const std::unique_ptr &v, PHYSFS_uint32 S, PHYSFS_uint32 C) +{ +#if defined(DXX_HAVE_BUILTIN_CONSTANT_P) && defined(DXX_HAVE_BUILTIN_OBJECT_SIZE) + if (__builtin_object_size(v.get(), 1) != -1 && dxx_builtin_constant_p(S * C > __builtin_object_size(v.get(), 1)) && S * C > __builtin_object_size(v.get(), 1)) + DXX_ALWAYS_ERROR_FUNCTION(dxx_trap_overwrite, "read size exceeds allocated size"); +#endif + return PHYSFS_read(file, v.get(), S, C); +} + template static inline PHYSFS_sint64 PHYSFSX_check_read(PHYSFS_file *file, const RAIIdmem &v, PHYSFS_uint32 S, PHYSFS_uint32 C) { diff --git a/common/include/ui.h b/common/include/ui.h index a6a0469ea..7d014ed3b 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -222,7 +222,7 @@ struct UI_DIALOG #define B1_JUST_RELEASED (event->type == EVENT_MOUSE_BUTTON_UP && event_mouse_get_button(event) == 0) #define B1_DOUBLE_CLICKED (event->type == EVENT_MOUSE_DOUBLE_CLICKED && event_mouse_get_button(event) == 0) -extern grs_font * ui_small_font; +extern grs_font_ptr ui_small_font; extern unsigned char CBLACK,CGREY,CWHITE,CBRIGHT,CRED; extern UI_GADGET * selected_gadget; diff --git a/common/main/gamefont.h b/common/main/gamefont.h index c63a45f3c..01dd9eea0 100644 --- a/common/main/gamefont.h +++ b/common/main/gamefont.h @@ -62,7 +62,7 @@ extern float FNTScaleX, FNTScaleY; #define FSPACY(y) ((float)((y)*(FNTScaleY*(GAME_FONT->ft_h/5)))) #define LINE_SPACING ((float)(FNTScaleY*(grd_curcanv->cv_font->ft_h+(GAME_FONT->ft_h/5)))) -extern grs_font *Gamefonts[MAX_FONTS]; +extern array Gamefonts; void gamefont_init(); void gamefont_close(); diff --git a/common/main/newmenu.h b/common/main/newmenu.h index 930b054d8..cf5e77b2a 100644 --- a/common/main/newmenu.h +++ b/common/main/newmenu.h @@ -321,8 +321,8 @@ static inline void nm_set_item_slider(newmenu_item *ni, const char *text, unsign #define UP_ARROW_MARKER "+" // 135 #define DOWN_ARROW_MARKER "+" // 136 #elif defined(DXX_BUILD_DESCENT_II) -#define UP_ARROW_MARKER ((grd_curcanv->cv_font==GAME_FONT)?"\202":"\207") // 135 -#define DOWN_ARROW_MARKER ((grd_curcanv->cv_font==GAME_FONT)?"\200":"\210") // 136 +#define UP_ARROW_MARKER ((grd_curcanv->cv_font==GAME_FONT.get())?"\202":"\207") // 135 +#define DOWN_ARROW_MARKER ((grd_curcanv->cv_font==GAME_FONT.get())?"\200":"\210") // 136 #endif #define BORDERX (15*(SWIDTH/320)) diff --git a/common/ui/icon.cpp b/common/ui/icon.cpp index 3151612a4..b14f2bc68 100644 --- a/common/ui/icon.cpp +++ b/common/ui/icon.cpp @@ -98,7 +98,7 @@ UI_GADGET_ICON * ui_add_gadget_icon( UI_DIALOG * dlg, const char * text, short x icon->oldposition = 0; icon->position = 0; icon->pressed = 0; - icon->canvas->cv_font = ui_small_font; + icon->canvas->cv_font = ui_small_font.get(); // Call twice to get original; if (f) diff --git a/common/ui/keypad.cpp b/common/ui/keypad.cpp index f57beaeb1..e0c11764d 100644 --- a/common/ui/keypad.cpp +++ b/common/ui/keypad.cpp @@ -107,55 +107,55 @@ void ui_pad_activate( UI_DIALOG * dlg, int x, int y ) n=0; row = 0; col = 0; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=1; row = 0; col = 1; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=2; row = 0; col = 2; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=3; row = 0; col = 3; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=4; row = 1; col = 0; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=5; row = 1; col = 1; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=6; row = 1; col = 2; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=7; row = 1; col = 3; w = 1; h = 2; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=8; row = 2; col = 0; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=9; row = 2; col = 1; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=10; row = 2; col = 2; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=11; row = 3; col = 0; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=12; row = 3; col = 1; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=13; row = 3; col = 2; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=14; row = 3; col = 3; w = 1; h = 2; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=15; row = 4; col = 0; w = 2; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); n=16; row = 4; col = 2; w = 1; h = 1; Pad[n] = ui_add_gadget_button( dlg, x+(bw*col), y+(bh*row), bw*w, bh*h, NULL, NULL ); - Pad[n]->canvas->cv_font = ui_small_font; + Pad[n]->canvas->cv_font = ui_small_font.get(); HotKey[0] = KEY_CTRLED + KEY_NUMLOCK; HotKey[1] = KEY_CTRLED + KEY_PADDIVIDE; diff --git a/common/ui/message.cpp b/common/ui/message.cpp index 915634e9b..33269ed5f 100644 --- a/common/ui/message.cpp +++ b/common/ui/message.cpp @@ -59,13 +59,13 @@ static int messagebox_handler(UI_DIALOG *dlg, d_event *event, messagebox *m) if (event->type == EVENT_UI_DIALOG_DRAW) { - grs_font * temp_font; + const grs_font * temp_font; gr_set_current_canvas( &grd_curscreen->sc_canvas ); temp_font = grd_curscreen->sc_canvas.cv_font; if ( grd_curscreen->sc_w < 640 ) { - grd_curscreen->sc_canvas.cv_font = ui_small_font; + grd_curscreen->sc_canvas.cv_font = ui_small_font.get(); } ui_dialog_set_current_canvas(dlg); diff --git a/common/ui/ui.cpp b/common/ui/ui.cpp index b8c1b869c..35cd6b70d 100644 --- a/common/ui/ui.cpp +++ b/common/ui/ui.cpp @@ -38,17 +38,16 @@ static int Initialized = 0; unsigned char CBLACK,CGREY,CWHITE,CBRIGHT,CRED; -grs_font * ui_small_font = NULL; +grs_font_ptr ui_small_font; void ui_init() { - grs_font * org_font; if (Initialized) return; Initialized = 1; - org_font = grd_curcanv->cv_font; + const grs_font *org_font = grd_curcanv->cv_font; ui_small_font = gr_init_font( "pc6x8.fnt" ); grd_curcanv->cv_font =org_font; @@ -77,9 +76,7 @@ void ui_close() menubar_close(); ui_pad_close(); - - gr_close_font( ui_small_font ); - + ui_small_font.reset(); } return; diff --git a/similar/2d/font.cpp b/similar/2d/font.cpp index 84358012b..1530bef13 100644 --- a/similar/2d/font.cpp +++ b/similar/2d/font.cpp @@ -23,6 +23,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. * */ +#include #include #include #include @@ -47,6 +48,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "ogl_init.h" #endif +#include "compiler-array.h" + #define FONTSCALE_X(x) ((float)(x)*(FNTScaleX)) #define FONTSCALE_Y(x) ((float)(x)*(FNTScaleY)) @@ -54,13 +57,14 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. struct openfont { - char filename[FILENAME_LEN]; + array filename; + // Unowned grs_font *ptr; - char *dataptr; + std::unique_ptr dataptr; }; //list of open fonts, for use (for now) for palette remapping -openfont open_font[MAX_OPEN_FONTS]; +static array open_font; #define BITS_TO_BYTES(x) (((x)+7)>>3) @@ -942,22 +946,15 @@ void (gr_printf)( int x, int y, const char * format, ... ) gr_string( x, y, buffer ); } -void gr_close_font( grs_font * font ) +void gr_close_font(std::unique_ptr font) { if (font) { - int fontnum; - char * font_data; - //find font in list - for (fontnum=0;fontnumft_chars ) d_free( font->ft_chars ); @@ -966,13 +963,14 @@ void gr_close_font( grs_font * font ) d_free( font->ft_bitmaps ); gr_free_bitmap_data(&font->ft_parent_bitmap); #endif - d_free( font ); + auto &f = *i; + f.dataptr.reset(); } } #if defined(DXX_BUILD_DESCENT_II) //remap a font, re-reading its data & palette -static void gr_remap_font( grs_font *font, const char * fontname, char *font_data ); +static void gr_remap_font( grs_font *font, const char * fontname, uint8_t *font_data ); //remap (by re-reading) all the color fonts void gr_remap_color_fonts() @@ -985,7 +983,7 @@ void gr_remap_color_fonts() font = open_font[fontnum].ptr; if (font && (font->ft_flags & FT_COLOR)) - gr_remap_font(font, open_font[fontnum].filename, open_font[fontnum].dataptr); + gr_remap_font(font, &open_font[fontnum].filename[0], open_font[fontnum].dataptr.get()); } } @@ -997,7 +995,7 @@ void gr_remap_mono_fonts() grs_font *font; font = open_font[fontnum].ptr; if (font && !(font->ft_flags & FT_COLOR)) - gr_remap_font(font, open_font[fontnum].filename, open_font[fontnum].dataptr); + gr_remap_font(font, &open_font[fontnum].filename[0], open_font[fontnum].dataptr.get()); } } #endif @@ -1020,10 +1018,8 @@ static void grs_font_read(grs_font *gf, PHYSFS_file *fp) gf->ft_kerndata = (ubyte *)((size_t)PHYSFSX_readInt(fp) - GRS_FONT_SIZE); } -grs_font * gr_init_font( const char * fontname ) +grs_font_ptr gr_init_font( const char * fontname ) { - grs_font *font; - char *font_data; int i,fontnum; unsigned char * ptr; int nchars; @@ -1035,33 +1031,30 @@ grs_font * gr_init_font( const char * fontname ) for (fontnum=0;fontnum font(new grs_font); + grs_font_read(font.get(), fontfile); - MALLOC(font_data, char, datasize); + std::unique_ptr font_data(new uint8_t[datasize]); PHYSFS_read(fontfile, font_data, 1, datasize); - open_font[fontnum].ptr = font; - open_font[fontnum].dataptr = font_data; - nchars = font->ft_maxchar - font->ft_minchar + 1; if (font->ft_flags & FT_PROPORTIONAL) { @@ -1083,7 +1076,7 @@ grs_font * gr_init_font( const char * fontname ) } else { - font->ft_data = (unsigned char *) font_data; + font->ft_data = font_data.get(); font->ft_chars = NULL; font->ft_widths = NULL; @@ -1111,20 +1104,22 @@ grs_font * gr_init_font( const char * fontname ) //set curcanv vars - grd_curcanv->cv_font = font; + grd_curcanv->cv_font = font.get(); grd_curcanv->cv_font_fg_color = 0; grd_curcanv->cv_font_bg_color = 0; #ifdef OGL - ogl_init_font(font); + ogl_init_font(font.get()); #endif - return font; + open_font[fontnum].ptr = font.get(); + open_font[fontnum].dataptr = move(font_data); + return grs_font_ptr(font.release()); } #if defined(DXX_BUILD_DESCENT_II) //remap a font by re-reading its data & palette -void gr_remap_font( grs_font *font, const char * fontname, char *font_data ) +void gr_remap_font( grs_font *font, const char * fontname, uint8_t *font_data ) { int i; int nchars; @@ -1210,7 +1205,7 @@ void gr_remap_font( grs_font *font, const char * fontname, char *font_data ) } #endif -void gr_set_curfont( grs_font * n) +void gr_set_curfont(const grs_font *n) { grd_curcanv->cv_font = n; } diff --git a/similar/editor/med.cpp b/similar/editor/med.cpp index 10d3600e0..6671321b2 100644 --- a/similar/editor/med.cpp +++ b/similar/editor/med.cpp @@ -117,7 +117,7 @@ grs_canvas *Canv_editor_game=&_canv_editor_game; //the game on the editor screen window *Pad_info; // Keypad text -grs_font *editor_font=NULL; +grs_font_ptr editor_font; //where the editor is looking vms_vector Ed_view_target=ZERO_VECTOR; @@ -730,12 +730,12 @@ void init_editor_screen() if (editor_screen_open) return; - grd_curscreen->sc_canvas.cv_font = editor_font; + grd_curscreen->sc_canvas.cv_font = editor_font.get(); //create canvas for game on the editor screen initializing = 1; gr_set_current_canvas(Canv_editor); - Canv_editor->cv_font = editor_font; + Canv_editor->cv_font = editor_font.get(); gr_init_sub_canvas(Canv_editor_game,Canv_editor,GAMEVIEW_X,GAMEVIEW_Y,GAMEVIEW_W,GAMEVIEW_H); //Editor renders into full (320x200) game screen @@ -898,7 +898,7 @@ void close_editor() { ui_close(); - gr_close_font(editor_font); + editor_font.reset(); PHYSFSX_removeRelFromSearchPath("editor/data"); PHYSFSX_removeRelFromSearchPath("editor"); diff --git a/similar/editor/texpage.cpp b/similar/editor/texpage.cpp index 58113ea55..6a3bb03f1 100644 --- a/similar/editor/texpage.cpp +++ b/similar/editor/texpage.cpp @@ -219,7 +219,7 @@ int texpage_do(d_event *event) if (event->type == EVENT_UI_DIALOG_DRAW) { gr_set_current_canvas( TmapnameCanvas ); - gr_set_curfont( ui_small_font ); + gr_set_curfont( ui_small_font.get() ); gr_set_fontcolor( CBLACK, CWHITE ); texpage_redraw(); diff --git a/similar/main/gamefont.cpp b/similar/main/gamefont.cpp index 13adbae82..d85d3e89e 100644 --- a/similar/main/gamefont.cpp +++ b/similar/main/gamefont.cpp @@ -52,7 +52,7 @@ static const char Gamefont_filenames_h[][16] = { "font3-1h.fnt" // Font 4 }; -grs_font *Gamefonts[MAX_FONTS]; +array Gamefonts; int Gamefont_installed=0; float FNTScaleX = 1, FNTScaleY = 1; @@ -81,8 +81,7 @@ static void gamefont_unloadfont(int gf) { if (Gamefonts[gf]){ font_conf[gf].cur=-1; - gr_close_font(Gamefonts[gf]); - Gamefonts[gf]=NULL; + Gamefonts[gf].reset(); } } @@ -92,7 +91,7 @@ static void gamefont_loadfont(int gf,int fi) gamefont_unloadfont(gf); Gamefonts[gf]=gr_init_font(font_conf[gf].font[fi].f.name); }else { - if (Gamefonts[gf]==NULL){ + if (!Gamefonts[gf]){ Gamefonts[gf]=gr_init_font(Gamefont_filenames_l[gf]); font_conf[gf].cur=-1; } diff --git a/similar/main/kconfig.cpp b/similar/main/kconfig.cpp index 173172db3..c842aacbd 100644 --- a/similar/main/kconfig.cpp +++ b/similar/main/kconfig.cpp @@ -818,7 +818,6 @@ static int get_item_height(const kc_item &item, const kc_mitem &mitem) static void kconfig_draw(kc_menu *menu) { grs_canvas * save_canvas = grd_curcanv; - grs_font * save_font; int w = FSPACX(290), h = FSPACY(170); gr_set_current_canvas(NULL); @@ -826,13 +825,13 @@ static void kconfig_draw(kc_menu *menu) gr_set_current_canvas(window_get_canvas(menu->wind)); - save_font = grd_curcanv->cv_font; - grd_curcanv->cv_font = MEDIUM3_FONT; + const grs_font *save_font = grd_curcanv->cv_font; + gr_set_curfont(MEDIUM3_FONT); Assert(!strchr( menu->title, '\n' )); gr_string( 0x8000, FSPACY(8), menu->title ); - grd_curcanv->cv_font = GAME_FONT; + gr_set_curfont(GAME_FONT); gr_set_fontcolor( BM_XRGB(28,28,28), -1 ); gr_string( 0x8000, FSPACY(21), "Enter changes, ctrl-d deletes, ctrl-r resets defaults, ESC exits"); gr_set_fontcolor( BM_XRGB(28,28,28), -1 ); diff --git a/similar/main/kmatrix.cpp b/similar/main/kmatrix.cpp index 6f7cbc963..12360ad02 100644 --- a/similar/main/kmatrix.cpp +++ b/similar/main/kmatrix.cpp @@ -166,7 +166,7 @@ static void kmatrix_draw_coop_names(int *) static void kmatrix_status_msg (fix time, int reactor) { - grd_curcanv->cv_font = GAME_FONT; + gr_set_curfont(GAME_FONT); gr_set_fontcolor(gr_find_closest_color(255,255,255),-1); if (reactor) @@ -198,7 +198,7 @@ static void kmatrix_redraw(kmatrix_screen *km) else { multi_sort_kill_list(); - grd_curcanv->cv_font = MEDIUM3_FONT; + gr_set_curfont(MEDIUM3_FONT); #if defined(DXX_BUILD_DESCENT_II) if (game_mode_capture_flag()) @@ -209,7 +209,7 @@ static void kmatrix_redraw(kmatrix_screen *km) #endif gr_string( 0x8000, FSPACY(10), TXT_KILL_MATRIX_TITLE); - grd_curcanv->cv_font = GAME_FONT; + gr_set_curfont(GAME_FONT); multi_get_kill_list(sorted); kmatrix_draw_names(sorted); @@ -238,9 +238,9 @@ static void kmatrix_redraw_coop() int sorted[MAX_PLAYERS]; multi_sort_kill_list(); - grd_curcanv->cv_font = MEDIUM3_FONT; + gr_set_curfont(MEDIUM3_FONT); gr_string( 0x8000, FSPACY(10), "COOPERATIVE SUMMARY"); - grd_curcanv->cv_font = GAME_FONT; + gr_set_curfont(GAME_FONT); multi_get_kill_list(sorted); kmatrix_draw_coop_names(sorted); diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index 387574cf6..9fb447ed5 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -5170,14 +5170,12 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n nm_draw_background(((SWIDTH-w)/2)-BORDERX,((SHEIGHT-h)/2)-BORDERY,((SWIDTH-w)/2)+w+BORDERX,((SHEIGHT-h)/2)+h+BORDERY); gr_set_current_canvas(window_get_canvas(wind)); - - grd_curcanv->cv_font = MEDIUM3_FONT; - + gr_set_curfont(MEDIUM3_FONT); gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1); #if defined(DXX_BUILD_DESCENT_I) gr_string( 0x8000, FSPACY(35), "NETGAME INFO" ); - grd_curcanv->cv_font = GAME_FONT; + gr_set_curfont(GAME_FONT); gr_printf( FSPACX( 25),FSPACY( 55), "Reactor Life:"); gr_printf( FSPACX( 25),FSPACY( 61), "Max Time:"); gr_printf( FSPACX( 25),FSPACY( 67), "Kill Goal:"); @@ -5226,7 +5224,7 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n #elif defined(DXX_BUILD_DESCENT_II) gr_string( 0x8000, FSPACY(15), "NETGAME INFO"); - grd_curcanv->cv_font = GAME_FONT; + gr_set_curfont(GAME_FONT); gr_string( FSPACX( 25),FSPACY( 35), "Reactor Life:"); gr_string( FSPACX( 25),FSPACY( 41), "Max Time:"); gr_string( FSPACX( 25),FSPACY( 47), "Kill Goal:"); diff --git a/similar/main/newmenu.cpp b/similar/main/newmenu.cpp index 85140b9fc..ec30ddb09 100644 --- a/similar/main/newmenu.cpp +++ b/similar/main/newmenu.cpp @@ -1153,7 +1153,6 @@ static void newmenu_create_structure( newmenu *menu ) { int i,j,aw, tw, th, twidth,fm,right_offset; int nmenus, nothers; - grs_font *save_font; grs_canvas *save_canvas; int string_width, string_height, average_width; @@ -1161,7 +1160,7 @@ static void newmenu_create_structure( newmenu *menu ) gr_set_current_canvas(NULL); - save_font = grd_curcanv->cv_font; + const grs_font *save_font = grd_curcanv->cv_font; tw = th = 0; diff --git a/similar/main/scores.cpp b/similar/main/scores.cpp index 65de62f9b..78c6b5313 100644 --- a/similar/main/scores.cpp +++ b/similar/main/scores.cpp @@ -415,13 +415,9 @@ static int scores_handler(window *wind, d_event *event, scores_menu *menu) nm_draw_background(((SWIDTH-w)/2)-BORDERX,((SHEIGHT-h)/2)-BORDERY,((SWIDTH-w)/2)+w+BORDERX,((SHEIGHT-h)/2)+h+BORDERY); gr_set_current_canvas(window_get_canvas(wind)); - - grd_curcanv->cv_font = MEDIUM3_FONT; - + gr_set_curfont(MEDIUM3_FONT); gr_string( 0x8000, FSPACY(15), TXT_HIGH_SCORES ); - - grd_curcanv->cv_font = GAME_FONT; - + gr_set_curfont(GAME_FONT); gr_set_fontcolor( BM_XRGB(31,26,5), -1 ); gr_string( FSPACX( 71), FSPACY(50), TXT_NAME ); gr_string( FSPACX(122), FSPACY(50), TXT_SCORE );