Client: Added Font_LoadFont() as a wrapper for loadfont(), which will

parse definitions located in the filesystem instead of hardcoding font
paths and sizes.
This commit is contained in:
Marco Cawthorne 2021-06-26 21:45:46 +02:00
parent 75f97827dc
commit e42b714458
12 changed files with 68 additions and 4 deletions

View File

@ -0,0 +1,3 @@
name "16"
font "gfx/shell/arial"
size "16"

View File

@ -0,0 +1,3 @@
name "cr"
font "gfx/shell/arial"
size "20"

View File

@ -0,0 +1,3 @@
name "font"
font "gfx/shell/arial"
size "12"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -113,9 +113,9 @@ void
CSQC_RendererRestarted(string rstr)
{
/* Fonts */
FONT_16 = loadfont("16", "fonts/default", "16", -1);
FONT_20 = loadfont("cr", "creditsfont?fmt=h", "20", -1);
FONT_CON = loadfont("font", "", "12", -1);
FONT_16 = Font_LoadFont("fonts/font16.font");
FONT_20 = Font_LoadFont("fonts/font20.font");
FONT_CON = Font_LoadFont("fonts/fontcon.font");
drawfont = FONT_CON;
/* Particles */

54
src/client/font.qc Normal file
View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2016-2021 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* very basic wrapper around loadfont(), as we don't want to hard-code
* paths to fonts used in the cgame */
float
Font_LoadFont(string filename)
{
string line;
filestream fs_font;
fs_font = fopen(filename, FILE_READ);
if (fs_font < 0) {
print(sprintf("[FONT] ^1WARNING: ^7Could NOT load %s\n", filename));
return -1;
}
string font;
string size;
string shortname;
while ((line = fgets(fs_font))) {
int c = tokenize_console(line);
switch (argv(0)) {
case "font":
font = argv(1);
break;
case "size":
size = argv(1);
break;
case "name":
shortname = argv(1);
break;
}
}
fclose(fs_font);
return loadfont(shortname, font, size, -1);
}

View File

@ -1,5 +1,6 @@
#includelist
fog.qc
font.qc
sky.qc
music.qc
sound.qc

View File

@ -106,7 +106,7 @@ m_init(void)
cvar_set("v_bobup", "0.5");
cvar_set("v_contentblend", "0");
cvar_set("gl_mindist", "4");
cvar_set("con_textsize", "-12");
cvar_set("con_textsize", "12");
cvar_set("scr_conalpha", "1");
cvar_set("scr_sshot_type", "tga");
cvar_set("con_notifylines", "0");