Encapsulated visual URL in new VisualUrl class.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / animated-image-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
3
4 /*
5  * Copyright (c) 2016 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/common/dali-vector.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/adaptor-framework/timer.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 class AnimatedImageVisual;
41 typedef IntrusivePtr< AnimatedImageVisual > AnimatedImageVisualPtr;
42
43 /**
44  * The visual which renders an animated image
45  *
46  * The following property is essential
47  *
48  * | %Property Name     | Type              |
49  * |------------------- |-------------------|
50  * | url                | STRING            |
51  * | pixelArea          | VECTOR4           |
52  * | wrapModeU          | INTEGER OR STRING |
53  * | wrapModeV          | INTEGER OR STRING |
54  *
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.
59  *
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:
62  *   "DEFAULT"
63  *   "CLAMP_TO_EDGE"
64  *   "REPEAT"
65  *   "MIRRORED_REPEAT"
66  */
67
68 class AnimatedImageVisual : public Visual::Base, public ConnectionTracker
69 {
70
71 public:
72
73   /**
74    * @brief Create the animated image Visual using the image URL.
75    *
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.
80    */
81   static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
82
83   /**
84    * @brief Create the animated image visual using the image URL.
85    *
86    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
87    * @param[in] imageUrl The URL to animated image resource to use
88    */
89   static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
90
91 public:  // from Visual
92
93   /**
94    * @copydoc Visual::Base::GetNaturalSize
95    */
96   virtual void GetNaturalSize( Vector2& naturalSize );
97
98   /**
99    * @copydoc Visual::Base::CreatePropertyMap
100    */
101   virtual void DoCreatePropertyMap( Property::Map& map ) const;
102
103   /**
104    * @copydoc Visual::Base::CreateInstancePropertyMap
105    */
106   virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
107
108 protected:
109
110   /**
111    * @brief Constructor.
112    *
113    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
114    */
115   AnimatedImageVisual( VisualFactoryCache& factoryCache );
116
117   /**
118    * @brief A reference counted object may only be deleted by calling Unreference().
119    */
120   virtual ~AnimatedImageVisual();
121
122   /**
123    * @copydoc Visual::Base::DoSetProperties
124    */
125   virtual void DoSetProperties( const Property::Map& propertyMap );
126
127   /**
128    * @copydoc Visual::Base::DoSetOnStage
129    */
130   virtual void DoSetOnStage( Actor& actor );
131
132   /**
133    * @copydoc Visual::Base::DoSetOffStage
134    */
135   virtual void DoSetOffStage( Actor& actor );
136
137   /**
138    * @copydoc Visual::Base::OnSetTransform
139    */
140   virtual void OnSetTransform();
141
142 private:
143
144   /**
145    * Load the animated image and pack the frames into atlas.
146    * @return That atlas texture.
147    */
148   Texture PrepareAnimatedImage();
149
150   /**
151    * Display the next frame. It is called when the mFrameDelayTimes ticks.
152    */
153   bool DisplayNextFrame();
154
155   // Undefined
156   AnimatedImageVisual( const AnimatedImageVisual& animatedImageVisual );
157
158   // Undefined
159   AnimatedImageVisual& operator=( const AnimatedImageVisual& animatedImageVisual );
160
161 private:
162
163   Timer mFrameDelayTimer;
164   Dali::Vector<Vector4> mTextureRectContainer;
165   Dali::Vector<uint32_t> mFrameDelayContainer;
166   Vector4 mPixelArea;
167   VisualUrl mImageUrl;
168
169   ImageDimensions mImageSize;
170   uint32_t mCurrentFrameIndex;
171   Dali::WrapMode::Type mWrapModeU:3;
172   Dali::WrapMode::Type mWrapModeV:3;
173 };
174
175 } // namespace Internal
176
177 } // namespace Toolkit
178
179 } // namespace Dali
180 #endif /* DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H */