From: Rudolf Polzer Date: Tue, 6 Jan 2015 16:21:04 +0000 (+0100) Subject: Condense fonts in listboxes too, where they are influenced by translation strings. X-Git-Tag: xonotic-v0.8.0~23 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d9fbe0feb8987959b30fb019008a56023a8869c4;p=xonotic%2Fxonotic-data.pk3dir.git Condense fonts in listboxes too, where they are influenced by translation strings. --- diff --git a/qcsrc/menu/draw.qc b/qcsrc/menu/draw.qc index df93daa6e..afa4d49e0 100644 --- a/qcsrc/menu/draw.qc +++ b/qcsrc/menu/draw.qc @@ -308,6 +308,16 @@ float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye) return v_x; } +float draw_CondensedFontFactor(string theText, float ICanHasKallerz, vector SizeThxBye, float maxWidth) +{ + float w = draw_TextWidth(theText, ICanHasKallerz, SizeThxBye); + if (w > maxWidth) { + //dprintf("NOTE: label text %s too wide for label, condensed by factor %f\n", theText, maxWidth / w); + return maxWidth / w; + } + return 0.8; +} + float draw_clipSet; void draw_SetClip() { diff --git a/qcsrc/menu/draw.qh b/qcsrc/menu/draw.qh index bd75795bb..9632c8fea 100644 --- a/qcsrc/menu/draw.qh +++ b/qcsrc/menu/draw.qh @@ -26,6 +26,7 @@ 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); +float draw_CondensedFontFactor(string theText, float ICanHasKallerz, vector SizeThxBye, float maxWidth); string draw_TextShortenToWidth(string text, float maxWidth, float allowColorCodes, vector size); float draw_TextLengthUpToWidth(string text, float maxWidth, float allowColorCodes, vector size); diff --git a/qcsrc/menu/xonotic/gametypelist.c b/qcsrc/menu/xonotic/gametypelist.c index c7f385761..e3df84467 100644 --- a/qcsrc/menu/xonotic/gametypelist.c +++ b/qcsrc/menu/xonotic/gametypelist.c @@ -76,23 +76,27 @@ void XonoticGametypeList_saveCvars(entity me) } void XonoticGametypeList_drawListBoxItem(entity me, float i, vector absSize, float isSelected) { - string s; + string s1, s2; if(isSelected) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); draw_Picture(me.columnIconOrigin * eX, GameType_GetIcon(i), me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED); - s = GameType_GetName(i); - draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); + s1 = GameType_GetName(i); if(_MapInfo_GetTeamPlayBool(GameType_GetID(i))) - s = _("teamplay"); + s2 = _("teamplay"); else - s = _("free for all"); + s2 = _("free for all"); - draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 1.0 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); - //s = GameType_GetTeams(i); - //draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + vector save_fontscale = draw_fontscale; + float f = draw_CondensedFontFactor(strcat(s1, " ", s2), FALSE, me.realFontSize, 1); + draw_fontscale_x *= f; + vector fs = me.realFontSize; + fs_x *= f; + draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s1, fs, '1 1 1', SKINALPHA_TEXT, 0); + draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 1.0 * (me.columnNameSize - draw_TextWidth(s2, 0, fs))) * eX, s2, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + draw_fontscale = save_fontscale; } void XonoticGametypeList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { diff --git a/qcsrc/menu/xonotic/languagelist.c b/qcsrc/menu/xonotic/languagelist.c index 56d074115..24445786a 100644 --- a/qcsrc/menu/xonotic/languagelist.c +++ b/qcsrc/menu/xonotic/languagelist.c @@ -64,14 +64,25 @@ void XonoticLanguageList_drawListBoxItem(entity me, float i, vector absSize, flo draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); s = me.languageParameter(me, i, LANGPARM_NAME_LOCALIZED); - s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + + vector save_fontscale = draw_fontscale; + float f = draw_CondensedFontFactor(s, FALSE, me.realFontSize, 1); + draw_fontscale_x *= f; + vector fs = me.realFontSize; + fs_x *= f; + draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + draw_fontscale = save_fontscale; p = me.languageParameter(me, i, LANGPARM_PERCENTAGE); if(p != "") { - p = draw_TextShortenToWidth(p, me.columnPercentageSize, 0, me.realFontSize); - draw_Text(me.realUpperMargin * eY + (me.columnPercentageOrigin + (me.columnPercentageSize - draw_TextWidth(p, 0, me.realFontSize))) * eX, p, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + vector save_fontscale = draw_fontscale; + float f = draw_CondensedFontFactor(p, FALSE, me.realFontSize, 1); + draw_fontscale_x *= f; + vector fs = me.realFontSize; + fs_x *= f; + draw_Text(me.realUpperMargin * eY + (me.columnPercentageOrigin + (me.columnPercentageSize - draw_TextWidth(p, 0, fs))) * eX, p, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + draw_fontscale = save_fontscale; } } diff --git a/qcsrc/menu/xonotic/playerlist.c b/qcsrc/menu/xonotic/playerlist.c index 315a68caa..b3ee38670 100644 --- a/qcsrc/menu/xonotic/playerlist.c +++ b/qcsrc/menu/xonotic/playerlist.c @@ -129,9 +129,9 @@ void XonoticPlayerList_drawListBoxItem(entity me, float i, vector absSize, float } s = draw_TextShortenToWidth(s, me.columnNameSize, 1, me.realFontSize); - score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize); - 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); + + score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize); draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + 1.00 * (me.columnScoreSize - draw_TextWidth(score, 1, me.realFontSize))) * eX, score, me.realFontSize, rgb, 1, 0); } diff --git a/qcsrc/menu/xonotic/weaponslist.c b/qcsrc/menu/xonotic/weaponslist.c index b6c536a90..8e573b8c3 100644 --- a/qcsrc/menu/xonotic/weaponslist.c +++ b/qcsrc/menu/xonotic/weaponslist.c @@ -100,7 +100,14 @@ void XonoticWeaponsList_drawListBoxItem(entity me, float i, vector absSize, floa string msg = e.message; if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED) msg = sprintf(_("%s (mutator weapon)"), msg); - draw_Text(me.realUpperMargin * eY, msg, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + + vector save_fontscale = draw_fontscale; + float f = draw_CondensedFontFactor(msg, FALSE, me.realFontSize, 1); + draw_fontscale_x *= f; + vector fs = me.realFontSize; + fs_x *= f; + draw_Text(me.realUpperMargin * eY, msg, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0); + draw_fontscale = save_fontscale; } float XonoticWeaponsList_keyDown(entity me, float scan, float ascii, float shift)