Some controls want to know the visual type when the visual is given from the user.
To do that in current DALi, it needs to call CreatePropertyMap() and get TYPE property from the map.
Instead, this patch provides an API Visual::Base::GetType() to make it easy to see what the visual type is.
Change-Id: I387a6cc43466897b2de17d3c2d9bae7dba201a10
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
}
DummyVisual::DummyVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::Type::COLOR ),
mActionCounter( 0 )
{
}
const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
+const char* TEST_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json";
const char* TEST_RESOURCE_LOCATION = TEST_RESOURCE_DIR "/";
END_TEST;
}
+
+int UtcDaliVisualGetType(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliVisualGetType" );
+
+ VisualFactory factory = VisualFactory::Get();
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::BORDER;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::BORDER );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::COLOR;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::COLOR );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::GRADIENT;
+ properties[GradientVisual::Property::START_POSITION] = Vector2( -1.f, -1.f );
+ properties[GradientVisual::Property::END_POSITION] = Vector2( 1.f, 1.f );
+ properties[GradientVisual::Property::STOP_OFFSET] = Vector2(0.f, 1.f);
+ // propertyMap.Insert( GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT) ;
+ Property::Array stopColors;
+ stopColors.PushBack( Color::RED );
+ stopColors.PushBack( Color::GREEN );
+ properties[GradientVisual::Property::STOP_COLOR] = stopColors;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::GRADIENT );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::IMAGE;
+ properties.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::IMAGE );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::MESH;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::MESH );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::PRIMITIVE;
+ properties[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::CUBE;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::PRIMITIVE );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::WIREFRAME;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::WIREFRAME );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::TEXT;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::TEXT );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::N_PATCH;
+ properties[ImageVisual::Property::URL] = TEST_NPATCH_FILE_NAME;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::N_PATCH );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::SVG;
+ properties[ImageVisual::Property::URL] = TEST_SVG_FILE_NAME;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::SVG );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = Visual::ANIMATED_IMAGE;
+ properties[ImageVisual::Property::URL] = TEST_GIF_FILE_NAME;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == Visual::ANIMATED_IMAGE );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = DevelVisual::ANIMATED_GRADIENT;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == static_cast<Visual::Type>( DevelVisual::ANIMATED_GRADIENT ) );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = DevelVisual::ANIMATED_VECTOR_IMAGE;
+ properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == static_cast<Visual::Type>( DevelVisual::ANIMATED_VECTOR_IMAGE ) );
+ }
+
+ {
+ Property::Map properties;
+ properties[Visual::Property::TYPE] = DevelVisual::ARC;
+ Visual::Base visual = factory.CreateVisual( properties );
+
+ DALI_TEST_CHECK( visual.GetType() == static_cast<Visual::Type>( DevelVisual::ARC ) );
+ }
+
+ END_TEST;
+}
GetImplementation( *this ).CreatePropertyMap( map );
}
+Visual::Type Visual::Base::GetType() const
+{
+ return GetImplementation( *this ).GetType();
+}
+
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/dali-toolkit-common.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
namespace Dali
{
*/
void CreatePropertyMap( Dali::Property::Map& map ) const;
+ /**
+ * @brief Get the type of this visual.
+ *
+ * @return The the type of this visual.
+ */
+ Visual::Type GetType() const;
+
public: // Not intended for application developers
explicit DALI_INTERNAL Base(Internal::Visual::Base *impl);
}
AnimatedGradientVisual::AnimatedGradientVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL )
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>( Toolkit::DevelVisual::ANIMATED_GRADIENT ) )
{
SetupDefaultValue();
}
}
AnimatedImageVisual::AnimatedImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory )
-: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::ANIMATED_IMAGE ),
mFrameDelayTimer(),
mPlacementActor(),
mImageVisualShaderFactory( shaderFactory ),
}
AnimatedVectorImageVisual::AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>( Toolkit::DevelVisual::ANIMATED_VECTOR_IMAGE ) ),
mUrl( imageUrl ),
mAnimationData(),
mVectorAnimationTask( new VectorAnimationTask( factoryCache, imageUrl.GetUrl() ) ),
}
ArcVisual::ArcVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, static_cast<Toolkit::Visual::Type>( Toolkit::DevelVisual::ARC ) ),
mThickness( 0.0f ),
mRadius( 0.0f ),
mStartAngle( 0.0f ),
}
BorderVisual::BorderVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::BORDER ),
mBorderColor( Color::TRANSPARENT ),
mBorderSize( 0.f ),
mBorderColorIndex( Property::INVALID_INDEX ),
}
ColorVisual::ColorVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR ),
mRenderIfTransparent( false )
{
}
}
GradientVisual::GradientVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::GRADIENT ),
mGradientType( LINEAR ),
mIsOpaque( true )
{
ImageDimensions size,
FittingMode::Type fittingMode,
Dali::SamplingMode::Type samplingMode )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE ),
mImage(),
mPixelArea( FULL_TEXTURE_RECT ),
mPlacementActor(),
}
ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const Image& image )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE ),
mImage( image ),
mPixelArea( FULL_TEXTURE_RECT ),
mPlacementActor(),
}
MeshVisual::MeshVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::MESH ),
mShadingMode( Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING ),
mUseTexture( true ),
mUseMipmapping( true ),
}
NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::N_PATCH ),
mLoader( factoryCache.GetNPatchLoader() ),
mImageUrl(),
mAuxiliaryUrl(),
}
PrimitiveVisual::PrimitiveVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::PRIMITIVE ),
mScaleDimensions( Vector3::ONE ),
mScaleTopRadius( DEFAULT_SCALE_TOP_RADIUS ),
mScaleBottomRadius( DEFAULT_SCALE_BOTTOM_RADIUS ),
}
SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::SVG ),
mImageVisualShaderFactory( shaderFactory ),
mAtlasRect( FULL_TEXTURE_RECT ),
mImageUrl( imageUrl ),
TextVisual::TextVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ),
+: Visual::Base( factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::TEXT ),
mController( Text::Controller::New() ),
mTypesetter( Text::Typesetter::New( mController->GetTextModel() ) ),
mAnimatableTextColorPropertyIndex( Property::INVALID_INDEX ),
} // unnamed namespace
-Internal::Visual::Base::Impl::Impl(FittingMode fittingMode)
+Internal::Visual::Base::Impl::Impl( FittingMode fittingMode, Toolkit::Visual::Type type )
: mCustomShader( NULL ),
mBlendSlotDelegate( NULL ),
mEventObserver( NULL ),
mCornerRadiusIndex( Property::INVALID_INDEX ),
mFittingMode( fittingMode ),
mFlags( 0 ),
- mResourceStatus( Toolkit::Visual::ResourceStatus::PREPARING )
+ mResourceStatus( Toolkit::Visual::ResourceStatus::PREPARING ),
+ mType( type )
{
}
/**
* Constructor
* @param [in] fittingMode that the derived class prefers
+ * @param [in] type The type of the this visual
*/
- Impl(FittingMode fittingMode);
+ Impl( FittingMode fittingMode, Toolkit::Visual::Type type );
/**
* Destructor
FittingMode mFittingMode; //< How the contents should fit the view
int mFlags;
Toolkit::Visual::ResourceStatus mResourceStatus;
+ const Toolkit::Visual::Type mType;
};
} // namespace Visual
} // namespace
-Visual::Base::Base( VisualFactoryCache& factoryCache, FittingMode fittingMode )
-: mImpl( new Impl(fittingMode) ),
+Visual::Base::Base( VisualFactoryCache& factoryCache, FittingMode fittingMode, Toolkit::Visual::Type type )
+: mImpl( new Impl( fittingMode, type ) ),
mFactoryCache( factoryCache )
{
}
return ( mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY );
}
+Toolkit::Visual::Type Visual::Base::GetType() const
+{
+ return mImpl->mType;
+}
+
Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
{
return mImpl->mResourceStatus;
*/
virtual Base& GetVisualObject();
+ /**
+ * @brief Get the type of this visual.
+ *
+ * @return The the type of this visual.
+ */
+ Toolkit::Visual::Type GetType() const;
+
protected:
/**
* @brief Constructor.
*
* @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+ * @param[in] fittingMode The value that determines how the visual should be fit to the view
+ * @param[in] type The type of the this visual
*/
- Base( VisualFactoryCache& factoryCache, FittingMode fittingMode );
+ Base( VisualFactoryCache& factoryCache, FittingMode fittingMode, Toolkit::Visual::Type type );
/**
* @brief A reference counted object may only be deleted by calling Unreference().
}
WireframeVisual::WireframeVisual( VisualFactoryCache& factoryCache, Visual::BasePtr actualVisual )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, actualVisual ? actualVisual->GetType() : Toolkit::Visual::WIREFRAME ),
mActualVisual( actualVisual )
{
}