1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 namespace Tizen.NUI.BaseComponents
20 using System.Runtime.InteropServices;
23 /// ImageView is a class for displaying an image resource.<br>
24 /// An instance of ImageView can be created using a URL or an image instance.<br>
26 public class ImageView : View
28 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
42 /// Event arguments of resource ready.
44 public class ResourceReadyEventArgs : EventArgs
49 /// The view whose resource is ready.
51 /// <since_tizen> 3 </since_tizen>
65 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
66 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
67 private delegate void ResourceReadyEventCallbackType(IntPtr data);
68 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
71 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br>
72 /// This signal is emitted after all resources required by a control are loaded and ready.<br>
73 /// Most resources are only loaded when the control is placed on the stage.<br>
75 /// <since_tizen> 3 </since_tizen>
76 public event EventHandler<ResourceReadyEventArgs> ResourceReady
80 if (_resourceReadyEventHandler == null)
82 _resourceReadyEventCallback = OnResourceReady;
83 ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
86 _resourceReadyEventHandler += value;
91 _resourceReadyEventHandler -= value;
93 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
95 ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
100 // Callback for View ResourceReady signal
101 private void OnResourceReady(IntPtr data)
103 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
106 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
109 if (_resourceReadyEventHandler != null)
111 _resourceReadyEventHandler(this, e);
115 //you can override it to clean-up your own resources.
116 protected override void Dispose(DisposeTypes type)
123 if(type == DisposeTypes.Explicit)
126 //Release your own managed resources here.
127 //You should release all of your own disposable objects here.
130 _nPatchMap?.Dispose();
134 //Release your own unmanaged resources here.
135 //You should not access any managed member here except static instance.
136 //because the execution order of Finalizes is non-deterministic.
138 if (swigCPtr.Handle != global::System.IntPtr.Zero)
143 NDalicPINVOKE.delete_ImageView(swigCPtr);
145 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
151 internal new class Property
153 internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
154 internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
155 internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
156 internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
160 /// Creates an initialized ImageView.
162 /// <since_tizen> 3 </since_tizen>
163 public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 /// Creates an initialized ImageView from a URL to an image resource.<br>
170 /// If the string is empty, ImageView will not display anything.<br>
172 /// <param name="url">The URL of the image resource to display.</param>
173 /// <since_tizen> 3 </since_tizen>
174 public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 [Obsolete("Please do not use! this will be deprecated")]
188 public new static ImageView DownCast(BaseHandle handle)
190 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195 /// Sets this ImageView from the given URL.<br>
196 /// If the URL is empty, ImageView will not display anything.<br>
198 /// <param name="url">The URL to the image resource to display.</param>
199 /// <since_tizen> 3 </since_tizen>
200 public void SetImage(string url)
203 NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 internal void SetImage(string url, Uint16Pair size)
209 NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 internal ViewResourceReadySignal ResourceReadySignal(View view) {
214 ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 /// Queries if all resources required by a control are loaded and ready.<br>
221 /// Most resources are only loaded when the control is placed on the stage.<br>
222 /// True if the resources are loaded and ready, false otherwise.<br>
224 /// <since_tizen> 3 </since_tizen>
225 public new bool IsResourceReady()
227 bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
228 if (NDalicPINVOKE.SWIGPendingException.Pending)
229 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 /// ImageView ResourceUrl, type string.
236 /// <since_tizen> 3 </since_tizen>
237 public string ResourceUrl
241 GetProperty(ImageView.Property.RESOURCE_URL).Get(out _url);
252 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise
254 /// <since_tizen> 3 </since_tizen>
255 public PropertyMap ImageMap
261 PropertyMap temp = new PropertyMap();
262 GetProperty(ImageView.Property.IMAGE).Get(temp);
274 SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
280 /// ImageView PreMultipliedAlpha, type Boolean.<br>
281 /// Image must be initialized.<br>
283 /// <since_tizen> 3 </since_tizen>
284 public bool PreMultipliedAlpha
289 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
294 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
299 /// ImageView PixelArea, type Vector4 (Animatable property).<br>
300 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br>
302 /// <since_tizen> 3 </since_tizen>
303 public RelativeVector4 PixelArea
307 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
308 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
313 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
318 /// The border of the image in the order: left, right, bottom, top.<br>
319 /// If set, ImageMap will be ignored.<br>
320 /// For N-Patch images only.<br>
323 /// <since_tizen> 3 </since_tizen>
324 public Rectangle Border
338 /// Gets or sets whether to draw the borders only (if true).<br>
339 /// If not specified, the default is false.<br>
340 /// For N-Patch images only.<br>
343 /// <since_tizen> 3 </since_tizen>
344 public bool BorderOnly
348 return _borderOnly ?? false;
357 public bool SynchronosLoading
361 return _synchronousLoading ?? false;
365 _synchronousLoading = value;
370 private void UpdateImage()
375 { // for nine-patch image
376 _nPatchMap = new PropertyMap();
377 _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
378 _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
379 _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
380 if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
381 if (_synchronousLoading != null) _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
382 SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
384 else if(_synchronousLoading != null)
385 { // for normal image, with synchronous loading property
386 PropertyMap imageMap = new PropertyMap();
387 imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
388 imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
389 imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
390 SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
393 { // just for normal image
394 SetProperty(ImageView.Property.RESOURCE_URL, new PropertyValue(_url));
399 private Rectangle _border = null;
400 private PropertyMap _nPatchMap = null;
401 private bool? _synchronousLoading = null;
402 private bool? _borderOnly = null;
403 private string _url = null;