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>
39 class AnimatedImageVisual;
40 typedef IntrusivePtr< AnimatedImageVisual > AnimatedImageVisualPtr;
43 * The visual which renders an animated image
45 * The following property is essential
47 * | %Property Name | Type |
48 * |------------------- |-------------------|
50 * | pixelArea | VECTOR4 |
51 * | wrapModeU | INTEGER OR STRING |
52 * | wrapModeV | INTEGER OR STRING |
54 * where pixelArea is a rectangular area.
55 * In its Vector4 value, the first two elements indicate the top-left position of the area,
56 * and the last two elements are the area width and height respectively.
57 * If not specified, the default value is [0.0, 0.0, 1.0, 1.0], i.e. the entire area of the image.
59 * 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.
60 * Its value should be one of the following wrap mode:
67 class AnimatedImageVisual : public Visual::Base, public ConnectionTracker
73 * @brief Create the animated image Visual using the image URL.
75 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
76 * @param[in] imageUrl The URL to svg resource to use
77 * @param[in] properties A Property::Map containing settings for this visual
78 * @return A smart-pointer to the newly allocated visual.
80 static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties );
83 * @brief Create the animated image visual using the image URL.
85 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
86 * @param[in] imageUrl The URL to animated image resource to use
88 static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
90 public: // from Visual
93 * @copydoc Visual::Base::GetNaturalSize
95 virtual void GetNaturalSize( Vector2& naturalSize );
98 * @copydoc Visual::Base::CreatePropertyMap
100 virtual void DoCreatePropertyMap( Property::Map& map ) const;
105 * @brief Constructor.
107 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
109 AnimatedImageVisual( VisualFactoryCache& factoryCache );
112 * @brief A reference counted object may only be deleted by calling Unreference().
114 virtual ~AnimatedImageVisual();
117 * @copydoc Visual::Base::DoSetProperties
119 virtual void DoSetProperties( const Property::Map& propertyMap );
122 * @copydoc Visual::Base::DoSetOnStage
124 virtual void DoSetOnStage( Actor& actor );
127 * @copydoc Visual::Base::DoSetOffStage
129 virtual void DoSetOffStage( Actor& actor );
132 * @copydoc Visual::Base::OnSetTransform
134 virtual void OnSetTransform();
139 * Load the animated image and pack the frames into atlas.
140 * @return That atlas texture.
142 Texture PrepareAnimatedImage();
145 * Display the next frame. It is called when the mFrameDelayTimes ticks.
147 bool DisplayNextFrame();
150 AnimatedImageVisual( const AnimatedImageVisual& animatedImageVisual );
153 AnimatedImageVisual& operator=( const AnimatedImageVisual& animatedImageVisual );
157 Timer mFrameDelayTimer;
158 Dali::Vector<Vector4> mTextureRectContainer;
159 Dali::Vector<uint32_t> mFrameDelayContainer;
161 std::string mImageUrl;
163 ImageDimensions mImageSize;
164 uint32_t mCurrentFrameIndex;
165 Dali::WrapMode::Type mWrapModeU:3;
166 Dali::WrapMode::Type mWrapModeV:3;
169 } // namespace Internal
171 } // namespace Toolkit
174 #endif /* DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H */