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);
893 PropertyValue setValue = new PropertyValue((int)ret);
894 if(_fittingMode != ret)
897 UpdateImage(Visual.Property.VisualFittingMode, setValue);
906 /// Gets or sets the desired image width.<br />
907 /// If not specified, the actual image width is used.<br />
908 /// For normal quad images only.<br />
911 /// <since_tizen> 6 </since_tizen>
912 [EditorBrowsable(EditorBrowsableState.Never)]
913 public int DesiredWidth
917 PropertyMap imageMap = new PropertyMap();
918 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
919 image?.Get(imageMap);
920 PropertyValue desireWidth = imageMap?.Find(ImageVisualProperty.DesiredWidth);
921 desireWidth?.Get(out _desired_width);
925 desireWidth?.Dispose();
927 return _desired_width;
931 if (_desired_width != value)
933 _desired_width = value;
934 UpdateImage(0, null);
940 /// Gets or sets the desired image height.<br />
941 /// If not specified, the actual image height is used.<br />
942 /// For normal quad images only.<br />
945 /// <since_tizen> 6 </since_tizen>
946 [EditorBrowsable(EditorBrowsableState.Never)]
947 public int DesiredHeight
951 PropertyMap imageMap = new PropertyMap();
952 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
953 image?.Get(imageMap);
954 PropertyValue desireheight = imageMap?.Find(ImageVisualProperty.DesiredHeight);
955 desireheight?.Get(out _desired_height);
959 desireheight?.Dispose();
961 return _desired_height;
965 if (_desired_height != value)
967 _desired_height = value;
968 UpdateImage(0, null);
974 /// Gets or sets ReleasePolicy for image.<br />
975 /// If not supplied, the default is ReleasePolicyType.Detached.<br />
977 [EditorBrowsable(EditorBrowsableState.Never)]
978 public ReleasePolicyType ReleasePolicy
982 int ret = (int)ReleasePolicyType.Detached;
983 PropertyMap imageMap = new PropertyMap();
984 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
985 image?.Get(imageMap);
986 PropertyValue releasePoli = imageMap?.Find(ImageVisualProperty.ReleasePolicy);
987 releasePoli?.Get(out ret);
991 releasePoli?.Dispose();
993 return (ReleasePolicyType)ret;
997 PropertyValue setValue = new PropertyValue((int)value);
998 UpdateImage(ImageVisualProperty.ReleasePolicy, setValue);
1004 /// Gets or sets the wrap mode for the u coordinate.<br />
1005 /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
1006 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1007 /// For normal quad images only.<br />
1010 /// <since_tizen> 6 </since_tizen>
1011 [EditorBrowsable(EditorBrowsableState.Never)]
1012 public WrapModeType WrapModeU
1016 int ret = (int)WrapModeType.Default;
1017 PropertyMap imageMap = new PropertyMap();
1018 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1019 image?.Get(imageMap);
1020 PropertyValue warpModeU = imageMap?.Find(ImageVisualProperty.WrapModeU);
1021 warpModeU?.Get(out ret);
1023 imageMap?.Dispose();
1025 warpModeU?.Dispose();
1027 return (WrapModeType)ret;
1031 PropertyValue setValue = new PropertyValue((int)value);
1032 UpdateImage(ImageVisualProperty.WrapModeU, setValue);
1033 setValue?.Dispose();
1038 /// Gets or sets the wrap mode for the v coordinate.<br />
1039 /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
1040 /// 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 />
1041 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1042 /// For normal quad images only.
1045 /// <since_tizen> 6 </since_tizen>
1046 [EditorBrowsable(EditorBrowsableState.Never)]
1047 public WrapModeType WrapModeV
1051 int ret = (int)WrapModeType.Default;
1052 PropertyMap imageMap = new PropertyMap();
1053 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1054 image?.Get(imageMap);
1055 PropertyValue wrapModeV = imageMap?.Find(ImageVisualProperty.WrapModeV);
1056 wrapModeV?.Get(out ret);
1058 imageMap?.Dispose();
1060 wrapModeV?.Dispose();
1062 return (WrapModeType)ret;
1066 PropertyValue setValue = new PropertyValue((int)value);
1067 UpdateImage(ImageVisualProperty.WrapModeV, setValue);
1068 setValue?.Dispose();
1072 internal Selector<string> ResourceUrlSelector
1074 get => GetSelector<string>(resourceUrlSelector, ImageView.ResourceUrlProperty);
1077 resourceUrlSelector?.Reset(this);
1078 if (value == null) return;
1080 if (value.HasAll()) SetResourceUrl(value.All);
1081 else resourceUrlSelector = new TriggerableSelector<string>(this, value, SetResourceUrl, true);
1086 /// Get attributes, it is abstract function and must be override.
1088 [EditorBrowsable(EditorBrowsableState.Never)]
1089 protected override ViewStyle CreateViewStyle()
1091 return new ImageViewStyle();
1094 internal void SetImage(string url, Uint16Pair size)
1096 if (url.Contains(".json"))
1098 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
1102 Interop.ImageView.SetImage(SwigCPtr, url, Uint16Pair.getCPtr(size));
1103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1108 internal ViewResourceReadySignal ResourceReadySignal(View view)
1110 ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
1111 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1115 internal override void ApplyCornerRadius()
1117 base.ApplyCornerRadius();
1119 UpdateImage(0, null);
1122 internal override void ApplyBorderline()
1124 base.ApplyBorderline();
1126 // Apply borderline to IMAGE.
1127 if (backgroundExtraData != null)
1129 var borderlineColor = backgroundExtraData.BorderlineColor == null ? new PropertyValue(Color.Black) : new PropertyValue(backgroundExtraData.BorderlineColor);
1131 // Apply to the image visual
1132 PropertyMap imageMap = new PropertyMap();
1133 PropertyValue imageValue = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1134 if (imageValue.Get(imageMap) && !imageMap.Empty())
1136 imageMap[Visual.Property.BorderlineWidth] = new PropertyValue(backgroundExtraData.BorderlineWidth);
1137 imageMap[Visual.Property.BorderlineColor] = borderlineColor;
1138 imageMap[Visual.Property.BorderlineOffset] = new PropertyValue(backgroundExtraData.BorderlineOffset);
1139 var temp = new PropertyValue(imageMap);
1140 Tizen.NUI.Object.SetProperty(SwigCPtr, ImageView.Property.IMAGE, temp);
1144 imageValue.Dispose();
1145 borderlineColor.Dispose();
1148 UpdateImage(0, null);
1151 internal ResourceLoadingStatusType GetResourceStatus()
1153 return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1157 /// you can override it to clean-up your own resources.
1159 /// <param name="type">DisposeTypes</param>
1160 /// <since_tizen> 3 </since_tizen>
1161 protected override void Dispose(DisposeTypes type)
1168 if (type == DisposeTypes.Explicit)
1171 //Release your own managed resources here.
1172 //You should release all of your own disposable objects here.
1175 borderSelector?.Reset(this);
1176 resourceUrlSelector?.Reset(this);
1182 /// This will not be public opened.
1183 [EditorBrowsable(EditorBrowsableState.Never)]
1184 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1186 Interop.ImageView.DeleteImageView(swigCPtr);
1189 // Callback for View ResourceReady signal
1190 private void OnResourceReady(IntPtr data)
1192 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1195 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1198 if (_resourceReadyEventHandler != null)
1200 _resourceReadyEventHandler(this, e);
1204 private void SetResourceUrl(string value)
1206 value = (value == null ? "" : value);
1207 if (value.StartsWith("*Resource*"))
1209 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
1210 value = value.Replace("*Resource*", resource);
1212 _resourceUrl = value;
1213 UpdateImage(ImageVisualProperty.URL, new PropertyValue(value));
1216 private void SetBorder(Rectangle value)
1222 _border = new Rectangle(value);
1223 UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1226 private void UpdateImageMap(PropertyMap fromMap)
1228 PropertyMap imageMap = new PropertyMap();
1230 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1231 image?.Get(imageMap);
1232 imageMap?.Merge(fromMap);
1233 PropertyValue setValue = new PropertyValue(imageMap);
1234 SetProperty(ImageView.Property.IMAGE, setValue);
1236 imageMap?.Dispose();
1238 setValue?.Dispose();
1241 private void UpdateImage(int key, PropertyValue value)
1243 PropertyMap imageMap = new PropertyMap();
1245 if (_alphaMaskUrl != null)
1247 PropertyValue alphaMaskUrl = new PropertyValue(_alphaMaskUrl);
1248 imageMap?.Insert(ImageVisualProperty.AlphaMaskURL, alphaMaskUrl);
1249 alphaMaskUrl?.Dispose();
1252 if (string.IsNullOrEmpty(_resourceUrl))
1254 PropertyValue resourceUrl = new PropertyValue(_resourceUrl);
1255 imageMap?.Insert(ImageVisualProperty.URL, resourceUrl);
1256 PropertyValue setValue = new PropertyValue(imageMap);
1257 SetProperty(ImageView.Property.IMAGE, setValue);
1258 resourceUrl?.Dispose();
1259 setValue?.Dispose();
1263 if (_border == null)
1265 PropertyValue image = new PropertyValue((int)Visual.Type.Image);
1266 imageMap?.Insert(Visual.Property.Type, image);
1271 PropertyValue nPatch = new PropertyValue((int)Visual.Type.NPatch);
1272 imageMap?.Insert(Visual.Property.Type, nPatch);
1274 PropertyValue border = new PropertyValue(_border);
1275 imageMap?.Insert(NpatchImageVisualProperty.Border, border);
1279 if(key != Visual.Property.VisualFittingMode && _fittingMode != VisualFittingModeType.Fill)
1281 PropertyValue fittingMode = new PropertyValue((int)_fittingMode);
1282 imageMap?.Insert(Visual.Property.VisualFittingMode, fittingMode);
1283 fittingMode?.Dispose();
1286 PropertyValue synchronosLoading = new PropertyValue(_synchronosLoading);
1287 imageMap?.Insert(NpatchImageVisualProperty.SynchronousLoading, synchronosLoading);
1288 synchronosLoading?.Dispose();
1290 if (backgroundExtraData != null && backgroundExtraData.CornerRadius != null)
1292 using (var cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius))
1293 using (var cornerRadiusPolicy = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy))
1295 imageMap.Insert(Visual.Property.CornerRadius, cornerRadius);
1296 imageMap.Insert(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(backgroundExtraData.CornerRadiusPolicy)));
1300 if (backgroundExtraData != null && backgroundExtraData.BorderlineWidth > 0.0f)
1302 using (var borderlineWidth = new PropertyValue(backgroundExtraData.BorderlineWidth))
1303 using (var borderlineColor = new PropertyValue(backgroundExtraData.BorderlineColor))
1304 using (var borderlineOffset = new PropertyValue(backgroundExtraData.BorderlineOffset))
1306 imageMap.Insert(Visual.Property.BorderlineWidth, borderlineWidth);
1307 imageMap.Insert(Visual.Property.BorderlineColor, borderlineColor);
1308 imageMap.Insert(Visual.Property.BorderlineOffset, borderlineOffset);
1314 imageMap?.Insert(key, value);
1317 // Do Fitting Buffer when desired dimension is set
1318 if (_desired_width != -1 && _desired_height != -1)
1320 if (_resourceUrl != null)
1322 Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl, true);
1323 if( imageSize.Height > 0 && imageSize.Width > 0 && _desired_width > 0 && _desired_height > 0 )
1325 int adjustedDesiredWidth, adjustedDesiredHeight;
1326 float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
1327 float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
1328 if (aspectOfImageSize > aspectOfDesiredSize)
1330 adjustedDesiredWidth = _desired_width;
1331 adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
1335 adjustedDesiredWidth = imageSize.Width * _desired_height / imageSize.Height;
1336 adjustedDesiredHeight = _desired_height;
1339 PropertyValue returnWidth = new PropertyValue(adjustedDesiredWidth);
1340 imageMap?.Insert(ImageVisualProperty.DesiredWidth, returnWidth);
1341 returnWidth?.Dispose();
1342 PropertyValue returnHeight = new PropertyValue(adjustedDesiredHeight);
1343 imageMap?.Insert(ImageVisualProperty.DesiredHeight, returnHeight);
1344 returnHeight?.Dispose();
1345 PropertyValue scaleToFit = new PropertyValue((int)FittingModeType.ScaleToFill);
1346 imageMap?.Insert(ImageVisualProperty.FittingMode, scaleToFit);
1347 scaleToFit?.Dispose();
1351 Tizen.Log.Fatal("NUI", "[ERROR] Can't use DesiredSize when ImageLoading is failed.");
1353 imageSize?.Dispose();
1357 UpdateImageMap(imageMap);
1359 imageMap?.Dispose();
1364 private void OnResourceLoaded(IntPtr view)
1366 ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1367 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1369 if (_resourceLoadedEventHandler != null)
1371 _resourceLoadedEventHandler(this, e);
1376 /// Event arguments of resource ready.
1378 /// <since_tizen> 3 </since_tizen>
1379 public class ResourceReadyEventArgs : EventArgs
1384 /// The view whose resource is ready.
1386 /// <since_tizen> 3 </since_tizen>
1400 internal class ResourceLoadedEventArgs : EventArgs
1402 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1403 public ResourceLoadingStatusType Status
1416 internal new class Property
1418 internal static readonly int IMAGE = Interop.ImageView.ImageGet();
1419 internal static readonly int PreMultipliedAlpha = Interop.ImageView.PreMultipliedAlphaGet();
1420 internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet();
1421 internal static readonly int ActionReload = Interop.ImageView.ImageVisualActionReloadGet();
1422 internal static readonly int ActionPlay = Interop.ImageView.ImageVisualActionPlayGet();
1423 internal static readonly int ActionPause = Interop.ImageView.ImageVisualActionPauseGet();
1424 internal static readonly int ActionStop = Interop.ImageView.ImageVisualActionStopGet();
1427 private enum ImageType
1430 /// For Normal Image.
1435 /// For normal image, with synchronous loading and orientation correction property
1440 /// For nine-patch image
1445 private void OnBorderChanged(int x, int y, int width, int height)
1447 Border = new Rectangle(x, y, width, height);
1449 private void OnPixelAreaChanged(float x, float y, float z, float w)
1451 PixelArea = new RelativeVector4(x, y, z, w);