2 * Copyright(c) 2019 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 using System.Runtime.InteropServices;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.BaseComponents
26 /// ImageView is a class for displaying an image resource.<br />
27 /// An instance of ImageView can be created using a URL or an image instance.<br />
29 /// <since_tizen> 3 </since_tizen>
30 public class ImageView : View
32 static ImageView() { }
34 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
38 var imageView = (ImageView)bindable;
39 string url = (string)newValue;
40 url = (url == null ? "" : url);
41 if (imageView.IsCreateByXaml && url.Contains("*Resource*"))
43 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
44 url = url.Replace("*Resource*", resource);
46 imageView._resourceUrl = url;
47 imageView.UpdateImage(ImageVisualProperty.URL, new PropertyValue(url));
49 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
51 var imageView = (ImageView)bindable;
54 PropertyMap imageMap = new PropertyMap();
55 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
56 imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
60 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
64 var imageView = (ImageView)bindable;
67 PropertyMap map = (PropertyMap)newValue;
68 if (imageView.IsCreateByXaml)
70 string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
71 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
72 PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
74 if (urlValue != null) ret = urlValue.Get(out url);
75 PropertyMap mmap = new PropertyMap();
76 if (ret && url.Contains("*Resource*"))
78 url = url.Replace("*Resource*", resource);
79 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
83 PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
84 if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
85 if (ret && alphaMaskURL.Contains("*Resource*"))
87 alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
88 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
92 PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
93 if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
94 if (ret && auxiliaryImageURL.Contains("*Resource*"))
96 auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
97 mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
102 if (imageView._border == null)
104 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
108 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
110 var imageView = (ImageView)bindable;
111 if (imageView._border == null)
113 PropertyMap temp = new PropertyMap();
114 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
123 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
127 var imageView = (ImageView)bindable;
128 if (newValue != null)
130 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
133 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
135 var imageView = (ImageView)bindable;
137 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
141 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
145 var imageView = (ImageView)bindable;
146 if (newValue != null)
148 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
151 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
153 var imageView = (ImageView)bindable;
154 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
155 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
156 RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
160 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
164 var imageView = (ImageView)bindable;
165 if (newValue != null)
167 imageView._border = new Rectangle((Rectangle)newValue);
168 imageView.UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(imageView._border));
171 defaultValueCreator: (bindable) =>
173 var imageView = (ImageView)bindable;
174 return imageView._border;
177 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
178 [EditorBrowsable(EditorBrowsableState.Never)]
179 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
181 var imageView = (ImageView)bindable;
182 if (newValue != null)
184 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
187 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
189 var imageView = (ImageView)bindable;
191 PropertyMap imageMap = new PropertyMap();
192 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
193 imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
197 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
198 [EditorBrowsable(EditorBrowsableState.Never)]
199 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronosLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
201 var imageView = (ImageView)bindable;
202 if (newValue != null)
204 imageView._synchronosLoading = (bool)newValue;
205 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
208 defaultValueCreator: (bindable) =>
210 var imageView = (ImageView)bindable;
211 return imageView._synchronosLoading;
214 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
218 var imageView = (ImageView)bindable;
219 if (newValue != null)
221 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
224 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
226 var imageView = (ImageView)bindable;
229 PropertyMap imageMap = new PropertyMap();
230 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
231 imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
236 internal static readonly BindableProperty ResourceUrlSelectorProperty = BindableProperty.Create("ResourceUrlSelector", typeof(Selector<string>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
238 var imageView = (ImageView)bindable;
239 imageView.resourceUrlSelector.Update(imageView, (Selector<string>)newValue, true);
241 defaultValueCreator: (bindable) =>
243 var imageView = (ImageView)bindable;
244 return imageView.resourceUrlSelector.Get(imageView);
247 internal static readonly BindableProperty BorderSelectorProperty = BindableProperty.Create("BorderSelector", typeof(Selector<Rectangle>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
249 var imageView = (ImageView)bindable;
250 imageView.borderSelector.Update(imageView, (Selector<Rectangle>)newValue, true);
252 defaultValueCreator: (bindable) =>
254 var imageView = (ImageView)bindable;
255 return imageView.borderSelector.Get(imageView);
258 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
259 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
260 private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
261 private _resourceLoadedCallbackType _resourceLoadedCallback;
263 private Rectangle _border;
264 private string _resourceUrl = "";
265 private bool _synchronosLoading = false;
266 private string _alphaMaskUrl = null;
267 private int _desired_width = -1;
268 private int _desired_height = -1;
269 private readonly TriggerableSelector<string> resourceUrlSelector = new TriggerableSelector<string>(ResourceUrlProperty);
270 private readonly TriggerableSelector<Rectangle> borderSelector = new TriggerableSelector<Rectangle>(BorderProperty);
273 /// Creates an initialized ImageView.
275 /// <since_tizen> 3 </since_tizen>
276 public ImageView() : this(Interop.ImageView.New(), true)
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.New(), true, viewStyle)
288 /// Creates an initialized ImageView with setting the status of shown or hidden.
290 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
291 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public ImageView(bool shown) : this(Interop.ImageView.New(), true)
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 /// Creates an initialized ImageView from a URL to an image resource.<br />
301 /// If the string is empty, ImageView will not display anything.<br />
303 /// <param name="url">The URL of the image resource to display.</param>
304 /// <since_tizen> 3 </since_tizen>
305 public ImageView(string url) : this(Interop.ImageView.New(url), true)
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
315 /// <param name="url">The URL of the image resource to display.</param>
316 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
317 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
318 [EditorBrowsable(EditorBrowsableState.Never)]
319 public ImageView(string url, bool shown) : this(Interop.ImageView.New(url), true)
322 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326 internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.New(url, Uint16Pair.getCPtr(size)), true)
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
345 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
353 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
354 private delegate void ResourceReadyEventCallbackType(IntPtr data);
355 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
356 private delegate void _resourceLoadedCallbackType(IntPtr view);
359 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
360 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
361 /// Most resources are only loaded when the control is placed on the stage.<br />
363 /// <since_tizen> 3 </since_tizen>
364 public event EventHandler<ResourceReadyEventArgs> ResourceReady
368 if (_resourceReadyEventHandler == null)
370 _resourceReadyEventCallback = OnResourceReady;
371 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
372 resourceReadySignal?.Connect(_resourceReadyEventCallback);
373 resourceReadySignal?.Dispose();
376 _resourceReadyEventHandler += value;
381 _resourceReadyEventHandler -= value;
383 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
384 if (_resourceReadyEventHandler == null && resourceReadySignal?.Empty() == false)
386 resourceReadySignal?.Disconnect(_resourceReadyEventCallback);
388 resourceReadySignal?.Dispose();
392 internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
396 if (_resourceLoadedEventHandler == null)
398 _resourceLoadedCallback = OnResourceLoaded;
399 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
400 resourceReadySignal?.Connect(_resourceLoadedCallback);
401 resourceReadySignal?.Dispose();
404 _resourceLoadedEventHandler += value;
408 _resourceLoadedEventHandler -= value;
409 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
410 if (_resourceLoadedEventHandler == null && resourceReadySignal?.Empty() == false)
412 resourceReadySignal?.Disconnect(_resourceLoadedCallback);
414 resourceReadySignal?.Dispose();
419 /// Enumeration for LoadingStatus of image.
421 /// <since_tizen> 5 </since_tizen>
422 public enum LoadingStatusType
425 /// Loading preparing status.
427 /// <since_tizen> 5 </since_tizen>
430 /// Loading ready status.
432 /// <since_tizen> 5 </since_tizen>
435 /// Loading failed status.
437 /// <since_tizen> 5 </since_tizen>
442 /// ImageView ResourceUrl, type string.
443 /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
444 /// When it is set as null, it gives empty string ("") to be read.
446 /// <since_tizen> 3 </since_tizen>
447 public string ResourceUrl
451 return (string)GetValue(ResourceUrlProperty);
455 SetValue(ResourceUrlProperty, value);
456 resourceUrlSelector.UpdateIfNeeds(this, value);
457 NotifyPropertyChanged();
462 /// This will be deprecated, please use Image instead. <br />
463 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
465 /// <since_tizen> 3 </since_tizen>
466 [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
467 [EditorBrowsable(EditorBrowsableState.Never)]
468 public PropertyMap ImageMap
474 PropertyMap returnValue = new PropertyMap();
475 PropertyValue image = GetProperty(ImageView.Property.IMAGE);
476 image?.Get(returnValue);
489 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
490 SetProperty(ImageView.Property.IMAGE, setValue);
491 NotifyPropertyChanged();
498 /// ImageView Image, type PropertyMap
500 /// <since_tizen> 4 </since_tizen>
501 public PropertyMap Image
507 return (PropertyMap)GetValue(ImageProperty);
518 SetValue(ImageProperty, value);
519 NotifyPropertyChanged();
525 /// ImageView PreMultipliedAlpha, type Boolean.<br />
526 /// Image must be initialized.<br />
528 /// <since_tizen> 3 </since_tizen>
529 public bool PreMultipliedAlpha
533 return (bool)GetValue(PreMultipliedAlphaProperty);
537 SetValue(PreMultipliedAlphaProperty, value);
538 NotifyPropertyChanged();
543 /// ImageView PixelArea, type Vector4 (Animatable property).<br />
544 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
547 /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
549 /// <since_tizen> 3 </since_tizen>
550 public RelativeVector4 PixelArea
554 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
555 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
559 SetValue(PixelAreaProperty, value);
560 NotifyPropertyChanged();
565 /// The border of the image in the order: left, right, bottom, top.<br />
566 /// If set, ImageMap will be ignored.<br />
567 /// For N-Patch images only.<br />
571 /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
573 /// <since_tizen> 3 </since_tizen>
574 public Rectangle Border
578 Rectangle temp = (Rectangle)GetValue(BorderProperty);
585 return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
590 SetValue(BorderProperty, value);
591 borderSelector.UpdateIfNeeds(this, value);
592 NotifyPropertyChanged();
597 /// Gets or sets whether to draw the borders only (if true).<br />
598 /// If not specified, the default is false.<br />
599 /// For N-Patch images only.<br />
602 /// <since_tizen> 3 </since_tizen>
603 public bool BorderOnly
607 return (bool)GetValue(BorderOnlyProperty);
611 SetValue(BorderOnlyProperty, value);
612 NotifyPropertyChanged();
617 /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
619 /// <since_tizen> 3 </since_tizen>
620 public bool SynchronosLoading
624 return (bool)GetValue(SynchronosLoadingProperty);
628 SetValue(SynchronosLoadingProperty, value);
629 NotifyPropertyChanged();
634 /// Gets or sets whether to automatically correct the orientation of an image.<br />
636 /// <since_tizen> 5 </since_tizen>
637 public bool OrientationCorrection
641 return (bool)GetValue(OrientationCorrectionProperty);
645 SetValue(OrientationCorrectionProperty, value);
646 NotifyPropertyChanged();
651 /// Gets the loading state of the visual resource.
653 /// <since_tizen> 5 </since_tizen>
654 public ImageView.LoadingStatusType LoadingStatus
658 return (ImageView.LoadingStatusType)Interop.View.GetVisualResourceStatus(SwigCPtr, (int)Property.IMAGE);
663 /// Downcasts a handle to imageView handle.
665 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
666 /// Please do not use! this will be deprecated!
667 /// Instead please use as keyword.
668 /// <since_tizen> 3 </since_tizen>
669 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
671 "BaseHandle handle = new ImageView(imagePath); " +
672 "ImageView image = handle as ImageView")]
673 [EditorBrowsable(EditorBrowsableState.Never)]
674 public static ImageView DownCast(BaseHandle handle)
678 throw new ArgumentNullException(nameof(handle));
680 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
681 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
686 /// Sets this ImageView from the given URL.<br />
687 /// If the URL is empty, ImageView will not display anything.<br />
689 /// <param name="url">The URL to the image resource to display.</param>
690 /// <exception cref="ArgumentNullException"> Thrown when url is null. </exception>
691 /// <since_tizen> 3 </since_tizen>
692 public void SetImage(string url)
696 throw new ArgumentNullException(nameof(url));
699 if (url.Contains(".json"))
701 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
705 Interop.ImageView.SetImage(SwigCPtr, url);
706 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
712 /// Queries if all resources required by a control are loaded and ready.<br />
713 /// Most resources are only loaded when the control is placed on the stage.<br />
714 /// True if the resources are loaded and ready, false otherwise.<br />
716 /// <since_tizen> 3 </since_tizen>
717 public new bool IsResourceReady()
719 bool ret = Interop.View.IsResourceReady(SwigCPtr);
720 if (NDalicPINVOKE.SWIGPendingException.Pending)
721 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
726 /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
728 /// <since_tizen> 5 </since_tizen>
731 PropertyValue attributes = new PropertyValue(0);
732 this.DoAction(ImageView.Property.IMAGE, Property.ActionReload, attributes);
733 attributes?.Dispose();
737 /// Plays the animated GIF. This is also the default playback mode.
739 /// <since_tizen> 5 </since_tizen>
742 PropertyValue attributes = new PropertyValue(0);
743 this.DoAction(ImageView.Property.IMAGE, Property.ActionPlay, attributes);
744 attributes?.Dispose();
748 /// Pauses the animated GIF.
750 /// <since_tizen> 5 </since_tizen>
753 PropertyValue attributes = new PropertyValue(0);
754 this.DoAction(ImageView.Property.IMAGE, Property.ActionPause, attributes);
755 attributes?.Dispose();
759 /// Stops the animated GIF.
761 /// <since_tizen> 5 </since_tizen>
764 PropertyValue attributes = new PropertyValue(0);
765 this.DoAction(ImageView.Property.IMAGE, Property.ActionStop, attributes);
766 attributes?.Dispose();
770 /// Gets or sets the URL of the alpha mask.<br />
773 /// <since_tizen> 6</since_tizen>
774 [EditorBrowsable(EditorBrowsableState.Never)]
775 public string AlphaMaskURL
780 PropertyMap imageMap = new PropertyMap();
781 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
782 image?.Get(imageMap);
783 PropertyValue maskUrl = imageMap?.Find(ImageVisualProperty.AlphaMaskURL);
784 maskUrl?.Get(out ret);
800 _alphaMaskUrl = value;
802 PropertyValue setValue = new PropertyValue(value);
803 UpdateImage(ImageVisualProperty.AlphaMaskURL, setValue);
810 /// Whether to crop image to mask or scale mask to fit image.
812 /// <since_tizen> 6 </since_tizen>
813 public bool CropToMask
818 PropertyMap imageMap = new PropertyMap();
819 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
820 image?.Get(imageMap);
821 PropertyValue cropUrl = imageMap?.Find(ImageVisualProperty.CropToMask);
822 cropUrl?.Get(out ret);
832 PropertyValue setValue = new PropertyValue(value);
833 UpdateImage(ImageVisualProperty.CropToMask, setValue);
838 internal VisualFittingModeType CovertFittingModetoVisualFittingMode(FittingModeType value)
842 case FittingModeType.ShrinkToFit:
843 return VisualFittingModeType.FitKeepAspectRatio;
844 case FittingModeType.ScaleToFill:
845 return VisualFittingModeType.OverFitKeepAspectRatio;
846 case FittingModeType.Center:
847 return VisualFittingModeType.Center;
848 case FittingModeType.Fill:
849 return VisualFittingModeType.Fill;
850 case FittingModeType.FitHeight:
851 return VisualFittingModeType.FitHeight;
852 case FittingModeType.FitWidth:
853 return VisualFittingModeType.FitHeight;
855 return VisualFittingModeType.Fill;
859 internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
863 case VisualFittingModeType.FitKeepAspectRatio:
864 return FittingModeType.ShrinkToFit;
865 case VisualFittingModeType.OverFitKeepAspectRatio:
866 return FittingModeType.ScaleToFill;
867 case VisualFittingModeType.Center:
868 return FittingModeType.Center;
869 case VisualFittingModeType.Fill:
870 return FittingModeType.Fill;
871 case VisualFittingModeType.FitHeight:
872 return FittingModeType.FitHeight;
873 case VisualFittingModeType.FitWidth:
874 return FittingModeType.FitWidth;
876 return FittingModeType.ShrinkToFit;
881 /// Gets or sets fitting options used when resizing images to fit.<br />
882 /// If not supplied, the default is FittingModeType.Fill.<br />
883 /// For normal quad images only.<br />
886 /// <since_tizen> 6 </since_tizen>
887 [EditorBrowsable(EditorBrowsableState.Never)]
888 public FittingModeType FittingMode
892 int ret = (int)VisualFittingModeType.Fill;
893 PropertyMap imageMap = new PropertyMap();
894 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
895 image?.Get(imageMap);
896 PropertyValue fittingMode = imageMap?.Find(Visual.Property.VisualFittingMode);
897 fittingMode?.Get(out ret);
901 fittingMode?.Dispose();
903 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
907 VisualFittingModeType ret = CovertFittingModetoVisualFittingMode(value);
908 PropertyValue setValue = new PropertyValue((int)ret);
909 UpdateImage(Visual.Property.VisualFittingMode, setValue);
917 /// Gets or sets the desired image width.<br />
918 /// If not specified, the actual image width is used.<br />
919 /// For normal quad images only.<br />
922 /// <since_tizen> 6 </since_tizen>
923 [EditorBrowsable(EditorBrowsableState.Never)]
924 public int DesiredWidth
928 PropertyMap imageMap = new PropertyMap();
929 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
930 image?.Get(imageMap);
931 PropertyValue desireWidth = imageMap?.Find(ImageVisualProperty.DesiredWidth);
932 desireWidth?.Get(out _desired_width);
936 desireWidth?.Dispose();
938 return _desired_width;
942 if (_desired_width != value)
944 _desired_width = value;
945 UpdateImage(0, null);
951 /// Gets or sets the desired image height.<br />
952 /// If not specified, the actual image height is used.<br />
953 /// For normal quad images only.<br />
956 /// <since_tizen> 6 </since_tizen>
957 [EditorBrowsable(EditorBrowsableState.Never)]
958 public int DesiredHeight
962 PropertyMap imageMap = new PropertyMap();
963 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
964 image?.Get(imageMap);
965 PropertyValue desireheight = imageMap?.Find(ImageVisualProperty.DesiredHeight);
966 desireheight?.Get(out _desired_height);
970 desireheight?.Dispose();
972 return _desired_height;
976 if (_desired_height != value)
978 _desired_height = value;
979 UpdateImage(0, null);
985 /// Gets or sets ReleasePolicy for image.<br />
986 /// If not supplied, the default is ReleasePolicyType.Detached.<br />
988 [EditorBrowsable(EditorBrowsableState.Never)]
989 public ReleasePolicyType ReleasePolicy
993 int ret = (int)ReleasePolicyType.Detached;
994 PropertyMap imageMap = new PropertyMap();
995 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
996 image?.Get(imageMap);
997 PropertyValue releasePoli = imageMap?.Find(ImageVisualProperty.ReleasePolicy);
998 releasePoli?.Get(out ret);
1000 imageMap?.Dispose();
1002 releasePoli?.Dispose();
1004 return (ReleasePolicyType)ret;
1008 PropertyValue setValue = new PropertyValue((int)value);
1009 UpdateImage(ImageVisualProperty.ReleasePolicy, setValue);
1010 setValue?.Dispose();
1015 /// Gets or sets the wrap mode for the u coordinate.<br />
1016 /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
1017 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1018 /// For normal quad images only.<br />
1021 /// <since_tizen> 6 </since_tizen>
1022 [EditorBrowsable(EditorBrowsableState.Never)]
1023 public WrapModeType WrapModeU
1027 int ret = (int)WrapModeType.Default;
1028 PropertyMap imageMap = new PropertyMap();
1029 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1030 image?.Get(imageMap);
1031 PropertyValue warpModeU = imageMap?.Find(ImageVisualProperty.WrapModeU);
1032 warpModeU?.Get(out ret);
1034 imageMap?.Dispose();
1036 warpModeU?.Dispose();
1038 return (WrapModeType)ret;
1042 PropertyValue setValue = new PropertyValue((int)value);
1043 UpdateImage(ImageVisualProperty.WrapModeU, setValue);
1044 setValue?.Dispose();
1049 /// Gets or sets the wrap mode for the v coordinate.<br />
1050 /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
1051 /// The first two elements indicate the top-left position of the area, and the last two elements are the areas of the width and the height respectively.<br />
1052 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1053 /// For normal quad images only.
1056 /// <since_tizen> 6 </since_tizen>
1057 [EditorBrowsable(EditorBrowsableState.Never)]
1058 public WrapModeType WrapModeV
1062 int ret = (int)WrapModeType.Default;
1063 PropertyMap imageMap = new PropertyMap();
1064 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1065 image?.Get(imageMap);
1066 PropertyValue wrapModeV = imageMap?.Find(ImageVisualProperty.WrapModeV);
1067 wrapModeV?.Get(out ret);
1069 imageMap?.Dispose();
1071 wrapModeV?.Dispose();
1073 return (WrapModeType)ret;
1077 PropertyValue setValue = new PropertyValue((int)value);
1078 UpdateImage(ImageVisualProperty.WrapModeV, setValue);
1079 setValue?.Dispose();
1084 /// Get attribues, it is abstract function and must be override.
1086 [EditorBrowsable(EditorBrowsableState.Never)]
1087 protected override ViewStyle CreateViewStyle()
1089 return new ImageViewStyle();
1092 internal void SetImage(string url, Uint16Pair size)
1094 if (url.Contains(".json"))
1096 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
1100 Interop.ImageView.SetImage(SwigCPtr, url, Uint16Pair.getCPtr(size));
1101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1106 internal ViewResourceReadySignal ResourceReadySignal(View view)
1108 ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
1109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1113 internal override void ApplyCornerRadius()
1115 base.ApplyCornerRadius();
1117 UpdateImage(0, null);
1120 internal ResourceLoadingStatusType GetResourceStatus()
1122 return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1126 /// you can override it to clean-up your own resources.
1128 /// <param name="type">DisposeTypes</param>
1129 /// <since_tizen> 3 </since_tizen>
1130 protected override void Dispose(DisposeTypes type)
1137 if (type == DisposeTypes.Explicit)
1140 //Release your own managed resources here.
1141 //You should release all of your own disposable objects here.
1144 borderSelector.Reset(this);
1145 resourceUrlSelector.Reset(this);
1151 /// This will not be public opened.
1152 [EditorBrowsable(EditorBrowsableState.Never)]
1153 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1155 Interop.ImageView.DeleteImageView(swigCPtr);
1158 // Callback for View ResourceReady signal
1159 private void OnResourceReady(IntPtr data)
1161 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1164 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1167 if (_resourceReadyEventHandler != null)
1169 _resourceReadyEventHandler(this, e);
1173 private void UpdateImageMap(PropertyMap fromMap)
1175 PropertyMap imageMap = new PropertyMap();
1177 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1178 image?.Get(imageMap);
1179 imageMap?.Merge(fromMap);
1180 PropertyValue setValue = new PropertyValue(imageMap);
1181 SetProperty(ImageView.Property.IMAGE, setValue);
1183 imageMap?.Dispose();
1185 setValue?.Dispose();
1188 private void UpdateImage(int key, PropertyValue value)
1190 PropertyMap imageMap = new PropertyMap();
1192 if (_alphaMaskUrl != null)
1194 PropertyValue alphaMaskUrl = new PropertyValue(_alphaMaskUrl);
1195 imageMap?.Insert(ImageVisualProperty.AlphaMaskURL, alphaMaskUrl);
1196 alphaMaskUrl?.Dispose();
1199 if (string.IsNullOrEmpty(_resourceUrl))
1201 PropertyValue resourceUrl = new PropertyValue(_resourceUrl);
1202 imageMap?.Insert(ImageVisualProperty.URL, resourceUrl);
1203 PropertyValue setValue = new PropertyValue(imageMap);
1204 SetProperty(ImageView.Property.IMAGE, setValue);
1205 resourceUrl?.Dispose();
1206 setValue?.Dispose();
1210 if (_border == null)
1212 PropertyValue image = new PropertyValue((int)Visual.Type.Image);
1213 imageMap?.Insert(Visual.Property.Type, image);
1218 PropertyValue nPatch = new PropertyValue((int)Visual.Type.NPatch);
1219 imageMap?.Insert(Visual.Property.Type, nPatch);
1221 PropertyValue border = new PropertyValue(_border);
1222 imageMap?.Insert(NpatchImageVisualProperty.Border, border);
1226 PropertyValue synchronosLoading = new PropertyValue(_synchronosLoading);
1227 imageMap?.Insert(NpatchImageVisualProperty.SynchronousLoading, synchronosLoading);
1228 synchronosLoading?.Dispose();
1230 if (backgroundExtraData != null && backgroundExtraData.CornerRadius > 0)
1232 PropertyValue cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius);
1233 imageMap?.Insert(Visual.Property.CornerRadius, cornerRadius);
1234 cornerRadius?.Dispose();
1239 imageMap?.Insert(key, value);
1242 // Do Fitting Buffer when desired dimension is set
1243 if (_desired_width != -1 && _desired_height != -1)
1245 if (_resourceUrl != null)
1247 Size2D originalImageSize = ImageLoading.GetOriginalImageSize(_resourceUrl);
1248 Size2D imageSize = originalImageSize;
1249 originalImageSize?.Dispose();
1251 int adjustedDesiredWidth, adjustedDesiredHeight;
1252 float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
1253 float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
1254 if( aspectOfImageSize > aspectOfDesiredSize)
1256 adjustedDesiredWidth = _desired_width;
1257 adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
1261 adjustedDesiredWidth = imageSize.Width * _desired_height/ imageSize.Height;
1262 adjustedDesiredHeight = _desired_height;
1265 PropertyValue returnWidth = new PropertyValue(adjustedDesiredWidth);
1266 imageMap?.Insert(ImageVisualProperty.DesiredWidth, returnWidth);
1267 returnWidth?.Dispose();
1268 PropertyValue returnHeight = new PropertyValue(adjustedDesiredHeight);
1269 imageMap?.Insert(ImageVisualProperty.DesiredHeight, returnHeight);
1270 returnHeight?.Dispose();
1271 PropertyValue scaleToFit = new PropertyValue((int)FittingModeType.ScaleToFill);
1272 imageMap?.Insert(ImageVisualProperty.FittingMode, scaleToFit);
1273 scaleToFit?.Dispose();
1277 UpdateImageMap(imageMap);
1279 imageMap?.Dispose();
1284 private void OnResourceLoaded(IntPtr view)
1286 ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1287 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1289 if (_resourceLoadedEventHandler != null)
1291 _resourceLoadedEventHandler(this, e);
1296 /// Event arguments of resource ready.
1298 /// <since_tizen> 3 </since_tizen>
1299 public class ResourceReadyEventArgs : EventArgs
1304 /// The view whose resource is ready.
1306 /// <since_tizen> 3 </since_tizen>
1320 internal class ResourceLoadedEventArgs : EventArgs
1322 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1323 public ResourceLoadingStatusType Status
1336 internal new class Property
1338 internal static readonly int IMAGE = Interop.ImageView.ImageGet();
1339 internal static readonly int PreMultipliedAlpha = Interop.ImageView.PreMultipliedAlphaGet();
1340 internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet();
1341 internal static readonly int ActionReload = Interop.ImageView.ImageVisualActionReloadGet();
1342 internal static readonly int ActionPlay = Interop.ImageView.ImageVisualActionPlayGet();
1343 internal static readonly int ActionPause = Interop.ImageView.ImageVisualActionPauseGet();
1344 internal static readonly int ActionStop = Interop.ImageView.ImageVisualActionStopGet();
1347 private enum ImageType
1350 /// For Normal Image.
1355 /// For normal image, with synchronous loading and orientation correction property
1360 /// For nine-patch image
1365 private void OnBorderChanged(int x, int y, int width, int height)
1367 Border = new Rectangle(x, y, width, height);
1369 private void OnPixelAreaChanged(float x, float y, float z, float w)
1371 PixelArea = new RelativeVector4(x, y, z, w);