static int JPLua_Export_Font_StringHeightPixels( lua_State *L ) { const char *text = lua_tostring(L, 1); float scale = lua_tonumber(L, 2); qhandle_t font = lua_tointeger(L, 3); qboolean customfont = lua_toboolean(L, 4); if (customfont) trap->R_Font_HeightPixels(font, scale); else lua_pushnumber( L, CG_Text_Height( text, scale, font ) ); return 1; }
static void DrawChatboxTabs( void ) { chatBox_t *cb = chatboxList; float xOffset = 0.0f; int cls_realtime = *(int *)0x8AF224; while ( cb ) { char *name = cb->shortname; float textWidth = CG_Text_Width( name, cg.chatbox.size.scale, JP_GetChatboxFont() ); float textHeight = CG_Text_Height( name, cg.chatbox.size.scale, JP_GetChatboxFont() ); CG_FillRect( cg.chatbox.pos.x + xOffset, cg.chatbox.pos.y + (cg_chatboxLineHeight.value*cg_chatboxLineCount.integer) + (textHeight*0.25f), textWidth+16.0f, cg_chatboxLineHeight.value, (cb==currentChatbox) ? &colorTable[CT_DKGREY] : &colorTable[CT_BLACK] ); CG_Text_Paint( cg.chatbox.pos.x + xOffset+8.0f, cg.chatbox.pos.y + (cg_chatboxLineHeight.value*cg_chatboxLineCount.integer), cg.chatbox.size.scale, &colorWhite, va( "^%c%s", (cb==currentChatbox) ? '2' : (cb->notification && ( (int)( cls_realtime >> 8 ) & 1 ) ) ? '1' : '7', cb->shortname ), 0.0f, 0, ITEM_TEXTSTYLE_OUTLINED, JP_GetChatboxFont() ); xOffset += textWidth + 16.0f; cb = cb->next; } }
static int JPLua_Export_Font_StringHeightPixels( lua_State *L ) { lua_pushnumber( L, CG_Text_Height( lua_tostring( L, 1 ), (float)lua_tonumber( L, 2 ), lua_tointeger( L, 3 ) ) ); return 1; }
int UI_DisplayContextCG::textHeight( const char *text, float scale, int limit ) { return CG_Text_Height( text, scale, limit ); }
/* ================= CG_DrawScoreboard ================= */ static void CG_DrawClientScore( int y, score_t *score, float *color, float fade, qboolean largeFormat ) { char string[1024]; vec3_t headAngles; clientInfo_t *ci; int iconx, headx; float scale = 0.35; int h = CG_Text_Height( "Tj", scale, 0 ); //int ty; if ( score->client < 0 || score->client >= cgs.maxclients ) { Com_Printf( "Bad score->client: %i\n", score->client ); return; } color[3] = fade; ci = &cgs.clientinfo[score->client]; iconx = SB_BOTICON_X + (SB_RATING_WIDTH / 2); headx = SB_HEAD_X + (SB_RATING_WIDTH / 2); // draw the handicap or bot skill marker (unless player has flag) if ( ci->powerups & ( 1 << PW_NEUTRALFLAG ) ) { if( largeFormat ) { CG_DrawFlagModel( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, TEAM_FREE, qfalse, SCR_CENTER ); } else { CG_DrawFlagModel( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, TEAM_FREE, qfalse, SCR_CENTER ); } } else if ( ci->powerups & ( 1 << PW_REDFLAG ) ) { if( largeFormat ) { CG_DrawFlagModel( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, TEAM_RED, qfalse, SCR_CENTER ); } else { CG_DrawFlagModel( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, TEAM_RED, qfalse, SCR_CENTER ); } } else if ( ci->powerups & ( 1 << PW_BLUEFLAG ) ) { if( largeFormat ) { CG_DrawFlagModel( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, TEAM_BLUE, qfalse, SCR_CENTER ); } else { CG_DrawFlagModel( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, TEAM_BLUE, qfalse, SCR_CENTER ); } } else { if ( ci->botSkill > 0 && ci->botSkill <= 5 ) { if ( cg_drawIcons.integer ) { if( largeFormat ) { CG_DrawColorPic( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, cgs.media.botSkillShaders[ci->botSkill - 1], SCR_CENTER, color ); } else { CG_DrawColorPic( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, cgs.media.botSkillShaders[ci->botSkill - 1], SCR_CENTER, color ); } } } else if ( ci->handicap < 100 ) { Com_sprintf( string, sizeof( string ), "%i", ci->handicap ); if ( gt[cgs.gametype].duel ) { if ( cg_highResFonts.integer ) { CG_Text_Paint( iconx, y + h + ((float)h/2), scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { CG_DrawSmallStringColor( iconx, y - SMALLCHAR_HEIGHT/2, string, color, SCR_CENTER ); } } else { if ( cg_highResFonts.integer ) { //w = CG_Text_Width(s, scale, 0); h = CG_Text_Height(string, scale, 0); CG_Text_Paint( iconx, y + h, scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { CG_DrawSmallStringColor( iconx, y, string, color, SCR_CENTER ); } } } // draw the wins / losses if ( gt[cgs.gametype].duel ) { Com_sprintf( string, sizeof( string ), "%i/%i", ci->wins, ci->losses ); if ( ci->handicap < 100 && !ci->botSkill ) { if ( cg_highResFonts.integer ) { CG_Text_Paint( iconx, y + h + ((float)h/2), scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { CG_DrawSmallStringColor( iconx, y + SMALLCHAR_HEIGHT/2, string, color, SCR_CENTER ); } } else { if ( cg_highResFonts.integer ) { CG_Text_Paint( iconx, y + h, scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { CG_DrawSmallStringColor( iconx, y, string, color, SCR_CENTER ); } } } } // draw the face VectorClear( headAngles ); headAngles[YAW] = 180; if ( largeFormat ) { CG_DrawHead( headx, y - SB_LARGE_SPACER*2, ICON_SIZE, ICON_SIZE, score->client, headAngles, SCR_CENTER, color ); } else { CG_DrawHead( headx, y + SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, score->client, headAngles, SCR_CENTER, color ); } // draw the score line // highlight your position if ( score->client == cg.snap->ps.clientNum ) { float hcolor[4]; int rank; localClient = qtrue; if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) { rank = -1; } else { rank = cg.snap->ps.persistant[PERS_RANK] & ~RANK_TIED_FLAG; } if ( rank == 0 ) { hcolor[0] = 0; hcolor[1] = 0; hcolor[2] = 0.7f; } else if ( rank == 1 ) { hcolor[0] = 0.7f; hcolor[1] = 0; hcolor[2] = 0; } else if ( rank == 2 ) { hcolor[0] = 0.7f; hcolor[1] = 0.7f; hcolor[2] = 0; } else { hcolor[0] = 0.4f; hcolor[1] = 0.4f; hcolor[2] = 0.4f; } hcolor[3] = fade * 0.7; /* CG_DrawTeamBackground( SB_SCORELINE_X + BIGCHAR_WIDTH + (SB_RATING_WIDTH / 2), y, SCREEN_WIDTH - SB_SCORELINE_X - BIGCHAR_WIDTH, BIGCHAR_HEIGHT+1, 1, gt[cgs.gametype].teams ? cg.snap->ps.persistant[PERS_TEAM] : hcolor, SCR_CENTER ); */ CG_FillRect( SB_SCORELINE_X + BIGCHAR_WIDTH + (SB_RATING_WIDTH / 2), y, SCREEN_WIDTH - SB_SCORELINE_X - BIGCHAR_WIDTH, BIGCHAR_HEIGHT+2, gt[cgs.gametype].teams ? CG_TeamColorDark(cg.snap->ps.persistant[PERS_TEAM], fade) : hcolor, SCR_CENTER ); } // draw client score strings if ( cg_highResFonts.integer ) { qboolean spec = ci->team == TEAM_SPECTATOR; int w; char *s; // score s = (score->ping == -1) ? "CONN" : spec ? "SPEC" : cg.warmup ? "-" : va("%i", score->score); w = CG_Text_Width( s, scale, 0 ); CG_Text_Paint( SB_SCORE_X + (SB_RATING_WIDTH / 2) + 64-w, y + h, scale, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); // ping s = va( "%i", score->ping ); w = CG_Text_Width( s, scale, 0 ); CG_Text_Paint( SB_PING_X - (SB_RATING_WIDTH + BIGCHAR_WIDTH )/2 + 64-w, y + h, scale, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); // time s = va( "%i", score->time ); //CG_IntToTime( score->time*1000, qtrue, qfalse ); w = CG_Text_Width( s, scale, 0 ); CG_Text_Paint( SB_TIME_X - (SB_RATING_WIDTH + BIGCHAR_WIDTH )/2 + 64-w, y + h, scale, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); // name CG_Text_Paint( SB_NAME_X - (SB_RATING_WIDTH / 2), y + h, scale, color, ci->name, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { if ( score->ping == -1 ) { Com_sprintf(string, sizeof(string), " connecting %s", ci->name); } else if ( ci->team == TEAM_SPECTATOR ) { Com_sprintf(string, sizeof(string), " SPECT %3i %4i %s", score->ping, score->time, ci->name); } else { Com_sprintf(string, sizeof(string), "%5i %4i %4i %s", score->score, score->ping, score->time, ci->name); } CG_DrawBigString( SB_SCORELINE_X + (SB_RATING_WIDTH / 2), y, string, fade, SCR_CENTER ); } // add the "ready" marker for intermission exiting if ( cg.snap->ps.stats[STAT_CLIENTS_READY] & ( 1 << score->client ) ) { if ( cg_highResFonts.integer ) { CG_Text_Paint( iconx, y + h, scale, color, "READY", 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { CG_DrawBigStringColor( iconx, y, "READY", color, SCR_CENTER ); } } }
/* ================= CG_DrawQ3Scoreboard Draw the normal in-game scoreboard ================= */ qboolean CG_DrawQ3Scoreboard( void ) { int x, y, w, i, n1, n2; float *fadeColor, fade; char *s; int maxClients; int lineHeight; int topBorderSize, bottomBorderSize; // don't draw anything if the menu or console is up if ( cg_paused.integer ) { cg.deferredPlayerLoading = 0; return qfalse; } if ( cgs.gametype == GT_SINGLE_PLAYER && cg.predictedPlayerState.pm_type == PM_INTERMISSION ) { cg.deferredPlayerLoading = 0; return qfalse; } // don't draw scoreboard during death while warmup up if ( cg.warmup && !cg.showScores && cg.time > cg.scoreFadeTime + FADE_TIME ) { return qfalse; } //#if 0 if ( cg.showScores || cg.predictedPlayerState.pm_type == PM_DEAD || cg.predictedPlayerState.pm_type == PM_INTERMISSION ) { fadeColor = colorWhite; } else { fadeColor = CG_FadeColor( cg.scoreFadeTime, FADE_TIME ); if ( !fadeColor ) { // next time scoreboard comes up, don't print killer cg.deferredPlayerLoading = 0; cg.killerName[0] = 0; return qfalse; } } //#endif //fadeColor = colorWhite; fade = fadeColor[3]; //#if 0 // request more scores regularly if ( cg.scoresRequestTime + 2000 < cg.time ) { cg.scoresRequestTime = cg.time; trap_SendClientCommand( "score" ); } //CG_Printf( "scoresRequestTime = %i\n", cg.scoresRequestTime ); //CG_Printf( "scoreFadeTime = %i, fade = %f\n", cg.scoreFadeTime, fade ); //#endif // fragged by ... line if ( !cg.warmup ) { if ( cg.killerName[0] ) { s = va( "Fragged by %s", cg.killerName ); y = 40; if ( cg_highResFonts.integer ) { float scale = 0.35; int h; w = CG_Text_Width(s, scale, 0); h = CG_Text_Height(s, scale, 0); x = (SCREEN_WIDTH - w) / 2; CG_Text_Paint( x, y + h, scale, fadeColor, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; x = ( SCREEN_WIDTH - w ) / 2; CG_DrawBigString( x, y, s, fade, SCR_CENTER ); } } // current rank { s = CG_GetGameStatusText(); if ( s[0] ) { y = 60; if ( cg_highResFonts.integer ) { float scale = 0.35f; int h; w = CG_Text_Width(s, scale, 0); h = CG_Text_Height(s, scale, 0); x = (SCREEN_WIDTH - w) / 2; CG_Text_Paint( x, y + h, scale, fadeColor, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER ); } else { w = CG_DrawStrlen( s ) * BIGCHAR_WIDTH; x = ( SCREEN_WIDTH - w ) / 2; CG_DrawBigString( x, y, s, fade, SCR_CENTER ); } } } } // scoreboard y = SB_HEADER; CG_DrawColorPic( SB_SCORE_X + (SB_RATING_WIDTH / 2), y, 64, 32, cgs.media.scoreboardScore, SCR_CENTER, fadeColor ); CG_DrawColorPic( SB_PING_X - (SB_RATING_WIDTH / 2), y, 64, 32, cgs.media.scoreboardPing, SCR_CENTER, fadeColor ); CG_DrawColorPic( SB_TIME_X - (SB_RATING_WIDTH / 2), y, 64, 32, cgs.media.scoreboardTime, SCR_CENTER, fadeColor ); CG_DrawColorPic( SB_NAME_X - (SB_RATING_WIDTH / 2), y, 64, 32, cgs.media.scoreboardName, SCR_CENTER, fadeColor ); y = SB_TOP; // If there are more than SB_MAXCLIENTS_NORMAL, use the interleaved scores if ( cg.numScores > SB_MAXCLIENTS_NORMAL ) { maxClients = SB_MAXCLIENTS_INTER; lineHeight = SB_INTER_HEIGHT; topBorderSize = 8; bottomBorderSize = 16; } else { maxClients = SB_MAXCLIENTS_NORMAL; lineHeight = SB_NORMAL_HEIGHT; topBorderSize = 16; bottomBorderSize = 16; } localClient = qfalse; if ( gt[cgs.gametype].teams ) { float team_opacity = 0.33f; // // teamplay scoreboard // y += lineHeight/2; if ( cg.teamScores[0] >= cg.teamScores[1] ) { n1 = CG_TeamScoreCount( TEAM_RED, maxClients ); CG_DrawTeamBackground( 0, y - topBorderSize, SCREEN_WIDTH, n1 * lineHeight + bottomBorderSize, team_opacity, TEAM_RED, SCR_NONE ); CG_TeamScoreboard( y, TEAM_RED, fade, maxClients, lineHeight ); y += (n1 * lineHeight) + BIGCHAR_HEIGHT; maxClients -= n1; n2 = CG_TeamScoreCount( TEAM_BLUE, maxClients ); CG_DrawTeamBackground( 0, y - topBorderSize, SCREEN_WIDTH, n2 * lineHeight + bottomBorderSize, team_opacity, TEAM_BLUE, SCR_NONE ); CG_TeamScoreboard( y, TEAM_BLUE, fade, maxClients, lineHeight ); y += (n2 * lineHeight) + BIGCHAR_HEIGHT; maxClients -= n2; } else { n1 = CG_TeamScoreCount( TEAM_BLUE, maxClients ); CG_DrawTeamBackground( 0, y - topBorderSize, SCREEN_WIDTH, n1 * lineHeight + bottomBorderSize, team_opacity, TEAM_BLUE, SCR_NONE ); CG_TeamScoreboard( y, TEAM_BLUE, fade, maxClients, lineHeight ); y += (n1 * lineHeight) + BIGCHAR_HEIGHT; maxClients -= n1; n2 = CG_TeamScoreCount( TEAM_RED, maxClients ); CG_DrawTeamBackground( 0, y - topBorderSize, SCREEN_WIDTH, n2 * lineHeight + bottomBorderSize, team_opacity, TEAM_RED, SCR_NONE ); CG_TeamScoreboard( y, TEAM_RED, fade, maxClients, lineHeight ); y += (n2 * lineHeight) + BIGCHAR_HEIGHT; maxClients -= n2; } /* n1 = CG_TeamScoreCount( TEAM_SPECTATOR, maxClients ); CG_TeamScoreboard( y, TEAM_SPECTATOR, fade, maxClients, lineHeight ); */ n1 = CG_TeamScoreboard( y, TEAM_SPECTATOR, fade, maxClients, lineHeight ); y += (n1 * lineHeight) + BIGCHAR_HEIGHT; } else { // // free for all scoreboard // /* n1 = CG_TeamScoreCount( TEAM_SPECTATOR, maxClients ); CG_TeamScoreboard( y, TEAM_FREE, fade, maxClients, lineHeight ); y += (n1 * lineHeight) + BIGCHAR_HEIGHT; n2 = CG_TeamScoreCount( TEAM_SPECTATOR, maxClients ); CG_TeamScoreboard( y, TEAM_SPECTATOR, fade, maxClients - n1, lineHeight ); y += (n2 * lineHeight) + BIGCHAR_HEIGHT; */ n1 = CG_TeamScoreboard( y, TEAM_FREE, fade, maxClients, lineHeight ); y += (n1 * lineHeight) + BIGCHAR_HEIGHT; n2 = CG_TeamScoreboard( y, TEAM_SPECTATOR, fade, maxClients - n1, lineHeight ); y += (n2 * lineHeight) + BIGCHAR_HEIGHT; } if (!localClient) { // draw local client at the bottom for ( i = 0 ; i < cg.numScores ; i++ ) { if ( cg.scores[i].client == cg.snap->ps.clientNum ) { CG_DrawClientScore( y, &cg.scores[i], fadeColor, fade, lineHeight == SB_NORMAL_HEIGHT ); break; } } } // load any models that have been deferred if ( ++cg.deferredPlayerLoading > 10 ) { CG_LoadDeferredPlayers(); } return qtrue; }