| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/gamefont.cpp $ |
| 21 | * $Revision: 28 $ |
| 22 | * $Date: 9/23/99 12:02p $ |
| 23 | * $Author: Jeff $ |
| 24 | * |
| 25 | * Game Font! |
| 26 | * |
| 27 | * $Log: /DescentIII/main/gamefont.cpp $ |
| 28 | * |
| 29 | * 28 9/23/99 12:02p Jeff |
| 30 | * include stdlib for atexit |
| 31 | * |
| 32 | * 27 5/10/99 10:22p Ardussi |
| 33 | * changes to compile on Mac |
| 34 | * |
| 35 | * 26 5/02/99 11:04p Matt |
| 36 | * Cleaned up HUD font code, now that we have only two sizes of HUD fonts. |
| 37 | * |
| 38 | * 25 4/27/99 2:13p Matt |
| 39 | * Replaced the two (new) new UI fonts with one new font from Doug. |
| 40 | * |
| 41 | * 24 4/26/99 10:34p Matt |
| 42 | * Deleted now-unused UI font. |
| 43 | * |
| 44 | * 23 4/25/99 5:19p Matt |
| 45 | * Revised font definition & loading |
| 46 | * |
| 47 | * 22 4/23/99 9:25p Matt |
| 48 | * Killed 'SMALL_FONT', since it was never being used. |
| 49 | * |
| 50 | * 21 4/16/99 5:06p Matt |
| 51 | * Deleted big UI font, which was unused. |
| 52 | * |
| 53 | * 20 3/02/99 6:26p Samir |
| 54 | * hires font madness. |
| 55 | * |
| 56 | * 19 2/28/99 3:23a Samir |
| 57 | * added superhires fonts. |
| 58 | * |
| 59 | * 18 2/16/99 12:08p Samir |
| 60 | * added new fonts. |
| 61 | * |
| 62 | * 17 10/20/98 3:20p Samir |
| 63 | * added big ui font. |
| 64 | * |
| 65 | * 16 6/16/98 10:38a Jeff |
| 66 | * localization, strings pulled out to stringtable.h and d3.str |
| 67 | * |
| 68 | * 15 5/15/98 5:35p Samir |
| 69 | * allow usage of hires and lores fonts. |
| 70 | * |
| 71 | * 14 4/28/98 11:15a Samir |
| 72 | * added big briefing load font. |
| 73 | * |
| 74 | * 13 4/27/98 10:50a Samir |
| 75 | * new hud font added. |
| 76 | * |
| 77 | * 12 4/16/98 6:51a Samir |
| 78 | * added big briefing font. |
| 79 | * |
| 80 | * 11 4/13/98 7:01p Samir |
| 81 | * added snazzy listbox and edit box art. |
| 82 | * |
| 83 | * 10 4/13/98 4:15p Samir |
| 84 | * hud now has new font, deal with it. |
| 85 | * |
| 86 | * 9 4/13/98 3:32p Samir |
| 87 | * Replaced HUD font with old UI font. |
| 88 | * |
| 89 | * 8 4/03/98 10:27a Samir |
| 90 | * commented out code to load a separate UI font. |
| 91 | * |
| 92 | * 7 3/06/98 3:24p Samir |
| 93 | * uifont = briefing font. |
| 94 | * |
| 95 | * 6 3/05/98 6:40p Samir |
| 96 | * New UI Font. |
| 97 | * |
| 98 | * 5 1/12/98 5:23p Samir |
| 99 | * New fonts. |
| 100 | * |
| 101 | * 4 12/29/97 5:46p Samir |
| 102 | * Modified gamefont system. |
| 103 | * |
| 104 | * 3 12/19/97 11:01a Samir |
| 105 | * Stubbed out functions. |
| 106 | * |
| 107 | * 2 11/10/97 12:56p Samir |
| 108 | * Macros for font rendering using the renderer. |
| 109 | * |
| 110 | * 1 11/04/97 2:03p Samir |
| 111 | * Game fonts. |
| 112 | * |
| 113 | * $NoKeywords: $ |
| 114 | */ |
| 115 | |
| 116 | #include <stdlib.h> |
| 117 | #include "gamefont.h"cxx . . $ `<file>/Descent3/gamefont.h`/ |
| 118 | #include "game.h"cxx . . $ `<file>/Descent3/game.h`/ |
| 119 | #include "grtext.h"cxx . . $ `<file>/grtext/grtext.h`/ |
| 120 | #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/ |
| 121 | #include "stringtable.h"cxx . . $ `<file>/Descent3/stringtable.h`/ |
| 122 | |
| 123 | int Game_fontscxx . . $ Game_fonts.[NUM_FONTScxx . . $ `Descent3/gamefont.h:92:9`!] = { |
| 124 | 0, 0, 0, 0, 0, 0, |
| 125 | }; |
| 126 | |
| 127 | // HUD font sizes |
| 128 | #define HUD_FONT_LOWREScxx . . $ `Descent3/gamefont.cpp:128:9`! 0 |
| 129 | #define HUD_FONT_HIGHREScxx . . $ `Descent3/gamefont.cpp:129:9`! 1 |
| 130 | |
| 131 | const char *HUD_font_filescxx . . $ HUD_font_files.[] = {"lohud.fnt", "hihud.fnt"}; |
| 132 | |
| 133 | #define HUD_FONT_FILEcxx . . $ `Descent3/gamefont.cpp:133:9`! HUD_font_files[HUD_font_resolution] |
| 134 | |
| 135 | static int HUD_font_resolutioncxx . . $ HUD_font_resolution. = HUD_FONT_LOWREScxx . . $ `Descent3/gamefont.cpp:128:9`!; |
| 136 | static bool Hud_font_template_initcxx . . $ Hud_font_template_init. = false; |
| 137 | tFontTemplatecxx . . $ tFontTemplate# Hud_font_templatecxx . . $ Hud_font_template.; // retain hud font template |
| 138 | |
| 139 | void FreeAuxFontDatacxx . . $ FreeAuxFontData(49f6e7a06ebc5aa8).() { |
| 140 | if (Hud_font_template_initcxx . . $ Hud_font_template_init.) { |
| 141 | Hud_font_template_initcxx . . $ Hud_font_template_init. = false; |
| 142 | grfont_FreeTemplatecxx . . $ grfont_FreeTemplate(218f1c398dde951b).(&Hud_font_templatecxx . . $ Hud_font_template.); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Loads the font and returns the handle. Exits with an error if the font can't be found. |
| 147 | int LoadFontcxx . . $ LoadFont(5c4306d8553b3696).(const char *font_name) { |
| 148 | int handle = grfont_Loadcxx . . $ grfont_Load(5c4306d8553b3696).(font_name); |
| 149 | if (handle == -1) |
| 150 | Errorcxx . . $ Error(326aeb464d16410c).(TXT_ERRNOFONTcxx . . $ `Descent3/stringtable.h:122:9`!, font_name); |
| 151 | |
| 152 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Font <%s> height = %d\n", font_name, grfont_GetHeight(handle)); |
| 153 | |
| 154 | return handle; |
| 155 | } |
| 156 | |
| 157 | // loads all game fonts. |
| 158 | void LoadAllFontscxx . . $ LoadAllFonts(49f6e7a06ebc5aa8).() { |
| 159 | grfont_Resetcxx . . $ grfont_Reset(49f6e7a06ebc5aa8).(); |
| 160 | |
| 161 | atexitcxx . . $ atexit(cc8c495369588262).(FreeAuxFontDatacxx . . $ FreeAuxFontData(49f6e7a06ebc5aa8).); |
| 162 | |
| 163 | if (Hud_font_template_initcxx . . $ Hud_font_template_init.) { |
| 164 | grfont_FreeTemplatecxx . . $ grfont_FreeTemplate(218f1c398dde951b).(&Hud_font_templatecxx . . $ Hud_font_template.); |
| 165 | } |
| 166 | |
| 167 | // Load the fonts (except HUD) |
| 168 | SMALL_FONTcxx . . $ `Descent3/gamefont.h:103:9`! = LoadFontcxx . . $ LoadFont(5c4306d8553b3696).("briefing.fnt"); |
| 169 | BIG_FONTcxx . . $ `Descent3/gamefont.h:104:9`! = LoadFontcxx . . $ LoadFont(5c4306d8553b3696).("bbriefing.fnt"); |
| 170 | MENU_FONTcxx . . $ `Descent3/gamefont.h:106:9`! = LoadFontcxx . . $ LoadFont(5c4306d8553b3696).("newmenu.fnt"); |
| 171 | SMALL_UI_FONTcxx . . $ `Descent3/gamefont.h:107:9`! = LoadFontcxx . . $ LoadFont(5c4306d8553b3696).("smallui.fnt"); |
| 172 | BIG_UI_FONTcxx . . $ `Descent3/gamefont.h:108:9`! = LoadFontcxx . . $ LoadFont(5c4306d8553b3696).("largeui.fnt"); |
| 173 | |
| 174 | // Load the HUD font |
| 175 | HUD_font_resolutioncxx . . $ HUD_font_resolution. = HUD_FONT_LOWREScxx . . $ `Descent3/gamefont.cpp:128:9`!; |
| 176 | HUD_FONTcxx . . $ `Descent3/gamefont.h:105:9`! = LoadFontcxx . . $ LoadFont(5c4306d8553b3696).(HUD_FONT_FILEcxx . . $ `Descent3/gamefont.cpp:133:9`!); |
| 177 | if (!grfont_LoadTemplatecxx . . $ grfont_LoadTemplate(5e0be355757499ea).(HUD_FONT_FILEcxx . . $ `Descent3/gamefont.cpp:133:9`!, &Hud_font_templatecxx . . $ Hud_font_template.)) |
| 178 | Errorcxx . . $ Error(326aeb464d16410c).(TXT_ERRNOFONTcxx . . $ `Descent3/stringtable.h:122:9`!, HUD_FONT_FILEcxx . . $ `Descent3/gamefont.cpp:133:9`!); |
| 179 | Hud_font_template_initcxx . . $ Hud_font_template_init. = true; |
| 180 | } |
| 181 | |
| 182 | // If screen width greater than this, use the superhires fonts |
| 183 | #define SUPERHIRES_THRESHOLD_Wcxx . . $ `Descent3/gamefont.cpp:183:9`! 1024 |
| 184 | |
| 185 | // Set the HUD font resolution based on the render width |
| 186 | void SelectHUDFontcxx . . $ SelectHUDFont(d4f767463ce0a6b3).(int rend_width) { |
| 187 | int fontres = (rend_width >= SUPERHIRES_THRESHOLD_Wcxx . . $ `Descent3/gamefont.cpp:183:9`!) ? HUD_FONT_HIGHREScxx . . $ `Descent3/gamefont.cpp:129:9`! : HUD_FONT_LOWREScxx . . $ `Descent3/gamefont.cpp:128:9`!; |
| 188 | |
| 189 | if (fontres == HUD_font_resolutioncxx . . $ HUD_font_resolution.) |
| 190 | return; |
| 191 | |
| 192 | HUD_font_resolutioncxx . . $ HUD_font_resolution. = fontres; |
| 193 | |
| 194 | grfont_Freecxx . . $ grfont_Free(d4f767463ce0a6b3).(HUD_FONTcxx . . $ `Descent3/gamefont.h:105:9`!); |
| 195 | |
| 196 | HUD_FONTcxx . . $ `Descent3/gamefont.h:105:9`! = LoadFontcxx . . $ LoadFont(5c4306d8553b3696).(HUD_FONT_FILEcxx . . $ `Descent3/gamefont.cpp:133:9`!); |
| 197 | } |