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.
64 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
65 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
66 private delegate void ResourceReadyEventCallbackType(IntPtr data);
67 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
70 /// Event for ResourceReady signal which can be used to subscribe/unsubscribe the event handler.<br>
71 /// This signal is emitted after all resources required by a control are loaded and ready.<br>
72 /// Most resources are only loaded when the control is placed on stage.<br>
74 public event EventHandler<ResourceReadyEventArgs> ResourceReady
78 if (_resourceReadyEventHandler == null)
80 _resourceReadyEventCallback = OnResourceReady;
81 ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
84 _resourceReadyEventHandler += value;
89 _resourceReadyEventHandler -= value;
91 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
93 ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
98 // Callback for View ResourceReady signal
99 private void OnResourceReady(IntPtr data)
101 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
104 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
107 if (_resourceReadyEventHandler != null)
109 _resourceReadyEventHandler(this, e);
113 //you can override it to clean-up your own resources.
114 protected override void Dispose(DisposeTypes type)
121 if(type == DisposeTypes.Explicit)
124 //Release your own managed resources here.
125 //You should release all of your own disposable objects here.
128 _nPatchMap?.Dispose();
132 //Release your own unmanaged resources here.
133 //You should not access any managed member here except static instance.
134 //because the execution order of Finalizes is non-deterministic.
136 if (swigCPtr.Handle != global::System.IntPtr.Zero)
141 NDalicPINVOKE.delete_ImageView(swigCPtr);
143 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
149 internal class Property
151 internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
152 internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
153 internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
154 internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
158 /// Creates an initialized ImageView.
160 public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166 /// Creates an initialized ImageView from an URL to an image resource.<br>
167 /// If the string is empty, ImageView will not display anything.<br>
169 /// <param name="url">The url of the image resource to display</param>
170 public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
172 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175 internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181 [Obsolete("Please do not use! this will be deprecated")]
182 public new static ImageView DownCast(BaseHandle handle)
184 ImageView ret = new ImageView(NDalicPINVOKE.ImageView_DownCast(BaseHandle.getCPtr(handle)), true);
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 /// Sets this ImageView from the given URL.<br>
190 /// If the URL is empty, ImageView will not display anything.<br>
192 /// <param name="url">The URL to the image resource to display</param>
193 public void SetImage(string url)
195 NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
196 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 internal void SetImage(string url, Uint16Pair size)
200 NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 internal ViewResourceReadySignal ResourceReadySignal(View view) {
205 ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 /// Query if all resources required by a control are loaded and ready.<br>
212 /// Most resources are only loaded when the control is placed on stage.<br>
213 /// true if the resources are loaded and ready, false otherwise.<br>
215 public bool IsResourceReady()
217 bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
218 if (NDalicPINVOKE.SWIGPendingException.Pending)
219 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 /// ImageView ResourceUrl, type string
226 public string ResourceUrl
230 GetProperty(ImageView.Property.RESOURCE_URL).Get(out _url);
241 /// ImageView ImageMap, type PropertyMap : string if it is a url, map otherwise
243 public PropertyMap ImageMap
249 PropertyMap temp = new PropertyMap();
250 GetProperty(ImageView.Property.IMAGE).Get(temp);
262 SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
268 /// ImageView PreMultipliedAlpha, type Boolean.<br>
269 /// Image must be initialized.<br>
271 public bool PreMultipliedAlpha
276 GetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
281 SetProperty(ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue(value));
286 /// ImageView PixelArea, type Vector4 (Animatable property).<br>
287 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br>
289 public RelativeVector4 PixelArea
293 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
294 GetProperty(ImageView.Property.PIXEL_AREA).Get(temp);
299 SetProperty(ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue(value));
304 /// The border of the image in the order: left, right, bottom, top.<br>
305 /// If set, ImageMap will be ignored.<br>
306 /// For N-Patch images only.<br>
309 public Rectangle Border
323 /// Get or set whether to draws the borders only(If true).<br>
324 /// If not specified, the default is false.<br>
325 /// For N-Patch images only.<br>
328 public bool BorderOnly
332 return _borderOnly ?? false;
341 public bool SynchronosLoading
345 return _synchronousLoading ?? false;
349 _synchronousLoading = value;
354 private void UpdateImage()
359 { // for nine-patch image
360 _nPatchMap = new PropertyMap();
361 _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
362 _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
363 _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
364 if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
365 if (_synchronousLoading != null) _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
366 SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
368 else if(_synchronousLoading != null)
369 { // for normal image, with synchronous loading property
370 PropertyMap imageMap = new PropertyMap();
371 imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
372 imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
373 imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading));
374 SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
377 { // just for normal image
378 SetProperty(ImageView.Property.RESOURCE_URL, new PropertyValue(_url));
383 private Rectangle _border = null;
384 private PropertyMap _nPatchMap = null;
385 private bool? _synchronousLoading = null;
386 private bool? _borderOnly = null;
387 private string _url = null;