Skip to content

Instantly share code, notes, and snippets.

@zturtleman
Last active June 27, 2020 15:45
Show Gist options
  • Select an option

  • Save zturtleman/9f7968b0be0e9c6524494687236444fa to your computer and use it in GitHub Desktop.

Select an option

Save zturtleman/9f7968b0be0e9c6524494687236444fa to your computer and use it in GitHub Desktop.
Patch for ioquake3 (2020-02-11) Quake 3 UI to use 16:9 widescreen virtual UI coordinates instead of 640x480.
diff --git a/code/q3_ui/ui_atoms.c b/code/q3_ui/ui_atoms.c
index ac17814f..a25b1c4a 100644
--- a/code/q3_ui/ui_atoms.c
+++ b/code/q3_ui/ui_atoms.c
@@ -351,8 +351,8 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
// draw the colored text
trap_R_SetColor( color );
- ax = x * uis.xscale + uis.bias;
- ay = y * uis.yscale;
+ ax = x * uis.xscale + uis.xbias;
+ ay = y * uis.yscale + uis.ybias;
s = str;
while ( *s )
@@ -461,8 +461,8 @@ static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t co
// draw the colored text
trap_R_SetColor( color );
- ax = x * uis.xscale + uis.bias;
- ay = y * uis.yscale;
+ ax = x * uis.xscale + uis.xbias;
+ ay = y * uis.yscale + uis.ybias;
s = str;
while ( *s )
@@ -656,8 +656,8 @@ static void UI_DrawString2( int x, int y, const char* str, vec4_t color, int cha
// draw the colored text
trap_R_SetColor( color );
- ax = x * uis.xscale + uis.bias;
- ay = y * uis.yscale;
+ ax = x * uis.xscale + uis.xbias;
+ ay = y * uis.yscale + uis.ybias;
aw = charw * uis.xscale;
ah = charh * uis.yscale;
@@ -876,27 +876,29 @@ UI_MouseEvent
void UI_MouseEvent( int dx, int dy )
{
int i;
- int bias;
+ int xbias;
+ int ybias;
menucommon_s* m;
if (!uis.activemenu)
return;
// convert X bias to 640 coords
- bias = uis.bias / uis.xscale;
+ xbias = uis.xbias / uis.xscale;
+ ybias = uis.ybias / uis.yscale;
// update mouse screen position
uis.cursorx += dx;
- if (uis.cursorx < -bias)
- uis.cursorx = -bias;
- else if (uis.cursorx > SCREEN_WIDTH+bias)
- uis.cursorx = SCREEN_WIDTH+bias;
+ if (uis.cursorx < -xbias)
+ uis.cursorx = -xbias;
+ else if (uis.cursorx > SCREEN_WIDTH+xbias)
+ uis.cursorx = SCREEN_WIDTH+xbias;
uis.cursory += dy;
- if (uis.cursory < 0)
- uis.cursory = 0;
- else if (uis.cursory > SCREEN_HEIGHT)
- uis.cursory = SCREEN_HEIGHT;
+ if (uis.cursory < -ybias)
+ uis.cursory = -ybias;
+ else if (uis.cursory > SCREEN_HEIGHT+ybias)
+ uis.cursory = SCREEN_HEIGHT+ybias;
// region test the active menu items
for (i=0; i<uis.activemenu->nitems; i++)
@@ -1076,16 +1078,22 @@ void UI_Init( void ) {
trap_GetGlconfig( &uis.glconfig );
// for 640x480 virtualized screen
- uis.xscale = uis.glconfig.vidWidth * (1.0/640.0);
- uis.yscale = uis.glconfig.vidHeight * (1.0/480.0);
- if ( uis.glconfig.vidWidth * 480 > uis.glconfig.vidHeight * 640 ) {
+ uis.xscale = uis.glconfig.vidWidth * (1.0f/(float)SCREEN_WIDTH);
+ uis.yscale = uis.glconfig.vidHeight * (1.0f/(float)SCREEN_HEIGHT);
+ if ( uis.glconfig.vidWidth * (float)SCREEN_HEIGHT > uis.glconfig.vidHeight * (float)SCREEN_WIDTH ) {
// wide screen
- uis.bias = 0.5 * ( uis.glconfig.vidWidth - ( uis.glconfig.vidHeight * (640.0/480.0) ) );
+ uis.xbias = 0.5 * ( uis.glconfig.vidWidth - ( uis.glconfig.vidHeight * ((float)SCREEN_WIDTH/(float)SCREEN_HEIGHT) ) );
uis.xscale = uis.yscale;
+
+ uis.ybias = 0;
}
else {
// no wide screen
- uis.bias = 0;
+ uis.xbias = 0;
+
+ // narrow screen
+ uis.ybias = 0.5 * ( uis.glconfig.vidHeight - ( uis.glconfig.vidWidth * ((float)SCREEN_HEIGHT/(float)SCREEN_WIDTH) ) );
+ uis.yscale = uis.xscale;
}
// initialize the menu system
@@ -1104,8 +1112,8 @@ Adjusted for resolution and screen aspect ratio
*/
void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) {
// expect valid pointers
- *x = *x * uis.xscale + uis.bias;
- *y *= uis.yscale;
+ *x = *x * uis.xscale + uis.xbias;
+ *y = *y * uis.yscale + uis.ybias;
*w *= uis.xscale;
*h *= uis.yscale;
}
@@ -1212,6 +1220,14 @@ void UI_Refresh( int realtime )
{
if (uis.activemenu->fullscreen)
{
+ // clear edge if window is different aspect than UI
+ // Clearing for 4:3 xbias is handled in SCR_DrawScreenField().
+ if ( /* uis.xbias || */ uis.ybias ) {
+ trap_R_SetColor( g_color_table[0] );
+ trap_R_DrawStretchPic( 0, 0, uis.glconfig.vidWidth, uis.glconfig.vidHeight, 0, 0, 0, 0, uis.whiteShader );
+ trap_R_SetColor( NULL );
+ }
+
// draw the background
if( uis.activemenu->showlogo ) {
UI_DrawHandlePic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, uis.menuBackShader );
diff --git a/code/q3_ui/ui_local.h b/code/q3_ui/ui_local.h
index 1135a52d..f32664bd 100644
--- a/code/q3_ui/ui_local.h
+++ b/code/q3_ui/ui_local.h
@@ -33,6 +33,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../client/keycodes.h"
#include "../game/bg_public.h"
+// SCREEN_WIDTH and SCREEN_HEIGHT should be max for UI_AdjustFrom640().
+// However for (only) widescreen menu SCREEN_* must be seprate values for UI, CGame, and Client. So redefine it here.
+#undef SCREEN_WIDTH
+#undef SCREEN_HEIGHT
+#define SCREEN_WIDTH 1280
+#define SCREEN_HEIGHT 720
+
+// Closer to Quake 3's 640x480 so existing menus fill screen height.
+//#define SCREEN_WIDTH 864
+//#define SCREEN_HEIGHT 486
+
typedef void (*voidfunc_f)(void);
extern vmCvar_t ui_ffa_fraglimit;
@@ -556,7 +567,8 @@ typedef struct {
qhandle_t rb_off;
float xscale;
float yscale;
- float bias;
+ float xbias;
+ float ybias;
qboolean demoversion;
qboolean firstdraw;
} uiStatic_t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment