1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
5 * Copyright (c) 2016 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/common/dali-vector.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/adaptor-framework/timer.h>
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
40 class AnimatedImageVisual;
41 typedef IntrusivePtr< AnimatedImageVisual > AnimatedImageVisualPtr;
44 * The visual which renders an animated image
46 * The following property is essential
48 * | %Property Name | Type |
49 * |------------------- |-------------------|
51 * | pixelArea | VECTOR4 |
52 * | wrapModeU | INTEGER OR STRING |
53 * | wrapModeV | INTEGER OR STRING |
55 * where pixelArea is a rectangular area.
56 * In its Vector4 value, the first two elements indicate the top-left position of the area,
57 * and the last two elements are the area width and height respectively.
58 * If not specified, the default value is [0.0, 0.0, 1.0, 1.0], i.e. the entire area of the image.
60 * where wrapModeU and wrapModeV separately decide how the texture should be sampled when the u and v coordinate exceeds the range of 0.0 to 1.0.
61 * Its value should be one of the following wrap mode:
68 class AnimatedImageVisual : public Visual::Base, public ConnectionTracker
74 * @brief Create the animated image Visual using the image URL.
76 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
77 * @param[in] imageUrl The URL to svg resource to use
78 * @param[in] properties A Property::Map containing settings for this visual
79 * @return A smart-pointer to the newly allocated visual.
81 static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
84 * @brief Create the animated image visual using the image URL.
86 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
87 * @param[in] imageUrl The URL to animated image resource to use
89 static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
91 public: // from Visual
94 * @copydoc Visual::Base::GetNaturalSize
96 virtual void GetNaturalSize( Vector2& naturalSize );
99 * @copydoc Visual::Base::CreatePropertyMap
101 virtual void DoCreatePropertyMap( Property::Map& map ) const;
104 * @copydoc Visual::Base::CreateInstancePropertyMap
106 virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
111 * @brief Constructor.
113 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
115 AnimatedImageVisual( VisualFactoryCache& factoryCache );
118 * @brief A reference counted object may only be deleted by calling Unreference().
120 virtual ~AnimatedImageVisual();
123 * @copydoc Visual::Base::DoSetProperties
125 virtual void DoSetProperties( const Property::Map& propertyMap );
128 * @copydoc Visual::Base::DoSetOnStage
130 virtual void DoSetOnStage( Actor& actor );
133 * @copydoc Visual::Base::DoSetOffStage
135 virtual void DoSetOffStage( Actor& actor );
138 * @copydoc Visual::Base::OnSetTransform
140 virtual void OnSetTransform();
145 * Load the animated image and pack the frames into atlas.
146 * @return That atlas texture.
148 Texture PrepareAnimatedImage();
151 * Display the next frame. It is called when the mFrameDelayTimes ticks.
153 bool DisplayNextFrame();
156 AnimatedImageVisual( const AnimatedImageVisual& animatedImageVisual );
159 AnimatedImageVisual& operator=( const AnimatedImageVisual& animatedImageVisual );
163 Timer mFrameDelayTimer;
164 Dali::Vector<Vector4> mTextureRectContainer;
165 Dali::Vector<uint32_t> mFrameDelayContainer;
169 ImageDimensions mImageSize;
170 uint32_t mCurrentFrameIndex;
171 Dali::WrapMode::Type mWrapModeU:3;
172 Dali::WrapMode::Type mWrapModeV:3;
175 } // namespace Internal
177 } // namespace Toolkit
180 #endif /* DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H */