// if r_textshadow is not zero, an additional instance of the text is drawn first at an offset with an inverted shade of gray (black text produces a white shadow, brightly colored text produces a black shadow)
float DrawQ_String(float x, float y, const char *text, size_t maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes);
float DrawQ_String_Font(float x, float y, const char *text, size_t maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt);
+float DrawQ_String_Font_Scale(float x, float y, const char *text, size_t maxlen, float sizex, float sizey, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt);
// you are STRONGLY DISCOURAGED to use a version without the _Size suffix!!!
/* don't use: */float DrawQ_TextWidth_Font(const char *text, size_t maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt);
/* use this: */float DrawQ_TextWidth_Font_Size(const char *text, float w, float h, size_t maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt);
/* use this: */float DrawQ_TextWidth_Font_UntilWidth_Size(const char *text, float w, float h, size_t *maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxWidth);
/* don't use: */float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth);
/* use this: */float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w, float h, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth);
+/* use this: */float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, float w, float h, float sw, float sh, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth);
// draw a very fancy pic (per corner texcoord/color control), the order is tl, tr, bl, br
void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height, float s1, float t1, float r1, float g1, float b1, float a1, float s2, float t2, float r2, float g2, float b2, float a2, float s3, float t3, float r3, float g3, float b3, float a3, float s4, float t4, float r4, float g4, float b4, float a4, int flags);
// draw a triangle mesh
}
// NOTE: this function always draws exactly one character if maxwidth <= 0
-float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w, float h, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth)
+float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, float w, float h, float sw, float sh, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth)
{
const char *text_start = text;
int colorindex = STRING_COLOR_DEFAULT;
// float ftbase_x;
qboolean snap = true;
qboolean least_one = false;
+ float dw, dh; // display w/h
if (!h) h = w;
if (!h) {
map_index = Font_IndexForSize(ft2, h, NULL, NULL);
fontmap = Font_MapForIndex(ft2, map_index);
}
+ if(snap)
+ {
+ if(fabs(sw - 1) > 0.001 || fabs(sh - 1) > 0.001)
+ snap = false; // turn off pixel snapping for better animation
+ else
+ sw = sh = 1;
+ }
+
+ dw = w * sw;
+ dh = h * sh;
if (*maxlen < 1)
*maxlen = 1<<30;
if (ch == ' ' && !fontmap)
{
if(!least_one || i0) // never skip the first character
- if(x + fnt->width_of[(int) ' '] * w > maxwidth)
+ if(x + fnt->width_of[(int) ' '] * dw > maxwidth)
{
i = i0;
break; // oops, can't draw this
}
- x += fnt->width_of[(int) ' '] * w;
+ x += fnt->width_of[(int) ' '] * dw;
continue;
}
// i points to the char after ^
map = ft2_oldstyle_map;
prevch = 0;
if(!least_one || i0) // never skip the first character
- if(x + fnt->width_of[ch] * w > maxwidth)
+ if(x + fnt->width_of[ch] * dw > maxwidth)
{
i = i0;
break; // oops, can't draw this
}
- x += fnt->width_of[ch] * w;
+ x += fnt->width_of[ch] * dw;
} else {
if (!map || map == ft2_oldstyle_map || map->start < ch || map->start + FONT_CHARS_PER_MAP >= ch)
{
}
mapch = ch - map->start;
if (prevch && Font_GetKerningForMap(ft2, map_index, w, h, prevch, ch, &kx, NULL))
- x += kx * w;
- x += map->glyphs[mapch].advance_x * w;
+ x += kx * dw;
+ x += map->glyphs[mapch].advance_x * dw;
prevmap = map;
prevch = ch;
}
return x;
}
-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)
+float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size_t maxlen, float w, float h, float sw, float sh, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt)
{
int shadow, colorindex = STRING_COLOR_DEFAULT;
size_t i;
qboolean snap = true;
float pix_x, pix_y;
size_t bytes_left;
+ float dw, dh;
int tw, th;
tw = R_TextureWidth(fnt->tex);
map_index = Font_IndexForSize(ft2, h, NULL, NULL);
fontmap = Font_MapForIndex(ft2, map_index);
}
+ if(snap)
+ {
+ if(fabs(sw - 1) > 0.001 || fabs(sh - 1) > 0.001)
+ snap = false; // turn off pixel snapping for better animation
+ else
+ sw = sh = 1;
+ }
+
+ dw = w * sw;
+ dh = h * sh;
// draw the font at its baseline when using freetype
//ftbase_x = 0;
- ftbase_y = h * (4.5/6.0);
+ ftbase_y = dh * (4.5/6.0);
if (maxlen < 1)
maxlen = 1<<30;
batchcount = 0;
//ftbase_x = snap_to_pixel_x(ftbase_x);
- ftbase_y = snap_to_pixel_y(ftbase_y, 0.3);
+ if(snap)
+ ftbase_y = snap_to_pixel_y(ftbase_y, 0.3);
pix_x = vid.width / vid_conwidth.value;
pix_y = vid.height / vid_conheight.value;
}
if (ch == ' ' && !fontmap)
{
- x += fnt->width_of[(int) ' '] * w;
+ x += fnt->width_of[(int) ' '] * dw;
continue;
}
if (ch == STRING_COLOR_TAG && !ignorecolorcodes && i < maxlen)
at[ 4] = s+u ; at[ 5] = t+v ;
at[ 6] = s ; at[ 7] = t+v ;
av[ 0] = x ; av[ 1] = y ; av[ 2] = 10;
- av[ 3] = x+w*thisw ; av[ 4] = y ; av[ 5] = 10;
- av[ 6] = x+w*thisw ; av[ 7] = y+h ; av[ 8] = 10;
- av[ 9] = x ; av[10] = y+h ; av[11] = 10;
+ av[ 3] = x+dw*thisw ; av[ 4] = y ; av[ 5] = 10;
+ av[ 6] = x+dw*thisw ; av[ 7] = y+dh ; av[ 8] = 10;
+ av[ 9] = x ; av[10] = y+dh ; av[11] = 10;
ac += 16;
at += 8;
av += 12;
at = texcoord2f;
av = vertex3f;
}
- x += thisw * w;
+ x += thisw * dw;
} else {
if (!map || map == ft2_oldstyle_map || map->start < ch || map->start + FONT_CHARS_PER_MAP >= ch)
{
y += ftbase_y;
if (prevch && Font_GetKerningForMap(ft2, map_index, w, h, prevch, ch, &kx, &ky))
{
- x += kx * w;
- y += ky * h;
+ x += kx * dw;
+ y += ky * dh;
}
else
kx = ky = 0;
at[2] = map->glyphs[mapch].txmax; at[3] = map->glyphs[mapch].tymin;
at[4] = map->glyphs[mapch].txmax; at[5] = map->glyphs[mapch].tymax;
at[6] = map->glyphs[mapch].txmin; at[7] = map->glyphs[mapch].tymax;
- av[ 0] = x + w * map->glyphs[mapch].vxmin; av[ 1] = y + h * map->glyphs[mapch].vymin; av[ 2] = 10;
- av[ 3] = x + w * map->glyphs[mapch].vxmax; av[ 4] = y + h * map->glyphs[mapch].vymin; av[ 5] = 10;
- av[ 6] = x + w * map->glyphs[mapch].vxmax; av[ 7] = y + h * map->glyphs[mapch].vymax; av[ 8] = 10;
- av[ 9] = x + w * map->glyphs[mapch].vxmin; av[10] = y + h * map->glyphs[mapch].vymax; av[11] = 10;
+ av[ 0] = x + dw * map->glyphs[mapch].vxmin; av[ 1] = y + dh * map->glyphs[mapch].vymin; av[ 2] = 10;
+ av[ 3] = x + dw * map->glyphs[mapch].vxmax; av[ 4] = y + dh * map->glyphs[mapch].vymin; av[ 5] = 10;
+ av[ 6] = x + dw * map->glyphs[mapch].vxmax; av[ 7] = y + dh * map->glyphs[mapch].vymax; av[ 8] = 10;
+ av[ 9] = x + dw * map->glyphs[mapch].vxmin; av[10] = y + dh * map->glyphs[mapch].vymax; av[11] = 10;
//x -= ftbase_x;
y -= ftbase_y;
- x += thisw * w;
+ x += thisw * dw;
ac += 16;
at += 8;
av += 12;
return x;
}
+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)
+{
+ return DrawQ_String_Font_Scale(startx, starty, text, maxlen, w, h, 1, 1, basered, basegreen, baseblue, basealpha, flags, outcolor, ignorecolorcodes, fnt);
+}
+
float DrawQ_String(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)
{
return DrawQ_String_Font(startx, starty, text, maxlen, w, h, basered, basegreen, baseblue, basealpha, flags, outcolor, ignorecolorcodes, &dp_fonts[0]);
}
+float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w, float h, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth)
+{
+ return DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(text, w, h, 1, 1, maxlen, outcolor, ignorecolorcodes, fnt, maxwidth);
+}
+
float DrawQ_TextWidth_Font(const char *text, size_t maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt)
{
return DrawQ_TextWidth_Font_UntilWidth(text, &maxlen, ignorecolorcodes, fnt, 1000000000);
int dmg_origin; // csqc
int sb_showscores; // csqc
int drawfont; // csqc / menu
+ int drawfontscale; // csqc / menu
int require_spawnfunc_prefix; // ssqc
int worldstatus; // ssqc
int servertime; // csqc
Draw_FreePic(s);
}
+void getdrawfontscale(float *sx, float *sy)
+{
+ vec3_t v;
+ *sx = *sy = 1;
+ if(prog->globaloffsets.drawfontscale >= 0)
+ {
+ VectorCopy(PRVM_G_VECTOR(prog->globaloffsets.drawfontscale), v);
+ if(VectorLength2(v) > 0)
+ {
+ *sx = v[0];
+ *sy = v[1];
+ }
+ }
+}
+
dp_font_t *getdrawfont(void)
{
if(prog->globaloffsets.drawfont >= 0)
float *pos,*scale,*rgb;
char character;
int flag;
+ float sx, sy;
VM_SAFEPARMCOUNT(6,VM_drawcharacter);
character = (char) PRVM_G_FLOAT(OFS_PARM1);
return;
}
- DrawQ_String_Font(pos[0], pos[1], &character, 1, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
+ getdrawfontscale(&sx, &sy);
+ DrawQ_String_Font_Scale(pos[0], pos[1], &character, 1, scale[0], scale[1], sx, sy, rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
PRVM_G_FLOAT(OFS_RETURN) = 1;
}
float *pos,*scale,*rgb;
const char *string;
int flag;
+ float sx, sy;
VM_SAFEPARMCOUNT(6,VM_drawstring);
string = PRVM_G_STRING(OFS_PARM1);
if(pos[2] || scale[2])
Con_Printf("VM_drawstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
- DrawQ_String_Font(pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
+ getdrawfontscale(&sx, &sy);
+ DrawQ_String_Font_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true, getdrawfont());
//Font_DrawString(pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true);
PRVM_G_FLOAT(OFS_RETURN) = 1;
}
float *pos,*scale;
const char *string;
int flag,color;
+ float sx, sy;
VM_SAFEPARMCOUNT(5,VM_drawstring);
string = PRVM_G_STRING(OFS_PARM1);
Con_Printf("VM_drawcolorcodedstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
color = -1;
- DrawQ_String_Font(pos[0], pos[1], string, 0, scale[0], scale[1], 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false, getdrawfont());
+ getdrawfontscale(&sx, &sy);
+ DrawQ_String_Font_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false, getdrawfont());
PRVM_G_FLOAT(OFS_RETURN) = 1;
}
/*
float *szv;
float mult; // sz is intended font size so we can later add freetype support, mult is font size multiplier in pixels per character cell
int colors;
- float x[200];
+ float sx, sy;
+ size_t maxlen = 0;
VM_SAFEPARMCOUNTRANGE(2,3,VM_drawstring);
if(prog->argc == 3)
szv = defsize;
mult = 1;
}
- x[180] = 3;
+ getdrawfontscale(&sx, &sy);
string = PRVM_G_STRING(OFS_PARM0);
colors = (int)PRVM_G_FLOAT(OFS_PARM1);
- PRVM_G_FLOAT(OFS_RETURN) = DrawQ_TextWidth_Font_Size(string, szv[0], szv[1], 0, !colors, getdrawfont()) * mult; // 1x1 characters, don't actually draw
+ PRVM_G_FLOAT(OFS_RETURN) = DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(string, szv[0], szv[1], sx, sy, &maxlen, NULL, !colors, getdrawfont(), 1000000000) * mult; // 1x1 characters, don't actually draw
/*
if(prog->argc == 3)
{
prog->globaloffsets.dmg_save = PRVM_ED_FindGlobalOffset("dmg_save");
prog->globaloffsets.dmg_take = PRVM_ED_FindGlobalOffset("dmg_take");
prog->globaloffsets.drawfont = PRVM_ED_FindGlobalOffset("drawfont");
+ prog->globaloffsets.drawfontscale = PRVM_ED_FindGlobalOffset("drawfontscale");
prog->globaloffsets.gettaginfo_forward = PRVM_ED_FindGlobalOffset("gettaginfo_forward");
prog->globaloffsets.gettaginfo_name = PRVM_ED_FindGlobalOffset("gettaginfo_name");
prog->globaloffsets.gettaginfo_offset = PRVM_ED_FindGlobalOffset("gettaginfo_offset");