[iortcw] 448/497: SP: Add aspect corrected UI to cg_fixedAspect

Simon McVittie smcv at debian.org
Fri Sep 8 10:37:49 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.42d
in repository iortcw.

commit 79f79da55b03485fac01ca647b2a2b9b6ca73dc3
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date:   Sat Nov 28 14:58:03 2015 -0500

    SP: Add aspect corrected UI to cg_fixedAspect
---
 SP/code/cgame/cg_local.h   |  13 ----
 SP/code/qcommon/q_shared.h |  13 ++++
 SP/code/ui/ui_atoms.c      |  23 -------
 SP/code/ui/ui_local.h      |   2 +
 SP/code/ui/ui_main.c       |  41 ++++++++++---
 SP/code/ui/ui_shared.c     | 150 +++++++++++++++++++++++++++++++++++++++++----
 SP/code/ui/ui_shared.h     |   9 +++
 7 files changed, 197 insertions(+), 54 deletions(-)

diff --git a/SP/code/cgame/cg_local.h b/SP/code/cgame/cg_local.h
index eff3f82..86d32e6 100644
--- a/SP/code/cgame/cg_local.h
+++ b/SP/code/cgame/cg_local.h
@@ -1831,19 +1831,6 @@ void CG_Concussive( centity_t *cent );
 //
 // cg_drawtools.c
 //
-typedef enum {
-	PLACE_STRETCH,
-	PLACE_CENTER,
-
-	// horizontal only
-	PLACE_LEFT,
-	PLACE_RIGHT,
-
-	// vertical only
-	PLACE_TOP,
-	PLACE_BOTTOM
-} screenPlacement_e;
-
 void CG_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos);
 void CG_PopScreenPlacement(void);
 screenPlacement_e CG_GetScreenHorizontalPlacement(void);
diff --git a/SP/code/qcommon/q_shared.h b/SP/code/qcommon/q_shared.h
index b8941c6..6adc8aa 100644
--- a/SP/code/qcommon/q_shared.h
+++ b/SP/code/qcommon/q_shared.h
@@ -474,6 +474,19 @@ extern vec4_t g_color_table[8];
 #define DEG2RAD( a ) ( ( ( a ) * M_PI ) / 180.0F )
 #define RAD2DEG( a ) ( ( ( a ) * 180.0f ) / M_PI )
 
+typedef enum {
+	PLACE_STRETCH,
+	PLACE_CENTER,
+
+	// horizontal only
+	PLACE_LEFT,
+	PLACE_RIGHT,
+
+	// vertical only
+	PLACE_TOP,
+	PLACE_BOTTOM
+} screenPlacement_e;
+
 struct cplane_s;
 
 extern vec3_t vec3_origin;
diff --git a/SP/code/ui/ui_atoms.c b/SP/code/ui/ui_atoms.c
index 368fa56..fda6182 100644
--- a/SP/code/ui/ui_atoms.c
+++ b/SP/code/ui/ui_atoms.c
@@ -425,29 +425,6 @@ UI_Shutdown
 void UI_Shutdown( void ) {
 }
 
-/*
-================
-UI_AdjustFrom640
-
-Adjusted for resolution and screen aspect ratio
-================
-*/
-void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) {
-	// expect valid pointers
-#if 0
-	*x = *x * uiInfo.uiDC.scale + uiInfo.uiDC.bias;
-	*y *= uiInfo.uiDC.scale;
-	*w *= uiInfo.uiDC.scale;
-	*h *= uiInfo.uiDC.scale;
-#endif
-
-	*x *= uiInfo.uiDC.xscale;
-	*y *= uiInfo.uiDC.yscale;
-	*w *= uiInfo.uiDC.xscale;
-	*h *= uiInfo.uiDC.yscale;
-
-}
-
 void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname ) {
 	qhandle_t hShader;
 
diff --git a/SP/code/ui/ui_local.h b/SP/code/ui/ui_local.h
index 205a6d4..c132346 100644
--- a/SP/code/ui/ui_local.h
+++ b/SP/code/ui/ui_local.h
@@ -75,6 +75,8 @@ extern vmCvar_t ui_autoactivate;
 extern vmCvar_t ui_emptyswitch;
 // END JOSEPH
 
+extern vmCvar_t ui_fixedAspect;
+
 extern vmCvar_t ui_server1;
 extern vmCvar_t ui_server2;
 extern vmCvar_t ui_server3;
diff --git a/SP/code/ui/ui_main.c b/SP/code/ui/ui_main.c
index 0083a2f..252385f 100644
--- a/SP/code/ui/ui_main.c
+++ b/SP/code/ui/ui_main.c
@@ -6587,14 +6587,36 @@ void _UI_Init( qboolean inGameLoad ) {
 	trap_GetGlconfig( &uiInfo.uiDC.glconfig );
 
 	// for 640x480 virtualized screen
-	uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * ( 1.0 / 480.0 );
-	uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * ( 1.0 / 640.0 );
-	if ( uiInfo.uiDC.glconfig.vidWidth * 480 > uiInfo.uiDC.glconfig.vidHeight * 640 ) {
-		// wide screen
-		uiInfo.uiDC.bias = 0.5 * ( uiInfo.uiDC.glconfig.vidWidth - ( uiInfo.uiDC.glconfig.vidHeight * ( 640.0 / 480.0 ) ) );
+	if ( ui_fixedAspect.integer ) {
+		uiInfo.uiDC.xscaleStretch = uiInfo.uiDC.glconfig.vidWidth * (1.0/640.0);
+		uiInfo.uiDC.yscaleStretch = uiInfo.uiDC.glconfig.vidHeight * (1.0/480.0);
+		if ( uiInfo.uiDC.glconfig.vidWidth * 480 > uiInfo.uiDC.glconfig.vidHeight * 640 ) {
+			uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * (1.0/640.0);
+			uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * (1.0/480.0);
+			// wide screen
+			uiInfo.uiDC.xBias = 0.5 * ( uiInfo.uiDC.glconfig.vidWidth - ( uiInfo.uiDC.glconfig.vidHeight * (640.0/480.0) ) );
+			uiInfo.uiDC.xscale = uiInfo.uiDC.yscale;
+			// no narrow screen
+			uiInfo.uiDC.yBias = 0;
+		} else {
+			uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * (1.0/640.0);
+			uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * (1.0/480.0);
+			// narrow screen
+			uiInfo.uiDC.yBias = 0.5 * ( uiInfo.uiDC.glconfig.vidHeight - ( uiInfo.uiDC.glconfig.vidWidth * (480.0/640.0) ) );
+			uiInfo.uiDC.yscale = uiInfo.uiDC.xscale;
+			// no wide screen
+			uiInfo.uiDC.xBias = 0;
+		}
 	} else {
-		// no wide screen
-		uiInfo.uiDC.bias = 0;
+		uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * ( 1.0 / 480.0 );
+		uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * ( 1.0 / 640.0 );
+		if ( uiInfo.uiDC.glconfig.vidWidth * 480 > uiInfo.uiDC.glconfig.vidHeight * 640 ) {
+			// wide screen
+			uiInfo.uiDC.bias = 0.5 * ( uiInfo.uiDC.glconfig.vidWidth - ( uiInfo.uiDC.glconfig.vidHeight * ( 640.0 / 480.0 ) ) );
+		} else {
+			// no wide screen
+			uiInfo.uiDC.bias = 0;
+		}
 	}
 
 
@@ -7247,6 +7269,8 @@ vmCvar_t ui_autoactivate;
 vmCvar_t ui_emptyswitch;        //----(SA)	added
 // END JOSEPH
 
+vmCvar_t ui_fixedAspect;
+
 vmCvar_t ui_server1;
 vmCvar_t ui_server2;
 vmCvar_t ui_server3;
@@ -7356,6 +7380,9 @@ cvarTable_t cvarTable[] = {
 	{ &ui_autoactivate, "cg_autoactivate", "1", CVAR_ARCHIVE },
 	{ &ui_useSuggestedWeapons, "cg_useSuggestedWeapons", "1", CVAR_ARCHIVE }, //----(SA)	added
 	{ &ui_emptyswitch, "cg_emptyswitch", "0", CVAR_ARCHIVE }, //----(SA)	added
+
+	{ &ui_fixedAspect, "cg_fixedAspect", "0", CVAR_ARCHIVE | CVAR_LATCH },
+
 	{ &ui_server1, "server1", "", CVAR_ARCHIVE },
 	{ &ui_server2, "server2", "", CVAR_ARCHIVE },
 	{ &ui_server3, "server3", "", CVAR_ARCHIVE },
diff --git a/SP/code/ui/ui_shared.c b/SP/code/ui/ui_shared.c
index 81c4a98..ee7466e 100644
--- a/SP/code/ui/ui_shared.c
+++ b/SP/code/ui/ui_shared.c
@@ -90,7 +90,6 @@ static qboolean Menu_OverActiveItem( menuDef_t *menu, float x, float y );
 static char memoryPool[MEM_POOL_SIZE];
 static int allocPoint, outOfMemory;
 
-
 // these are expected to be translated by the strings.txt file
 translateString_t translateStrings[] = {
 	{"end_time"},                //	"Time"
@@ -147,6 +146,114 @@ translateString_t translateStrings[] = {
 	{"or"}                       //
 };
 
+
+static screenPlacement_e ui_horizontalPlacement = PLACE_CENTER;
+static screenPlacement_e ui_verticalPlacement = PLACE_CENTER;
+static screenPlacement_e ui_lastHorizontalPlacement = PLACE_CENTER;
+static screenPlacement_e ui_lastVerticalPlacement = PLACE_CENTER;
+
+/*
+================
+UI_SetScreenPlacement
+================
+*/
+void UI_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos)
+{
+	ui_lastHorizontalPlacement = ui_horizontalPlacement;
+	ui_lastVerticalPlacement = ui_verticalPlacement;
+
+	ui_horizontalPlacement = hpos;
+	ui_verticalPlacement = vpos;
+}
+
+/*
+================
+UI_PopScreenPlacement
+================
+*/
+void UI_PopScreenPlacement(void)
+{
+	ui_horizontalPlacement = ui_lastHorizontalPlacement;
+	ui_verticalPlacement = ui_lastVerticalPlacement;
+}
+
+/*
+================
+UI_GetScreenHorizontalPlacement
+================
+*/
+screenPlacement_e UI_GetScreenHorizontalPlacement(void)
+{
+	return ui_horizontalPlacement;
+}
+
+/*
+================
+UI_GetScreenVerticalPlacement
+================
+*/
+screenPlacement_e UI_GetScreenVerticalPlacement(void)
+{
+	return ui_verticalPlacement;
+}
+
+vmCvar_t ui_fixedAspect;
+
+/*
+================
+UI_AdjustFrom640
+
+Adjusted for resolution and screen aspect ratio
+================
+*/
+void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) {
+	// expect valid pointers
+#if 0
+	*x = *x * DC->scale + DC->bias;
+	*y *= DC->scale;
+	*w *= DC->scale;
+	*h *= DC->scale;
+#endif
+
+	if ( ui_fixedAspect.integer ) {
+		if (ui_horizontalPlacement == PLACE_STRETCH) {
+			// scale for screen sizes (not aspect correct in wide screen)
+			*w *= DC->xscaleStretch;
+			*x *= DC->xscaleStretch;
+		} else {
+			// scale for screen sizes
+			*w *= DC->xscale;
+			*x *= DC->xscale;
+	
+			if (ui_horizontalPlacement == PLACE_CENTER) {
+				*x += DC->xBias;
+			} else if (ui_horizontalPlacement == PLACE_RIGHT) {
+				*x += DC->xBias*2;
+			}
+		}
+
+		if (ui_verticalPlacement == PLACE_STRETCH) {
+			*h *= DC->yscaleStretch;
+			*y *= DC->yscaleStretch;
+		} else {
+			*h *= DC->yscale;
+			*y *= DC->yscale;
+	
+			if (ui_verticalPlacement == PLACE_CENTER) {
+				*y += DC->yBias;
+			} else if (ui_verticalPlacement == PLACE_BOTTOM) {
+				*y += DC->yBias*2;
+			}
+		}
+	} else {
+		*x *= DC->xscale;
+		*y *= DC->yscale;
+		*w *= DC->xscale;
+		*h *= DC->yscale;
+	}
+}
+
+
 //----(SA)	added
 /*
 ==============
@@ -712,8 +819,6 @@ void Fade( int *flags, float *f, float clamp, int *nextTime, int offsetTime, qbo
 	}
 }
 
-
-
 void Window_Paint( Window *w, float fadeAmount, float fadeClamp, float fadeCycle ) {
 	//float bordersize = 0;
 	vec4_t color = {0};
@@ -741,6 +846,17 @@ void Window_Paint( Window *w, float fadeAmount, float fadeClamp, float fadeCycle
 		fillRect.h -= w->borderSize + 1;
 	}
 
+	// Make pillarbox for 4:3 UI
+	if ( ui_fixedAspect.integer == 1 ) {
+		if ( DC->glconfig.vidWidth * 480 > DC->glconfig.vidHeight * 640 ) {
+			vec4_t col = {0, 0, 0, 1};
+			UI_SetScreenPlacement(PLACE_LEFT, PLACE_CENTER);
+			DC->drawRect( 0, 0, DC->xBias, 480, DC->xBias + 1, col );
+			DC->drawRect( 640 + DC->xBias, 0, DC->xBias, 480, DC->xBias + 1, col );
+			UI_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+		}
+	}
+
 	if ( w->style == WINDOW_STYLE_FILLED ) {
 		// box, but possible a shader that needs filled
 		if ( w->background ) {
@@ -758,8 +874,15 @@ void Window_Paint( Window *w, float fadeAmount, float fadeClamp, float fadeCycle
 		if ( w->flags & WINDOW_FORECOLORSET ) {
 			DC->setColor( w->foreColor );
 		}
-		DC->drawHandlePic( fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background );
-		DC->setColor( NULL );
+		if ( ui_fixedAspect.integer == 2 && ( Q_stricmpn( w->name, "FLA", 3 ) ) && ( Q_stricmpn( w->name, "WOLF", 4 ) ) ) { // HACK to widen menu items
+			UI_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
+			DC->drawHandlePic( fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background );
+			DC->setColor( NULL );
+		} else {
+			UI_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
+			DC->drawHandlePic( fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background );
+			DC->setColor( NULL );
+		}
 	} else if ( w->style == WINDOW_STYLE_TEAMCOLOR ) {
 		if ( DC->getTeamColor ) {
 			DC->getTeamColor( &color );
@@ -3855,14 +3978,19 @@ qboolean Item_Bind_HandleKey( itemDef_t *item, int key, qboolean down ) {
 	return qtrue;
 }
 
-
-
 void AdjustFrom640( float *x, float *y, float *w, float *h ) {
 	//*x = *x * DC->scale + DC->bias;
-	*x *= DC->xscale;
-	*y *= DC->yscale;
-	*w *= DC->xscale;
-	*h *= DC->yscale;
+	if ( ui_fixedAspect.integer ) {
+		*w *= DC->xscale;
+		*x = *x * DC->xscale + DC->xBias;
+		*h *= DC->yscale;
+		*y = *y * DC->yscale + DC->yBias;
+	} else {
+		*x *= DC->xscale;
+		*y *= DC->yscale;
+		*w *= DC->xscale;
+		*h *= DC->yscale;
+	}
 }
 
 void Item_Model_Paint( itemDef_t *item ) {
diff --git a/SP/code/ui/ui_shared.h b/SP/code/ui/ui_shared.h
index 1d2cf84..36d5b51 100644
--- a/SP/code/ui/ui_shared.h
+++ b/SP/code/ui/ui_shared.h
@@ -406,6 +406,10 @@ typedef struct {
 
 	float yscale;
 	float xscale;
+	float yscaleStretch;
+	float xscaleStretch;
+	float yBias;
+	float xBias;
 	float bias;
 	int realTime;
 	int frameTime;
@@ -501,4 +505,9 @@ int         trap_PC_FreeSource( int handle );
 int         trap_PC_ReadToken( int handle, pc_token_t *pc_token );
 int         trap_PC_SourceFileAndLine( int handle, char *filename, int *line );
 
+void UI_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos);
+void UI_PopScreenPlacement(void);
+screenPlacement_e UI_GetScreenHorizontalPlacement(void);
+screenPlacement_e UI_GetScreenVerticalPlacement(void);
+
 #endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git



More information about the Pkg-games-commits mailing list