/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/property-array.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
-#include <dali/devel-api/scripting/enum-helper.h>
#include <dali/devel-api/scripting/scripting.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/text-visual-properties.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/visuals/border/border-visual.h>
#include <dali-toolkit/internal/visuals/color/color-visual.h>
#include <dali-toolkit/internal/visuals/gradient/gradient-visual.h>
+#include <dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.h>
#include <dali-toolkit/internal/visuals/image/image-visual.h>
#include <dali-toolkit/internal/visuals/mesh/mesh-visual.h>
#include <dali-toolkit/internal/visuals/npatch/npatch-visual.h>
#include <dali-toolkit/internal/visuals/primitive/primitive-visual.h>
#include <dali-toolkit/internal/visuals/svg/svg-visual.h>
+#include <dali-toolkit/internal/visuals/text/text-visual.h>
+#include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
#include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
-namespace
-{
-const char * const BROKEN_VISUAL_IMAGE_URL( DALI_IMAGE_DIR "broken.png");
-}
-
namespace Dali
{
namespace
{
-DALI_ENUM_TO_STRING_TABLE_BEGIN( VISUAL_TYPE )
-DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, BORDER )
-DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, COLOR )
-DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, GRADIENT )
-DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, IMAGE )
-DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, MESH )
-DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, PRIMITIVE )
-DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Visual, WIREFRAME )
-DALI_ENUM_TO_STRING_TABLE_END( VISUAL_TYPE )
-
-const char * const VISUAL_TYPE( "visualType" );
-
BaseHandle Create()
{
BaseHandle handle = Toolkit::VisualFactory::Get();
} // namespace
VisualFactory::VisualFactory( bool debugEnabled )
-:mDebugEnabled( debugEnabled )
+: mDebugEnabled( debugEnabled ),
+ mPreMultiplyOnLoad( true )
{
}
Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& propertyMap )
{
- // Create factory cache if it hasn't already been
- if( !mFactoryCache )
- {
- mFactoryCache = new VisualFactoryCache();
- }
-
- // Return a new WireframeVisual if we have debug enabled
- if( mDebugEnabled )
- {
- return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) );
- }
-
- Visual::Base* visualPtr = NULL;
+ Visual::BasePtr visualPtr;
Property::Value* typeValue = propertyMap.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE );
- Toolkit::Visual::Type visualType = Toolkit::Visual::IMAGE; // Default to IMAGE type
+ Toolkit::DevelVisual::Type visualType = Toolkit::DevelVisual::IMAGE; // Default to IMAGE type.
if( typeValue )
{
Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, visualType );
{
case Toolkit::Visual::BORDER:
{
- visualPtr = new BorderVisual( *( mFactoryCache.Get() ) );
+ visualPtr = BorderVisual::New( GetFactoryCache(), propertyMap );
break;
}
case Toolkit::Visual::COLOR:
{
- visualPtr = new ColorVisual( *( mFactoryCache.Get() ) );
+ visualPtr = ColorVisual::New( GetFactoryCache(), propertyMap );
break;
}
case Toolkit::Visual::GRADIENT:
{
- visualPtr = new GradientVisual( *( mFactoryCache.Get() ) );
+ visualPtr = GradientVisual::New( GetFactoryCache(), propertyMap );
break;
}
{
Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
std::string imageUrl;
- if( imageURLValue && imageURLValue->Get( imageUrl ) )
+ if( imageURLValue )
{
- if( NinePatchImage::IsNinePatchUrl( imageUrl ) )
+ if( imageURLValue->Get( imageUrl ) )
{
- visualPtr = new NPatchVisual( *( mFactoryCache.Get() ) );
+ if( !imageUrl.empty() )
+ {
+ VisualUrl visualUrl( imageUrl );
+
+ switch( visualUrl.GetType() )
+ {
+ case VisualUrl::N_PATCH:
+ {
+ visualPtr = NPatchVisual::New( GetFactoryCache(), visualUrl, propertyMap );
+ break;
+ }
+ case VisualUrl::SVG:
+ {
+ visualPtr = SvgVisual::New( GetFactoryCache(), visualUrl, propertyMap );
+ break;
+ }
+ case VisualUrl::GIF:
+ {
+ visualPtr = AnimatedImageVisual::New( GetFactoryCache(), visualUrl, propertyMap );
+ break;
+ }
+ case VisualUrl::REGULAR_IMAGE:
+ {
+ visualPtr = ImageVisual::New( GetFactoryCache(), visualUrl, propertyMap );
+ break;
+ }
+ }
+ }
}
else
{
- CreateAtlasManager();
-
- if( SvgVisual::IsSvgUrl( imageUrl ) )
- {
- visualPtr = new SvgVisual( *( mFactoryCache.Get() ), *( mAtlasManager.Get() ) );
- }
- else
+ Property::Array* array = imageURLValue->GetArray();
+ if( array )
{
- visualPtr = new ImageVisual( *( mFactoryCache.Get() ), *( mAtlasManager.Get() ) );
+ visualPtr = AnimatedImageVisual::New( GetFactoryCache(), *array, propertyMap );
}
}
}
case Toolkit::Visual::MESH:
{
- visualPtr = new MeshVisual( *( mFactoryCache.Get() ) );
+ visualPtr = MeshVisual::New( GetFactoryCache(), propertyMap );
break;
}
case Toolkit::Visual::PRIMITIVE:
{
- visualPtr = new PrimitiveVisual( *( mFactoryCache.Get() ) );
+ visualPtr = PrimitiveVisual::New( GetFactoryCache(), propertyMap );
break;
}
case Toolkit::Visual::WIREFRAME:
{
- visualPtr = new WireframeVisual( *( mFactoryCache.Get() ) );
+ visualPtr = WireframeVisual::New( GetFactoryCache(), propertyMap );
+ break;
+ }
+
+ case Toolkit::Visual::TEXT:
+ {
+ visualPtr = TextVisual::New( GetFactoryCache(), propertyMap );
+ break;
+ }
+
+ case Toolkit::Visual::N_PATCH:
+ {
+ Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
+ std::string imageUrl;
+ if( imageURLValue && imageURLValue->Get( imageUrl ) )
+ {
+ visualPtr = NPatchVisual::New( GetFactoryCache(), imageUrl, propertyMap );
+ }
+ break;
+ }
+
+ case Toolkit::Visual::SVG:
+ {
+ Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
+ std::string imageUrl;
+ if( imageURLValue && imageURLValue->Get( imageUrl ) )
+ {
+ visualPtr = SvgVisual::New( GetFactoryCache(), imageUrl, propertyMap );
+ }
+ break;
+ }
+
+ case Toolkit::Visual::ANIMATED_IMAGE:
+ {
+ Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
+ std::string imageUrl;
+ if( imageURLValue )
+ {
+ if( imageURLValue->Get( imageUrl ) )
+ {
+ visualPtr = AnimatedImageVisual::New( GetFactoryCache(), imageUrl, propertyMap );
+ }
+ else
+ {
+ Property::Array* array = imageURLValue->GetArray();
+ if( array )
+ {
+ visualPtr = AnimatedImageVisual::New( GetFactoryCache(), *array, propertyMap );
+ }
+ }
+ }
+ break;
+ }
+
+ case Toolkit::DevelVisual::ANIMATED_GRADIENT:
+ {
+ visualPtr = AnimatedGradientVisual::New( GetFactoryCache(), propertyMap );
break;
}
}
- if( visualPtr )
+ if( !visualPtr )
{
- Actor actor;
- visualPtr->Initialize( actor, propertyMap );
+ DALI_LOG_ERROR( "Renderer type unknown\n" );
}
- else
+
+ if( mDebugEnabled && visualType != Toolkit::DevelVisual::WIREFRAME )
{
- DALI_LOG_ERROR( "Renderer type unknown\n" );
+ //Create a WireframeVisual if we have debug enabled
+ visualPtr = WireframeVisual::New(GetFactoryCache(), visualPtr, propertyMap );
}
- return Toolkit::Visual::Base( visualPtr );
+ return Toolkit::Visual::Base( visualPtr.Get() );
}
Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image )
{
- if( !mFactoryCache )
- {
- mFactoryCache = new VisualFactoryCache();
- }
+ Visual::BasePtr visualPtr;
- if( mDebugEnabled )
+ if( image )
{
- return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) );
+ NinePatchImage npatchImage = NinePatchImage::DownCast( image );
+ if( npatchImage )
+ {
+ visualPtr = NPatchVisual::New( GetFactoryCache(), npatchImage );
+ }
+ else
+ {
+ visualPtr = ImageVisual::New(GetFactoryCache(), image );
+ }
}
- NinePatchImage npatchImage = NinePatchImage::DownCast( image );
- if( npatchImage )
+ if( mDebugEnabled )
{
- NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ) );
- visualPtr->SetImage( npatchImage );
-
- return Toolkit::Visual::Base( visualPtr );
+ //Create a WireframeVisual if we have debug enabled
+ visualPtr = WireframeVisual::New( GetFactoryCache(), visualPtr );
}
- else
- {
- CreateAtlasManager();
- ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), *( mAtlasManager.Get() ) );
- Actor actor;
- visualPtr->SetImage( actor, image );
- return Toolkit::Visual::Base( visualPtr );
- }
+ return Toolkit::Visual::Base( visualPtr.Get() );
}
Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, ImageDimensions size )
{
- if( !mFactoryCache )
+ Visual::BasePtr visualPtr;
+
+ if( !url.empty() )
{
- mFactoryCache = new VisualFactoryCache();
+ // first resolve url type to know which visual to create
+ VisualUrl visualUrl( url );
+ switch( visualUrl.GetType() )
+ {
+ case VisualUrl::N_PATCH:
+ {
+ visualPtr = NPatchVisual::New( GetFactoryCache(), visualUrl );
+ break;
+ }
+ case VisualUrl::SVG:
+ {
+ visualPtr = SvgVisual::New( GetFactoryCache(), visualUrl );
+ break;
+ }
+ case VisualUrl::GIF:
+ {
+ visualPtr = AnimatedImageVisual::New( GetFactoryCache(), visualUrl );
+ break;
+ }
+ case VisualUrl::REGULAR_IMAGE:
+ {
+ visualPtr = ImageVisual::New(GetFactoryCache(), visualUrl, size );
+ break;
+ }
+ }
}
if( mDebugEnabled )
{
- return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) );
+ //Create a WireframeVisual if we have debug enabled
+ visualPtr = WireframeVisual::New( GetFactoryCache(), visualPtr );
}
- if( NinePatchImage::IsNinePatchUrl( url ) )
- {
- NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ) );
- visualPtr->SetImage( url );
+ return Toolkit::Visual::Base( visualPtr.Get() );
+}
- return Toolkit::Visual::Base( visualPtr );
- }
- else if( SvgVisual::IsSvgUrl( url ) )
+void VisualFactory::SetPreMultiplyOnLoad( bool preMultiply )
+{
+ if( mPreMultiplyOnLoad != preMultiply )
{
- CreateAtlasManager();
- SvgVisual* visualPtr = new SvgVisual( *( mFactoryCache.Get() ), *( mAtlasManager.Get() ) );
- visualPtr->SetImage( url, size );
- return Toolkit::Visual::Base( visualPtr );
+ GetFactoryCache().SetPreMultiplyOnLoad( preMultiply );
}
- else
- {
- CreateAtlasManager();
- ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), *( mAtlasManager.Get() ) );
- Actor actor;
- visualPtr->SetImage( actor, url, size );
+ mPreMultiplyOnLoad = preMultiply;
+}
- return Toolkit::Visual::Base( visualPtr );
- }
+bool VisualFactory::GetPreMultiplyOnLoad() const
+{
+ return mPreMultiplyOnLoad;
}
-Image VisualFactory::GetBrokenVisualImage()
+Internal::TextureManager& VisualFactory::GetTextureManager()
{
- return ResourceImage::New( BROKEN_VISUAL_IMAGE_URL );
+ return GetFactoryCache().GetTextureManager();
}
-void VisualFactory::CreateAtlasManager()
+Internal::VisualFactoryCache& VisualFactory::GetFactoryCache()
{
- if( !mAtlasManager )
+ if( !mFactoryCache )
{
- Shader shader = ImageVisual::GetImageShader( *( mFactoryCache.Get() ) );
- mAtlasManager = new ImageAtlasManager();
- mAtlasManager->SetBrokenImage( BROKEN_VISUAL_IMAGE_URL );
+ mFactoryCache = std::unique_ptr<VisualFactoryCache>( new VisualFactoryCache( mPreMultiplyOnLoad ) );
}
+ return *mFactoryCache;
}
} // namespace Internal