Change PositionUsesAnchorPoint property to PositionUsesPivotPoint
[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 = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
115             }
116
117             if (_resourceReadyEventHandler != null)
118             {
119                 _resourceReadyEventHandler(this, e);
120             }
121         }
122
123         //you can override it to clean-up your own resources.
124         protected override void Dispose(DisposeTypes type)
125         {
126             if (!disposed)
127             {
128                 return;
129             }
130
131             if(type == DisposeTypes.Explicit)
132             {
133                 //Called by User
134                 //Release your own managed resources here.
135                 //You should release all of your own disposable objects here.
136                 _border?.Dispose();
137                 _border = null;
138                 _nPatchMap?.Dispose();
139                 _nPatchMap = null;
140             }
141
142             //Release your own unmanaged resources here.
143             //You should not access any managed member here except static instance.
144             //because the execution order of Finalizes is non-deterministic.
145
146             if (swigCPtr.Handle != global::System.IntPtr.Zero)
147             {
148                 if (swigCMemOwn)
149                 {
150                     swigCMemOwn = false;
151                     NDalicPINVOKE.delete_ImageView(swigCPtr);
152                 }
153                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
154             }
155
156             base.Dispose(type);
157         }
158
159         internal class Property
160         {
161             internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
162             internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
163             internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
164             internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
165         }
166
167         /// <summary>
168         /// Creates an initialized ImageView.
169         /// </summary>
170         public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
171         {
172             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173
174         }
175         /// <summary>
176         /// Creates an initialized ImageView from an URL to an image resource.<br>
177         /// If the string is empty, ImageView will not display anything.<br>
178         /// </summary>
179         /// <param name="url">The url of the image resource to display</param>
180         public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
181         {
182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183
184         }
185         internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
186         {
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188
189         }
190
191         /// <summary>
192         /// Sets this ImageView from the given URL.<br>
193         /// If the URL is empty, ImageView will not display anything.<br>
194         /// </summary>
195         /// <param name="url">The URL to the image resource to display</param>
196         public void SetImage(string url)
197         {
198             NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
199             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200         }
201         internal void SetImage(string url, Uint16Pair size)
202         {
203             NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205         }
206
207         internal ViewResourceReadySignal ResourceReadySignal(View view) {
208             ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210             return ret;
211         }
212
213         /// <summary>
214         /// Query if all resources required by a control are loaded and ready.<br>
215         /// Most resources are only loaded when the control is placed on stage.<br>
216         /// true if the resources are loaded and ready, false otherwise.<br>
217         /// </summary>
218         public bool IsResourceReady()
219         {
220             bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
221             if (NDalicPINVOKE.SWIGPendingException.Pending)
222                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223             return ret;
224         }
225
226         /// <summary>
227         /// ImageView ResourceUrl, type string
228         /// </summary>
229         public string ResourceUrl
230         {
231             get
232             {
233                 GetProperty(ImageView.Property.RESOURCE_URL).Get(out _url);
234                 return _url;
235             }
236             set
237             {
238                 _url = value;
239                 UpdateImage();
240             }
241         }
242
243         /// <summary>
244         /// ImageView ImageMap, type PropertyMap : string if it is a url, map otherwise
245         /// </summary>
246         public PropertyMap ImageMap
247         {
248             get
249             {
250                 if (_border == null)
251                 {
252                     PropertyMap temp = new PropertyMap();
253                     GetProperty(ImageView.Property.IMAGE).Get(temp);
254                     return temp;
255                 }
256                 else
257                 {
258                     return null;
259                 }
260             }
261             set
262             {
263                 if (_border == null)
264                 {
265                     SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
266                 }
267             }
268         }
269
270         /// <summary>
271         /// ImageView PreMultipliedAlpha, type Boolean.<br>
272         /// Image must be initialized.<br>
273         /// </summary>
274         public bool PreMultipliedAlpha
275         {
276             get
277             {
278                 bool temp = false;
279                 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
280                 return temp;
281             }
282             set
283             {
284                 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
285             }
286         }
287
288         /// <summary>
289         /// ImageView PixelArea, type Vector4 (Animatable property).<br>
290         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br>
291         /// </summary>
292         public RelativeVector4 PixelArea
293         {
294             get
295             {
296                 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
297                 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
298                 return temp;
299             }
300             set
301             {
302                 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
303             }
304         }
305
306         /// <summary>
307         /// The border of the image in the order: left, right, bottom, top.<br>
308         /// If set, ImageMap will be ignored.<br>
309         /// For N-Patch images only.<br>
310         /// Optional.
311         /// </summary>
312         public Rectangle Border
313         {
314             get
315             {
316                 return _border;
317             }
318             set
319             {
320                 _border = value;
321                 UpdateImage();
322             }
323         }
324
325         /// <summary>
326         /// Get or set whether to draws the borders only(If true).<br>
327         /// If not specified, the default is false.<br>
328         /// For N-Patch images only.<br>
329         /// Optional.
330         /// </summary>
331         public bool BorderOnly
332         {
333             get
334             {
335                 return _borderOnly ?? false;
336             }
337             set
338             {
339                 _borderOnly = value;
340                 UpdateImage();
341             }
342         }
343
344         public bool SynchronosLoading
345         {
346             get
347             {
348                 return _synchronousLoading ?? false;
349             }
350             set
351             {
352                 _synchronousLoading = value;
353                 UpdateImage();
354             }
355         }
356
357         private void UpdateImage()
358         {
359             if (_url != null)
360             {
361                 if (_border != null)
362                 { // for nine-patch image
363                     _nPatchMap = new PropertyMap();
364                     _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
365                     _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
366                     _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
367                     if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
368                     if (_synchronousLoading != null) _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
369                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
370                 }
371                 else if(_synchronousLoading != null)
372                 { // for normal image, with synchronous loading property
373                     PropertyMap imageMap = new PropertyMap();
374                     imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
375                     imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
376                     imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
377                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
378                 }
379                 else
380                 { // just for normal image
381                     SetProperty(ImageView.Property.RESOURCE_URL, new PropertyValue(_url));
382                 }
383             }
384         }
385
386         private Rectangle _border = null;
387         private PropertyMap _nPatchMap = null;
388         private bool? _synchronousLoading = null;
389         private bool? _borderOnly = null;
390         private string _url = null;
391
392     }
393
394 }