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;
24 /// ImageView is a class for displaying an image resource.<br />
25 /// An instance of ImageView can be created using a URL or an image instance.<br />
27 public class ImageView : View
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
33 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
38 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
43 /// Event arguments of resource ready.
45 public class ResourceReadyEventArgs : EventArgs
50 /// The view whose resource is ready.
52 /// <since_tizen> 3 </since_tizen>
66 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
67 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
68 private delegate void ResourceReadyEventCallbackType(IntPtr data);
69 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
72 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
73 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
74 /// Most resources are only loaded when the control is placed on the stage.<br />
76 /// <since_tizen> 3 </since_tizen>
77 public event EventHandler<ResourceReadyEventArgs> ResourceReady
81 if (_resourceReadyEventHandler == null)
83 _resourceReadyEventCallback = OnResourceReady;
84 ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
87 _resourceReadyEventHandler += value;
92 _resourceReadyEventHandler -= value;
94 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
96 ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
101 // Callback for View ResourceReady signal
102 private void OnResourceReady(IntPtr data)
104 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
107 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
110 if (_resourceReadyEventHandler != null)
112 _resourceReadyEventHandler(this, e);
117 /// you can override it to clean-up your own resources.
119 /// <param name="type">DisposeTypes</param>
120 /// <since_tizen> 3 </since_tizen>
121 protected override void Dispose(DisposeTypes type)
128 if(type == DisposeTypes.Explicit)
131 //Release your own managed resources here.
132 //You should release all of your own disposable objects here.
135 _nPatchMap?.Dispose();
139 //Release your own unmanaged resources here.
140 //You should not access any managed member here except static instance.
141 //because the execution order of Finalizes is non-deterministic.
143 if (swigCPtr.Handle != global::System.IntPtr.Zero)
148 NDalicPINVOKE.delete_ImageView(swigCPtr);
150 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
156 internal new class Property
158 internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
159 internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
160 internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
161 internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
165 /// Creates an initialized ImageView.
167 /// <since_tizen> 3 </since_tizen>
168 public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 /// Creates an initialized ImageView from a URL to an image resource.<br />
175 /// If the string is empty, ImageView will not display anything.<br />
177 /// <param name="url">The URL of the image resource to display.</param>
178 /// <since_tizen> 3 </since_tizen>
179 public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
182 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185 internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
188 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 /// [Obsolete("Please do not use! this will be deprecated")]
195 [Obsolete("Please do not use! this will be deprecated")]
196 public new static ImageView DownCast(BaseHandle handle)
198 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 /// Sets this ImageView from the given URL.<br />
204 /// If the URL is empty, ImageView will not display anything.<br />
206 /// <param name="url">The URL to the image resource to display.</param>
207 /// <since_tizen> 3 </since_tizen>
208 public void SetImage(string url)
211 NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
212 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214 internal void SetImage(string url, Uint16Pair size)
217 NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
218 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 internal ViewResourceReadySignal ResourceReadySignal(View view) {
222 ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 /// Queries if all resources required by a control are loaded and ready.<br />
229 /// Most resources are only loaded when the control is placed on the stage.<br />
230 /// True if the resources are loaded and ready, false otherwise.<br />
232 /// <since_tizen> 3 </since_tizen>
233 public new bool IsResourceReady()
235 bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
236 if (NDalicPINVOKE.SWIGPendingException.Pending)
237 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// ImageView ResourceUrl, type string.
244 /// <since_tizen> 3 </since_tizen>
245 public string ResourceUrl
249 GetProperty(ImageView.Property.RESOURCE_URL).Get(out _url);
260 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise
262 /// <since_tizen> 3 </since_tizen>
263 public PropertyMap ImageMap
269 PropertyMap temp = new PropertyMap();
270 GetProperty(ImageView.Property.IMAGE).Get(temp);
282 SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
288 /// ImageView PreMultipliedAlpha, type Boolean.<br />
289 /// Image must be initialized.<br />
291 /// <since_tizen> 3 </since_tizen>
292 public bool PreMultipliedAlpha
297 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
302 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
307 /// ImageView PixelArea, type Vector4 (Animatable property).<br />
308 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
310 /// <since_tizen> 3 </since_tizen>
311 public RelativeVector4 PixelArea
315 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
316 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
321 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
326 /// The border of the image in the order: left, right, bottom, top.<br />
327 /// If set, ImageMap will be ignored.<br />
328 /// For N-Patch images only.<br />
331 /// <since_tizen> 3 </since_tizen>
332 public Rectangle Border
346 /// Gets or sets whether to draw the borders only (if true).<br />
347 /// If not specified, the default is false.<br />
348 /// For N-Patch images only.<br />
351 /// <since_tizen> 3 </since_tizen>
352 public bool BorderOnly
356 return _borderOnly ?? false;
366 /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
368 /// <since_tizen> 3 </since_tizen>
369 public bool SynchronosLoading
373 return _synchronousLoading ?? false;
377 _synchronousLoading = value;
382 private void UpdateImage()
387 { // for nine-patch image
388 _nPatchMap = new PropertyMap();
389 _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
390 _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
391 _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
392 if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
393 if (_synchronousLoading != null) _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
394 SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
396 else if(_synchronousLoading != null)
397 { // for normal image, with synchronous loading property
398 PropertyMap imageMap = new PropertyMap();
399 imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
400 imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
401 imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
402 SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
405 { // just for normal image
406 SetProperty(ImageView.Property.RESOURCE_URL, new PropertyValue(_url));
411 private Rectangle _border = null;
412 private PropertyMap _nPatchMap = null;
413 private bool? _synchronousLoading = null;
414 private bool? _borderOnly = null;
415 private string _url = null;