Merge "Fix TableView::GetNextKeyboardFocusableActor function by returning a valid...
[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
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 class AnimatedImageVisual;
40 typedef IntrusivePtr< AnimatedImageVisual > AnimatedImageVisualPtr;
41
42 /**
43  * The visual which renders an animated image
44  *
45  * The following property is essential
46  *
47  * | %Property Name           | Type             |
48  * |--------------------------|------------------|
49  * | url                      | STRING           |
50  *
51  */
52
53 class AnimatedImageVisual : public Visual::Base, public ConnectionTracker
54 {
55
56 public:
57
58   /**
59    * @brief Create the animated image Visual using the image URL.
60    *
61    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
62    * @param[in] imageUrl The URL to svg resource to use
63    * @param[in] properties A Property::Map containing settings for this visual
64    * @return A smart-pointer to the newly allocated visual.
65    */
66   static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties );
67
68   /**
69    * @brief Create the animated image visual using the image URL.
70    *
71    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
72    * @param[in] imageUrl The URL to animated image resource to use
73    */
74   static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
75
76 public:  // from Visual
77
78   /**
79    * @copydoc Visual::Base::GetNaturalSize
80    */
81   virtual void GetNaturalSize( Vector2& naturalSize );
82
83   /**
84    * @copydoc Visual::Base::CreatePropertyMap
85    */
86   virtual void DoCreatePropertyMap( Property::Map& map ) const;
87
88 protected:
89
90   /**
91    * @brief Constructor.
92    *
93    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
94    */
95   AnimatedImageVisual( VisualFactoryCache& factoryCache );
96
97   /**
98    * @brief A reference counted object may only be deleted by calling Unreference().
99    */
100   virtual ~AnimatedImageVisual();
101
102   /**
103    * @copydoc Visual::Base::DoSetProperties
104    */
105   virtual void DoSetProperties( const Property::Map& propertyMap );
106
107   /**
108    * @copydoc Visual::Base::DoSetOnStage
109    */
110   virtual void DoSetOnStage( Actor& actor );
111
112   /**
113    * @copydoc Visual::Base::DoSetOffStage
114    */
115   virtual void DoSetOffStage( Actor& actor );
116
117   /**
118    * @copydoc Visual::Base::OnSetTransform
119    */
120   virtual void OnSetTransform();
121
122 private:
123
124   /**
125    * Load the animated image and pack the frames into atlas.
126    * @return That atlas texture.
127    */
128   Texture PrepareAnimatedImage();
129
130   /**
131    * Display the next frame. It is called when the mFrameDelayTimes ticks.
132    */
133   bool DisplayNextFrame();
134
135   // Undefined
136   AnimatedImageVisual( const AnimatedImageVisual& animatedImageVisual );
137
138   // Undefined
139   AnimatedImageVisual& operator=( const AnimatedImageVisual& animatedImageVisual );
140
141 private:
142
143   Timer mFrameDelayTimer;
144   Dali::Vector<Vector4> mTextureRectContainer;
145   Dali::Vector<uint32_t> mFrameDelayContainer;
146   std::string  mImageUrl;
147   ImageDimensions mImageSize;
148   uint32_t mCurrentFrameIndex;
149 };
150
151 } // namespace Internal
152
153 } // namespace Toolkit
154
155 } // namespace Dali
156 #endif /* DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H */