Merge "Removed unnecessary try-catch from Control base class" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / animated-vector-image-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/weak-handle.h>
24 #include <memory>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
28 #include <dali-toolkit/internal/visuals/visual-url.h>
29 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 class ImageVisualShaderFactory;
41 class VectorRasterizeThread;
42 class AnimatedVectorImageVisual;
43 using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
44
45 /**
46  * The visual which renders an animated vector image using VectorAnimationRenderer.
47  * VectorAnimationRenderer renders the animation image and this visuall controls the images.
48  *
49  * The following property is essential
50  *
51  * | %Property Name           | Type             |
52  * |--------------------------|------------------|
53  * | url                      | STRING           |
54  *
55  */
56 class AnimatedVectorImageVisual: public Visual::Base
57 {
58 public:
59
60   /**
61    * @brief Create the AnimatedVectorImageVisual using the image URL.
62    *
63    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
64    * @param[in] shaderFactory The ImageVisualShaderFactory object
65    * @param[in] imageUrl The URL to an animated vector image to use
66    * @param[in] properties A Property::Map containing settings for this visual
67    * @return A smart-pointer to the newly allocated visual.
68    */
69   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
70
71   /**
72    * @brief Create the AnimatedVectorImageVisual using the image URL.
73    *
74    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
75    * @param[in] shaderFactory The ImageVisualShaderFactory object
76    * @param[in] imageUrl The URL to an animated vector image to use
77    * @return A smart-pointer to the newly allocated visual.
78    */
79   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
80
81 public:  // from Visual
82
83   /**
84    * @copydoc Visual::Base::GetNaturalSize
85    */
86   virtual void GetNaturalSize( Vector2& naturalSize ) override;
87
88   /**
89    * @copydoc Visual::Base::CreatePropertyMap
90    */
91   virtual void DoCreatePropertyMap( Property::Map& map ) const override;
92
93   /**
94    * @copydoc Visual::Base::CreateInstancePropertyMap
95    */
96   virtual void DoCreateInstancePropertyMap( Property::Map& map ) const override;
97
98 protected:
99
100   /**
101    * @brief Constructor.
102    *
103    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
104    * @param[in] shaderFactory The ImageVisualShaderFactory object
105    * @param[in] imageUrl The URL to an animated vector image to use
106    */
107   AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
108
109   /**
110    * @brief A reference counted object may only be deleted by calling Unreference().
111    */
112   virtual ~AnimatedVectorImageVisual();
113
114   /**
115    * @copydoc Visual::Base::DoSetProperties
116    */
117   virtual void DoSetProperties( const Property::Map& propertyMap ) override;
118
119   /**
120    * @copydoc Visual::Base::DoSetOnStage
121    */
122   virtual void DoSetOnStage( Actor& actor ) override;
123
124   /**
125    * @copydoc Visual::Base::DoSetOffStage
126    */
127   virtual void DoSetOffStage( Actor& actor ) override;
128
129   /**
130    * @copydoc Visual::Base::OnSetTransform
131    */
132   virtual void OnSetTransform() override;
133
134   /**
135    * @copydoc Visual::Base::OnDoAction
136    */
137   virtual void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
138
139 private:
140
141   /**
142    * Helper method to set individual values by index key.
143    * @param[in] index The index key of the value
144    * @param[in] value The value
145    */
146   void DoSetProperty( Property::Index index, const Property::Value& value );
147
148   /**
149    * @brief Event callback from rasterize thread. This is called after the first frame is ready.
150    */
151   void OnResourceReady();
152
153   // Undefined
154   AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
155
156   // Undefined
157   AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
158
159 private:
160   ImageVisualShaderFactory&                    mImageVisualShaderFactory;
161   VisualUrl                                    mUrl;
162   Vector2                                      mVisualSize;
163   Vector2                                      mPlayRange;
164   WeakHandle< Actor >                          mPlacementActor;
165   std::unique_ptr< VectorRasterizeThread >     mVectorRasterizeThread;
166
167   int32_t                                      mLoopCount;
168   DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
169 };
170
171 } // namespace Internal
172
173 } // namespace Toolkit
174
175 } // namespace Dali
176
177 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H