From ca9950b2829bb6dee003e9d8c3efdc0a95c8734a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Tue, 21 Mar 2017 23:34:50 -0300 Subject: [PATCH] Minor clean up. --HG-- branch : dev --- bin/assets/ee.ini | 2 +- include/eepp/ui/uibackground.hpp | 15 +++++------ include/eepp/ui/uiborder.hpp | 7 ++--- include/eepp/ui/uiskincomplex.hpp | 4 ++- include/eepp/ui/uiskinsimple.hpp | 5 ++-- include/eepp/ui/uiskinstate.hpp | 2 ++ include/eepp/ui/uitheme.hpp | 2 ++ include/eepp/ui/uithemedefault.hpp | 2 ++ src/eepp/ui/uibackground.cpp | 43 +++++++++++------------------- src/eepp/ui/uiborder.cpp | 16 ++++++++--- src/eepp/ui/uicontrol.cpp | 21 +++++++-------- src/eepp/ui/uiskincomplex.cpp | 10 ++++--- src/eepp/ui/uiskinsimple.cpp | 10 ++++--- src/eepp/ui/uiskinstate.cpp | 4 +++ src/eepp/ui/uitheme.cpp | 16 ++++++----- src/eepp/ui/uithemedefault.cpp | 4 +++ src/test/eetest.cpp | 4 +-- 17 files changed, 96 insertions(+), 71 deletions(-) diff --git a/bin/assets/ee.ini b/bin/assets/ee.ini index d52fcf716..64e42fc34 100755 --- a/bin/assets/ee.ini +++ b/bin/assets/ee.ini @@ -13,4 +13,4 @@ JoystickEnabled = 0 ParticlesNum = 1000 UseShaders = 1 Music = 0 -PixelDensity = 1 +PixelDensity = 2 diff --git a/include/eepp/ui/uibackground.hpp b/include/eepp/ui/uibackground.hpp index 64a5aabf4..5a47a315d 100644 --- a/include/eepp/ui/uibackground.hpp +++ b/include/eepp/ui/uibackground.hpp @@ -7,28 +7,27 @@ namespace EE { namespace UI { class EE_API UIBackground { public: + static UIBackground * New(); + UIBackground(); - UIBackground( const ColorA& color, const unsigned int& corners = 0, const EE_BLEND_MODE& BlendMode = ALPHA_NORMAL ); - UIBackground( const UIBackground& Back ); - UIBackground( const ColorA& TopLeftColor, const ColorA& BottomLeftColor, const ColorA& BottomRightColor, const ColorA& TopRightColor, const unsigned int& corners, const EE_BLEND_MODE& BlendMode ); ColorA& getColor( const unsigned int& index = 0 ); - void setColor( const ColorA& Col ); + UIBackground * setColor( const ColorA& Col ); const std::vector& getColors(); - void setColors( const ColorA& TopLeftColor, const ColorA& BottomLeftColor, const ColorA& BottomRightColor, const ColorA& TopRightColor ); + UIBackground * setColors( const ColorA& TopLeftColor, const ColorA& BottomLeftColor, const ColorA& BottomRightColor, const ColorA& TopRightColor ); - void setColorsTo( const ColorA& color ); + UIBackground * setColorsTo( const ColorA& color ); const EE_BLEND_MODE& getBlendMode() const; - void setBlendMode( const EE_BLEND_MODE& blend ); + UIBackground * setBlendMode( const EE_BLEND_MODE& blend ); const unsigned int& getCorners() const; - void setCorners( const unsigned int& corners ); + UIBackground * setCorners( const unsigned int& corners ); protected: std::vector mColor; diff --git a/include/eepp/ui/uiborder.hpp b/include/eepp/ui/uiborder.hpp index d22fc1e6e..b18f0a34e 100644 --- a/include/eepp/ui/uiborder.hpp +++ b/include/eepp/ui/uiborder.hpp @@ -7,16 +7,17 @@ namespace EE { namespace UI { class EE_API UIBorder { public: + static UIBorder * New(); + UIBorder(); - UIBorder( const UIBorder& border ); const ColorA& getColor() const; - void setColor( const ColorA& Col ); + UIBorder * setColor( const ColorA& Col ); const unsigned int& getWidth() const; - void setWidth( const unsigned int& width ); + UIBorder * setWidth( const unsigned int& width ); protected: ColorA mColor; unsigned int mWidth; diff --git a/include/eepp/ui/uiskincomplex.hpp b/include/eepp/ui/uiskincomplex.hpp index 4dade009a..e1c1070d5 100644 --- a/include/eepp/ui/uiskincomplex.hpp +++ b/include/eepp/ui/uiskincomplex.hpp @@ -12,6 +12,8 @@ namespace EE { namespace UI { class EE_API UISkinComplex : public UISkin { public: + static UISkinComplex * New( const std::string& name ); + static std::string getSideSuffix( const Uint32& Side ); enum UISkinComplexSides { @@ -27,7 +29,7 @@ class EE_API UISkinComplex : public UISkin { SideCount }; - UISkinComplex( const std::string& getName ); + UISkinComplex( const std::string& name ); virtual ~UISkinComplex(); diff --git a/include/eepp/ui/uiskinsimple.hpp b/include/eepp/ui/uiskinsimple.hpp index 8ef114f39..b4c455a6e 100644 --- a/include/eepp/ui/uiskinsimple.hpp +++ b/include/eepp/ui/uiskinsimple.hpp @@ -12,7 +12,9 @@ namespace EE { namespace UI { class EE_API UISkinSimple : public UISkin { public: - UISkinSimple( const std::string& getName ); + static UISkinSimple * New( const std::string& name ); + + UISkinSimple( const std::string& name ); virtual ~UISkinSimple(); @@ -39,4 +41,3 @@ class EE_API UISkinSimple : public UISkin { }} #endif - diff --git a/include/eepp/ui/uiskinstate.hpp b/include/eepp/ui/uiskinstate.hpp index 863300ffc..bbf2e3f85 100644 --- a/include/eepp/ui/uiskinstate.hpp +++ b/include/eepp/ui/uiskinstate.hpp @@ -19,6 +19,8 @@ class EE_API UISkinState { StateCount }; + static UISkinState * New( UISkin * skin ); + UISkinState( UISkin * Skin ); ~UISkinState(); diff --git a/include/eepp/ui/uitheme.hpp b/include/eepp/ui/uitheme.hpp index 66f3508ec..103ce0b83 100644 --- a/include/eepp/ui/uitheme.hpp +++ b/include/eepp/ui/uitheme.hpp @@ -23,6 +23,8 @@ class EE_API UITheme : protected ResourceManager { using ResourceManager::exists; using ResourceManager::existsId; + static UITheme * New( const std::string& name, const std::string& abbr, Graphics::Font * defaultFont = NULL ); + static UITheme * loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtlas * getTextureAtlas ); static UITheme * loadFromFile( UITheme * tTheme, const std::string& Path, const std::string ImgExt = "png" ); diff --git a/include/eepp/ui/uithemedefault.hpp b/include/eepp/ui/uithemedefault.hpp index 56506571e..e8cb56891 100644 --- a/include/eepp/ui/uithemedefault.hpp +++ b/include/eepp/ui/uithemedefault.hpp @@ -7,6 +7,8 @@ namespace EE { namespace UI { class EE_API UIThemeDefault : public UITheme { public: + static UIThemeDefault * New( const std::string& name, const std::string& abbr, Graphics::Font * defaultFont = NULL ); + UIThemeDefault( const std::string& name, const std::string& abbr, Graphics::Font * defaultFont = NULL ); UITabWidgetStyleConfig getTabWidgetStyleConfig(); diff --git a/src/eepp/ui/uibackground.cpp b/src/eepp/ui/uibackground.cpp index eb2dc83f6..8d835877f 100644 --- a/src/eepp/ui/uibackground.cpp +++ b/src/eepp/ui/uibackground.cpp @@ -2,6 +2,10 @@ namespace EE { namespace UI { +UIBackground * UIBackground::New() { + return eeNew( UIBackground, () ); +} + UIBackground::UIBackground() : mBlendMode( ALPHA_NORMAL ), mCorners(0) @@ -9,28 +13,6 @@ UIBackground::UIBackground() : mColor.push_back( ColorA(0xFF404040) ); } -UIBackground::UIBackground( const UIBackground& Back ) : - mBlendMode( ALPHA_NORMAL ), - mCorners( Back.getCorners() ) -{ - UIBackground * b = const_cast ( &Back ); // cheating - mColor = b->getColors(); -} - -UIBackground::UIBackground( const ColorA& Color, const unsigned int& Corners, const EE_BLEND_MODE& BlendMode ) : - mBlendMode( BlendMode ), - mCorners( Corners ) -{ - mColor.push_back( Color ); -} - -UIBackground::UIBackground( const ColorA& TopLeftColor, const ColorA& BottomLeftColor, const ColorA& BottomRightColor, const ColorA& TopRightColor, const unsigned int& Corners, const EE_BLEND_MODE& BlendMode ) : - mBlendMode( BlendMode ), - mCorners( Corners ) -{ - setColors( TopLeftColor, BottomLeftColor, BottomRightColor, TopRightColor ); -} - ColorA& UIBackground::getColor( const unsigned int& index ) { if ( index < mColor.size() ) return mColor[ index ]; @@ -38,12 +20,14 @@ ColorA& UIBackground::getColor( const unsigned int& index ) { return mColor[ 0 ]; } -void UIBackground::setColorsTo( const ColorA& Color ) { +UIBackground * UIBackground::setColorsTo( const ColorA& Color ) { for ( unsigned int i = 0; i < mColor.size(); i++ ) mColor[i] = Color; + + return this; } -void UIBackground::setColors( const ColorA& TopLeftColor, const ColorA& BottomLeftColor, const ColorA& BottomRightColor, const ColorA& TopRightColor ) { +UIBackground * UIBackground::setColors( const ColorA& TopLeftColor, const ColorA& BottomLeftColor, const ColorA& BottomRightColor, const ColorA& TopRightColor ) { mColor[0] = TopLeftColor; if ( mColor.size() < 2 ) @@ -60,30 +44,35 @@ void UIBackground::setColors( const ColorA& TopLeftColor, const ColorA& BottomLe mColor.push_back( TopRightColor ); else mColor[3] = TopRightColor; + + return this; } const std::vector& UIBackground::getColors() { return mColor; } -void UIBackground::setColor( const ColorA& Col ) { +UIBackground * UIBackground::setColor( const ColorA& Col ) { mColor[0] = Col; + return this; } const EE_BLEND_MODE& UIBackground::getBlendMode() const { return mBlendMode; } -void UIBackground::setBlendMode( const EE_BLEND_MODE& blend ) { +UIBackground * UIBackground::setBlendMode( const EE_BLEND_MODE& blend ) { mBlendMode = blend; + return this; } const unsigned int& UIBackground::getCorners() const { return mCorners; } -void UIBackground::setCorners( const unsigned int& corners ) { +UIBackground * UIBackground::setCorners( const unsigned int& corners ) { mCorners = corners; + return this; } }} diff --git a/src/eepp/ui/uiborder.cpp b/src/eepp/ui/uiborder.cpp index 0126ad3de..68af9ea93 100644 --- a/src/eepp/ui/uiborder.cpp +++ b/src/eepp/ui/uiborder.cpp @@ -2,23 +2,31 @@ namespace EE { namespace UI { -UIBorder::UIBorder() : mColor( 0xFF404040 ), mWidth( 1 ) {} -UIBorder::UIBorder( const UIBorder& border ) : mColor( border.getColor() ), mWidth( border.getWidth() ) {} +UIBorder * UIBorder::New() { + return eeNew( UIBorder, () ); +} + +UIBorder::UIBorder() : + mColor( ColorA::Black ), + mWidth( 1 ) +{} const ColorA& UIBorder::getColor() const { return mColor; } -void UIBorder::setColor( const ColorA& Col ) { +UIBorder * UIBorder::setColor( const ColorA& Col ) { mColor = Col; + return this; } const unsigned int& UIBorder::getWidth() const { return mWidth; } -void UIBorder::setWidth( const unsigned int& width ) { +UIBorder * UIBorder::setWidth( const unsigned int& width ) { mWidth = width; + return this; } }} diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 0c114869a..336da5902 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -557,7 +557,7 @@ UIBackground * UIControl::setBackgroundFillEnabled( bool enabled ) { writeFlag( UI_FILL_BACKGROUND, enabled ? 1 : 0 ); if ( enabled && NULL == mBackground ) { - mBackground = eeNew( UIBackground, () ); + mBackground = UIBackground::New(); } return mBackground; @@ -567,10 +567,10 @@ UIBorder * UIControl::setBorderEnabled( bool enabled ) { writeFlag( UI_BORDER, enabled ? 1 : 0 ); if ( enabled && NULL == mBorder ) { - mBorder = eeNew( UIBorder, () ); + mBorder = UIBorder::New(); if ( NULL == mBackground ) { - mBackground = eeNew( UIBackground, () ); + mBackground = UIBackground::New(); } } @@ -606,10 +606,10 @@ const Uint32& UIControl::getFlags() const { UIControl * UIControl::setFlags( const Uint32& flags ) { if ( NULL == mBackground && ( flags & UI_FILL_BACKGROUND ) ) - mBackground = eeNew( UIBackground, () ); + mBackground = UIBackground::New(); if ( NULL == mBorder && ( flags & UI_BORDER ) ) - mBorder = eeNew( UIBorder, () ); + mBorder = UIBorder::New(); if ( fontHAlignGet( flags ) || fontVAlignGet( flags ) ) { onAlignChange(); @@ -720,7 +720,6 @@ void UIControl::drawBorder() { P.setLineWidth( PixelDensity::dpToPx( mBorder->getWidth() ) ); P.setColor( mBorder->getColor() ); - //! @TODO: Check why was this +0.1f -0.1f? if ( mFlags & UI_CLIP_ENABLE ) { Rectf R( Vector2f( mScreenPosf.x + 0.1f, mScreenPosf.y + 0.1f ), Sizef( (Float)mRealSize.getWidth() - 0.1f, (Float)mRealSize.getHeight() - 0.1f ) ); @@ -1190,7 +1189,7 @@ void UIControl::sendEvent( const UIEvent * Event ) { UIBackground * UIControl::getBackground() { if ( NULL == mBackground ) { - mBackground = eeNew( UIBackground, () ); + mBackground = UIBackground::New(); } return mBackground; @@ -1198,7 +1197,7 @@ UIBackground * UIControl::getBackground() { UIBorder * UIControl::getBorder() { if ( NULL == mBorder ) { - mBorder = eeNew( UIBorder, () ); + mBorder = UIBorder::New(); } return mBorder; @@ -1229,7 +1228,7 @@ UIControl * UIControl::setThemeControl( UITheme * Theme, const std::string& Cont removeSkin(); - mSkinState = eeNew( UISkinState, ( tSkin ) ); + mSkinState = UISkinState::New( tSkin ); mSkinState->setState( InitialState ); onThemeLoaded(); @@ -1246,7 +1245,7 @@ void UIControl::setSkin( const UISkin& Skin ) { UISkin * SkinCopy = const_cast( &Skin )->clone(); - mSkinState = eeNew( UISkinState, ( SkinCopy ) ); + mSkinState = UISkinState::New( SkinCopy ); onThemeLoaded(); } @@ -1264,7 +1263,7 @@ UIControl * UIControl::setSkin( UISkin * skin ) { removeSkin(); - mSkinState = eeNew( UISkinState, ( skin ) ); + mSkinState = UISkinState::New( skin ); mSkinState->setState( InitialState ); onThemeLoaded(); diff --git a/src/eepp/ui/uiskincomplex.cpp b/src/eepp/ui/uiskincomplex.cpp index 197d3c103..773c4b5e5 100644 --- a/src/eepp/ui/uiskincomplex.cpp +++ b/src/eepp/ui/uiskincomplex.cpp @@ -8,14 +8,18 @@ static const char SideSuffix[ UISkinComplex::SideCount ][4] = { "ml", "mr","d","u","ul","ur","dl","dr","m" }; +UISkinComplex *UISkinComplex::New(const std::string & name) { + return eeNew( UISkinComplex, ( name ) ); +} + std::string UISkinComplex::getSideSuffix( const Uint32& Side ) { eeASSERT( Side < UISkinComplex::SideCount ); return std::string( SideSuffix[ Side ] ); } -UISkinComplex::UISkinComplex( const std::string& Name ) : - UISkin( Name, SkinComplex ) +UISkinComplex::UISkinComplex(const std::string& name ) : + UISkin( name, SkinComplex ) { for ( Int32 x = 0; x < UISkinState::StateCount; x++ ) for ( Int32 y = 0; y < SideCount; y++ ) @@ -194,7 +198,7 @@ void UISkinComplex::stateNormalToState( const Uint32& State ) { } UISkinComplex * UISkinComplex::clone( const std::string& NewName, const bool& CopyColorsState ) { - UISkinComplex * SkinC = eeNew( UISkinComplex, ( NewName ) ); + UISkinComplex * SkinC = UISkinComplex::New( NewName ); if ( CopyColorsState ) { SkinC->mColorDefault = mColorDefault; diff --git a/src/eepp/ui/uiskinsimple.cpp b/src/eepp/ui/uiskinsimple.cpp index b8700f93b..c3e28f8ba 100644 --- a/src/eepp/ui/uiskinsimple.cpp +++ b/src/eepp/ui/uiskinsimple.cpp @@ -4,8 +4,12 @@ namespace EE { namespace UI { -UISkinSimple::UISkinSimple( const std::string& Name ) : - UISkin( Name, SkinSimple ) +UISkinSimple * UISkinSimple::New( const std::string& name ) { + return eeNew( UISkinSimple, ( name ) ); +} + +UISkinSimple::UISkinSimple(const std::string& name ) : + UISkin( name, SkinSimple ) { for ( Int32 i = 0; i < UISkinState::StateCount; i++ ) mDrawable[ i ] = NULL; @@ -52,7 +56,7 @@ void UISkinSimple::stateNormalToState( const Uint32& State ) { } UISkinSimple * UISkinSimple::clone( const std::string& NewName, const bool& CopyColorsState ) { - UISkinSimple * SkinS = eeNew( UISkinSimple, ( NewName ) ); + UISkinSimple * SkinS = UISkinSimple::New( NewName ); if ( CopyColorsState ) { SkinS->mColorDefault = mColorDefault; diff --git a/src/eepp/ui/uiskinstate.cpp b/src/eepp/ui/uiskinstate.cpp index 9b88ea82d..7e9799316 100644 --- a/src/eepp/ui/uiskinstate.cpp +++ b/src/eepp/ui/uiskinstate.cpp @@ -3,6 +3,10 @@ namespace EE { namespace UI { +UISkinState *UISkinState::New( UISkin * skin ) { + return eeNew( UISkinState, ( skin ) ); +} + UISkinState::UISkinState( UISkin * Skin ) : mSkin( Skin ), mCurState(0), diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index ac7b1ae7f..4460d2294 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -124,6 +124,10 @@ void UITheme::addThemeIcon( const std::string& Icon ) { mUIIcons.push_back( Icon ); } +UITheme * UITheme::New( const std::string & name, const std::string & abbr, Font * defaultFont ) { + return eeNew( UITheme, ( name, abbr, defaultFont ) ); +} + UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtlas * TextureAtlas ) { eeASSERT( NULL != tTheme && NULL != TextureAtlas ); @@ -159,9 +163,9 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla for ( i = 0; i < ElemFound.size(); i++ ) { if ( ElemType[i] ) - tTheme->add( eeNew( UISkinComplex, ( ElemFound[i] ) ) ); + tTheme->add( UISkinComplex::New( ElemFound[i] ) ); else - tTheme->add( eeNew( UISkinSimple, ( ElemFound[i] ) ) ); + tTheme->add( UISkinSimple::New( ElemFound[i] ) ); } eePRINTL( "UI Theme Loaded in: %4.3f ms ( from TextureAtlas )", TE.getElapsed().asMilliseconds() ); @@ -222,9 +226,9 @@ UITheme * UITheme::loadFromFile( UITheme * tTheme, const std::string& Path, cons for ( i = 0; i < ElemFound.size(); i++ ) { if ( ElemType[i] ) - tTheme->add( eeNew( UISkinComplex, ( ElemFound[i] ) ) ); + tTheme->add( UISkinComplex::New( ElemFound[i] ) ); else - tTheme->add( eeNew( UISkinSimple, ( ElemFound[i] ) ) ); + tTheme->add( UISkinSimple::New( ElemFound[i] ) ); } eePRINTL( "UI Theme Loaded in: %4.3f ms ( from path )", TE.getElapsed().asMilliseconds() ); @@ -233,11 +237,11 @@ UITheme * UITheme::loadFromFile( UITheme * tTheme, const std::string& Path, cons } UITheme * UITheme::loadFromFile( const std::string& Path, const std::string& Name, const std::string& NameAbbr, const std::string ImgExt ) { - return loadFromFile( eeNew( UITheme, ( Name, NameAbbr ) ), Path, ImgExt ); + return loadFromFile( UITheme::New( Name, NameAbbr ), Path, ImgExt ); } UITheme * UITheme::loadFromTextureAtlas( Graphics::TextureAtlas * TextureAtlas, const std::string& Name, const std::string NameAbbr ) { - return loadFromTextureAtlas( eeNew( UITheme, ( Name, NameAbbr ) ), TextureAtlas ); + return loadFromTextureAtlas( UITheme::New( Name, NameAbbr ), TextureAtlas ); } bool UITheme::searchFilesInAtlas( Graphics::TextureAtlas * SG, std::string Element, Uint32& IsComplex ) { diff --git a/src/eepp/ui/uithemedefault.cpp b/src/eepp/ui/uithemedefault.cpp index bf48a329d..9a966134c 100644 --- a/src/eepp/ui/uithemedefault.cpp +++ b/src/eepp/ui/uithemedefault.cpp @@ -9,6 +9,10 @@ namespace EE { namespace UI { +UIThemeDefault * UIThemeDefault::New( const std::string & name, const std::string & abbr, Font * defaultFont ) { + return eeNew( UIThemeDefault, ( name, abbr, defaultFont ) ); +} + UIThemeDefault::UIThemeDefault( const std::string& name, const std::string& Abbr, Graphics::Font * defaultFont ) : UITheme( name, Abbr, defaultFont ) { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 7b380e516..691d5ee6b 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -286,11 +286,11 @@ void EETest::createUI() { //UI_MAN_OPS = UI_MANAGER_HIGHLIGHT_FOCUS | UI_MANAGER_HIGHLIGHT_OVER | UI_MANAGER_DRAW_DEBUG_DATA | UI_MANAGER_DRAW_BOXES; UIManager::instance()->init(UI_MAN_OPS); - //mTheme = UITheme::loadFromFile( eeNew( UIThemeDefault, ( mThemeName, mThemeName ) ), MyPath + mThemeName + "/" ); + //mTheme = UITheme::loadFromFile( UIThemeDefault::New( mThemeName, mThemeName ), MyPath + mThemeName + "/" ); TextureAtlasLoader tgl( MyPath + "ui/" + mThemeName + EE_TEXTURE_ATLAS_EXTENSION ); - mTheme = UITheme::loadFromTextureAtlas( eeNew( UIThemeDefault, ( mThemeName, mThemeName ) ), TextureAtlasManager::instance()->getByName( mThemeName ) ); + mTheme = UITheme::loadFromTextureAtlas( UIThemeDefault::New( mThemeName, mThemeName ), TextureAtlasManager::instance()->getByName( mThemeName ) ); UIThemeManager::instance()->add( mTheme ); UIThemeManager::instance()->setDefaultEffectsEnabled( true );