[Tizen] Add VisualBase::GetType() 96/236296/1
authorJiyun Yang <ji.yang@samsung.com>
Tue, 9 Jun 2020 07:26:43 +0000 (16:26 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Tue, 16 Jun 2020 06:27:47 +0000 (15:27 +0900)
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>
22 files changed:
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dummy-visual.cpp
automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
dali-toolkit/devel-api/visual-factory/visual-base.cpp
dali-toolkit/devel-api/visual-factory/visual-base.h
dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/arc/arc-visual.cpp
dali-toolkit/internal/visuals/border/border-visual.cpp
dali-toolkit/internal/visuals/color/color-visual.cpp
dali-toolkit/internal/visuals/gradient/gradient-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/mesh/mesh-visual.cpp
dali-toolkit/internal/visuals/npatch/npatch-visual.cpp
dali-toolkit/internal/visuals/primitive/primitive-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/visual-base-data-impl.cpp
dali-toolkit/internal/visuals/visual-base-data-impl.h
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.h
dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp

index c679479..651797e 100644 (file)
@@ -38,7 +38,7 @@ DummyVisualPtr DummyVisual::New( const Property::Map& properties )
 }
 
 DummyVisual::DummyVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::Type::COLOR ),
   mActionCounter( 0 )
 {
 }
index e50669c..9f922d8 100644 (file)
@@ -46,6 +46,7 @@ const char* TEST_NPATCH_FILE_NAME =  TEST_RESOURCE_DIR "/button-up.9.png";
 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 "/";
 
 
@@ -3670,3 +3671,139 @@ int UtcDaliVisualRoundedCorner(void)
 
   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;
+}
index 7b20c60..c0c6d2b 100644 (file)
@@ -96,6 +96,11 @@ void Visual::Base::CreatePropertyMap( Dali::Property::Map& map ) const
   GetImplementation( *this ).CreatePropertyMap( map );
 }
 
+Visual::Type Visual::Base::GetType() const
+{
+  return GetImplementation( *this ).GetType();
+}
+
 
 
 
index 94db5c4..0d6fd9e 100755 (executable)
@@ -23,6 +23,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/dali-toolkit-common.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
 
 namespace Dali
 {
@@ -190,6 +191,13 @@ public:
    */
   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);
index d4e2f6e..d871c87 100755 (executable)
@@ -216,7 +216,7 @@ AnimatedGradientVisualPtr AnimatedGradientVisual::New( VisualFactoryCache& facto
 }
 
 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();
 }
index a0ebe45..386013a 100755 (executable)
@@ -168,7 +168,7 @@ void AnimatedImageVisual::InitializeGif( const VisualUrl& imageUrl )
 }
 
 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 ),
index a44b5a0..d40eb18 100644 (file)
@@ -84,7 +84,7 @@ AnimatedVectorImageVisualPtr AnimatedVectorImageVisual::New( VisualFactoryCache&
 }
 
 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() ) ),
index a1eb02a..618b75d 100644 (file)
@@ -153,7 +153,7 @@ ArcVisualPtr ArcVisual::New( VisualFactoryCache& factoryCache, const Property::M
 }
 
 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 ),
index a64b48d..63bf8d9 100644 (file)
@@ -125,7 +125,7 @@ BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache, const Prope
 }
 
 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 ),
index 25ea34b..73fb54a 100644 (file)
@@ -135,7 +135,7 @@ ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Propert
 }
 
 ColorVisual::ColorVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::COLOR ),
   mRenderIfTransparent( false )
 {
 }
index 53ea041..afa5e60 100644 (file)
@@ -212,7 +212,7 @@ GradientVisualPtr GradientVisual::New( VisualFactoryCache& factoryCache, const P
 }
 
 GradientVisual::GradientVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+: Visual::Base( factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::GRADIENT ),
   mGradientType( LINEAR ),
   mIsOpaque( true )
 {
index ad3f047..035c41e 100755 (executable)
@@ -156,7 +156,7 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
                           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(),
@@ -182,7 +182,7 @@ ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
 }
 
 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(),
index 7fbb28e..3b918e2 100644 (file)
@@ -351,7 +351,7 @@ MeshVisualPtr MeshVisual::New( VisualFactoryCache& factoryCache, const Property:
 }
 
 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 ),
index 9006a5a..f5d4da5 100755 (executable)
@@ -419,7 +419,7 @@ void NPatchVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
 }
 
 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(),
index 8b2346c..9a9c06f 100644 (file)
@@ -173,7 +173,7 @@ PrimitiveVisualPtr PrimitiveVisual::New( VisualFactoryCache& factoryCache, const
 }
 
 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 ),
index 59c3877..d8d18f7 100644 (file)
@@ -65,7 +65,7 @@ SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, ImageVisualShader
 }
 
 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 ),
index 7b07205..bd23926 100755 (executable)
@@ -380,7 +380,7 @@ void TextVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
 
 
 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 ),
index 67d54d5..acb13e4 100644 (file)
@@ -114,7 +114,7 @@ bool GetPolicyFromValue( const Property::Value& value, Vector2& policy )
 
 } // 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 ),
@@ -127,7 +127,8 @@ Internal::Visual::Base::Impl::Impl(FittingMode fittingMode)
   mCornerRadiusIndex( Property::INVALID_INDEX ),
   mFittingMode( fittingMode ),
   mFlags( 0 ),
-  mResourceStatus( Toolkit::Visual::ResourceStatus::PREPARING )
+  mResourceStatus( Toolkit::Visual::ResourceStatus::PREPARING ),
+  mType( type )
 {
 }
 
index 123a722..906e104 100644 (file)
@@ -46,8 +46,9 @@ struct Base::Impl
   /**
    * 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
@@ -131,6 +132,7 @@ struct Base::Impl
   FittingMode     mFittingMode;  //< How the contents should fit the view
   int             mFlags;
   Toolkit::Visual::ResourceStatus  mResourceStatus;
+  const Toolkit::Visual::Type      mType;
 };
 
 } // namespace Visual
index 3abe018..cff0018 100755 (executable)
@@ -63,8 +63,8 @@ DALI_ENUM_TO_STRING_TABLE_END( VISUAL_FITTING_MODE )
 
 } // 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 )
 {
 }
@@ -492,6 +492,11 @@ bool Visual::Base::IsResourceReady() const
   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;
index ecf832c..9017b36 100644 (file)
@@ -266,14 +266,23 @@ public:
    */
   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().
index 1202d1c..5364de2 100644 (file)
@@ -106,7 +106,7 @@ WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, Visua
 }
 
 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 )
 {
 }