"config":
{
"alwaysShowFocus":false,
- "clearFocusOnEscape":true
+ "clearFocusOnEscape":true,
+ "brokenImageUrl":"{DALI_IMAGE_DIR}broken.png"
},
"constants":
{
styleManager.StyleChangedSignal().Connect(&styleChangedSignalHandler, &StyleChangedSignalChecker::OnStyleChanged);
+ // To ensure we make VisualFactory
+ VisualFactory factory = VisualFactory::Get();
+ Property::Map propertyMap;
+ propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT );
+ Visual::Base textVisual = factory.CreateVisual( propertyMap );
+
// Render and notify
application.SendNotification();
application.Render();
const char* defaultTheme =
"{\n"
+ " \"constants\":\n"
+ " {\n"
+ " \"TEST\":\"broken\"\n"
+ " },\n"
" \"config\":\n"
" {\n"
+ " \"brokenImageUrl\":\"{TEST}|{TEST}|{TEST|TEST.png\",\n"
" \"alwaysShowFocus\":false,\n"
" \"clearFocusOnEscape\":false\n"
" },\n"
DALI_TEST_CHECK( !alwaysShowFocus );
bool clearFocusOnEscape = config["clearFocusOnEscape"].Get<bool>();
DALI_TEST_CHECK( !clearFocusOnEscape );
+ std::string brokenImageUrl = config["brokenImageUrl"].Get<std::string>();
+ DALI_TEST_CHECK( brokenImageUrl.compare( "broken|broken|{TEST|TEST.png" ) == 0 );
// For coverage
Toolkit::TextEditor editor = Toolkit::TextEditor::New();
namespace
{
const char* DEFAULT_THEME=
- "{\"styles\":{\n"
+ "{\n"
+ " \"config\":\n"
+ " {\n"
+ " \"brokenImageUrl\":\"{DALI_IMAGE_DIR}broken.png\"\n"
+ " },\n"
+ " \"styles\":\n"
+ " {\n"
" \"textlabel\":\n"
" {\n"
" \"fontStyle\":{\"weight\":\"normal\"},\n"
}
else
{
- // load configuration map
- LoadConfiguration( *parser.GetRoot(), mConfigurationMap );
// load constant map (allows the user to override the constants in the json after loading)
LoadConstants( *parser.GetRoot(), mReplacementMap );
+ // load configuration map
+ LoadConfiguration( *parser.GetRoot(), mConfigurationMap );
// merge includes
if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) )
{
if( (*iter).second.GetName() )
{
DeterminePropertyFromNode( (*iter).second, property, replacer );
+
+ // If config is string, find constant and replace it to original value.
+ if( (*iter).second.GetType() == TreeNode::STRING )
+ {
+ std::string stringConfigValue;
+ if( property.Get( stringConfigValue ) )
+ {
+ std::size_t pos = 0;
+
+ while( pos < stringConfigValue.size() )
+ {
+ // If we can't find "{","}" pair in stringConfigValue, will out loop.
+ std::size_t leftPos = stringConfigValue.find( "{", pos );
+ if( leftPos != std::string::npos )
+ {
+ std::size_t rightPos = stringConfigValue.find( "}", pos+1 );
+
+ if( rightPos != std::string::npos )
+ {
+ // If we find "{","}" pair but can't find matched constant
+ // try to find other "{","}" pair after current left position.
+ pos = leftPos+1;
+
+ for( unsigned int i = 0; i < mReplacementMap.Count() ; i++ )
+ {
+ std::string constant = mReplacementMap.GetKey(i);
+
+ // Compare string which is between "{" and "}" with constant string
+ // If they are same, change string in stringConfigValue to mapped constant value.
+ if ( stringConfigValue.compare( leftPos+1, rightPos-leftPos-1,constant) == 0 )
+ {
+ std::string replaceString;
+ mReplacementMap.GetValue(i).Get( replaceString );
+
+ stringConfigValue.replace( leftPos, rightPos-leftPos+1, replaceString );
+ pos = leftPos + replaceString.size();
+ break;
+ }
+ }
+ }
+ else
+ {
+ // If we cannot find constant in const value, will out loop.
+ pos = stringConfigValue.size();
+ }
+ }
+ else
+ {
+ // If we cannot find constant in const value, will out loop.
+ pos = stringConfigValue.size();
+ }
+ }
+ property = Property::Value( stringConfigValue );
+ }
+ }
intoMap[ (*iter).second.GetName() ] = property;
}
}
}
else
{
- Image brokenImage = VisualFactoryCache::GetBrokenVisualImage();
+ Image brokenImage = mFactoryCache.GetBrokenVisualImage();
naturalSize.x = brokenImage.GetWidth();
naturalSize.y = brokenImage.GetWidth();
}
else
{
- Image brokenImage = VisualFactoryCache::GetBrokenVisualImage();
+ Image brokenImage = mFactoryCache.GetBrokenVisualImage();
textureSet = TextureSet::New();
mImpl->mRenderer.SetTextures( textureSet );
DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.GetUrl().c_str() );
textureSet = TextureSet::New();
- Image croppedImage = VisualFactoryCache::GetBrokenVisualImage();
+ Image croppedImage = mFactoryCache.GetBrokenVisualImage();
TextureSetImage( textureSet, 0u, croppedImage );
mImpl->mRenderer.RegisterProperty( "uFixed[0]", Vector2::ZERO );
mImpl->mRenderer.RegisterProperty( "uFixed[1]", Vector2::ZERO );
const uint32_t DEFAULT_ATLAS_SIZE( 1024u ); ///< This size can fit 8 by 8 images of average size 128 * 128
const Vector4 FULL_ATLAS_RECT( 0.0f, 0.0f, 1.0f, 1.0f ); ///< UV Rectangle that covers the full Texture
-const char * const BROKEN_IMAGE_URL( DALI_IMAGE_DIR "broken.png" ); ///< URL For the broken image placeholder
const int INVALID_INDEX( -1 ); ///< Invalid index used to represent a non-existant TextureInfo struct
const int INVALID_CACHE_INDEX( -1 ); ///< Invalid Cache index
TextureManager::TextureManager()
: mAsyncLocalLoaders( GetNumberOfLocalLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
mAsyncRemoteLoaders( GetNumberOfRemoteLoaderThreads(), [&]() { return AsyncLoadingHelper(*this); } ),
+ mBrokenImageUrl(""),
mCurrentTextureId( 0 )
{
}
{
// use broken image
textureSet = TextureSet::New();
- Devel::PixelBuffer pixelBuffer = LoadImageFromFile( BROKEN_IMAGE_URL );
+ Devel::PixelBuffer pixelBuffer = LoadImageFromFile( mBrokenImageUrl );
if( pixelBuffer )
{
PreMultiply( pixelBuffer, preMultiplyOnLoad );
mTextureManager.AsyncLoadComplete(mLoadingInfoContainer, id, pixelBuffer);
}
+void TextureManager::SetBrokenImageUrl(const std::string& brokenImageUrl)
+{
+ mBrokenImageUrl = brokenImageUrl;
+}
+
} // namespace Internal
} // namespace Toolkit
*/
void RemoveObserver( TextureManager::LifecycleObserver& observer );
+ /**
+ * @brief Set an image to be used when a visual has failed to correctly render
+ * @param[in] brokenImageUrl The broken image url.
+ */
+ void SetBrokenImageUrl(const std::string& brokenImageUrl);
+
private:
/**
RoundRobinContainerView< AsyncLoadingHelper > mAsyncRemoteLoaders; ///< The Asynchronous image loaders used to provide all remote async loads
std::vector< ExternalTextureInfo > mExternalTextures; ///< Externally provided textures
Dali::Vector<LifecycleObserver*> mLifecycleObservers; ///< Lifecycle observers of texture manager
+ std::string mBrokenImageUrl; ///< Broken image url
TextureId mCurrentTextureId; ///< The current value used for the unique Texture Id generation
};
#include <dali-toolkit/internal/visuals/svg/svg-visual.h>
#include <dali-toolkit/internal/visuals/image-atlas-manager.h>
+
namespace
{
const char * const BROKEN_VISUAL_IMAGE_URL( DALI_IMAGE_DIR "broken.png");
VisualFactoryCache::VisualFactoryCache( bool preMultiplyOnLoad )
: mSvgRasterizeThread( NULL ),
+ mBrokenImageUrl(""),
mPreMultiplyOnLoad( preMultiplyOnLoad )
{
}
if( !mAtlasManager )
{
mAtlasManager = new ImageAtlasManager();
- mAtlasManager->SetBrokenImage( BROKEN_VISUAL_IMAGE_URL );
+ mAtlasManager->SetBrokenImage( mBrokenImageUrl );
}
return mAtlasManager;
Image VisualFactoryCache::GetBrokenVisualImage()
{
- return ResourceImage::New( BROKEN_VISUAL_IMAGE_URL );
+ return ResourceImage::New( mBrokenImageUrl );
}
void VisualFactoryCache::SetPreMultiplyOnLoad( bool preMultiply )
return mPreMultiplyOnLoad;
}
+void VisualFactoryCache::SetBrokenImageUrl(const std::string& brokenImageUrl)
+{
+ mBrokenImageUrl = brokenImageUrl;
+
+ if( !mAtlasManager )
+ {
+ mAtlasManager = new ImageAtlasManager();
+ }
+
+ mAtlasManager->SetBrokenImage( mBrokenImageUrl );
+ mTextureManager.SetBrokenImageUrl( mBrokenImageUrl );
+}
+
} // namespace Internal
} // namespace Toolkit
* @brief Returns an image to be used when a visual has failed to correctly render
* @return The broken image handle.
*/
- static Image GetBrokenVisualImage();
+ Image GetBrokenVisualImage();
/**
* @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
*/
bool GetPreMultiplyOnLoad();
+ /**
+ * @brief Set an image to be used when a visual has failed to correctly render
+ * @param[in] brokenImageUrl The broken image url.
+ */
+ void SetBrokenImageUrl(const std::string& brokenImageUrl);
+
public:
/**
* Get the image atlas manager.
TextureManager mTextureManager;
NPatchLoader mNPatchLoader;
SvgRasterizeThread* mSvgRasterizeThread;
+ std::string mBrokenImageUrl;
bool mPreMultiplyOnLoad;
};
DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::VisualFactory, Dali::BaseHandle, Create, true )
DALI_TYPE_REGISTRATION_END()
+const char * const BROKEN_IMAGE_URL( DALI_IMAGE_DIR "broken.png" ); ///< URL For the broken image
} // namespace
VisualFactory::VisualFactory( bool debugEnabled )
: mFactoryCache(),
+ mSlotDelegate(this),
mDebugEnabled( debugEnabled ),
mPreMultiplyOnLoad( true )
{
{
}
+void VisualFactory::OnStyleChangedSignal( Toolkit::StyleManager styleManager, StyleChange::Type type)
+{
+ if( type == StyleChange::THEME_CHANGE )
+ {
+ std::string brokenImageUrl(BROKEN_IMAGE_URL);
+
+ Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
+ config["brokenImageUrl"].Get( brokenImageUrl );
+
+ if( mFactoryCache )
+ {
+ mFactoryCache->SetBrokenImageUrl(brokenImageUrl);
+ }
+ }
+}
+
Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& propertyMap )
{
Visual::BasePtr visualPtr;
if( !mFactoryCache )
{
mFactoryCache = std::unique_ptr<VisualFactoryCache>( new VisualFactoryCache( mPreMultiplyOnLoad ) );
+
+ std::string brokenImageUrl(BROKEN_IMAGE_URL);
+ Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
+ if( styleManager )
+ {
+ Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager );
+ config["brokenImageUrl"].Get( brokenImageUrl );
+ styleManager.StyleChangedSignal().Connect( mSlotDelegate, &VisualFactory::OnStyleChangedSignal );
+ }
+
+ mFactoryCache->SetBrokenImageUrl(brokenImageUrl);
}
return *mFactoryCache;
}
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/public-api/styling/style-manager.h>
+#include <dali-toolkit/devel-api/styling/style-manager-devel.h>
namespace Dali
{
VisualFactory( bool debugEnabled );
/**
+ * @brief StyleChanged callback
+ *
+ * @param[in] styleManager Handle for style manager.
+ * @param[in] type Style change type.
+ */
+ void OnStyleChangedSignal( Toolkit::StyleManager styleManager, StyleChange::Type type );
+
+ /**
* @copydoc Toolkit::VisualFactory::CreateVisual( const Property::Map& )
*/
Toolkit::Visual::Base CreateVisual( const Property::Map& propertyMap );
private:
std::unique_ptr<VisualFactoryCache> mFactoryCache;
+ SlotDelegate< VisualFactory > mSlotDelegate;
bool mDebugEnabled:1;
bool mPreMultiplyOnLoad:1; ///< Local store for this flag
};
{
"config":
{
+ "brokenImageUrl":"{DALI_IMAGE_DIR}broken.png",
"alwaysShowFocus":true,
"clearFocusOnEscape":false
},
{
"config":
{
+ "brokenImageUrl":"{DALI_IMAGE_DIR}broken.png",
"alwaysShowFocus":false,
"clearFocusOnEscape":true
},
{
"config":
{
+ "brokenImageUrl":"{DALI_IMAGE_DIR}broken.png",
"alwaysShowFocus":false,
"clearFocusOnEscape":true
},