From ea28f7419a24f5ed6054aa753b4c36004e1ec442 Mon Sep 17 00:00:00 2001 From: blub0 Date: Thu, 3 Sep 2009 20:33:44 +0000 Subject: [PATCH] reverting the preparations, we first need a stringwidth wrapper, and some things are still broken it seems git-svn-id: svn://svn.icculus.org/nexuiz/trunk@7617 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/defaultNexuiz.cfg | 8 +- data/qcsrc/client/Main.qc | 2 +- data/qcsrc/client/csqc_builtins.qc | 2 +- data/qcsrc/client/mapvoting.qc | 20 ++--- data/qcsrc/client/miscfunctions.qc | 6 +- data/qcsrc/client/sbar.qc | 91 ++++++++++---------- data/qcsrc/common/util.qc | 123 ++-------------------------- data/qcsrc/common/util.qh | 12 +-- data/qcsrc/menu/draw.qc | 26 +++--- data/qcsrc/menu/draw.qh | 10 +-- data/qcsrc/menu/item/inputbox.c | 18 ++-- data/qcsrc/menu/item/label.c | 12 +-- data/qcsrc/menu/mbuiltin.qh | 2 +- data/qcsrc/menu/menu.qc | 8 +- data/qcsrc/menu/nexuiz/campaign.c | 12 +-- data/qcsrc/menu/nexuiz/cvarlist.c | 4 +- data/qcsrc/menu/nexuiz/demolist.c | 4 +- data/qcsrc/menu/nexuiz/keybinder.c | 2 +- data/qcsrc/menu/nexuiz/maplist.c | 8 +- data/qcsrc/menu/nexuiz/playerlist.c | 8 +- data/qcsrc/menu/nexuiz/serverlist.c | 14 ++-- data/qcsrc/menu/nexuiz/skinlist.c | 8 +- data/qcsrc/menu/nexuiz/util.qc | 2 +- data/qcsrc/server/cl_player.qc | 2 +- 24 files changed, 140 insertions(+), 264 deletions(-) diff --git a/data/defaultNexuiz.cfg b/data/defaultNexuiz.cfg index 6e13c82a3..d879346d9 100644 --- a/data/defaultNexuiz.cfg +++ b/data/defaultNexuiz.cfg @@ -1291,11 +1291,11 @@ set menu_slowmo 1 // loadfont console gfx/vera-mono // loadfont sbar gfx/vera-mono -loadfont notify gfx/vera-sans 0 10 12 18 24 32 -loadfont chat gfx/vera-sans 0 10 12 18 24 32 +loadfont notify gfx/vera-sans +loadfont chat gfx/vera-sans // loadfont centerprint gfx/vera-mono // loadfont infobar gfx/vera-mono -loadfont user0 gfx/vera-sans 0 10 12 18 24 32 +loadfont user0 gfx/vera-sans r_textbrightness 0.2 r_textcontrast 0.8 r_textshadow 1 @@ -1425,7 +1425,7 @@ seta scr_centersize 11 seta sbar_width 560 alias sbar_font "loadfont user1 $*; loadfont user2 ${*}-big; sbar_columns_set" seta sbar_columns default -sbar_font gfx/vera-sans 0 10 12 18 24 32 +sbar_font gfx/vera-sans seta sbar_showbinds 1 "display actions / bound keys in the strings shown during the game. 0 displays only actions, 1 displays only bound keys, 2 displays both" seta sbar_showbinds_limit 2 "maximum number of bound keys to show for an action. 0 for unlimited" diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index 540c9d405..9e6f24ef9 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -411,7 +411,7 @@ void ShotOrg_Draw2D() coord2d_topleft = project_3d_to_2d(self.origin + view_up * 4 - view_right * 4); coord2d_topright = project_3d_to_2d(self.origin + view_up * 4 + view_right * 4); - fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE, '8 8 0')); + fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE)); coord2d = coord2d_topleft; if(fs_x < 8) diff --git a/data/qcsrc/client/csqc_builtins.qc b/data/qcsrc/client/csqc_builtins.qc index ac3bf67e5..21c119117 100644 --- a/data/qcsrc/client/csqc_builtins.qc +++ b/data/qcsrc/client/csqc_builtins.qc @@ -98,7 +98,7 @@ float drawfill(vector position, vector size, vector rgb, float alpha, float flag void drawsetcliparea(float x, float y, float width, float height) = #324; void drawresetcliparea(void) = #325; float drawcolorcodedstring(vector position, string text, vector scale, float alpha, float flag) = #326; -float stringwidth(string text, float handleColors, vector fontSize) = #327; +float stringwidth(string text, float handleColors) = #327; float drawsubpic(vector position, vector size, string pic, vector srcPosition, vector srcSize, vector rgb, float alpha, float flag) = #328; diff --git a/data/qcsrc/client/mapvoting.qc b/data/qcsrc/client/mapvoting.qc index 929ca19cc..a1970df97 100644 --- a/data/qcsrc/client/mapvoting.qc +++ b/data/qcsrc/client/mapvoting.qc @@ -13,7 +13,7 @@ float mv_detail; float mv_timeout; float mv_maps_mask; -string MapVote_FormatMapItem(float id, string map, float count, float maxwidth, vector fontsize) +string MapVote_FormatMapItem(float id, string map, float count, float maxwidth) { string pre, post; pre = strcat(ftos(id+1), ". "); @@ -26,8 +26,8 @@ string MapVote_FormatMapItem(float id, string map, float count, float maxwidth, } else post = ""; - maxwidth -= stringwidth(pre, FALSE, fontsize) + stringwidth(post, FALSE, fontsize); - map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors); + maxwidth -= stringwidth(pre, FALSE) + stringwidth(post, FALSE); + map = textShortenToWidth(map, maxwidth, stringwidth_nocolors); return strcat(pre, map, post); } @@ -56,9 +56,9 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin drawfont = sbar_font; pos_y = pos_y + img_size_y; - label = MapVote_FormatMapItem(id, map, count, tsize, sbar_fontsize); + label = MapVote_FormatMapItem(id, map, count, tsize / sbar_fontsize_x); - text_size = stringwidth(label, false, sbar_fontsize); + text_size = stringwidth(label, false) * sbar_fontsize_x; pos_x -= text_size*0.5; drawstring(pos, label, sbar_fontsize, rgb, 1, DRAWFLAG_NORMAL); @@ -102,9 +102,9 @@ void MapVote_DrawAbstain(vector pos, float isize, float tsize, float count, floa drawfont = sbar_font; pos_y = pos_y + sbar_fontsize_y; - label = MapVote_FormatMapItem(id, "Don't care", count, tsize, sbar_fontsize); + label = MapVote_FormatMapItem(id, "Don't care", count, tsize / sbar_fontsize_x); - text_size = stringwidth(label, false, sbar_fontsize); + text_size = stringwidth(label, false) * sbar_fontsize_x; pos_x -= text_size*0.5; drawstring(pos, label, sbar_fontsize, rgb, 1, DRAWFLAG_NORMAL); @@ -149,15 +149,13 @@ void MapVote_Draw() pos_y = ymin; pos_z = 0; - //pos_x = center - stringwidth("Vote for a map", false) * 0.5 * 24; - pos_x = center - stringwidth("Vote for a map", false, '12 0 0'); + pos_x = center - stringwidth("Vote for a map", false) * 0.5 * 24; drawstring(pos, "Vote for a map", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL); pos_y += 26; i = ceil(max(0, mv_timeout - time)); map = strcat(ftos(i), " seconds left"); - //pos_x = center - stringwidth(map, false) * 0.5 * 16; - pos_x = center - stringwidth(map, false, '8 0 0'); + pos_x = center - stringwidth(map, false) * 0.5 * 16; drawstring(pos, map, '16 16 0', '0 1 0', 1, DRAWFLAG_NORMAL); pos_y += 22; pos_x = xmin; diff --git a/data/qcsrc/client/miscfunctions.qc b/data/qcsrc/client/miscfunctions.qc index df8a24762..ebf18aa7e 100644 --- a/data/qcsrc/client/miscfunctions.qc +++ b/data/qcsrc/client/miscfunctions.qc @@ -1,4 +1,4 @@ -var float(string text, float handleColors, vector fontSize) stringwidth; +var float(string text, float handleColors) stringwidth; entity players; entity teams; @@ -384,7 +384,7 @@ void drawstring_expanding(vector position, string text, vector scale, vector rgb sz = expandingbox_sizefactor_from_fadelerp(fadelerp); dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); - drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, '1 0 0')), text, scale * sz, rgb, alpha * (1 - fadelerp), flag); + drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE)), text, scale * sz, rgb, alpha * (1 - fadelerp), flag); } void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp) @@ -393,5 +393,5 @@ void drawcolorcodedstring_expanding(vector position, string text, vector scale, sz = expandingbox_sizefactor_from_fadelerp(fadelerp); dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); - drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, '1 0 0')), text, scale * sz, alpha * (1 - fadelerp), flag); + drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE)), text, scale * sz, alpha * (1 - fadelerp), flag); } diff --git a/data/qcsrc/client/sbar.qc b/data/qcsrc/client/sbar.qc index 0f55340af..0c3e1e3fc 100644 --- a/data/qcsrc/client/sbar.qc +++ b/data/qcsrc/client/sbar.qc @@ -434,6 +434,7 @@ void Cmd_Sbar_SetFields(float argc) { float i, j, slash; string str, pattern; + float digit; float have_name, have_primary, have_secondary, have_separator; float missing; @@ -470,6 +471,7 @@ void Cmd_Sbar_SetFields(float argc) sbar_num_fields = 0; drawfont = sbar_font; + digit = stringwidth("0123456789", FALSE) / 10; for(i = 0; i < argc - 1; ++i) { @@ -495,7 +497,7 @@ void Cmd_Sbar_SetFields(float argc) strunzone(sbar_title[sbar_num_fields]); sbar_title[sbar_num_fields] = strzone(str); - sbar_size[sbar_num_fields] = stringwidth(str, FALSE, sbar_fontsize); + sbar_size[sbar_num_fields] = stringwidth(str, FALSE); str = strtolower(str); if(str == "ping") { @@ -572,7 +574,7 @@ void Cmd_Sbar_SetFields(float argc) } sbar_title[1] = strzone("|"); sbar_field[1] = SP_SEPARATOR; - sbar_size[1] = stringwidth("|", FALSE, sbar_fontsize); + sbar_size[1] = stringwidth("|", FALSE); ++sbar_num_fields; print("fixed missing field '|'\n"); } @@ -581,7 +583,7 @@ void Cmd_Sbar_SetFields(float argc) { strunzone(sbar_title[sbar_num_fields]); sbar_title[sbar_num_fields] = strzone("|"); - sbar_size[sbar_num_fields] = stringwidth("|", FALSE, sbar_fontsize); + sbar_size[sbar_num_fields] = stringwidth("|", FALSE); sbar_field[sbar_num_fields] = SP_SEPARATOR; ++sbar_num_fields; print("fixed missing field '|'\n"); @@ -590,7 +592,7 @@ void Cmd_Sbar_SetFields(float argc) { strunzone(sbar_title[sbar_num_fields]); sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]); - sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE, sbar_fontsize); + sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE); sbar_field[sbar_num_fields] = ps_secondary; ++sbar_num_fields; print("fixed missing field '", scores_label[ps_secondary], "'\n"); @@ -599,7 +601,7 @@ void Cmd_Sbar_SetFields(float argc) { strunzone(sbar_title[sbar_num_fields]); sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]); - sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE, sbar_fontsize); + sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE); sbar_field[sbar_num_fields] = ps_primary; ++sbar_num_fields; print("fixed missing field '", scores_label[ps_primary], "'\n"); @@ -716,14 +718,14 @@ float sbar_fixscoreboardcolumnwidth_len; float sbar_fixscoreboardcolumnwidth_iconlen; float sbar_fixscoreboardcolumnwidth_marginlen; -float stringwidth_colors(string s, vector theSize) +float stringwidth_colors(string s) { - return stringwidth(s, TRUE, theSize); + return stringwidth(s, TRUE); } -float stringwidth_nocolors(string s, vector theSize) +float stringwidth_nocolors(string s) { - return stringwidth(s, FALSE, theSize); + return stringwidth(s, FALSE); } string Sbar_FixScoreboardColumnWidth(float i, string str) @@ -761,14 +763,14 @@ string Sbar_FixScoreboardColumnWidth(float i, string str) sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect if(sbar_fixscoreboardcolumnwidth_iconlen != 0) - sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE, sbar_fontsize); + sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE); else sbar_fixscoreboardcolumnwidth_marginlen = 0; if(field == SP_NAME) // name gets all remaining space { float namesize, j; - namesize = sbwidth;// / sbar_fontsize_x; + namesize = sbwidth / sbar_fontsize_x; for(j = 0; j < sbar_num_fields; ++j) if(j != i) if (sbar_field[i] != SP_SEPARATOR) @@ -778,11 +780,11 @@ string Sbar_FixScoreboardColumnWidth(float i, string str) if (sbar_fixscoreboardcolumnwidth_iconlen != 0) namesize -= sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen; - str = textShortenToWidth(str, namesize, sbar_fontsize, stringwidth_colors); - sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE, sbar_fontsize); + str = textShortenToWidth(str, namesize, stringwidth_colors); + sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE); } else - sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE, sbar_fontsize); + sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE); f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen; if(sbar_size[i] < f) @@ -823,23 +825,23 @@ void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_num break; if(is_spec && field != SP_NAME && field != SP_PING) { - pos_x += sbar_size[i] + sbar_fontsize_x; + pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x; continue; } str = Sbar_GetField(pl, field); str = Sbar_FixScoreboardColumnWidth(i, str); - pos_x += sbar_size[i] + sbar_fontsize_x; + pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x; if(field == SP_NAME) { - tmp_x = (sbar_size[i] - sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen) + sbar_fontsize_x; + tmp_x = sbar_fontsize_x*(sbar_size[i] - sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen) + sbar_fontsize_x; drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL); } else { - tmp_x = sbar_fixscoreboardcolumnwidth_len + sbar_fontsize_x; + tmp_x = sbar_fixscoreboardcolumnwidth_len*sbar_fontsize_x + sbar_fontsize_x; drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL); } - tmp_x = sbar_size[i] + sbar_fontsize_x; + tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x; if(sbar_field_icon0 != "") drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha, DRAWFLAG_NORMAL); if(sbar_field_icon1 != "") @@ -858,7 +860,7 @@ void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_num break; if(is_spec && field != SP_NAME && field != SP_PING) { - pos_x -= sbar_size[i] + sbar_fontsize_x; + pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x; continue; } @@ -866,14 +868,14 @@ void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_num str = Sbar_FixScoreboardColumnWidth(i, str); if(field == SP_NAME) { - tmp_x = sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right... + tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right... drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL); } else { - tmp_x = sbar_fixscoreboardcolumnwidth_len; + tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL); } - tmp_x = sbar_size[i]; + tmp_x = sbar_fontsize_x*sbar_size[i]; if(sbar_field_icon0 != "") drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha, DRAWFLAG_NORMAL); if(sbar_field_icon1 != "") @@ -881,7 +883,7 @@ void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_num if(sbar_field_icon2 != "") drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha, DRAWFLAG_NORMAL); - pos_x -= sbar_size[i] + sbar_fontsize_x; + pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x; } } } @@ -945,7 +947,7 @@ vector Sbar_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_si { if(sbar_field[i] == SP_SEPARATOR) break; - column_dim_x = sbar_size[i] + sbar_fontsize_x; + column_dim_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x; if (sbar_scoreboard_highlight) { if (mod(i,2)) @@ -963,21 +965,21 @@ vector Sbar_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_si if(sbar_field[i] == SP_SEPARATOR) break; - pos_x -= sbar_size[i]; + pos_x -= sbar_size[i]*sbar_fontsize_x; if (sbar_scoreboard_highlight) { if (!mod(i,2)) { if (i == sbar_num_fields-1) - column_dim_x = sbar_size[i] + sbar_fontsize_x / 2 + 1; + column_dim_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x / 2 + 1; else - column_dim_x = sbar_size[i] + sbar_fontsize_x; + column_dim_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x; drawfill(pos - '0 1 0' - sbar_fontsize_x / 2 * '1 0 0', column_dim, '0 0 0', sbar_scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL); } } - tmp_x = stringwidth(sbar_title[i], FALSE, sbar_fontsize); + tmp_x = stringwidth(sbar_title[i], FALSE); tmp_x = (sbar_size[i] - tmp_x) * sbar_fontsize_x; drawstring(pos + tmp, sbar_title[i], sbar_fontsize, rgb, 1, DRAWFLAG_NORMAL); pos_x -= sbar_fontsize_x; @@ -1180,7 +1182,7 @@ void Sbar_DrawScoreboard() pos_y += 1.2 * sbar_fontsize_y; - drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, sbar_fontsize)), str, sbar_fontsize, 0.8, DRAWFLAG_NORMAL); + drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, DRAWFLAG_NORMAL); sbar = sbar_save; scoreboard_bottom = pos_y + 2 * sbar_fontsize_y; @@ -1534,8 +1536,7 @@ void Sbar_Score(float margin) if(s != "" && a > 0) { dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0) - //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); - drawcolorcodedstring(m - '0 16 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); + drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); } if(race_penaltytime) @@ -1545,16 +1546,14 @@ void Sbar_Score(float margin) { s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")"); dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0) - //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); - drawcolorcodedstring(m - '0 32 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); + drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); } } if(forcetime != "") { a = bound(0, (time - race_checkpointtime) / 0.5, 1); - //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a); - drawstring_expanding(m - '1 0 0' * stringwidth(forcetime, FALSE, '16 0 0'), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a); + drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', sbar_alpha_fg, 0, a); } else a = 1; @@ -1562,8 +1561,7 @@ void Sbar_Score(float margin) if(race_laptime && race_checkpoint != 255) { s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime)); - //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL); - drawstring(m - '0.5 0 0' * stringwidth(s, FALSE, '32 32 0'), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL); + drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, DRAWFLAG_NORMAL); } } else @@ -1573,16 +1571,14 @@ void Sbar_Score(float margin) a = bound(0, 2 - (time - race_mycheckpointtime), 1); s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy); dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0) - //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); - drawcolorcodedstring(m - '0 16 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); + drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); } if(race_othercheckpointtime && race_othercheckpointenemy != "") { a = bound(0, 2 - (time - race_othercheckpointtime), 1); s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy); dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0) - //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); - drawcolorcodedstring(m - '0 0 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); + drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); } if(race_penaltytime && !race_penaltyaccumulator) @@ -1596,8 +1592,7 @@ void Sbar_Score(float margin) else s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")"); dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0) - //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); - drawcolorcodedstring(m - '0 32 0' - '0.5 0 0' * stringwidth(s, TRUE, '16 16 0'), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); + drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, DRAWFLAG_NORMAL); } } } @@ -1756,11 +1751,11 @@ void centerprint(string strMessage) getWrappedLine_remaining = argv(j); while(getWrappedLine_remaining) { - s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors); + s = getWrappedLine(vid_conwidth * 0.75 / centerprint_fontsize_x, stringwidth_colors); if(centerprint_messages[i]) strunzone(centerprint_messages[i]); centerprint_messages[i] = strzone(s); - centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize); + centerprint_width[i] = stringwidth(s, TRUE); ++i; // half height for empty lines looks better @@ -1888,7 +1883,7 @@ vector Sbar_DrawNoteLine(vector offset, string s) { dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0) drawcolorcodedstring( - offset - '1 0 0' * stringwidth(s, TRUE, sbar_fontsize), + offset - sbar_fontsize_x * '1 0 0' * stringwidth(s, TRUE), s, sbar_fontsize, sbar_alpha_fg, @@ -2222,7 +2217,7 @@ void Sbar_Draw (void) // spectated player name between HUD and chat area, aligned to the left pos_x = bottomleft_x; pos_y = bottom_y - 50 - sbar_fontsize_spec_y; - s = textShortenToWidth(s, vid_conwidth/2.5, sbar_fontsize_spec, stringwidth_colors); + s = textShortenToWidth(s, vid_conwidth/2.5/sbar_fontsize_spec_x, stringwidth_colors); drawcolorcodedstring(pos, s, sbar_fontsize_spec, 1, DRAWFLAG_NORMAL); // spectator text in the upper right corner diff --git a/data/qcsrc/common/util.qc b/data/qcsrc/common/util.qc index e58d89de0..9e4e8b88b 100644 --- a/data/qcsrc/common/util.qc +++ b/data/qcsrc/common/util.qc @@ -1201,76 +1201,7 @@ vector AnglesTransform_Divide(vector to_transform, vector from_transform) } #endif -float textLengthUpToWidth(string theText, float maxWidth, vector theSize, textLengthUpToWidth_widthFunction_t w) -{ - float ICanHasKallerz; - - // detect color codes support in the width function - ICanHasKallerz = (w("^7", theSize) == 0); - - // STOP. - // The following function is SLOW. - // For your safety and for the protection of those around you... - // DO NOT CALL THIS AT HOME. - // No really, don't. - if(w(theText, theSize) <= maxWidth) - return strlen(theText); // yeah! - - // binary search for right place to cut string - float ch; - float left, right, middle; // this always works - left = 0; - right = strlen(theText); // this always fails - do - { - middle = floor((left + right) / 2); - if(w(substring(theText, 0, middle), theSize) <= maxWidth) - left = middle; - else - right = middle; - } - while(left < right - 1); - - if(ICanHasKallerz) - { - // NOTE: when color codes are involved, this binary search is, - // mathematically, BROKEN. However, it is obviously guaranteed to - // terminate, as the range still halves each time - but nevertheless, it is - // guaranteed that it finds ONE valid cutoff place (where "left" is in - // range, and "right" is outside). - - // terencehill: the following code detects truncated ^xrgb tags (e.g. ^x or ^x4) - // and decrease left on the basis of the chars detected of the truncated tag - // Even if the ^xrgb tag is not complete/correct, left is decreased - // (sometimes too much but with a correct result) - // it fixes also ^[0-9] - while(left >= 1 && substring(theText, left-1, 1) == "^") - left-=1; - - if (left >= 2 && substring(theText, left-2, 2) == "^x") // ^x/ - left-=2; - else if (left >= 3 && substring(theText, left-3, 2) == "^x") - { - ch = str2chr(theText, left-1); - if( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') ) // ^xr/ - left-=3; - } - else if (left >= 4 && substring(theText, left-4, 2) == "^x") - { - ch = str2chr(theText, left-2); - if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') ) - { - ch = str2chr(theText, left-1); - if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') ) // ^xrg/ - left-=4; - } - } - } - - return left; -} - -float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t w) +float textLengthUpToWidth(string theText, float maxWidth, textLengthUpToWidth_widthFunction_t w) { float ICanHasKallerz; @@ -1339,43 +1270,7 @@ float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_ return left; } -string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw) -{ - float cantake; - float take; - string s; - - s = getWrappedLine_remaining; - - cantake = textLengthUpToWidth(s, w, theFontSize, tw); - if(cantake > 0 && cantake < strlen(s)) - { - take = cantake - 1; - while(take > 0 && substring(s, take, 1) != " ") - --take; - if(take == 0) - { - getWrappedLine_remaining = substring(s, cantake, strlen(s) - cantake); - if(getWrappedLine_remaining == "") - getWrappedLine_remaining = string_null; - return substring(s, 0, cantake); - } - else - { - getWrappedLine_remaining = substring(s, take + 1, strlen(s) - take); - if(getWrappedLine_remaining == "") - getWrappedLine_remaining = string_null; - return substring(s, 0, take); - } - } - else - { - getWrappedLine_remaining = string_null; - return s; - } -} - -string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw) +string getWrappedLine(float w, textLengthUpToWidth_widthFunction_t tw) { float cantake; float take; @@ -1383,7 +1278,7 @@ string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw) s = getWrappedLine_remaining; - cantake = textLengthUpToLength(s, w, tw); + cantake = textLengthUpToWidth(s, w, tw); if(cantake > 0 && cantake < strlen(s)) { take = cantake - 1; @@ -1411,20 +1306,12 @@ string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw) } } -string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw) -{ - if(tw(theText, theFontSize) <= maxWidth) - return theText; - else - return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - tw("...", theFontSize), theFontSize, tw)), "..."); -} - -string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw) +string textShortenToWidth(string theText, float maxWidth, textLengthUpToWidth_widthFunction_t tw) { if(tw(theText) <= maxWidth) return theText; else - return strcat(substring(theText, 0, textLengthUpToLength(theText, maxWidth - tw("..."), tw)), "..."); + return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - tw("..."), tw)), "..."); } float isGametypeInFilter(float gt, float tp, string pattern) diff --git a/data/qcsrc/common/util.qh b/data/qcsrc/common/util.qh index 2b49366ca..45ebad53d 100644 --- a/data/qcsrc/common/util.qh +++ b/data/qcsrc/common/util.qh @@ -150,16 +150,12 @@ vector AnglesTransform_TurnDirection(vector transform); vector AnglesTransform_Divide(vector to_transform, vector from_transform); #endif -typedef float(string s, vector size) textLengthUpToWidth_widthFunction_t; -typedef float(string s) textLengthUpToLength_lenFunction_t; -float textLengthUpToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw); -string textShortenToWidth(string theText, float maxWidth, vector size, textLengthUpToWidth_widthFunction_t tw); -float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw); -string textShortenToLength(string theText, float maxWidth, textLengthUpToLength_lenFunction_t tw); +typedef float(string s) textLengthUpToWidth_widthFunction_t; +float textLengthUpToWidth(string theText, float maxWidth, textLengthUpToWidth_widthFunction_t tw); +string textShortenToWidth(string theText, float maxWidth, textLengthUpToWidth_widthFunction_t tw); string getWrappedLine_remaining; -string getWrappedLine(float w, vector size, textLengthUpToWidth_widthFunction_t tw); -string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw); +string getWrappedLine(float w, textLengthUpToWidth_widthFunction_t tw); float isGametypeInFilter(float gt, float tp, string pattern); diff --git a/data/qcsrc/menu/draw.qc b/data/qcsrc/menu/draw.qc index 0cf3dc165..d0a24749e 100644 --- a/data/qcsrc/menu/draw.qc +++ b/data/qcsrc/menu/draw.qc @@ -238,14 +238,14 @@ void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor } void draw_CenterText(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz) { - draw_Text(theOrigin - eX * 0.5 * draw_TextWidth(theText, ICanHasKallerz, theSize), theText, theSize, theColor, theAlpha, ICanHasKallerz); + draw_Text(theOrigin - eX * theSize_x * 0.5 * draw_TextWidth(theText, ICanHasKallerz), theText, theSize, theColor, theAlpha, ICanHasKallerz); } -float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye) +float draw_TextWidth(string theText, float ICanHasKallerz) { //return strlen(theText); //print("draw_TextWidth \"", theText, "\"\n"); - return stringwidth(theText, ICanHasKallerz, SizeThxBye); + return stringwidth(theText, ICanHasKallerz); } float draw_clipSet; @@ -276,28 +276,28 @@ void draw_ClearClip() draw_clipSet = 0; } -string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye) +string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz) { - if(draw_TextWidth(theText, ICanHasKallerz, SizeThxBye) <= maxWidth) + if(draw_TextWidth(theText, ICanHasKallerz) <= maxWidth) return theText; else - return strcat(substring(theText, 0, draw_TextLengthUpToWidth(theText, maxWidth - draw_TextWidth("...", ICanHasKallerz, SizeThxBye), ICanHasKallerz, SizeThxBye)), "..."); + return strcat(substring(theText, 0, draw_TextLengthUpToWidth(theText, maxWidth - draw_TextWidth("...", ICanHasKallerz), ICanHasKallerz)), "..."); } -float draw_TextWidth_WithColors(string s, vector theFontSize) +float draw_TextWidth_WithColors(string s) { - return draw_TextWidth(s, TRUE, theFontSize); + return draw_TextWidth(s, TRUE); } -float draw_TextWidth_WithoutColors(string s, vector theFontSize) +float draw_TextWidth_WithoutColors(string s) { - return draw_TextWidth(s, FALSE, theFontSize); + return draw_TextWidth(s, FALSE); } -float draw_TextLengthUpToWidth(string theText, float maxWidth, float allowColorCodes, vector theFontSize) +float draw_TextLengthUpToWidth(string theText, float maxWidth, float allowColorCodes) { if(allowColorCodes) - return textLengthUpToWidth(theText, maxWidth, theFontSize, draw_TextWidth_WithColors); + return textLengthUpToWidth(theText, maxWidth, draw_TextWidth_WithColors); else - return textLengthUpToWidth(theText, maxWidth, theFontSize, draw_TextWidth_WithoutColors); + return textLengthUpToWidth(theText, maxWidth, draw_TextWidth_WithoutColors); } diff --git a/data/qcsrc/menu/draw.qh b/data/qcsrc/menu/draw.qh index 0dc6da160..6ee212706 100644 --- a/data/qcsrc/menu/draw.qh +++ b/data/qcsrc/menu/draw.qh @@ -15,9 +15,9 @@ vector draw_PictureSize(string pic); void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha); void draw_Text(vector origin, string text, vector size, vector color, float alpha, float allowColorCodes); void draw_CenterText(vector origin, string text, vector size, vector color, float alpha, float allowColorCodes); -float draw_TextWidth(string text, float allowColorCodes, vector size); -string draw_TextShortenToWidth(string text, float maxWidth, float allowColorCodes, vector size); -float draw_TextLengthUpToWidth(string text, float maxWidth, float allowColorCodes, vector size); +float draw_TextWidth(string text, float allowColorCodes); +string draw_TextShortenToWidth(string text, float maxWidth, float allowColorCodes); +float draw_TextLengthUpToWidth(string text, float maxWidth, float allowColorCodes); void draw_SetClip(); void draw_SetClipRect(vector theOrigin, vector theScale); @@ -32,5 +32,5 @@ float draw_NeedResizeNotify; string draw_currentSkin; -float draw_TextWidth_WithColors(string s, vector size); -float draw_TextWidth_WithoutColors(string s, vector size); +float draw_TextWidth_WithColors(string s); +float draw_TextWidth_WithoutColors(string s); diff --git a/data/qcsrc/menu/item/inputbox.c b/data/qcsrc/menu/item/inputbox.c index 03e1605da..16d2cf401 100644 --- a/data/qcsrc/menu/item/inputbox.c +++ b/data/qcsrc/menu/item/inputbox.c @@ -55,7 +55,7 @@ float mouseDragInputBox(entity me, vector pos) float p; me.dragScrollPos = pos; p = me.scrollPos + pos_x - me.keepspaceLeft; - me.cursorPos = draw_TextLengthUpToWidth(me.text, p, 0, me.realFontSize); + me.cursorPos = draw_TextLengthUpToWidth(me.text, p / me.realFontSize_x, 0); me.lastChangeTime = time; return 1; } @@ -146,8 +146,8 @@ void drawInputBox(entity me) } me.cursorPos = bound(0, me.cursorPos, strlen(me.text)); - cursorPosInWidths = draw_TextWidth(substring(me.text, 0, me.cursorPos), 0, me.realFontSize); - totalSizeInWidths = draw_TextWidth(strcat(me.text, CURSOR), 0, me.realFontSize); + cursorPosInWidths = draw_TextWidth(substring(me.text, 0, me.cursorPos), 0) * me.realFontSize_x; + totalSizeInWidths = draw_TextWidth(strcat(me.text, CURSOR), 0) * me.realFontSize_x; if(me.dragScrollTimer < time) { @@ -183,7 +183,7 @@ void drawInputBox(entity me) { float w; ch2 = substring(me.text, i+1, 1); - w = draw_TextWidth(strcat(ch, ch2), 0, me.realFontSize); + w = draw_TextWidth(strcat(ch, ch2), 0) * me.realFontSize_x; if(ch2 == "^") { draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5); @@ -227,7 +227,7 @@ void drawInputBox(entity me) { theTempColor_z = component/15; theColor = theTempColor; - w = draw_TextWidth(substring(me.text, i, 5), 0, me.realFontSize); + w = draw_TextWidth(substring(me.text, i, 5), 0) * me.realFontSize_x; draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5); draw_Text(p, substring(me.text, i, 5), me.realFontSize, theColor, 1, 0); // theVariableAlpha instead of 1 using alpha tags ^ax @@ -236,7 +236,7 @@ void drawInputBox(entity me) else { // blue missing - w = draw_TextWidth(substring(me.text, i, 4), 0, me.realFontSize); + w = draw_TextWidth(substring(me.text, i, 4), 0) * me.realFontSize_x; draw_Fill(p, eX * w + eY * me.realFontSize_y, eZ, 0.5); draw_Text(p, substring(me.text, i, 4), me.realFontSize, '1 1 1', theAlpha, 0); i += 2; @@ -245,7 +245,7 @@ void drawInputBox(entity me) else { // green missing - w = draw_TextWidth(substring(me.text, i, 3), 0, me.realFontSize); + w = draw_TextWidth(substring(me.text, i, 3), 0) * me.realFontSize_x; draw_Fill(p, eX * w + eY * me.realFontSize_y, eY, 0.5); draw_Text(p, substring(me.text, i, 3), me.realFontSize, '1 1 1', theAlpha, 0); i += 1; @@ -284,7 +284,7 @@ void drawInputBox(entity me) else theVariableAlpha = component*0.0625; - draw_Fill(p, eX * draw_TextWidth(substring(me.text, i, 3), 0, me.realFontSize) + eY * me.realFontSize_y, '0.8 0.8 0.8', 0.5); + draw_Fill(p, eX * draw_TextWidth(substring(me.text, i, 3), 0) * me.realFontSize_x + eY * me.realFontSize_y, '0.8 0.8 0.8', 0.5); draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, 0.8, 0); } }*/ @@ -298,7 +298,7 @@ void drawInputBox(entity me) continue; } draw_Text(p, ch, me.realFontSize, theColor, theAlpha, 0); // TODO theVariableAlpha - p += eX * draw_TextWidth(ch, 0, me.realFontSize); + p += eX * draw_TextWidth(ch, 0) * me.realFontSize_x; } } else diff --git a/data/qcsrc/menu/item/label.c b/data/qcsrc/menu/item/label.c index 1ac50be75..c5fce1698 100644 --- a/data/qcsrc/menu/item/label.c +++ b/data/qcsrc/menu/item/label.c @@ -33,7 +33,7 @@ string toStringLabel(entity me) void setTextLabel(entity me, string txt) { me.text = txt; - me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(draw_TextWidth(me.text, me.allowColors, me.realFontSize), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft; + me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(me.realFontSize_x * draw_TextWidth(me.text, me.allowColors), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft; } void resizeNotifyLabel(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { @@ -45,7 +45,7 @@ void resizeNotifyLabel(entity me, vector relOrigin, vector relSize, vector absOr me.keepspaceLeft = me.marginLeft * me.realFontSize_x; if(me.marginRight) me.keepspaceRight = me.marginRight * me.realFontSize_x; - me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(draw_TextWidth(me.text, me.allowColors, me.realFontSize), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft; + me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(me.realFontSize_x * draw_TextWidth(me.text, me.allowColors), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft; me.realOrigin_y = 0.5 * (1 - me.realFontSize_y); } void configureLabelLabel(entity me, string txt, float sz, float algn) @@ -64,7 +64,7 @@ void drawLabel(entity me) if(me.textEntity) { t = me.textEntity.toString(me.textEntity); - me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(draw_TextWidth(t, 0, me.realFontSize), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft; + me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(me.realFontSize_x * draw_TextWidth(t, 0), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft; } else t = me.text; @@ -73,7 +73,7 @@ void drawLabel(entity me) if(t) { if(me.allowCut) // FIXME allowCut incompatible with align != 0 - draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, me.realFontSize), me.realFontSize, me.colorL, me.alpha, me.allowColors); + draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight) / me.realFontSize_x, me.allowColors), me.realFontSize, me.colorL, me.alpha, me.allowColors); else if(me.allowWrap) // FIXME allowWrap incompatible with align != 0 { getWrappedLine_remaining = t; @@ -81,9 +81,9 @@ void drawLabel(entity me) while(getWrappedLine_remaining) { if (me.allowColors) - t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), me.realFontSize, draw_TextWidth_WithColors); + t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight) / me.realFontSize_x, draw_TextWidth_WithColors); else - t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), me.realFontSize, draw_TextWidth_WithoutColors); + t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight) / me.realFontSize_x, draw_TextWidth_WithoutColors); draw_Text(o, t, me.realFontSize, me.colorL, me.alpha, me.allowColors); o_y += me.realFontSize_y; } diff --git a/data/qcsrc/menu/mbuiltin.qh b/data/qcsrc/menu/mbuiltin.qh index 5697c1486..5b079c5e1 100644 --- a/data/qcsrc/menu/mbuiltin.qh +++ b/data/qcsrc/menu/mbuiltin.qh @@ -195,7 +195,7 @@ float drawcharacter(vector position, float character, vector scale, vector rgb, float drawstring(vector position, string text, vector scale, vector rgb, float alpha, float flag) = #455; float drawcolorcodedstring(vector position, string text, vector scale, float alpha, float flag) = #467; -float stringwidth(string text, float handleColors, vector size) = #468; +float stringwidth(string text, float handleColors) = #468; float drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag) = #456; float drawsubpic(vector position, vector size, string pic, vector srcPosition, vector srcSize, vector rgb, float alpha, float flag) = #469; diff --git a/data/qcsrc/menu/menu.qc b/data/qcsrc/menu/menu.qc index e6c21c341..ec3ee2e58 100644 --- a/data/qcsrc/menu/menu.qc +++ b/data/qcsrc/menu/menu.qc @@ -377,13 +377,13 @@ void m_tooltip(vector pos) getWrappedLine_remaining = it.tooltip; while(getWrappedLine_remaining) { - s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors); + s = getWrappedLine(SKINWIDTH_TOOLTIP / fontsize_x, draw_TextWidth_WithoutColors); ++i; - f = draw_TextWidth(s, FALSE, fontsize); + f = draw_TextWidth(s, FALSE); if(f > w) w = f; } - menuTooltipSize_x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth); + menuTooltipSize_x = w * fontsize_x + 2 * (SKINMARGIN_TOOLTIP_x / conwidth); menuTooltipSize_y = i * fontsize_y + 2 * (SKINMARGIN_TOOLTIP_y / conheight); menuTooltipSize_z = 0; } @@ -439,7 +439,7 @@ void m_tooltip(vector pos) getWrappedLine_remaining = menuTooltipItem.tooltip; while(getWrappedLine_remaining) { - s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors); + s = getWrappedLine(SKINWIDTH_TOOLTIP / fontsize_x, draw_TextWidth_WithoutColors); draw_Text(p, s, fontsize, '1 1 1', SKINALPHA_TOOLTIP * menuTooltipAlpha, FALSE); p_y += fontsize_y; } diff --git a/data/qcsrc/menu/nexuiz/campaign.c b/data/qcsrc/menu/nexuiz/campaign.c index 81b5365f4..e538c6fd6 100644 --- a/data/qcsrc/menu/nexuiz/campaign.c +++ b/data/qcsrc/menu/nexuiz/campaign.c @@ -49,7 +49,7 @@ void MultiCampaign_Prev(entity btn, entity me); #ifdef IMPLEMENTATION string campaign_longdesc_wrapped[CAMPAIGN_MAX_ENTRIES]; -void rewrapCampaign(float w, float l0, float emptyheight, vector theFontSize) +void rewrapCampaign(float w, float l0, float emptyheight) { float i, j; float n, l; @@ -74,7 +74,7 @@ void rewrapCampaign(float w, float l0, float emptyheight, vector theFontSize) getWrappedLine_remaining = s; while(getWrappedLine_remaining) { - s = getWrappedLine(w, theFontSize, draw_TextWidth_WithoutColors); + s = getWrappedLine(w, draw_TextWidth_WithoutColors); if(--l < 0) goto toolong; r = strcat(r, s, "\n"); } @@ -125,7 +125,7 @@ void loadCvarsNexuizCampaignList(entity me) me.campaignIndex = bound(0, cvar(me.cvarName), campaign_entries); cvar_set(me.cvarName, ftos(me.campaignIndex)); if(me.columnNameSize) - rewrapCampaign(me.columnNameSize, me.rowsPerItem - 3, me.emptyLineHeight, me.realFontSize); + rewrapCampaign(me.columnNameSize / me.realFontSize_x, me.rowsPerItem - 3, me.emptyLineHeight); me.nItems = min(me.campaignIndex + 2, campaign_entries); me.selectedItem = min(me.campaignIndex, me.nItems - 1); me.scrollPos = me.nItems * me.itemHeight - 1; @@ -222,7 +222,7 @@ void resizeNotifyNexuizCampaignList(entity me, vector relOrigin, vector relSize, me.checkMarkOrigin = eY + eX * (me.columnCheckMarkOrigin + me.columnCheckMarkSize) - me.checkMarkSize; - rewrapCampaign(me.columnNameSize, me.rowsPerItem - 3, me.emptyLineHeight, me.realFontSize); + rewrapCampaign(me.columnNameSize / me.realFontSize_x, me.rowsPerItem - 3, me.emptyLineHeight); } void clickListBoxItemNexuizCampaignList(entity me, float i, vector where) { @@ -273,8 +273,8 @@ void drawListBoxItemNexuizCampaignList(entity me, float i, vector absSize, float s = campaign_shortdesc[i]; // fteqcc sucks else s = "???"; - s = draw_TextShortenToWidth(strcat("Level ", ftos(i + 1), ": ", s), me.columnNameSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, theColor, theAlpha, 0); + s = draw_TextShortenToWidth(strcat("Level ", ftos(i + 1), ": ", s), me.columnNameSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, theColor, theAlpha, 0); if(i <= me.campaignIndex) { diff --git a/data/qcsrc/menu/nexuiz/cvarlist.c b/data/qcsrc/menu/nexuiz/cvarlist.c index b3cd5c4f5..f2ca75dd3 100644 --- a/data/qcsrc/menu/nexuiz/cvarlist.c +++ b/data/qcsrc/menu/nexuiz/cvarlist.c @@ -143,9 +143,9 @@ void drawListBoxItemNexuizCvarList(entity me, float i, vector absSize, float isS else theColor = SKINCOLOR_CVARLIST_CHANGED; - s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize); + s = draw_TextShortenToWidth(k, me.columnNameSize / me.realFontSize_x, 0); draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0); - s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize); + s = draw_TextShortenToWidth(v, me.columnValueSize / me.realFontSize_x, 0); draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0); } diff --git a/data/qcsrc/menu/nexuiz/demolist.c b/data/qcsrc/menu/nexuiz/demolist.c index d3d940520..f938b723d 100644 --- a/data/qcsrc/menu/nexuiz/demolist.c +++ b/data/qcsrc/menu/nexuiz/demolist.c @@ -99,8 +99,8 @@ void drawListBoxItemNexuizDemoList(entity me, float i, vector absSize, float isS draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); s = me.demoName(me,i); - s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); + s = draw_TextShortenToWidth(s, me.columnNameSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); } void showNotifyNexuizDemoList(entity me) diff --git a/data/qcsrc/menu/nexuiz/keybinder.c b/data/qcsrc/menu/nexuiz/keybinder.c index 7d9fc6d6c..7161bf7c1 100644 --- a/data/qcsrc/menu/nexuiz/keybinder.c +++ b/data/qcsrc/menu/nexuiz/keybinder.c @@ -312,7 +312,7 @@ void drawListBoxItemNexuizKeyBinder(entity me, float i, vector absSize, float is s = strcat(s, keynumtostring(k)); } } - s = draw_TextShortenToWidth(s, me.columnKeysSize, 0, me.realFontSize); + s = draw_TextShortenToWidth(s, me.columnKeysSize / me.realFontSize_x, 0); draw_CenterText(me.realUpperMargin * eY + (me.columnKeysOrigin + 0.5 * me.columnKeysSize) * eX, s, me.realFontSize, theColor, theAlpha, 0); } } diff --git a/data/qcsrc/menu/nexuiz/maplist.c b/data/qcsrc/menu/nexuiz/maplist.c index c58dc71fd..de73d7829 100644 --- a/data/qcsrc/menu/nexuiz/maplist.c +++ b/data/qcsrc/menu/nexuiz/maplist.c @@ -187,10 +187,10 @@ void drawListBoxItemNexuizMapList(entity me, float i, vector absSize, float isSe draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); if(included) draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1); - s = draw_TextShortenToWidth(strcat(MapInfo_Map_bspname, ": ", MapInfo_Map_title), me.columnNameSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_TITLE, theAlpha, 0); - s = draw_TextShortenToWidth(MapInfo_Map_author, me.columnNameSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_AUTHOR, theAlpha, 0); + s = draw_TextShortenToWidth(strcat(MapInfo_Map_bspname, ": ", MapInfo_Map_title), me.columnNameSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_TITLE, theAlpha, 0); + s = draw_TextShortenToWidth(MapInfo_Map_author, me.columnNameSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_AUTHOR, theAlpha, 0); MapInfo_ClearTemps(); } diff --git a/data/qcsrc/menu/nexuiz/playerlist.c b/data/qcsrc/menu/nexuiz/playerlist.c index 6fabbd70c..9ae656378 100644 --- a/data/qcsrc/menu/nexuiz/playerlist.c +++ b/data/qcsrc/menu/nexuiz/playerlist.c @@ -127,11 +127,11 @@ void drawListBoxItemNexuizPlayerList(entity me, float i, vector absSize, float i score = substring(score, 0, t); } - s = draw_TextShortenToWidth(s, me.columnNameSize, 1, me.realFontSize); - score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize); + s = draw_TextShortenToWidth(s, (me.columnNameSize / me.realFontSize_x), 1); + score = draw_TextShortenToWidth(score, me.columnScoreSize / me.realFontSize_x, 0); - draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 1, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', 1, 1); - draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + 1.00 * (me.columnScoreSize - draw_TextWidth(score, 1, me.realFontSize))) * eX, score, me.realFontSize, rgb, 1, 0); + draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 1) * me.realFontSize_x)) * eX, s, me.realFontSize, '1 1 1', 1, 1); + draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + 1.00 * (me.columnScoreSize - draw_TextWidth(score, 1) * me.realFontSize_x)) * eX, score, me.realFontSize, rgb, 1, 0); } #endif diff --git a/data/qcsrc/menu/nexuiz/serverlist.c b/data/qcsrc/menu/nexuiz/serverlist.c index d89f3ff7f..bc5855868 100644 --- a/data/qcsrc/menu/nexuiz/serverlist.c +++ b/data/qcsrc/menu/nexuiz/serverlist.c @@ -557,21 +557,21 @@ void drawListBoxItemNexuizServerList(entity me, float i, vector absSize, float i } s = ftos(p); - draw_Text(me.realUpperMargin * eY + (me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0); - s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize, 0, me.realFontSize); + draw_Text(me.realUpperMargin * eY + (me.columnPingSize - draw_TextWidth(s, 0) * me.realFontSize_x) * eX, s, me.realFontSize, theColor, theAlpha, 0); + s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize / me.realFontSize_x, 0); draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0); - s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0); + s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0) * me.realFontSize_x) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0); s = gethostcachestring(SLIST_FIELD_QCSTATUS, i); p = strstrofs(s, ":", 0); if(p >= 0) s = substring(s, 0, p); else s = ""; - s = draw_TextShortenToWidth(s, me.columnMapSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0); + s = draw_TextShortenToWidth(s, me.columnMapSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0) * me.realFontSize_x) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0); s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i))); - draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0); + draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0) * me.realFontSize_x) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0); } float keyDownNexuizServerList(entity me, float scan, float ascii, float shift) diff --git a/data/qcsrc/menu/nexuiz/skinlist.c b/data/qcsrc/menu/nexuiz/skinlist.c index 9d742e8fe..c88fabc3c 100644 --- a/data/qcsrc/menu/nexuiz/skinlist.c +++ b/data/qcsrc/menu/nexuiz/skinlist.c @@ -160,12 +160,12 @@ void drawListBoxItemNexuizSkinList(entity me, float i, vector absSize, float isS s = me.skinParameter(me, i, SKINPARM_NAME); s = strcat(s, ": ", me.skinParameter(me, i, SKINPARM_TITLE)); - s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_SKINLIST_TITLE, SKINALPHA_TEXT, 0); + s = draw_TextShortenToWidth(s, me.columnNameSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_SKINLIST_TITLE, SKINALPHA_TEXT, 0); s = me.skinParameter(me, i, SKINPARM_AUTHOR); - s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_SKINLIST_AUTHOR, SKINALPHA_TEXT, 0); + s = draw_TextShortenToWidth(s, me.columnNameSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_SKINLIST_AUTHOR, SKINALPHA_TEXT, 0); } void setSkinNexuizSkinList(entity me) diff --git a/data/qcsrc/menu/nexuiz/util.qc b/data/qcsrc/menu/nexuiz/util.qc index 13446ee24..7ee4e8255 100644 --- a/data/qcsrc/menu/nexuiz/util.qc +++ b/data/qcsrc/menu/nexuiz/util.qc @@ -324,7 +324,7 @@ void preMenuDraw() { fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12; line = eY * fs_y; - sz_x = draw_TextWidth(" http://www.nexuiz.com/ ", 0, fs); + sz_x = draw_TextWidth(" http://www.nexuiz.com/ ", 0) * fs_x; sz_y = 3 * fs_y; draw_alpha = sin(time * 0.112 - 0.3) * 0.7; diff --git a/data/qcsrc/server/cl_player.qc b/data/qcsrc/server/cl_player.qc index 9b3d9b231..5bd84ecb9 100644 --- a/data/qcsrc/server/cl_player.qc +++ b/data/qcsrc/server/cl_player.qc @@ -888,7 +888,7 @@ void Say(entity source, float teamsay, entity privatesay, string msgin, float fl lines = 0; while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax)) { - msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width + msgstr = strcat(msgstr, " ", getWrappedLine(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width ++lines; } msgstr = substring(msgstr, 1, strlen(msgstr) - 1); -- 2.39.2