[quake3] [PATCH] set custom resolution from UI

Erik Auerswald auerswal at unix-ag.uni-kl.de
Sun Feb 12 07:10:24 EST 2006


Hi,

On Thu, Feb 02, 2006 at 12:37:13AM +0100, Erik Auerswald wrote:
> the attached patch adds setting the custom resolution (r_mode -1,
> r_customwidth and r_customheight) to the menu.

That patch had wrong dimensions for the input fields blocking the two
menu entries below. The attached patch fixes this.

Erik
-------------- next part --------------
Index: code/q3_ui/ui_video.c
===================================================================
--- code/q3_ui/ui_video.c	(revision 538)
+++ code/q3_ui/ui_video.c	(working copy)
@@ -254,7 +254,11 @@
 #define ID_DISPLAY		107
 #define ID_SOUND		108
 #define ID_NETWORK		109
+#define ID_CUSTOM_WIDTH		110
+#define ID_CUSTOM_HEIGHT	111
 
+#define MAX_RES_LENGTH		5 // maximum # digits in custom width/height
+
 typedef struct {
 	menuframework_s	menu;
 
@@ -269,6 +273,8 @@
 
 	menulist_s		list;
 	menulist_s		mode;
+	menufield_s		customwidth;
+	menufield_s		customheight;
 	menulist_s		driver;
 	menuslider_s	tq;
 	menulist_s  	fs;
@@ -298,8 +304,15 @@
 	qboolean extensions;
 } InitialVideoOptions_s;
 
+typedef struct
+{
+	char width[MAX_RES_LENGTH+1];
+	char height[MAX_RES_LENGTH+1];
+} InitialCustomResolution_s;
+
 static InitialVideoOptions_s	s_ivo;
 static graphicsoptions_t		s_graphicsoptions;	
+static InitialCustomResolution_s	s_icr;
 
 static InitialVideoOptions_s s_ivo_templates[] =
 {
@@ -342,6 +355,8 @@
 	s_ivo.geometry    = s_graphicsoptions.geometry.curvalue;
 	s_ivo.filter      = s_graphicsoptions.filter.curvalue;
 	s_ivo.texturebits = s_graphicsoptions.texturebits.curvalue;
+	Q_strncpyz( s_icr.width, s_graphicsoptions.customwidth.field.buffer, MAX_RES_LENGTH+1);
+	Q_strncpyz( s_icr.height, s_graphicsoptions.customheight.field.buffer, MAX_RES_LENGTH+1);
 }
 
 /*
@@ -423,6 +438,14 @@
 	{
 		s_graphicsoptions.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
 	}
+	if ( strcmp( s_icr.width, s_graphicsoptions.customwidth.field.buffer ) )
+	{
+		s_graphicsoptions.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
+	}
+	if ( strcmp( s_icr.height, s_graphicsoptions.customheight.field.buffer ) )
+	{
+		s_graphicsoptions.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
+	}
 	if ( s_ivo.fullscreen != s_graphicsoptions.fs.curvalue )
 	{
 		s_graphicsoptions.apply.generic.flags &= ~(QMF_HIDDEN|QMF_INACTIVE);
@@ -487,7 +510,20 @@
 	}
 	trap_Cvar_SetValue( "r_picmip", 3 - s_graphicsoptions.tq.curvalue );
 	trap_Cvar_SetValue( "r_allowExtensions", s_graphicsoptions.allow_extensions.curvalue );
-	trap_Cvar_SetValue( "r_mode", s_graphicsoptions.mode.curvalue );
+
+	if ( s_graphicsoptions.mode.curvalue == s_graphicsoptions.mode.numitems - 1 )
+	{
+		trap_Cvar_SetValue( "r_mode", -1 );
+	}
+	else
+	{
+		trap_Cvar_SetValue( "r_mode", s_graphicsoptions.mode.curvalue );
+	}
+	
+	// set custom width and height
+	trap_Cvar_Set( "r_customwidth", s_graphicsoptions.customwidth.field.buffer );
+	trap_Cvar_Set( "r_customheight", s_graphicsoptions.customheight.field.buffer );
+
 	trap_Cvar_SetValue( "r_fullscreen", s_graphicsoptions.fs.curvalue );
 	trap_Cvar_Set( "r_glDriver", ( char * ) s_drivers[s_graphicsoptions.driver.curvalue] );
 	switch ( s_graphicsoptions.colordepth.curvalue )
@@ -599,6 +635,12 @@
 		UI_PopMenu();
 		UI_NetworkOptionsMenu();
 		break;
+
+	case ID_CUSTOM_WIDTH:
+		break;
+
+	case ID_CUSTOM_HEIGHT:
+		break;
 	}
 }
 
@@ -618,6 +660,94 @@
 
 /*
 ================
+GraphicsOptions_DrawCustomwidth
+================
+*/
+static void GraphicsOptions_DrawCustomwidth( void *self ) {
+	menufield_s		*f;
+	qboolean		focus;
+	int			style;
+	float			*color;
+	int			basex, y;
+	char			c;
+
+	f = (menufield_s*)self;
+	basex = f->generic.x;
+	y = f->generic.y;
+	focus = (f->generic.parent->cursor == f->generic.menuPosition);
+
+	style = UI_LEFT|UI_SMALLFONT;
+	color = text_color_normal;
+	if( focus ) {
+		style |= UI_PULSE;
+		color = text_color_highlight;
+	}
+
+	UI_DrawString( basex, y, "Custom Resolution:", style, color);
+	UI_DrawString( basex + 20 * SMALLCHAR_WIDTH, y, f->field.buffer, style, color_white );
+
+	// draw cursor if we have focus
+	if( focus ) {
+		if ( trap_Key_GetOverstrikeMode() ) {
+			c = 11;
+		} else {
+			c = 10;
+		}
+
+		style &= ~UI_PULSE;
+		style |= UI_BLINK;
+
+		UI_DrawChar( basex + 20 * SMALLCHAR_WIDTH + f->field.cursor * SMALLCHAR_WIDTH, y, c, style, color_white );
+	}
+}
+
+
+/*
+================
+GraphicsOptions_DrawCustomheight
+================
+*/
+static void GraphicsOptions_DrawCustomheight( void *self ) {
+	menufield_s		*f;
+	qboolean		focus;
+	int			style;
+	float			*color;
+	int			basex, y;
+	char			c;
+
+	f = (menufield_s*)self;
+	basex = f->generic.x;
+	y = f->generic.y;
+	focus = (f->generic.parent->cursor == f->generic.menuPosition);
+
+	style = UI_LEFT|UI_SMALLFONT;
+	color = text_color_normal;
+	if( focus ) {
+		style |= UI_PULSE;
+		color = text_color_highlight;
+	}
+
+	UI_DrawString( basex, y, "x", style, color);
+	UI_DrawString( basex + 2 * SMALLCHAR_WIDTH, y, f->field.buffer, style, color_white );
+
+	// draw cursor if we have focus
+	if( focus ) {
+		if ( trap_Key_GetOverstrikeMode() ) {
+			c = 11;
+		} else {
+			c = 10;
+		}
+
+		style &= ~UI_PULSE;
+		style |= UI_BLINK;
+
+		UI_DrawChar( basex + 2 * SMALLCHAR_WIDTH + f->field.cursor * SMALLCHAR_WIDTH, y, c, style, color_white );
+	}
+}
+
+
+/*
+================
 GraphicsOptions_MenuDraw
 ================
 */
@@ -639,8 +769,10 @@
 	s_graphicsoptions.mode.curvalue = trap_Cvar_VariableValue( "r_mode" );
 	if ( s_graphicsoptions.mode.curvalue < 0 )
 	{
-		s_graphicsoptions.mode.curvalue = 3;
+		s_graphicsoptions.mode.curvalue = s_graphicsoptions.mode.numitems - 1;
 	}
+	Q_strncpyz( s_graphicsoptions.customwidth.field.buffer, UI_Cvar_VariableString("r_customwidth"), sizeof(s_graphicsoptions.customwidth.field.buffer) );
+	Q_strncpyz( s_graphicsoptions.customheight.field.buffer, UI_Cvar_VariableString("r_customheight"), sizeof(s_graphicsoptions.customheight.field.buffer) );
 	s_graphicsoptions.fs.curvalue = trap_Cvar_VariableValue("r_fullscreen");
 	s_graphicsoptions.allow_extensions.curvalue = trap_Cvar_VariableValue("r_allowExtensions");
 	s_graphicsoptions.tq.curvalue = 3-trap_Cvar_VariableValue( "r_picmip");
@@ -779,6 +911,7 @@
 		"1600x1200",
 		"2048x1536",
 		"856x480 wide screen",
+		"use custom resolution", // this must be the last item
 		NULL
 	};
 	static const char *filter_names[] =
@@ -915,6 +1048,35 @@
 	s_graphicsoptions.mode.generic.id       = ID_MODE;
 	y += BIGCHAR_HEIGHT+2;
 
+	// references/modifies "r_customwidth"
+	s_graphicsoptions.customwidth.generic.type       = MTYPE_FIELD;
+	s_graphicsoptions.customwidth.generic.flags      = QMF_NODEFAULTINIT|QMF_NUMBERSONLY;
+	s_graphicsoptions.customwidth.generic.ownerdraw  = GraphicsOptions_DrawCustomwidth;
+	s_graphicsoptions.customwidth.generic.id         = ID_CUSTOM_WIDTH;
+	s_graphicsoptions.customwidth.generic.x          = 400 - 19 * SMALLCHAR_WIDTH;
+	s_graphicsoptions.customwidth.generic.y          = y;
+	s_graphicsoptions.customwidth.generic.left       = 400 - 19 * SMALLCHAR_WIDTH - 8;
+	s_graphicsoptions.customwidth.generic.top        = y - 8;
+	s_graphicsoptions.customwidth.generic.right      = 400 + 5 * SMALLCHAR_WIDTH;
+	s_graphicsoptions.customwidth.generic.bottom     = y + BIGCHAR_HEIGHT;
+	s_graphicsoptions.customwidth.field.widthInChars = MAX_RES_LENGTH;
+	s_graphicsoptions.customwidth.field.maxchars     = MAX_RES_LENGTH;
+
+	// references/modifies "r_customheight"
+	s_graphicsoptions.customheight.generic.type       = MTYPE_FIELD;
+	s_graphicsoptions.customheight.generic.flags      = QMF_NODEFAULTINIT|QMF_NUMBERSONLY;
+	s_graphicsoptions.customheight.generic.ownerdraw  = GraphicsOptions_DrawCustomheight;
+	s_graphicsoptions.customwidth.generic.id         = ID_CUSTOM_HEIGHT;
+	s_graphicsoptions.customheight.generic.x          = 400 + 6 * SMALLCHAR_WIDTH;
+	s_graphicsoptions.customheight.generic.y          = y;
+	s_graphicsoptions.customheight.generic.left       = 400 + 6 * SMALLCHAR_WIDTH;
+	s_graphicsoptions.customheight.generic.top        = y - 8;
+	s_graphicsoptions.customheight.generic.right      = 400 + 11 * SMALLCHAR_WIDTH;
+	s_graphicsoptions.customheight.generic.bottom     = y + BIGCHAR_HEIGHT;
+	s_graphicsoptions.customheight.field.widthInChars = MAX_RES_LENGTH;
+	s_graphicsoptions.customheight.field.maxchars     = MAX_RES_LENGTH;
+	y += BIGCHAR_HEIGHT+2;
+
 	// references "r_colorbits"
 	s_graphicsoptions.colordepth.generic.type     = MTYPE_SPINCONTROL;
 	s_graphicsoptions.colordepth.generic.name     = "Color Depth:";
@@ -1025,6 +1187,8 @@
 	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.driver );
 	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.allow_extensions );
 	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.mode );
+	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.customwidth );
+	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.customheight );
 	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.colordepth );
 	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.fs );
 	Menu_AddItem( &s_graphicsoptions.menu, ( void * ) &s_graphicsoptions.lighting );


More information about the quake3 mailing list