Merge branch 'devel/master' into tizen
[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 = View.GetViewFromPtr(data);
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         /// Downcasts a handle to ImageView handle.<br>
195         /// If handle points to a ImageView, the downcast produces valid handle.<br>
196         /// If not, the returned handle is left uninitialized.<br>
197         /// </summary>
198         /// <param name="handle">Handle to an object</param>
199         /// <returns>Handle to a ImageView or an uninitialized handle</returns>
200         internal new static ImageView DownCast(BaseHandle handle)
201         {
202             ImageView ret = new ImageView(NDalicPINVOKE.ImageView_DownCast(BaseHandle.getCPtr(handle)), true);
203             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204             return ret;
205         }
206         /// <summary>
207         /// Sets this ImageView from the given URL.<br>
208         /// If the URL is empty, ImageView will not display anything.<br>
209         /// </summary>
210         /// <param name="url">The URL to the image resource to display</param>
211         public void SetImage(string url)
212         {
213             NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215         }
216         internal void SetImage(string url, Uint16Pair size)
217         {
218             NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220         }
221
222         internal ViewResourceReadySignal ResourceReadySignal(View view) {
223             ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
224             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225             return ret;
226         }
227
228         /// <summary>
229         /// Query if all resources required by a control are loaded and ready.<br>
230         /// Most resources are only loaded when the control is placed on stage.<br>
231         /// true if the resources are loaded and ready, false otherwise.<br>
232         /// </summary>
233         public bool IsResourceReady()
234         {
235             bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
236             if (NDalicPINVOKE.SWIGPendingException.Pending)
237                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238             return ret;
239         }
240
241         /// <summary>
242         /// ImageView ResourceUrl, type string
243         /// </summary>
244         public string ResourceUrl
245         {
246             get
247             {
248                 GetProperty(ImageView.Property.RESOURCE_URL).Get(out _url);
249                 return _url;
250             }
251             set
252             {
253                 _url = value;
254                 UpdateImage();
255             }
256         }
257
258         /// <summary>
259         /// ImageView ImageMap, type PropertyMap : string if it is a url, map otherwise
260         /// </summary>
261         public PropertyMap ImageMap
262         {
263             get
264             {
265                 if (_border == null)
266                 {
267                     PropertyMap temp = new PropertyMap();
268                     GetProperty(ImageView.Property.IMAGE).Get(temp);
269                     return temp;
270                 }
271                 else
272                 {
273                     return null;
274                 }
275             }
276             set
277             {
278                 if (_border == null)
279                 {
280                     SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
281                 }
282             }
283         }
284
285         /// <summary>
286         /// ImageView PreMultipliedAlpha, type Boolean.<br>
287         /// Image must be initialized.<br>
288         /// </summary>
289         public bool PreMultipliedAlpha
290         {
291             get
292             {
293                 bool temp = false;
294                 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
295                 return temp;
296             }
297             set
298             {
299                 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
300             }
301         }
302
303         /// <summary>
304         /// ImageView PixelArea, type Vector4 (Animatable property).<br>
305         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br>
306         /// </summary>
307         public RelativeVector4 PixelArea
308         {
309             get
310             {
311                 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
312                 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
313                 return temp;
314             }
315             set
316             {
317                 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
318             }
319         }
320
321         /// <summary>
322         /// The border of the image in the order: left, right, bottom, top.<br>
323         /// If set, ImageMap will be ignored.<br>
324         /// For N-Patch images only.<br>
325         /// Optional.
326         /// </summary>
327         public Rectangle Border
328         {
329             get
330             {
331                 return _border;
332             }
333             set
334             {
335                 _border = value;
336                 UpdateImage();
337             }
338         }
339
340         /// <summary>
341         /// Get or set whether to draws the borders only(If true).<br>
342         /// If not specified, the default is false.<br>
343         /// For N-Patch images only.<br>
344         /// Optional.
345         /// </summary>
346         public bool BorderOnly
347         {
348             get
349             {
350                 return _borderOnly ?? false;
351             }
352             set
353             {
354                 _borderOnly = value;
355                 UpdateImage();
356             }
357         }
358
359         public bool SynchronosLoading
360         {
361             get
362             {
363                 return _synchronousLoading ?? false;
364             }
365             set
366             {
367                 _synchronousLoading = value;
368                 UpdateImage();
369             }
370         }
371
372         private void UpdateImage()
373         {
374             if (_url != null)
375             {
376                 if (_border != null)
377                 { // for nine-patch image
378                     _nPatchMap = new PropertyMap();
379                     _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
380                     _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
381                     _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
382                     if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
383                     if (_synchronousLoading != null) _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
384                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
385                 }
386                 else if(_synchronousLoading != null)
387                 { // for normal image, with synchronous loading property
388                     PropertyMap imageMap = new PropertyMap();
389                     imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
390                     imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
391                     imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
392                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
393                 }
394                 else
395                 { // just for normal image
396                     SetProperty(ImageView.Property.RESOURCE_URL, new PropertyValue(_url));
397                 }
398             }
399         }
400
401         private Rectangle _border = null;
402         private PropertyMap _nPatchMap = null;
403         private bool? _synchronousLoading = null;
404         private bool? _borderOnly = null;
405         private string _url = null;
406
407     }
408
409 }