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