Fix subtitles rendering; Fix rendering of other centered texts

This commit is contained in:
Petr Bartos 2023-03-28 23:21:28 +02:00 committed by Simon
parent 40128567be
commit 94e82c2da3
8 changed files with 61 additions and 55 deletions

View file

@ -3666,11 +3666,11 @@ static void CG_DrawAmmoWarning( void ) {
}
w = cgi_R_Font_StrLenPixels(text, cgs.media.qhFontSmall, FONT_SCALE);
int tempX = 320 - w/2;
int offset = w / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = 64;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, text, colorTable[CT_LTGOLD1], cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, text, colorTable[CT_LTGOLD1], cgs.media.qhFontSmall, -1, FONT_SCALE);
}
//---------------------------------------
@ -4236,9 +4236,7 @@ static void CG_Draw2D( void )
CG_DrawScrollText();
if (!vr->immersive_cinematics) {
CG_DrawCaptionText();
}
CG_DrawCaptionText( in_camera && vr->immersive_cinematics );
if ( in_camera )
{//still draw the saber clash flare, but nothing else
@ -4370,30 +4368,34 @@ static void CG_Draw2D( void )
cgi_SP_GetStringTextString( "SP_INGAME_NEW_OBJECTIVE_INFO", text, sizeof(text) );
int x_pos = 0;
int offset = 0;
y_pos = 20;
w = cgi_R_Font_StrLenPixels(text,cgs.media.qhFontSmall, FONT_SCALE);
x_pos = (SCREEN_WIDTH/2)-(w/2);
offset = w / 2;
x_pos = SCREEN_WIDTH / 2;
int tempX = x_pos;
int tempY = y_pos;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
}
}
if (cg.weaponPickupTextTime > cg.time )
{
int x_pos = 0;
int offset = 0;
y_pos = 5;
gi.Cvar_VariableStringBuffer( "cg_WeaponPickupText", text, sizeof(text) );
w = cgi_R_Font_StrLenPixels(text,cgs.media.qhFontSmall, FONT_SCALE);
x_pos = (SCREEN_WIDTH/2)-(w/2);
offset = w / 2;
x_pos = SCREEN_WIDTH / 2;
int tempX = x_pos;
int tempY = y_pos;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, text, colorTable[CT_WHITE], cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, text, colorTable[CT_WHITE], cgs.media.qhFontSmall, -1, FONT_SCALE);
}
cg.drawingHUD = CG_HUD_NORMAL;

View file

@ -28,7 +28,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
if (cg.drawingHUD && !vr->cin_camera && !vr->using_screen_layer)
if (cg.drawingHUD && (!vr->cin_camera || vr->immersive_cinematics) && !vr->using_screen_layer)
{
float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.0f);
float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.25f);

View file

@ -820,7 +820,7 @@ void CG_CaptionTextStop( void );
// cg_text.c
//
void CG_DrawScrollText( void );
void CG_DrawCaptionText( void );
void CG_DrawCaptionText( bool inImmersiveCamera );
void CG_DrawCenterString( void );

View file

@ -262,7 +262,7 @@ void CG_CaptionText( const char *str, int sound)
if (in_camera) {
cg.captionTextY = SCREEN_HEIGHT - (client_camera.bar_height_dest/2); // ths is now a centre'd Y, not a start Y
} else { //get above the hud
cg.captionTextY = (int) (0.88f*((float)SCREEN_HEIGHT - (float)fontHeight * 1.5f)); // do NOT move this, it has to fit in between the weapon HUD and the datapad update.
cg.captionTextY = (int) (0.80f*((float)SCREEN_HEIGHT - (float)fontHeight * 1.5f)); // do NOT move this, it has to fit in between the weapon HUD and the datapad update.
}
cg.captionTextCurrentLine = 0;
@ -389,7 +389,7 @@ void CG_CaptionText( const char *str, int sound)
}
void CG_DrawCaptionText(void)
void CG_DrawCaptionText( bool inImmersiveCamera )
{
int i;
int x, y, w;
@ -442,22 +442,24 @@ void CG_DrawCaptionText(void)
// Set Y of the first line (varies if only printing one line of text)
// (this all works, please don't mess with it)
const int fontHeight = (int) ((cgi_Language_IsAsian() ? 1.4f : 1.0f) * (float) cgi_R_Font_HeightPixels(cgs.media.qhFontSmall, fFontScale * FONT_SCALE));
const int fontHeight = (int) (3.0f * (float) cgi_R_Font_HeightPixels(cgs.media.qhFontSmall, fFontScale * FONT_SCALE));
const bool bPrinting2Lines = !!(cg.captionText[ cg.captionTextCurrentLine+1 ][0]);
y = cg.captionTextY - ( (float)fontHeight * (bPrinting2Lines ? 1 : 0.5f)); // captionTextY was a centered Y pos, not a top one
y -= cgi_Language_IsAsian() ? 0 : 4;
if (inImmersiveCamera) {
y -= 100;
}
for (i= cg.captionTextCurrentLine;i< cg.captionTextCurrentLine + 2;++i)
{
w = cgi_R_Font_StrLenPixels(cg.captionText[i], cgs.media.qhFontSmall, fFontScale * FONT_SCALE);
if (w)
{
x = (SCREEN_WIDTH-w) / 2;
int tempX = x;
int offset = w / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = y;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, cg.captionText[i], textcolor_caption, cgs.media.qhFontSmall, -1, fFontScale * FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, cg.captionText[i], textcolor_caption, cgs.media.qhFontSmall, -1, fFontScale * FONT_SCALE);
y += fontHeight;
}
}
@ -650,12 +652,11 @@ void CG_DrawScrollText(void)
// w = cgi_R_Font_StrLenPixels(cg.printText[i], cgs.media.qhFontMedium, 1.0f);
// if (w)
{
x = (SCREEN_WIDTH - giScrollTextPixelWidth) / 2;
int tempX = x;
int offset = giScrollTextPixelWidth / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = y;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, cg.printText[i], textcolor_scroll, cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, cg.printText[i], textcolor_scroll, cgs.media.qhFontSmall, -1, FONT_SCALE);
y += fontHeight;
}
}
@ -777,12 +778,11 @@ void CG_DrawCenterString( void )
w = cgi_R_Font_StrLenPixels(linebuffer, cgs.media.qhFontSmall, FONT_SCALE);
x = ( SCREEN_WIDTH - w ) / 2;
int tempX = x;
int offset = w / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = y;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY,linebuffer, textcolor_center, cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY,linebuffer, textcolor_center, cgs.media.qhFontSmall, -1, FONT_SCALE);
y += fontHeight;

View file

@ -2502,10 +2502,12 @@ static void CG_DrawAmmoWarning( void ) {
//s = "LOW AMMO WARNING";
}
int tempX = 320 - w/2;
w = cgi_R_Font_StrLenPixels(text,cgs.media.qhFontSmall, FONT_SCALE);
int offset = w / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = 64;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, text, colorTable[CT_LTGOLD1], cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, text, colorTable[CT_LTGOLD1], cgs.media.qhFontSmall, -1, FONT_SCALE);
}
//---------------------------------------
@ -2728,9 +2730,7 @@ static void CG_Draw2D( void )
CG_DrawScrollText();
if (!vr->immersive_cinematics) {
CG_DrawCaptionText();
}
CG_DrawCaptionText( in_camera && vr->immersive_cinematics );
if ( in_camera )
{//still draw the saber clash flare, but nothing else
@ -2842,17 +2842,19 @@ static void CG_Draw2D( void )
cgi_SP_GetStringTextString( "INGAME_DATAPAD_UPDATED", text, sizeof(text) );
int x_pos = 0;
int offset = 0;
y_pos = (SCREEN_HEIGHT/2)+80;
if ( cg_missionInfoCentered.integer )
{
w = cgi_R_Font_StrLenPixels(text,cgs.media.qhFontSmall, FONT_SCALE);
x_pos = (SCREEN_WIDTH/2)-(w/2);
offset = w / 2;
x_pos = SCREEN_WIDTH / 2;
}
int tempX = x_pos;
int tempY = y_pos;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
if (cg_updatedDataPadForcePower1.integer)
{
@ -2861,13 +2863,14 @@ static void CG_Draw2D( void )
if ( cg_missionInfoCentered.integer )
{
w = cgi_R_Font_StrLenPixels(text,cgs.media.qhFontSmall, FONT_SCALE);
x_pos = (SCREEN_WIDTH/2)-(w/2);
offset = w / 2;
x_pos = SCREEN_WIDTH / 2;
}
tempX = x_pos;
tempY = y_pos;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
}
if (cg_updatedDataPadObjective.integer)
@ -2877,13 +2880,14 @@ static void CG_Draw2D( void )
if ( cg_missionInfoCentered.integer )
{
w = cgi_R_Font_StrLenPixels(text,cgs.media.qhFontSmall, FONT_SCALE);
x_pos = (SCREEN_WIDTH/2)-(w/2);
offset = w / 2;
x_pos = SCREEN_WIDTH / 2;
}
tempX = x_pos;
tempY = y_pos;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, text, colorTable[CT_LTRED1], cgs.media.qhFontSmall, -1, FONT_SCALE);
}
// if (cent->gent->client->sess.missionObjectivesShown<3)

View file

@ -27,7 +27,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
if (cg.drawingHUD && !vr->cin_camera && !vr->using_screen_layer)
if (cg.drawingHUD && (!vr->cin_camera || vr->immersive_cinematics) && !vr->using_screen_layer)
{
float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.0f);
float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.25f);

View file

@ -801,7 +801,7 @@ void CG_GameText(int y );
// cg_text.c
//
void CG_DrawScrollText( void );
void CG_DrawCaptionText( void );
void CG_DrawCaptionText( bool inImmersiveCamera );
void CG_DrawCenterString( void );

View file

@ -259,7 +259,7 @@ void CG_CaptionText( const char *str, int sound)
if (in_camera) {
cg.captionTextY = SCREEN_HEIGHT - (client_camera.bar_height_dest/2); // ths is now a centre'd Y, not a start Y
} else { //get above the hud
cg.captionTextY = (int) (0.88f*((float)SCREEN_HEIGHT - (float)fontHeight * 1.5f)); // do NOT move this, it has to fit in between the weapon HUD and the datapad update.
cg.captionTextY = (int) (0.84f*((float)SCREEN_HEIGHT - (float)fontHeight * 1.5f)); // do NOT move this, it has to fit in between the weapon HUD and the datapad update.
}
cg.captionTextCurrentLine = 0;
@ -385,7 +385,7 @@ void CG_CaptionText( const char *str, int sound)
}
void CG_DrawCaptionText(void)
void CG_DrawCaptionText( bool inImmersiveCamera )
{
int i;
int x, y, w;
@ -438,22 +438,24 @@ void CG_DrawCaptionText(void)
// Set Y of the first line (varies if only printing one line of text)
// (this all works, please don't mess with it)
const int fontHeight = (int) ((cgi_Language_IsAsian() ? 1.4f : 1.0f) * (float) cgi_R_Font_HeightPixels(cgs.media.qhFontSmall, fFontScale * FONT_SCALE));
const int fontHeight = (int) (3.0f * (float) cgi_R_Font_HeightPixels(cgs.media.qhFontSmall, fFontScale * FONT_SCALE));
const bool bPrinting2Lines = !!(cg.captionText[ cg.captionTextCurrentLine+1 ][0]);
y = cg.captionTextY - ( (float)fontHeight * (bPrinting2Lines ? 1 : 0.5f)); // captionTextY was a centered Y pos, not a top one
y -= cgi_Language_IsAsian() ? 0 : 4;
if (inImmersiveCamera) {
y -= 100;
}
for (i= cg.captionTextCurrentLine;i< cg.captionTextCurrentLine + 2;++i)
{
w = cgi_R_Font_StrLenPixels(cg.captionText[i], cgs.media.qhFontSmall, fFontScale * FONT_SCALE);
if (w)
{
x = (SCREEN_WIDTH-w) / 2;
int tempX = x;
int offset = w / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = y;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, cg.captionText[i], textcolor_caption, cgs.media.qhFontSmall, -1, fFontScale * FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, cg.captionText[i], textcolor_caption, cgs.media.qhFontSmall, -1, fFontScale * FONT_SCALE);
y += fontHeight;
}
}
@ -644,12 +646,11 @@ void CG_DrawScrollText(void)
// w = cgi_R_Font_StrLenPixels(cg.printText[i], cgs.media.qhFontMedium, 1.0f);
// if (w)
{
x = (SCREEN_WIDTH - giScrollTextPixelWidth) / 2;
int tempX = x;
int offset = giScrollTextPixelWidth / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = y;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY, cg.printText[i], textcolor_scroll, cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY, cg.printText[i], textcolor_scroll, cgs.media.qhFontSmall, -1, FONT_SCALE);
y += fontHeight;
}
}
@ -769,12 +770,11 @@ void CG_DrawCenterString( void )
w = cgi_R_Font_StrLenPixels(linebuffer, cgs.media.qhFontSmall, FONT_SCALE);
x = ( SCREEN_WIDTH - w ) / 2;
int tempX = x;
int offset = w / 2;
int tempX = SCREEN_WIDTH / 2;
int tempY = y;
CG_AdjustFrom640Int( &tempX, &tempY, NULL, NULL );
cgi_R_Font_DrawString(tempX, tempY,linebuffer, textcolor_center, cgs.media.qhFontSmall, -1, FONT_SCALE);
cgi_R_Font_DrawString(tempX - offset, tempY,linebuffer, textcolor_center, cgs.media.qhFontSmall, -1, FONT_SCALE);
y += fontHeight;