1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/weak-handle.h>
24 #include <dali/public-api/object/property-notification.h>
25 #include <dali/devel-api/actors/actor-devel.h>
26 #include <dali/public-api/adaptor-framework/window.h>
29 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
30 #include <dali-toolkit/internal/visuals/visual-url.h>
31 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
32 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
43 class ImageVisualShaderFactory;
44 class AnimatedVectorImageVisual;
45 using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
48 * The visual which renders an animated vector image using VectorAnimationRenderer.
49 * VectorAnimationRenderer renders the animation image and this visuall controls the images.
51 * The following property is essential
53 * | %Property Name | Type |
54 * |--------------------------|------------------|
58 class AnimatedVectorImageVisual: public Visual::Base, public ConnectionTracker
63 * @brief Create the AnimatedVectorImageVisual using the image URL.
65 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
66 * @param[in] shaderFactory The ImageVisualShaderFactory object
67 * @param[in] imageUrl The URL to an animated vector image to use
68 * @param[in] properties A Property::Map containing settings for this visual
69 * @return A smart-pointer to the newly allocated visual.
71 static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
74 * @brief Create the AnimatedVectorImageVisual using the image URL.
76 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
77 * @param[in] shaderFactory The ImageVisualShaderFactory object
78 * @param[in] imageUrl The URL to an animated vector image to use
79 * @return A smart-pointer to the newly allocated visual.
81 static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
83 public: // from Visual
86 * @copydoc Visual::Base::GetNaturalSize
88 void GetNaturalSize( Vector2& naturalSize ) override;
91 * @copydoc Visual::Base::CreatePropertyMap
93 void DoCreatePropertyMap( Property::Map& map ) const override;
96 * @copydoc Visual::Base::CreateInstancePropertyMap
98 void DoCreateInstancePropertyMap( Property::Map& map ) const override;
103 * @brief Constructor.
105 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
106 * @param[in] shaderFactory The ImageVisualShaderFactory object
107 * @param[in] imageUrl The URL to an animated vector image to use
109 AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
112 * @brief A reference counted object may only be deleted by calling Unreference().
114 virtual ~AnimatedVectorImageVisual();
117 * @copydoc Visual::Base::DoSetProperties
119 void DoSetProperties( const Property::Map& propertyMap ) override;
122 * @copydoc Visual::Base::DoSetOnStage
124 void DoSetOnStage( Actor& actor ) override;
127 * @copydoc Visual::Base::DoSetOffStage
129 void DoSetOffStage( Actor& actor ) override;
132 * @copydoc Visual::Base::OnSetTransform
134 void OnSetTransform() override;
137 * @copydoc Visual::Base::OnDoAction
139 void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
144 * Helper method to set individual values by index key.
145 * @param[in] index The index key of the value
146 * @param[in] value The value
148 void DoSetProperty( Property::Index index, const Property::Value& value );
151 * @brief Called when the texture upload is completed.
153 void OnUploadCompleted();
156 * @brief Event callback from rasterize thread. This is called after the animation is finished.
158 void OnAnimationFinished();
161 * @brief Send animation data to the rasterize thread.
163 void SendAnimationData();
166 * @brief Set the vector image size.
168 void SetVectorImageSize();
171 * @brief Pause the animation.
173 void PauseAnimation();
176 * @brief Callback when the world scale factor changes.
178 void OnScaleNotification( PropertyNotification& source );
181 * @brief Callback when the size changes.
183 void OnSizeNotification( PropertyNotification& source );
186 * @brief Callback when the visibility of the actor is changed.
188 void OnControlVisibilityChanged( Actor actor, bool visible, DevelActor::VisibilityChange::Type type );
191 * @brief Callback when the visibility of the window is changed.
193 void OnWindowVisibilityChanged( Window window, bool visible );
196 AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
199 AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
203 VectorAnimationTaskPtr mVectorAnimationTask;
204 ImageVisualShaderFactory& mImageVisualShaderFactory;
205 PropertyNotification mScaleNotification;
206 PropertyNotification mSizeNotification;
208 Vector2 mVisualScale;
209 WeakHandle< Actor > mPlacementActor;
211 uint32_t mStartFrame;
213 uint32_t mResendFlag;
214 DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
215 DevelImageVisual::StopBehavior::Type mStopBehavior;
216 DevelImageVisual::LoopingMode::Type mLoopingMode;
220 } // namespace Internal
222 } // namespace Toolkit
226 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H