[NUI] Add license, delete unnecessary code(public)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / AnimatedImageVisual.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System.Collections.Generic;
18
19 namespace Tizen.NUI
20 {
21     /// <summary>
22     /// A class encapsulating the property map of the animated image (AGIF) visual.
23     /// </summary>
24     /// <since_tizen> 3 </since_tizen>
25     public class AnimatedImageVisual : VisualMap
26     {
27         private List<string> urls = null;
28         private int? batchSize = null;
29         private int? cacheSize = null;
30         private float? frameDelay = null;
31         private float? loopCount = null;
32
33         /// <summary>
34         /// Constructor.
35         /// </summary>
36         /// <since_tizen> 3 </since_tizen>
37         public AnimatedImageVisual() : base()
38         {
39         }
40
41         /// <summary>
42         /// Gets and Sets the url in the AnimatedImageVisual.
43         /// </summary>
44         /// <since_tizen> 3 </since_tizen>
45         public string URL
46         {
47             get
48             {
49                 if (urls != null)
50                 {
51                     return urls[0];
52                 }
53                 else
54                 {
55                     return null;
56                 }
57             }
58             set
59             {
60                 if (urls == null)
61                 {
62                     urls = new List<string>();
63                     urls.Add(value);
64                 }
65                 else
66                 {
67                     urls[0] = value;
68                 }
69                 UpdateVisual();
70             }
71         }
72
73         /// <summary>
74         /// Gets and Sets the url list in the AnimatedImageVisual.
75         /// </summary>
76         /// <since_tizen> 4 </since_tizen>
77         public List<string> URLS
78         {
79             get
80             {
81                 return urls;
82             }
83             set
84             {
85                 urls = value;
86                 UpdateVisual();
87             }
88         }
89
90         /// <summary>
91         /// Gets and Sets the batch size for pre-loading images in the AnimatedImageVisual.
92         /// </summary>
93         /// <since_tizen> 4 </since_tizen>
94         public int BatchSize
95         {
96             get
97             {
98                 return batchSize ?? 1;
99             }
100             set
101             {
102                 batchSize = value;
103                 UpdateVisual();
104             }
105         }
106
107         /// <summary>
108         /// Gets and Sets the cache size for loading images in the AnimatedImageVisual.
109         /// </summary>
110         /// <since_tizen> 4 </since_tizen>
111         public int CacheSize
112         {
113             get
114             {
115                 return cacheSize ?? 1;
116             }
117             set
118             {
119                 cacheSize = value;
120                 UpdateVisual();
121             }
122         }
123
124         /// <summary>
125         /// Gets and Sets The number of milliseconds between each frame in the AnimatedImageVisual.
126         /// </summary>
127         /// <since_tizen> 4 </since_tizen>
128         public float FrameDelay
129         {
130             get
131             {
132                 return frameDelay ?? 0.1f;
133             }
134             set
135             {
136                 frameDelay = value;
137                 UpdateVisual();
138             }
139         }
140
141         /// <summary>
142         /// Gets and sets the number of times the AnimatedImageVisual will be looped.
143         /// The default is -1. If the number is less than 0 then it loops unlimited,otherwise loop loopCount times.
144         /// </summary>
145         /// <since_tizen> 5 </since_tizen>
146         public float LoopCount
147         {
148             get
149             {
150                 return loopCount ?? -1;
151             }
152             set
153             {
154                 loopCount = value;
155                 UpdateVisual();
156             }
157         }
158
159         /// <summary>
160         /// Compose the out visual map.
161         /// </summary>
162         /// <since_tizen> 3 </since_tizen>
163         protected override void ComposingPropertyMap()
164         {
165             if (urls != null)
166             {
167                 _outputVisualMap = new PropertyMap();
168                 PropertyValue temp = new PropertyValue((int)Visual.Type.AnimatedImage);
169                 _outputVisualMap.Add(Visual.Property.Type, temp);
170                 temp.Dispose();
171                 if (urls.Count == 1)
172                 {
173                     temp = new PropertyValue(urls[0]);
174                     _outputVisualMap.Add(ImageVisualProperty.URL, temp);
175                     temp.Dispose();
176                 }
177                 else
178                 {
179                     var urlArray = new PropertyArray();
180                     foreach (var url in urls)
181                     {
182                         urlArray.Add(new PropertyValue(url));
183                     }
184                     temp = new PropertyValue(urlArray);
185                     _outputVisualMap.Add(ImageVisualProperty.URL, temp);
186                     temp.Dispose();
187                     urlArray.Dispose();
188                 }
189                 if (batchSize != null)
190                 {
191                     temp = new PropertyValue((int)batchSize);
192                     _outputVisualMap.Add(ImageVisualProperty.BatchSize, temp);
193                     temp.Dispose();
194                 }
195                 if (cacheSize != null)
196                 {
197                     temp = new PropertyValue((int)cacheSize);
198                     _outputVisualMap.Add(ImageVisualProperty.CacheSize, temp);
199                     temp.Dispose();
200                 }
201                 if (frameDelay != null)
202                 {
203                     temp = new PropertyValue((float)frameDelay);
204                     _outputVisualMap.Add(ImageVisualProperty.FrameDelay, temp);
205                     temp.Dispose();
206                 }
207                 if (loopCount != null)
208                 {
209                     temp = new PropertyValue((int)loopCount);
210                     _outputVisualMap.Add(ImageVisualProperty.LoopCount, temp);
211                     temp.Dispose();
212                 }
213                 base.ComposingPropertyMap();
214             }
215         }
216     }
217 }