Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/RichLabel.h"
#include "Gwen/Controls/Label.h"
@@ -16,7 +15,7 @@ using namespace Gwen::Controls;
const unsigned char Type_Text = 0;
const unsigned char Type_Newline = 1;
GWEN_CONTROL_CONSTRUCTOR( RichLabel )
GWEN_CONTROL_CONSTRUCTOR(RichLabel)
{
m_bNeedsRebuild = false;
}
@@ -26,19 +25,19 @@ void RichLabel::AddLineBreak()
DividedText t;
t.type = Type_Newline;
m_TextBlocks.push_back( t );
m_TextBlocks.push_back(t);
}
void RichLabel::AddText( const Gwen::TextObject& text, Gwen::Color color, Gwen::Font* font )
void RichLabel::AddText(const Gwen::TextObject& text, Gwen::Color color, Gwen::Font* font)
{
if ( text.m_Data.size() == 0 ) return;
if (text.m_Data.size() == 0) return;
Gwen::Utility::Strings::UnicodeList lst;
Gwen::Utility::Strings::Split( text.GetUnicode(), L"\n", lst, false );
Gwen::Utility::Strings::Split(text.GetUnicode(), L"\n", lst, false);
for (size_t i=0; i<lst.size(); i++ )
for (size_t i = 0; i < lst.size(); i++)
{
if ( i > 0 ) AddLineBreak();
if (i > 0) AddLineBreak();
DividedText t;
t.type = Type_Text;
@@ -46,120 +45,120 @@ void RichLabel::AddText( const Gwen::TextObject& text, Gwen::Color color, Gwen::
t.color = color;
t.font = font;
m_TextBlocks.push_back( t );
m_TextBlocks.push_back(t);
m_bNeedsRebuild = true;
Invalidate();
}
}
bool RichLabel::SizeToChildren( bool w, bool h )
bool RichLabel::SizeToChildren(bool w, bool h)
{
Rebuild();
return BaseClass::SizeToChildren( w, h );
return BaseClass::SizeToChildren(w, h);
}
void RichLabel::SplitLabel( const Gwen::UnicodeString& text, Gwen::Font* pFont, const DividedText& txt, int& x, int& y, int& lineheight )
void RichLabel::SplitLabel(const Gwen::UnicodeString& text, Gwen::Font* pFont, const DividedText& txt, int& x, int& y, int& lineheight)
{
Gwen::Utility::Strings::UnicodeList lst;
Gwen::Utility::Strings::Split( text, L" ", lst, true );
if ( lst.size() == 0 ) return;
Gwen::Utility::Strings::Split(text, L" ", lst, true);
if (lst.size() == 0) return;
int iSpaceLeft = Width() - x;
// Does the whole word fit in?
{
Gwen::Point StringSize = GetSkin()->GetRender()->MeasureText( pFont, text );
if ( iSpaceLeft > StringSize.x )
Gwen::Point StringSize = GetSkin()->GetRender()->MeasureText(pFont, text);
if (iSpaceLeft > StringSize.x)
{
return CreateLabel( text, txt, x, y, lineheight, true );
return CreateLabel(text, txt, x, y, lineheight, true);
}
}
// If the first word is bigger than the line, just give up.
{
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText( pFont, lst[0] );
if ( WordSize.x >= iSpaceLeft )
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText(pFont, lst[0]);
if (WordSize.x >= iSpaceLeft)
{
CreateLabel( lst[0], txt, x, y, lineheight, true );
if ( lst[0].size() >= text.size() ) return;
CreateLabel(lst[0], txt, x, y, lineheight, true);
if (lst[0].size() >= text.size()) return;
Gwen::UnicodeString LeftOver = text.substr( lst[0].size() + 1 );
return SplitLabel( LeftOver, pFont, txt, x, y, lineheight );
Gwen::UnicodeString LeftOver = text.substr(lst[0].size() + 1);
return SplitLabel(LeftOver, pFont, txt, x, y, lineheight);
}
}
Gwen::UnicodeString strNewString = L"";
for ( size_t i=0; i<lst.size(); i++ )
for (size_t i = 0; i < lst.size(); i++)
{
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText( pFont, strNewString + lst[i] );
if ( WordSize.x > iSpaceLeft )
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText(pFont, strNewString + lst[i]);
if (WordSize.x > iSpaceLeft)
{
CreateLabel( strNewString, txt, x, y, lineheight, true );
CreateLabel(strNewString, txt, x, y, lineheight, true);
x = 0;
y += lineheight;
break;;
break;
;
}
strNewString += lst[i];
}
Gwen::UnicodeString LeftOver = text.substr( strNewString.size() + 1 );
return SplitLabel( LeftOver, pFont, txt, x, y, lineheight );
Gwen::UnicodeString LeftOver = text.substr(strNewString.size() + 1);
return SplitLabel(LeftOver, pFont, txt, x, y, lineheight);
}
void RichLabel::CreateLabel( const Gwen::UnicodeString& text, const DividedText& txt, int& x, int& y, int& lineheight, bool NoSplit )
void RichLabel::CreateLabel(const Gwen::UnicodeString& text, const DividedText& txt, int& x, int& y, int& lineheight, bool NoSplit)
{
//
// Use default font or is one set?
//
Gwen::Font* pFont = GetSkin()->GetDefaultFont();
if ( txt.font ) pFont = txt.font;
if (txt.font) pFont = txt.font;
//
// This string is too long for us, split it up.
//
Gwen::Point p = GetSkin()->GetRender()->MeasureText( pFont, text );
Gwen::Point p = GetSkin()->GetRender()->MeasureText(pFont, text);
if ( lineheight == -1 )
if (lineheight == -1)
{
lineheight = p.y;
}
if ( !NoSplit )
if (!NoSplit)
{
if ( x + p.x > Width() )
if (x + p.x > Width())
{
return SplitLabel( text, pFont, txt, x, y, lineheight );
return SplitLabel(text, pFont, txt, x, y, lineheight);
}
}
//
// Wrap
//
if ( x + p.x >= Width() )
if (x + p.x >= Width())
{
CreateNewline( x, y, lineheight );
CreateNewline(x, y, lineheight);
}
Gwen::Controls::Label* pLabel = new Gwen::Controls::Label( this );
pLabel->SetText( x == 0 ? Gwen::Utility::Strings::TrimLeft<Gwen::UnicodeString>( text, L" " ) : text );
pLabel->SetTextColor( txt.color );
pLabel->SetFont( pFont );
Gwen::Controls::Label* pLabel = new Gwen::Controls::Label(this);
pLabel->SetText(x == 0 ? Gwen::Utility::Strings::TrimLeft<Gwen::UnicodeString>(text, L" ") : text);
pLabel->SetTextColor(txt.color);
pLabel->SetFont(pFont);
pLabel->SizeToContents();
pLabel->SetPos( x, y );
pLabel->SetPos(x, y);
//lineheight = (lineheight + pLabel->Height()) / 2;
//lineheight = (lineheight + pLabel->Height()) / 2;
x += pLabel->Width();
if ( x >= Width() )
if (x >= Width())
{
CreateNewline( x, y, lineheight );
CreateNewline(x, y, lineheight);
}
}
void RichLabel::CreateNewline( int& x, int& y, int& lineheight )
void RichLabel::CreateNewline(int& x, int& y, int& lineheight)
{
x = 0;
y += lineheight;
@@ -172,37 +171,36 @@ void RichLabel::Rebuild()
int x = 0;
int y = 0;
int lineheight = -1;
for ( DividedText::List::iterator it = m_TextBlocks.begin(); it != m_TextBlocks.end(); ++it )
for (DividedText::List::iterator it = m_TextBlocks.begin(); it != m_TextBlocks.end(); ++it)
{
if ( it->type == Type_Newline )
if (it->type == Type_Newline)
{
CreateNewline( x, y, lineheight );
CreateNewline(x, y, lineheight);
continue;
}
if ( it->type == Type_Text )
if (it->type == Type_Text)
{
CreateLabel( (*it).text, *it, x, y, lineheight, false );
CreateLabel((*it).text, *it, x, y, lineheight, false);
continue;
}
}
m_bNeedsRebuild = false;
}
void RichLabel::OnBoundsChanged( Gwen::Rect oldBounds )
void RichLabel::OnBoundsChanged(Gwen::Rect oldBounds)
{
BaseClass::OnBoundsChanged( oldBounds );
BaseClass::OnBoundsChanged(oldBounds);
Rebuild();
}
void RichLabel::Layout( Gwen::Skin::Base* skin )
void RichLabel::Layout(Gwen::Skin::Base* skin)
{
BaseClass::Layout( skin );
BaseClass::Layout(skin);
if ( m_bNeedsRebuild )
if (m_bNeedsRebuild)
{
Rebuild();
}