diff options
author | Tim Angus <tim@ngus.net> | 2007-11-08 00:05:14 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2007-11-08 00:05:14 +0000 |
commit | 74c8d33a2b830a47c31272bcf16cbbfd404ce0e8 (patch) | |
tree | e57fc261700a619fbf9a09a589706a5165653221 /src | |
parent | c6a9027b7cf0d35401cae346b67ca95c5f55b4a1 (diff) |
* Merge and move text paint functions into ui_shared.c
* Add aspectBias to indicate alignment on non-4:3 video modes
* Add "reset <item>" script command to reset an item
* Compensate for aspect ratio in lots and lots and lots of places
* Release edit field focus when tabbing away
* Fix infinite loop bug in text wrapping code when rect is very narrow
* Mung .menu scripts to line things up correctly on non-4:3 ratios
Diffstat (limited to 'src')
-rw-r--r-- | src/cgame/cg_draw.c | 445 | ||||
-rw-r--r-- | src/cgame/cg_local.h | 6 | ||||
-rw-r--r-- | src/cgame/cg_main.c | 25 | ||||
-rw-r--r-- | src/cgame/cg_scanner.c | 8 | ||||
-rw-r--r-- | src/cgame/cg_weapons.c | 37 | ||||
-rw-r--r-- | src/sys/win_resource.rc | 5 | ||||
-rw-r--r-- | src/ui/ui_atoms.c | 23 | ||||
-rw-r--r-- | src/ui/ui_main.c | 449 | ||||
-rw-r--r-- | src/ui/ui_shared.c | 853 | ||||
-rw-r--r-- | src/ui/ui_shared.h | 35 |
10 files changed, 884 insertions, 1002 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index ec50146e..56d25c9c 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -28,8 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "cg_local.h" #include "../ui/ui_shared.h" -// used for scoreboard -extern displayContextDef_t cgDC; menuDef_t *menuScoreboard = NULL; int drawTeamOverlayModificationCount = -1; @@ -37,107 +35,6 @@ int drawTeamOverlayModificationCount = -1; int sortedTeamPlayers[ TEAM_MAXOVERLAY ]; int numSortedTeamPlayers; -//TA UI -float CG_Text_Width( const char *text, float scale, int limit ) -{ - int count,len; - float out; - glyphInfo_t *glyph; - float useScale; - const char *s = text; - fontInfo_t *font = &cgDC.Assets.textFont; - - if( scale <= cg_smallFont.value ) - font = &cgDC.Assets.smallFont; - else if( scale > cg_bigFont.value ) - font = &cgDC.Assets.bigFont; - - useScale = scale * font->glyphScale; - out = 0; - - if( text ) - { - len = strlen( text ); - if( limit > 0 && len > limit ) - len = limit; - - count = 0; - while( s && *s && count < len ) - { - if( Q_IsColorString( s ) ) - { - s += 2; - continue; - } - else - { - glyph = &font->glyphs[ (int)*s ]; - out += glyph->xSkip; - s++; - count++; - } - } - } - - return out * useScale; -} - -float CG_Text_Height( const char *text, float scale, int limit ) -{ - int len, count; - float max; - glyphInfo_t *glyph; - float useScale; - const char *s = text; - fontInfo_t *font = &cgDC.Assets.textFont; - - if( scale <= cg_smallFont.value ) - font = &cgDC.Assets.smallFont; - else if( scale > cg_bigFont.value ) - font = &cgDC.Assets.bigFont; - - useScale = scale * font->glyphScale; - max = 0; - - if( text ) - { - len = strlen( text ); - if( limit > 0 && len > limit ) - len = limit; - - count = 0; - while( s && *s && count < len ) - { - if( Q_IsColorString( s ) ) - { - s += 2; - continue; - } - else - { - glyph = &font->glyphs[ (int)*s ]; - if( max < glyph->height ) - max = glyph->height; - - s++; - count++; - } - } - } - - return max * useScale; -} - -float CG_Text_EmWidth( float scale ) -{ - return CG_Text_Width( "M", scale, 0 ); -} - -float CG_Text_EmHeight( float scale ) -{ - return CG_Text_Height( "M", scale, 0 ); -} - static void CG_AlignText( rectDef_t *rect, const char *text, float scale, float w, float h, int align, int valign, @@ -147,22 +44,22 @@ static void CG_AlignText( rectDef_t *rect, const char *text, float scale, if( scale > 0.0f ) { - w = CG_Text_Width( text, scale, 0 ); - h = CG_Text_Height( text, scale, 0 ); + w = UI_Text_Width( text, scale, 0 ); + h = UI_Text_Height( text, scale, 0 ); } switch( align ) { default: - case ITEM_ALIGN_LEFT: + case ALIGN_LEFT: tx = 0.0f; break; - case ITEM_ALIGN_RIGHT: + case ALIGN_RIGHT: tx = rect->w - w; break; - case ITEM_ALIGN_CENTER: + case ALIGN_CENTER: tx = ( rect->w - w ) / 2.0f; break; } @@ -170,15 +67,15 @@ static void CG_AlignText( rectDef_t *rect, const char *text, float scale, switch( valign ) { default: - case ITEM_VALIGN_BOTTOM: + case VALIGN_BOTTOM: ty = rect->h; break; - case ITEM_VALIGN_TOP: + case VALIGN_TOP: ty = h; break; - case ITEM_VALIGN_CENTER: + case VALIGN_CENTER: ty = h + ( ( rect->h - h ) / 2.0f ); break; } @@ -190,156 +87,6 @@ static void CG_AlignText( rectDef_t *rect, const char *text, float scale, *y = rect->y + ty; } -void CG_Text_PaintChar( float x, float y, float width, float height, float scale, - float s, float t, float s2, float t2, qhandle_t hShader ) -{ - float w, h; - w = width * scale; - h = height * scale; - CG_AdjustFrom640( &x, &y, &w, &h ); - trap_R_DrawStretchPic( x, y, w, h, s, t, s2, t2, hShader ); -} - -void CG_Text_Paint( float x, float y, float scale, vec4_t color, const char *text, - float adjust, int limit, int style ) -{ - int len, count; - vec4_t newColor; - glyphInfo_t *glyph; - float useScale; - fontInfo_t *font = &cgDC.Assets.textFont; - - if( scale <= cg_smallFont.value ) - font = &cgDC.Assets.smallFont; - else if( scale > cg_bigFont.value ) - font = &cgDC.Assets.bigFont; - - useScale = scale * font->glyphScale; - if( text ) - { - - const char *s = text; - - trap_R_SetColor( color ); - memcpy( &newColor[ 0 ], &color[ 0 ], sizeof( vec4_t ) ); - len = strlen( text ); - - if( limit > 0 && len > limit ) - len = limit; - - count = 0; - while( s && *s && count < len ) - { - glyph = &font->glyphs[ (int)*s ]; - - if( Q_IsColorString( s ) ) - { - memcpy( newColor, g_color_table[ ColorIndex( *( s + 1 ) ) ], sizeof( newColor ) ); - newColor[ 3 ] = color[ 3 ]; - trap_R_SetColor( newColor ); - s += 2; - continue; - } - else - { - float yadj = useScale * glyph->top; - if( style == ITEM_TEXTSTYLE_SHADOWED || - style == ITEM_TEXTSTYLE_SHADOWEDMORE ) - { - int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; - colorBlack[ 3 ] = newColor[ 3 ]; - trap_R_SetColor( colorBlack ); - CG_Text_PaintChar( x + ofs, y - yadj + ofs, - glyph->imageWidth, - glyph->imageHeight, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - colorBlack[ 3 ] = 1.0; - trap_R_SetColor( newColor ); - } - else if( style == ITEM_TEXTSTYLE_NEON ) - { - vec4_t glow, outer, inner, white; - - glow[ 0 ] = newColor[ 0 ] * 0.5; - glow[ 1 ] = newColor[ 1 ] * 0.5; - glow[ 2 ] = newColor[ 2 ] * 0.5; - glow[ 3 ] = newColor[ 3 ] * 0.2; - - outer[ 0 ] = newColor[ 0 ]; - outer[ 1 ] = newColor[ 1 ]; - outer[ 2 ] = newColor[ 2 ]; - outer[ 3 ] = newColor[ 3 ]; - - inner[ 0 ] = newColor[ 0 ] * 1.5 > 1.0f ? 1.0f : newColor[ 0 ] * 1.5; - inner[ 1 ] = newColor[ 1 ] * 1.5 > 1.0f ? 1.0f : newColor[ 1 ] * 1.5; - inner[ 2 ] = newColor[ 2 ] * 1.5 > 1.0f ? 1.0f : newColor[ 2 ] * 1.5; - inner[ 3 ] = newColor[ 3 ]; - - white[ 0 ] = white[ 1 ] = white[ 2 ] = white[ 3 ] = 1.0f; - - trap_R_SetColor( glow ); - CG_Text_PaintChar( x - 3, y - yadj - 3, - glyph->imageWidth + 6, - glyph->imageHeight + 6, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( outer ); - CG_Text_PaintChar( x - 1, y - yadj - 1, - glyph->imageWidth + 2, - glyph->imageHeight + 2, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( inner ); - CG_Text_PaintChar( x - 0.5, y - yadj - 0.5, - glyph->imageWidth + 1, - glyph->imageHeight + 1, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( white ); - } - - - CG_Text_PaintChar( x, y - yadj, - glyph->imageWidth, - glyph->imageHeight, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - x += ( glyph->xSkip * useScale ) + adjust; - s++; - count++; - } - } - - trap_R_SetColor( NULL ); - } -} - /* ============== CG_DrawFieldPadded @@ -358,7 +105,7 @@ static void CG_DrawFieldPadded( int x, int y, int width, int cw, int ch, int val charWidth = CHAR_WIDTH; if( !( charHeight = ch ) ) - charWidth = CHAR_HEIGHT; + charHeight = CHAR_HEIGHT; if( width < 1 ) return; @@ -395,7 +142,7 @@ static void CG_DrawFieldPadded( int x, int y, int width, int cw, int ch, int val orgL = l; - x += 2; + x += ( 2.0f * cgDC.aspectScale ); ptr = num; while( *ptr && l ) @@ -438,7 +185,7 @@ void CG_DrawField( float x, float y, int width, float cw, float ch, int value ) charWidth = CHAR_WIDTH; if( !( charHeight = ch ) ) - charWidth = CHAR_HEIGHT; + charHeight = CHAR_HEIGHT; if( width < 1 ) return; @@ -473,7 +220,7 @@ void CG_DrawField( float x, float y, int width, float cw, float ch, int value ) if( l > width ) l = width; - x += 2 + charWidth * ( width - l ); + x += ( 2.0f * cgDC.aspectScale ) + charWidth * ( width - l ); ptr = num; while( *ptr && l ) @@ -516,7 +263,7 @@ static void CG_DrawProgressBar( rectDef_t *rect, vec4_t color, float scale, trap_R_SetColor( color ); //draw rim and bar - if( align == ITEM_ALIGN_RIGHT ) + if( align == ALIGN_RIGHT ) { CG_DrawPic( rect->x, rect->y, rimWidth, rect->h, cgs.media.whiteShader ); CG_DrawPic( rect->x + rimWidth, rect->y, @@ -542,9 +289,9 @@ static void CG_DrawProgressBar( rectDef_t *rect, vec4_t color, float scale, if( scale > 0.0 ) { Com_sprintf( textBuffer, sizeof( textBuffer ), "%d%%", (int)( progress * 100 ) ); - CG_AlignText( rect, textBuffer, scale, 0.0f, 0.0f, textalign, ITEM_VALIGN_CENTER, &tx, &ty ); + CG_AlignText( rect, textBuffer, scale, 0.0f, 0.0f, textalign, VALIGN_CENTER, &tx, &ty ); - CG_Text_Paint( tx, ty, scale, color, textBuffer, 0, 0, textStyle ); + UI_Text_Paint( tx, ty, scale, color, textBuffer, 0, 0, textStyle ); } } @@ -1172,10 +919,10 @@ static void CG_DrawProgressLabel( rectDef_t *rect, float text_x, float text_y, v CG_AlignText( rect, s, scale, 0.0f, 0.0f, textalign, textvalign, &tx, &ty ); if( fraction < 1.0f ) - CG_Text_Paint( text_x + tx, text_y + ty, scale, white, + UI_Text_Paint( text_x + tx, text_y + ty, scale, white, s, 0, 0, ITEM_TEXTSTYLE_NORMAL ); else - CG_Text_Paint( text_x + tx, text_y + ty, scale, color, + UI_Text_Paint( text_x + tx, text_y + ty, scale, color, s, 0, 0, ITEM_TEXTSTYLE_NEON ); } @@ -1392,82 +1139,12 @@ static void CG_DrawKiller( rectDef_t *rect, float scale, vec4_t color, if( cg.killerName[ 0 ] ) { int x = rect->x + rect->w / 2; - CG_Text_Paint( x - CG_Text_Width( CG_GetKillerText( ), scale, 0 ) / 2, + UI_Text_Paint( x - UI_Text_Width( CG_GetKillerText( ), scale, 0 ) / 2, rect->y + rect->h, scale, color, CG_GetKillerText( ), 0, 0, textStyle ); } } -static void CG_Text_Paint_Limit( float *maxX, float x, float y, float scale, - vec4_t color, const char* text, float adjust, int limit ) -{ - int len, count; - vec4_t newColor; - glyphInfo_t *glyph; - - if( text ) - { - const char *s = text; - float max = *maxX; - float useScale; - fontInfo_t *font = &cgDC.Assets.textFont; - - if( scale <= cg_smallFont.value ) - font = &cgDC.Assets.smallFont; - else if( scale > cg_bigFont.value ) - font = &cgDC.Assets.bigFont; - - useScale = scale * font->glyphScale; - trap_R_SetColor( color ); - len = strlen( text ); - - if( limit > 0 && len > limit ) - len = limit; - - count = 0; - - while( s && *s && count < len ) - { - glyph = &font->glyphs[ (int)*s ]; - - if( Q_IsColorString( s ) ) - { - memcpy( newColor, g_color_table[ ColorIndex( *(s+1) ) ], sizeof( newColor ) ); - newColor[ 3 ] = color[ 3 ]; - trap_R_SetColor( newColor ); - s += 2; - continue; - } - else - { - float yadj = useScale * glyph->top; - - if( CG_Text_Width( s, useScale, 1 ) + x > max ) - { - *maxX = 0; - break; - } - - CG_Text_PaintChar( x, y - yadj, - glyph->imageWidth, - glyph->imageHeight, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - x += ( glyph->xSkip * useScale ) + adjust; - *maxX = x; - count++; - s++; - } - } - - trap_R_SetColor( NULL ); - } -} - static void CG_DrawTeamSpectators( rectDef_t *rect, float scale, int textvalign, vec4_t color, qhandle_t shader ) { float y; @@ -1503,7 +1180,7 @@ static void CG_DrawTeamSpectators( rectDef_t *rect, float scale, int textvalign, cg.spectatorOffset += 2; else { - cg.spectatorPaintX += CG_Text_Width( &cg.spectatorList[ cg.spectatorOffset ], scale, 1 ) - 1; + cg.spectatorPaintX += UI_Text_Width( &cg.spectatorList[ cg.spectatorOffset ], scale, 1 ) - 1; cg.spectatorOffset++; } } @@ -1529,16 +1206,16 @@ static void CG_DrawTeamSpectators( rectDef_t *rect, float scale, int textvalign, } maxX = rect->x + rect->w - 2; - CG_AlignText( rect, NULL, 0.0f, 0.0f, CG_Text_EmHeight( scale ), - ITEM_ALIGN_LEFT, textvalign, NULL, &y ); + CG_AlignText( rect, NULL, 0.0f, 0.0f, UI_Text_EmHeight( scale ), + ALIGN_LEFT, textvalign, NULL, &y ); - CG_Text_Paint_Limit( &maxX, cg.spectatorPaintX, y, scale, color, + UI_Text_Paint_Limit( &maxX, cg.spectatorPaintX, y, scale, color, &cg.spectatorList[ cg.spectatorOffset ], 0, 0 ); if( cg.spectatorPaintX2 >= 0 ) { float maxX2 = rect->x + rect->w - 2; - CG_Text_Paint_Limit( &maxX2, cg.spectatorPaintX2, y, scale, + UI_Text_Paint_Limit( &maxX2, cg.spectatorPaintX2, y, scale, color, cg.spectatorList, 0, cg.spectatorOffset ); } @@ -1590,17 +1267,17 @@ static void CG_DrawTeamLabel( rectDef_t *rect, pTeam_t team, float text_x, float switch( textalign ) { default: - case ITEM_ALIGN_LEFT: + case ALIGN_LEFT: s = va( "%s %s", t, stage ); break; - case ITEM_ALIGN_RIGHT: + case ALIGN_RIGHT: s = va( "%s %s", stage, t ); break; } CG_AlignText( rect, s, scale, 0.0f, 0.0f, textalign, textvalign, &tx, &ty ); - CG_Text_Paint( text_x + tx, text_y + ty, scale, color, s, 0, 0, textStyle ); + UI_Text_Paint( text_x + tx, text_y + ty, scale, color, s, 0, 0, textStyle ); } /* @@ -1650,7 +1327,7 @@ static void CG_DrawStageReport( rectDef_t *rect, float text_x, float text_y, CG_AlignText( rect, s, scale, 0.0f, 0.0f, textalign, textvalign, &tx, &ty ); - CG_Text_Paint( text_x + tx, text_y + ty, scale, color, s, 0, 0, textStyle ); + UI_Text_Paint( text_x + tx, text_y + ty, scale, color, s, 0, 0, textStyle ); } /* @@ -1702,10 +1379,10 @@ static void CG_DrawFPS( rectDef_t *rect, float text_x, float text_y, fps = 1000 * FPS_FRAMES / total; s = va( "%d", fps ); - w = CG_Text_Width( "0", scale, 0 ); - h = CG_Text_Height( "0", scale, 0 ); + w = UI_Text_Width( "0", scale, 0 ); + h = UI_Text_Height( "0", scale, 0 ); strLength = CG_DrawStrlen( s ); - totalWidth = CG_Text_Width( FPS_STRING, scale, 0 ) + w * strLength; + totalWidth = UI_Text_Width( FPS_STRING, scale, 0 ) + w * strLength; CG_AlignText( rect, s, 0.0f, totalWidth, h, textalign, textvalign, &tx, &ty ); @@ -1718,10 +1395,10 @@ static void CG_DrawFPS( rectDef_t *rect, float text_x, float text_y, c[ 0 ] = s[ i ]; c[ 1 ] = '\0'; - CG_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, c, 0, 0, textStyle ); + UI_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, c, 0, 0, textStyle ); } - CG_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, FPS_STRING, 0, 0, textStyle ); + UI_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, FPS_STRING, 0, 0, textStyle ); } else { @@ -1811,8 +1488,8 @@ static void CG_DrawTimer( rectDef_t *rect, float text_x, float text_y, seconds -= tens * 10; s = va( "%d:%d%d", mins, tens, seconds ); - w = CG_Text_Width( "0", scale, 0 ); - h = CG_Text_Height( "0", scale, 0 ); + w = UI_Text_Width( "0", scale, 0 ); + h = UI_Text_Height( "0", scale, 0 ); strLength = CG_DrawStrlen( s ); totalWidth = w * strLength; @@ -1825,7 +1502,7 @@ static void CG_DrawTimer( rectDef_t *rect, float text_x, float text_y, c[ 0 ] = s[ i ]; c[ 1 ] = '\0'; - CG_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, c, 0, 0, textStyle ); + UI_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, c, 0, 0, textStyle ); } } @@ -1872,8 +1549,8 @@ static void CG_DrawClock( rectDef_t *rect, float text_x, float text_y, s = va( "%d%s%02d%s", h, ( qt.tm_sec % 2 ) ? ":" : " ", qt.tm_min, pm ); } - w = CG_Text_Width( "0", scale, 0 ); - h = CG_Text_Height( "0", scale, 0 ); + w = UI_Text_Width( "0", scale, 0 ); + h = UI_Text_Height( "0", scale, 0 ); strLength = CG_DrawStrlen( s ); totalWidth = w * strLength; @@ -1886,7 +1563,7 @@ static void CG_DrawClock( rectDef_t *rect, float text_x, float text_y, c[ 0 ] = s[ i ]; c[ 1 ] = '\0'; - CG_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, c, 0, 0, textStyle ); + UI_Text_Paint( text_x + tx + i * w, text_y + ty, scale, color, c, 0, 0, textStyle ); } } @@ -1910,7 +1587,7 @@ static void CG_DrawSnapshot( rectDef_t *rect, float text_x, float text_y, CG_AlignText( rect, s, scale, 0.0f, 0.0f, textalign, textvalign, &tx, &ty ); - CG_Text_Paint( text_x + tx, text_y + ty, scale, color, s, 0, 0, textStyle ); + UI_Text_Paint( text_x + tx, text_y + ty, scale, color, s, 0, 0, textStyle ); } /* @@ -2021,8 +1698,8 @@ static void CG_DrawDisconnect( void ) // also add text in center of screen s = "Connection Interrupted"; - w = CG_Text_Width( s, 0.7f, 0 ); - CG_Text_Paint( 320 - w / 2, 100, 0.7f, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); + w = UI_Text_Width( s, 0.7f, 0 ); + UI_Text_Paint( 320 - w / 2, 100, 0.7f, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); // blink the icon if( ( cg.time >> 9 ) & 1 ) @@ -2175,18 +1852,18 @@ static void CG_DrawLagometer( rectDef_t *rect, float text_x, float text_y, trap_R_SetColor( NULL ); if( cg_nopredict.integer || cg_synchronousClients.integer ) - CG_Text_Paint( ax, ay, 0.5, white, "snc", 0, 0, ITEM_TEXTSTYLE_NORMAL ); + UI_Text_Paint( ax, ay, 0.5, white, "snc", 0, 0, ITEM_TEXTSTYLE_NORMAL ); else { char *s; s = va( "%d", cg.ping ); - ax = rect->x + ( rect->w / 2.0f ) - ( CG_Text_Width( s, scale, 0 ) / 2.0f ) + text_x; - ay = rect->y + ( rect->h / 2.0f ) + ( CG_Text_Height( s, scale, 0 ) / 2.0f ) + text_y; + ax = rect->x + ( rect->w / 2.0f ) - ( UI_Text_Width( s, scale, 0 ) / 2.0f ) + text_x; + ay = rect->y + ( rect->h / 2.0f ) + ( UI_Text_Height( s, scale, 0 ) / 2.0f ) + text_y; Vector4Copy( textColor, adjustedColor ); adjustedColor[ 3 ] = 0.5f; - CG_Text_Paint( ax, ay, scale, adjustedColor, s, 0, 0, ITEM_TEXTSTYLE_NORMAL ); + UI_Text_Paint( ax, ay, scale, adjustedColor, s, 0, 0, ITEM_TEXTSTYLE_NORMAL ); } CG_DrawDisconnect( ); @@ -2311,6 +1988,8 @@ static void CG_DrawCrosshair( void ) w = h = wi->crossHairSize; + w *= cgDC.aspectScale; + x = cg_crosshairX.integer; y = cg_crosshairY.integer; CG_AdjustFrom640( &x, &y, &w, &h ); @@ -2397,9 +2076,9 @@ static void CG_DrawCrosshairNames( rectDef_t *rect, float scale, int textStyle ) } name = cgs.clientinfo[ cg.crosshairClientNum ].name; - w = CG_Text_Width( name, scale, 0 ); + w = UI_Text_Width( name, scale, 0 ); x = rect->x + rect->w / 2; - CG_Text_Paint( x - w / 2, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); + UI_Text_Paint( x - w / 2, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); trap_R_SetColor( NULL ); } @@ -2842,10 +2521,10 @@ static void CG_DrawCenterString( void ) linebuffer[ l ] = 0; - w = CG_Text_Width( linebuffer, 0.5, 0 ); - h = CG_Text_Height( linebuffer, 0.5, 0 ); + w = UI_Text_Width( linebuffer, 0.5, 0 ); + h = UI_Text_Height( linebuffer, 0.5, 0 ); x = ( SCREEN_WIDTH - w ) / 2; - CG_Text_Paint( x, y + h, 0.5, color, linebuffer, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE ); + UI_Text_Paint( x, y + h, 0.5, color, linebuffer, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE ); y += h + 6; while( *start && ( *start != '\n' ) ) @@ -2898,7 +2577,7 @@ static void CG_DrawVote( void ) Q_strncpyz( nokey, CG_KeyBinding( "vote no" ), sizeof( nokey ) ); s = va( "VOTE(%i): \"%s\" [%s]Yes:%i [%s]No:%i", sec, cgs.voteString, yeskey, cgs.voteYes, nokey, cgs.voteNo ); - CG_Text_Paint( 8, 340, 0.3f, white, s, 0, 0, ITEM_TEXTSTYLE_NORMAL ); + UI_Text_Paint( 8, 340, 0.3f, white, s, 0, 0, ITEM_TEXTSTYLE_NORMAL ); } /* @@ -2942,7 +2621,7 @@ static void CG_DrawTeamVote( void ) yeskey, cgs.teamVoteYes[cs_offset], nokey, cgs.teamVoteNo[ cs_offset ] ); - CG_Text_Paint( 8, 360, 0.3f, white, s, 0, 0, ITEM_TEXTSTYLE_NORMAL ); + UI_Text_Paint( 8, 360, 0.3f, white, s, 0, 0, ITEM_TEXTSTYLE_NORMAL ); } @@ -3031,8 +2710,8 @@ static qboolean CG_DrawFollow( void ) strcpy( buffer, FOLLOWING_STRING ); strcat( buffer, cgs.clientinfo[ cg.snap->ps.clientNum ].name ); - w = CG_Text_Width( buffer, 0.7f, 0 ); - CG_Text_Paint( 320 - w / 2, 400, 0.7f, color, buffer, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); + w = UI_Text_Width( buffer, 0.7f, 0 ); + UI_Text_Paint( 320 - w / 2, 400, 0.7f, color, buffer, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); return qtrue; } @@ -3059,8 +2738,8 @@ static qboolean CG_DrawQueue( void ) Com_sprintf( buffer, MAX_STRING_CHARS, "You are in position %d of the spawn queue.", cg.snap->ps.persistant[ PERS_QUEUEPOS ] + 1 ); - w = CG_Text_Width( buffer, 0.7f, 0 ); - CG_Text_Paint( 320 - w / 2, 360, 0.7f, color, buffer, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); + w = UI_Text_Width( buffer, 0.7f, 0 ); + UI_Text_Paint( 320 - w / 2, 360, 0.7f, color, buffer, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); if( cg.snap->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) { @@ -3079,8 +2758,8 @@ static qboolean CG_DrawQueue( void ) cgs.numHumanSpawns ); } - w = CG_Text_Width( buffer, 0.7f, 0 ); - CG_Text_Paint( 320 - w / 2, 400, 0.7f, color, buffer, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); + w = UI_Text_Width( buffer, 0.7f, 0 ); + UI_Text_Paint( 320 - w / 2, 400, 0.7f, color, buffer, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); return qtrue; } @@ -3121,8 +2800,8 @@ static void CG_Draw2D( void ) if( cg.snap->ps.persistant[ PERS_TEAM ] == TEAM_SPECTATOR ) { - w = CG_Text_Width( SPECTATOR_STRING, 0.7f, 0 ); - CG_Text_Paint( 320 - w / 2, 440, 0.7f, color, SPECTATOR_STRING, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); + w = UI_Text_Width( SPECTATOR_STRING, 0.7f, 0 ); + UI_Text_Paint( 320 - w / 2, 440, 0.7f, color, SPECTATOR_STRING, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); } else menu = Menus_FindByName( BG_FindHudNameForClass( cg.predictedPlayerState.stats[ STAT_PCLASS ] ) ); diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index 012a29ed..f70afc85 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -1375,6 +1375,7 @@ typedef struct extern cgs_t cgs; extern cg_t cg; extern centity_t cg_entities[ MAX_GENTITIES ]; +extern displayContextDef_t cgDC; extern weaponInfo_t cg_weapons[ 32 ]; extern upgradeInfo_t cg_upgrades[ 32 ]; @@ -1589,11 +1590,6 @@ void CG_OwnerDraw( float x, float y, float w, float h, float text_x, int align, int textalign, int textvalign, float special, float scale, vec4_t color, qhandle_t shader, int textStyle ); -void CG_Text_Paint( float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style ); -float CG_Text_Width( const char *text, float scale, int limit ); -float CG_Text_Height( const char *text, float scale, int limit ); -float CG_Text_EmWidth( float scale ); -float CG_Text_EmHeight( float scale ); float CG_GetValue(int ownerDraw); void CG_RunMenuScript(char **args); void CG_SetPrintString( int type, const char *p ); diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 618762e3..b3452371 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -1594,7 +1594,7 @@ static float CG_Cvar_Get( const char *cvar ) void CG_Text_PaintWithCursor( float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style ) { - CG_Text_Paint( x, y, scale, color, text, 0, limit, style ); + UI_Text_Paint( x, y, scale, color, text, 0, limit, style ); } static int CG_OwnerDrawWidth( int ownerDraw, float scale ) @@ -1602,7 +1602,7 @@ static int CG_OwnerDrawWidth( int ownerDraw, float scale ) switch( ownerDraw ) { case CG_KILLER: - return CG_Text_Width( CG_GetKillerText( ), scale, 0 ); + return UI_Text_Width( CG_GetKillerText( ), scale, 0 ); break; } @@ -1646,15 +1646,15 @@ void CG_LoadHudMenu( void ) char buff[ 1024 ]; const char *hudSet; + cgDC.aspectScale = ( ( 640.0f * cgs.glconfig.vidHeight ) / + ( 480.0f * cgs.glconfig.vidWidth ) ); + cgDC.xscale = cgs.glconfig.vidWidth / 640.0f; + cgDC.yscale = cgs.glconfig.vidHeight / 480.0f; + cgDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; cgDC.setColor = &trap_R_SetColor; cgDC.drawHandlePic = &CG_DrawPic; cgDC.drawStretchPic = &trap_R_DrawStretchPic; - cgDC.drawText = &CG_Text_Paint; - cgDC.textWidth = &CG_Text_Width; - cgDC.textHeight = &CG_Text_Height; - cgDC.textEmWidth = &CG_Text_EmWidth; - cgDC.textEmHeight = &CG_Text_EmHeight; cgDC.registerModel = &trap_R_RegisterModel; cgDC.modelBounds = &trap_R_ModelBounds; cgDC.fillRect = &CG_FillRect; @@ -1673,7 +1673,6 @@ void CG_LoadHudMenu( void ) cgDC.setCVar = trap_Cvar_Set; cgDC.getCVarString = trap_Cvar_VariableStringBuffer; cgDC.getCVarValue = CG_Cvar_Get; - cgDC.drawTextWithCursor = &CG_Text_PaintWithCursor; cgDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode; cgDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode; cgDC.startLocalSound = &trap_S_StartLocalSound; @@ -1748,6 +1747,11 @@ void CG_Init( int serverMessageNum, int serverCommandSequence, int clientNum ) cgs.processedSnapshotNum = serverMessageNum; cgs.serverCommandSequence = serverCommandSequence; + // get the rendering configuration from the client system + trap_GetGlconfig( &cgs.glconfig ); + cgs.screenXScale = cgs.glconfig.vidWidth / 640.0f; + cgs.screenYScale = cgs.glconfig.vidHeight / 480.0f; + // load a few needed things before we do any screen updates cgs.media.whiteShader = trap_R_RegisterShader( "white" ); cgs.media.charsetShader = trap_R_RegisterShader( "gfx/2d/bigchars" ); @@ -1775,11 +1779,6 @@ void CG_Init( int serverMessageNum, int serverCommandSequence, int clientNum ) // old servers - // get the rendering configuration from the client system - trap_GetGlconfig( &cgs.glconfig ); - cgs.screenXScale = cgs.glconfig.vidWidth / 640.0; - cgs.screenYScale = cgs.glconfig.vidHeight / 480.0; - // get the gamestate from the client system trap_GetGameState( &cgs.gameState ); diff --git a/src/cgame/cg_scanner.c b/src/cgame/cg_scanner.c index f9175ede..067ca7fb 100644 --- a/src/cgame/cg_scanner.c +++ b/src/cgame/cg_scanner.c @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "cg_local.h" -static entityPos_t entityPositions; +static entityPos_t entityPositions; #define HUMAN_SCANNER_UPDATE_PERIOD 700 @@ -104,8 +104,8 @@ void CG_UpdateEntityPositions( void ) } } -#define STALKWIDTH 2.0f -#define BLIPX 16.0f +#define STALKWIDTH (2.0f * cgDC.aspectScale) +#define BLIPX (16.0f * cgDC.aspectScale) #define BLIPY 8.0f #define FAR_ALPHA 0.8f #define NEAR_ALPHA 1.2f @@ -162,7 +162,7 @@ static void CG_DrawBlips( rectDef_t *rect, vec3_t origin, vec4_t colour ) trap_R_SetColor( NULL ); } -#define BLIPX2 24.0f +#define BLIPX2 (24.0f * cgDC.aspectScale) #define BLIPY2 24.0f /* diff --git a/src/cgame/cg_weapons.c b/src/cgame/cg_weapons.c index 613cddb2..fc8dc058 100644 --- a/src/cgame/cg_weapons.c +++ b/src/cgame/cg_weapons.c @@ -1140,11 +1140,12 @@ CG_DrawItemSelect void CG_DrawItemSelect( rectDef_t *rect, vec4_t color ) { int i; - int x = rect->x; - int y = rect->y; - int width = rect->w; - int height = rect->h; - int iconsize; + float x = rect->x; + float y = rect->y; + float width = rect->w; + float height = rect->h; + float iconWidth; + float iconHeight; int items[ 64 ]; int numItems = 0, selectedItem = 0; int length; @@ -1177,14 +1178,16 @@ void CG_DrawItemSelect( rectDef_t *rect, vec4_t color ) if( height > width ) { vertical = qtrue; - iconsize = width; - length = height / width; + iconWidth = width * cgDC.aspectScale; + iconHeight = width; + length = height / ( width * cgDC.aspectScale ); } else if( height <= width ) { vertical = qfalse; - iconsize = height; - length = width / height; + iconWidth = height * cgDC.aspectScale; + iconHeight = height; + length = width / ( height * cgDC.aspectScale ); } selectWindow = length / 2; @@ -1248,17 +1251,17 @@ void CG_DrawItemSelect( rectDef_t *rect, vec4_t color ) trap_R_SetColor( color ); if( items[ item ] <= 32 ) - CG_DrawPic( x, y, iconsize, iconsize, cg_weapons[ items[ item ] ].weaponIcon ); + CG_DrawPic( x, y, iconWidth, iconHeight, cg_weapons[ items[ item ] ].weaponIcon ); else if( items[ item ] > 32 ) - CG_DrawPic( x, y, iconsize, iconsize, cg_upgrades[ items[ item ] - 32 ].upgradeIcon ); + CG_DrawPic( x, y, iconWidth, iconHeight, cg_upgrades[ items[ item ] - 32 ].upgradeIcon ); trap_R_SetColor( NULL ); } if( vertical ) - y += iconsize; + y += iconHeight; else - x += iconsize; + x += iconWidth; } } @@ -1288,9 +1291,9 @@ void CG_DrawItemSelectText( rectDef_t *rect, float scale, int textStyle ) { if( ( name = cg_weapons[ cg.weaponSelect ].humanName ) ) { - w = CG_Text_Width( name, scale, 0 ); + w = UI_Text_Width( name, scale, 0 ); x = rect->x + rect->w / 2; - CG_Text_Paint( x - w / 2, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); + UI_Text_Paint( x - w / 2, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); } } } @@ -1301,9 +1304,9 @@ void CG_DrawItemSelectText( rectDef_t *rect, float scale, int textStyle ) { if( ( name = cg_upgrades[ cg.weaponSelect - 32 ].humanName ) ) { - w = CG_Text_Width( name, scale, 0 ); + w = UI_Text_Width( name, scale, 0 ); x = rect->x + rect->w / 2; - CG_Text_Paint( x - w / 2, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); + UI_Text_Paint( x - w / 2, rect->y + rect->h, scale, color, name, 0, 0, textStyle ); } } } diff --git a/src/sys/win_resource.rc b/src/sys/win_resource.rc index 2527af2f..6f5d82ac 100644 --- a/src/sys/win_resource.rc +++ b/src/sys/win_resource.rc @@ -7,11 +7,7 @@ // // Generated from the TEXTINCLUDE 2 resource. // -#ifndef __MINGW32__ -#include "winres.h" -#else #include <winresrc.h> -#endif ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -58,7 +54,6 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDI_ICON1 ICON DISCARDABLE "misc/tremulous.ico" -#endif ///////////////////////////////////////////////////////////////////////////// diff --git a/src/ui/ui_atoms.c b/src/ui/ui_atoms.c index d2bb6b26..7d9185f7 100644 --- a/src/ui/ui_atoms.c +++ b/src/ui/ui_atoms.c @@ -412,29 +412,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/src/ui/ui_main.c b/src/ui/ui_main.c index 7618c211..25462a86 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -244,370 +244,6 @@ void _UI_DrawRect( float x, float y, float width, float height, float size, cons trap_R_SetColor( NULL ); } - - - -float Text_Width(const char *text, float scale, int limit) { - int count,len; - float out; - glyphInfo_t *glyph; - float useScale; - const char *s = text; - fontInfo_t *font = &uiInfo.uiDC.Assets.textFont; - if (scale <= ui_smallFont.value) { - font = &uiInfo.uiDC.Assets.smallFont; - } else if (scale >= ui_bigFont.value) { - font = &uiInfo.uiDC.Assets.bigFont; - } - useScale = scale * font->glyphScale; - out = 0; - if (text) { - len = Q_PrintStrlen( text ); - if (limit > 0 && len > limit) { - len = limit; - } - count = 0; - while (s && *s && count < len) { - if ( Q_IsColorString(s) ) { - s += 2; - continue; - } else { - glyph = &font->glyphs[(int)*s]; - out += glyph->xSkip; - s++; - count++; - } - } - } - return out * useScale; -} - -float Text_Height(const char *text, float scale, int limit) { - int len, count; - float max; - glyphInfo_t *glyph; - float useScale; - const char *s = text; - fontInfo_t *font = &uiInfo.uiDC.Assets.textFont; - if (scale <= ui_smallFont.value) { - font = &uiInfo.uiDC.Assets.smallFont; - } else if (scale >= ui_bigFont.value) { - font = &uiInfo.uiDC.Assets.bigFont; - } - useScale = scale * font->glyphScale; - max = 0; - if (text) { - len = strlen(text); - if (limit > 0 && len > limit) { - len = limit; - } - count = 0; - while (s && *s && count < len) { - if ( Q_IsColorString(s) ) { - s += 2; - continue; - } else { - glyph = &font->glyphs[(int)*s]; - if (max < glyph->height) { - max = glyph->height; - } - s++; - count++; - } - } - } - return max * useScale; -} - -float Text_EmWidth( float scale ) -{ - return Text_Width( "M", scale, 0 ); -} - -float Text_EmHeight( float scale ) -{ - return Text_Height( "M", scale, 0 ); -} - -void Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader) { - float w, h; - w = width * scale; - h = height * scale; - UI_AdjustFrom640( &x, &y, &w, &h ); - trap_R_DrawStretchPic( x, y, w, h, s, t, s2, t2, hShader ); -} - -void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style) { - int len, count; - vec4_t newColor; - glyphInfo_t *glyph; - float useScale; - fontInfo_t *font = &uiInfo.uiDC.Assets.textFont; - if (scale <= ui_smallFont.value) { - font = &uiInfo.uiDC.Assets.smallFont; - } else if (scale >= ui_bigFont.value) { - font = &uiInfo.uiDC.Assets.bigFont; - } - useScale = scale * font->glyphScale; - if (text) { - const char *s = text; - trap_R_SetColor( color ); - memcpy(&newColor[0], &color[0], sizeof(vec4_t)); - len = strlen(text); - if (limit > 0 && len > limit) { - len = limit; - } - count = 0; - while (s && *s && count < len) { - glyph = &font->glyphs[(int)*s]; - if ( Q_IsColorString( s ) ) { - memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) ); - newColor[3] = color[3]; - trap_R_SetColor( newColor ); - s += 2; - continue; - } else { - float yadj = useScale * glyph->top; - if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) { - int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; - colorBlack[3] = newColor[3]; - trap_R_SetColor( colorBlack ); - Text_PaintChar(x + ofs, y - yadj + ofs, - glyph->imageWidth, - glyph->imageHeight, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); - trap_R_SetColor( newColor ); - colorBlack[3] = 1.0; - } - else if( style == ITEM_TEXTSTYLE_NEON ) - { - vec4_t glow, outer, inner, white; - - glow[ 0 ] = newColor[ 0 ] * 0.5; - glow[ 1 ] = newColor[ 1 ] * 0.5; - glow[ 2 ] = newColor[ 2 ] * 0.5; - glow[ 3 ] = newColor[ 3 ] * 0.2; - - outer[ 0 ] = newColor[ 0 ]; - outer[ 1 ] = newColor[ 1 ]; - outer[ 2 ] = newColor[ 2 ]; - outer[ 3 ] = newColor[ 3 ]; - - inner[ 0 ] = newColor[ 0 ] * 1.5 > 1.0f ? 1.0f : newColor[ 0 ] * 1.5; - inner[ 1 ] = newColor[ 1 ] * 1.5 > 1.0f ? 1.0f : newColor[ 1 ] * 1.5; - inner[ 2 ] = newColor[ 2 ] * 1.5 > 1.0f ? 1.0f : newColor[ 2 ] * 1.5; - inner[ 3 ] = newColor[ 3 ]; - - white[ 0 ] = white[ 1 ] = white[ 2 ] = white[ 3 ] = 1.0f; - - trap_R_SetColor( glow ); - Text_PaintChar( x - 1.5, y - yadj - 1.5, - glyph->imageWidth + 3, - glyph->imageHeight + 3, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( outer ); - Text_PaintChar( x - 1, y - yadj - 1, - glyph->imageWidth + 2, - glyph->imageHeight + 2, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( inner ); - Text_PaintChar( x - 0.5, y - yadj - 0.5, - glyph->imageWidth + 1, - glyph->imageHeight + 1, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( white ); - } - - Text_PaintChar(x, y - yadj, - glyph->imageWidth, - glyph->imageHeight, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); - - x += (glyph->xSkip * useScale) + adjust; - s++; - count++; - } - } - trap_R_SetColor( NULL ); - } -} - -//FIXME: merge this with Text_Paint, somehow -void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style) { - int len, count; - vec4_t newColor; - glyphInfo_t *glyph, *glyph2; - float yadj; - float useScale; - fontInfo_t *font = &uiInfo.uiDC.Assets.textFont; - if (scale <= ui_smallFont.value) { - font = &uiInfo.uiDC.Assets.smallFont; - } else if (scale >= ui_bigFont.value) { - font = &uiInfo.uiDC.Assets.bigFont; - } - useScale = scale * font->glyphScale; - if (text) { - const char *s = text; - trap_R_SetColor( color ); - memcpy(&newColor[0], &color[0], sizeof(vec4_t)); - len = strlen(text); - if (limit > 0 && len > limit) { - len = limit; - } - count = 0; - glyph2 = &font->glyphs[ (int) cursor]; - while (s && *s && count < len) { - glyph = &font->glyphs[(int)*s]; - yadj = useScale * glyph->top; - if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) { - int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; - colorBlack[3] = newColor[3]; - trap_R_SetColor( colorBlack ); - Text_PaintChar(x + ofs, y - yadj + ofs, - glyph->imageWidth, - glyph->imageHeight, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); - colorBlack[3] = 1.0; - trap_R_SetColor( newColor ); - } - else if( style == ITEM_TEXTSTYLE_NEON ) - { - vec4_t glow, outer, inner, white; - - glow[ 0 ] = newColor[ 0 ] * 0.5; - glow[ 1 ] = newColor[ 1 ] * 0.5; - glow[ 2 ] = newColor[ 2 ] * 0.5; - glow[ 3 ] = newColor[ 3 ] * 0.2; - - outer[ 0 ] = newColor[ 0 ]; - outer[ 1 ] = newColor[ 1 ]; - outer[ 2 ] = newColor[ 2 ]; - outer[ 3 ] = newColor[ 3 ]; - - inner[ 0 ] = newColor[ 0 ] * 1.5 > 1.0f ? 1.0f : newColor[ 0 ] * 1.5; - inner[ 1 ] = newColor[ 1 ] * 1.5 > 1.0f ? 1.0f : newColor[ 1 ] * 1.5; - inner[ 2 ] = newColor[ 2 ] * 1.5 > 1.0f ? 1.0f : newColor[ 2 ] * 1.5; - inner[ 3 ] = newColor[ 3 ]; - - white[ 0 ] = white[ 1 ] = white[ 2 ] = white[ 3 ] = 1.0f; - - trap_R_SetColor( glow ); - Text_PaintChar( x - 1.5, y - yadj - 1.5, - glyph->imageWidth + 3, - glyph->imageHeight + 3, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( outer ); - Text_PaintChar( x - 1, y - yadj - 1, - glyph->imageWidth + 2, - glyph->imageHeight + 2, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( inner ); - Text_PaintChar( x - 0.5, y - yadj - 0.5, - glyph->imageWidth + 1, - glyph->imageHeight + 1, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph ); - - trap_R_SetColor( white ); - } - - Text_PaintChar(x, y - yadj, - glyph->imageWidth, - glyph->imageHeight, - useScale, - glyph->s, - glyph->t, - glyph->s2, - glyph->t2, - glyph->glyph); - - yadj = useScale * glyph2->top; - if (count == cursorPos && !((uiInfo.uiDC.realTime/BLINK_DIVISOR) & 1)) { - Text_PaintChar(x, y - yadj, - glyph2->imageWidth, - glyph2->imageHeight, - useScale, - glyph2->s, - glyph2->t, - glyph2->s2, - glyph2->t2, - glyph2->glyph); - } - - x += (glyph->xSkip * useScale); - s++; - count++; - } - // need to paint cursor at end of text - if (cursorPos == len && !((uiInfo.uiDC.realTime/BLINK_DIVISOR) & 1)) { - yadj = useScale * glyph2->top; - Text_PaintChar(x, y - yadj, - glyph2->imageWidth, - glyph2->imageHeight, - useScale, - glyph2->s, - glyph2->t, - glyph2->s2, - glyph2->t2, - glyph2->glyph); - - } - - - trap_R_SetColor( NULL ); - } -} - - void UI_ShowPostGame(qboolean newHigh) { trap_Cvar_Set ("cg_cameraOrbit", "0"); trap_Cvar_Set("cg_thirdPerson", "0"); @@ -676,20 +312,11 @@ void _UI_Refresh( int realtime ) // draw cursor UI_SetColor( NULL ); - - // don't draw the cursor whilst loading if( Menu_Count( ) > 0 && !trap_Cvar_VariableValue( "ui_hideCursor" ) ) - UI_DrawHandlePic( uiInfo.uiDC.cursorx-16, uiInfo.uiDC.cursory-16, 32, 32, uiInfo.uiDC.Assets.cursor); - -#ifndef NDEBUG - if (uiInfo.uiDC.debug) { - // cursor coordinates - //FIXME - //UI_DrawString( 0, 0, va("(%d,%d)",uis.cursorx,uis.cursory), UI_LEFT|UI_SMALLFONT, colorRed ); + UI_DrawHandlePic( uiInfo.uiDC.cursorx - ( 16.0f * uiInfo.uiDC.aspectScale ), uiInfo.uiDC.cursory - 16.0f, + 32.0f * uiInfo.uiDC.aspectScale, 32.0f, uiInfo.uiDC.Assets.cursor); } -#endif - } /* @@ -1035,11 +662,11 @@ static void UI_DrawHandicap(rectDef_t *rect, float scale, vec4_t color, int text h = Com_Clamp( 5, 100, trap_Cvar_VariableValue("handicap") ); i = 20 - h / 5; - Text_Paint(rect->x, rect->y, scale, color, handicapValues[i], 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, handicapValues[i], 0, 0, textStyle); } static void UI_DrawClanName(rectDef_t *rect, float scale, vec4_t color, int textStyle) { - Text_Paint(rect->x, rect->y, scale, color, UI_Cvar_VariableString("ui_teamName"), 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, UI_Cvar_VariableString("ui_teamName"), 0, 0, textStyle); } @@ -1056,7 +683,7 @@ static void UI_SetCapFragLimits(qboolean uiVars) { } // ui_gameType assumes gametype 0 is -1 ALL and will not show static void UI_DrawGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) { - Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_gameType.integer].gameType, 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_gameType.integer].gameType, 0, 0, textStyle); } static void UI_DrawNetGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) { @@ -1064,14 +691,14 @@ static void UI_DrawNetGameType(rectDef_t *rect, float scale, vec4_t color, int t trap_Cvar_Set("ui_netGameType", "0"); trap_Cvar_Set("ui_actualNetGameType", "0"); } - Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_netGameType.integer].gameType , 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_netGameType.integer].gameType , 0, 0, textStyle); } static void UI_DrawJoinGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) { if (ui_joinGameType.integer < 0 || ui_joinGameType.integer > uiInfo.numJoinGameTypes) { trap_Cvar_Set("ui_joinGameType", "0"); } - Text_Paint(rect->x, rect->y, scale, color, uiInfo.joinGameTypes[ui_joinGameType.integer].gameType , 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.joinGameTypes[ui_joinGameType.integer].gameType , 0, 0, textStyle); } @@ -1261,7 +888,7 @@ static void UI_DrawSkill(rectDef_t *rect, float scale, vec4_t color, int textSty if (i < 1 || i > numSkillLevels) { i = 1; } - Text_Paint(rect->x, rect->y, scale, color, skillLevels[i-1],0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, skillLevels[i-1],0, 0, textStyle); } @@ -1269,7 +896,7 @@ static void UI_DrawTeamName(rectDef_t *rect, float scale, vec4_t color, qboolean int i; i = UI_TeamIndexFromName(UI_Cvar_VariableString((blue) ? "ui_blueTeam" : "ui_redTeam")); if (i >= 0 && i < uiInfo.teamCount) { - Text_Paint(rect->x, rect->y, scale, color, va("%s: %s", (blue) ? "Blue" : "Red", uiInfo.teamList[i].teamName),0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, va("%s: %s", (blue) ? "Blue" : "Red", uiInfo.teamList[i].teamName),0, 0, textStyle); } } @@ -1291,7 +918,7 @@ static void UI_DrawTeamMember(rectDef_t *rect, float scale, vec4_t color, qboole text = UI_GetBotNameByNumber(value); } - Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle); } static void UI_DrawMapPreview(rectDef_t *rect, float scale, vec4_t color, qboolean net) { @@ -1331,7 +958,7 @@ static void UI_DrawMapTimeToBeat(rectDef_t *rect, float scale, vec4_t color, int minutes = time / 60; seconds = time % 60; - Text_Paint(rect->x, rect->y, scale, color, va("%02i:%02i", minutes, seconds), 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, va("%02i:%02i", minutes, seconds), 0, 0, textStyle); } @@ -1445,7 +1072,7 @@ static void UI_DrawTier(rectDef_t *rect, float scale, vec4_t color, int textStyl if (i < 0 || i >= uiInfo.tierCount) { i = 0; } - Text_Paint(rect->x, rect->y, scale, color, va("Tier: %s", uiInfo.tierList[i].tierName),0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, va("Tier: %s", uiInfo.tierList[i].tierName),0, 0, textStyle); } static void UI_DrawTierMap(rectDef_t *rect, int index) { @@ -1483,7 +1110,7 @@ static void UI_DrawTierMapName(rectDef_t *rect, float scale, vec4_t color, int t j = 0; } - Text_Paint(rect->x, rect->y, scale, color, UI_EnglishMapName(uiInfo.tierList[i].maps[j]), 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, UI_EnglishMapName(uiInfo.tierList[i].maps[j]), 0, 0, textStyle); } static void UI_DrawTierGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) { @@ -1497,7 +1124,7 @@ static void UI_DrawTierGameType(rectDef_t *rect, float scale, vec4_t color, int j = 0; } - Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[uiInfo.tierList[i].gameTypes[j]].gameType , 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[uiInfo.tierList[i].gameTypes[j]].gameType , 0, 0, textStyle); } @@ -1655,7 +1282,7 @@ static void UI_DrawOpponentLogoName(rectDef_t *rect, vec3_t color) { static void UI_DrawAllMapsSelection(rectDef_t *rect, float scale, vec4_t color, int textStyle, qboolean net) { int map = (net) ? ui_currentNetMap.integer : ui_currentMap.integer; if (map >= 0 && map < uiInfo.mapCount) { - Text_Paint(rect->x, rect->y, scale, color, uiInfo.mapList[map].mapName, 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.mapList[map].mapName, 0, 0, textStyle); } } @@ -1664,7 +1291,7 @@ static void UI_DrawPlayerListSelection( rectDef_t *rect, float scale, { if( uiInfo.playerIndex >= 0 && uiInfo.playerIndex < uiInfo.playerCount ) { - Text_Paint(rect->x, rect->y, scale, color, + UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.rawPlayerNames[ uiInfo.playerIndex ], 0, 0, textStyle); } @@ -1675,14 +1302,14 @@ static void UI_DrawTeamListSelection( rectDef_t *rect, float scale, { if( uiInfo.teamIndex >= 0 && uiInfo.teamIndex < uiInfo.myTeamCount ) { - Text_Paint(rect->x, rect->y, scale, color, + UI_Text_Paint(rect->x, rect->y, scale, color, uiInfo.rawTeamNames[ uiInfo.teamIndex ], 0, 0, textStyle); } } static void UI_DrawOpponentName(rectDef_t *rect, float scale, vec4_t color, int textStyle) { - Text_Paint(rect->x, rect->y, scale, color, UI_Cvar_VariableString("ui_opponentName"), 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, UI_Cvar_VariableString("ui_opponentName"), 0, 0, textStyle); } static const char *UI_OwnerDrawText(int ownerDraw) { @@ -1844,7 +1471,7 @@ static int UI_OwnerDrawWidth(int ownerDraw, float scale) { } if (s) { - return Text_Width(s, scale, 0); + return UI_Text_Width(s, scale, 0); } return 0; } @@ -1858,17 +1485,17 @@ static void UI_DrawBotName(rectDef_t *rect, float scale, vec4_t color, int textS text = UI_GetBotNameByNumber( value ); - Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle); } static void UI_DrawBotSkill(rectDef_t *rect, float scale, vec4_t color, int textStyle) { if (uiInfo.skillIndex >= 0 && uiInfo.skillIndex < numSkillLevels) { - Text_Paint(rect->x, rect->y, scale, color, skillLevels[uiInfo.skillIndex], 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, skillLevels[uiInfo.skillIndex], 0, 0, textStyle); } } static void UI_DrawRedBlue(rectDef_t *rect, float scale, vec4_t color, int textStyle) { - Text_Paint(rect->x, rect->y, scale, color, (uiInfo.redBlue == 0) ? "Red" : "Blue", 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, (uiInfo.redBlue == 0) ? "Red" : "Blue", 0, 0, textStyle); } /* @@ -1950,7 +1577,7 @@ static void UI_DrawSelectedPlayer(rectDef_t *rect, float scale, vec4_t color, in else s = UI_Cvar_VariableString("name"); Q_strncpyz( name, s, sizeof( name ) ); - Text_Paint(rect->x, rect->y, scale, color, name, 0, 0, textStyle); + UI_Text_Paint(rect->x, rect->y, scale, color, name, 0, 0, textStyle); } static void UI_DrawGLInfo( rectDef_t *rect, float scale, int textalign, int textvalign, @@ -5179,28 +4806,17 @@ 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) ) ); - } - else { - // no wide screen - uiInfo.uiDC.bias = 0; - } + uiInfo.uiDC.yscale = uiInfo.uiDC.glconfig.vidHeight * ( 1.0f / 480.0f ); + uiInfo.uiDC.xscale = uiInfo.uiDC.glconfig.vidWidth * ( 1.0f / 640.0f ); + // wide screen + uiInfo.uiDC.aspectScale = ( ( 640.0f * uiInfo.uiDC.glconfig.vidHeight ) / + ( 480.0f * uiInfo.uiDC.glconfig.vidWidth ) ); - //UI_Load(); uiInfo.uiDC.registerShaderNoMip = &trap_R_RegisterShaderNoMip; uiInfo.uiDC.setColor = &UI_SetColor; uiInfo.uiDC.drawHandlePic = &UI_DrawHandlePic; uiInfo.uiDC.drawStretchPic = &trap_R_DrawStretchPic; - uiInfo.uiDC.drawText = &Text_Paint; - uiInfo.uiDC.textWidth = &Text_Width; - uiInfo.uiDC.textHeight = &Text_Height; - uiInfo.uiDC.textEmWidth = &Text_EmWidth; - uiInfo.uiDC.textEmHeight = &Text_EmHeight; uiInfo.uiDC.registerModel = &trap_R_RegisterModel; uiInfo.uiDC.modelBounds = &trap_R_ModelBounds; uiInfo.uiDC.fillRect = &UI_FillRect; @@ -5220,7 +4836,6 @@ void _UI_Init( qboolean inGameLoad ) { uiInfo.uiDC.setCVar = trap_Cvar_Set; uiInfo.uiDC.getCVarString = trap_Cvar_VariableStringBuffer; uiInfo.uiDC.getCVarValue = trap_Cvar_VariableValue; - uiInfo.uiDC.drawTextWithCursor = &Text_PaintWithCursor; uiInfo.uiDC.setOverstrikeMode = &trap_Key_SetOverstrikeMode; uiInfo.uiDC.getOverstrikeMode = &trap_Key_GetOverstrikeMode; uiInfo.uiDC.startLocalSound = &trap_S_StartLocalSound; @@ -5324,7 +4939,7 @@ UI_MouseEvent void _UI_MouseEvent( int dx, int dy ) { // update mouse screen position - uiInfo.uiDC.cursorx += dx; + uiInfo.uiDC.cursorx += ( dx * uiInfo.uiDC.aspectScale ); if (uiInfo.uiDC.cursorx < 0) uiInfo.uiDC.cursorx = 0; else if (uiInfo.uiDC.cursorx > SCREEN_WIDTH) @@ -5451,8 +5066,8 @@ static void UI_PrintTime ( char *buf, int bufsize, int time ) { } void Text_PaintCenter(float x, float y, float scale, vec4_t color, const char *text, float adjust) { - int len = Text_Width(text, scale, 0); - Text_Paint(x - len / 2, y, scale, color, text, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); + int len = UI_Text_Width(text, scale, 0); + UI_Text_Paint(x - len / 2, y, scale, color, text, 0, 0, ITEM_TEXTSTYLE_SHADOWEDMORE); } void Text_PaintCenter_AutoWrapped(float x, float y, float xmax, float ystep, float scale, vec4_t color, const char *str, float adjust) { @@ -5473,7 +5088,7 @@ void Text_PaintCenter_AutoWrapped(float x, float y, float xmax, float ystep, flo } while (*s3!=' ' && *s3!='\0'); c_bcp = *s3; *s3 = '\0'; - width = Text_Width(s1, scale, 0); + width = UI_Text_Width(s1, scale, 0); *s3 = c_bcp; if (width > xmax) { if (s1==s2) diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index ec6a07eb..52aa1fc4 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -1058,6 +1058,59 @@ void Menu_UpdatePosition(menuDef_t *menu) { } } +static void Menu_AspectiseRect( int bias, Rectangle *rect ) +{ + switch( bias ) + { + case ALIGN_LEFT: + rect->x *= DC->aspectScale; + rect->w *= DC->aspectScale; + break; + + case ALIGN_CENTER: + rect->x = ( rect->x * DC->aspectScale ) + + ( 320.0f - ( 320.0f * DC->aspectScale ) ); + rect->w *= DC->aspectScale; + break; + + case ALIGN_RIGHT: + rect->x = 640.0f - ( ( 640.0f - rect->x ) * DC->aspectScale ); + rect->w *= DC->aspectScale; + break; + + default: + case ASPECT_NONE: + break; + } +} + +void Menu_AspectCompensate( menuDef_t *menu ) +{ + int i; + + if( menu->window.aspectBias != ASPECT_NONE ) + { + Menu_AspectiseRect( menu->window.aspectBias, &menu->window.rect ); + + for( i = 0; i < menu->itemCount; i++ ) + { + menu->items[ i ]->window.rectClient.x *= DC->aspectScale; + menu->items[ i ]->window.rectClient.w *= DC->aspectScale; + menu->items[ i ]->textalignx *= DC->aspectScale; + } + } + else + { + for( i = 0; i < menu->itemCount; i++ ) + { + Menu_AspectiseRect( menu->items[ i ]->window.aspectBias, + &menu->items[ i ]->window.rectClient ); + if( menu->items[ i ]->window.aspectBias != ASPECT_NONE ) + menu->items[ i ]->textalignx *= DC->aspectScale; + } + } +} + void Menu_PostParse(menuDef_t *menu) { if (menu == NULL) { return; @@ -1068,6 +1121,7 @@ void Menu_PostParse(menuDef_t *menu) { menu->window.rect.w = 640; menu->window.rect.h = 480; } + Menu_AspectCompensate( menu ); Menu_UpdatePosition(menu); } @@ -1485,6 +1539,27 @@ void Script_SetFocus(itemDef_t *item, char **args) { } } +void Script_Reset( itemDef_t *item, char **args ) +{ + const char *name; + itemDef_t *resetItem; + + if( String_Parse( args, &name ) ) + { + resetItem = Menu_FindItemByName( item->parent, name ); + if( resetItem ) + { + if( resetItem->type == ITEM_TYPE_LISTBOX ) + { + listBoxDef_t *listPtr = (listBoxDef_t*)resetItem->typeData; + resetItem->cursorPos = 0; + listPtr->startPos = 0; + DC->feederSelection( resetItem->special, 0 ); + } + } + } +} + void Script_SetPlayerModel(itemDef_t *item, char **args) { const char *name; if (String_Parse(args, &name)) { @@ -1529,6 +1604,467 @@ void Script_playLooped(itemDef_t *item, char **args) { } } +float UI_Text_Width(const char *text, float scale, int limit) { + int count,len; + float out; + glyphInfo_t *glyph; + float useScale; + const char *s = text; + fontInfo_t *font = &DC->Assets.textFont; + if (scale <= DC->getCVarValue( "ui_smallFont" )) { + font = &DC->Assets.smallFont; + } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + font = &DC->Assets.bigFont; + } + useScale = scale * font->glyphScale; + out = 0; + if (text) { + len = Q_PrintStrlen( text ); + if (limit > 0 && len > limit) { + len = limit; + } + count = 0; + while (s && *s && count < len) { + if ( Q_IsColorString(s) ) { + s += 2; + continue; + } else { + glyph = &font->glyphs[(int)*s]; + out += ( glyph->xSkip * DC->aspectScale ); + s++; + count++; + } + } + } + return out * useScale; +} + +float UI_Text_Height(const char *text, float scale, int limit) { + int len, count; + float max; + glyphInfo_t *glyph; + float useScale; + const char *s = text; + fontInfo_t *font = &DC->Assets.textFont; + if (scale <= DC->getCVarValue( "ui_smallFont" )) { + font = &DC->Assets.smallFont; + } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + font = &DC->Assets.bigFont; + } + useScale = scale * font->glyphScale; + max = 0; + if (text) { + len = strlen(text); + if (limit > 0 && len > limit) { + len = limit; + } + count = 0; + while (s && *s && count < len) { + if ( Q_IsColorString(s) ) { + s += 2; + continue; + } else { + glyph = &font->glyphs[(int)*s]; + if (max < glyph->height) { + max = glyph->height; + } + s++; + count++; + } + } + } + return max * useScale; +} + +float UI_Text_EmWidth( float scale ) +{ + return UI_Text_Width( "M", scale, 0 ); +} + +float UI_Text_EmHeight( float scale ) +{ + return UI_Text_Height( "M", scale, 0 ); +} + + +/* +================ +UI_AdjustFrom640 + +Adjusted for resolution and screen aspect ratio +================ +*/ +void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) { + *x *= DC->xscale; + *y *= DC->yscale; + *w *= DC->xscale; + *h *= DC->yscale; +} + +static void UI_Text_PaintChar(float x, float y, float width, float height, float scale, float s, float t, float s2, float t2, qhandle_t hShader) { + float w, h; + w = width * scale; + h = height * scale; + UI_AdjustFrom640( &x, &y, &w, &h ); + DC->drawStretchPic( x, y, w, h, s, t, s2, t2, hShader ); +} + +void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, + vec4_t color, const char* text, float adjust, int limit ) +{ + int len, count; + vec4_t newColor; + glyphInfo_t *glyph; + + if( text ) + { + const char *s = text; + float max = *maxX; + float useScale; + fontInfo_t *font = &DC->Assets.textFont; + + if( scale <= DC->getCVarValue( "ui_smallFont" ) ) + font = &DC->Assets.smallFont; + else if( scale > DC->getCVarValue( "ui_bigFont" ) ) + font = &DC->Assets.bigFont; + + useScale = scale * font->glyphScale; + DC->setColor( color ); + len = strlen( text ); + + if( limit > 0 && len > limit ) + len = limit; + + count = 0; + + while( s && *s && count < len ) + { + float width, height, skip; + glyph = &font->glyphs[ (int)*s ]; + width = glyph->imageWidth * DC->aspectScale; + height = glyph->imageHeight; + skip = glyph->xSkip * DC->aspectScale; + + if( Q_IsColorString( s ) ) + { + memcpy( newColor, g_color_table[ ColorIndex( *(s+1) ) ], sizeof( newColor ) ); + newColor[ 3 ] = color[ 3 ]; + DC->setColor( newColor ); + s += 2; + continue; + } + else + { + float yadj = useScale * glyph->top; + + if( UI_Text_Width( s, useScale, 1 ) + x > max ) + { + *maxX = 0; + break; + } + + UI_Text_PaintChar( x, y - yadj, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + x += ( skip * useScale ) + adjust; + *maxX = x; + count++; + s++; + } + } + + DC->setColor( NULL ); + } +} + +void UI_Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style) { + int len, count; + vec4_t newColor; + glyphInfo_t *glyph; + float useScale; + fontInfo_t *font = &DC->Assets.textFont; + if (scale <= DC->getCVarValue( "ui_smallFont" )) { + font = &DC->Assets.smallFont; + } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + font = &DC->Assets.bigFont; + } + useScale = scale * font->glyphScale; + if (text) { + const char *s = text; + DC->setColor( color ); + memcpy(&newColor[0], &color[0], sizeof(vec4_t)); + len = strlen(text); + if (limit > 0 && len > limit) { + len = limit; + } + count = 0; + while (s && *s && count < len) { + float width, height, skip; + glyph = &font->glyphs[(int)*s]; + width = glyph->imageWidth * DC->aspectScale; + height = glyph->imageHeight; + skip = glyph->xSkip * DC->aspectScale; + + if ( Q_IsColorString( s ) ) { + memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) ); + newColor[3] = color[3]; + DC->setColor( newColor ); + s += 2; + continue; + } else { + float yadj = useScale * glyph->top; + if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) { + int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; + colorBlack[3] = newColor[3]; + DC->setColor( colorBlack ); + UI_Text_PaintChar(x + ofs, y - yadj + ofs, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph); + DC->setColor( newColor ); + colorBlack[3] = 1.0; + } + else if( style == ITEM_TEXTSTYLE_NEON ) + { + vec4_t glow, outer, inner, white; + + glow[ 0 ] = newColor[ 0 ] * 0.5; + glow[ 1 ] = newColor[ 1 ] * 0.5; + glow[ 2 ] = newColor[ 2 ] * 0.5; + glow[ 3 ] = newColor[ 3 ] * 0.2; + + outer[ 0 ] = newColor[ 0 ]; + outer[ 1 ] = newColor[ 1 ]; + outer[ 2 ] = newColor[ 2 ]; + outer[ 3 ] = newColor[ 3 ]; + + inner[ 0 ] = newColor[ 0 ] * 1.5 > 1.0f ? 1.0f : newColor[ 0 ] * 1.5; + inner[ 1 ] = newColor[ 1 ] * 1.5 > 1.0f ? 1.0f : newColor[ 1 ] * 1.5; + inner[ 2 ] = newColor[ 2 ] * 1.5 > 1.0f ? 1.0f : newColor[ 2 ] * 1.5; + inner[ 3 ] = newColor[ 3 ]; + + white[ 0 ] = white[ 1 ] = white[ 2 ] = white[ 3 ] = 1.0f; + + DC->setColor( glow ); + UI_Text_PaintChar( x - 1.5, y - yadj - 1.5, + width + 3, + height + 3, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + + DC->setColor( outer ); + UI_Text_PaintChar( x - 1, y - yadj - 1, + width + 2, + height + 2, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + + DC->setColor( inner ); + UI_Text_PaintChar( x - 0.5, y - yadj - 0.5, + width + 1, + height + 1, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + + DC->setColor( white ); + } + + UI_Text_PaintChar(x, y - yadj, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph); + + x += (skip * useScale) + adjust; + s++; + count++; + } + } + DC->setColor( NULL ); + } +} + +//FIXME: merge this with Text_Paint, somehow +void UI_Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style) { + int len, count; + vec4_t newColor; + glyphInfo_t *glyph, *glyph2; + float yadj; + float useScale; + fontInfo_t *font = &DC->Assets.textFont; + if (scale <= DC->getCVarValue( "ui_smallFont" )) { + font = &DC->Assets.smallFont; + } else if (scale >= DC->getCVarValue( "ui_bigFont" )) { + font = &DC->Assets.bigFont; + } + useScale = scale * font->glyphScale; + if (text) { + float width2, height2, skip2; + const char *s = text; + DC->setColor( color ); + memcpy(&newColor[0], &color[0], sizeof(vec4_t)); + len = strlen(text); + if (limit > 0 && len > limit) { + len = limit; + } + count = 0; + glyph2 = &font->glyphs[ (int) cursor]; + width2 = glyph2->imageWidth * DC->aspectScale; + height2 = glyph2->imageHeight; + skip2 = glyph2->xSkip * DC->aspectScale; + while (s && *s && count < len) { + float width, height, skip; + glyph = &font->glyphs[(int)*s]; + width = glyph->imageWidth * DC->aspectScale; + height = glyph->imageHeight; + skip = glyph->xSkip * DC->aspectScale; + + yadj = useScale * glyph->top; + if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE) { + int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2; + colorBlack[3] = newColor[3]; + DC->setColor( colorBlack ); + UI_Text_PaintChar(x + ofs, y - yadj + ofs, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph); + colorBlack[3] = 1.0; + DC->setColor( newColor ); + } + else if( style == ITEM_TEXTSTYLE_NEON ) + { + vec4_t glow, outer, inner, white; + + glow[ 0 ] = newColor[ 0 ] * 0.5; + glow[ 1 ] = newColor[ 1 ] * 0.5; + glow[ 2 ] = newColor[ 2 ] * 0.5; + glow[ 3 ] = newColor[ 3 ] * 0.2; + + outer[ 0 ] = newColor[ 0 ]; + outer[ 1 ] = newColor[ 1 ]; + outer[ 2 ] = newColor[ 2 ]; + outer[ 3 ] = newColor[ 3 ]; + + inner[ 0 ] = newColor[ 0 ] * 1.5 > 1.0f ? 1.0f : newColor[ 0 ] * 1.5; + inner[ 1 ] = newColor[ 1 ] * 1.5 > 1.0f ? 1.0f : newColor[ 1 ] * 1.5; + inner[ 2 ] = newColor[ 2 ] * 1.5 > 1.0f ? 1.0f : newColor[ 2 ] * 1.5; + inner[ 3 ] = newColor[ 3 ]; + + white[ 0 ] = white[ 1 ] = white[ 2 ] = white[ 3 ] = 1.0f; + + DC->setColor( glow ); + UI_Text_PaintChar( x - 1.5, y - yadj - 1.5, + width + 3, + height + 3, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + + DC->setColor( outer ); + UI_Text_PaintChar( x - 1, y - yadj - 1, + width + 2, + height + 2, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + + DC->setColor( inner ); + UI_Text_PaintChar( x - 0.5, y - yadj - 0.5, + width + 1, + height + 1, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph ); + + DC->setColor( white ); + } + + UI_Text_PaintChar(x, y - yadj, + width, + height, + useScale, + glyph->s, + glyph->t, + glyph->s2, + glyph->t2, + glyph->glyph); + + yadj = useScale * glyph2->top; + if (count == cursorPos && !((DC->realTime/BLINK_DIVISOR) & 1)) { + UI_Text_PaintChar(x, y - yadj, + width2, + height2, + useScale, + glyph2->s, + glyph2->t, + glyph2->s2, + glyph2->t2, + glyph2->glyph); + } + + x += (skip * useScale); + s++; + count++; + } + // need to paint cursor at end of text + if (cursorPos == len && !((DC->realTime/BLINK_DIVISOR) & 1)) { + yadj = useScale * glyph2->top; + UI_Text_PaintChar(x, y - yadj, + width2, + height2, + useScale, + glyph2->s, + glyph2->t, + glyph2->s2, + glyph2->t2, + glyph2->glyph); + + } + + DC->setColor( NULL ); + } +} commandDef_t commandList[] = { @@ -1545,6 +2081,7 @@ commandDef_t commandList[] = {"setitemcolor", &Script_SetItemColor}, // group/name {"setteamcolor", &Script_SetTeamColor}, // sets this background color to team color {"setfocus", &Script_SetFocus}, // sets this background color to team color + {"reset", &Script_Reset}, // resets the state of the item argument {"setplayermodel", &Script_SetPlayerModel}, // sets this background color to team color {"setplayerhead", &Script_SetPlayerHead}, // sets this background color to team color {"transition", &Script_Transition}, // group/name @@ -1724,24 +2261,24 @@ int Item_ListBox_ThumbPosition(itemDef_t *item) { max = Item_ListBox_MaxScroll(item); if (item->window.flags & WINDOW_HORIZONTAL) { - size = item->window.rect.w - (SCROLLBAR_SIZE * 2) - 2; + size = item->window.rect.w - (SCROLLBAR_WIDTH * 2) - 2; if (max > 0) { - pos = (size-SCROLLBAR_SIZE) / (float) max; + pos = (size-SCROLLBAR_WIDTH) / (float) max; } else { pos = 0; } pos *= listPtr->startPos; - return item->window.rect.x + 1 + SCROLLBAR_SIZE + pos; + return item->window.rect.x + 1 + SCROLLBAR_WIDTH + pos; } else { - size = item->window.rect.h - (SCROLLBAR_SIZE * 2) - 2; + size = item->window.rect.h - (SCROLLBAR_HEIGHT * 2) - 2; if (max > 0) { - pos = (size-SCROLLBAR_SIZE) / (float) max; + pos = (size-SCROLLBAR_HEIGHT) / (float) max; } else { pos = 0; } pos *= listPtr->startPos; - return item->window.rect.y + 1 + SCROLLBAR_SIZE + pos; + return item->window.rect.y + 1 + SCROLLBAR_HEIGHT + pos; } } @@ -1750,20 +2287,20 @@ int Item_ListBox_ThumbDrawPosition(itemDef_t *item) { if (itemCapture == item) { if (item->window.flags & WINDOW_HORIZONTAL) { - min = item->window.rect.x + SCROLLBAR_SIZE + 1; - max = item->window.rect.x + item->window.rect.w - 2*SCROLLBAR_SIZE - 1; - if (DC->cursorx >= min + SCROLLBAR_SIZE/2 && DC->cursorx <= max + SCROLLBAR_SIZE/2) { - return DC->cursorx - SCROLLBAR_SIZE/2; + min = item->window.rect.x + SCROLLBAR_WIDTH + 1; + max = item->window.rect.x + item->window.rect.w - 2*SCROLLBAR_WIDTH - 1; + if (DC->cursorx >= min + SCROLLBAR_WIDTH/2 && DC->cursorx <= max + SCROLLBAR_WIDTH/2) { + return DC->cursorx - SCROLLBAR_WIDTH/2; } else { return Item_ListBox_ThumbPosition(item); } } else { - min = item->window.rect.y + SCROLLBAR_SIZE + 1; - max = item->window.rect.y + item->window.rect.h - 2*SCROLLBAR_SIZE - 1; - if (DC->cursory >= min + SCROLLBAR_SIZE/2 && DC->cursory <= max + SCROLLBAR_SIZE/2) { - return DC->cursory - SCROLLBAR_SIZE/2; + min = item->window.rect.y + SCROLLBAR_HEIGHT + 1; + max = item->window.rect.y + item->window.rect.h - 2*SCROLLBAR_HEIGHT - 1; + if (DC->cursory >= min + SCROLLBAR_HEIGHT/2 && DC->cursory <= max + SCROLLBAR_HEIGHT/2) { + return DC->cursory - SCROLLBAR_HEIGHT/2; } else { return Item_ListBox_ThumbPosition(item); @@ -1841,13 +2378,14 @@ int Item_ListBox_OverLB(itemDef_t *item, float x, float y) { if (item->window.flags & WINDOW_HORIZONTAL) { // check if on left arrow r.x = item->window.rect.x; - r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE; - r.h = r.w = SCROLLBAR_SIZE; + r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT; + r.w = SCROLLBAR_WIDTH; + r.h = SCROLLBAR_HEIGHT; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_LEFTARROW; } // check if on right arrow - r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE; + r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_RIGHTARROW; } @@ -1857,24 +2395,25 @@ int Item_ListBox_OverLB(itemDef_t *item, float x, float y) { if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_THUMB; } - r.x = item->window.rect.x + SCROLLBAR_SIZE; + r.x = item->window.rect.x + SCROLLBAR_WIDTH; r.w = thumbstart - r.x; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_PGUP; } - r.x = thumbstart + SCROLLBAR_SIZE; - r.w = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE; + r.x = thumbstart + SCROLLBAR_WIDTH; + r.w = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_PGDN; } } else { - r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE; + r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH; r.y = item->window.rect.y; - r.h = r.w = SCROLLBAR_SIZE; + r.w = SCROLLBAR_WIDTH; + r.h = SCROLLBAR_HEIGHT; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_LEFTARROW; } - r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE; + r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_RIGHTARROW; } @@ -1883,13 +2422,13 @@ int Item_ListBox_OverLB(itemDef_t *item, float x, float y) { if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_THUMB; } - r.y = item->window.rect.y + SCROLLBAR_SIZE; + r.y = item->window.rect.y + SCROLLBAR_HEIGHT; r.h = thumbstart - r.y; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_PGUP; } - r.y = thumbstart + SCROLLBAR_SIZE; - r.h = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE; + r.y = thumbstart + SCROLLBAR_HEIGHT; + r.h = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT; if (Rect_ContainsPoint(&r, x, y)) { return WINDOW_LB_PGDN; } @@ -1912,7 +2451,7 @@ void Item_ListBox_MouseEnter(itemDef_t *item, float x, float y) if (listPtr->elementStyle == LISTBOX_IMAGE) { r.x = item->window.rect.x; r.y = item->window.rect.y; - r.h = item->window.rect.h - SCROLLBAR_SIZE; + r.h = item->window.rect.h - SCROLLBAR_HEIGHT; r.w = item->window.rect.w - listPtr->drawPadding; if (Rect_ContainsPoint(&r, x, y)) { listPtr->cursorPos = (int)((x - r.x) / listPtr->elementWidth) + listPtr->startPos; @@ -1927,7 +2466,7 @@ void Item_ListBox_MouseEnter(itemDef_t *item, float x, float y) } else if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN))) { r.x = item->window.rect.x; r.y = item->window.rect.y; - r.w = item->window.rect.w - SCROLLBAR_SIZE; + r.w = item->window.rect.w - SCROLLBAR_WIDTH; r.h = item->window.rect.h - listPtr->drawPadding; if (Rect_ContainsPoint(&r, x, y)) { listPtr->cursorPos = (int)((y - 2 - r.y) / listPtr->elementHeight) + listPtr->startPos; @@ -2156,14 +2695,14 @@ qboolean Item_ListBox_HandleKey(itemDef_t *item, int key, qboolean down, qboolea // Display_SetCaptureItem(item); } else { // select an item - if (DC->realTime < lastListBoxClickTime && listPtr->doubleClick) { - Item_RunScript(item, listPtr->doubleClick); - } - lastListBoxClickTime = DC->realTime + DOUBLE_CLICK_DELAY; if (item->cursorPos != listPtr->cursorPos) { item->cursorPos = listPtr->cursorPos; DC->feederSelection(item->special, item->cursorPos); } + if (DC->realTime < lastListBoxClickTime && listPtr->doubleClick) { + Item_RunScript(item, listPtr->doubleClick); + } + lastListBoxClickTime = DC->realTime + DOUBLE_CLICK_DELAY; } return qtrue; } @@ -2376,7 +2915,7 @@ static void Item_TextField_CalcPaintOffset( itemDef_t *item, char *buff ) // string that's visible if( buff[ item->cursorPos + 1 ] == '\0' ) { - while( DC->textWidth( &buff[ editPtr->paintOffset ], item->textscale, 0 ) <= + while( UI_Text_Width( &buff[ editPtr->paintOffset ], item->textscale, 0 ) <= ( editPtr->maxFieldWidth - EDIT_CURSOR_WIDTH ) && editPtr->paintOffset > 0 ) editPtr->paintOffset--; } @@ -2384,7 +2923,7 @@ static void Item_TextField_CalcPaintOffset( itemDef_t *item, char *buff ) buff[ item->cursorPos + 1 ] = '\0'; // Shift paintOffset so that the cursor is visible - while( DC->textWidth( &buff[ editPtr->paintOffset ], item->textscale, 0 ) > + while( UI_Text_Width( &buff[ editPtr->paintOffset ], item->textscale, 0 ) > ( editPtr->maxFieldWidth - EDIT_CURSOR_WIDTH ) ) editPtr->paintOffset++; } @@ -2514,12 +3053,23 @@ qboolean Item_TextField_HandleKey(itemDef_t *item, int key) case K_KP_UPARROW: newItem = Menu_SetNextCursorItem(item->parent); if( newItem && ( newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD ) ) + { g_editItem = newItem; + } + else + { + releaseFocus = qtrue; + goto exit; + } break; case K_ENTER: case K_KP_ENTER: case K_ESCAPE: + case K_MOUSE1: + case K_MOUSE2: + case K_MOUSE3: + case K_MOUSE4: releaseFocus = qtrue; goto exit; @@ -2565,13 +3115,13 @@ static void Scroll_ListBox_ThumbFunc(void *p) { if (DC->cursorx == si->xStart) { return; } - r.x = si->item->window.rect.x + SCROLLBAR_SIZE + 1; - r.y = si->item->window.rect.y + si->item->window.rect.h - SCROLLBAR_SIZE - 1; - r.h = SCROLLBAR_SIZE; - r.w = si->item->window.rect.w - (SCROLLBAR_SIZE*2) - 2; + r.x = si->item->window.rect.x + SCROLLBAR_WIDTH + 1; + r.y = si->item->window.rect.y + si->item->window.rect.h - SCROLLBAR_HEIGHT - 1; + r.w = si->item->window.rect.w - (SCROLLBAR_WIDTH*2) - 2; + r.h = SCROLLBAR_HEIGHT; max = Item_ListBox_MaxScroll(si->item); // - pos = (DC->cursorx - r.x - SCROLLBAR_SIZE/2) * max / (r.w - SCROLLBAR_SIZE); + pos = (DC->cursorx - r.x - SCROLLBAR_WIDTH/2) * max / (r.w - SCROLLBAR_WIDTH); if (pos < 0) { pos = 0; } @@ -2583,13 +3133,13 @@ static void Scroll_ListBox_ThumbFunc(void *p) { } else if (DC->cursory != si->yStart) { - r.x = si->item->window.rect.x + si->item->window.rect.w - SCROLLBAR_SIZE - 1; - r.y = si->item->window.rect.y + SCROLLBAR_SIZE + 1; - r.h = si->item->window.rect.h - (SCROLLBAR_SIZE*2) - 2; - r.w = SCROLLBAR_SIZE; + r.x = si->item->window.rect.x + si->item->window.rect.w - SCROLLBAR_WIDTH - 1; + r.y = si->item->window.rect.y + SCROLLBAR_HEIGHT + 1; + r.w = SCROLLBAR_WIDTH; + r.h = si->item->window.rect.h - (SCROLLBAR_HEIGHT*2) - 2; max = Item_ListBox_MaxScroll(si->item); // - pos = (DC->cursory - r.y - SCROLLBAR_SIZE/2) * max / (r.h - SCROLLBAR_SIZE); + pos = (DC->cursory - r.y - SCROLLBAR_HEIGHT/2) * max / (r.h - SCROLLBAR_HEIGHT); if (pos < 0) { pos = 0; } @@ -3167,37 +3717,37 @@ void Item_SetTextExtents(itemDef_t *item, int *width, int *height, const char *t *height = item->textRect.h; // keeps us from computing the widths and heights more than once - if (*width == 0 || (item->type == ITEM_TYPE_OWNERDRAW && item->textalignment == ITEM_ALIGN_CENTER)) { + if (*width == 0 || (item->type == ITEM_TYPE_OWNERDRAW && item->textalignment == ALIGN_CENTER)) { int originalWidth; - if (item->type == ITEM_TYPE_EDITFIELD && item->textalignment == ITEM_ALIGN_CENTER && item->cvar) { + if (item->type == ITEM_TYPE_EDITFIELD && item->textalignment == ALIGN_CENTER && item->cvar) { //FIXME: this will only be called once? char buff[256]; DC->getCVarString(item->cvar, buff, 256); - originalWidth = DC->textWidth(item->text, item->textscale, 0) + - DC->textWidth(buff, item->textscale, 0); + originalWidth = UI_Text_Width(item->text, item->textscale, 0) + + UI_Text_Width(buff, item->textscale, 0); } else { - originalWidth = DC->textWidth(item->text, item->textscale, 0); + originalWidth = UI_Text_Width(item->text, item->textscale, 0); } - *width = DC->textWidth(textPtr, item->textscale, 0); - *height = DC->textHeight(textPtr, item->textscale, 0); + *width = UI_Text_Width(textPtr, item->textscale, 0); + *height = UI_Text_Height(textPtr, item->textscale, 0); item->textRect.w = *width; item->textRect.h = *height; - if (item->textvalignment == ITEM_VALIGN_BOTTOM) { + if (item->textvalignment == VALIGN_BOTTOM) { item->textRect.y = item->textaligny + item->window.rect.h; - } else if (item->textvalignment == ITEM_VALIGN_CENTER) { + } else if (item->textvalignment == VALIGN_CENTER) { item->textRect.y = item->textaligny + ( ( *height + item->window.rect.h ) / 2.0f ); - } else if (item->textvalignment == ITEM_VALIGN_TOP) { + } else if (item->textvalignment == VALIGN_TOP) { item->textRect.y = item->textaligny + *height; } - if (item->textalignment == ITEM_ALIGN_LEFT) { + if (item->textalignment == ALIGN_LEFT) { item->textRect.x = item->textalignx; - } else if (item->textalignment == ITEM_ALIGN_CENTER) { + } else if (item->textalignment == ALIGN_CENTER) { item->textRect.x = item->textalignx + ( ( item->window.rect.w - originalWidth ) / 2.0f ); - } else if (item->textalignment == ITEM_ALIGN_RIGHT) { + } else if (item->textalignment == ALIGN_RIGHT) { item->textRect.x = item->textalignx + item->window.rect.w - originalWidth; } @@ -3271,8 +3821,14 @@ static const char *Item_Text_Wrap( const char *text, float scale, float width ) testLength = 1; eol = p; - - while( DC->textWidth( p, scale, testLength ) < width ) + q = p; + while( Q_IsColorString( q ) ) + q += 2; + q++; + while( Q_IsColorString( q ) ) + q += 2; + + while( UI_Text_Width( p, scale, testLength ) < width ) { if( testLength >= strlen( p ) ) { @@ -3465,14 +4021,14 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) { while( UI_NextWrapLine( &p, &x, &y ) ) { - DC->drawText( x, y, item->textscale, color, + UI_Text_Paint( x, y, item->textscale, color, p, 0, 0, item->textStyle ); } } else { char buff[ 1024 ]; - float fontHeight = DC->textEmHeight( item->textscale ); + float fontHeight = UI_Text_EmHeight( item->textscale ); const float lineSpacing = fontHeight * 0.4f; float lineHeight = fontHeight + lineSpacing; float textHeight; @@ -3508,15 +4064,15 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) switch( item->textvalignment ) { default: - case ITEM_VALIGN_BOTTOM: + case VALIGN_BOTTOM: paintY = y + ( h - textHeight ); break; - case ITEM_VALIGN_CENTER: + case VALIGN_CENTER: paintY = y + ( ( h - textHeight ) / 2.0f ); break; - case ITEM_VALIGN_TOP: + case VALIGN_TOP: paintY = y; break; } @@ -3543,7 +4099,7 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) lineItem.textStyle = item->textStyle; lineItem.text = buff; lineItem.textalignment = item->textalignment; - lineItem.textvalignment = ITEM_VALIGN_TOP; + lineItem.textvalignment = VALIGN_TOP; lineItem.textalignx = 0.0f; lineItem.textaligny = 0.0f; @@ -3566,7 +4122,7 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ) } Item_SetTextExtents( &lineItem, &width, &height, buff ); - DC->drawText( lineItem.textRect.x, lineItem.textRect.y, + UI_Text_Paint( lineItem.textRect.x, lineItem.textRect.y, lineItem.textscale, color, buff, 0, 0, lineItem.textStyle ); UI_AddCacheEntryLine( buff, lineItem.textRect.x, lineItem.textRect.y ); @@ -3661,7 +4217,7 @@ void Item_Text_Paint(itemDef_t *item) { if (item->textStyle == ITEM_TEXTSTYLE_SHADOWED || item->textStyle == ITEM_TEXTSTYLE_OUTLINESHADOWED) { Fade(&item->window.flags, &DC->Assets.shadowColor[3], DC->Assets.fadeClamp, &item->window.nextTime, DC->Assets.fadeCycle, qfalse); - DC->drawText(item->textRect.x + DC->Assets.shadowX, item->textRect.y + DC->Assets.shadowY, item->textscale, DC->Assets.shadowColor, textPtr, adjust); + UI_Text_Paint(item->textRect.x + DC->Assets.shadowX, item->textRect.y + DC->Assets.shadowY, item->textscale, DC->Assets.shadowColor, textPtr, adjust); } */ @@ -3678,10 +4234,10 @@ void Item_Text_Paint(itemDef_t *item) { // Text_Paint(item->textRect.x, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); // Text_Paint(item->textRect.x+1, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); // */ -// DC->drawText(item->textRect.x - 1, item->textRect.y + 1, item->textscale * 1.02, item->window.outlineColor, textPtr, adjust); +// UI_Text_Paint(item->textRect.x - 1, item->textRect.y + 1, item->textscale * 1.02, item->window.outlineColor, textPtr, adjust); // } - DC->drawText(item->textRect.x, item->textRect.y, item->textscale, color, textPtr, 0, 0, item->textStyle); + UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, color, textPtr, 0, 0, item->textStyle); } @@ -3719,7 +4275,7 @@ void Item_TextField_Paint(itemDef_t *item) editPtr->paintOffset = 0; // Shorten string to max viewable - while( DC->textWidth( buff + editPtr->paintOffset, item->textscale, 0 ) > + while( UI_Text_Width( buff + editPtr->paintOffset, item->textscale, 0 ) > ( editPtr->maxFieldWidth - cursorWidth ) && strlen( buff ) > 0 ) buff[ strlen( buff ) - 1 ] = '\0'; @@ -3732,7 +4288,7 @@ void Item_TextField_Paint(itemDef_t *item) if( editing ) { - DC->drawTextWithCursor( item->textRect.x + item->textRect.w + offset, + UI_Text_PaintWithCursor( item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, buff + editPtr->paintOffset, item->cursorPos - editPtr->paintOffset, @@ -3740,7 +4296,7 @@ void Item_TextField_Paint(itemDef_t *item) } else { - DC->drawText( item->textRect.x + item->textRect.w + offset, + UI_Text_Paint( item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, buff + editPtr->paintOffset, 0, editPtr->maxPaintChars, item->textStyle ); @@ -3765,9 +4321,9 @@ void Item_YesNo_Paint(itemDef_t *item) { offset = (item->text && *item->text) ? ITEM_VALUE_OFFSET : 0; if (item->text) { Item_Text_Paint(item); - DC->drawText(item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); + UI_Text_Paint(item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); } else { - DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); + UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); } } @@ -3786,9 +4342,9 @@ void Item_Multi_Paint(itemDef_t *item) { if (item->text) { Item_Text_Paint(item); - DC->drawText(item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); + UI_Text_Paint(item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); } else { - DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); + UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); } } @@ -4103,17 +4659,17 @@ void Item_Bind_Paint(itemDef_t *item) { if( g_bindItem == item && g_waitingForKey ) { - DC->drawText( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, + UI_Text_Paint( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, item->textscale, newColor, "Press key", 0, maxChars, item->textStyle); } else { BindingFromName(item->cvar); - DC->drawText( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, + UI_Text_Paint( item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, item->textscale, newColor, g_nameBind1, 0, maxChars, item->textStyle); } } else { - DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "FIXME" : "FIXME", 0, maxChars, item->textStyle); + UI_Text_Paint(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "FIXME" : "FIXME", 0, maxChars, item->textStyle); } } @@ -4323,6 +4879,19 @@ void Item_ListBox_Paint(itemDef_t *item) { qhandle_t image; qhandle_t optionalImage; listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; + menuDef_t *menu = (menuDef_t *)item->parent; + float one, two; + + if( menu->window.aspectBias != ASPECT_NONE || item->window.aspectBias != ASPECT_NONE ) + { + one = 1.0f * DC->aspectScale; + two = 2.0f * DC->aspectScale; + } + else + { + one = 1.0f; + two = 2.0f; + } // the listbox is horizontal or vertical and has a fixed size scroll bar going either direction // elements are enumerated from the DC and either text or image handles are acquired from the DC as well @@ -4331,24 +4900,25 @@ void Item_ListBox_Paint(itemDef_t *item) { count = DC->feederCount(item->special); // default is vertical if horizontal flag is not here if (item->window.flags & WINDOW_HORIZONTAL) { + //FIXME: unmaintained cruft? if( !listPtr->notselectable ) { // draw scrollbar in bottom of the window // bar x = item->window.rect.x + 1; - y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE - 1; - DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowLeft); - x += SCROLLBAR_SIZE - 1; - size = item->window.rect.w - (SCROLLBAR_SIZE * 2); - DC->drawHandlePic(x, y, size+1, SCROLLBAR_SIZE, DC->Assets.scrollBar); + y = item->window.rect.y + item->window.rect.h - SCROLLBAR_HEIGHT - 1; + DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowLeft); + x += SCROLLBAR_WIDTH - 1; + size = item->window.rect.w - (SCROLLBAR_WIDTH * 2); + DC->drawHandlePic(x, y, size+1, SCROLLBAR_HEIGHT, DC->Assets.scrollBar); x += size - 1; - DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowRight); + DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowRight); // thumb thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item); - if (thumb > x - SCROLLBAR_SIZE - 1) { - thumb = x - SCROLLBAR_SIZE - 1; + if (thumb > x - SCROLLBAR_WIDTH - 1) { + thumb = x - SCROLLBAR_WIDTH - 1; } - DC->drawHandlePic(thumb, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarThumb); + DC->drawHandlePic(thumb, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarThumb); // listPtr->endPos = listPtr->startPos; } @@ -4388,40 +4958,41 @@ void Item_ListBox_Paint(itemDef_t *item) { if( !listPtr->notselectable ) { // draw scrollbar to right side of the window - x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE - 1; + x = item->window.rect.x + item->window.rect.w - SCROLLBAR_WIDTH - one; y = item->window.rect.y + 1; - DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowUp); - y += SCROLLBAR_SIZE - 1; + DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowUp); + y += SCROLLBAR_HEIGHT - 1; listPtr->endPos = listPtr->startPos; - size = item->window.rect.h - (SCROLLBAR_SIZE * 2); - DC->drawHandlePic(x, y, SCROLLBAR_SIZE, size+1, DC->Assets.scrollBar); + size = item->window.rect.h - (SCROLLBAR_HEIGHT * 2); + DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, size+1, DC->Assets.scrollBar); y += size - 1; - DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowDown); + DC->drawHandlePic(x, y, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarArrowDown); // thumb thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item); - if (thumb > y - SCROLLBAR_SIZE - 1) { - thumb = y - SCROLLBAR_SIZE - 1; + if (thumb > y - SCROLLBAR_HEIGHT - 1) { + thumb = y - SCROLLBAR_HEIGHT - 1; } - DC->drawHandlePic(x, thumb, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarThumb); + DC->drawHandlePic(x, thumb, SCROLLBAR_WIDTH, SCROLLBAR_HEIGHT, DC->Assets.scrollBarThumb); } // adjust size for item painting size = item->window.rect.h - 2; if (listPtr->elementStyle == LISTBOX_IMAGE) { // fit = 0; - x = item->window.rect.x + 1; + x = item->window.rect.x + one; y = item->window.rect.y + 1; for (i = listPtr->startPos; i < count; i++) { // always draw at least one // which may overdraw the box if it is too small for the element image = DC->feederItemImage(item->special, i); if (image) { - DC->drawHandlePic(x+1, y+1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image); + DC->drawHandlePic(x+one, y+1, listPtr->elementWidth - two, listPtr->elementHeight - 2, image); } if (i == item->cursorPos) { - DC->drawRect(x, y, listPtr->elementWidth - 1, listPtr->elementHeight - 1, item->window.borderSize, item->window.borderColor); + DC->drawRect( x, y, listPtr->elementWidth - one, listPtr->elementHeight - 1, + item->window.borderSize, item->window.borderColor); } listPtr->endPos++; @@ -4434,8 +5005,8 @@ void Item_ListBox_Paint(itemDef_t *item) { // fit++; } } else { - float m = DC->textEmHeight( item->textscale ); - x = item->window.rect.x + 1; + float m = UI_Text_EmHeight( item->textscale ); + x = item->window.rect.x + one; y = item->window.rect.y + 1; for (i = listPtr->startPos; i < count; i++) { char text[ MAX_STRING_CHARS ]; @@ -4445,60 +5016,82 @@ void Item_ListBox_Paint(itemDef_t *item) { if (listPtr->numColumns > 0) { int j; for (j = 0; j < listPtr->numColumns; j++) { + float columnPos; + float width, height; + + if( menu->window.aspectBias != ASPECT_NONE || item->window.aspectBias != ASPECT_NONE ) + { + columnPos = ( listPtr->columnInfo[ j ].pos + 4.0f ) * DC->aspectScale; + width = listPtr->columnInfo[ j ].width * DC->aspectScale; + } + else + { + columnPos = ( listPtr->columnInfo[ j ].pos + 4.0f ); + width = listPtr->columnInfo[ j ].width; + } + + height = listPtr->columnInfo[ j ].width; + Q_strncpyz( text, DC->feederItemText(item->special, i, j, &optionalImage), sizeof( text ) ); if (optionalImage >= 0) { - DC->drawHandlePic(x + 4 + listPtr->columnInfo[j].pos, - y + ( ( listPtr->elementHeight - listPtr->columnInfo[ j ].width ) / 2.0f ), - listPtr->columnInfo[j].width, listPtr->columnInfo[j].width, optionalImage); + DC->drawHandlePic( x + columnPos, y + ( ( listPtr->elementHeight - height ) / 2.0f ), + width, height, optionalImage); } else if (text) { int alignOffset = 0.0f, tw; - tw = DC->textWidth( text, item->textscale, 0 ); + tw = UI_Text_Width( text, item->textscale, 0 ); // Shorten the string if it's too long - while( tw > listPtr->columnInfo[ j ].width && strlen( text ) > 0 ) + while( tw > width && strlen( text ) > 0 ) { text[ strlen( text ) - 1 ] = '\0'; - tw = DC->textWidth( text, item->textscale, 0 ); + tw = UI_Text_Width( text, item->textscale, 0 ); } switch( listPtr->columnInfo[ j ].align ) { - case ITEM_ALIGN_LEFT: + case ALIGN_LEFT: alignOffset = 0.0f; break; - case ITEM_ALIGN_RIGHT: - alignOffset = listPtr->columnInfo[ j ].width - tw; + case ALIGN_RIGHT: + alignOffset = width - tw; break; - case ITEM_ALIGN_CENTER: - alignOffset = ( listPtr->columnInfo[ j ].width / 2.0f ) - ( tw / 2.0f ); + case ALIGN_CENTER: + alignOffset = ( width / 2.0f ) - ( tw / 2.0f ); break; default: alignOffset = 0.0f; } - DC->drawText( x + 4 + listPtr->columnInfo[j].pos + alignOffset, + UI_Text_Paint( x + columnPos + alignOffset, y + m + ( ( listPtr->elementHeight - m ) / 2.0f ), item->textscale, item->window.foreColor, text, 0, 0, item->textStyle ); } } } else { + float offset; + + if( menu->window.aspectBias != ASPECT_NONE || item->window.aspectBias != ASPECT_NONE ) + offset = 4.0f * DC->aspectScale; + else + offset = 4.0f; + Q_strncpyz( text, DC->feederItemText(item->special, i, 0, &optionalImage), sizeof( text ) ); if (optionalImage >= 0) { - DC->drawHandlePic(x + 4, y, listPtr->elementHeight, listPtr->elementHeight, optionalImage); + DC->drawHandlePic(x + offset, y, listPtr->elementHeight, listPtr->elementHeight, optionalImage); } else if (text) { - DC->drawText( x + 4, y + m + ( ( listPtr->elementHeight - m ) / 2.0f ), + UI_Text_Paint( x + offset, y + m + ( ( listPtr->elementHeight - m ) / 2.0f ), item->textscale, item->window.foreColor, text, 0, 0, item->textStyle ); } } if (i == item->cursorPos) { - DC->fillRect( x, y, item->window.rect.w - SCROLLBAR_SIZE - ( 2 * item->window.borderSize ), + DC->fillRect( x, y, item->window.rect.w - SCROLLBAR_WIDTH - ( two * item->window.borderSize ), listPtr->elementHeight, item->window.outlineColor); } @@ -4563,7 +5156,7 @@ void Item_OwnerDraw_Paint(itemDef_t *item) { if (item->text && *item->text) { Item_Text_Paint(item); - DC->drawText(item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, + UI_Text_Paint(item->textRect.x + item->textRect.w + ITEM_VALUE_OFFSET, item->textRect.y, item->textscale, color, text, 0, 0, item->textStyle); } else { @@ -4783,6 +5376,7 @@ void Menu_Init(menuDef_t *menu) { menu->fadeClamp = DC->Assets.fadeClamp; menu->fadeCycle = DC->Assets.fadeCycle; Window_Init(&menu->window); + menu->window.aspectBias = ALIGN_CENTER; } itemDef_t *Menu_GetFocusedItem(menuDef_t *menu) { @@ -4885,6 +5479,7 @@ void Item_Init(itemDef_t *item) { memset(item, 0, sizeof(itemDef_t)); item->textscale = 0.55f; Window_Init(&item->window); + item->window.aspectBias = ASPECT_NONE; } void Menu_HandleMouseMove(menuDef_t *menu, float x, float y) { @@ -5224,6 +5819,14 @@ qboolean ItemParse_rect( itemDef_t *item, int handle ) { return qtrue; } +// aspectBias <bias> +qboolean ItemParse_aspectBias( itemDef_t *item, int handle ) { + if (!PC_Int_Parse(handle, &item->window.aspectBias)) { + return qfalse; + } + return qtrue; +} + // style <integer> qboolean ItemParse_style( itemDef_t *item, int handle ) { if (!PC_Int_Parse(handle, &item->window.style)) { @@ -5839,6 +6442,7 @@ keywordHash_t itemParseKeywords[] = { {"model_rotation", ItemParse_model_rotation, NULL}, {"model_angle", ItemParse_model_angle, NULL}, {"rect", ItemParse_rect, NULL}, + {"aspectBias", ItemParse_aspectBias, NULL}, {"style", ItemParse_style, NULL}, {"decoration", ItemParse_decoration, NULL}, {"notselectable", ItemParse_notselectable, NULL}, @@ -6015,6 +6619,14 @@ qboolean MenuParse_rect( itemDef_t *item, int handle ) { return qtrue; } +qboolean MenuParse_aspectBias( itemDef_t *item, int handle ) { + menuDef_t *menu = (menuDef_t*)item; + if (!PC_Int_Parse(handle, &menu->window.aspectBias)) { + return qfalse; + } + return qtrue; +} + qboolean MenuParse_style( itemDef_t *item, int handle ) { menuDef_t *menu = (menuDef_t*)item; if (!PC_Int_Parse(handle, &menu->window.style)) { @@ -6270,6 +6882,7 @@ keywordHash_t menuParseKeywords[] = { {"name", MenuParse_name, NULL}, {"fullscreen", MenuParse_fullscreen, NULL}, {"rect", MenuParse_rect, NULL}, + {"aspectBias", MenuParse_aspectBias, NULL}, {"style", MenuParse_style, NULL}, {"visible", MenuParse_visible, NULL}, {"onOpen", MenuParse_onOpen, NULL}, @@ -6397,7 +7010,7 @@ void Menu_PaintAll( void ) { if (DC->getCVarValue( "ui_developer" )) { vec4_t v = {1, 1, 1, 1}; - DC->drawText(5, 25, .5, v, va("fps: %f", DC->FPS), 0, 0, 0); + UI_Text_Paint(5, 25, .5, v, va("fps: %f", DC->FPS), 0, 0, 0); } } @@ -6425,7 +7038,7 @@ void *Display_CaptureItem(int x, int y) { // FIXME: -qboolean Display_MouseMove(void *p, int x, int y) { +qboolean Display_MouseMove(void *p, float x, float y) { int i; menuDef_t *menu = p; diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h index 504d0ddf..30568e85 100644 --- a/src/ui/ui_shared.h +++ b/src/ui/ui_shared.h @@ -100,11 +100,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define ASSET_SCROLL_THUMB "ui/assets/scrollbar_thumb.tga" #define ASSET_SLIDER_BAR "ui/assets/slider2.tga" #define ASSET_SLIDER_THUMB "ui/assets/sliderbutt_1.tga" -#define SCROLLBAR_SIZE 16.0 -#define SLIDER_WIDTH 96.0 -#define SLIDER_HEIGHT 16.0 -#define SLIDER_THUMB_WIDTH 12.0 -#define SLIDER_THUMB_HEIGHT 20.0 +#define SCROLLBAR_SIZE 16.0f +#define SCROLLBAR_WIDTH (SCROLLBAR_SIZE*DC->aspectScale) +#define SCROLLBAR_HEIGHT SCROLLBAR_SIZE +#define SLIDER_WIDTH (96.0f*DC->aspectScale) +#define SLIDER_HEIGHT 16.0f +#define SLIDER_THUMB_WIDTH (12.0f*DC->aspectScale) +#define SLIDER_THUMB_HEIGHT 20.0f #define NUM_CROSSHAIRS 10 typedef struct { @@ -125,6 +127,7 @@ typedef rectDef_t Rectangle; // FIXME: do something to separate text vs window stuff typedef struct { Rectangle rect; // client coord rectangle + int aspectBias; // direction in which to aspect compensate Rectangle rectClient; // screen coord rectangle const char *name; // const char *group; // if it belongs to a group @@ -133,7 +136,7 @@ typedef struct { int style; // int border; // int ownerDraw; // ownerDraw style - int ownerDrawFlags; // show flags for ownerdraw items + int ownerDrawFlags; // show flags for ownerdraw items float borderSize; // int flags; // visible, focus, mouseover, cursor Rectangle rectEffects; // for various effects @@ -320,11 +323,6 @@ typedef struct { void (*setColor) (const vec4_t v); void (*drawHandlePic) (float x, float y, float w, float h, qhandle_t asset); void (*drawStretchPic) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); - void (*drawText) (float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style ); - float (*textWidth) (const char *text, float scale, int limit); - float (*textHeight) (const char *text, float scale, int limit); - float (*textEmWidth) (float scale); - float (*textEmHeight) (float scale); qhandle_t (*registerModel) (const char *p); void (*modelBounds) (qhandle_t model, vec3_t min, vec3_t max); void (*fillRect) ( float x, float y, float w, float h, const vec4_t color); @@ -371,11 +369,11 @@ typedef struct { float yscale; float xscale; - float bias; + float aspectScale; int realTime; int frameTime; - int cursorx; - int cursory; + float cursorx; + float cursory; qboolean debug; cachedAssets_t Assets; @@ -422,7 +420,7 @@ void Menus_Activate(menuDef_t *menu); displayContextDef_t *Display_GetContext( void ); void *Display_CaptureItem(int x, int y); -qboolean Display_MouseMove(void *p, int x, int y); +qboolean Display_MouseMove(void *p, float x, float y); int Display_CursorType(int x, int y); qboolean Display_KeyBindPending( void ); menuDef_t *Menus_FindByName(const char *p); @@ -452,6 +450,13 @@ void Item_Text_Wrapped_Paint( itemDef_t *item ); void UI_DrawTextBlock( rectDef_t *rect, float text_x, float text_y, vec4_t color, float scale, int textalign, int textvalign, int textStyle, const char *text ); +void UI_Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style); +void UI_Text_Paint_Limit( float *maxX, float x, float y, float scale, + vec4_t color, const char* text, float adjust, int limit ); +float UI_Text_Width(const char *text, float scale, int limit); +float UI_Text_Height(const char *text, float scale, int limit); +float UI_Text_EmWidth( float scale ); +float UI_Text_EmHeight( float scale ); int trap_Parse_AddGlobalDefine( char *define ); int trap_Parse_LoadSource( const char *filename ); |