X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=gl_draw.c;h=da5935015d4332cd57e79aa22fa947cc681845b6;hb=02d7fcc5c3668e2ff5df5838fba4074f66c37842;hp=ee605fcfc5e08ea769e8b06c63b55e4ea32f3c48;hpb=8588130643358b707944100e8fa2f62ce0fae008;p=xonotic%2Fdarkplaces.git diff --git a/gl_draw.c b/gl_draw.c index ee605fcf..da593501 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -532,6 +532,7 @@ void Draw_FreePic(const char *picname) } } +static float snap_to_pixel_x(float x, float roundUpAt); extern int con_linewidth; // to force rewrapping static void LoadFont(qboolean override, const char *name, dp_font_t *fnt) { @@ -615,7 +616,19 @@ static void LoadFont(qboolean override, const char *name, dp_font_t *fnt) case '+': case '-': case '.': - fnt->width_of[ch++] = atof(com_token) + extraspacing; + fnt->width_of[ch] = atof(com_token) + extraspacing; + if (fnt->ft2) + { + for (i = 0; i < MAX_FONT_SIZES; ++i) + { + //Font_MapForIndex(fnt->ft2, i)->width_of[ch] = snap_to_pixel_x(fnt->width_of[ch] * fnt->req_sizes[i], 0.4); + ft2_font_map_t *map = Font_MapForIndex(fnt->ft2, i); + if (!map) + break; + map->width_of[ch] = Font_SnapTo(fnt->width_of[ch], 1/map->size); + } + } + ch++; break; default: if(!strcmp(com_token, "extraspacing")) @@ -782,7 +795,6 @@ static void LoadFont_f(void) for(i = 1; i < MAX_FONT_SIZES; ++i) f->req_sizes[i] = -1; - // for some reason this argc is 3 even when using 2 arguments here, maybe nexuiz screws up if(Cmd_Argc() >= 3) { for(i = 0; i < Cmd_Argc()-3; ++i) @@ -853,7 +865,6 @@ void GL_Draw_Init (void) for(i = 0, j = 0; i < MAX_USERFONTS; ++i) if(!FONT_USER[i].title[0]) dpsnprintf(FONT_USER[i].title, sizeof(FONT_USER[i].title), "user%d", j++); - Font_Init(); } void _DrawQ_Setup(void) @@ -1072,7 +1083,7 @@ static void DrawQ_GetTextColor(float color[4], int colorindex, float r, float g, } // NOTE: this function always draws exactly one character if maxwidth <= 0 -float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, size_t *maxlen, float w, float h, float sw, float sh, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth) +float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *maxlen, float w, float h, float sw, float sh, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth) { const char *text_start = text; int colorindex = STRING_COLOR_DEFAULT; @@ -1092,6 +1103,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, s qboolean snap = true; qboolean least_one = false; float dw, dh; // display w/h + const float *width_of; if (!h) h = w; if (!h) { @@ -1111,13 +1123,6 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, s 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; @@ -1139,6 +1144,14 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, s maxwidth = -maxwidth; } + //if (snap) + // x = snap_to_pixel_x(x, 0.4); // haha, it's 0 anyway + + if (fontmap) + width_of = fontmap->width_of; + else + width_of = fnt->width_of; + for (i = 0;((bytes_left = *maxlen - (text - text_start)) > 0) && *text;) { size_t i0 = i; @@ -1146,17 +1159,15 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, s i = text - text_start; if (!ch) break; - if (snap) - x = snap_to_pixel_x(x, 0.4); if (ch == ' ' && !fontmap) { if(!least_one || i0) // never skip the first character - if(x + fnt->width_of[(int) ' '] * dw > maxwidth) + if(x + width_of[(int) ' '] * dw > maxwidth) { i = i0; break; // oops, can't draw this } - x += fnt->width_of[(int) ' '] * dw; + x += width_of[(int) ' '] * dw; continue; } // i points to the char after ^ @@ -1223,12 +1234,12 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, s map = ft2_oldstyle_map; prevch = 0; if(!least_one || i0) // never skip the first character - if(x + fnt->width_of[ch] * dw > maxwidth) + if(x + width_of[ch] * dw > maxwidth) { i = i0; break; // oops, can't draw this } - x += fnt->width_of[ch] * dw; + x += width_of[ch] * dw; } else { if (!map || map == ft2_oldstyle_map || map->start < ch || map->start + FONT_CHARS_PER_MAP >= ch) { @@ -1258,7 +1269,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(const char *text, s return x; } -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) +float DrawQ_String_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; @@ -1284,6 +1295,7 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size float pix_x, pix_y; size_t bytes_left; float dw, dh; + const float *width_of; int tw, th; tw = R_TextureWidth(fnt->tex); @@ -1307,13 +1319,6 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size 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; @@ -1342,12 +1347,23 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size //ftbase_x = snap_to_pixel_x(ftbase_x); if(snap) + { + startx = snap_to_pixel_x(startx, 0.4); + starty = snap_to_pixel_y(starty, 0.4); 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 (fontmap) + width_of = fontmap->width_of; + else + width_of = fnt->width_of; + for (shadow = r_textshadow.value != 0 && basealpha > 0;shadow >= 0;shadow--) { + prevch = 0; text = text_start; if (!outcolor || *outcolor == -1) @@ -1372,14 +1388,9 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size i = text - text_start; if (!ch) break; - if (snap) - { - x = snap_to_pixel_x(x, 0.4); - y = snap_to_pixel_y(y, 0.4); - } if (ch == ' ' && !fontmap) { - x += fnt->width_of[(int) ' '] * dw; + x += width_of[(int) ' '] * dw; continue; } if (ch == STRING_COLOR_TAG && !ignorecolorcodes && i < maxlen) @@ -1456,9 +1467,7 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size if (batchcount) { // switching from freetype to non-freetype rendering - GL_LockArrays(0, batchcount * 4); R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0); - GL_LockArrays(0, 0); batchcount = 0; ac = color4f; at = texcoord2f; @@ -1495,15 +1504,13 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size batchcount++; if (batchcount >= QUADELEMENTS_MAXQUADS) { - GL_LockArrays(0, batchcount * 4); R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0); - GL_LockArrays(0, 0); batchcount = 0; ac = color4f; at = texcoord2f; av = vertex3f; } - x += thisw * dw; + x += width_of[ch] * dw; } else { if (!map || map == ft2_oldstyle_map || map->start < ch || map->start + FONT_CHARS_PER_MAP >= ch) { @@ -1511,9 +1518,7 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size if (batchcount) { // we need a different character map, render what we currently have: - GL_LockArrays(0, batchcount * 4); R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0); - GL_LockArrays(0, 0); batchcount = 0; ac = color4f; at = texcoord2f; @@ -1572,9 +1577,7 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size batchcount++; if (batchcount >= QUADELEMENTS_MAXQUADS) { - GL_LockArrays(0, batchcount * 4); R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0); - GL_LockArrays(0, 0); batchcount = 0; ac = color4f; at = texcoord2f; @@ -1592,11 +1595,7 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size } } if (batchcount > 0) - { - GL_LockArrays(0, batchcount * 4); R_Mesh_Draw(0, batchcount * 4, 0, batchcount * 2, quadelement3i, quadelement3s, 0, 0); - GL_LockArrays(0, 0); - } if (outcolor) *outcolor = colorindex; @@ -1605,46 +1604,26 @@ float DrawQ_String_Font_Scale(float startx, float starty, const char *text, size 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) +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, const dp_font_t *fnt) { - return DrawQ_String_Font(startx, starty, text, maxlen, w, h, basered, basegreen, baseblue, basealpha, flags, outcolor, ignorecolorcodes, &dp_fonts[0]); + return DrawQ_String_Scale(startx, starty, text, maxlen, w, h, 1, 1, basered, basegreen, baseblue, basealpha, flags, outcolor, ignorecolorcodes, fnt); } -float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, size_t *maxlen, float w, float h, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth) +float DrawQ_TextWidth_UntilWidth_TrackColors(const char *text, size_t *maxlen, float w, float h, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth) { - return DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size_Scale(text, maxlen, w, h, 1, 1, outcolor, ignorecolorcodes, fnt, maxwidth); + return DrawQ_TextWidth_UntilWidth_TrackColors_Scale(text, maxlen, w, h, 1, 1, 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); -//} - -float DrawQ_TextWidth_Font_Size(const char *text, size_t maxlen, float w, float h, qboolean ignorecolorcodes, const dp_font_t *fnt) +float DrawQ_TextWidth(const char *text, size_t maxlen, float w, float h, qboolean ignorecolorcodes, const dp_font_t *fnt) { - return DrawQ_TextWidth_Font_UntilWidth_Size(text, &maxlen, w, h, ignorecolorcodes, fnt, 1000000000); + return DrawQ_TextWidth_UntilWidth(text, &maxlen, w, h, ignorecolorcodes, fnt, 1000000000); } -//float DrawQ_TextWidth_Font_UntilWidth(const char *text, size_t *maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxWidth) -//{ -// return DrawQ_TextWidth_Font_UntilWidth_TrackColors(text, maxlen, NULL, ignorecolorcodes, fnt, maxWidth); -//} - -float DrawQ_TextWidth_Font_UntilWidth_Size(const char *text, size_t *maxlen, float w, float h, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxWidth) +float DrawQ_TextWidth_UntilWidth(const char *text, size_t *maxlen, float w, float h, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxWidth) { - return DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(text, maxlen, w, h, NULL, ignorecolorcodes, fnt, maxWidth); + return DrawQ_TextWidth_UntilWidth_TrackColors(text, maxlen, w, h, NULL, ignorecolorcodes, fnt, maxWidth); } -//float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth) -//{ -// return DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(text, maxlen, 0, 0, outcolor, ignorecolorcodes, fnt, maxwidth); -//} - #if 0 // not used // no ^xrgb management @@ -1733,9 +1712,7 @@ void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags) R_Mesh_TexCoordPointer(0, 2, mesh->data_texcoord2f, 0, 0); R_SetupShader_Generic(mesh->texture, NULL, GL_MODULATE, 1); - GL_LockArrays(0, mesh->num_vertices); R_Mesh_Draw(0, mesh->num_vertices, 0, mesh->num_triangles, mesh->data_element3i, mesh->data_element3s, 0, 0); - GL_LockArrays(0, 0); } void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)