mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2024-12-26 14:55:30 +03:00
Added GetNewlinePositions for vgui::TextImage
This commit is contained in:
parent
daa4779978
commit
633e90fe16
@ -105,6 +105,11 @@ public:
|
|||||||
void SetColorChangeStream( CUtlSortVector<label_colorchange_t,CColorChangeListLess> *pUtlVecStream );
|
void SetColorChangeStream( CUtlSortVector<label_colorchange_t,CColorChangeListLess> *pUtlVecStream );
|
||||||
void ClearColorChangeStream( void ) { m_ColorChangeStream.Purge(); }
|
void ClearColorChangeStream( void ) { m_ColorChangeStream.Purge(); }
|
||||||
|
|
||||||
|
#ifdef MAPBASE
|
||||||
|
// Gets the relative y coordinates of all new lines created by newline (\n) characters.
|
||||||
|
void GetNewlinePositions( CUtlVector<int> *pOutCoords, bool bIgnoreEmptyLines = true );
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// truncate the _text string to fit into the draw width
|
// truncate the _text string to fit into the draw width
|
||||||
void SizeText(wchar_t *tempText, int stringLength);
|
void SizeText(wchar_t *tempText, int stringLength);
|
||||||
|
@ -983,3 +983,117 @@ void TextImage::SetColorChangeStream( CUtlSortVector<label_colorchange_t,CColorC
|
|||||||
|
|
||||||
m_ColorChangeStream = *pUtlVecStream;
|
m_ColorChangeStream = *pUtlVecStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MAPBASE
|
||||||
|
void TextImage::GetNewlinePositions( CUtlVector<int> *pOutCoords, bool bIgnoreEmptyLines )
|
||||||
|
{
|
||||||
|
HFont font = GetFont();
|
||||||
|
if (!_utext || font == INVALID_FONT )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Early out if there's no newlines in our text
|
||||||
|
if (wcschr( _utext, L'\n' ) == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_bRecalculateTruncation)
|
||||||
|
{
|
||||||
|
if ( m_bWrap || m_bWrapCenter )
|
||||||
|
{
|
||||||
|
RecalculateNewLinePositions();
|
||||||
|
}
|
||||||
|
|
||||||
|
RecalculateEllipsesPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineHeight = surface()->GetFontTall( GetFont() );
|
||||||
|
float x = 0.0f;
|
||||||
|
int y = 0;
|
||||||
|
int iIndent = 0;
|
||||||
|
|
||||||
|
int px, py;
|
||||||
|
GetPos(px, py);
|
||||||
|
|
||||||
|
int currentLineBreak = 0;
|
||||||
|
|
||||||
|
if ( m_bWrapCenter && m_LineXIndent.Count() )
|
||||||
|
{
|
||||||
|
x = m_LineXIndent[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (wchar_t *wsz = _utext; *wsz != 0; wsz++)
|
||||||
|
{
|
||||||
|
wchar_t ch = wsz[0];
|
||||||
|
|
||||||
|
if ( m_bAllCaps )
|
||||||
|
{
|
||||||
|
ch = towupper( ch );
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for special characters
|
||||||
|
if ( ch == '\r' || ch <= 8 )
|
||||||
|
{
|
||||||
|
// ignore, just use \n for newlines
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (ch == '\n')
|
||||||
|
{
|
||||||
|
// newline
|
||||||
|
iIndent++;
|
||||||
|
if ( m_bWrapCenter && iIndent < m_LineXIndent.Count() )
|
||||||
|
{
|
||||||
|
x = m_LineXIndent[iIndent];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
y += lineHeight;
|
||||||
|
|
||||||
|
if (!bIgnoreEmptyLines || (*(wsz + 1) != 0 && wsz[1] != '\n'))
|
||||||
|
{
|
||||||
|
pOutCoords->AddToTail( y );
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (ch == '&')
|
||||||
|
{
|
||||||
|
// "&&" means draw a single ampersand, single one is a shortcut character
|
||||||
|
if (wsz[1] == '&')
|
||||||
|
{
|
||||||
|
// just move on and draw the second ampersand
|
||||||
|
wsz++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// see if we've hit the truncated portion of the string
|
||||||
|
if (wsz == m_pwszEllipsesPosition)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLineBreak != m_LineBreaks.Count())
|
||||||
|
{
|
||||||
|
if (wsz == m_LineBreaks[currentLineBreak])
|
||||||
|
{
|
||||||
|
// newline
|
||||||
|
iIndent++;
|
||||||
|
if ( m_bWrapCenter && iIndent < m_LineXIndent.Count() )
|
||||||
|
{
|
||||||
|
x = m_LineXIndent[iIndent];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
y += lineHeight;
|
||||||
|
currentLineBreak++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Underlined text wants to draw the spaces anyway
|
||||||
|
x += surface()->GetCharacterWidth(font, ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user