2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 namespace Tizen.NUI.BaseComponents
21 using System.Runtime.InteropServices;
22 using System.ComponentModel;
25 /// ImageView is a class for displaying an image resource.<br />
26 /// An instance of ImageView can be created using a URL or an image instance.<br />
28 public class ImageView : View
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
34 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
37 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
39 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 /// Event arguments of resource ready.
46 public class ResourceReadyEventArgs : EventArgs
51 /// The view whose resource is ready.
53 /// <since_tizen> 3 </since_tizen>
67 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
68 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
69 private delegate void ResourceReadyEventCallbackType(IntPtr data);
70 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
73 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
74 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
75 /// Most resources are only loaded when the control is placed on the stage.<br />
77 /// <since_tizen> 3 </since_tizen>
78 public event EventHandler<ResourceReadyEventArgs> ResourceReady
82 if (_resourceReadyEventHandler == null)
84 _resourceReadyEventCallback = OnResourceReady;
85 ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
88 _resourceReadyEventHandler += value;
93 _resourceReadyEventHandler -= value;
95 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
97 ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
102 // Callback for View ResourceReady signal
103 private void OnResourceReady(IntPtr data)
105 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
108 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
111 if (_resourceReadyEventHandler != null)
113 _resourceReadyEventHandler(this, e);
118 /// you can override it to clean-up your own resources.
120 /// <param name="type">DisposeTypes</param>
121 /// <since_tizen> 3 </since_tizen>
122 protected override void Dispose(DisposeTypes type)
129 if (type == DisposeTypes.Explicit)
132 //Release your own managed resources here.
133 //You should release all of your own disposable objects here.
136 _nPatchMap?.Dispose();
140 //Release your own unmanaged resources here.
141 //You should not access any managed member here except static instance.
142 //because the execution order of Finalizes is non-deterministic.
144 if (swigCPtr.Handle != global::System.IntPtr.Zero)
149 NDalicPINVOKE.delete_ImageView(swigCPtr);
151 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
157 internal new class Property
159 internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
160 internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
161 internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
162 internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
166 /// Creates an initialized ImageView.
168 /// <since_tizen> 3 </since_tizen>
169 public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
171 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175 /// Creates an initialized ImageView from a URL to an image resource.<br />
176 /// If the string is empty, ImageView will not display anything.<br />
178 /// <param name="url">The URL of the image resource to display.</param>
179 /// <since_tizen> 3 </since_tizen>
180 public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 /// [Obsolete("Please do not use! this will be deprecated")]
196 [Obsolete("Please do not use! this will be deprecated")]
197 public new static ImageView DownCast(BaseHandle handle)
199 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 /// Sets this ImageView from the given URL.<br />
205 /// If the URL is empty, ImageView will not display anything.<br />
207 /// <param name="url">The URL to the image resource to display.</param>
208 /// <since_tizen> 3 </since_tizen>
209 public void SetImage(string url)
212 NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 internal void SetImage(string url, Uint16Pair size)
218 NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222 internal ViewResourceReadySignal ResourceReadySignal(View view)
224 ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 /// Queries if all resources required by a control are loaded and ready.<br />
231 /// Most resources are only loaded when the control is placed on the stage.<br />
232 /// True if the resources are loaded and ready, false otherwise.<br />
234 /// <since_tizen> 3 </since_tizen>
235 public new bool IsResourceReady()
237 bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
238 if (NDalicPINVOKE.SWIGPendingException.Pending)
239 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 /// ImageView ResourceUrl, type string.
246 /// <since_tizen> 3 </since_tizen>
247 public string ResourceUrl
251 GetProperty(ImageView.Property.IMAGE).Get(out _url);
262 /// This will be deprecated, please use Image instead. <br />
263 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
265 /// <since_tizen> 3 </since_tizen>
266 [EditorBrowsable(EditorBrowsableState.Never)]
267 public PropertyMap ImageMap
273 PropertyMap temp = new PropertyMap();
274 GetProperty(ImageView.Property.IMAGE).Get(temp);
286 SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
292 /// ImageView Image, type PropertyMap
294 /// <since_tizen> 4 </since_tizen>
295 public PropertyMap Image
301 PropertyMap temp = new PropertyMap();
302 GetProperty(ImageView.Property.IMAGE).Get(temp);
314 SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
320 /// ImageView PreMultipliedAlpha, type Boolean.<br />
321 /// Image must be initialized.<br />
323 /// <since_tizen> 3 </since_tizen>
324 public bool PreMultipliedAlpha
329 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
334 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
339 /// ImageView PixelArea, type Vector4 (Animatable property).<br />
340 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
342 /// <since_tizen> 3 </since_tizen>
343 public RelativeVector4 PixelArea
347 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
348 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
353 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
358 /// The border of the image in the order: left, right, bottom, top.<br />
359 /// If set, ImageMap will be ignored.<br />
360 /// For N-Patch images only.<br />
363 /// <since_tizen> 3 </since_tizen>
364 public Rectangle Border
378 /// Gets or sets whether to draw the borders only (if true).<br />
379 /// If not specified, the default is false.<br />
380 /// For N-Patch images only.<br />
383 /// <since_tizen> 3 </since_tizen>
384 public bool BorderOnly
388 return _borderOnly ?? false;
398 /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
400 /// <since_tizen> 3 </since_tizen>
401 public bool SynchronosLoading
405 return _synchronousLoading ?? false;
409 _synchronousLoading = value;
414 private void UpdateImage()
419 { // for nine-patch image
420 _nPatchMap = new PropertyMap();
421 _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
422 _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
423 _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
424 if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
425 if (_synchronousLoading != null) _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
426 SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
428 else if (_synchronousLoading != null)
429 { // for normal image, with synchronous loading property
430 PropertyMap imageMap = new PropertyMap();
431 imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
432 imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
433 imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
434 SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
437 { // just for normal image
438 SetProperty(ImageView.Property.IMAGE, new PropertyValue(_url));
443 private Rectangle _border = null;
444 private PropertyMap _nPatchMap = null;
445 private bool? _synchronousLoading = null;
446 private bool? _borderOnly = null;
447 private string _url = null;