From: vortex Date: Sat, 22 May 2010 23:52:10 +0000 (+0000) Subject: DP_GFX_FONTS: add 2 additional parms to loadfont() - char scale and vertical offset... X-Git-Tag: xonotic-v0.1.0preview~230^2~264 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6e72d351e642c980bf8dd007fdb2617c8932fbb5;p=xonotic%2Fdarkplaces.git DP_GFX_FONTS: add 2 additional parms to loadfont() - char scale and vertical offset, scale are identical to .width file "scale" parm (per-character center-oriented scale that doesn't change line height), vertical offset are added to each char during render, it's a multiplier to character height. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10214 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index ea8c318b..cb22966d 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -801,13 +801,16 @@ float FONT_USER6 = 14; // 'user6', userdefined fonts float FONT_USER7 = 15; // 'user7' slot, userdefined fonts //builtin definitions: float findfont(string s) = #356; // find font by fontname and return it's index -float loadfont(string fontname, string fontmaps, string sizes, float slot) = #357; +float loadfont(string fontname, string fontmaps, string sizes, float slot, float fix_scale, float fix_voffset) = #357; // loads font immediately so stringwidth() function can be used just after builtin call // returns a font slotnum (which is used to set drawfont to) // first 3 parms are identical to "loadfont" console command ones // slot could be one of FONT_ constants or result of findfont() or -1 to not use it // if slot is given, font will be loaded to this slotnum and fontname become new title for it // this way you can rename user* fonts to something more usable +// fix_* parms let you fix badly made fonts by applying some transformations to them +// fix_scale : per-character center-oriented scale (doesn't change line height at all) +// fix_voffset : vertical offset for each character, it's a multiplier to character height float stringwidth(string text, float allowColorCodes, vector size) = #327; // get a width of string with given font and char size float stringwidth_menu(string text, float allowColorCodes, vector size) = #468; // in menu.dat it has different builtin # //description: engine support for custom fonts in console, hud, qc etc. diff --git a/draw.h b/draw.h index 538a44ba..1744419b 100644 --- a/draw.h +++ b/draw.h @@ -105,6 +105,7 @@ typedef struct dp_font_s float width_of[256]; // width_of[0] == max width of any char; 1.0f is base width (1/16 of texture width); therefore, all widths have to be <= 1 (does not include scale) float maxwidth; // precalculated max width of the font (includes scale) float scale; // scales the font (without changing line height!) + float voffset; // offsets the font up/down (without changing line position) char texpath[MAX_QPATH]; char title[MAX_QPATH]; diff --git a/gl_draw.c b/gl_draw.c index 1a7785ec..039a9c91 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -541,10 +541,10 @@ void Draw_FreePic(const char *picname) static float snap_to_pixel_x(float x, float roundUpAt); extern int con_linewidth; // to force rewrapping -void LoadFont(qboolean override, const char *name, dp_font_t *fnt) +void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale, float voffset) { int i; - float maxwidth, scale; + float maxwidth; char widthfile[MAX_QPATH]; char *widthbuf; fs_offset_t widthbufsize; @@ -605,7 +605,6 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt) // unspecified width == 1 (base width) for(i = 1; i < 256; ++i) fnt->width_of[i] = 1; - scale = 1; // FIXME load "name.width", if it fails, fill all with 1 if((widthbuf = (char *) FS_LoadFile(widthfile, tempmempool, true, &widthbufsize))) @@ -682,6 +681,7 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt) // fix up maxwidth for overlap fnt->maxwidth *= scale; fnt->scale = scale; + fnt->voffset = voffset; if(fnt == FONT_CONSOLE) con_linewidth = -1; // rewrap console in next frame @@ -849,7 +849,7 @@ static void LoadFont_f(void) } } - LoadFont(true, mainfont, f); + LoadFont(true, mainfont, f, 1, 0); } /* @@ -870,7 +870,7 @@ static void gl_draw_start(void) // load default font textures for(i = 0; i < dp_fonts.maxsize; ++i) if (dp_fonts.f[i].title[0]) - LoadFont(false, va("gfx/font_%s", &dp_fonts.f[i].title), &dp_fonts.f[i]); + LoadFont(false, va("gfx/font_%s", &dp_fonts.f[i].title), &dp_fonts.f[i], 1, 0); // draw the loading screen so people have something to see in the newly opened window SCR_UpdateLoadingScreen(true); @@ -1378,7 +1378,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma snap = false; } - starty -= (fnt->scale - 1) * h * 0.5; // center + starty -= (fnt->scale - 1) * h * 0.5 - fnt->voffset*h; // center & offset w *= fnt->scale; h *= fnt->scale; diff --git a/prvm_cmds.c b/prvm_cmds.c index 6b8fde31..cb78833c 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -3513,16 +3513,16 @@ float loadfont(string fontname, string fontmaps, string sizes, float slot) */ dp_font_t *FindFont(const char *title, qboolean allocate_new); -void LoadFont(qboolean override, const char *name, dp_font_t *fnt); +void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale, float voffset); void VM_loadfont(void) { const char *fontname, *filelist, *sizes, *c, *cm; char mainfont[MAX_QPATH]; int i, numsizes; - float sz; + float sz, scale, voffset; dp_font_t *f; - VM_SAFEPARMCOUNTRANGE(3,4,VM_loadfont); + VM_SAFEPARMCOUNTRANGE(3,6,VM_loadfont); fontname = PRVM_G_STRING(OFS_PARM0); if (!fontname[0]) @@ -3629,8 +3629,20 @@ void VM_loadfont(void) numsizes++; } + // additional scale/hoffset parms + scale = 1; + voffset = 0; + if (prog->argc >= 5) + { + scale = PRVM_G_FLOAT(OFS_PARM4); + if (scale <= 0) + scale = 1; + } + if (prog->argc >= 6) + voffset = PRVM_G_FLOAT(OFS_PARM5); + // load - LoadFont(true, mainfont, f); + LoadFont(true, mainfont, f, scale, voffset); // return index of loaded font PRVM_G_FLOAT(OFS_RETURN) = (f - dp_fonts.f);