@@ -57,6 +57,11 @@ CChat::CChat ( CGUI* pManager, const CVector2D & vecPosition )
57
57
m_pCacheTexture = NULL ;
58
58
m_iCacheTextureRevision = 0 ;
59
59
m_iReportCount = 0 ;
60
+ m_fPositionOffsetX = 0.0125 ;
61
+ m_fPositionOffsetY = 0.0150 ;
62
+ m_ePositionHorizontal = Chat::Position::Horizontal::LEFT;
63
+ m_ePositionVertical = Chat::Position::Vertical::TOP;
64
+ m_eTextAlign = Chat::Text::Align::LEFT;
60
65
61
66
// Background area
62
67
m_pBackground = m_pManager->CreateStaticImage ();
@@ -125,46 +130,11 @@ void CChat::LoadCVars ( void )
125
130
CVARS_GET ( " chat_line_fade_out" , (unsigned int &)m_ulChatLineFadeOut );
126
131
CVARS_GET ( " chat_font" , (unsigned int &)Font ); SetChatFont ( (eChatFont)Font );
127
132
CVARS_GET ( " chat_nickcompletion" , m_bNickCompletion );
128
-
129
- CVector2D vecResolution = m_pManager->GetResolution ();
130
- float fLineDifference = CChat::GetFontHeight ( m_vecScale.fY );
131
- float fRelativeWidth = (m_vecBackgroundSize.fX / vecResolution.fX ),
132
- fRelativeHeight = ((m_vecBackgroundSize.fY + fLineDifference * 1 .25f ) / vecResolution.fY );
133
-
134
- int iHorizontal, iVertical;
135
- float fOffsetX , fOffsetY , fPosX , fPosY ;
136
- CVARS_GET ( " chat_position_offset_x" , fOffsetX );
137
- CVARS_GET ( " chat_position_offset_y" , fOffsetY );
138
- CVARS_GET ( " chat_position_horizontal" , iHorizontal );
139
- CVARS_GET ( " chat_position_vertical" , iVertical );
140
- switch ( iHorizontal )
141
- {
142
- case Chat::Position::Horizontal::RIGHT:
143
- fPosX = 1.0 - fRelativeWidth + fOffsetX ;
144
- break ;
145
- case Chat::Position::Horizontal::CENTER:
146
- fPosX = (1.0 - fRelativeWidth ) / 2 + fOffsetX ;
147
- break ;
148
- case Chat::Position::Horizontal::LEFT:
149
- default :
150
- fPosX = fOffsetX ;
151
- break ;
152
- }
153
- switch ( iVertical )
154
- {
155
- case Chat::Position::Vertical::BOTTOM:
156
- fPosY = 1.0 - fRelativeHeight + fOffsetY ;
157
- break ;
158
- case Chat::Position::Vertical::CENTER:
159
- fPosY = (1.0 - fRelativeHeight ) / 2 + fOffsetY ;
160
- break ;
161
- case Chat::Position::Vertical::TOP:
162
- default :
163
- fPosY = fOffsetY ;
164
- break ;
165
- }
166
- m_vecBackgroundPosition = CVector2D ( fPosX , fPosY ) * vecResolution;
167
- m_pBackground->SetPosition ( m_vecBackgroundPosition );
133
+ CVARS_GET ( " chat_position_offset_x" , m_fPositionOffsetX );
134
+ CVARS_GET ( " chat_position_offset_y" , m_fPositionOffsetY );
135
+ CVARS_GET ( " chat_position_horizontal" , (unsigned int &)m_ePositionHorizontal );
136
+ CVARS_GET ( " chat_position_vertical" , (unsigned int &)m_ePositionVertical );
137
+ CVARS_GET ( " chat_text_alignment" , (unsigned int &)m_eTextAlign );
168
138
169
139
// Modify default chat box to be like 'Transparent' preset
170
140
SString strFlags;
@@ -317,8 +287,6 @@ void CChat::Draw ( bool bUseCacheTexture )
317
287
//
318
288
void CChat::DrawDrawList ( const SDrawList& drawList, const CVector2D& topLeftOffset )
319
289
{
320
- CGraphics::GetSingleton ().BeginDrawBatch ();
321
-
322
290
CVector2D chatTopLeft ( drawList.renderBounds .fX1 , drawList.renderBounds .fY1 );
323
291
CVector2D chatBotRight ( drawList.renderBounds .fX2 , drawList.renderBounds .fY2 );
324
292
CVector2D chatSize = chatBotRight - chatTopLeft;
@@ -329,9 +297,10 @@ void CChat::DrawDrawList ( const SDrawList& drawList, const CVector2D& topLeftOf
329
297
chatBounds.fX2 += topLeftOffset.fX ;
330
298
chatBounds.fY2 += topLeftOffset.fY ;
331
299
332
- for ( uint i = 0 ; i < drawList.lineItemList .size () ; i++ )
300
+ CGraphics::GetSingleton ().BeginDrawBatch ();
301
+
302
+ for ( const auto & item : drawList.lineItemList )
333
303
{
334
- const SDrawListLineItem& item = drawList.lineItemList [i];
335
304
m_Lines [ item.uiLine ].Draw ( item.vecPosition - chatTopLeft + topLeftOffset, item.ucAlpha , drawList.bShadow , chatBounds );
336
305
}
337
306
@@ -347,6 +316,7 @@ void CChat::GetDrawList ( SDrawList& outDrawList )
347
316
{
348
317
float fLineDifference = CChat::GetFontHeight ( m_vecScale.fY );
349
318
CVector2D vecPosition ( m_vecBackgroundPosition.fX + ( 5 .0f * m_vecScale.fX ), m_vecBackgroundPosition.fY + m_vecBackgroundSize.fY - ( fLineDifference * 1 .25f ) );
319
+ float fMaxLineWidth = m_vecBackgroundSize.fX - ( 10 .0f * m_vecScale.fX );
350
320
unsigned long ulTime = GetTickCount32 ();
351
321
float fRcpChatLineFadeOut = 1 .0f / m_ulChatLineFadeOut;
352
322
bool bShadow = ( m_Color.A * m_fBackgroundAlpha == 0 .f );
@@ -400,9 +370,15 @@ void CChat::GetDrawList ( SDrawList& outDrawList )
400
370
401
371
if ( fLineAlpha > 0 .f )
402
372
{
373
+ CVector2D vecOffset;
374
+
375
+ if ( m_eTextAlign == Chat::Text::Align::RIGHT ) {
376
+ vecOffset.fX = fMaxLineWidth - m_Lines[ uiLine ].GetWidth ();
377
+ }
378
+
403
379
SDrawListLineItem item;
404
380
item.uiLine = uiLine;
405
- item.vecPosition = vecPosition;
381
+ item.vecPosition = vecPosition + vecOffset ;
406
382
item.ucAlpha = static_cast < unsigned char >( fLineAlpha * 255 .0f );
407
383
outDrawList.lineItemList .push_back ( item );
408
384
}
@@ -570,8 +546,10 @@ void CChat::ClearInput ( void )
570
546
m_strInputText.clear ();
571
547
m_InputLine.Clear ();
572
548
m_vecInputSize = CalcInputSize ();
573
- if ( m_pInput )
549
+ if ( m_pInput ) {
574
550
m_pInput->SetSize ( m_vecInputSize );
551
+ UpdatePosition ();
552
+ }
575
553
}
576
554
577
555
void CChat::ScrollUp ()
@@ -774,7 +752,7 @@ void CChat::SetInputVisible ( bool bVisible )
774
752
if ( !IsVisible () )
775
753
bVisible = false ;
776
754
777
- if ( bVisible )
755
+ if ( ! bVisible )
778
756
{
779
757
ClearInput ();
780
758
}
@@ -854,11 +832,6 @@ void CChat::UpdateGUI ( void )
854
832
m_vecBackgroundPosition.fY = Round ( m_vecBackgroundPosition.fY );
855
833
m_pBackground->SetSize ( m_vecBackgroundSize );
856
834
857
- m_vecInputPosition = CVector2D (
858
- m_vecBackgroundPosition.fX ,
859
- m_vecBackgroundPosition.fY + m_vecBackgroundSize.fY
860
- );
861
-
862
835
// Make sure there is enough room for all the lines
863
836
uint uiMaxNumLines = g_pCore->GetGraphics ()->GetViewportHeight () / std::max ( 1 .f , CChat::GetFontHeight ( m_vecScale.fY ) ) - 3 ;
864
837
if ( m_uiNumLines > uiMaxNumLines )
@@ -867,9 +840,60 @@ void CChat::UpdateGUI ( void )
867
840
m_vecInputSize = CalcInputSize ();
868
841
if ( m_pInput )
869
842
{
870
- m_pInput->SetPosition ( m_vecInputPosition );
871
843
m_pInput->SetSize ( m_vecInputSize );
872
844
}
845
+
846
+ UpdatePosition ();
847
+ }
848
+
849
+
850
+ void CChat::UpdatePosition ( void )
851
+ {
852
+ CVector2D vecResolution = m_pManager->GetResolution ();
853
+
854
+ float fRelativeWidth = ( m_vecBackgroundSize.fX / vecResolution.fX ),
855
+ fRelativeHeight = ( ( m_vecBackgroundSize.fY + m_vecInputSize.fY ) / vecResolution.fY ),
856
+ fPosX , fPosY ;
857
+
858
+ switch ( m_ePositionHorizontal )
859
+ {
860
+ case Chat::Position::Horizontal::RIGHT:
861
+ fPosX = 1.0 - fRelativeWidth + m_fPositionOffsetX;
862
+ break ;
863
+ case Chat::Position::Horizontal::CENTER:
864
+ fPosX = (1.0 - fRelativeWidth ) / 2 + m_fPositionOffsetX;
865
+ break ;
866
+ case Chat::Position::Horizontal::LEFT:
867
+ default :
868
+ fPosX = m_fPositionOffsetX;
869
+ break ;
870
+ }
871
+
872
+ switch ( m_ePositionVertical )
873
+ {
874
+ case Chat::Position::Vertical::BOTTOM:
875
+ fPosY = 1.0 - fRelativeHeight + m_fPositionOffsetY;
876
+ break ;
877
+ case Chat::Position::Vertical::CENTER:
878
+ fPosY = (1.0 - fRelativeHeight ) / 2 + m_fPositionOffsetY;
879
+ break ;
880
+ case Chat::Position::Vertical::TOP:
881
+ default :
882
+ fPosY = m_fPositionOffsetY;
883
+ break ;
884
+ }
885
+
886
+ m_vecBackgroundPosition = CVector2D ( fPosX , fPosY ) * vecResolution;
887
+ m_vecInputPosition = CVector2D (
888
+ m_vecBackgroundPosition.fX ,
889
+ m_vecBackgroundPosition.fY + m_vecBackgroundSize.fY
890
+ );
891
+
892
+ m_pBackground->SetPosition ( m_vecBackgroundPosition );
893
+
894
+ if ( m_pInput ) {
895
+ m_pInput->SetPosition ( m_vecInputPosition );
896
+ }
873
897
}
874
898
875
899
@@ -936,8 +960,10 @@ void CChat::SetInputText ( const char* szText )
936
960
m_strInputText.resize ( szRemainingText - szText );
937
961
938
962
m_vecInputSize = CalcInputSize ();
939
- if ( m_pInput )
963
+ if ( m_pInput ) {
940
964
m_pInput->SetSize ( m_vecInputSize );
965
+ UpdatePosition ();
966
+ }
941
967
}
942
968
943
969
@@ -1080,7 +1106,7 @@ const char* CChatLine::Format ( const char* szStringAnsi, float fWidth, CColor&
1080
1106
{
1081
1107
float fSectionWidth = CChat::GetTextExtent ( UTF16ToMbUTF8 ( strSectionStart.substr ( 0 , uiSeekPos ) ).c_str (), g_pChat->m_vecScale .fX );
1082
1108
1083
- if ( *szSectionEnd == ' \0 ' || *szSectionEnd == ' \n ' || fPrevSectionsWidth + fSectionWidth > fWidth )
1109
+ if ( *szSectionEnd == ' \0 ' || *szSectionEnd == ' \n ' || std::ceil ( fPrevSectionsWidth + fSectionWidth ) > fWidth )
1084
1110
{
1085
1111
bLastSection = true ;
1086
1112
break ;
@@ -1237,7 +1263,7 @@ float CChatLineSection::GetWidth ()
1237
1263
{
1238
1264
if ( m_fCachedWidth < 0 .0f || m_strText.size () != m_uiCachedLength )
1239
1265
{
1240
- m_fCachedWidth = CChat::GetTextExtent ( m_strText.c_str (), g_pChat->m_vecScale .fX ) / std::max ( 0 .01f , g_pChat->m_vecScale .fX );
1266
+ m_fCachedWidth = std::ceil ( CChat::GetTextExtent ( m_strText.c_str (), g_pChat->m_vecScale .fX ) / std::max ( 0 .01f , g_pChat->m_vecScale .fX ) );
1241
1267
m_uiCachedLength = m_strText.size ();
1242
1268
}
1243
1269
return m_fCachedWidth * g_pChat->m_vecScale .fX ;
0 commit comments