From 4a085c19287dcd1f3f7876a2e3b01a719a96ba59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Tue, 21 Mar 2017 02:30:43 -0300 Subject: [PATCH] Minor fixes. --HG-- branch : dev --- include/eepp/graphics/drawablesearcher.hpp | 8 ++++- include/eepp/graphics/textureatlasmanager.hpp | 4 +-- src/eepp/graphics/drawablesearcher.cpp | 34 ++++++++++++++----- src/eepp/graphics/textureatlasmanager.cpp | 4 +-- src/eepp/ui/uiskinsimple.cpp | 4 +-- src/test/eetest.cpp | 7 ++-- 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/include/eepp/graphics/drawablesearcher.hpp b/include/eepp/graphics/drawablesearcher.hpp index cdcc88995..0b090d970 100644 --- a/include/eepp/graphics/drawablesearcher.hpp +++ b/include/eepp/graphics/drawablesearcher.hpp @@ -6,11 +6,17 @@ namespace EE { namespace Graphics { -class DrawableSearcher { +class EE_API DrawableSearcher { public: static Drawable * searchByName( const std::string& name ); static Drawable * searchById( const Uint32 & id ); + + static void setPrintWarnings( const bool& print ); + + static bool getPrintWarnings(); + protected: + static bool sPrintWarnings; }; }} diff --git a/include/eepp/graphics/textureatlasmanager.hpp b/include/eepp/graphics/textureatlasmanager.hpp index dc8df53a0..85685e8f8 100644 --- a/include/eepp/graphics/textureatlasmanager.hpp +++ b/include/eepp/graphics/textureatlasmanager.hpp @@ -54,10 +54,10 @@ class EE_API TextureAtlasManager : public ResourceManager { void printResources(); /** Sets if the warnings for not finding a resource must be printed in screen. */ - void printWarnings( const bool& warn ); + void setPrintWarnings( const bool& warn ); /** @return If warnings are being printed. */ - const bool& printWarnings() const; + const bool& getPrintWarnings() const; protected: bool mWarnings; diff --git a/src/eepp/graphics/drawablesearcher.cpp b/src/eepp/graphics/drawablesearcher.cpp index e4203079a..44ccd6513 100644 --- a/src/eepp/graphics/drawablesearcher.cpp +++ b/src/eepp/graphics/drawablesearcher.cpp @@ -6,6 +6,8 @@ namespace EE { namespace Graphics { +bool DrawableSearcher::sPrintWarnings = false; + static Drawable * getSprite( const std::string& sprite ) { std::vector tSubTextureVec = TextureAtlasManager::instance()->getSubTexturesByPattern( sprite ); @@ -22,7 +24,7 @@ static Drawable * getSprite( const std::string& sprite ) { static Drawable * searchByNameInternal( const std::string& name ) { Uint32 id = String::hash( name ); - Drawable * drawable = GlobalTextureAtlas::instance()->getById( id ); + Drawable * drawable = TextureAtlasManager::instance()->getSubTextureById( id ); if ( NULL == drawable ) { drawable = TextureFactory::instance()->getByHash( id ); @@ -41,28 +43,31 @@ Drawable * DrawableSearcher::searchByName( const std::string& name ) { if ( name.size() ) { if ( name[0] == '@' ) { if ( String::startsWith( name, "@subtexture/" ) ) { - return GlobalTextureAtlas::instance()->getByName( name.substr( 12 ) ); + drawable = TextureAtlasManager::instance()->getSubTextureByName( name.substr( 12 ) ); } else if ( String::startsWith( name, "@image/" ) ) { - return TextureFactory::instance()->getByName( name.substr( 7 ) ); + drawable = TextureFactory::instance()->getByName( name.substr( 7 ) ); } else if ( String::startsWith( name, "@texture/" ) ) { - return TextureFactory::instance()->getByName( name.substr( 9 ) ); + drawable = TextureFactory::instance()->getByName( name.substr( 9 ) ); } else if ( String::startsWith( name, "@sprite/" ) ) { - return getSprite( name.substr( 8 ) ); + drawable = getSprite( name.substr( 8 ) ); } else if ( String::startsWith( name, "@drawable/" ) ) { - return searchByNameInternal( name.substr( 10 ) ); + drawable = searchByNameInternal( name.substr( 10 ) ); } else { - return searchByNameInternal( name ); + drawable = searchByNameInternal( name ); } } else { - return searchByNameInternal( name ); + drawable = searchByNameInternal( name ); } } + if ( NULL == drawable && sPrintWarnings ) + eePRINTL( "DrawableSearcher::searchByName: \"%s\" not found", name.c_str() ); + return drawable; } Drawable * DrawableSearcher::searchById( const Uint32& id ) { - Drawable * drawable = GlobalTextureAtlas::instance()->getById( id ); + Drawable * drawable = TextureAtlasManager::instance()->getSubTextureById( id ); if ( NULL == drawable ) { drawable = TextureFactory::instance()->getByHash( id ); @@ -80,7 +85,18 @@ Drawable * DrawableSearcher::searchById( const Uint32& id ) { } } + if ( NULL == drawable && sPrintWarnings ) + eePRINTL( "DrawableSearcher::searchById: \"%ld\" not found", id ); + return drawable; } +void DrawableSearcher::setPrintWarnings( const bool& print ) { + sPrintWarnings = print; +} + +bool DrawableSearcher::getPrintWarnings() { + return sPrintWarnings; +} + }} diff --git a/src/eepp/graphics/textureatlasmanager.cpp b/src/eepp/graphics/textureatlasmanager.cpp index e7e1e10c6..3b2231c48 100644 --- a/src/eepp/graphics/textureatlasmanager.cpp +++ b/src/eepp/graphics/textureatlasmanager.cpp @@ -95,11 +95,11 @@ std::vector TextureAtlasManager::getSubTexturesByPatternId( const U return std::vector(); } -void TextureAtlasManager::printWarnings( const bool& warn ) { +void TextureAtlasManager::setPrintWarnings( const bool& warn ) { mWarnings = warn; } -const bool& TextureAtlasManager::printWarnings() const { +const bool& TextureAtlasManager::getPrintWarnings() const { return mWarnings; } diff --git a/src/eepp/ui/uiskinsimple.cpp b/src/eepp/ui/uiskinsimple.cpp index 5ae046f5b..4b940b69e 100644 --- a/src/eepp/ui/uiskinsimple.cpp +++ b/src/eepp/ui/uiskinsimple.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include namespace EE { namespace UI { @@ -39,7 +39,7 @@ void UISkinSimple::setSkin( const Uint32& State ) { std::string Name( mName + "_" + UISkin::getSkinStateName( State ) ); - mDrawable[ State ] = TextureAtlasManager::instance()->getSubTextureByName( Name ); + mDrawable[ State ] = DrawableSearcher::searchByName( Name ); } bool UISkinSimple::stateExists( const Uint32 & state ) { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index e066917ef..7b380e516 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -11,6 +11,9 @@ namespace Demo_Test { void EETest::init() { EE = Engine::instance(); + Log::instance()->setLiveWrite( true ); + Log::instance()->setConsoleOutput( true ); + Translator t; t.loadFromString( @@ -20,9 +23,6 @@ void EETest::init() { "" ); - Log::instance()->setLiveWrite( true ); - Log::instance()->setConsoleOutput( true ); - DrawBack = false; MultiViewportMode = false; @@ -556,6 +556,7 @@ void EETest::createNewUI() { pushButton->setIcon( mTheme->getIconByName( "ok" ) ); UISprite * sprite = UISprite::New(); + sprite->setFlags( UI_AUTO_SIZE ); sprite->setPosition( 50, 600 ); sprite->setSprite( &SP );