]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
add a new "scale" property in font files. Specifying, e.g., "scale 1.2" in a font...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 29 Jul 2008 09:42:13 +0000 (09:42 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 29 Jul 2008 09:42:13 +0000 (09:42 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8429 d7cf8633-e32d-0410-b094-e92efae38249

console.c
draw.h
gl_draw.c
sbar.c

index ab1af14e7003f6fbb3d6eb6dd2954169aa9f5114..14642f1b3347e52df4ecfd012970fb6a7e7277c7 100644 (file)
--- a/console.c
+++ b/console.c
@@ -1195,7 +1195,7 @@ float Con_WordWidthFunc(void *passthrough, const char *w, size_t *length, float
        if(w == NULL)
        {
                ti->colorindex = -1;
-               return ti->fontsize * ti->font->width_of[0];
+               return ti->fontsize * ti->font->maxwidth;
        }
        if(maxWidth >= 0)
                return DrawQ_TextWidth_Font_UntilWidth(w, length, false, ti->font, maxWidth / ti->fontsize) * ti->fontsize;
diff --git a/draw.h b/draw.h
index 17c366bc8d975f8d7ed34e591c52c0f68ee9af33..c4bf81d9bc27f9ba1b6a8aa8752dd8db59eed25e 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -81,7 +81,9 @@ DRAWFLAG_NUMFLAGS
 typedef struct dp_font_s
 {
        rtexture_t *tex;
-       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
+       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!)
        char texpath[MAX_QPATH];
        char title[MAX_QPATH];
 }
index f6a7532c1cc2ef90323b25e806d970d443cfef62..6bb31b205e59b14fdd2d490d90e291dbf0e1d3e2 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -601,7 +601,7 @@ extern int con_linewidth; // to force rewrapping
 static void LoadFont(qboolean override, const char *name, dp_font_t *fnt)
 {
        int i;
-       float maxwidth;
+       float maxwidth, scale;
        char widthfile[MAX_QPATH];
        char *widthbuf;
        fs_offset_t widthbufsize;
@@ -624,6 +624,7 @@ static 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)))
@@ -643,6 +644,12 @@ static void LoadFont(qboolean override, const char *name, dp_font_t *fnt)
                                        return;
                                extraspacing = atof(com_token);
                        }
+                       else if(!strcmp(com_token, "scale"))
+                       {
+                               if(!COM_ParseToken_Simple(&p, false, false))
+                                       return;
+                               scale = atof(com_token);
+                       }
                        else
                                fnt->width_of[ch++] = atof(com_token) + extraspacing;
                }
@@ -653,7 +660,11 @@ static void LoadFont(qboolean override, const char *name, dp_font_t *fnt)
        maxwidth = fnt->width_of[1];
        for(i = 2; i < 256; ++i)
                maxwidth = max(maxwidth, fnt->width_of[i]);
-       fnt->width_of[0] = maxwidth;
+       fnt->maxwidth = maxwidth;
+
+       // fix up maxwidth for overlap
+       fnt->maxwidth *= scale;
+       fnt->scale = scale;
 
        if(fnt == FONT_CONSOLE)
                con_linewidth = -1; // rewrap console in next frame
@@ -908,6 +919,8 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
        else
                colorindex = *outcolor;
 
+       maxwidth /= fnt->scale;
+
        for (i = 0;i < *maxlen && text[i];i++)
        {
                if (text[i] == ' ')
@@ -941,7 +954,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
        if (outcolor)
                *outcolor = colorindex;
 
-       return x;
+       return x * fnt->scale;
 }
 
 float DrawQ_String_Font(float startx, float starty, const char *text, size_t maxlen, float w, float h, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt)
@@ -960,6 +973,10 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
        tw = R_TextureWidth(fnt->tex);
        th = R_TextureHeight(fnt->tex);
 
+       starty -= (fnt->scale - 1) * h * 0.5; // center
+       w *= fnt->scale;
+       h *= fnt->scale;
+
        if (maxlen < 1)
                maxlen = 1<<30;
 
diff --git a/sbar.c b/sbar.c
index f1b5ab58c03d2d5629114b7e1ba49ac2f8af1c16..5594495ef4a0702b61799fcb1f0867f8b76dcc27 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -1690,9 +1690,9 @@ float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y)
                        //
                        //
                        c = palette_rgb_pantsscoreboard[(s->colors & 0xf0) >> 4];
-                       DrawQ_Fill(x + 14*8*FONT_SBAR->width_of[0], y+1, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
+                       DrawQ_Fill(x + 14*8*FONT_SBAR->maxwidth, y+1, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
                        c = palette_rgb_shirtscoreboard[s->colors & 0xf];
-                       DrawQ_Fill(x + 14*8*FONT_SBAR->width_of[0], y+4, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
+                       DrawQ_Fill(x + 14*8*FONT_SBAR->maxwidth, y+4, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
                        // print the text
                        //DrawQ_String(x, y, va("%c%4i %s", myself ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0, NULL, true);
                        if (s->qw_ping || s->qw_packetloss)
@@ -1714,9 +1714,9 @@ float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y)
                {
                        // draw colors behind score
                        c = palette_rgb_pantsscoreboard[(s->colors & 0xf0) >> 4];
-                       DrawQ_Fill(x + 9*8*FONT_SBAR->width_of[0], y+1, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
+                       DrawQ_Fill(x + 9*8*FONT_SBAR->maxwidth, y+1, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
                        c = palette_rgb_shirtscoreboard[s->colors & 0xf];
-                       DrawQ_Fill(x + 9*8*FONT_SBAR->width_of[0], y+4, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
+                       DrawQ_Fill(x + 9*8*FONT_SBAR->maxwidth, y+4, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0);
                        // print the text
                        //DrawQ_String(x, y, va("%c%4i %s", myself ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0, NULL, true);
                        if (s->qw_ping || s->qw_packetloss)
@@ -1774,9 +1774,9 @@ void Sbar_DeathmatchOverlay (void)
        ymax = 40 + 8 + (Sbar_IsTeammatch() ? (teamlines * 8 + 5): 0) + scoreboardlines * 8 - 1;
 
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
-               xmin = (vid_conwidth.integer - (26 + 15) * 8 * FONT_SBAR->width_of[0]) / 2; // 26 characters until name, then we assume 15 character names (they can be longer but usually aren't)
+               xmin = (vid_conwidth.integer - (26 + 15) * 8 * FONT_SBAR->maxwidth) / 2; // 26 characters until name, then we assume 15 character names (they can be longer but usually aren't)
        else
-               xmin = (vid_conwidth.integer - (16 + 25) * 8 * FONT_SBAR->width_of[0]) / 2; // 16 characters until name, then we assume 25 character names (they can be longer but usually aren't)
+               xmin = (vid_conwidth.integer - (16 + 25) * 8 * FONT_SBAR->maxwidth) / 2; // 16 characters until name, then we assume 25 character names (they can be longer but usually aren't)
        xmax = vid_conwidth.integer - xmin;
 
        if(gamemode == GAME_NEXUIZ)