summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2009-10-03 11:27:22 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:15:00 +0000
commitf65675275f974129c76249e374b5423a2a444acd (patch)
tree1da97a1bd26d179ad9da2342df8060638d24ef8a /src/ui
parente5d4b2471e72ff574ebc0d01afbab50fc447cf5a (diff)
* s/r_custom/r_/
* Remove r_mode, making r_width and r_height the only way to choose resolution * Add UI code to parse the detected resolutions list * Make ITEM_TYPE_COMBO do something; basically an ITEM_TYPE_MULTI which is populated by a feeder. A proper combobox widget would be better... in the future maybe * Improve keyboard/mouse button control on ITEM_TYPE_MULTI * Change resolution selection in options menu to use an ITEM_TYPE_COMBO fed by FEEDER_RESOLUTIONS
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/ui_local.h11
-rw-r--r--src/ui/ui_main.c83
-rw-r--r--src/ui/ui_shared.c102
-rw-r--r--src/ui/ui_shared.h8
4 files changed, 193 insertions, 11 deletions
diff --git a/src/ui/ui_local.h b/src/ui/ui_local.h
index 222942cb..e01f1b8f 100644
--- a/src/ui/ui_local.h
+++ b/src/ui/ui_local.h
@@ -58,6 +58,7 @@ void UI_DrawConnectScreen( qboolean overlay );
#define MAX_DEMOS 256
#define MAX_MOVIES 256
#define MAX_HELP_INFOPANES 32
+#define MAX_RESOLUTIONS 32
typedef struct
{
@@ -178,6 +179,13 @@ menuItem_t;
typedef struct
{
+ int w;
+ int h;
+}
+resolution_t;
+
+typedef struct
+{
displayContextDef_t uiDC;
int playerCount;
@@ -267,6 +275,9 @@ typedef struct
int numFoundPlayerServers;
int nextFindPlayerRefresh;
+ resolution_t resolutions[ MAX_RESOLUTIONS ];
+ int numResolutions;
+
qboolean inGameLoad;
qboolean chatTeam;
diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c
index fcc3799d..5144c7c7 100644
--- a/src/ui/ui_main.c
+++ b/src/ui/ui_main.c
@@ -3353,6 +3353,8 @@ static int UI_FeederCount( float feederID )
return uiInfo.alienBuildCount;
else if( feederID == FEEDER_TREMHUMANBUILD )
return uiInfo.humanBuildCount;
+ else if( feederID == FEEDER_RESOLUTIONS )
+ return uiInfo.numResolutions;
return 0;
}
@@ -3382,9 +3384,12 @@ static const char *UI_FeederItemText( float feederID, int index, int column, qha
static char info[MAX_STRING_CHARS];
static char hostname[1024];
static char clientBuff[32];
+ static char resolution[MAX_STRING_CHARS];
static int lastColumn = -1;
static int lastTime = 0;
- *handle = -1;
+
+ if( handle )
+ *handle = -1;
if( feederID == FEEDER_MAPS )
{
@@ -3571,6 +3576,24 @@ static const char *UI_FeederItemText( float feederID, int index, int column, qha
if( index >= 0 && index < uiInfo.humanBuildCount )
return uiInfo.humanBuildList[ index ].text;
}
+ else if( feederID == FEEDER_RESOLUTIONS )
+ {
+ int i;
+ int w = trap_Cvar_VariableValue( "r_width" );
+ int h = trap_Cvar_VariableValue( "r_height" );
+
+ for( i = 0; i < uiInfo.numResolutions; i++ )
+ {
+ if( w == uiInfo.resolutions[ i ].w && h == uiInfo.resolutions[ i ].h )
+ {
+ Com_sprintf( resolution, sizeof( resolution ), "%dx%d", w, h );
+ return resolution;
+ }
+ }
+
+ Com_sprintf( resolution, sizeof( resolution ), "Custom (%dx%d)", w, h );
+ return resolution;
+ }
return "";
}
@@ -3697,6 +3720,29 @@ static void UI_FeederSelection( float feederID, int index )
uiInfo.alienBuildIndex = index;
else if( feederID == FEEDER_TREMHUMANBUILD )
uiInfo.humanBuildIndex = index;
+ else if( feederID == FEEDER_RESOLUTIONS )
+ {
+ trap_Cvar_Set( "r_width", va( "%d", uiInfo.resolutions[ index ].w ) );
+ trap_Cvar_Set( "r_height", va( "%d", uiInfo.resolutions[ index ].h ) );
+ }
+}
+
+static int UI_FeederInitialise( float feederID )
+{
+ if( feederID == FEEDER_RESOLUTIONS )
+ {
+ int i;
+ int w = trap_Cvar_VariableValue( "r_width" );
+ int h = trap_Cvar_VariableValue( "r_height" );
+
+ for( i = 0; i < uiInfo.numResolutions; i++ )
+ {
+ if( w == uiInfo.resolutions[ i ].w && h == uiInfo.resolutions[ i ].h )
+ return i;
+ }
+ }
+
+ return 0;
}
static void UI_Pause( qboolean b )
@@ -3756,6 +3802,38 @@ static float UI_GetValue( int ownerDraw )
return 0.0f;
}
+/*
+=================
+UI_ParseResolutions
+=================
+*/
+void UI_ParseResolutions( void )
+{
+ char buf[ MAX_STRING_CHARS ];
+ char w[ 16 ], h[ 16 ];
+ char *p;
+ const char *out;
+ char *s = NULL;
+
+ trap_Cvar_VariableStringBuffer( "r_availableModes", buf, sizeof( buf ) );
+ p = buf;
+ uiInfo.numResolutions = 0;
+
+ while( String_Parse( &p, &out ) )
+ {
+ Q_strncpyz( w, out, sizeof( w ) );
+ s = strchr( w, 'x' );
+ if( !s )
+ return;
+
+ *s++ = '\0';
+ Q_strncpyz( h, s, sizeof( h ) );
+
+ uiInfo.resolutions[ uiInfo.numResolutions ].w = atoi( w );
+ uiInfo.resolutions[ uiInfo.numResolutions ].h = atoi( h );
+ uiInfo.numResolutions++;
+ }
+}
/*
=================
@@ -3815,6 +3893,7 @@ void UI_Init( qboolean inGameLoad )
uiInfo.uiDC.feederItemImage = &UI_FeederItemImage;
uiInfo.uiDC.feederItemText = &UI_FeederItemText;
uiInfo.uiDC.feederSelection = &UI_FeederSelection;
+ uiInfo.uiDC.feederInitialise = &UI_FeederInitialise;
uiInfo.uiDC.setBinding = &trap_Key_SetBinding;
uiInfo.uiDC.getBindingBuf = &trap_Key_GetBindingBuf;
uiInfo.uiDC.keynumToStringBuf = &trap_Key_KeynumToStringBuf;
@@ -3858,6 +3937,8 @@ void UI_Init( qboolean inGameLoad )
uiInfo.previewMovie = -1;
trap_Cvar_Register( NULL, "debug_protocol", "", 0 );
+
+ UI_ParseResolutions( );
}
diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c
index 2b06329a..8d6d3635 100644
--- a/src/ui/ui_shared.c
+++ b/src/ui/ui_shared.c
@@ -3320,23 +3320,70 @@ const char *Item_Multi_Setting( itemDef_t *item )
return "";
}
+qboolean Item_Combobox_HandleKey( itemDef_t *item, int key )
+{
+ comboBoxDef_t *comboPtr = (comboBoxDef_t *)item->typeData;
+ qboolean mouseOver = Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory );
+ int count = DC->feederCount( item->special );
+
+ if( comboPtr )
+ {
+ if( item->window.flags & WINDOW_HASFOCUS )
+ {
+ if( ( mouseOver && key == K_MOUSE1 ) ||
+ key == K_ENTER || key == K_RIGHTARROW || key == K_DOWNARROW )
+ {
+ if( count > 0 )
+ comboPtr->cursorPos = ( comboPtr->cursorPos + 1 ) % count;
+
+ DC->feederSelection( item->special, comboPtr->cursorPos );
+
+ return qtrue;
+ }
+ else if( ( mouseOver && key == K_MOUSE2 ) ||
+ key == K_LEFTARROW || key == K_UPARROW )
+ {
+ if( count > 0 )
+ comboPtr->cursorPos = ( count + comboPtr->cursorPos - 1 ) % count;
+
+ DC->feederSelection( item->special, comboPtr->cursorPos );
+
+ return qtrue;
+ }
+ }
+ }
+
+ return qfalse;
+}
+
qboolean Item_Multi_HandleKey( itemDef_t *item, int key )
{
multiDef_t * multiPtr = ( multiDef_t* )item->typeData;
+ qboolean mouseOver = Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory );
+ int max = Item_Multi_CountSettings( item );
+ qboolean changed = qfalse;
if( multiPtr )
{
- if( Rect_ContainsPoint( &item->window.rect, DC->cursorx, DC->cursory ) &&
- item->window.flags & WINDOW_HASFOCUS && item->cvar )
+ if( item->window.flags & WINDOW_HASFOCUS && item->cvar && max > 0 )
{
- if( key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3 )
- {
- int current = Item_Multi_FindCvarByValue( item ) + 1;
- int max = Item_Multi_CountSettings( item );
+ int current;
- if( current < 0 || current >= max )
- current = 0;
+ if( ( mouseOver && key == K_MOUSE1 ) ||
+ key == K_ENTER || key == K_RIGHTARROW || key == K_DOWNARROW )
+ {
+ current = ( Item_Multi_FindCvarByValue( item ) + 1 ) % max;
+ changed = qtrue;
+ }
+ else if( ( mouseOver && key == K_MOUSE2 ) ||
+ key == K_LEFTARROW || key == K_UPARROW )
+ {
+ current = ( Item_Multi_FindCvarByValue( item ) + max - 1 ) % max;
+ changed = qtrue;
+ }
+ if( changed )
+ {
if( multiPtr->strDef )
DC->setCVar( item->cvar, multiPtr->cvarStr[current] );
else
@@ -3820,7 +3867,7 @@ qboolean Item_HandleKey( itemDef_t *item, int key, qboolean down )
break;
case ITEM_TYPE_COMBO:
- return qfalse;
+ return Item_Combobox_HandleKey( item, key );
break;
case ITEM_TYPE_LISTBOX:
@@ -4003,6 +4050,12 @@ void Menus_Activate( menuDef_t *menu )
listPtr->startPos = 0;
DC->feederSelection( menu->items[ i ]->special, 0 );
}
+ else if( menu->items[ i ]->type == ITEM_TYPE_COMBO )
+ {
+ comboBoxDef_t *comboPtr = (comboBoxDef_t *)menu->items[ i ]->typeData;
+
+ comboPtr->cursorPos = DC->feederInitialise( menu->items[ i ]->special );
+ }
}
@@ -4958,6 +5011,31 @@ void Item_Multi_Paint( itemDef_t *item )
UI_Text_Paint( item->textRect.x, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle );
}
+void Item_Combobox_Paint( itemDef_t *item )
+{
+ vec4_t newColor;
+ const char *text = "";
+ menuDef_t *parent = (menuDef_t *)item->parent;
+ comboBoxDef_t *comboPtr = (comboBoxDef_t *)item->typeData;
+
+ if( item->window.flags & WINDOW_HASFOCUS )
+ memcpy( newColor, &parent->focusColor, sizeof( vec4_t ) );
+ else
+ memcpy( &newColor, &item->window.foreColor, sizeof( vec4_t ) );
+
+ if( comboPtr )
+ text = DC->feederItemText( item->special, comboPtr->cursorPos, 0, NULL );
+
+ if( item->text )
+ {
+ Item_Text_Paint( item );
+ UI_Text_Paint( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y,
+ item->textscale, newColor, text, 0, 0, item->textStyle );
+ }
+ else
+ UI_Text_Paint( item->textRect.x, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle );
+}
+
typedef struct
{
@@ -6064,6 +6142,7 @@ void Item_Paint( itemDef_t *item )
break;
case ITEM_TYPE_COMBO:
+ Item_Combobox_Paint( item );
break;
case ITEM_TYPE_LISTBOX:
@@ -6379,6 +6458,11 @@ void Item_ValidateTypeData( itemDef_t *item )
item->typeData = UI_Alloc( sizeof( listBoxDef_t ) );
memset( item->typeData, 0, sizeof( listBoxDef_t ) );
}
+ else if( item->type == ITEM_TYPE_COMBO )
+ {
+ item->typeData = UI_Alloc( sizeof( comboBoxDef_t ) );
+ memset( item->typeData, 0, sizeof( comboBoxDef_t ) );
+ }
else if( item->type == ITEM_TYPE_EDITFIELD ||
item->type == ITEM_TYPE_NUMERICFIELD ||
item->type == ITEM_TYPE_YESNO ||
diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h
index bbf09234..36d77bf8 100644
--- a/src/ui/ui_shared.h
+++ b/src/ui/ui_shared.h
@@ -203,9 +203,14 @@ typedef struct listBoxDef_s
qboolean notselectable;
qboolean noscrollbar;
}
-
listBoxDef_t;
+typedef struct comboBoxDef_s
+{
+ int cursorPos;
+}
+comboBoxDef_t;
+
typedef struct editFieldDef_s
{
float minVal; // edit field limits
@@ -380,6 +385,7 @@ typedef struct
const char *( *feederItemText )( float feederID, int index, int column, qhandle_t *handle );
qhandle_t ( *feederItemImage )( float feederID, int index );
void ( *feederSelection )( float feederID, int index );
+ int ( *feederInitialise )( float feederID );
void ( *keynumToStringBuf )( int keynum, char *buf, int buflen );
void ( *getBindingBuf )( int keynum, char *buf, int buflen );
void ( *setBinding )( int keynum, const char *binding );