- Fixed menu in widescreen.

- Cleaned up some code and merged more to ioq3.
- Allow cursor to move to edge of screen in wide screen (copied from Turtle Arena).
This commit is contained in:
zturtleman 2011-02-18 21:46:14 +00:00
parent dcdc537bfa
commit 8ccf97ae15
3 changed files with 242 additions and 126 deletions

View file

@ -492,7 +492,7 @@ UI_DrawBannerString
static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
{
const char* s;
char ch;
unsigned char ch;
float ax;
float ay;
float aw;
@ -505,22 +505,15 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
// draw the colored text
trap_R_SetColor( color );
// STONELANCE
// ax = x * uis.scale + uis.bias;
// ay = y * uis.scale;
ax = x * uis.screenXScale + uis.bias;
ay = y * uis.screenYScale;
// END
ax = x * uis.xscale + uis.bias;
ay = y * uis.yscale;
s = str;
while ( *s )
{
ch = *s & 127;
if ( ch == ' ' ) {
// STONELANCE
// ax += ((float)PROPB_SPACE_WIDTH + (float)PROPB_GAP_WIDTH)* uis.scale;
ax += ((float)PROPB_SPACE_WIDTH + (float)PROPB_GAP_WIDTH)* uis.screenXScale;
// END
ax += ((float)PROPB_SPACE_WIDTH + (float)PROPB_GAP_WIDTH)* uis.xscale;
}
// STONELANCE
// else if ( ch >= 'A' && ch <= 'Z' ) {
@ -528,8 +521,7 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
else if ( ch >= 'A' && ch <= 'Z' || ch == '3') {
if ( ch == '3' ) {
ch = 26;
}
else {
} else {
ch -= 'A';
}
// END
@ -537,17 +529,10 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
frow = (float)propMapB[ch][1] / 256.0f;
fwidth = (float)propMapB[ch][2] / 256.0f;
fheight = (float)PROPB_HEIGHT / 256.0f;
// STONELANCE
// aw = (float)propMapB[ch][2] * uis.scale;
// ah = (float)PROPB_HEIGHT * uis.scale;
aw = (float)propMapB[ch][2] * uis.screenXScale;
ah = (float)PROPB_HEIGHT * uis.screenYScale;
// END
aw = (float)propMapB[ch][2] * uis.xscale;
ah = (float)PROPB_HEIGHT * uis.yscale;
trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol+fwidth, frow+fheight, uis.charsetPropB );
// STONELANCE
// ax += (aw + (float)PROPB_GAP_WIDTH * uis.scale);
ax += (aw + (float)PROPB_GAP_WIDTH * uis.screenXScale);
// END
ax += (aw + (float)PROPB_GAP_WIDTH * uis.xscale);
}
s++;
}
@ -625,10 +610,10 @@ int UI_ProportionalStringWidth( const char* str ) {
static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t color, float sizeScale, qhandle_t charset )
{
const char* s;
char ch;
unsigned char ch;
float ax;
float ay;
float aw;
float aw = 0;
float ah;
float frow;
float fcol;
@ -638,41 +623,27 @@ static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t co
// draw the colored text
trap_R_SetColor( color );
// STONELANCE
// ax = x * uis.scale + uis.bias;
// ay = y * uis.scale;
ax = x * uis.screenXScale + uis.bias;
ay = y * uis.screenYScale;
// END
ax = x * uis.xscale + uis.bias;
ay = y * uis.yscale;
s = str;
while ( *s )
{
ch = *s & 127;
if ( ch == ' ' ) {
// STONELANCE
// aw = (float)PROP_SPACE_WIDTH * uis.scale * sizeScale;
aw = (float)PROP_SPACE_WIDTH * uis.screenXScale * sizeScale;
// END
aw = (float)PROP_SPACE_WIDTH * uis.xscale * sizeScale;
}
else if ( propMap[ch][2] != -1 ) {
fcol = (float)propMap[ch][0] / 256.0f;
frow = (float)propMap[ch][1] / 256.0f;
fwidth = (float)propMap[ch][2] / 256.0f;
fheight = (float)PROP_HEIGHT / 256.0f;
// STONELANCE
// aw = (float)propMap[ch][2] * uis.scale * sizeScale;
// ah = (float)PROP_HEIGHT * uis.scale * sizeScale;
aw = (float)propMap[ch][2] * uis.screenXScale * sizeScale;
ah = (float)PROP_HEIGHT * uis.screenYScale * sizeScale;
// END
aw = (float)propMap[ch][2] * uis.xscale * sizeScale;
ah = (float)PROP_HEIGHT * uis.yscale * sizeScale;
trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol+fwidth, frow+fheight, charset );
}
// STONELANCE
// ax += (aw + (float)PROP_GAP_WIDTH * uis.scale * sizeScale);
ax += (aw + (float)PROP_GAP_WIDTH * uis.screenXScale * sizeScale);
// END
ax += (aw + (float)PROP_GAP_WIDTH * uis.xscale * sizeScale);
s++;
}
@ -764,6 +735,70 @@ void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t
UI_DrawProportionalString2( x, y, str, color, sizeScale, uis.charsetProp );
}
/*
=================
UI_DrawProportionalString_Wrapped
=================
*/
void UI_DrawProportionalString_AutoWrapped( int x, int y, int xmax, int ystep, const char* str, int style, vec4_t color ) {
int width;
char *s1,*s2,*s3;
char c_bcp;
char buf[1024];
float sizeScale;
if (!str || str[0]=='\0')
return;
sizeScale = UI_ProportionalSizeScale( style );
Q_strncpyz(buf, str, sizeof(buf));
s1 = s2 = s3 = buf;
while (1) {
do {
s3++;
} while (*s3!=' ' && *s3!='\0');
c_bcp = *s3;
*s3 = '\0';
width = UI_ProportionalStringWidth(s1) * sizeScale;
*s3 = c_bcp;
if (width > xmax) {
if (s1==s2)
{
// fuck, don't have a clean cut, we'll overflow
s2 = s3;
}
*s2 = '\0';
UI_DrawProportionalString(x, y, s1, style, color);
y += ystep;
if (c_bcp == '\0')
{
// that was the last word
// we could start a new loop, but that wouldn't be much use
// even if the word is too long, we would overflow it (see above)
// so just print it now if needed
s2++;
if (*s2 != '\0') // if we are printing an overflowing line we have s2 == s3
UI_DrawProportionalString(x, y, s2, style, color);
break;
}
s2++;
s1 = s2;
s3 = s2;
}
else
{
s2 = s3;
if (c_bcp == '\0') // we reached the end
{
UI_DrawProportionalString(x, y, s1, style, color);
break;
}
}
}
}
/*
=================
UI_DrawString2
@ -792,18 +827,10 @@ static void UI_DrawString2( int x, int y, const char* str, vec4_t color, int cha
// STONELANCE - move font closer together
x -= 1;
// END
// STONELANCE
/*
ax = x * uis.scale + uis.bias;
ay = y * uis.scale;
aw = charw * uis.scale;
ah = charh * uis.scale;
*/
ax = x * uis.screenXScale + uis.bias;
ay = y * uis.screenYScale;
aw = charw * uis.screenXScale;
ah = charh * uis.screenYScale;
// END
ax = x * uis.xscale + uis.bias;
ay = y * uis.yscale;
aw = charw * uis.xscale;
ah = charh * uis.yscale;
s = str;
while ( *s )
@ -830,7 +857,7 @@ static void UI_DrawString2( int x, int y, const char* str, vec4_t color, int cha
// STONELANCE - move font closer together
// ax += aw;
ax += aw - 2 * uis.screenXScale;
ax += aw - 2 * uis.xscale;
// END
s++;
}
@ -963,7 +990,6 @@ static void NeedCDKeyAction( qboolean result ) {
}
}
void UI_SetActiveMenu( uiMenuCommand_t menu ) {
// this should be the ONLY way the menu system is brought up
// enusure minumum menu data is cached
@ -980,10 +1006,10 @@ void UI_SetActiveMenu( uiMenuCommand_t menu ) {
// END
return;
case UIMENU_NEED_CD:
UI_ConfirmMenu( "Insert the CD", NULL, NeedCDAction );
UI_ConfirmMenu( "Insert the CD", 0, NeedCDAction );
return;
case UIMENU_BAD_CD_KEY:
UI_ConfirmMenu( "Bad CD Key", NULL, NeedCDKeyAction );
UI_ConfirmMenu( "Bad CD Key", 0, NeedCDKeyAction );
return;
case UIMENU_INGAME:
/*
@ -994,6 +1020,14 @@ void UI_SetActiveMenu( uiMenuCommand_t menu ) {
trap_Cvar_Set( "cl_paused", "1" );
UI_InGameMenu();
return;
case UIMENU_TEAM:
case UIMENU_POSTGAME:
default:
#ifndef NDEBUG
Com_Printf("UI_SetActiveMenu: bad enum %d\n", menu );
#endif
break;
}
}
@ -1047,10 +1081,16 @@ void UI_MouseEvent( int dx, int dy )
// END
uis.cursorx += dx;
if (uis.cursorx < 0)
uis.cursorx = 0;
else if (uis.cursorx > SCREEN_WIDTH)
uis.cursorx = SCREEN_WIDTH;
// ZTM: Allow cursor to move to edge of screen in wide screen
if (uis.cursorx < -uis.bias)
uis.cursorx = -uis.bias;
else if (uis.cursorx > SCREEN_WIDTH+uis.bias)
uis.cursorx = SCREEN_WIDTH+uis.bias;
// if (uis.cursorx < 0)
// uis.cursorx = 0;
// else if (uis.cursorx > SCREEN_WIDTH)
// uis.cursorx = SCREEN_WIDTH;
// END
uis.cursory += dy;
if (uis.cursory < 0)
@ -1155,6 +1195,7 @@ void UI_Cache_f( void ) {
UI_BotSelectMenu_Cache();
UI_CDKeyMenu_Cache();
UI_ModsMenu_Cache();
}
@ -1240,19 +1281,16 @@ void UI_Init( void ) {
UI_InitGameinfo();
// cache redundant calulations
trap_GetGlconfig( &uis.glconfig );
// for 640x480 virtualized screen
// STONELANCE
// uis.scale = uis.glconfig.vidHeight * (1.0/480.0);
uis.screenXScale = uis.glconfig.vidWidth * (1.0/640.0);
uis.screenYScale = uis.glconfig.vidHeight * (1.0/480.0);
// END
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 ) {
// wide screen
uis.bias = 0.5 * ( uis.glconfig.vidWidth - ( uis.glconfig.vidHeight * (640.0/480.0) ) );
uis.xscale = uis.yscale;
}
else {
// no wide screen
@ -1303,7 +1341,6 @@ void UI_Init( void ) {
// initialize the menu system
Menu_Cache();
uis.activemenu = NULL;
uis.menusp = 0;
}
@ -1317,18 +1354,10 @@ Adjusted for resolution and screen aspect ratio
*/
void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) {
// expect valid pointers
// STONELANCE
/*
*x = *x * uis.scale + uis.bias;
*y *= uis.scale;
*w *= uis.scale;
*h *= uis.scale;
*/
*x = *x * uis.screenXScale + uis.bias;
*y *= uis.screenYScale;
*w *= uis.screenXScale;
*h *= uis.screenYScale;
// END
*x = *x * uis.xscale + uis.bias;
*y *= uis.yscale;
*w *= uis.xscale;
*h *= uis.yscale;
}
void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname ) {
@ -1546,9 +1575,8 @@ void UI_Refresh( int realtime )
uis.firstdraw = qfalse;
}
}
//=================
// draw cursor
//=================
// UI_SetColor( NULL );
// UI_DrawCursor( uis.cursorx-24, uis.cursory-24, 48, 48, uis.cursorModel );
@ -1561,8 +1589,6 @@ UI_DrawHandlePic( uis.cursorx-16, uis.cursory-16, 32, 32, uis.cursor);
// UI_DrawHandlePic( uis.cursorx-16, uis.cursory-16, 32, 32, uis.cursor);
// }
#ifndef NDEBUG
if (uis.debug)
{

View file

@ -49,6 +49,9 @@ typedef struct {
const char * question;
void (*draw)( void );
void (*action)( qboolean result );
int style;
const char **lines;
} confirmMenu_t;
@ -111,6 +114,30 @@ static sfxHandle_t ConfirmMenu_Key( int key ) {
}
/*
=================
MessaheMenu_Draw
=================
*/
static void MessageMenu_Draw( void ) {
int i,y;
UI_DrawNamedPic( 142, 118, 359, 256, ART_CONFIRM_FRAME );
y = 188;
for(i=0; s_confirm.lines[i]; i++)
{
UI_DrawProportionalString( 320, y, s_confirm.lines[i], s_confirm.style, color_red );
y += 18;
}
Menu_Draw( &s_confirm.menu );
if( s_confirm.draw ) {
s_confirm.draw();
}
}
/*
=================
ConfirmMenu_Draw
@ -120,9 +147,9 @@ static void ConfirmMenu_Draw( void ) {
UI_DrawNamedPic( 142, 118, 359, 256, ART_CONFIRM_FRAME );
// BAGPUSS CHANGED TO TEXT_COLOR_NORMAL
// UI_DrawProportionalString( 320, 204, s_confirm.question, UI_CENTER|UI_INVERSE, color_red );
// UI_DrawProportionalString( 320, 204, s_confirm.question, s_confirm.style, color_red );
// UI_DrawProportionalString( s_confirm.slashX, 265, "/", UI_LEFT|UI_INVERSE, color_red );
UI_DrawProportionalString( 320, 204, s_confirm.question, UI_CENTER|UI_INVERSE, text_color_normal );
UI_DrawProportionalString( 320, 204, s_confirm.question, s_confirm.style, text_color_normal );
UI_DrawProportionalString( s_confirm.slashX, 265, "/", UI_LEFT|UI_INVERSE, text_color_normal );
// END
@ -146,10 +173,10 @@ void ConfirmMenu_Cache( void ) {
/*
=================
UI_ConfirmMenu
UI_ConfirmMenu_Stlye
=================
*/
void UI_ConfirmMenu( const char *question, void (*draw)( void ), void (*action)( qboolean result ) ) {
void UI_ConfirmMenu_Style( const char *question, int style, void (*draw)( void ), void (*action)( qboolean result ) ) {
uiClientState_t cstate;
int n1, n2, n3;
int l1, l2, l3;
@ -170,6 +197,7 @@ void UI_ConfirmMenu( const char *question, void (*draw)( void ), void (*action)(
s_confirm.question = question;
s_confirm.draw = draw;
s_confirm.action = action;
s_confirm.style = style;
s_confirm.menu.draw = ConfirmMenu_Draw;
s_confirm.menu.key = ConfirmMenu_Key;
@ -219,3 +247,62 @@ void UI_ConfirmMenu( const char *question, void (*draw)( void ), void (*action)(
Menu_SetCursorToItem( &s_confirm.menu, &s_confirm.no );
}
/*
=================
UI_ConfirmMenu
=================
*/
void UI_ConfirmMenu( const char *question, void (*draw)( void ), void (*action)( qboolean result ) ) {
UI_ConfirmMenu_Style(question, UI_CENTER|UI_INVERSE, draw, action);
}
/*
=================
UI_Message
hacked over from Confirm stuff
=================
*/
void UI_Message( const char **lines ) {
uiClientState_t cstate;
int n1, l1;
// zero set all our globals
memset( &s_confirm, 0, sizeof(s_confirm) );
ConfirmMenu_Cache();
n1 = UI_ProportionalStringWidth( "OK" );
l1 = 320 - ( n1 / 2 );
s_confirm.lines = lines;
s_confirm.style = UI_CENTER|UI_INVERSE|UI_SMALLFONT;
s_confirm.menu.draw = MessageMenu_Draw;
s_confirm.menu.key = ConfirmMenu_Key;
s_confirm.menu.wrapAround = qtrue;
trap_GetClientState( &cstate );
if ( cstate.connState >= CA_CONNECTED ) {
s_confirm.menu.fullscreen = qfalse;
}
else {
s_confirm.menu.fullscreen = qtrue;
}
s_confirm.yes.generic.type = MTYPE_PTEXT;
s_confirm.yes.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
s_confirm.yes.generic.callback = ConfirmMenu_Event;
s_confirm.yes.generic.id = ID_CONFIRM_YES;
s_confirm.yes.generic.x = l1;
s_confirm.yes.generic.y = 280;
s_confirm.yes.string = "OK";
s_confirm.yes.color = color_red;
s_confirm.yes.style = UI_LEFT;
Menu_AddItem( &s_confirm.menu, &s_confirm.yes );
UI_PushMenu( &s_confirm.menu );
Menu_SetCursorToItem( &s_confirm.menu, &s_confirm.yes );
}

View file

@ -126,6 +126,7 @@ extern vmCvar_t ui_server16;
extern vmCvar_t ui_cdkey;
extern vmCvar_t ui_cdkeychecked;
extern vmCvar_t ui_ioq3;
// STONELANCE
extern vmCvar_t ui_favoritecar1;
@ -190,29 +191,29 @@ extern vmCvar_t ui_mainViewRenderLevel;
#define SB_HIDE 16
// END
#define QMF_BLINK 0x00000001
#define QMF_SMALLFONT 0x00000002
#define QMF_LEFT_JUSTIFY 0x00000004
#define QMF_CENTER_JUSTIFY 0x00000008
#define QMF_RIGHT_JUSTIFY 0x00000010
#define QMF_NUMBERSONLY 0x00000020 // edit field is only numbers
#define QMF_HIGHLIGHT 0x00000040
#define QMF_HIGHLIGHT_IF_FOCUS 0x00000080 // steady focus
#define QMF_PULSEIFFOCUS 0x00000100 // pulse if focus
#define QMF_HASMOUSEFOCUS 0x00000200
#define QMF_NOONOFFTEXT 0x00000400
#define QMF_MOUSEONLY 0x00000800 // only mouse input allowed
#define QMF_HIDDEN 0x00001000 // skips drawing
#define QMF_GRAYED 0x00002000 // grays and disables
#define QMF_INACTIVE 0x00004000 // disables any input
#define QMF_NODEFAULTINIT 0x00008000 // skip default initialization
#define QMF_OWNERDRAW 0x00010000
#define QMF_PULSE 0x00020000
#define QMF_LOWERCASE 0x00040000 // edit field is all lower case
#define QMF_UPPERCASE 0x00080000 // edit field is all upper case
#define QMF_SILENT 0x00100000
#define QMF_BLINK ((unsigned int) 0x00000001)
#define QMF_SMALLFONT ((unsigned int) 0x00000002)
#define QMF_LEFT_JUSTIFY ((unsigned int) 0x00000004)
#define QMF_CENTER_JUSTIFY ((unsigned int) 0x00000008)
#define QMF_RIGHT_JUSTIFY ((unsigned int) 0x00000010)
#define QMF_NUMBERSONLY ((unsigned int) 0x00000020) // edit field is only numbers
#define QMF_HIGHLIGHT ((unsigned int) 0x00000040)
#define QMF_HIGHLIGHT_IF_FOCUS ((unsigned int) 0x00000080) // steady focus
#define QMF_PULSEIFFOCUS ((unsigned int) 0x00000100) // pulse if focus
#define QMF_HASMOUSEFOCUS ((unsigned int) 0x00000200)
#define QMF_NOONOFFTEXT ((unsigned int) 0x00000400)
#define QMF_MOUSEONLY ((unsigned int) 0x00000800) // only mouse input allowed
#define QMF_HIDDEN ((unsigned int) 0x00001000) // skips drawing
#define QMF_GRAYED ((unsigned int) 0x00002000) // grays and disables
#define QMF_INACTIVE ((unsigned int) 0x00004000) // disables any input
#define QMF_NODEFAULTINIT ((unsigned int) 0x00008000) // skip default initialization
#define QMF_OWNERDRAW ((unsigned int) 0x00010000)
#define QMF_PULSE ((unsigned int) 0x00020000)
#define QMF_LOWERCASE ((unsigned int) 0x00040000) // edit field is all lower case
#define QMF_UPPERCASE ((unsigned int) 0x00080000) // edit field is all upper case
#define QMF_SILENT ((unsigned int) 0x00100000)
// STONELANCE
#define QMF_SCROLL_ONLY 0x00200000
#define QMF_SCROLL_ONLY ((unsigned int) 0x00200000)
// END
// callback notifications
@ -256,7 +257,7 @@ typedef struct
int bottom;
menuframework_s *parent;
int menuPosition;
unsigned flags;
unsigned int flags;
void (*callback)( void *self, int event );
void (*statusbar)( void *self );
@ -460,6 +461,8 @@ extern void UI_InGameMenu(void);
//
extern void ConfirmMenu_Cache( void );
extern void UI_ConfirmMenu( const char *question, void (*draw)( void ), void (*action)( qboolean result ) );
extern void UI_ConfirmMenu_Style( const char *question, int style, void (*draw)( void ), void (*action)( qboolean result ) );
extern void UI_Message( const char **lines );
//
// ui_setup.c
@ -725,10 +728,9 @@ typedef struct {
qhandle_t sb_u1;
qhandle_t sb_d0;
qhandle_t sb_d1;
// float scale;
float screenXScale;
float screenYScale;
// END
float xscale;
float yscale;
float bias;
qboolean demoversion;
qboolean firstdraw;
@ -780,6 +782,7 @@ extern void UI_LerpColor(vec4_t a, vec4_t b, vec4_t c, float t);
extern void UI_DrawBannerString( int x, int y, const char* str, int style, vec4_t color );
extern float UI_ProportionalSizeScale( int style );
extern void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color );
extern void UI_DrawProportionalString_AutoWrapped( int x, int ystart, int xmax, int ystep, const char* str, int style, vec4_t color );
extern int UI_ProportionalStringWidth( const char* str );
extern void UI_DrawString( int x, int y, const char* str, int style, vec4_t color );
extern void UI_DrawChar( int x, int y, int ch, int style, vec4_t color );
@ -846,6 +849,7 @@ void trap_FS_Read( void *buffer, int len, fileHandle_t f );
void trap_FS_Write( const void *buffer, int len, fileHandle_t f );
void trap_FS_FCloseFile( fileHandle_t f );
int trap_FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
int trap_FS_Seek( fileHandle_t f, long offset, int origin ); // fsOrigin_t
qhandle_t trap_R_RegisterModel( const char *name );
qhandle_t trap_R_RegisterSkin( const char *name );
qhandle_t trap_R_RegisterShaderNoMip( const char *name );
@ -877,7 +881,7 @@ int trap_LAN_GetServerCount( int source );
void trap_LAN_GetServerAddressString( int source, int n, char *buf, int buflen );
void trap_LAN_GetServerInfo( int source, int n, char *buf, int buflen );
int trap_LAN_GetPingQueueCount( void );
int trap_LAN_ServerStatus( char *serverAddress, char *serverStatus, int maxLen );
int trap_LAN_ServerStatus( const char *serverAddress, char *serverStatus, int maxLen );
void trap_LAN_ClearPing( int n );
void trap_LAN_GetPing( int n, char *buf, int buflen, int *pingtime );
void trap_LAN_GetPingInfo( int n, char *buf, int buflen );
@ -1031,4 +1035,3 @@ void RankStatus_Cache( void );
void UI_RankStatusMenu( void );
#endif