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;
40 if (newValue is Selector<string> selector)
42 imageView.ResourceUrlSelector = selector;
46 imageView.resourceUrlSelector?.Reset(imageView);
47 imageView.SetResourceUrl((string)newValue);
50 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
52 var imageView = (ImageView)bindable;
55 PropertyMap imageMap = new PropertyMap();
56 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
57 imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
61 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
65 var imageView = (ImageView)bindable;
68 PropertyMap map = (PropertyMap)newValue;
69 if (imageView.IsCreateByXaml)
71 string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
72 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
73 PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
75 if (urlValue != null) ret = urlValue.Get(out url);
76 PropertyMap mmap = new PropertyMap();
77 if (ret && url.StartsWith("*Resource*"))
79 url = url.Replace("*Resource*", resource);
80 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
84 PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
85 if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
86 if (ret && alphaMaskURL.StartsWith("*Resource*"))
88 alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
89 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
93 PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
94 if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
95 if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
97 auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
98 mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
103 if (imageView._border == null)
105 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
109 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
111 var imageView = (ImageView)bindable;
112 if (imageView._border == null)
114 PropertyMap temp = new PropertyMap();
115 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
124 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
128 var imageView = (ImageView)bindable;
129 if (newValue != null)
131 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
134 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
136 var imageView = (ImageView)bindable;
138 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
142 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
146 var imageView = (ImageView)bindable;
147 if (newValue != null)
149 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
152 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
154 var imageView = (ImageView)bindable;
155 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
156 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
157 RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
161 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
162 [EditorBrowsable(EditorBrowsableState.Never)]
163 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
165 var imageView = (ImageView)bindable;
166 imageView.borderSelector?.Reset(imageView);
168 if (newValue is Selector<Rectangle> selector)
170 if (selector.HasAll()) imageView.SetBorder(selector.All);
171 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
175 imageView.SetBorder((Rectangle)newValue);
178 defaultValueCreator: (bindable) =>
180 var imageView = (ImageView)bindable;
181 return imageView._border;
184 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
185 [EditorBrowsable(EditorBrowsableState.Never)]
186 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
188 var imageView = (ImageView)bindable;
189 if (newValue != null)
191 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
194 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
196 var imageView = (ImageView)bindable;
198 PropertyMap imageMap = new PropertyMap();
199 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
200 imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
204 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
205 [EditorBrowsable(EditorBrowsableState.Never)]
206 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronosLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
208 var imageView = (ImageView)bindable;
209 if (newValue != null)
211 imageView._synchronosLoading = (bool)newValue;
212 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
215 defaultValueCreator: (bindable) =>
217 var imageView = (ImageView)bindable;
218 return imageView._synchronosLoading;
221 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
225 var imageView = (ImageView)bindable;
226 if (newValue != null)
228 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
231 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
233 var imageView = (ImageView)bindable;
236 PropertyMap imageMap = new PropertyMap();
237 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
238 imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
243 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
244 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
245 private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
246 private _resourceLoadedCallbackType _resourceLoadedCallback;
248 private Rectangle _border;
249 private string _resourceUrl = "";
250 private bool _synchronosLoading = false;
251 private string _alphaMaskUrl = null;
252 private int _desired_width = -1;
253 private int _desired_height = -1;
254 private VisualFittingModeType _fittingMode = VisualFittingModeType.Fill;
255 private TriggerableSelector<string> resourceUrlSelector;
256 private TriggerableSelector<Rectangle> borderSelector;
259 /// Creates an initialized ImageView.
261 /// <since_tizen> 3 </since_tizen>
262 public ImageView() : this(Interop.ImageView.New(), true)
264 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.New(), true, viewStyle)
274 /// Creates an initialized ImageView with setting the status of shown or hidden.
276 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
277 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public ImageView(bool shown) : this(Interop.ImageView.New(), true)
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Creates an initialized ImageView from a URL to an image resource.<br />
287 /// If the string is empty, ImageView will not display anything.<br />
289 /// <param name="url">The URL of the image resource to display.</param>
290 /// <since_tizen> 3 </since_tizen>
291 public ImageView(string url) : this(Interop.ImageView.New(url), true)
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
301 /// <param name="url">The URL of the image resource to display.</param>
302 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
303 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
304 [EditorBrowsable(EditorBrowsableState.Never)]
305 public ImageView(string url, bool shown) : this(Interop.ImageView.New(url), true)
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.New(url, Uint16Pair.getCPtr(size)), true)
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
331 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
339 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
340 private delegate void ResourceReadyEventCallbackType(IntPtr data);
341 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
342 private delegate void _resourceLoadedCallbackType(IntPtr view);
345 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
346 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
347 /// Most resources are only loaded when the control is placed on the stage.<br />
349 /// <since_tizen> 3 </since_tizen>
350 public event EventHandler<ResourceReadyEventArgs> ResourceReady
354 if (_resourceReadyEventHandler == null)
356 _resourceReadyEventCallback = OnResourceReady;
357 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
358 resourceReadySignal?.Connect(_resourceReadyEventCallback);
359 resourceReadySignal?.Dispose();
362 _resourceReadyEventHandler += value;
367 _resourceReadyEventHandler -= value;
369 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
370 if (_resourceReadyEventHandler == null && resourceReadySignal?.Empty() == false)
372 resourceReadySignal?.Disconnect(_resourceReadyEventCallback);
374 resourceReadySignal?.Dispose();
378 internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
382 if (_resourceLoadedEventHandler == null)
384 _resourceLoadedCallback = OnResourceLoaded;
385 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
386 resourceReadySignal?.Connect(_resourceLoadedCallback);
387 resourceReadySignal?.Dispose();
390 _resourceLoadedEventHandler += value;
394 _resourceLoadedEventHandler -= value;
395 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
396 if (_resourceLoadedEventHandler == null && resourceReadySignal?.Empty() == false)
398 resourceReadySignal?.Disconnect(_resourceLoadedCallback);
400 resourceReadySignal?.Dispose();
405 /// Enumeration for LoadingStatus of image.
407 /// <since_tizen> 5 </since_tizen>
408 public enum LoadingStatusType
411 /// Loading preparing status.
413 /// <since_tizen> 5 </since_tizen>
416 /// Loading ready status.
418 /// <since_tizen> 5 </since_tizen>
421 /// Loading failed status.
423 /// <since_tizen> 5 </since_tizen>
428 /// ImageView ResourceUrl, type string.
429 /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
430 /// When it is set as null, it gives empty string ("") to be read.
432 /// <since_tizen> 3 </since_tizen>
433 public string ResourceUrl
437 return (string)GetValue(ResourceUrlProperty);
441 SetValue(ResourceUrlProperty, value);
442 NotifyPropertyChanged();
447 /// This will be deprecated, please use Image instead. <br />
448 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
450 /// <since_tizen> 3 </since_tizen>
451 [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
452 [EditorBrowsable(EditorBrowsableState.Never)]
453 public PropertyMap ImageMap
459 PropertyMap returnValue = new PropertyMap();
460 PropertyValue image = GetProperty(ImageView.Property.IMAGE);
461 image?.Get(returnValue);
474 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
475 SetProperty(ImageView.Property.IMAGE, setValue);
476 NotifyPropertyChanged();
483 /// ImageView Image, type PropertyMap
485 /// <since_tizen> 4 </since_tizen>
486 public PropertyMap Image
492 return (PropertyMap)GetValue(ImageProperty);
503 SetValue(ImageProperty, value);
504 NotifyPropertyChanged();
510 /// ImageView PreMultipliedAlpha, type Boolean.<br />
511 /// Image must be initialized.<br />
513 /// <since_tizen> 3 </since_tizen>
514 public bool PreMultipliedAlpha
518 return (bool)GetValue(PreMultipliedAlphaProperty);
522 SetValue(PreMultipliedAlphaProperty, value);
523 NotifyPropertyChanged();
528 /// ImageView PixelArea, type Vector4 (Animatable property).<br />
529 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
532 /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
534 /// <since_tizen> 3 </since_tizen>
535 public RelativeVector4 PixelArea
539 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
540 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
544 SetValue(PixelAreaProperty, value);
545 NotifyPropertyChanged();
550 /// The border of the image in the order: left, right, bottom, top.<br />
551 /// If set, ImageMap will be ignored.<br />
552 /// For N-Patch images only.<br />
556 /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
558 /// <since_tizen> 3 </since_tizen>
559 public Rectangle Border
563 Rectangle temp = (Rectangle)GetValue(BorderProperty);
570 return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
575 SetValue(BorderProperty, value);
576 NotifyPropertyChanged();
581 /// Gets or sets whether to draw the borders only (if true).<br />
582 /// If not specified, the default is false.<br />
583 /// For N-Patch images only.<br />
586 /// <since_tizen> 3 </since_tizen>
587 public bool BorderOnly
591 return (bool)GetValue(BorderOnlyProperty);
595 SetValue(BorderOnlyProperty, value);
596 NotifyPropertyChanged();
601 /// Gets or sets whether to synchronous loading the resourceurl of image.<br />
603 /// <since_tizen> 3 </since_tizen>
604 public bool SynchronosLoading
608 return (bool)GetValue(SynchronosLoadingProperty);
612 SetValue(SynchronosLoadingProperty, value);
613 NotifyPropertyChanged();
618 /// Gets or sets whether to automatically correct the orientation of an image.<br />
620 /// <since_tizen> 5 </since_tizen>
621 public bool OrientationCorrection
625 return (bool)GetValue(OrientationCorrectionProperty);
629 SetValue(OrientationCorrectionProperty, value);
630 NotifyPropertyChanged();
635 /// Gets the loading state of the visual resource.
637 /// <since_tizen> 5 </since_tizen>
638 public ImageView.LoadingStatusType LoadingStatus
642 return (ImageView.LoadingStatusType)Interop.View.GetVisualResourceStatus(SwigCPtr, (int)Property.IMAGE);
647 /// Downcasts a handle to imageView handle.
649 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
650 /// Please do not use! this will be deprecated!
651 /// Instead please use as keyword.
652 /// <since_tizen> 3 </since_tizen>
653 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
655 "BaseHandle handle = new ImageView(imagePath); " +
656 "ImageView image = handle as ImageView")]
657 [EditorBrowsable(EditorBrowsableState.Never)]
658 public static ImageView DownCast(BaseHandle handle)
662 throw new ArgumentNullException(nameof(handle));
664 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
665 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
670 /// Sets this ImageView from the given URL.<br />
671 /// If the URL is empty, ImageView will not display anything.<br />
673 /// <param name="url">The URL to the image resource to display.</param>
674 /// <exception cref="ArgumentNullException"> Thrown when url is null. </exception>
675 /// <since_tizen> 3 </since_tizen>
676 public void SetImage(string url)
680 throw new ArgumentNullException(nameof(url));
683 if (url.Contains(".json"))
685 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
689 Interop.ImageView.SetImage(SwigCPtr, url);
690 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
696 /// Queries if all resources required by a control are loaded and ready.<br />
697 /// Most resources are only loaded when the control is placed on the stage.<br />
698 /// True if the resources are loaded and ready, false otherwise.<br />
700 /// <since_tizen> 3 </since_tizen>
701 public new bool IsResourceReady()
703 bool ret = Interop.View.IsResourceReady(SwigCPtr);
704 if (NDalicPINVOKE.SWIGPendingException.Pending)
705 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
710 /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
712 /// <since_tizen> 5 </since_tizen>
715 PropertyValue attributes = new PropertyValue(0);
716 this.DoAction(ImageView.Property.IMAGE, Property.ActionReload, attributes);
717 attributes?.Dispose();
721 /// Plays the animated GIF. This is also the default playback mode.
723 /// <since_tizen> 5 </since_tizen>
726 PropertyValue attributes = new PropertyValue(0);
727 this.DoAction(ImageView.Property.IMAGE, Property.ActionPlay, attributes);
728 attributes?.Dispose();
732 /// Pauses the animated GIF.
734 /// <since_tizen> 5 </since_tizen>
737 PropertyValue attributes = new PropertyValue(0);
738 this.DoAction(ImageView.Property.IMAGE, Property.ActionPause, attributes);
739 attributes?.Dispose();
743 /// Stops the animated GIF.
745 /// <since_tizen> 5 </since_tizen>
748 PropertyValue attributes = new PropertyValue(0);
749 this.DoAction(ImageView.Property.IMAGE, Property.ActionStop, attributes);
750 attributes?.Dispose();
754 /// Gets or sets the URL of the alpha mask.<br />
757 /// <since_tizen> 6</since_tizen>
758 [EditorBrowsable(EditorBrowsableState.Never)]
759 public string AlphaMaskURL
764 PropertyMap imageMap = new PropertyMap();
765 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
766 image?.Get(imageMap);
767 PropertyValue maskUrl = imageMap?.Find(ImageVisualProperty.AlphaMaskURL);
768 maskUrl?.Get(out ret);
784 _alphaMaskUrl = value;
786 PropertyValue setValue = new PropertyValue(value);
787 UpdateImage(ImageVisualProperty.AlphaMaskURL, setValue);
794 /// Whether to crop image to mask or scale mask to fit image.
796 /// <since_tizen> 6 </since_tizen>
797 public bool CropToMask
802 PropertyMap imageMap = new PropertyMap();
803 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
804 image?.Get(imageMap);
805 PropertyValue cropUrl = imageMap?.Find(ImageVisualProperty.CropToMask);
806 cropUrl?.Get(out ret);
816 PropertyValue setValue = new PropertyValue(value);
817 UpdateImage(ImageVisualProperty.CropToMask, setValue);
822 internal VisualFittingModeType CovertFittingModetoVisualFittingMode(FittingModeType value)
826 case FittingModeType.ShrinkToFit:
827 return VisualFittingModeType.FitKeepAspectRatio;
828 case FittingModeType.ScaleToFill:
829 return VisualFittingModeType.OverFitKeepAspectRatio;
830 case FittingModeType.Center:
831 return VisualFittingModeType.Center;
832 case FittingModeType.Fill:
833 return VisualFittingModeType.Fill;
834 case FittingModeType.FitHeight:
835 return VisualFittingModeType.FitHeight;
836 case FittingModeType.FitWidth:
837 return VisualFittingModeType.FitHeight;
839 return VisualFittingModeType.Fill;
843 internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
847 case VisualFittingModeType.FitKeepAspectRatio:
848 return FittingModeType.ShrinkToFit;
849 case VisualFittingModeType.OverFitKeepAspectRatio:
850 return FittingModeType.ScaleToFill;
851 case VisualFittingModeType.Center:
852 return FittingModeType.Center;
853 case VisualFittingModeType.Fill:
854 return FittingModeType.Fill;
855 case VisualFittingModeType.FitHeight:
856 return FittingModeType.FitHeight;
857 case VisualFittingModeType.FitWidth:
858 return FittingModeType.FitWidth;
860 return FittingModeType.ShrinkToFit;
865 /// Gets or sets fitting options used when resizing images to fit.<br />
866 /// If not supplied, the default is FittingModeType.Fill.<br />
867 /// For normal quad images only.<br />
870 /// <since_tizen> 6 </since_tizen>
871 [EditorBrowsable(EditorBrowsableState.Never)]
872 public FittingModeType FittingMode
876 int ret = (int)_fittingMode;
877 PropertyMap imageMap = new PropertyMap();
878 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
879 image?.Get(imageMap);
880 PropertyValue fittingMode = imageMap?.Find(Visual.Property.VisualFittingMode);
881 fittingMode?.Get(out ret);
882 _fittingMode = (VisualFittingModeType)ret;
886 fittingMode?.Dispose();
888 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
892 VisualFittingModeType ret = CovertFittingModetoVisualFittingMode(value);
894 PropertyValue setValue = new PropertyValue((int)ret);
895 UpdateImage(Visual.Property.VisualFittingMode, setValue);
903 /// Gets or sets the desired image width.<br />
904 /// If not specified, the actual image width is used.<br />
905 /// For normal quad images only.<br />
908 /// <since_tizen> 6 </since_tizen>
909 [EditorBrowsable(EditorBrowsableState.Never)]
910 public int DesiredWidth
914 PropertyMap imageMap = new PropertyMap();
915 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
916 image?.Get(imageMap);
917 PropertyValue desireWidth = imageMap?.Find(ImageVisualProperty.DesiredWidth);
918 desireWidth?.Get(out _desired_width);
922 desireWidth?.Dispose();
924 return _desired_width;
928 if (_desired_width != value)
930 _desired_width = value;
931 UpdateImage(0, null);
937 /// Gets or sets the desired image height.<br />
938 /// If not specified, the actual image height is used.<br />
939 /// For normal quad images only.<br />
942 /// <since_tizen> 6 </since_tizen>
943 [EditorBrowsable(EditorBrowsableState.Never)]
944 public int DesiredHeight
948 PropertyMap imageMap = new PropertyMap();
949 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
950 image?.Get(imageMap);
951 PropertyValue desireheight = imageMap?.Find(ImageVisualProperty.DesiredHeight);
952 desireheight?.Get(out _desired_height);
956 desireheight?.Dispose();
958 return _desired_height;
962 if (_desired_height != value)
964 _desired_height = value;
965 UpdateImage(0, null);
971 /// Gets or sets ReleasePolicy for image.<br />
972 /// If not supplied, the default is ReleasePolicyType.Detached.<br />
974 [EditorBrowsable(EditorBrowsableState.Never)]
975 public ReleasePolicyType ReleasePolicy
979 int ret = (int)ReleasePolicyType.Detached;
980 PropertyMap imageMap = new PropertyMap();
981 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
982 image?.Get(imageMap);
983 PropertyValue releasePoli = imageMap?.Find(ImageVisualProperty.ReleasePolicy);
984 releasePoli?.Get(out ret);
988 releasePoli?.Dispose();
990 return (ReleasePolicyType)ret;
994 PropertyValue setValue = new PropertyValue((int)value);
995 UpdateImage(ImageVisualProperty.ReleasePolicy, setValue);
1001 /// Gets or sets the wrap mode for the u coordinate.<br />
1002 /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
1003 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1004 /// For normal quad images only.<br />
1007 /// <since_tizen> 6 </since_tizen>
1008 [EditorBrowsable(EditorBrowsableState.Never)]
1009 public WrapModeType WrapModeU
1013 int ret = (int)WrapModeType.Default;
1014 PropertyMap imageMap = new PropertyMap();
1015 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1016 image?.Get(imageMap);
1017 PropertyValue warpModeU = imageMap?.Find(ImageVisualProperty.WrapModeU);
1018 warpModeU?.Get(out ret);
1020 imageMap?.Dispose();
1022 warpModeU?.Dispose();
1024 return (WrapModeType)ret;
1028 PropertyValue setValue = new PropertyValue((int)value);
1029 UpdateImage(ImageVisualProperty.WrapModeU, setValue);
1030 setValue?.Dispose();
1035 /// Gets or sets the wrap mode for the v coordinate.<br />
1036 /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
1037 /// 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 />
1038 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1039 /// For normal quad images only.
1042 /// <since_tizen> 6 </since_tizen>
1043 [EditorBrowsable(EditorBrowsableState.Never)]
1044 public WrapModeType WrapModeV
1048 int ret = (int)WrapModeType.Default;
1049 PropertyMap imageMap = new PropertyMap();
1050 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1051 image?.Get(imageMap);
1052 PropertyValue wrapModeV = imageMap?.Find(ImageVisualProperty.WrapModeV);
1053 wrapModeV?.Get(out ret);
1055 imageMap?.Dispose();
1057 wrapModeV?.Dispose();
1059 return (WrapModeType)ret;
1063 PropertyValue setValue = new PropertyValue((int)value);
1064 UpdateImage(ImageVisualProperty.WrapModeV, setValue);
1065 setValue?.Dispose();
1069 internal Selector<string> ResourceUrlSelector
1071 get => GetSelector<string>(resourceUrlSelector, ImageView.ResourceUrlProperty);
1074 resourceUrlSelector?.Reset(this);
1075 if (value == null) return;
1077 if (value.HasAll()) SetResourceUrl(value.All);
1078 else resourceUrlSelector = new TriggerableSelector<string>(this, value, SetResourceUrl, true);
1083 /// Get attributes, it is abstract function and must be override.
1085 [EditorBrowsable(EditorBrowsableState.Never)]
1086 protected override ViewStyle CreateViewStyle()
1088 return new ImageViewStyle();
1091 internal void SetImage(string url, Uint16Pair size)
1093 if (url.Contains(".json"))
1095 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
1099 Interop.ImageView.SetImage(SwigCPtr, url, Uint16Pair.getCPtr(size));
1100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1105 internal ViewResourceReadySignal ResourceReadySignal(View view)
1107 ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
1108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1112 internal override void ApplyCornerRadius()
1114 base.ApplyCornerRadius();
1116 UpdateImage(0, null);
1119 internal ResourceLoadingStatusType GetResourceStatus()
1121 return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1125 /// you can override it to clean-up your own resources.
1127 /// <param name="type">DisposeTypes</param>
1128 /// <since_tizen> 3 </since_tizen>
1129 protected override void Dispose(DisposeTypes type)
1136 if (type == DisposeTypes.Explicit)
1139 //Release your own managed resources here.
1140 //You should release all of your own disposable objects here.
1143 borderSelector?.Reset(this);
1144 resourceUrlSelector?.Reset(this);
1150 /// This will not be public opened.
1151 [EditorBrowsable(EditorBrowsableState.Never)]
1152 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1154 Interop.ImageView.DeleteImageView(swigCPtr);
1157 // Callback for View ResourceReady signal
1158 private void OnResourceReady(IntPtr data)
1160 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1163 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1166 if (_resourceReadyEventHandler != null)
1168 _resourceReadyEventHandler(this, e);
1172 private void SetResourceUrl(string value)
1174 value = (value == null ? "" : value);
1175 if (value.StartsWith("*Resource*"))
1177 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
1178 value = value.Replace("*Resource*", resource);
1180 _resourceUrl = value;
1181 UpdateImage(ImageVisualProperty.URL, new PropertyValue(value));
1184 private void SetBorder(Rectangle value)
1190 _border = new Rectangle(value);
1191 UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1194 private void UpdateImageMap(PropertyMap fromMap)
1196 PropertyMap imageMap = new PropertyMap();
1198 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1199 image?.Get(imageMap);
1200 imageMap?.Merge(fromMap);
1201 PropertyValue setValue = new PropertyValue(imageMap);
1202 SetProperty(ImageView.Property.IMAGE, setValue);
1204 imageMap?.Dispose();
1206 setValue?.Dispose();
1209 private void UpdateImage(int key, PropertyValue value)
1211 PropertyMap imageMap = new PropertyMap();
1213 if (_alphaMaskUrl != null)
1215 PropertyValue alphaMaskUrl = new PropertyValue(_alphaMaskUrl);
1216 imageMap?.Insert(ImageVisualProperty.AlphaMaskURL, alphaMaskUrl);
1217 alphaMaskUrl?.Dispose();
1220 if (string.IsNullOrEmpty(_resourceUrl))
1222 PropertyValue resourceUrl = new PropertyValue(_resourceUrl);
1223 imageMap?.Insert(ImageVisualProperty.URL, resourceUrl);
1224 PropertyValue setValue = new PropertyValue(imageMap);
1225 SetProperty(ImageView.Property.IMAGE, setValue);
1226 resourceUrl?.Dispose();
1227 setValue?.Dispose();
1231 if (_border == null)
1233 PropertyValue image = new PropertyValue((int)Visual.Type.Image);
1234 imageMap?.Insert(Visual.Property.Type, image);
1239 PropertyValue nPatch = new PropertyValue((int)Visual.Type.NPatch);
1240 imageMap?.Insert(Visual.Property.Type, nPatch);
1242 PropertyValue border = new PropertyValue(_border);
1243 imageMap?.Insert(NpatchImageVisualProperty.Border, border);
1247 if(key != Visual.Property.VisualFittingMode && _fittingMode != VisualFittingModeType.Fill)
1249 PropertyValue fittingMode = new PropertyValue((int)_fittingMode);
1250 imageMap?.Insert(Visual.Property.VisualFittingMode, fittingMode);
1251 fittingMode?.Dispose();
1254 PropertyValue synchronosLoading = new PropertyValue(_synchronosLoading);
1255 imageMap?.Insert(NpatchImageVisualProperty.SynchronousLoading, synchronosLoading);
1256 synchronosLoading?.Dispose();
1258 if (backgroundExtraData != null && backgroundExtraData.CornerRadius != null)
1260 using (var cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius))
1261 using (var cornerRadiusPolicy = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy))
1263 imageMap.Insert(Visual.Property.CornerRadius, cornerRadius);
1264 imageMap.Insert(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(backgroundExtraData.CornerRadiusPolicy)));
1270 imageMap?.Insert(key, value);
1273 // Do Fitting Buffer when desired dimension is set
1274 if (_desired_width != -1 && _desired_height != -1)
1276 if (_resourceUrl != null)
1278 Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl, true);
1280 int adjustedDesiredWidth, adjustedDesiredHeight;
1281 float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
1282 float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
1283 if (aspectOfImageSize > aspectOfDesiredSize)
1285 adjustedDesiredWidth = _desired_width;
1286 adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
1290 adjustedDesiredWidth = imageSize.Width * _desired_height / imageSize.Height;
1291 adjustedDesiredHeight = _desired_height;
1294 PropertyValue returnWidth = new PropertyValue(adjustedDesiredWidth);
1295 imageMap?.Insert(ImageVisualProperty.DesiredWidth, returnWidth);
1296 returnWidth?.Dispose();
1297 PropertyValue returnHeight = new PropertyValue(adjustedDesiredHeight);
1298 imageMap?.Insert(ImageVisualProperty.DesiredHeight, returnHeight);
1299 returnHeight?.Dispose();
1300 PropertyValue scaleToFit = new PropertyValue((int)FittingModeType.ScaleToFill);
1301 imageMap?.Insert(ImageVisualProperty.FittingMode, scaleToFit);
1302 scaleToFit?.Dispose();
1306 UpdateImageMap(imageMap);
1308 imageMap?.Dispose();
1313 private void OnResourceLoaded(IntPtr view)
1315 ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1316 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1318 if (_resourceLoadedEventHandler != null)
1320 _resourceLoadedEventHandler(this, e);
1325 /// Event arguments of resource ready.
1327 /// <since_tizen> 3 </since_tizen>
1328 public class ResourceReadyEventArgs : EventArgs
1333 /// The view whose resource is ready.
1335 /// <since_tizen> 3 </since_tizen>
1349 internal class ResourceLoadedEventArgs : EventArgs
1351 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1352 public ResourceLoadingStatusType Status
1365 internal new class Property
1367 internal static readonly int IMAGE = Interop.ImageView.ImageGet();
1368 internal static readonly int PreMultipliedAlpha = Interop.ImageView.PreMultipliedAlphaGet();
1369 internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet();
1370 internal static readonly int ActionReload = Interop.ImageView.ImageVisualActionReloadGet();
1371 internal static readonly int ActionPlay = Interop.ImageView.ImageVisualActionPlayGet();
1372 internal static readonly int ActionPause = Interop.ImageView.ImageVisualActionPauseGet();
1373 internal static readonly int ActionStop = Interop.ImageView.ImageVisualActionStopGet();
1376 private enum ImageType
1379 /// For Normal Image.
1384 /// For normal image, with synchronous loading and orientation correction property
1389 /// For nine-patch image
1394 private void OnBorderChanged(int x, int y, int width, int height)
1396 Border = new Rectangle(x, y, width, height);
1398 private void OnPixelAreaChanged(float x, float y, float z, float w)
1400 PixelArea = new RelativeVector4(x, y, z, w);