98bad2085609f318587fb3a7f29124329d9e3d68
[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         }
44
45         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
46         {
47             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48         }
49
50
51         /// <summary>
52         /// Event arguments of resource ready.
53         /// </summary>
54         public class ResourceReadyEventArgs : EventArgs
55         {
56             private View _view;
57
58             /// <summary>
59             /// The view whose resource is ready.
60             /// </summary>
61             public View View
62             {
63                 get
64                 {
65                     return _view;
66                 }
67                 set
68                 {
69                     _view = value;
70                 }
71             }
72         }
73
74         private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
75         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
76         private delegate void ResourceReadyEventCallbackType(IntPtr data);
77         private ResourceReadyEventCallbackType _resourceReadyEventCallback;
78
79         /// <summary>
80         /// Event for ResourceReady signal which can be used to subscribe/unsubscribe the event handler.<br>
81         /// This signal is emitted after all resources required by a control are loaded and ready.<br>
82         /// Most resources are only loaded when the control is placed on stage.<br>
83         /// </summary>
84         public event EventHandler<ResourceReadyEventArgs> ResourceReady
85         {
86             add
87             {
88                 if (_resourceReadyEventHandler == null)
89                 {
90                     _resourceReadyEventCallback = OnResourceReady;
91                     ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
92                 }
93
94                 _resourceReadyEventHandler += value;
95             }
96
97             remove
98             {
99                 _resourceReadyEventHandler -= value;
100
101                 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
102                 {
103                     ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
104                 }
105             }
106         }
107
108         // Callback for View ResourceReady signal
109         private void OnResourceReady(IntPtr data)
110         {
111             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
112             if(data != null)
113             {
114                 e.View = View.GetViewFromPtr(data);
115             }
116
117             if (_resourceReadyEventHandler != null)
118             {
119                 _resourceReadyEventHandler(this, e);
120             }
121         }
122
123         public override void Dispose()
124         {
125             if (!Window.IsInstalled())
126             {
127                 DisposeQueue.Instance.Add(this);
128                 return;
129             }
130
131             lock (this)
132             {
133                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
134                 {
135                     if (swigCMemOwn)
136                     {
137                         swigCMemOwn = false;
138                         NDalicPINVOKE.delete_ImageView(swigCPtr);
139                     }
140                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
141                 }
142                 global::System.GC.SuppressFinalize(this);
143                 base.Dispose();
144             }
145         }
146
147         internal class Property : global::System.IDisposable
148         {
149             private global::System.Runtime.InteropServices.HandleRef swigCPtr;
150             protected bool swigCMemOwn;
151
152             internal Property(global::System.IntPtr cPtr, bool cMemoryOwn)
153             {
154                 swigCMemOwn = cMemoryOwn;
155                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
156             }
157
158             internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Property obj)
159             {
160                 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
161             }
162
163             ~Property()
164             {
165                 DisposeQueue.Instance.Add(this);
166             }
167
168             public virtual void Dispose()
169             {
170                 if (!Window.IsInstalled()) {
171                     DisposeQueue.Instance.Add(this);
172                     return;
173                 }
174
175                 lock (this)
176                 {
177                     if (swigCPtr.Handle != global::System.IntPtr.Zero)
178                     {
179                         if (swigCMemOwn)
180                         {
181                             swigCMemOwn = false;
182                             NDalicPINVOKE.delete_ImageView_Property(swigCPtr);
183                         }
184                         swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
185                     }
186                     global::System.GC.SuppressFinalize(this);
187                 }
188             }
189
190             internal Property() : this(NDalicPINVOKE.new_ImageView_Property(), true)
191             {
192                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193             }
194
195             internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
196             internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
197             internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
198             internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
199
200         }
201
202         /// <summary>
203         /// Creates an initialized ImageView.
204         /// </summary>
205         public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
206         {
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208
209         }
210         /// <summary>
211         /// Creates an initialized ImageView from an URL to an image resource.<br>
212         /// If the string is empty, ImageView will not display anything.<br>
213         /// </summary>
214         /// <param name="url">The url of the image resource to display</param>
215         public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
216         {
217             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218
219         }
220         internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
221         {
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223
224         }
225         internal ImageView(ImageView imageView) : this(NDalicPINVOKE.new_ImageView__SWIG_1(ImageView.getCPtr(imageView)), true)
226         {
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228         }
229         internal ImageView Assign(ImageView imageView)
230         {
231             ImageView ret = new ImageView(NDalicPINVOKE.ImageView_Assign(swigCPtr, ImageView.getCPtr(imageView)), false);
232             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233             return ret;
234         }
235         /// <summary>
236         /// Downcasts a handle to ImageView handle.<br>
237         /// If handle points to a ImageView, the downcast produces valid handle.<br>
238         /// If not, the returned handle is left uninitialized.<br>
239         /// </summary>
240         /// <param name="handle">Handle to an object</param>
241         /// <returns>Handle to a ImageView or an uninitialized handle</returns>
242         public new static ImageView DownCast(BaseHandle handle)
243         {
244             ImageView ret = new ImageView(NDalicPINVOKE.ImageView_DownCast(BaseHandle.getCPtr(handle)), true);
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246             return ret;
247         }
248         /// <summary>
249         /// Sets this ImageView from the given URL.<br>
250         /// If the URL is empty, ImageView will not display anything.<br>
251         /// </summary>
252         /// <param name="url">The URL to the image resource to display</param>
253         public void SetImage(string url)
254         {
255             NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257         }
258         internal void SetImage(string url, Uint16Pair size)
259         {
260             NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262         }
263         internal enum PropertyRange
264         {
265             PROPERTY_START_INDEX = PropertyRanges.PROPERTY_REGISTRATION_START_INDEX,
266             PROPERTY_END_INDEX = View.PropertyRange.PROPERTY_START_INDEX + 1000,
267             ANIMATABLE_PROPERTY_START_INDEX = PropertyRanges.ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
268             ANIMATABLE_PROPERTY_END_INDEX = PropertyRanges.ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000
269         }
270
271
272         internal ViewResourceReadySignal ResourceReadySignal(View view) {
273             ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
274             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275             return ret;
276         }
277
278         /// <summary>
279         /// Query if all resources required by a control are loaded and ready.<br>
280         /// Most resources are only loaded when the control is placed on stage.<br>
281         /// true if the resources are loaded and ready, false otherwise.<br>
282         /// </summary>
283         public bool IsResourceReady()
284         {
285             bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
286             if (NDalicPINVOKE.SWIGPendingException.Pending)
287                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         /// <summary>
292         /// ImageView ResourceUrl, type string
293         /// </summary>
294         public string ResourceUrl
295         {
296             get
297             {
298                 return _url;
299             }
300             set
301             {
302                 _url = value;
303                 UpdateImage();
304             }
305         }
306
307         /// <summary>
308         /// ImageView ImageMap, type PropertyMap : string if it is a url, map otherwise
309         /// </summary>
310         public PropertyMap ImageMap
311         {
312             get
313             {
314                 if (_border == null)
315                 {
316                     PropertyMap temp = new PropertyMap();
317                     GetProperty(ImageView.Property.IMAGE).Get(temp);
318                     return temp;
319                 }
320                 else
321                 {
322                     return null;
323                 }
324             }
325             set
326             {
327                 if (_border == null)
328                 {
329                     SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
330                 }
331             }
332         }
333
334         /// <summary>
335         /// ImageView PreMultipliedAlpha, type Boolean.<br>
336         /// Image must be initialized.<br>
337         /// </summary>
338         public bool PreMultipliedAlpha
339         {
340             get
341             {
342                 bool temp = false;
343                 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(ref temp);
344                 return temp;
345             }
346             set
347             {
348                 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
349             }
350         }
351
352         /// <summary>
353         /// ImageView PixelArea, type Vector4 (Animatable property).<br>
354         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br>
355         /// </summary>
356         public RelativeVector4 PixelArea
357         {
358             get
359             {
360                 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
361                 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
362                 return temp;
363             }
364             set
365             {
366                 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
367             }
368         }
369
370         /// <summary>
371         /// The border of the image in the order: left, right, bottom, top.<br>
372         /// If set, ImageMap will be ignored.<br>
373         /// For N-Patch images only.<br>
374         /// Optional.
375         /// </summary>
376         public Rectangle Border
377         {
378             get
379             {
380                 return _border;
381             }
382             set
383             {
384                 _border = value;
385                 UpdateImage();
386             }
387         }
388
389         /// <summary>
390         /// Get or set whether to draws the borders only(If true).<br>
391         /// If not specified, the default is false.<br>
392         /// For N-Patch images only.<br>
393         /// Optional.
394         /// </summary>
395         public bool BorderOnly
396         {
397             get
398             {
399                 return _borderOnly;
400             }
401             set
402             {
403                 _borderOnly = value;
404                 UpdateImage();
405             }
406         }
407
408         private void UpdateImage()
409         {
410             if (_border != null && _url != null)
411             {
412                 _nPatchMap = new PropertyMap();
413                 _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
414                 _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
415                 _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
416                 if (_borderOnly) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue(_borderOnly)); }
417                 SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
418             }
419             else
420             {
421                 if (_url != null) { SetProperty(ImageView.Property.RESOURCE_URL, new PropertyValue(_url)); }
422             }
423         }
424
425         private Rectangle _border = null;
426         private bool _borderOnly = false;
427         private string _url = null;
428         private PropertyMap _nPatchMap = null;
429
430     }
431
432 }