Debian Codegraph @

Descent3/gamefont.cpp

raw symbols SCIP
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"
118 #include "game.h"
119 #include "grtext.h"
120 #include "pserror.h"
121 #include "stringtable.h"
122
123 int Game_fonts[NUM_FONTS] = {
124 0, 0, 0, 0, 0, 0,
125 };
126
127 // HUD font sizes
128 #define HUD_FONT_LOWRES 0
129 #define HUD_FONT_HIGHRES 1
130
131 const char *HUD_font_files[] = {"lohud.fnt", "hihud.fnt"};
132
133 #define HUD_FONT_FILE HUD_font_files[HUD_font_resolution]
134
135 static int HUD_font_resolution = HUD_FONT_LOWRES;
136 static bool Hud_font_template_init = false;
137 tFontTemplate Hud_font_template; // retain hud font template
138
139 void FreeAuxFontData() {
140 if (Hud_font_template_init) {
141 Hud_font_template_init = false;
142 grfont_FreeTemplate(&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 LoadFont(const char *font_name) {
148 int handle = grfont_Load(font_name);
149 if (handle == -1)
150 Error(TXT_ERRNOFONT, font_name);
151
152 mprintf(0, "Font <%s> height = %d\n", font_name, grfont_GetHeight(handle));
153
154 return handle;
155 }
156
157 // loads all game fonts.
158 void LoadAllFonts() {
159 grfont_Reset();
160
161 atexit(FreeAuxFontData);
162
163 if (Hud_font_template_init) {
164 grfont_FreeTemplate(&Hud_font_template);
165 }
166
167 // Load the fonts (except HUD)
168 SMALL_FONT = LoadFont("briefing.fnt");
169 BIG_FONT = LoadFont("bbriefing.fnt");
170 MENU_FONT = LoadFont("newmenu.fnt");
171 SMALL_UI_FONT = LoadFont("smallui.fnt");
172 BIG_UI_FONT = LoadFont("largeui.fnt");
173
174 // Load the HUD font
175 HUD_font_resolution = HUD_FONT_LOWRES;
176 HUD_FONT = LoadFont(HUD_FONT_FILE);
177 if (!grfont_LoadTemplate(HUD_FONT_FILE, &Hud_font_template))
178 Error(TXT_ERRNOFONT, HUD_FONT_FILE);
179 Hud_font_template_init = true;
180 }
181
182 // If screen width greater than this, use the superhires fonts
183 #define SUPERHIRES_THRESHOLD_W 1024
184
185 // Set the HUD font resolution based on the render width
186 void SelectHUDFont(int rend_width) {
187 int fontres = (rend_width >= SUPERHIRES_THRESHOLD_W) ? HUD_FONT_HIGHRES : HUD_FONT_LOWRES;
188
189 if (fontres == HUD_font_resolution)
190 return;
191
192 HUD_font_resolution = fontres;
193
194 grfont_Free(HUD_FONT);
195
196 HUD_FONT = LoadFont(HUD_FONT_FILE);
197 }