From 3c08e99162d74149335df16de4beacd36f91957c Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Tue, 30 Jun 2009 02:34:25 +0000 Subject: [PATCH] Wide screen support. --- reaction/cgame/cg_draw.c | 87 +++++++++++++++++------------------ reaction/cgame/cg_drawtools.c | 8 +--- reaction/cgame/cg_local.h | 4 ++ reaction/cgame/cg_main.c | 9 +++- reaction/cgame/cg_view.c | 2 +- 5 files changed, 56 insertions(+), 54 deletions(-) diff --git a/reaction/cgame/cg_draw.c b/reaction/cgame/cg_draw.c index 368cfb0c..947151c5 100644 --- a/reaction/cgame/cg_draw.c +++ b/reaction/cgame/cg_draw.c @@ -494,7 +494,7 @@ static void CG_DrawStatusBar(void) qhandle_t hicon; qhandle_t icon; //Makro - added x and y for weapon drawing - int i, x = 640 - SMICON_SIZE, y = 400; + int i, x = cgs.screenXMax - SMICON_SIZE - 8, y = 400; //Makro - old values /* @@ -573,10 +573,10 @@ static void CG_DrawStatusBar(void) } } */ - CG_DrawPic(8, 440, SMICON_SIZE, SMICON_SIZE, hicon); + CG_DrawPic(cgs.screenXMin + 8, 440, SMICON_SIZE, SMICON_SIZE, hicon); //CG_DrawStringExt(44, 444, va("%d", value), hcolor, qtrue, qtrue, 24, 24, 3); //UI_DrawProportionalString(44, 444, va("%d", value), style, hcolor); - UI_DrawProportionalString(40, 444, va("%d", value), style, hcolor); + UI_DrawProportionalString(cgs.screenXMin + 40, 444, va("%d", value), style, hcolor); //Elder: Draw weapon ammo and clips style = UI_LEFT | UI_DROPSHADOW; @@ -596,7 +596,7 @@ static void CG_DrawStatusBar(void) //if (icon && cg.predictedPlayerState.weapon != WP_KNIFE && cg.predictedPlayerState.weapon != WP_GRENADE) if (icon) //CG_DrawPic(252, 440, SMICON_SIZE, SMICON_SIZE, icon); - CG_DrawPic(288, 440, SMICON_SIZE, SMICON_SIZE, icon); + CG_DrawPic(cgs.screenXMin + 288, 440, SMICON_SIZE, SMICON_SIZE, icon); if (cent->currentState.weapon) { value = ps->ammo[cent->currentState.weapon]; @@ -637,7 +637,7 @@ static void CG_DrawStatusBar(void) } if (value >= 0) - UI_DrawProportionalString(200, 444, va("%d", value), style, hcolor); + UI_DrawProportionalString(cgs.screenXMin + 200, 444, va("%d", value), style, hcolor); #endif //UI_DrawProportionalString(188, 444, "/"), style, colors[0]); @@ -646,7 +646,7 @@ static void CG_DrawStatusBar(void) if (value > -1 && cg.predictedPlayerState.weapon != WP_KNIFE && cg.predictedPlayerState.weapon != WP_GRENADE) //Makro - pretty colours ! - UI_DrawProportionalString(320, 444, va("%d", value), style, (value != 0) ? colors[0] : colors[3]); + UI_DrawProportionalString(cgs.screenXMin + 320, 444, va("%d", value), style, (value != 0) ? colors[0] : colors[3]); } // Elder: temporary //if (cg.snap->ps.stats[STAT_RELOADTIME] > 0) @@ -828,9 +828,9 @@ static float CG_DrawScore(float y) w = CG_DrawStrlen(s) * SMALLCHAR_WIDTH; x = w; - CG_FillRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, BColor); - CG_DrawCleanRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, FColor); - CG_DrawSmallString(631 - x, y + 2, s, 1.0f); + CG_FillRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, BColor); + CG_DrawCleanRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, FColor); + CG_DrawSmallString(cgs.screenXMax - x - 9, y + 2, s, 1.0f); // Your team: if (team == TEAM_RED) { @@ -846,9 +846,9 @@ static float CG_DrawScore(float y) w = CG_DrawStrlen(s) * SMALLCHAR_WIDTH; x += w + 9; - CG_FillRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, BColor); - CG_DrawCleanRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, FColor); - CG_DrawSmallString(631 - x, y + 2, s, 1.0f); + CG_FillRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, BColor); + CG_DrawCleanRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, FColor); + CG_DrawSmallString(cgs.screenXMax - x - 9, y + 2, s, 1.0f); } s = va("%i", cg.snap->ps.persistant[PERS_SCORE]); @@ -865,10 +865,10 @@ static float CG_DrawScore(float y) //MAKERGBA(BColor, 1.0f, 1.0f, 1.0f, 1.0f); //CG_FillRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, BColor); - CG_DrawCleanRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, FColor); + CG_DrawCleanRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, FColor); MAKERGBA(FColor, 0.75f, 0.75f, 0.75f, 1.0f); - CG_DrawStringExt(631 - x, y + 2, s, FColor, qfalse, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0); + CG_DrawStringExt(cgs.screenXMax - x - 9, y + 2, s, FColor, qfalse, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0); //CG_DrawSmallString(631 - x, y + 2, s, 1.0F); @@ -936,12 +936,12 @@ static float CG_DrawFPSandPing(float y) x = w; MAKERGBA(Color, 0.0f, 0.0f, 0.0f, 0.4f); - CG_FillRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, Color); + CG_FillRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, Color); MAKERGBA(Color, 0.0f, 0.0f, 0.0f, 1.0f); - CG_DrawCleanRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, Color); + CG_DrawCleanRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, Color); - CG_DrawSmallString(631 - x, y + 2, s, 1.0F); + CG_DrawSmallString(cgs.screenXMax - x - 9, y + 2, s, 1.0F); x += 9; } @@ -973,10 +973,10 @@ static float CG_DrawFPSandPing(float y) if (l < 0) l += LAG_SAMPLES; MAKERGBA(Color, 0.0f, 0.0f, 0.0f, 0.4f); - CG_FillRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, Color); + CG_FillRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, Color); MAKERGBA(Color, 0.0f, 0.0f, 0.0f, 1.0f); - CG_DrawCleanRect(631 - x - 3, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, Color); + CG_DrawCleanRect(cgs.screenXMax - x - 12, y - 1, w + 6, SMALLCHAR_HEIGHT + 6, 1, Color); MAKERGBA(Color, 0.0f, 1.0f, 0.0f, 1.0f); // Green, All good @@ -987,7 +987,7 @@ static float CG_DrawFPSandPing(float y) if (lagometer.snapshotFlags[l] & SNAPFLAG_RATE_DELAYED) // Yellow. Delayed packet MAKERGBA(Color, 1.0f, 1.0f, 0.0f, 1.0f); - CG_DrawStringExt(631 - x, y + 2, s, Color, qfalse, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0); + CG_DrawStringExt(cgs.screenXMax - x - 9, y + 2, s, Color, qfalse, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0); } if (!cg_drawFPS.integer && (!cg_drawPing.integer || cg.demoPlayback)) @@ -1375,8 +1375,8 @@ static int CG_DrawPickupItem(int y) if (fadeColor) { CG_RegisterItemVisuals(value); trap_R_SetColor(fadeColor); - CG_DrawPic(8, y, ICON_SIZE, ICON_SIZE, cg_items[value].icon); - CG_DrawBigString(ICON_SIZE + 16, y + (ICON_SIZE / 2 - BIGCHAR_HEIGHT / 2), + CG_DrawPic(cgs.screenXMin + 8, y, ICON_SIZE, ICON_SIZE, cg_items[value].icon); + CG_DrawBigString(cgs.screenXMin + ICON_SIZE + 16, y + (ICON_SIZE / 2 - BIGCHAR_HEIGHT / 2), bg_itemlist[value].pickup_name, fadeColor[0]); trap_R_SetColor(NULL); } @@ -1502,7 +1502,7 @@ static void CG_DrawHoldableItem(void) if (item) { value = BG_FindItemForHoldable(item) - bg_itemlist; CG_RegisterItemVisuals(value); - CG_DrawPic(640 - SMICON_SIZE, 440, SMICON_SIZE, SMICON_SIZE, cg_items[value].icon); + CG_DrawPic(cgs.screenXMax - SMICON_SIZE - 8, 440, SMICON_SIZE, SMICON_SIZE, cg_items[value].icon); } } @@ -1662,7 +1662,7 @@ static void CG_DrawDisconnect(void) //x = 640 - 48; //y = 480 - 48; - CG_DrawPic(x, y, 48, 48, trap_R_RegisterShader("gfx/2d/net.tga")); + CG_DrawPic(cgs.screenXMin + x, y, 48, 48, trap_R_RegisterShader("gfx/2d/net.tga")); } #define MAX_LAGOMETER_PING 900 @@ -1694,9 +1694,9 @@ static void CG_DrawLagometer(void) y = 0; trap_R_SetColor(NULL); - CG_DrawPic(x, y, 48, 48, cgs.media.lagometerShader); + CG_DrawPic(cgs.screenXMin + x, y, 48, 48, cgs.media.lagometerShader); - ax = x; + ax = cgs.screenXMin + x; ay = y; aw = 48; ah = 48; @@ -2031,9 +2031,9 @@ static void CG_DrawCrosshair(void) } if (drawSSG == 0 || (drawSSG == 1 && cg_RQ3_overlaycrosshair.integer == 1)) { - x = cg_crosshairX.integer; - y = cg_crosshairY.integer; - CG_AdjustFrom640(&x, &y, &w, &h); + float half = w * 0.5f; + x = cg_crosshairX.integer + SCREEN_WIDTH / 2; + y = cg_crosshairY.integer + SCREEN_HEIGHT / 2; ca = cg_drawCrosshair.integer; if (ca < 0) { @@ -2053,8 +2053,7 @@ static void CG_DrawCrosshair(void) } trap_R_SetColor(crosshairColor); - trap_R_DrawStretchPic(x + cg.refdef.x + 0.5 * (cg.refdef.width - w), - y + cg.refdef.y + 0.5 * (cg.refdef.height - h), w, h, 0, 0, 1, 1, hShader); + CG_DrawPic(x - half, y - half, w, h, hShader); trap_R_SetColor(NULL); } } @@ -2208,19 +2207,19 @@ static void CG_DrawVote(void) MAKERGBA(Color1, 0.0f, 0.0f, 0.0f, 0.4f); - CG_FillRect(1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, + CG_FillRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, Color1); - CG_DrawCleanRect(1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, + CG_DrawCleanRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, 1, colorBlack); - CG_DrawStringExt(3, y+2, s, colorWhite, qtrue, qfalse, + CG_DrawStringExt(cgs.screenXMin + 3, y+2, s, colorWhite, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 100); y += SMALLCHAR_HEIGHT + 3; - CG_FillRect(1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, + CG_FillRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, Color1); - CG_DrawCleanRect(1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, + CG_DrawCleanRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, 1, colorBlack); - CG_DrawStringExt(3, y + 2, s2, colorWhite, qtrue, qfalse, + CG_DrawStringExt(cgs.screenXMin + 3, y + 2, s2, colorWhite, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 100); } @@ -2265,19 +2264,19 @@ static void CG_DrawTeamVote(void) MAKERGBA(Color1, 0.0f, 0.0f, 0.0f, 0.4f); - CG_FillRect(1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, + CG_FillRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, Color1); - CG_DrawCleanRect(1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, + CG_DrawCleanRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, 1, colorBlack); - CG_DrawStringExt(3, y+2, s, colorWhite, qtrue, qfalse, + CG_DrawStringExt(cgs.screenXMin + 3, y+2, s, colorWhite, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 100); y += SMALLCHAR_HEIGHT + 3; - CG_FillRect(1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, + CG_FillRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, Color1); - CG_DrawCleanRect(1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, + CG_DrawCleanRect(cgs.screenXMin + 1, y, CG_DrawStrlen(s2) * SMALLCHAR_WIDTH + 4, SMALLCHAR_HEIGHT + 4, 1, colorBlack); - CG_DrawStringExt(3, y + 2, s2, colorWhite, qtrue, qfalse, + CG_DrawStringExt(cgs.screenXMin + 3, y + 2, s2, colorWhite, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 100); } @@ -2662,7 +2661,7 @@ static void CG_DrawDamageBlend() else if (damageColor[3] < 0) damageColor[3] = 0; - CG_FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, damageColor); + CG_FillRect(cgs.screenXMin, 0, cgs.screenWidth, SCREEN_HEIGHT, damageColor); } /* diff --git a/reaction/cgame/cg_drawtools.c b/reaction/cgame/cg_drawtools.c index d2ca9a9b..0bb2bf13 100644 --- a/reaction/cgame/cg_drawtools.c +++ b/reaction/cgame/cg_drawtools.c @@ -45,14 +45,8 @@ Adjusted for resolution and screen aspect ratio */ void CG_AdjustFrom640(float *x, float *y, float *w, float *h) { -#if 0 - // adjust for wide screens - if (cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640) { - *x += 0.5 * (cgs.glconfig.vidWidth - (cgs.glconfig.vidHeight * 640 / 480)); - } -#endif // scale for screen sizes - *x *= cgs.screenXScale; + *x = *x * cgs.screenXScale + cgs.screenXBias; *y *= cgs.screenYScale; *w *= cgs.screenXScale; *h *= cgs.screenYScale; diff --git a/reaction/cgame/cg_local.h b/reaction/cgame/cg_local.h index 60f2370b..68fe539a 100644 --- a/reaction/cgame/cg_local.h +++ b/reaction/cgame/cg_local.h @@ -1671,6 +1671,10 @@ typedef struct { float screenXScale; // derived from glconfig float screenYScale; float screenXBias; + + float screenXMin; // Makro - derived from glconfig, used for wide-screens + float screenXMax; + float screenWidth; int serverCommandSequence; // reliable command stream counter int processedSnapshotNum; // the number of snapshots cgame has requested diff --git a/reaction/cgame/cg_main.c b/reaction/cgame/cg_main.c index dbd6bbd1..3e8bc17b 100644 --- a/reaction/cgame/cg_main.c +++ b/reaction/cgame/cg_main.c @@ -2963,8 +2963,13 @@ void CG_Init(int serverMessageNum, int serverCommandSequence, int clientNum) // get the rendering configuration from the client system trap_GetGlconfig(&cgs.glconfig); - cgs.screenXScale = cgs.glconfig.vidWidth / 640.0; - cgs.screenYScale = cgs.glconfig.vidHeight / 480.0; + cgs.screenYScale = cgs.glconfig.vidHeight * (1.f / SCREEN_HEIGHT); + cgs.screenXScale = cgs.screenYScale; + cgs.screenXBias = 0.5f * (cgs.glconfig.vidWidth - (cgs.glconfig.vidHeight * SCREEN_WIDTH / (float)SCREEN_HEIGHT)); + + cgs.screenXMin = 0.5f * (SCREEN_WIDTH - SCREEN_HEIGHT * cgs.glconfig.vidWidth / (float)cgs.glconfig.vidHeight); + cgs.screenXMax = SCREEN_WIDTH - cgs.screenXMin; + cgs.screenWidth = cgs.screenXMax - cgs.screenXMin; // get the gamestate from the client system trap_GetGameState(&cgs.gameState); diff --git a/reaction/cgame/cg_view.c b/reaction/cgame/cg_view.c index f7c9a070..412e73d5 100644 --- a/reaction/cgame/cg_view.c +++ b/reaction/cgame/cg_view.c @@ -1231,7 +1231,7 @@ void CG_AddLensFlare(qboolean sun) color[3] = (cgs.flareForwardFactor - ffov) / (1 - ffov) * cgs.flareFadeFactor * FLARE_BLIND_ALPHA; //Makro - too expensive //color[3] = cgs.sunAlpha * cgs.flareFadeFactor * FLARE_BLIND_ALPHA * (1.0f - abs(320 - cgs.lastSunX) / 320.0f) * (1.0f - abs(240 - cgs.lastSunY) / 240.0f); - CG_FillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color); + CG_FillRect(cgs.screenXMin, 0, cgs.screenWidth, SCREEN_HEIGHT, color); } } }