diff --git a/code/cgame/cg_drawtools.cpp b/code/cgame/cg_drawtools.cpp index c6dd9de8..27ea8d6b 100644 --- a/code/cgame/cg_drawtools.cpp +++ b/code/cgame/cg_drawtools.cpp @@ -191,8 +191,8 @@ void CG_DrawDisconnect(void) } handle = cgi.R_RegisterShader("gfx/2d/net.tga"); - w = cgi.R_GetShaderWidth(handle); - h = cgi.R_GetShaderHeight(handle); + w = cgi.R_GetShaderWidth(handle) * cgs.uiHiResScale[0]; + h = cgi.R_GetShaderHeight(handle) * cgs.uiHiResScale[1]; x = ((float)cgs.glconfig.vidWidth - w) * 0.5; y = (float)cgs.glconfig.vidHeight - h; @@ -331,7 +331,7 @@ static void CG_DrawPauseIcon() x = (cgs.glconfig.vidWidth - w) / 2.f; cgi.R_SetColor(colorWhite); - cgi.R_DrawStretchPic(x, y, w, h, 0, 0, 1, 1, handle); + cgi.R_DrawStretchPic(x, y, w * cgs.uiHiResScale[0], h * cgs.uiHiResScale[1], 0, 0, 1, 1, handle); } static void CG_DrawServerLag() @@ -362,8 +362,8 @@ static void CG_DrawServerLag() } handle = cgi.R_RegisterShader("gfx/2d/slowserver"); - w = (float)cgi.R_GetShaderWidth(handle) / 4; - h = (float)cgi.R_GetShaderHeight(handle) / 4; + w = (float)cgi.R_GetShaderWidth(handle) * cgs.uiHiResScale[0] / 4; + h = (float)cgi.R_GetShaderHeight(handle) * cgs.uiHiResScale[1] / 4; x = ((float)cgs.glconfig.vidWidth - w) / 2; y = (float)cgs.glconfig.vidHeight - h; cgi.R_DrawStretchPic(x, y, w, h, 0.0, 0.0, 1.0, 1.0, handle); @@ -580,11 +580,15 @@ void CG_HudDrawElements() int i; float fX, fY; float fWidth, fHeight; + vec2_t virtualScale; if (!cg_huddraw_force->integer && !cg_hud->integer) { return; } + virtualScale[0] = cgs.glconfig.vidWidth / 640.0; + virtualScale[1] = cgs.glconfig.vidWidth / 480.0; + for (i = 0; i < MAX_HUDDRAW_ELEMENTS; i++) { if ((!cgi.HudDrawElements[i].hShader && !cgi.HudDrawElements[i].string[0]) || !cgi.HudDrawElements[i].vColor[3]) { @@ -634,7 +638,7 @@ void CG_HudDrawElements() fX, fY, -1, - cgi.HudDrawElements[i].bVirtualScreen + cgi.HudDrawElements[i].bVirtualScreen ? virtualScale : cgs.uiHiResScale ); } else { cgi.R_DrawString( @@ -643,7 +647,7 @@ void CG_HudDrawElements() fX, fY, -1, - cgi.HudDrawElements[i].bVirtualScreen + cgi.HudDrawElements[i].bVirtualScreen ? virtualScale : cgs.uiHiResScale ); } } else { @@ -734,7 +738,7 @@ void CG_DrawObjectives() vColor[0] = 0.2f; vColor[3] = cg.ObjectivesCurrentAlpha * 0.75; cgi.R_SetColor(vColor); - cgi.R_DrawStretchPic(fX, fY, 450.0, fWidth, 0.0, 0.0, 1.0, 1.0, cgs.media.objectivesBackShader); + cgi.R_DrawStretchPic(fX, fY, 450.0 * cgs.uiHiResScale[0], fWidth * cgs.uiHiResScale[1], 0.0, 0.0, 1.0, 1.0, cgs.media.objectivesBackShader); fX = 30.0; fY = fObjectivesTop + 10; @@ -743,11 +747,11 @@ void CG_DrawObjectives() vColor[2] = 1.0; vColor[3] = cg.ObjectivesCurrentAlpha; cgi.R_SetColor(vColor); - cgi.R_DrawString(cgs.media.objectiveFont, cgi.LV_ConvertString("Mission Objectives:"), fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.objectiveFont, cgi.LV_ConvertString("Mission Objectives:"), fX, fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); fY = fY + 5.0; - cgi.R_DrawString(cgs.media.objectiveFont, "_______________________________________________________", fX, fY, -1, 0); - fHeight = fObjectivesTop + 35; + cgi.R_DrawString(cgs.media.objectiveFont, "_______________________________________________________", fX, fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); + fHeight = fObjectivesTop + 35 * cgs.uiHiResScale[1]; for (i = 0; i < MAX_OBJECTIVES; ++i) { qhandle_t hBoxShader; @@ -785,7 +789,14 @@ void CG_DrawObjectives() cgi.R_SetColor(vColor); fX = 55.0; fY = fHeight; - cgi.R_DrawString(cgs.media.objectiveFont, cgi.LV_ConvertString(cg.Objectives[i].text), 55.0, fHeight, -1, 0); + cgi.R_DrawString( + cgs.media.objectiveFont, + cgi.LV_ConvertString(cg.Objectives[i].text), + 55.0, + fY / cgs.uiHiResScale[1], + -1, + cgs.uiHiResScale + ); fX = 30.0; fY = fHeight; @@ -794,9 +805,19 @@ void CG_DrawObjectives() vColor[2] = 1.0; vColor[3] = cg.ObjectivesCurrentAlpha; cgi.R_SetColor(vColor); - cgi.R_DrawStretchPic(fX, fY, 16.0, 16.0, 0.0, 0.0, 1.0, 1.0, hBoxShader); + cgi.R_DrawStretchPic( + fX * cgs.uiHiResScale[0], + fY, + 16.0 * cgs.uiHiResScale[0], + 16.0 * cgs.uiHiResScale[1], + 0.0, + 0.0, + 1.0, + 1.0, + hBoxShader + ); - fHeight += iNumLines[i] * 12 + 25; + fHeight += iNumLines[i] * 12 + 25 * cgs.uiHiResScale[1]; } } @@ -820,7 +841,17 @@ void CG_DrawPlayerTeam() if (handle) { cgi.R_SetColor(NULL); - cgi.R_DrawStretchPic(96.0, cgs.glconfig.vidHeight - 46, 24.0, 24.0, 0.0, 0.0, 1.0, 1.0, handle); + cgi.R_DrawStretchPic( + 96.0 * cgs.uiHiResScale[0], + cgs.glconfig.vidHeight - 46 * cgs.uiHiResScale[1], + 24.0 * cgs.uiHiResScale[0], + 24.0 * cgs.uiHiResScale[1], + 0.0, + 0.0, + 1.0, + 1.0, + handle + ); } } @@ -862,13 +893,12 @@ void CG_DrawPlayerEntInfo() if (handle) { cgi.R_SetColor(0); - cgi.R_DrawStretchPic(56.0, fY, 16.0, 16.0, 0.0, 0.0, 1.0, 1.0, handle); - fX = 56.0 + 24.0; + cgi.R_DrawStretchPic(fX, fY, 16.0 * cgs.uiHiResScale[0], 16.0 * cgs.uiHiResScale[1], 0.0, 0.0, 1.0, 1.0, handle); } cgi.R_SetColor(color); - cgi.R_DrawString(cgs.media.hudDrawFont, (char *)pszName, fX, fY, -1, 0); - cgi.R_DrawString(cgs.media.hudDrawFont, va("%i", cg.snap->ps.stats[STAT_INFOCLIENT_HEALTH]), fX, fY + 20.0, -1, 0); + cgi.R_DrawString(cgs.media.hudDrawFont, (char *)pszName, fX / cgs.uiHiResScale[0] + 24.0, fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); + cgi.R_DrawString(cgs.media.hudDrawFont, va("%i", cg.snap->ps.stats[STAT_INFOCLIENT_HEALTH]), fX / cgs.uiHiResScale[0] + 24.0, fY / cgs.uiHiResScale[1] + 20.0, -1, cgs.uiHiResScale); } void CG_UpdateAttackerDisplay() @@ -907,7 +937,17 @@ void CG_UpdateAttackerDisplay() if (handle) { cgi.R_SetColor(0); - cgi.R_DrawStretchPic(56.0, fY, 24.0, 24.0, 0.0, 0.0, 1.0, 1.0, handle); + cgi.R_DrawStretchPic( + 56.0 * cgs.uiHiResScale[0], + fY, + 24.0 * cgs.uiHiResScale[0], + 24.0 * cgs.uiHiResScale[1], + 0.0, + 0.0, + 1.0, + 1.0, + handle + ); } if ((cg.snap->ps.stats[STAT_TEAM] == TEAM_ALLIES || cg.snap->ps.stats[STAT_TEAM] == TEAM_AXIS) @@ -921,7 +961,7 @@ void CG_UpdateAttackerDisplay() color[2] = 0.5; } - fX = 56.0 + 32.0; + fX = 56.0; } else { color[0] = 1.0; color[1] = 0.5; @@ -929,7 +969,7 @@ void CG_UpdateAttackerDisplay() } cgi.R_SetColor(color); - cgi.R_DrawString(cgs.media.attackerFont, pszName, fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.attackerFont, pszName, fX / cgs.uiHiResScale[0] + 32.0, fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); } void CG_UpdateCountdown() @@ -1043,7 +1083,7 @@ void CG_DrawInstantMessageMenu() x = 8.0; y = ((float)cgs.glconfig.vidHeight - h) * 0.5; cgi.R_SetColor(0); - cgi.R_DrawStretchPic(x, y, w, h, 0.0, 0.0, 1.0, 1.0, handle); + cgi.R_DrawStretchPic(x * cgs.uiHiResScale[0], y, w * cgs.uiHiResScale[0], h * cgs.uiHiResScale[1], 0.0, 0.0, 1.0, 1.0, handle); } void CG_DrawSpectatorView_ver_15() @@ -1069,7 +1109,7 @@ void CG_DrawSpectatorView_ver_15() fX = (float)(cgs.glconfig.vidWidth - cgi.UI_FontStringWidth(cgs.media.attackerFont, pszString, -1)) * 0.5; fY = cgs.glconfig.vidHeight - 64.0; cgi.R_SetColor(NULL); - cgi.R_DrawString(cgs.media.attackerFont, pszString, fX, fY, -1, qfalse); + cgi.R_DrawString(cgs.media.attackerFont, pszString, fX / cgs.uiHiResScale[0], fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); } if (cg.predicted_player_state.pm_flags & PMF_CAMERA_VIEW) { @@ -1085,7 +1125,7 @@ void CG_DrawSpectatorView_ver_15() fX = (float)(cgs.glconfig.vidWidth - cgi.UI_FontStringWidth(cgs.media.attackerFont, pszString, -1)) * 0.5; fY = (float)cgs.glconfig.vidHeight - 40.0; cgi.R_SetColor(0); - cgi.R_DrawString(cgs.media.attackerFont, pszString, fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.attackerFont, pszString, fX / cgs.uiHiResScale[0], fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); } if (!bOnTeam && (cg.predicted_player_state.pm_flags & PMF_CAMERA_VIEW)) { @@ -1096,7 +1136,7 @@ void CG_DrawSpectatorView_ver_15() fX = (float)(cgs.glconfig.vidWidth - cgi.UI_FontStringWidth(cgs.media.attackerFont, pszString, -1)) * 0.5; fY = (float)cgs.glconfig.vidHeight - 24.0; cgi.R_SetColor(0); - cgi.R_DrawString(cgs.media.attackerFont, pszString, fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.attackerFont, pszString, fX / cgs.uiHiResScale[0], fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); } if (!(cg.predicted_player_state.pm_flags & PMF_CAMERA_VIEW)) { @@ -1109,10 +1149,10 @@ void CG_DrawSpectatorView_ver_15() fX = (float)(cgs.glconfig.vidWidth - cgi.UI_FontStringWidth(cgs.media.attackerFont, pszString, -1)) * 0.5; fY = (float)cgs.glconfig.vidHeight - 24.0; cgi.R_SetColor(0); - cgi.R_DrawString(cgs.media.attackerFont, pszString, fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.attackerFont, pszString, fX / cgs.uiHiResScale[0], fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); } - if ((cg.predicted_player_state.pm_flags & 0x80) != 0 && cg.snap && cg.snap->ps.stats[STAT_INFOCLIENT] != -1) { + if ((cg.predicted_player_state.pm_flags & PMF_CAMERA_VIEW) != 0 && cg.snap && cg.snap->ps.stats[STAT_INFOCLIENT] != -1) { int iClientNum; qhandle_t hShader; vec4_t color; @@ -1130,7 +1170,7 @@ void CG_DrawSpectatorView_ver_15() fX = (float)(cgs.glconfig.vidWidth - cgi.UI_FontStringWidth(cgs.media.attackerFont, pszString, -1) - 16) * 0.5; fY = (float)cgs.glconfig.vidHeight - 80.0; cgi.R_SetColor(color); - cgi.R_DrawString(cgs.media.attackerFont, buf, fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.attackerFont, buf, fX / cgs.uiHiResScale[0], fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); if (cg.clientinfo[iClientNum].team == TEAM_ALLIES) { hShader = cgi.R_RegisterShader("textures/hud/allies"); @@ -1139,9 +1179,18 @@ void CG_DrawSpectatorView_ver_15() } if (hShader) { - fX -= 20.0; cgi.R_SetColor(NULL); - cgi.R_DrawStretchPic(fX, fY, 16.0, 16.0, 0.0, 0.0, 1.0, 1.0, hShader); + cgi.R_DrawStretchPic( + fX - 20.0 * cgs.uiHiResScale[0], + fY, + 16.0 * cgs.uiHiResScale[0], + 16.0 * cgs.uiHiResScale[1], + 0.0, + 0.0, + 1.0, + 1.0, + hShader + ); } } } @@ -1176,7 +1225,7 @@ void CG_DrawSpectatorView_ver_6() fX = (float)(cgs.glconfig.vidWidth - cgi.UI_FontStringWidth(cgs.media.attackerFont, pszString, -1)) * 0.5; fY = (float)cgs.glconfig.vidHeight - 40.0; cgi.R_SetColor(0); - cgi.R_DrawString(cgs.media.attackerFont, pszString, fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.attackerFont, pszString, fX / cgs.uiHiResScale[0], fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); if (!bOnTeam && (cg.predicted_player_state.pm_flags & PMF_CAMERA_VIEW)) { cgi.Key_GetKeysForCommand("+moveup", &iKey1, &iKey2); @@ -1190,7 +1239,7 @@ void CG_DrawSpectatorView_ver_6() fX = (float)(cgs.glconfig.vidWidth - cgi.UI_FontStringWidth(cgs.media.attackerFont, pszString, -1)) * 0.5; fY = (float)cgs.glconfig.vidHeight - 24.0; cgi.R_SetColor(0); - cgi.R_DrawString(cgs.media.attackerFont, pszString, fX, fY, -1, 0); + cgi.R_DrawString(cgs.media.attackerFont, pszString, fX / cgs.uiHiResScale[0], fY / cgs.uiHiResScale[1], -1, cgs.uiHiResScale); } } @@ -1287,7 +1336,17 @@ void CG_DrawCrosshair() y = (cgs.glconfig.vidHeight - height) * 0.5f; cgi.R_SetColor(NULL); - cgi.R_DrawStretchPic(x, y, width, height, 0, 0, 1, 1, shader); + cgi.R_DrawStretchPic( + x, + y, + width * cgs.uiHiResScale[0], + height * cgs.uiHiResScale[1], + 0, + 0, + 1, + 1, + shader + ); } } @@ -1324,7 +1383,7 @@ void CG_DrawVote() cgi.R_SetColor(NULL); text = va("%s: %s", cgi.LV_ConvertString("Vote Running"), cgs.voteString); - cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, qfalse); + cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, cgs.uiHiResScale); y += 12; @@ -1338,7 +1397,7 @@ void CG_DrawVote() percentNo, cgi.LV_ConvertString("Undecided"), percentUndecided); - cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, qfalse); + cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, cgs.uiHiResScale); if (cg.snap && !cg.snap->ps.voted) { col[0] = 0.5; @@ -1350,12 +1409,12 @@ void CG_DrawVote() y += 12; text = cgi.LV_ConvertString("Vote now, it's your patriotic duty!"); - cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, qfalse); + cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, cgs.uiHiResScale); y += 12; text = cgi.LV_ConvertString("To vote Yes, press F1. To vote No, press F2."); - cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, qfalse); + cgi.R_DrawString(cgs.media.attackerFont, text, x, y, -1, cgs.uiHiResScale); cgi.R_SetColor(NULL); } } diff --git a/code/cgame/cg_local.h b/code/cgame/cg_local.h index 05a3ef61..313c0c1a 100644 --- a/code/cgame/cg_local.h +++ b/code/cgame/cg_local.h @@ -380,6 +380,7 @@ extern "C" { float screenXScale; // derived from glconfig float screenYScale; float screenXBias; + vec2_t uiHiResScale; int serverCommandSequence; // reliable command stream counter int processedSnapshotNum; // the number of snapshots cgame has requested diff --git a/code/cgame/cg_main.c b/code/cgame/cg_main.c index 6b00d8e1..17468f3b 100644 --- a/code/cgame/cg_main.c +++ b/code/cgame/cg_main.c @@ -570,6 +570,7 @@ void CG_GetRendererConfig(void) cgi.GetGlconfig(&cgs.glconfig); cgs.screenXScale = cgs.glconfig.vidWidth / 640.0; cgs.screenYScale = cgs.glconfig.vidHeight / 480.0; + cgi.UI_GetHighResolutionScale(&cgs.uiHiResScale); } /* diff --git a/code/cgame/cg_public.h b/code/cgame/cg_public.h index b1e76f85..7d01c86c 100644 --- a/code/cgame/cg_public.h +++ b/code/cgame/cg_public.h @@ -312,7 +312,7 @@ functions exported to the main executable ); // 0 = white fontheader_t *(*R_LoadFont)(const char *name); void (*R_DrawString)( - fontheader_t *font, const char *text, float x, float y, int maxLen, qboolean virtualScreen + fontheader_t *font, const char *text, float x, float y, int maxLen, const float *pvVirtualScreen ); refEntity_t *(*R_GetRenderEntity)(int entityNumber); void (*R_ModelBounds)(clipHandle_t model, vec3_t mins, vec3_t maxs); @@ -363,6 +363,7 @@ functions exported to the main executable int (*UI_FontStringWidth)(fontheader_t *font, const char *string, int maxLen); // Added in 2.0 float (*UI_GetObjectivesTop)(void); + void (*UI_GetHighResolutionScale)(vec2_t scale); int (*Key_StringToKeynum)(const char *str); const char *(*Key_KeynumToBindString)(int keyNum); diff --git a/code/client/cl_cgame.cpp b/code/client/cl_cgame.cpp index 89d6c093..16454809 100644 --- a/code/client/cl_cgame.cpp +++ b/code/client/cl_cgame.cpp @@ -774,6 +774,7 @@ void CL_InitCGameDLL( clientGameImport_t *cgi, clientGameExport_t **cge ) { cgi->UI_HideMenu = UI_HideMenu; cgi->UI_FontStringWidth = CL_FontStringWidth; cgi->UI_GetObjectivesTop = UI_GetObjectivesTop; + cgi->UI_GetHighResolutionScale = UI_GetHighResolutionScale; cgi->Key_StringToKeynum = Key_StringToKeynum; cgi->Key_KeynumToBindString = Key_KeynumToBindString; cgi->Key_GetKeysForCommand = Key_GetKeysForCommand; diff --git a/code/client/cl_ui.cpp b/code/client/cl_ui.cpp index f66a1d18..abfdcf22 100644 --- a/code/client/cl_ui.cpp +++ b/code/client/cl_ui.cpp @@ -1009,7 +1009,7 @@ static UIRect2D getQuickMessageDMConsoleRectangle(void) // Was 38.0 in 1.11 and below // This prevents characters to be seen from the DM console // in the quick message console - rect.size.height = 36.0; + rect.size.height = 36.0 * uid.scaleRes[1]; } return rect; @@ -1196,7 +1196,7 @@ static UIRect2D getDefaultGMBoxRectangle(void) height = y; } - return UIRect2D(20.0f, height, uid.vidWidth - 20, 128.0f); + return UIRect2D(20.0f, height, (uid.vidWidth - 20) * uid.scaleRes[0], 128.0f * uid.scaleRes[1]); } /* @@ -1206,9 +1206,9 @@ getDefaultDMBoxRectangle */ static UIRect2D getDefaultDMBoxRectangle(void) { - float width = uid.vidWidth * ui_compass_scale->value * 0.2f; + float width = uid.vidWidth * uid.scaleRes[0] * ui_compass_scale->value * 0.2f; - return UIRect2D(width, 0, uid.vidWidth - (width + 192.0f), 120.0f); + return UIRect2D(width, 0, (uid.vidWidth - (width + 192.0f)) * uid.scaleRes[0], 120.0f * uid.scaleRes[1]); } /* @@ -1221,6 +1221,21 @@ float UI_GetObjectivesTop(void) return getDefaultGMBoxRectangle().pos.y; } +/* +==================== +UI_GetObjectivesTop +==================== +*/ +void UI_GetHighResolutionScale(vec2_t scale) +{ + if (uid.bHighResScaling) { + scale[0] = uid.scaleRes[0]; + scale[1] = uid.scaleRes[1]; + } else { + scale[0] = scale[1] = 1.0; + } +} + /* ==================== UI_ShowHudList @@ -3831,6 +3846,8 @@ UI_ResolutionChange void UI_ResolutionChange(void) { UIRect2D frame; + const float maxWidthRes = 1920; + const float maxHeightRes = 1080; if (com_target_game->integer >= TG_MOHTA) { ui_compass_scale = Cvar_Get("ui_compass_scale", "0.75", CVAR_ARCHIVE | CVAR_LATCH); @@ -3842,6 +3859,22 @@ void UI_ResolutionChange(void) CL_FillUIImports(); CL_FillUIDef(); + // Added in OPM + // Scaling for high resolutions + if (uid.vidWidth > maxWidthRes && uid.vidHeight > maxHeightRes) { + const float vidRatio = (float)uid.vidWidth / (float)uid.vidHeight; + + uid.scaleRes[0] = (float)uid.vidWidth / (maxHeightRes * vidRatio); + uid.scaleRes[1] = (float)uid.vidHeight / maxHeightRes; + //uid.scaleRes[0] = (float)uid.vidWidth / maxWidthRes; + //uid.scaleRes[1] = (float)uid.vidHeight / maxHeightRes; + uid.bHighResScaling = qtrue; + } else { + uid.scaleRes[0] = 1; + uid.scaleRes[1] = 1; + uid.bHighResScaling = qfalse; + } + if (!uie.ResolutionChange) { return; } @@ -4409,7 +4442,7 @@ void ScoreboardListItem::DrawListItem(int iColumn, const UIRect2D& drawRect, boo { DrawBox(drawRect, backColor, 1.0); pFont->setColor(textColor); - pFont->Print(drawRect.pos.x + 1, drawRect.pos.y, Sys_LV_CL_ConvertString(getListItemString(iColumn)), -1, qfalse); + pFont->Print((drawRect.pos.x + 1) / uid.scaleRes[0], drawRect.pos.y / uid.scaleRes[1], Sys_LV_CL_ConvertString(getListItemString(iColumn)), -1, uid.scaleRes); if (bTitleItem) { UIRect2D lineRect; diff --git a/code/client/cl_ui.h b/code/client/cl_ui.h index fce7c3b7..60da029e 100644 --- a/code/client/cl_ui.h +++ b/code/client/cl_ui.h @@ -57,6 +57,7 @@ void UI_ClearState(void); void CL_BeginRegistration(void); void CL_EndRegistration(void); float UI_GetObjectivesTop(void); +void UI_GetHighResolutionScale(vec2_t scale); // // menu diff --git a/code/client/cl_uidmbox.cpp b/code/client/cl_uidmbox.cpp index 95fc1ec5..98e49fb6 100644 --- a/code/client/cl_uidmbox.cpp +++ b/code/client/cl_uidmbox.cpp @@ -266,15 +266,15 @@ float UIDMBox::PrintWrap( UIFont *font, float x, float y, str text ) break; } - font->Print(x, fY, p1, p2 - p1, qfalse); + font->Print(x, fY, p1, p2 - p1, getHighResScale()); p1 = p2 + 1; l -= n; - fY += font->getHeight(qfalse); + fY += font->getHeight(); } - font->Print(x, fY, p1, l, qfalse); + font->Print(x, fY, p1, l, getHighResScale()); - return font->getHeight(qfalse) + (fY - y); + return font->getHeight() + (fY - y); } float UIDMBox::DrawItem( item_t *in, float x, float y, float alpha ) diff --git a/code/client/cl_uigmbox.cpp b/code/client/cl_uigmbox.cpp index 5266a01f..8823fa56 100644 --- a/code/client/cl_uigmbox.cpp +++ b/code/client/cl_uigmbox.cpp @@ -260,15 +260,15 @@ float UIGMBox::PrintWrap( UIFont *font, float x, float y, str text ) break; } - font->Print(x, fY, p1, p2 - p1, qfalse); + font->Print(x, fY, p1, p2 - p1, getHighResScale()); p1 = p2 + 1; l -= n; - fY += font->getHeight(qfalse); + fY += font->getHeight(); } - font->Print(x, fY, p1, l, qfalse); + font->Print(x, fY, p1, l, getHighResScale()); - return font->getHeight(qfalse) + (fY - y); + return font->getHeight() + (fY - y); } float UIGMBox::DrawItem( item_t *in, float x, float y, float alpha ) diff --git a/code/client/cl_uiminicon.cpp b/code/client/cl_uiminicon.cpp index d0d02723..c1c8e6db 100644 --- a/code/client/cl_uiminicon.cpp +++ b/code/client/cl_uiminicon.cpp @@ -112,7 +112,7 @@ void FakkMiniconsole::PostMoveinEvent(void) void FakkMiniconsole::OnSizeChanged(Event *ev) { - m_maxlines = m_frame.size.height / m_font->getHeight(false); + m_maxlines = m_frame.size.height / m_font->getHeight(getHighResScale()); } void FakkMiniconsole::MoveInEvent(Event *ev) @@ -163,14 +163,14 @@ void FakkMiniconsole::Draw(void) HandleBoxMoving(); m_font->setColor(m_foreground_color); - aty = m_frame.size.height - m_font->getHeight(false); + aty = m_frame.size.height - m_font->getHeight(getHighResScale()); for (i = m_lines.NumObjects(); i > 0; i--) { - if (-m_font->getHeight(false) >= aty) { + if (-m_font->getHeight(getHighResScale()) >= aty) { break; } - m_font->Print(0, aty, m_lines.ObjectAt(i), -1, false); - aty -= m_font->getHeight(false); + m_font->Print(0, aty / getHighResScale()[1], m_lines.ObjectAt(i), -1, getHighResScale()); + aty -= m_font->getHeight(getHighResScale()); } } diff --git a/code/client/cl_uiserverlist.cpp b/code/client/cl_uiserverlist.cpp index c40716c7..eca7fde8 100644 --- a/code/client/cl_uiserverlist.cpp +++ b/code/client/cl_uiserverlist.cpp @@ -177,6 +177,9 @@ void FAKKServerListItem::DrawListItem(int iColumn, const UIRect2D& drawRect, boo newRect.size.height *= uid.vidHeight / 768; } */ + + virtualScale[0] = m_parent->getHighResScale()[0]; + virtualScale[1] = m_parent->getHighResScale()[1]; if (!pColoringType->integer) { if (IfQueryFailed() || (IsDifferentVersion() && IsQueried())) { @@ -210,7 +213,7 @@ void FAKKServerListItem::DrawListItem(int iColumn, const UIRect2D& drawRect, boo newRect.pos.y / virtualScale[1], getListItemString(iColumn).c_str(), -1, - false //m_parent->isVirtual() + virtualScale ); } else { if (IsDifferentVersion()) { @@ -266,7 +269,7 @@ void FAKKServerListItem::DrawListItem(int iColumn, const UIRect2D& drawRect, boo newRect.pos.y / virtualScale[1], getListItemString(iColumn).c_str(), -1, - false //m_parent->isVirtual() + virtualScale ); if (IsDifferentVersion()) { diff --git a/code/client/cl_uistd.cpp b/code/client/cl_uistd.cpp index 639881f8..4fd41c6e 100644 --- a/code/client/cl_uistd.cpp +++ b/code/client/cl_uistd.cpp @@ -443,6 +443,7 @@ void UIFakkLabel::DrawStatbar(float frac) float alpha; qhandle_t hMat; float w, h; + float fvWidth, fvHeight; col[0] = col[1] = col[2] = col[3] = 1.0; @@ -488,11 +489,20 @@ void UIFakkLabel::DrawStatbar(float frac) { float width = frac * m_frame.size.width; - re.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material->GetMaterial()); + fvWidth = m_frame.size.width / m_vVirtualScale[0] / uii.Rend_GetShaderWidth(m_statbar_material->GetMaterial()); + fvHeight = m_frame.size.height / m_vVirtualScale[1] / uii.Rend_GetShaderHeight(m_statbar_material->GetMaterial()); + + re.DrawStretchPic(0.0, 0.0, width, m_frame.size.height, 0, 0, fvWidth, fvHeight, m_statbar_material->GetMaterial()); + //re.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material->GetMaterial()); if (alpha != 0.0 && m_statbar_material_flash) { re.SetColor(col); - re.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material_flash->GetMaterial()); + + fvWidth = m_frame.size.width / m_vVirtualScale[0] / uii.Rend_GetShaderWidth(m_statbar_material_flash->GetMaterial()); + fvHeight = m_frame.size.height / m_vVirtualScale[1] / uii.Rend_GetShaderHeight(m_statbar_material_flash->GetMaterial()); + + re.DrawStretchPic(0.0, 0.0, width, m_frame.size.height, 0, 0, fvWidth, fvHeight, m_statbar_material_flash->GetMaterial()); + //re.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material_flash->GetMaterial()); } if (m_statbar_material_marker) { @@ -521,13 +531,22 @@ void UIFakkLabel::DrawStatbar(float frac) { float y = m_frame.size.height * (1.0 - frac); - re.DrawTilePic(0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material->GetMaterial()); + fvWidth = m_frame.size.width / m_vVirtualScale[0] / uii.Rend_GetShaderWidth(m_statbar_material->GetMaterial()); + fvHeight = m_frame.size.height / m_vVirtualScale[1] / uii.Rend_GetShaderHeight(m_statbar_material->GetMaterial()); + + re.DrawStretchPic(0.0, y, m_frame.size.width, m_frame.size.height, 0, 0, fvWidth, fvHeight, m_statbar_material->GetMaterial()); + //re.DrawTilePic(0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material->GetMaterial()); if (alpha != 0.0 && m_statbar_material_flash) { re.SetColor(col); - re.DrawTilePic( - 0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material_flash->GetMaterial() - ); + + fvWidth = m_frame.size.width / m_vVirtualScale[0] / uii.Rend_GetShaderWidth(m_statbar_material_flash->GetMaterial()); + fvHeight = m_frame.size.height / m_vVirtualScale[1] / uii.Rend_GetShaderHeight(m_statbar_material_flash->GetMaterial()); + + re.DrawStretchPic(0.0, y, m_frame.size.width, m_frame.size.height, 0, 0, fvWidth, fvHeight, m_statbar_material_flash->GetMaterial()); + //re.DrawTilePic( + // 0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material_flash->GetMaterial() + //); } if (m_statbar_material_marker) { @@ -961,8 +980,8 @@ void UIFakkLabel::DrawStatRotator(float frac) vNeedleDir[0] = fSinVal; vNeedleDir[1] = -fCosVal; - vSize[0] = (m_frame.size.width + m_frame.size.height) / m_frame.size.width * m_angles[2] * m_vVirtualScale[0]; - vSize[1] = (m_frame.size.width + m_frame.size.height) / m_frame.size.height * m_scale * m_vVirtualScale[1]; + vSize[0] = (m_frame.size.width + m_frame.size.height) / m_frame.size.width * m_angles[2] * getVirtualScale()[0]; + vSize[1] = (m_frame.size.width + m_frame.size.height) / m_frame.size.height * m_scale * getVirtualScale()[1]; vCenter[0] = (m_frame.size.width * 0.5f - vSize[0]) * vNeedleDir[0] + m_frame.size.width * 0.5f; vCenter[1] = (m_frame.size.height * 0.5f - vSize[1]) * vNeedleDir[1] + m_frame.size.height * 0.5f; @@ -1357,7 +1376,7 @@ void UIFakkLabel::Draw(void) m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(va("%s", CL_ConfigString(cl.snap.ps.stats[m_stat_configstring]))), UBlack, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } else { m_font->PrintJustified( @@ -1365,7 +1384,7 @@ void UIFakkLabel::Draw(void) m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(va("%s", CL_ConfigString(cl.snap.ps.stats[m_stat_configstring]))), - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } return; @@ -1384,7 +1403,7 @@ void UIFakkLabel::Draw(void) m_iFontAlignmentVertical, va("%d", delta), UBlack, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } else { m_font->PrintJustified( @@ -1392,7 +1411,7 @@ void UIFakkLabel::Draw(void) m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, va("%d", delta), - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } return; @@ -1478,7 +1497,7 @@ void UIFakkLabel::Draw(void) m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(va("%s", CL_ConfigString(CS_WEAPONS + cl.snap.ps.activeItems[m_itemindex]))), UBlack, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } else { m_font->PrintJustified( @@ -1486,7 +1505,7 @@ void UIFakkLabel::Draw(void) m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(va("%s", CL_ConfigString(CS_WEAPONS + cl.snap.ps.activeItems[m_itemindex]))), - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } diff --git a/code/client/cl_uiview3d.cpp b/code/client/cl_uiview3d.cpp index 234e89a7..98440439 100644 --- a/code/client/cl_uiview3d.cpp +++ b/code/client/cl_uiview3d.cpp @@ -124,9 +124,9 @@ void View3D::DrawFPS(void) re.SetColor(UBlack); re.DrawBox( 0.0, - m_frame.pos.y + m_frame.size.height - m_font->getHeight(qfalse) * 4.0, + m_frame.pos.y + m_frame.size.height - m_font->getHeight() * 4.0, m_frame.pos.x + m_frame.size.width, - m_font->getHeight(qfalse) * 4.0 + m_font->getHeight() * 4.0 ); } @@ -145,11 +145,11 @@ void View3D::DrawFPS(void) } m_font->Print( - m_font->getHeight(qfalse) * 10.0, - m_frame.pos.y + m_frame.size.height - m_font->getHeight(qfalse) * 3.0, + m_font->getHeight(getHighResScale()) * 10.0 / getHighResScale()[0], + (m_frame.pos.y + m_frame.size.height - m_font->getHeight(getHighResScale()) * 3.0) / getHighResScale()[1], string, -1, - qfalse + getHighResScale() ); // Draw elements count @@ -162,11 +162,11 @@ void View3D::DrawFPS(void) Com_sprintf(string, sizeof(string), "wt%5d wv%5d cl%d", cls.world_tris, cls.world_verts, cls.character_lights); m_font->Print( - m_font->getHeight(qfalse) * 10.0, - m_frame.pos.y + m_frame.size.height - m_font->getHeight(qfalse) * 2.0, + (m_font->getHeight(getHighResScale()) * 10.0) / getHighResScale()[0], + (m_frame.pos.y + m_frame.size.height - m_font->getHeight(getHighResScale()) * 2.0) / getHighResScale()[1], string, -1, - qfalse + getHighResScale() ); Com_sprintf( @@ -179,11 +179,11 @@ void View3D::DrawFPS(void) ); m_font->Print( - m_font->getHeight(qfalse) * 10.0, - m_frame.pos.y + m_frame.size.height - m_font->getHeight(qfalse), + (m_font->getHeight(getHighResScale()) * 10.0) / getHighResScale()[0], + (m_frame.pos.y + m_frame.size.height - m_font->getHeight(getHighResScale())) / getHighResScale()[1], string, -1, - qfalse + getHighResScale() ); m_font->setColor(UBlack); @@ -208,32 +208,32 @@ void View3D::PrintSound(int channel, const char *name, float vol, int rvol, floa float xStep; float height; - height = m_font->getHeight(false); + height = m_font->getHeight(getHighResScale()); xStep = height; x = 0; Com_sprintf(buf, sizeof(buf), "%d", channel); - m_font->Print(x, height * line + m_frame.pos.y, buf, -1, false); + m_font->Print(x, height * line + m_frame.pos.y, buf, -1, getHighResScale()); x += xStep + xStep; Com_sprintf(buf, sizeof(buf), "%s", name); - m_font->Print(x, height * line + m_frame.pos.y, buf, -1, false); + m_font->Print(x, height * line + m_frame.pos.y, buf, -1, getHighResScale()); x += xStep * 30.0; Com_sprintf(buf, sizeof(buf), "vol:%.2f", vol); - m_font->Print(x, height * line + m_frame.pos.y, buf, -1, false); + m_font->Print(x, height * line + m_frame.pos.y, buf, -1, getHighResScale()); x += xStep * 8; Com_sprintf(buf, sizeof(buf), "rvol:%.2f", (float)(rvol / 128.f)); - m_font->Print(x, height * line + m_frame.pos.y, buf, -1, false); + m_font->Print(x, height * line + m_frame.pos.y, buf, -1, getHighResScale()); x += xStep * 5; Com_sprintf(buf, sizeof(buf), "pit:%.2f", pitch); - m_font->Print(x, height * line + m_frame.pos.y, buf, -1, false); + m_font->Print(x, height * line + m_frame.pos.y, buf, -1, getHighResScale()); x += xStep * 5; Com_sprintf(buf, sizeof(buf), "base:%d", (int)base); - m_font->Print(x, height * line + m_frame.pos.y, buf, -1, false); + m_font->Print(x, height * line + m_frame.pos.y, buf, -1, getHighResScale()); line++; } @@ -264,8 +264,7 @@ void DisplayServerNetProfileInfo(UIFont *font, float y, netprofclient_t *netprof (unsigned int)((float)(netprofile->outPackets.numFragmented + netprofile->inPackets.numFragmented) / (float)(netprofile->inPackets.totalProcessed + netprofile->outPackets.totalProcessed) )), - -1, - qfalse + -1 ); font->Print(334, y, va("%i", netprofile->inPackets.percentDropped)); font->Print(364, y, va("%i", netprofile->outPackets.percentDropped)); @@ -276,8 +275,7 @@ void DisplayServerNetProfileInfo(UIFont *font, float y, netprofclient_t *netprof (unsigned int)((float)(netprofile->outPackets.numDropped + netprofile->inPackets.numDropped) / (float)(netprofile->inPackets.totalProcessed + netprofile->outPackets.totalProcessed) )), - -1, - qfalse + -1 ); font->Print(434, y, va("%i", netprofile->inPackets.percentDropped)); font->Print(464, y, va("%i", netprofile->outPackets.percentDropped)); @@ -288,8 +286,7 @@ void DisplayServerNetProfileInfo(UIFont *font, float y, netprofclient_t *netprof (unsigned int)((float)(netprofile->outPackets.totalLengthConnectionLess + netprofile->inPackets.totalLengthConnectionLess) / (float)(netprofile->outPackets.totalSize + netprofile->inPackets.totalSize))), - -1, - qfalse + -1 ); font->Print(534, y, va("%i", netprofile->inPackets.bytesPerSec)); font->Print(594, y, va("%i", netprofile->outPackets.bytesPerSec)); @@ -303,7 +300,7 @@ void DisplayClientNetProfile(UIFont *font, float x, float y, netprofclient_t *ne float fontHeight; float columnHeight; - fontHeight = font->getHeight(qfalse); + fontHeight = font->getHeight(); columns[0] = x + 120; columns[1] = x + 230; columns[2] = x + 330; @@ -402,13 +399,13 @@ void View3D::DrawNetProfile(void) setFont("verdana-14"); m_font->setColor(UWhite); - fontHeight = m_font->getHeight(qfalse); + fontHeight = m_font->getHeight(); yOffset = sv_netprofileoverlay->integer + 8; if (svs.netprofile.rate) { - m_font->Print(8, yOffset, va("Server Net Profile Max Rate: %i", svs.netprofile.rate), -1, qfalse); + m_font->Print(8, yOffset, va("Server Net Profile Max Rate: %i", svs.netprofile.rate), -1); } else { - m_font->Print(8, yOffset, "Server Net Profile Max Rate: none", -1, qfalse); + m_font->Print(8, yOffset, "Server Net Profile Max Rate: none", -1); } columnHeight = fontHeight + fontHeight + yOffset; @@ -487,10 +484,10 @@ void View3D::DrawNetProfile(void) setFont("verdana-14"); m_font->setColor(UWhite); - fontHeight = m_font->getHeight(qfalse); + fontHeight = m_font->getHeight(); yOffset = cl_netprofileoverlay->integer + 16; - m_font->Print(16, yOffset, "Client Net Profile", -1, qfalse); + m_font->Print(16, yOffset, "Client Net Profile", -1); NetProfileCalcStats(&cls.netprofile.outPackets, 500); NetProfileCalcStats(&cls.netprofile.inPackets, 500); @@ -567,7 +564,7 @@ void View3D::CenterPrint(void) m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, p, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); m_font->setColor(UColor(1, 1, 1, alpha)); @@ -575,7 +572,7 @@ void View3D::CenterPrint(void) frame = getClientFrame(); m_font->PrintJustified( - frame, m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, p, m_bVirtual ? m_vVirtualScale : NULL + frame, m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, p, getVirtualScale() ); m_font->setColor(UBlack); @@ -628,7 +625,7 @@ void View3D::LocationPrint(void) alpha = Q_clamp_float(alpha, 0, 1); x = m_x_coord / 640.f * m_screenframe.size.width; - y = (480 - m_font->getHeight(false) - m_y_coord) / 480.f * m_screenframe.size.height; + y = (480 - m_font->getHeight(getHighResScale()) - m_y_coord) / 480.f * m_screenframe.size.height; if (m_x_coord == -1) { horiz = FONT_JUSTHORZ_CENTER; @@ -647,7 +644,7 @@ void View3D::LocationPrint(void) horiz, vert, p, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); m_font->setColor(UColor(1, 1, 1, alpha)); @@ -658,7 +655,7 @@ void View3D::LocationPrint(void) horiz, vert, p, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); m_font->setColor(UBlack); @@ -746,7 +743,7 @@ void View3D::DrawSubtitleOverlay(void) { cvar_t *subAlpha; int i; - float minX, maxY; + float minX, maxX; int line; subAlpha = Cvar_Get("subAlpha", "0.5", 0); @@ -781,8 +778,8 @@ void View3D::DrawSubtitleOverlay(void) } } - minX = m_screenframe.size.height - m_font->getHeight(false) * 10; - maxY = (m_frame.pos.x + m_frame.size.width) - (m_frame.pos.x + m_frame.size.width) * 0.2f; + minX = m_screenframe.size.height - m_font->getHeight(getHighResScale()) * 10; + maxX = ((m_frame.pos.x + m_frame.size.width) - (m_frame.pos.x + m_frame.size.width) * 0.2f) / getHighResScale()[0]; line = 0; for (i = 0; i < MAX_SUBTITLES; i++) { @@ -790,7 +787,7 @@ void View3D::DrawSubtitleOverlay(void) continue; } - if (m_font->getWidth(subs[i]->string, sizeof(oldStrings[i])) > maxY) { + if (m_font->getWidth(subs[i]->string, sizeof(oldStrings[i])) > maxX) { char buf[2048]; char *c; char *end; @@ -813,12 +810,12 @@ void View3D::DrawSubtitleOverlay(void) width = m_font->getWidth(c, blockcount); - if (total + width > maxY) { + if (total + width > maxX) { m_font->setColor(UColor(0, 0, 0, alpha[i] * subAlpha->value)); - m_font->Print(18, m_font->getHeight(false) * line + minX + 1.f, buf, -1, false); + m_font->Print(18, (m_font->getHeight(getHighResScale()) * line + minX + 1.f) / getHighResScale()[1], buf, -1, getHighResScale()); m_font->setColor(UColor(1, 1, 1, alpha[i] * subAlpha->value)); - m_font->Print(20, m_font->getHeight(false) * line + minX, buf, -1, false); + m_font->Print(20, (m_font->getHeight(getHighResScale()) * line + minX) / getHighResScale()[1], buf, -1, getHighResScale()); line++; @@ -841,17 +838,17 @@ void View3D::DrawSubtitleOverlay(void) } m_font->setColor(UColor(0, 0, 0, alpha[i] * subAlpha->value)); - m_font->Print(18, m_font->getHeight(false) * line + minX + 1.f, buf, -1, qfalse); + m_font->Print(18, (m_font->getHeight(getHighResScale()) * line + minX + 1.f) / getHighResScale()[1], buf, -1, getHighResScale()); m_font->setColor(UColor(1, 1, 1, alpha[i] * subAlpha->value)); - m_font->Print(20, m_font->getHeight(false) * line + minX, buf, -1, qfalse); + m_font->Print(20, (m_font->getHeight(getHighResScale()) * line + minX) / getHighResScale()[1], buf, -1, getHighResScale()); line++; } else { m_font->setColor(UColor(0, 0, 0, alpha[i] * subAlpha->value)); - m_font->Print(18, m_font->getHeight(false) * line + minX + 1.f, subs[i]->string, -1, qfalse); + m_font->Print(18, (m_font->getHeight(getHighResScale()) * line + minX + 1.f) / getHighResScale()[1], subs[i]->string, -1, getHighResScale()); m_font->setColor(UColor(1, 1, 1, alpha[i] * subAlpha->value)); - m_font->Print(20, m_font->getHeight(false) * line + minX, subs[i]->string, -1, qfalse); + m_font->Print(20, (m_font->getHeight(getHighResScale()) * line + minX) / getHighResScale()[1], subs[i]->string, -1, getHighResScale()); line++; } diff --git a/code/renderer/tr_font.cpp b/code/renderer/tr_font.cpp index 3f6e8d26..ecc1d1aa 100644 --- a/code/renderer/tr_font.cpp +++ b/code/renderer/tr_font.cpp @@ -525,7 +525,7 @@ void R_LoadFontShader(fontheader_sgl_t* font) } } -void R_DrawString_sgl(fontheader_sgl_t* font, const char* text, float x, float y, int maxlen, qboolean bVirtualScreen) { +void R_DrawString_sgl(fontheader_sgl_t* font, const char* text, float x, float y, int maxlen, const float *pvVirtualScreen) { float charHeight; float startx, starty; int i; @@ -534,8 +534,19 @@ void R_DrawString_sgl(fontheader_sgl_t* font, const char* text, float x, float y i = 0; startx = x; starty = y; - fWidthScale = (double)glConfig.vidWidth / 640.0; - fHeightScale = (double)glConfig.vidHeight / 480.0; + if (pvVirtualScreen) { + if (pvVirtualScreen[0]) { + fWidthScale = pvVirtualScreen[0]; + } else { + fWidthScale = (double)glConfig.vidWidth / 640.0; + } + + if (pvVirtualScreen[1]) { + fHeightScale = pvVirtualScreen[1]; + } else { + fHeightScale = (double)glConfig.vidHeight / 480.0; + } + } if (!font) { return; @@ -636,7 +647,7 @@ void R_DrawString_sgl(fontheader_sgl_t* font, const char* text, float x, float y tess.indexes[tess.numIndexes + 4] = tess.numVertexes + 3; tess.indexes[tess.numIndexes + 5] = tess.numVertexes + 2; - if (bVirtualScreen) + if (pvVirtualScreen) { // scale the string properly if virtual screen tess.xyz[tess.numVertexes][0] *= fWidthScale; @@ -659,7 +670,7 @@ void R_DrawString_sgl(fontheader_sgl_t* font, const char* text, float x, float y RB_EndSurface(); } -void R_DrawString(fontheader_t* font, const char* text, float x, float y, int maxlen, qboolean bVirtualScreen) { +void R_DrawString(fontheader_t* font, const char* text, float x, float y, int maxlen, const float *pvVirtualScreen) { int i; int code; unsigned short uch; @@ -671,7 +682,7 @@ void R_DrawString(fontheader_t* font, const char* text, float x, float y, int ma if (!font->numPages) { if (font->sgl[0]) { - R_DrawString_sgl(font->sgl[0], text, x, y, maxlen, bVirtualScreen); + R_DrawString_sgl(font->sgl[0], text, x, y, maxlen, pvVirtualScreen); } return; } @@ -704,7 +715,7 @@ void R_DrawString(fontheader_t* font, const char* text, float x, float y, int ma if (uch == '\n' || uch == '\r') { buffer[buflen] = 0; - R_DrawString_sgl(font->sgl[cursgl], buffer, curX, curY, maxlen, bVirtualScreen); + R_DrawString_sgl(font->sgl[cursgl], buffer, curX, curY, maxlen, pvVirtualScreen); curX = x; curHeight = 0.f; @@ -728,7 +739,7 @@ void R_DrawString(fontheader_t* font, const char* text, float x, float y, int ma ct = &font->charTable[code]; if (cursgl != ct->index || buflen >= ARRAY_LEN(buffer) - 2) { buffer[buflen] = 0; - R_DrawString_sgl(font->sgl[cursgl], buffer, curX, curY, maxlen, bVirtualScreen); + R_DrawString_sgl(font->sgl[cursgl], buffer, curX, curY, maxlen, pvVirtualScreen); curX += curHeight; curHeight = 0.f; @@ -744,7 +755,7 @@ void R_DrawString(fontheader_t* font, const char* text, float x, float y, int ma if (buflen) { buffer[buflen] = 0; - R_DrawString_sgl(font->sgl[cursgl], buffer, curX, y, buflen, bVirtualScreen); + R_DrawString_sgl(font->sgl[cursgl], buffer, curX, y, buflen, pvVirtualScreen); } } diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index fd014422..c7a44adf 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -2084,7 +2084,7 @@ FONT */ fontheader_t* R_LoadFont(const char* name); void R_LoadFontShader(fontheader_sgl_t* font); -void R_DrawString(fontheader_t* font, const char* text, float x, float y, int maxlen, qboolean bVirtualScreen); +void R_DrawString(fontheader_t* font, const char* text, float x, float y, int maxlen, const float *pvVirtualScreen); void R_DrawFloatingString(fontheader_t* font, const char* text, const vec3_t org, const vec4_t color, float scale, int maxlen); float R_GetFontHeight(const fontheader_t* font); float R_GetFontStringWidth(const fontheader_t* font, const char* s); diff --git a/code/renderercommon/tr_public.h b/code/renderercommon/tr_public.h index 507b2075..31d01f69 100644 --- a/code/renderercommon/tr_public.h +++ b/code/renderercommon/tr_public.h @@ -152,7 +152,7 @@ typedef struct { float (*ModelRadius)(qhandle_t handle); dtiki_t* (*R_Model_GetHandle)(qhandle_t handle); - void (*DrawString)(fontheader_t* font, const char* text, float x, float y, int maxLen, qboolean virtualScreen); + void (*DrawString)(fontheader_t* font, const char* text, float x, float y, int maxLen, const float *pvVirtualScreen); float (*GetFontHeight)(const fontheader_t* font); float (*GetFontStringWidth)(const fontheader_t* font, const char* string); fontheader_t* (*LoadFont)(const char* name); diff --git a/code/uilib/ui_public.h b/code/uilib/ui_public.h index a30b5bcb..9547e57b 100644 --- a/code/uilib/ui_public.h +++ b/code/uilib/ui_public.h @@ -80,7 +80,7 @@ typedef struct uiimport_s { void( *Rend_DrawPicStretched2 )( float x, float y, float w, float h, float s1, float t1, float s2, float t2, float sx, float sy, qhandle_t hShader ); void( *Rend_DrawPicTiled )( float x, float y, float w, float h, qhandle_t hShader ); fontheader_t *( *Rend_LoadFont )( const char *name ); - void( *Rend_DrawString )( fontheader_t *font, const char *text, float x, float y, int maxlen, qboolean bVirtualScreen ); + void( *Rend_DrawString )( fontheader_t *font, const char *text, float x, float y, int maxlen, const float *pvVirtualScreen ); void( *Rend_DrawBox )( float x, float y, float w, float h ); int( *Rend_GetShaderWidth )( qhandle_t hShader ); int( *Rend_GetShaderHeight )( qhandle_t hShader ); @@ -162,7 +162,9 @@ typedef struct uidef_s { int mouseX; int mouseY; unsigned int mouseFlags; - int uiHasMouse; + qboolean uiHasMouse; + qboolean bHighResScaling; + vec2_t scaleRes; } uidef_t; extern uidef_t uid; diff --git a/code/uilib/uibutton.cpp b/code/uilib/uibutton.cpp index 9d8877fa..eeb29f45 100644 --- a/code/uilib/uibutton.cpp +++ b/code/uilib/uibutton.cpp @@ -258,7 +258,7 @@ void UIButton::DrawPressed m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(m_title.c_str()), - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } @@ -278,7 +278,7 @@ void UIButton::DrawUnpressed m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(m_title.c_str()), - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } diff --git a/code/uilib/uiconsole.cpp b/code/uilib/uiconsole.cpp index 00aaa915..24cfb5c1 100644 --- a/code/uilib/uiconsole.cpp +++ b/code/uilib/uiconsole.cpp @@ -155,13 +155,15 @@ void UIConsole::DrawBottomLine int promptwidth; static str prompt = ">"; int top; + float topScaled; int iXPos; int iMaxStringWidth; int widthbeforecaret; promptwidth = m_font->getWidth(prompt.c_str(), -1); - top = m_frame.size.height - m_font->getHeight(qfalse); - m_font->Print(0.0, top, prompt.c_str(), -1, qfalse); + top = m_frame.size.height - m_font->getHeight(getHighResScale()); + topScaled = top / getHighResScale()[1]; + m_font->Print(0.0, topScaled, prompt.c_str(), -1, getHighResScale()); iXPos = promptwidth + 1; iMaxStringWidth = m_frame.size.width - iXPos - m_scroll->getSize().width; @@ -187,12 +189,12 @@ void UIConsole::DrawBottomLine if (widthbeforecaret < iMaxStringWidth) { - m_font->Print(iXPos, top, m_currentline.c_str(), -1, qfalse); + m_font->Print(iXPos, topScaled, m_currentline.c_str(), -1, getHighResScale()); } else { indicatorwidth = m_font->getWidth(indicator.c_str(), -1); - m_font->Print(iXPos, top, indicator.c_str(), -1, 0); + m_font->Print(iXPos, topScaled, indicator.c_str(), -1, getHighResScale()); iXPos += indicatorwidth; iMaxStringWidth -= indicatorwidth; @@ -207,7 +209,7 @@ void UIConsole::DrawBottomLine iCharLength = m_font->getCharWidth(pString[iChar - 1]); } - m_font->Print(iXPos, top, pString + 1, -1, qfalse); + m_font->Print(iXPos, topScaled, pString + 1, -1, getHighResScale()); widthbeforecaret = iXPos + m_font->getWidth(pString + 1, m_caret - iChar); } } @@ -218,19 +220,19 @@ void UIConsole::DrawBottomLine completewidth = m_font->getWidth(m_completionbuffer.c_str(), -1); linewidth = m_font->getWidth(&m_currentline[m_completionbuffer.length()], -1); - m_font->Print(iXPos, top, m_completionbuffer.c_str(), -1, qfalse); + m_font->Print(iXPos, topScaled, m_completionbuffer.c_str(), -1, getHighResScale()); iXPos += completewidth; - m_font->Print(iXPos, top, &m_currentline[m_completionbuffer.length()], -1, 0); + m_font->Print(iXPos, topScaled, &m_currentline[m_completionbuffer.length()], -1, getHighResScale()); - DrawBoxWithSolidBorder(UIRect2D(iXPos, top, linewidth, m_font->getHeight(qfalse)), UBlack, URed, 1, 2, 1.0); + DrawBoxWithSolidBorder(UIRect2D(iXPos * getHighResScale()[0], top, linewidth * getHighResScale()[0], m_font->getHeight(getHighResScale())), UBlack, URed, 1, 2, 1.0); } // // Make the caret blink // if ((uid.time % 750) > 375 && IsActive()) { - DrawBox(UIRect2D(widthbeforecaret, top, 1.0, m_font->getHeight(qfalse)), m_foreground_color, 1.0); + DrawBox(UIRect2D(widthbeforecaret * getHighResScale()[0], top, 1.0, m_font->getHeight(getHighResScale())), m_foreground_color, 1.0); } } @@ -503,7 +505,7 @@ void UIConsole::Draw int lines_drawn, at_line; int topitem; - top = (int)(m_frame.size.height - m_font->getHeight(false) * (m_scroll->getPageHeight() + 2)); + top = (int)(m_frame.size.height - m_font->getHeight(getHighResScale()) * (m_scroll->getPageHeight() + 2)); item = m_firstitem; topitem = m_scroll->getTopItem() - 1; @@ -553,10 +555,10 @@ void UIConsole::Draw } m_font->setAlpha(m_alpha); - m_font->Print(0.0, top, &theItem->string.c_str()[theItem->begins[at_line]], theItem->breaks[at_line], 0); + m_font->Print(0.0, top / getHighResScale()[1], &theItem->string.c_str()[theItem->begins[at_line]], theItem->breaks[at_line], getHighResScale()); } - top += m_font->getHeight(false); + top += m_font->getHeight(getHighResScale()); lines_drawn++; at_line++; } @@ -813,7 +815,7 @@ void UIConsole::OnSizeChanged attop = false; atbottom = false; - linesperpage = (m_frame.size.height / (float)m_font->getHeight(qfalse)); + linesperpage = (m_frame.size.height / (float)m_font->getHeight(getHighResScale())); m_scroll->InitFrameAlignRight(this, 0, 0); if (ev) @@ -906,13 +908,13 @@ void UIFloatingConsole::FrameInitialized // call the parent initialisation UIFloatingWindow::FrameInitialized(); - m_status = new UIStatusBar(alignment_t::WND_ALIGN_BOTTOM, 20.0); - m_status->InitFrame(getChildSpace(), UIRect2D(0, 0, 20.0, 20.0), 0, "verdana-12"); + m_status = new UIStatusBar(alignment_t::WND_ALIGN_BOTTOM, 20.0 * getHighResScale()[1]); + m_status->InitFrame(getChildSpace(), UIRect2D(0, 0, 20.0 * getHighResScale()[0], 20.0 * getHighResScale()[1]), 0, "verdana-12"); m_status->EnableSizeBox(this); m_status->setTitle(str()); m_console = new UIConsole(); - m_console->InitFrame(getChildSpace(), UIRect2D(0, 0, 20.0, 20.0), 0, "verdana-14"); + m_console->InitFrame(getChildSpace(), UIRect2D(0, 0, 20.0 * getHighResScale()[0], 20.0 * getHighResScale()[1]), 0, "verdana-14"); setConsoleColor(m_consoleColor); setConsoleBackground(m_consoleBackground, m_consoleAlpha); m_console->setConsoleHandler(m_handler); @@ -1423,7 +1425,7 @@ void UIFloatingDMConsole::FrameInitialized UIFloatingWindow::FrameInitialized(); m_console = new UIDMConsole(); - m_console->InitFrame(getChildSpace(), UIRect2D(0, 0, 20.0, 20.0), 0, "facfont-20"); + m_console->InitFrame(getChildSpace(), UIRect2D(0, 0, 20.0 * getHighResScale()[0], 20.0 * getHighResScale()[1]), 0, "facfont-20"); m_console->Connect(this, W_Deactivated, W_Deactivated); setConsoleColor(m_consoleColor); @@ -1456,7 +1458,6 @@ void UIFloatingDMConsole::OnChildSizeChanged } else { - m_console->setFrame(UIRect2D(UIPoint2D(0, 0), childSpaceSize)); } } diff --git a/code/uilib/uifield.cpp b/code/uilib/uifield.cpp index 952e3f7f..51a4a744 100644 --- a/code/uilib/uifield.cpp +++ b/code/uilib/uifield.cpp @@ -38,7 +38,7 @@ void UIField::Draw(void) UpdateData(); // the width of the widget that can be filled with valid text - float fVirtualWidth = m_frame.size.width / m_vVirtualScale[0] - m_font->getWidth(" ..", -1); + float fVirtualWidth = m_frame.size.width / getVirtualScale()[0] - m_font->getWidth(" ..", -1); float indentLength = m_indent; float cursorSize = m_font->getCharWidth('_'); @@ -125,7 +125,7 @@ void UIField::Draw(void) cursorPos = Q_min(cursorPos, fVirtualWidth); // Calculate text height - float y = m_frame.size.height / m_vVirtualScale[1] - m_font->getHeight(qfalse); + float y = m_frame.size.height / getVirtualScale()[1] - m_font->getHeight(); if (m_bottomindent * 2 <= y) // upper and lower margin { y -= m_bottomindent; @@ -135,27 +135,27 @@ void UIField::Draw(void) // Show text m_font->setColor(m_foreground_color); - m_font->Print(m_indent, y, temptext, -1, m_bVirtual); + m_font->Print(m_indent, y, temptext, -1, getVirtualScale()); // Display blinking cursor if field is in focus if (IsActive()) { const char *cursorChar = (uid.time / 250) & 1 ? "|" : "_"; - m_font->Print(cursorPos, y, cursorChar, -1, m_bVirtual); + m_font->Print(cursorPos, y, cursorChar, -1, getVirtualScale()); } Q_strncpyz(temptext, "..", EDITFIELD_BUFSIZE); if (m_iPreStep) { // Display leading dots if not starting from the beginning - m_font->Print(2.0f, y, temptext, -1, m_bVirtual); + m_font->Print(2.0f, y, temptext, -1, getVirtualScale()); } // Added in OPM // new iLastChar < EDITFIELD_BUFSIZE check for extra safety if (iLastChar < EDITFIELD_BUFSIZE && m_edit.m_buffer[iLastChar]) { // Display trailing dots if not ending at the end - fVirtualWidth = m_frame.size.width / m_vVirtualScale[0] - m_font->getWidth(temptext, -1) - 2.0f; - m_font->Print(fVirtualWidth, y, temptext, -1, m_bVirtual); + fVirtualWidth = m_frame.size.width / getVirtualScale()[0] - m_font->getWidth(temptext, -1) - 2.0f; + m_font->Print(fVirtualWidth, y, temptext, -1, getVirtualScale()); } } @@ -306,7 +306,7 @@ void UIField::UpdateData(void) void UIField::Pressed(Event *ev) { float xpos = ev->GetFloat(1); - float point = (xpos - m_frame.pos.x) / m_vVirtualScale[0]; + float point = (xpos - m_frame.pos.x) / getVirtualScale()[0]; point = Q_max(point, 0.0f); // added in 2.15 int iStep = m_iPreStep; diff --git a/code/uilib/uifloatwnd.cpp b/code/uilib/uifloatwnd.cpp index d4805684..21f698ac 100644 --- a/code/uilib/uifloatwnd.cpp +++ b/code/uilib/uifloatwnd.cpp @@ -115,10 +115,10 @@ void UIFloatingWindow::FrameInitialized // m_closeButton->InitFrame( this, - m_frame.size.width - 18.0, + m_frame.size.width - 18.0 * getHighResScale()[0], 2.0, - 16.0, - 16.0, + 16.0 * getHighResScale()[0], + 16.0 * getHighResScale()[1], -1, "marlett" ); @@ -131,10 +131,10 @@ void UIFloatingWindow::FrameInitialized // m_minimizeButton->InitFrame( this, - m_frame.size.width - 36.0, + m_frame.size.width - 36.0 * getHighResScale()[0], 2.0, - 16.0, - 16.0, + 16.0 * getHighResScale()[0], + 16.0 * getHighResScale()[1], -1, "marlett" ); @@ -156,7 +156,7 @@ void UIFloatingWindow::FrameInitialized { m_childspace->InitFrame( this, - UIRect2D(2.0, 20.0, m_frame.size.width - 4.0, m_frame.size.height - 22.0), + UIRect2D(2.0, 20.0 * getHighResScale()[1], m_frame.size.width - 4.0, m_frame.size.height - 22.0 * getHighResScale()[1]), 0, "verdana-12" ); @@ -198,7 +198,7 @@ void UIFloatingWindow::MinimizePressed // save the hold height // so the window can be restored later m_restoredHeight = size.height; - size.height = 20.0; + size.height = 20.0 * getHighResScale()[1]; m_minimizeButton->setTitle("1"); } else @@ -288,17 +288,17 @@ void UIFloatingWindow::SizeChanged { UIRect2D childRect; childRect.pos.x = 2.0; - childRect.pos.y = 20.0; - childRect.size.width = m_frame.size.width - 4.0; - childRect.size.height = m_frame.size.height - 22.0; + childRect.pos.y = 20.0 * getHighResScale()[1]; + childRect.size.width = m_frame.size.width - 4.0 * getHighResScale()[0]; + childRect.size.height = m_frame.size.height - 22.0 * getHighResScale()[1]; if (childRect.size.width <= 0.0 || childRect.size.height <= 0.0) { return; } m_childspace->setFrame(childRect); - m_closeButton->setFrame(UIRect2D(m_frame.size.width - 18.0, 2.0, 16.0, 16.0)); - m_minimizeButton->setFrame(UIRect2D(m_frame.size.width - 36.0, 2.0, 16.0, 16.0)); + m_closeButton->setFrame(UIRect2D(m_frame.size.width - 18.0 * getHighResScale()[0], 2.0, 16.0 * getHighResScale()[0], 16.0 * getHighResScale()[1])); + m_minimizeButton->setFrame(UIRect2D(m_frame.size.width - 36.0 * getHighResScale()[0], 2.0, 16.0 * getHighResScale()[0], 16.0 * getHighResScale()[1])); } void UIFloatingWindow::OnActivated @@ -414,11 +414,13 @@ void UIFloatingWindow::Draw ); } + const float maxTitleBarHeight = 20 * getHighResScale()[1]; + DrawBox( 0.0, 0.0, m_frame.size.width, - m_frame.size.height > 20.0 ? 20.0 : m_frame.size.height, + m_frame.size.height > maxTitleBarHeight ? maxTitleBarHeight : m_frame.size.height, titleBar, 1.0 ); @@ -427,7 +429,7 @@ void UIFloatingWindow::Draw 0.0, 0.0, m_frame.size.width, - m_frame.size.height > 20.0 ? 20.0 : m_frame.size.height, + m_frame.size.height > maxTitleBarHeight ? maxTitleBarHeight : m_frame.size.height, false, titleBorder, 1.0 diff --git a/code/uilib/uifont.cpp b/code/uilib/uifont.cpp index 9f2fc2ad..48cb298e 100644 --- a/code/uilib/uifont.cpp +++ b/code/uilib/uifont.cpp @@ -274,14 +274,14 @@ void UIFont::setFont(const char *fontname) } } -void UIFont::Print(float x, float y, const char *text, size_t maxlen, qboolean bVirtualScreen) +void UIFont::Print(float x, float y, const char *text, size_t maxlen, const float *virtualScreen) { uii.Rend_SetColor(color); - uii.Rend_DrawString(m_font, text, x, y, maxlen, bVirtualScreen); + uii.Rend_DrawString(m_font, text, x, y, maxlen, virtualScreen); } void UIFont::PrintJustified( - const UIRect2D& rect, fonthorzjustify_t horz, fontvertjustify_t vert, const char *text, float *vVirtualScale + const UIRect2D& rect, fonthorzjustify_t horz, fontvertjustify_t vert, const char *text, const float *vVirtualScale ) { float newx, newy; @@ -302,11 +302,11 @@ void UIFont::PrintJustified( if (horz == FONT_JUSTHORZ_LEFT && vert == FONT_JUSTVERT_TOP) { // no need to justify - Print(sizedRect.pos.x, sizedRect.pos.y, text, -1, vVirtualScale != NULL); + Print(sizedRect.pos.x, sizedRect.pos.y, text, -1, vVirtualScale); return; } - textheight = getHeight(text, -1, qfalse); + textheight = getHeight(text, -1); switch (vert) { case FONT_JUSTVERT_TOP: @@ -360,10 +360,10 @@ void UIFont::PrintJustified( break; } - Print(newx, newy, string, -1, vVirtualScale != NULL); + Print(newx, newy, string, -1, vVirtualScale); // expand for newline - newy += getHeight(" ", -1, qfalse); + newy += getHeight(" ", -1); } } @@ -373,7 +373,7 @@ void UIFont::PrintOutlinedJustified( fontvertjustify_t vert, const char *text, const UColor & outlineColor, - float *vVirtualScale + const float *vVirtualScale ) { float newx, newy; @@ -398,11 +398,11 @@ void UIFont::PrintOutlinedJustified( if (horz == FONT_JUSTHORZ_LEFT && vert == FONT_JUSTVERT_TOP) { // no need to justify - Print(sizedRect.pos.x, sizedRect.pos.y, text, -1, vVirtualScale != NULL); + Print(sizedRect.pos.x, sizedRect.pos.y, text, -1, vVirtualScale); return; } - textheight = getHeight(text, -1, qfalse); + textheight = getHeight(text, -1); switch (vert) { case FONT_JUSTVERT_TOP: @@ -464,26 +464,26 @@ void UIFont::PrintOutlinedJustified( // draw the outline // setColor(outlineColor); - Print(newx + 1, newy + 2, string, -1, bVirtual); - Print(newx + 2, newy + 1, string, -1, bVirtual); - Print(newx - 1, newy + 2, string, -1, bVirtual); - Print(newx - 2, newy + 1, string, -1, bVirtual); - Print(newx - 1, newy - 2, string, -1, bVirtual); - Print(newx - 2, newy - 1, string, -1, bVirtual); - Print(newx + 1, newy - 2, string, -1, bVirtual); - Print(newx + 2, newy - 1, string, -1, bVirtual); - Print(newx + 2, newy, string, -1, bVirtual); - Print(newx - 2, newy, string, -1, bVirtual); - Print(newx, newy + 2, string, -1, bVirtual); - Print(newx, newy - 2, string, -1, bVirtual); + Print(newx + 1, newy + 2, string, -1, vVirtualScale); + Print(newx + 2, newy + 1, string, -1, vVirtualScale); + Print(newx - 1, newy + 2, string, -1, vVirtualScale); + Print(newx - 2, newy + 1, string, -1, vVirtualScale); + Print(newx - 1, newy - 2, string, -1, vVirtualScale); + Print(newx - 2, newy - 1, string, -1, vVirtualScale); + Print(newx + 1, newy - 2, string, -1, vVirtualScale); + Print(newx + 2, newy - 1, string, -1, vVirtualScale); + Print(newx + 2, newy, string, -1, vVirtualScale); + Print(newx - 2, newy, string, -1, vVirtualScale); + Print(newx, newy + 2, string, -1, vVirtualScale); + Print(newx, newy - 2, string, -1, vVirtualScale); // // draw the text // setColor(originalColor); - Print(newx, newy, string, -1, bVirtual); + Print(newx, newy, string, -1, vVirtualScale); // expand for newline - newy += getHeight(" ", -1, qfalse); + newy += getHeight(" ", -1); } } @@ -532,7 +532,7 @@ int UIFont::getCharWidth(unsigned short ch) return m_font->sgl[index]->locations[indirected].size[0] * 256.0 * widthMul; } -int UIFont::getHeight(const char *text, int maxlen, qboolean bVirtual) +int UIFont::getHeight(const char *text, int maxlen, const float* virtualScale) { float height; int i; @@ -541,7 +541,7 @@ int UIFont::getHeight(const char *text, int maxlen, qboolean bVirtual) return 0; } - height = getHeight(bVirtual); + height = getHeight(virtualScale); for (i = 0; text[i]; i++) { if (maxlen != -1 && i > maxlen) { @@ -549,20 +549,20 @@ int UIFont::getHeight(const char *text, int maxlen, qboolean bVirtual) } if (text[i] == '\n') { - height += getHeight(bVirtual); + height += getHeight(virtualScale); } } return height; } -int UIFont::getHeight(qboolean bVirtual) +int UIFont::getHeight(const float* virtualScale) { - if (bVirtual) { + if (virtualScale) { if (m_font) { - return (m_font->sgl[0]->height * uid.vidHeight / 480.0); + return (m_font->sgl[0]->height * virtualScale[0]); } else { - return (16.0 * uid.vidHeight / 480.0); + return (16.0 * uid.vidHeight * virtualScale[1]); } } else { if (m_font) { diff --git a/code/uilib/uifont.h b/code/uilib/uifont.h index e22a0c0e..93a61349 100644 --- a/code/uilib/uifont.h +++ b/code/uilib/uifont.h @@ -47,12 +47,12 @@ public: UIFont(); UIFont(const char *fn); - void Print(float x, float y, const char *text, size_t maxlen = -1, qboolean bVirtualScreen = qfalse); + void Print(float x, float y, const char *text, size_t maxlen = -1, const float *virtualScreen = NULL); void PrintJustified( - const UIRect2D& rect, fonthorzjustify_t horz, fontvertjustify_t vert, const char *text, float *vVirtualScale + const UIRect2D& rect, fonthorzjustify_t horz, fontvertjustify_t vert, const char *text, const float *vVirtualScale ); void PrintOutlinedJustified( - const UIRect2D& rect, fonthorzjustify_t horz, fontvertjustify_t vert, const char* text, const UColor& outlineColor, float* vVirtualScale + const UIRect2D& rect, fonthorzjustify_t horz, fontvertjustify_t vert, const char* text, const UColor& outlineColor, const float* vVirtualScale ); void setColor(UColor col); void setAlpha(float alpha); @@ -60,8 +60,8 @@ public: int getMaxWidthIndex(const char* text, int maxlen); int getWidth(const char *text, int maxlen); int getCharWidth(unsigned short ch); - int getHeight(const char *text, int maxlen, qboolean bVirtual); - int getHeight(qboolean bVirtual); + int getHeight(const char *text, int maxlen, const float* virtualScale = NULL); + int getHeight(const float* virtualScale = NULL); int CodeSearch(unsigned short uch); bool DBCSIsLeadByte(unsigned short uch); bool DBCSIsMaekin(unsigned short uch); diff --git a/code/uilib/uilabel.cpp b/code/uilib/uilabel.cpp index cb39cba3..642dc49d 100644 --- a/code/uilib/uilabel.cpp +++ b/code/uilib/uilabel.cpp @@ -318,7 +318,7 @@ void UILabel::Draw(void) m_iFontAlignmentVertical, string, UBlack, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } else { // print the text @@ -327,7 +327,7 @@ void UILabel::Draw(void) m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, string, - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } } diff --git a/code/uilib/uilist.cpp b/code/uilib/uilist.cpp index fdc6f782..107571e1 100644 --- a/code/uilib/uilist.cpp +++ b/code/uilib/uilist.cpp @@ -92,10 +92,10 @@ void UIList::Draw } float textX = 0.5f * m_frame.size.width - 0.5f * m_font->getWidth(itemText, -1); - float textY = 0.5f * (m_frame.size.height - m_font->getHeight(m_bVirtual)) - 1.0f; + float textY = 0.5f * (m_frame.size.height - m_font->getHeight(m_bVirtual ? m_vVirtualScale : uid.scaleRes)) - 1.0f; m_font->setColor(m_foreground_color); const char *text = Sys_LV_CL_ConvertString(itemText); - m_font->Print(textX, textY, text, -1, m_bVirtual); + m_font->Print(textX, textY, text, -1, m_bVirtual ? m_vVirtualScale : NULL); } // draw the previous arrow diff --git a/code/uilib/uilistbox.cpp b/code/uilib/uilistbox.cpp index 228b04a5..ab18e695 100644 --- a/code/uilib/uilistbox.cpp +++ b/code/uilib/uilistbox.cpp @@ -303,7 +303,7 @@ void UIListBox::Draw(void) 0, aty * m_vVirtualScale[1], m_frame.size.width - m_vVirtualScale[0] * 16, - m_font->getHeight(m_bVirtual), + m_font->getHeight(getVirtualScale()), selectedBG, 1.f ); @@ -318,7 +318,7 @@ void UIListBox::Draw(void) } else { str = li->string; } - m_font->Print(m_indent, aty, str, -1, m_bVirtual); + m_font->Print(m_indent, aty, str, -1, m_bVirtual ? m_vVirtualScale : NULL); if (i == m_currentItem) { DrawBoxWithSolidBorder( @@ -326,7 +326,7 @@ void UIListBox::Draw(void) 0, aty * m_vVirtualScale[1], m_frame.size.width - m_vVirtualScale[0] * 16, - m_font->getHeight(m_bVirtual) + m_font->getHeight(getVirtualScale()) ), UWhite, selectedBorder, @@ -336,7 +336,7 @@ void UIListBox::Draw(void) ); } - aty += m_font->getHeight(false); + aty += m_font->getHeight(getHighResScale()); i++; } } @@ -349,9 +349,9 @@ void UIListBox::MousePressed(Event *ev) p.y = ev->GetFloat(2) - m_screenframe.pos.y; if (m_vertscroll) { - TrySelectItem((m_vertscroll->getTopItem() + 1) + p.y / m_font->getHeight(m_bVirtual)); + TrySelectItem((m_vertscroll->getTopItem() + 1) + p.y / m_font->getHeight(getVirtualScale())); } else { - TrySelectItem(p.y / m_font->getHeight(m_bVirtual) + 1); + TrySelectItem(p.y / m_font->getHeight(getVirtualScale()) + 1); } if (m_clickState.time + 500 > uid.time && m_currentItem == m_clickState.selected) { @@ -409,7 +409,7 @@ void UIListBox::SetListFont(Event *ev) LayoutFont(ev); if (m_vertscroll) { - m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual)); + m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(getVirtualScale())); } FrameInitialized(); @@ -483,7 +483,7 @@ void UIListBox::FrameInitialized(void) UIListBase::FrameInitialized(); if (m_vertscroll) { - m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual)); + m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(getVirtualScale())); m_vertscroll->setNumItems(m_itemlist.NumObjects()); } } diff --git a/code/uilib/uilistctrl.cpp b/code/uilib/uilistctrl.cpp index 8d56a818..fd470fce 100644 --- a/code/uilib/uilistctrl.cpp +++ b/code/uilib/uilistctrl.cpp @@ -155,14 +155,14 @@ int UIListCtrl::getHeaderHeight } if (m_headerfont) { - return (int)(m_headerfont->getHeight(m_bVirtual) + (s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1]); + return (int)(m_headerfont->getHeight(getVirtualScale()) + (s_columnpadding.height + s_columnpadding.height) * getVirtualScale()[1]); } if (m_font) { - return (int)(m_font->getHeight(m_bVirtual) + (s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1]); + return (int)(m_font->getHeight(getVirtualScale()) + (s_columnpadding.height + s_columnpadding.height) * getVirtualScale()[1]); } - return (int)((s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1]); + return (int)((s_columnpadding.height + s_columnpadding.height) * getVirtualScale()[1]); } void UIListCtrl::MousePressed @@ -215,9 +215,9 @@ void UIListCtrl::MousePressed else { if (m_vertscroll) { - TrySelectItem((m_vertscroll->getTopItem() + 1) + (p.y - getHeaderHeight()) / m_font->getHeight(m_bVirtual)); + TrySelectItem((m_vertscroll->getTopItem() + 1) + (p.y - getHeaderHeight()) / m_font->getHeight(getVirtualScale())); } else { - TrySelectItem(1.0 + (p.y - getHeaderHeight()) / m_font->getHeight(m_bVirtual)); + TrySelectItem(1.0 + (p.y - getHeaderHeight()) / m_font->getHeight(getVirtualScale())); } if (m_clickState.time + 500 > uid.time @@ -298,7 +298,7 @@ void UIListCtrl::OnSizeChanged } m_vertscroll->InitFrame(this, m_frame.size.width - 16.0, 0.0, 16.0, m_frame.size.height, -1); - m_vertscroll->setPageHeight((m_frame.size.height - getHeaderHeight()) / m_font->getHeight(m_bVirtual)); + m_vertscroll->setPageHeight((m_frame.size.height - getHeaderHeight()) / m_font->getHeight(getVirtualScale())); m_vertscroll->setNumItems(m_itemlist.NumObjects()); } @@ -321,7 +321,7 @@ void UIListCtrl::DrawColumns pFont = m_headerfont; if (!pFont) pFont = m_font; - height = (s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1] + pFont->getHeight(m_bVirtual); + height = (s_columnpadding.height + s_columnpadding.height) * getVirtualScale()[1] + pFont->getHeight(getVirtualScale()); pFont->setColor(textColor); for (i = 1; i <= m_columnlist.NumObjects(); i++) @@ -329,7 +329,7 @@ void UIListCtrl::DrawColumns const columndef_t& column = m_columnlist.ObjectAt(i); DrawBoxWithSolidBorder( - UIRect2D(atleft, 0, column.width + m_vVirtualScale[1], height), + UIRect2D(atleft, 0, column.width + getVirtualScale()[1], height), columnColor, textColor, 1, @@ -338,11 +338,11 @@ void UIListCtrl::DrawColumns ); pFont->Print( - atleft / m_vVirtualScale[0] + s_columnpadding.width, + atleft / getVirtualScale()[0] + s_columnpadding.width, s_columnpadding.height, Sys_LV_CL_ConvertString(column.title.c_str()), -1, - m_bVirtual + getVirtualScale() ); atleft += column.width; @@ -374,14 +374,14 @@ void UIListCtrl::DrawContent UColor selColor, selText; UColor backColor, textColor; - height = m_font->getHeight(m_bVirtual); + height = m_font->getHeight(getVirtualScale()); selColor = UColor(0.21f, 0.18f, 0.015f, 1.0f); selText = UColor(0.9f, 0.8f, 0.6f, 1.0f); backColor = m_background_color; textColor = m_foreground_color; if (m_headerfont) { - headerheight = m_headerfont->getHeight(m_bVirtual); + headerheight = m_headerfont->getHeight(getVirtualScale()); } else { headerheight = 0; } @@ -439,11 +439,11 @@ void UIListCtrl::DrawContent case TYPE_STRING: DrawBox(drawRect, *itemBg, m_local_alpha); pFont->Print( - drawRect.pos.x / m_vVirtualScale[0] + 1.0, - drawRect.pos.y / m_vVirtualScale[1], + drawRect.pos.x / getVirtualScale()[0] + 1.0, + drawRect.pos.y / getVirtualScale()[1], Sys_LV_CL_ConvertString(theitem->getListItemString(column.name)), -1, - m_bVirtual + getVirtualScale() ); break; case TYPE_OWNERDRAW: diff --git a/code/uilib/uimledit.cpp b/code/uilib/uimledit.cpp index cac86015..c8fbedb7 100644 --- a/code/uilib/uimledit.cpp +++ b/code/uilib/uimledit.cpp @@ -146,7 +146,7 @@ void UIMultiLineEdit::FrameInitialized(void) { delete m_vertscroll; m_vertscroll = new UIVertScroll(); - m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(false)); + m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(getHighResScale())); m_vertscroll->setTopItem(0); m_vertscroll->setNumItems(m_lines.getCount()); m_vertscroll->InitFrameAlignRight(this, 0, 0); @@ -157,7 +157,7 @@ void UIMultiLineEdit::FrameInitialized(void) void UIMultiLineEdit::SizeChanged(Event *ev) { - m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual)); + m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(getVirtualScale())); m_vertscroll->InitFrameAlignRight(this, 0, 0); } @@ -209,7 +209,7 @@ void UIMultiLineEdit::Draw(void) if (i < topsel->line || i > botsel->line) { // Print regular line without any selection or cursor present m_font->setColor(m_foreground_color); - m_font->Print(0, aty, cur, -1, m_bVirtual); + m_font->Print(0, aty / getVirtualScale()[1], cur, -1, getVirtualScale()); } else { // Current line contains cursor and/or selected text float linewidth = m_font->getWidth(cur, -1); @@ -217,13 +217,13 @@ void UIMultiLineEdit::Draw(void) if (i > topsel->line && i < botsel->line) { // all text in current line is selected, it's part of a larger selection, // print entire line with the selection highlight box around it - DrawBox(0.0f, aty, linewidth, m_font->getHeight(m_bVirtual), selectionBG, 1.f); + DrawBox(0.0f, aty, linewidth * getVirtualScale()[0], m_font->getHeight(getVirtualScale()), selectionBG, 1.f); m_font->setColor(selectionColor); // Fixed in OPM: // don't spam LOCALIZATION ERROR messages to console // for clicking lines in the opened text document //m_font->Print(0, aty, Sys_LV_CL_ConvertString(cur), -1, m_bVirtual); - m_font->Print(0, aty, cur, -1, m_bVirtual); + m_font->Print(0, aty / getVirtualScale()[1], cur, -1, getVirtualScale()); } else if (i != topsel->line) { // part of this line is selected, and selection continues/began above if (i == botsel->line) { // sanity check, should always be true @@ -232,13 +232,13 @@ void UIMultiLineEdit::Draw(void) // selection contains text from the beginning of the line, // print it with the selection highlight box around it m_font->setColor(selectionColor); - DrawBox(0, aty, toplen, m_font->getHeight(m_bVirtual), selectionBG, 1.f); - m_font->Print(0, aty, cur, botsel->column, m_bVirtual); + DrawBox(0, aty, toplen * getVirtualScale()[0], m_font->getHeight(getVirtualScale()), selectionBG, 1.f); + m_font->Print(0, aty / getVirtualScale()[1], cur, botsel->column, getVirtualScale()); } if (toplen < linewidth) { // is there still text on this line after the selection? m_font->setColor(m_foreground_color); - m_font->Print(toplen, aty, &cur[botsel->column], -1, m_bVirtual); + m_font->Print(toplen, aty / getVirtualScale()[1], &cur[botsel->column], -1, getVirtualScale()); } if (botsel == &m_selection.end) { @@ -251,14 +251,14 @@ void UIMultiLineEdit::Draw(void) int toplen = m_font->getWidth(cur, topsel->column); // X coord of highlighting start if (topsel->column) { // is there any text on this line before the selection? m_font->setColor(m_foreground_color); - m_font->Print(0, aty, cur, topsel->column, m_bVirtual); + m_font->Print(0, aty / getVirtualScale()[1], cur, topsel->column, getVirtualScale()); } if (toplen < linewidth) { // is there any selected text before the end of the line? // print the selected text with the selection highlight box around it m_font->setColor(selectionColor); - DrawBox(toplen, aty, linewidth - toplen, m_font->getHeight(m_bVirtual), selectionBG, 1.f); - m_font->Print(toplen, aty, &cur[topsel->column], -1, m_bVirtual); + DrawBox(toplen * getVirtualScale()[0], aty, (linewidth - toplen) * getVirtualScale()[0], m_font->getHeight(getVirtualScale()), selectionBG, 1.f); + m_font->Print(toplen, aty / getVirtualScale()[1], &cur[topsel->column], -1, getVirtualScale()); } if (topsel == &m_selection.end) { @@ -275,7 +275,7 @@ void UIMultiLineEdit::Draw(void) // don't spam LOCALIZATION ERROR messages to console // for clicking lines in the opened text document //m_font->Print(0, aty, Sys_LV_CL_ConvertString(cur), -1, m_bVirtual); - m_font->Print(0, aty, cur, -1, m_bVirtual); + m_font->Print(0, aty / getVirtualScale()[1], cur, -1, getVirtualScale()); } else { // selection starts and ends on this line int toplen = m_font->getWidth(cur, topsel->column); // X coord of highlighting start @@ -283,14 +283,14 @@ void UIMultiLineEdit::Draw(void) if (toplen) { // is there any text on this line before the selection? m_font->setColor(m_foreground_color); - m_font->Print(0, aty, cur, topsel->column, m_bVirtual); + m_font->Print(0, aty / getVirtualScale()[1], cur, topsel->column, getVirtualScale()); } if (botlen != toplen) { // is the selection wider than 0 pixels? (sanity check, always true) // print the selected text with the selection highlight box around it - DrawBox(toplen, aty, botlen - toplen, m_font->getHeight(m_bVirtual), selectionBG, 1.f); + DrawBox(toplen * getVirtualScale()[0], aty, (botlen - toplen) * getVirtualScale()[0], m_font->getHeight(getVirtualScale()), selectionBG, 1.f); m_font->setColor(selectionColor); - m_font->Print(toplen, aty, &cur[topsel->column], botsel->column - topsel->column, m_bVirtual); + m_font->Print(toplen, aty / getVirtualScale()[1], &cur[topsel->column], botsel->column - topsel->column, getVirtualScale()); } if (cur.length() != botsel->column) { // is there still text on this line after the selection? @@ -302,7 +302,7 @@ void UIMultiLineEdit::Draw(void) // Cause: the last two arguments were incorrectly passed in originally, // always specifying maxlen as m_bVirtual (which is usually zero). // m_font->Print(botlen, aty, &cur[botsel->column], m_bVirtual, false); - m_font->Print(botlen, aty, &cur[botsel->column], -1, m_bVirtual); + m_font->Print(botlen, aty / getVirtualScale()[1], &cur[botsel->column], -1, getVirtualScale()); } // Place the cursor at the end of the selection... @@ -320,10 +320,10 @@ void UIMultiLineEdit::Draw(void) if (m_selection.end.line == i && (uid.time % 750) >= 375 && IsActive()) { // draw cursor caret - DrawBox(caret, aty, 2.f, m_font->getHeight(m_bVirtual), UBlack, 1.f); + DrawBox(caret * getVirtualScale()[0], aty, 2.f, m_font->getHeight(getVirtualScale()), UBlack, 1.f); } - aty += m_font->getHeight(m_bVirtual); + aty += m_font->getHeight(getVirtualScale()); } } @@ -363,7 +363,7 @@ void UIMultiLineEdit::PointToSelectionPoint(const UIPoint2D& p, selectionpoint_t float totalWidth = 0; float lastWidth = 0; - clickedLine = m_vertscroll->getTopItem() + p.y / m_font->getHeight(m_bVirtual); + clickedLine = m_vertscroll->getTopItem() + p.y / m_font->getHeight(getVirtualScale()); clickedLine = Q_min(clickedLine, m_lines.getCount() - 1); if (clickedLine < 0) { @@ -374,7 +374,7 @@ void UIMultiLineEdit::PointToSelectionPoint(const UIPoint2D& p, selectionpoint_t const char *line = LineFromLineNumber(clickedLine, true).c_str(); for (i = 0; line[i] && totalWidth < p.x; i++) { - lastWidth = m_font->getCharWidth(line[i]); + lastWidth = m_font->getCharWidth(line[i]) * getVirtualScale()[0]; totalWidth += lastWidth; } diff --git a/code/uilib/uipopupmenu.cpp b/code/uilib/uipopupmenu.cpp index afcefc63..b119100b 100644 --- a/code/uilib/uipopupmenu.cpp +++ b/code/uilib/uipopupmenu.cpp @@ -100,7 +100,7 @@ uipopup_describe *UIPopupMenu::getDescribeFromPoint return NULL; } - float top = m_vVirtualScale[1] * 4.0f; + float top = getVirtualScale()[1] * 4.0f; for (int i = 1; i <= m_describe->NumObjects(); i++) { uipopup_describe* desc = m_describe->ObjectAt(i); @@ -163,10 +163,10 @@ float UIPopupMenu::getDescribeHeight { if (d->type == UIP_SEPARATOR) { - return 8.0f; + return 8.0f * getVirtualScale()[0]; } - return m_font->getHeight(m_bVirtual); + return m_font->getHeight(getVirtualScale()); } float UIPopupMenu::getDescribeWidth @@ -175,7 +175,7 @@ float UIPopupMenu::getDescribeWidth ) { - return m_font->getWidth(d->title, -1); + return m_font->getWidth(d->title, -1) * getVirtualScale()[0]; } bool UIPopupMenu::MouseInSubmenus @@ -251,7 +251,7 @@ void UIPopupMenu::Create } } - totalSize.height /= m_vVirtualScale[1]; + totalSize.height /= getVirtualScale()[1]; if (width != -1.0f) { @@ -266,11 +266,11 @@ void UIPopupMenu::Create totalSize.width += 24.0f; totalSize.height += 8.0f; - if (m_bVirtual) - { - totalSize.width *= m_vVirtualScale[0]; - totalSize.height *= m_vVirtualScale[1]; - } + //if (m_bVirtual) + //{ + totalSize.width *= getVirtualScale()[0]; + totalSize.height *= getVirtualScale()[1]; + //} UIPoint2D place; place.x = (where) ? createRect.pos.x : createRect.size.width + createRect.pos.x; @@ -326,10 +326,10 @@ void UIPopupMenu::Draw ) { - const float originX = m_vVirtualScale[0] * 4.0f; - const float originY = m_vVirtualScale[1] * 4.0f; + const float originX = getVirtualScale()[0] * 4.0f; + const float originY = getVirtualScale()[1] * 4.0f; - float fFontHeight = m_font->getHeight(m_bVirtual); + float fFontHeight = m_font->getHeight(getVirtualScale()); float top = originY; for (int i = 1; i <= m_describe->NumObjects(); i++) { @@ -369,7 +369,7 @@ void UIPopupMenu::Draw m_font->setColor(textColor); m_marlett.setColor(textColor); const char *text = Sys_LV_CL_ConvertString(desc->title); - m_font->Print(4.0f, top / m_vVirtualScale[1], text, -1, m_bVirtual); + m_font->Print(4.0f, top / getVirtualScale()[1], text, -1, getVirtualScale()); if (desc->type == UIP_SUBMENU) { @@ -378,7 +378,7 @@ void UIPopupMenu::Draw m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, "4", - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } } diff --git a/code/uilib/uipulldownmenu.cpp b/code/uilib/uipulldownmenu.cpp index 780ad481..e062e4bc 100644 --- a/code/uilib/uipulldownmenu.cpp +++ b/code/uilib/uipulldownmenu.cpp @@ -115,7 +115,7 @@ UIRect2D UIPulldownMenu::getAlignmentRect m_vVirtualScale[1] = (float)uid.vidHeight / SCREEN_HEIGHT; } - int maxheight = m_font->getHeight(m_bVirtual); + int maxheight = m_font->getHeight(m_bVirtual ? m_vVirtualScale : NULL); for (int i = 1; i <= m_desc.NumObjects(); i++) { uipull_describe *uipd = m_desc.ObjectAt(i); @@ -164,7 +164,7 @@ float UIPulldownMenu::getDescHeight return uii.Rend_GetShaderHeight(mat->GetMaterial()); } - return m_font->getHeight(m_bVirtual); + return m_font->getHeight(m_bVirtual ? m_vVirtualScale : NULL); } uipull_describe *UIPulldownMenu::getPulldown @@ -590,7 +590,7 @@ void UIPulldownMenu::Draw const char *text = Sys_LV_CL_ConvertString(desc->title); float text_xpos = m_vVirtualScale[0] * 4.0f + atx; float text_ypos = m_vVirtualScale[1] * 2.0f; - m_font->Print(text_xpos, text_ypos, text, -1, m_bVirtual); + m_font->Print(text_xpos, text_ypos, text, -1, m_bVirtual ? m_vVirtualScale : NULL); } atx += width; diff --git a/code/uilib/uistatus.cpp b/code/uilib/uistatus.cpp index 19d6d2a5..ff05d122 100644 --- a/code/uilib/uistatus.cpp +++ b/code/uilib/uistatus.cpp @@ -51,10 +51,10 @@ void UIWindowSizer::Draw { m_font->setColor(UWhite); - m_font->Print(0, 0, "o", -1, m_bVirtual); + m_font->Print(0, 0, "o", -1, getVirtualScale()); m_font->setColor(UBlack); - m_font->Print(0, 0, "p", -1, m_bVirtual); + m_font->Print(0, 0, "p", -1, getVirtualScale()); } void UIWindowSizer::FrameInitialized @@ -202,7 +202,7 @@ void UIStatusBar::Draw m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(m_title.c_str()), - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); if (m_sizer) @@ -267,16 +267,13 @@ void UIStatusBar::SelfSized { if (m_sizeenabled) { - if (m_sizer) { - if (m_sizer->getDraggingWidget() != m_sizeenabled) { - m_sizer->setDraggingWidget(m_sizeenabled); - } - } - else { - m_sizer = new UIWindowSizer(m_sizeenabled); - m_sizer->InitFrame(this, 0, 0, 16.0, 16.0, 0); - } - + if (!m_sizer) { + m_sizer = new UIWindowSizer(m_sizeenabled); + m_sizer->InitFrame(this, 0, 0, 16.0 * getHighResScale()[0], 16.0 * getHighResScale()[1], 0); + + } else if (m_sizer->getDraggingWidget() != m_sizeenabled) { + m_sizer->setDraggingWidget(m_sizeenabled); + } UISize2D sizerFrame = m_sizer->getSize(); diff --git a/code/uilib/uivertscroll.cpp b/code/uilib/uivertscroll.cpp index 28cc252d..0c196b7b 100644 --- a/code/uilib/uivertscroll.cpp +++ b/code/uilib/uivertscroll.cpp @@ -74,7 +74,7 @@ int UIVertScroll::getItemFromHeight ) { - return (int)((height - 16.0) * (float)this->m_numitems / (m_frame.size.height - 32.0)); + return (int)((height - 16.0 * uid.scaleRes[1]) * (float)this->m_numitems / (m_frame.size.height - 32.0 * uid.scaleRes[1])); } bool UIVertScroll::isEnoughItems @@ -102,7 +102,7 @@ void UIVertScroll::Draw ); DrawArrow(0.0, "5", m_pressed == VS_UP_ARROW); - DrawArrow(m_frame.size.height - m_vVirtualScale[1] * 16.0, "6", m_pressed == VS_DOWN_ARROW); + DrawArrow(m_frame.size.height - getVirtualScale()[1] * 16.0, "6", m_pressed == VS_DOWN_ARROW); if (m_numitems > m_pageheight) { DrawThumb(); @@ -123,7 +123,7 @@ void UIVertScroll::DrawArrow arrowRect.pos.x = 0.0; arrowRect.pos.y = top; arrowRect.size.width = m_frame.size.width; - arrowRect.size.height = m_vVirtualScale[1] * 16.0; + arrowRect.size.height = getVirtualScale()[1] * 16.0; innerColor = getBackgroundColor(); m_marlett.setColor(getForegroundColor()); @@ -150,7 +150,7 @@ void UIVertScroll::DrawArrow m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString(text), - m_bVirtual ? m_vVirtualScale : NULL + getVirtualScale() ); } @@ -164,10 +164,10 @@ void UIVertScroll::DrawThumb float thumbHeight, thumbdiff; UColor thumbInside; - thumbdiff = m_frame.size.height - m_vVirtualScale[1] * 32.0; + thumbdiff = m_frame.size.height - getVirtualScale()[1] * 32.0; inbarrect.pos.x = 0.0; - inbarrect.pos.y = m_vVirtualScale[1] * 16.0; + inbarrect.pos.y = getVirtualScale()[1] * 16.0; inbarrect.size.width = m_frame.size.width; inbarrect.size.height = m_frame.size.height - thumbdiff; @@ -500,10 +500,10 @@ void UIVertScroll::InitFrameAlignRight UIRect2D frame, frameOut; frame = parent->getClientFrame(); - frameOut.pos.x = frame.pos.x + frame.size.width - (fWidthPadding + 16.0) * m_vVirtualScale[0]; - frameOut.pos.y = fHeightPadding * m_vVirtualScale[1]; - frameOut.size.width = m_vVirtualScale[0] * 16.0; - frameOut.size.height = frame.size.height - (fHeightPadding * 2) * m_vVirtualScale[1]; + frameOut.pos.x = frame.pos.x + frame.size.width - (fWidthPadding + 16.0) * getVirtualScale()[0]; + frameOut.pos.y = fHeightPadding * getVirtualScale()[1]; + frameOut.size.width = getVirtualScale()[0] * 16.0; + frameOut.size.height = frame.size.height - (fHeightPadding * 2) * getVirtualScale()[1]; if (!m_frameinitted) { @@ -514,3 +514,8 @@ void UIVertScroll::InitFrameAlignRight setFrame(frameOut); } } + +void UIVertScroll::FrameInitialized() +{ + UIWidget::FrameInitialized(); +} diff --git a/code/uilib/uivertscroll.h b/code/uilib/uivertscroll.h index f1f3232a..dd245167 100644 --- a/code/uilib/uivertscroll.h +++ b/code/uilib/uivertscroll.h @@ -70,5 +70,6 @@ public: void setThumbColor( const UColor& thumb ); void setSolidBorderColor( const UColor& col ); void InitFrameAlignRight( UIWidget *parent, float fWidthPadding, float fHeightPadding ); + void FrameInitialized() override; }; diff --git a/code/uilib/uiwidget.cpp b/code/uilib/uiwidget.cpp index 77ba2361..0082c4c9 100644 --- a/code/uilib/uiwidget.cpp +++ b/code/uilib/uiwidget.cpp @@ -607,6 +607,23 @@ void DrawBoxWithSolidBorder( const UIRect2D& rect, const UColor& inside, const U } } +static bool scaleFrameVirtualRes(UIRect2D& frame, vec3_t outScale, const vec3_t newScale) +{ + if (!VectorCompare2D(outScale, newScale)) + { + frame.pos.x = frame.pos.x / outScale[0] * newScale[0]; + frame.pos.y = frame.pos.y / outScale[1] * newScale[1]; + frame.size.width = frame.size.width / outScale[0] * newScale[0]; + frame.size.height = frame.size.height / outScale[1] * newScale[1]; + outScale[0] = newScale[0]; + outScale[1] = newScale[1]; + + return true; + } + + return false; +} + UIReggedMaterial::UIReggedMaterial() { hMat = 0; @@ -924,7 +941,7 @@ void UIWidget::DrawTitle { m_font->setColor( m_foreground_color ); - m_font->Print( x, y, Sys_LV_CL_ConvertString( m_title ), -1, m_bVirtual ); + m_font->Print( x, y, Sys_LV_CL_ConvertString( m_title ), -1, getVirtualScale() ); } void UIWidget::Motion @@ -1108,16 +1125,17 @@ void UIWidget::AlignPosition SetVirtualScale(vNewVirtualScale); - if (!VectorCompare2D(m_vVirtualScale, vNewVirtualScale)) - { - m_frame.pos.x = m_frame.pos.x / m_vVirtualScale[0] * vNewVirtualScale[0]; - m_frame.pos.y = m_frame.pos.y / m_vVirtualScale[1] * vNewVirtualScale[1]; - m_frame.size.width = m_frame.size.width / m_vVirtualScale[0] * vNewVirtualScale[0]; - m_frame.size.height = m_frame.size.height / m_vVirtualScale[1] * vNewVirtualScale[1]; - m_vVirtualScale[0] = vNewVirtualScale[0]; - m_vVirtualScale[1] = vNewVirtualScale[1]; - } + scaleFrameVirtualRes(m_frame, m_vVirtualScale, vNewVirtualScale); } + else if (uid.bHighResScaling) + { + scaleFrameVirtualRes(m_frame, m_vVirtualScale, uid.scaleRes); + } + else + { + vec2_t vNewVirtualScale = { 1.0, 1.0 }; + scaleFrameVirtualRes(m_frame, m_vVirtualScale, vNewVirtualScale); + } if (m_flags & WF_STRETCH_VERTICAL) { @@ -1330,7 +1348,7 @@ void UIWidget::InitFrame setParent( parentview ); } else if( this != &uWinMan ) - { + { setParent( &uWinMan ); } @@ -2473,7 +2491,7 @@ void UIWidget::Display if( m_flags & WF_TILESHADER ) { - if (m_bVirtual) { + if (m_bVirtual) { float fvWidth = m_frame.size.width / m_vVirtualScale[0] / uii.Rend_GetShaderWidth(m_material->GetMaterial()); float fvHeight = m_frame.size.height / m_vVirtualScale[1] / uii.Rend_GetShaderHeight(m_material->GetMaterial()); @@ -2555,7 +2573,7 @@ float UIWidget::getTitleHeight ) { - return m_font->getHeight( m_bVirtual ); + return m_font->getHeight(getVirtualScale()); } bool UIWidget::CanActivate @@ -2741,22 +2759,27 @@ void UIWidget::Realign ) { + bool bScaled = false; + if (m_bVirtual) { vec2_t vNewVirtualScale; - SetVirtualScale(vNewVirtualScale); + SetVirtualScale(vNewVirtualScale); - if (!VectorCompare2D(m_vVirtualScale, vNewVirtualScale)) - { - m_frame.pos.x = m_frame.pos.x / m_vVirtualScale[0] * vNewVirtualScale[0]; - m_frame.pos.y = m_frame.pos.y / m_vVirtualScale[1] * vNewVirtualScale[1]; - m_frame.size.width = m_frame.size.width / m_vVirtualScale[0] * vNewVirtualScale[0]; - m_frame.size.height = m_frame.size.height / m_vVirtualScale[1] * vNewVirtualScale[1]; - m_vVirtualScale[0] = vNewVirtualScale[0]; - m_vVirtualScale[1] = vNewVirtualScale[1]; - } + scaleFrameVirtualRes(m_frame, m_vVirtualScale, vNewVirtualScale); + bScaled = true; } + else if (uid.bHighResScaling) + { + scaleFrameVirtualRes(m_frame, m_vVirtualScale, uid.scaleRes); + bScaled = true; + } + else + { + vec2_t vNewVirtualScale = { 1.0, 1.0 }; + bScaled = scaleFrameVirtualRes(m_frame, m_vVirtualScale, vNewVirtualScale); + } if (m_flags & WF_STRETCH_VERTICAL) { @@ -2797,7 +2820,7 @@ void UIWidget::Realign m_frame.pos.y = 0; } - if ((m_align & WA_FULL) || (m_flags & (WF_STRETCH_HORIZONTAL | WF_STRETCH_VERTICAL)) || (m_bVirtual)) + if ((m_align & WA_FULL) || (m_flags & (WF_STRETCH_HORIZONTAL | WF_STRETCH_VERTICAL)) || bScaled) { setFrame(m_frame); m_startingpos = m_frame.pos; @@ -3119,7 +3142,16 @@ bool UIWidget::isVirtual() const const vec2_t& UIWidget::getVirtualScale() const { - return m_vVirtualScale; + if (m_bVirtual) { + return m_vVirtualScale; + } else { + return uid.scaleRes; + } +} + +const vec2_t& UIWidget::getHighResScale() const +{ + return uid.scaleRes; } void UIWidget::SetEnabledCvar @@ -3208,16 +3240,17 @@ void UIWidgetContainer::AlignPosition SetVirtualScale(vNewVirtualScale); - if (!VectorCompare2D(m_vVirtualScale, vNewVirtualScale)) - { - m_frame.pos.x = m_frame.pos.x / m_vVirtualScale[0] * vNewVirtualScale[0]; - m_frame.pos.y = m_frame.pos.y / m_vVirtualScale[1] * vNewVirtualScale[1]; - m_frame.size.width = m_frame.size.width / m_vVirtualScale[0] * vNewVirtualScale[0]; - m_frame.size.height = m_frame.size.height / m_vVirtualScale[1] * vNewVirtualScale[1]; - m_vVirtualScale[0] = vNewVirtualScale[0]; - m_vVirtualScale[1] = vNewVirtualScale[1]; - } + scaleFrameVirtualRes(m_frame, m_vVirtualScale, vNewVirtualScale); } + else if (uid.bHighResScaling) + { + scaleFrameVirtualRes(m_frame, m_vVirtualScale, uid.scaleRes); + } + else + { + vec2_t vNewVirtualScale = { 1.0, 1.0 }; + scaleFrameVirtualRes(m_frame, m_vVirtualScale, vNewVirtualScale); + } if (m_align & WA_LEFT) { diff --git a/code/uilib/uiwidget.h b/code/uilib/uiwidget.h index 602f8838..53dff224 100644 --- a/code/uilib/uiwidget.h +++ b/code/uilib/uiwidget.h @@ -333,6 +333,7 @@ public: // Added in OPM bool isVirtual() const; const vec2_t& getVirtualScale() const; + const vec2_t& getHighResScale() const; }; class UIWidgetContainer : public UIWidget { diff --git a/code/uilib/uiwinman.cpp b/code/uilib/uiwinman.cpp index 41c528ef..90631334 100644 --- a/code/uilib/uiwinman.cpp +++ b/code/uilib/uiwinman.cpp @@ -269,7 +269,7 @@ void UIWindowManager::UpdateViews(void) if (UI_GetCvarInt("ui_drawcoords", 0)) { x = uid.mouseX + 10; y = uid.mouseY - 10; - m_font->Print(x, y, va("%d:%d", uid.mouseX, uid.mouseY), -1, m_bVirtual); + m_font->Print(x, y, va("%d:%d", uid.mouseX, uid.mouseY), -1, m_bVirtual ? m_vVirtualScale : NULL); } } } diff --git a/docs/features.md b/docs/features.md index 5c1b3a5d..483b31ff 100644 --- a/docs/features.md +++ b/docs/features.md @@ -10,6 +10,7 @@ A lot of bugs and exploits from MOH:AA were fixed in OpenMoHAA (BOF exploit, gre - Cross-platform support - Multiuser support on OS (On Windows, user game data is stored in "%APPDATA%\openmohaa") - Many bug fixes and additions from ioquake3 +- Automatic scaling of UI elements on high resolutions like 4K Overall, better compatibility on modern systems and bugfixes.