ce3a7d4fedd23743c65c60d11382e0f58660930c
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ImageView.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 //------------------------------------------------------------------------------
18 // <auto-generated />
19 //
20 // This file was automatically generated by SWIG (http://www.swig.org).
21 // Version 3.0.9
22 //
23 // Do not make changes to this file unless you know what you are doing--modify
24 // the SWIG interface file instead.
25 //------------------------------------------------------------------------------
26
27 namespace Tizen.NUI.BaseComponents
28 {
29     using System;
30     using System.Runtime.InteropServices;
31
32     /// <summary>
33     /// ImageView is a class for displaying an image resource.<br>
34     /// An instance of ImageView can be created using a URL or an Image instance.<br>
35     /// </summary>
36     public class ImageView : View
37     {
38         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
39
40         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
41         {
42             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43             // By default, we do not want the position to use the anchor point
44             PositionUsesAnchorPoint = false;
45         }
46
47         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
48         {
49             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
50         }
51
52
53         /// <summary>
54         /// Event arguments of resource ready.
55         /// </summary>
56         public class ResourceReadyEventArgs : EventArgs
57         {
58             private View _view;
59
60             /// <summary>
61             /// The view whose resource is ready.
62             /// </summary>
63             public View View
64             {
65                 get
66                 {
67                     return _view;
68                 }
69                 set
70                 {
71                     _view = value;
72                 }
73             }
74         }
75
76         private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
77         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
78         private delegate void ResourceReadyEventCallbackType(IntPtr data);
79         private ResourceReadyEventCallbackType _resourceReadyEventCallback;
80
81         /// <summary>
82         /// Event for ResourceReady signal which can be used to subscribe/unsubscribe the event handler.<br>
83         /// This signal is emitted after all resources required by a control are loaded and ready.<br>
84         /// Most resources are only loaded when the control is placed on stage.<br>
85         /// </summary>
86         public event EventHandler<ResourceReadyEventArgs> ResourceReady
87         {
88             add
89             {
90                 if (_resourceReadyEventHandler == null)
91                 {
92                     _resourceReadyEventCallback = OnResourceReady;
93                     ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
94                 }
95
96                 _resourceReadyEventHandler += value;
97             }
98
99             remove
100             {
101                 _resourceReadyEventHandler -= value;
102
103                 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
104                 {
105                     ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
106                 }
107             }
108         }
109
110         // Callback for View ResourceReady signal
111         private void OnResourceReady(IntPtr data)
112         {
113             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
114             if(data != null)
115             {
116                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
117             }
118
119             if (_resourceReadyEventHandler != null)
120             {
121                 _resourceReadyEventHandler(this, e);
122             }
123         }
124
125         //you can override it to clean-up your own resources.
126         protected override void Dispose(DisposeTypes type)
127         {
128             if (!disposed)
129             {
130                 return;
131             }
132
133             if(type == DisposeTypes.Explicit)
134             {
135                 //Called by User
136                 //Release your own managed resources here.
137                 //You should release all of your own disposable objects here.
138                 _border?.Dispose();
139                 _border = null;
140                 _nPatchMap?.Dispose();
141                 _nPatchMap = null;
142             }
143
144             //Release your own unmanaged resources here.
145             //You should not access any managed member here except static instance.
146             //because the execution order of Finalizes is non-deterministic.
147
148             if (swigCPtr.Handle != global::System.IntPtr.Zero)
149             {
150                 if (swigCMemOwn)
151                 {
152                     swigCMemOwn = false;
153                     NDalicPINVOKE.delete_ImageView(swigCPtr);
154                 }
155                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
156             }
157
158             base.Dispose(type);
159         }
160
161         internal class Property
162         {
163             internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
164             internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
165             internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
166             internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
167         }
168
169         /// <summary>
170         /// Creates an initialized ImageView.
171         /// </summary>
172         public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
173         {
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175
176         }
177         /// <summary>
178         /// Creates an initialized ImageView from an URL to an image resource.<br>
179         /// If the string is empty, ImageView will not display anything.<br>
180         /// </summary>
181         /// <param name="url">The url of the image resource to display</param>
182         public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
183         {
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185
186         }
187         internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
188         {
189             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190
191         }
192
193         /// <summary>
194         /// Sets this ImageView from the given URL.<br>
195         /// If the URL is empty, ImageView will not display anything.<br>
196         /// </summary>
197         /// <param name="url">The URL to the image resource to display</param>
198         public void SetImage(string url)
199         {
200             NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202         }
203         internal void SetImage(string url, Uint16Pair size)
204         {
205             NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207         }
208
209         internal ViewResourceReadySignal ResourceReadySignal(View view) {
210             ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return ret;
213         }
214
215         /// <summary>
216         /// Query if all resources required by a control are loaded and ready.<br>
217         /// Most resources are only loaded when the control is placed on stage.<br>
218         /// true if the resources are loaded and ready, false otherwise.<br>
219         /// </summary>
220         public bool IsResourceReady()
221         {
222             bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
223             if (NDalicPINVOKE.SWIGPendingException.Pending)
224                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225             return ret;
226         }
227
228         /// <summary>
229         /// ImageView ResourceUrl, type string
230         /// </summary>
231         public string ResourceUrl
232         {
233             get
234             {
235                 GetProperty(ImageView.Property.RESOURCE_URL).Get(out _url);
236                 return _url;
237             }
238             set
239             {
240                 _url = value;
241                 UpdateImage();
242             }
243         }
244
245         /// <summary>
246         /// ImageView ImageMap, type PropertyMap : string if it is a url, map otherwise
247         /// </summary>
248         public PropertyMap ImageMap
249         {
250             get
251             {
252                 if (_border == null)
253                 {
254                     PropertyMap temp = new PropertyMap();
255                     GetProperty(ImageView.Property.IMAGE).Get(temp);
256                     return temp;
257                 }
258                 else
259                 {
260                     return null;
261                 }
262             }
263             set
264             {
265                 if (_border == null)
266                 {
267                     SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
268                 }
269             }
270         }
271
272         /// <summary>
273         /// ImageView PreMultipliedAlpha, type Boolean.<br>
274         /// Image must be initialized.<br>
275         /// </summary>
276         public bool PreMultipliedAlpha
277         {
278             get
279             {
280                 bool temp = false;
281                 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
282                 return temp;
283             }
284             set
285             {
286                 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
287             }
288         }
289
290         /// <summary>
291         /// ImageView PixelArea, type Vector4 (Animatable property).<br>
292         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br>
293         /// </summary>
294         public RelativeVector4 PixelArea
295         {
296             get
297             {
298                 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
299                 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
300                 return temp;
301             }
302             set
303             {
304                 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
305             }
306         }
307
308         /// <summary>
309         /// The border of the image in the order: left, right, bottom, top.<br>
310         /// If set, ImageMap will be ignored.<br>
311         /// For N-Patch images only.<br>
312         /// Optional.
313         /// </summary>
314         public Rectangle Border
315         {
316             get
317             {
318                 return _border;
319             }
320             set
321             {
322                 _border = value;
323                 UpdateImage();
324             }
325         }
326
327         /// <summary>
328         /// Get or set whether to draws the borders only(If true).<br>
329         /// If not specified, the default is false.<br>
330         /// For N-Patch images only.<br>
331         /// Optional.
332         /// </summary>
333         public bool BorderOnly
334         {
335             get
336             {
337                 return _borderOnly ?? false;
338             }
339             set
340             {
341                 _borderOnly = value;
342                 UpdateImage();
343             }
344         }
345
346         public bool SynchronosLoading
347         {
348             get
349             {
350                 return _synchronousLoading ?? false;
351             }
352             set
353             {
354                 _synchronousLoading = value;
355                 UpdateImage();
356             }
357         }
358
359         private void UpdateImage()
360         {
361             if (_url != null)
362             {
363                 if (_border != null)
364                 { // for nine-patch image
365                     _nPatchMap = new PropertyMap();
366                     _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
367                     _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
368                     _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
369                     if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
370                     if (_synchronousLoading != null) _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
371                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
372                 }
373                 else if(_synchronousLoading != null)
374                 { // for normal image, with synchronous loading property
375                     PropertyMap imageMap = new PropertyMap();
376                     imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
377                     imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
378                     imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
379                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
380                 }
381                 else
382                 { // just for normal image
383                     SetProperty(ImageView.Property.RESOURCE_URL, new PropertyValue(_url));
384                 }
385             }
386         }
387
388         private Rectangle _border = null;
389         private PropertyMap _nPatchMap = null;
390         private bool? _synchronousLoading = null;
391         private bool? _borderOnly = null;
392         private string _url = null;
393
394     }
395
396 }