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: (bindable) =>
51 var imageView = (ImageView)bindable;
54 PropertyMap imageMap = new PropertyMap();
55 Tizen.NUI.Object.GetProperty(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: (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(imageView.swigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
108 defaultValueCreator: (bindable) =>
110 var imageView = (ImageView)bindable;
111 if (imageView._border == null)
113 PropertyMap temp = new PropertyMap();
114 Tizen.NUI.Object.GetProperty(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: (bindable, oldValue, newValue) =>
127 var imageView = (ImageView)bindable;
128 if (newValue != null)
130 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
133 defaultValueCreator: (bindable) =>
135 var imageView = (ImageView)bindable;
137 Tizen.NUI.Object.GetProperty(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: (bindable, oldValue, newValue) =>
145 var imageView = (ImageView)bindable;
146 if (newValue != null)
148 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
151 defaultValueCreator: (bindable) =>
153 var imageView = (ImageView)bindable;
154 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
155 Tizen.NUI.Object.GetProperty(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: (bindable) =>
189 var imageView = (ImageView)bindable;
191 PropertyMap imageMap = new PropertyMap();
192 Tizen.NUI.Object.GetProperty(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: (bindable) =>
226 var imageView = (ImageView)bindable;
229 PropertyMap imageMap = new PropertyMap();
230 Tizen.NUI.Object.GetProperty(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);
272 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 public ImageViewStyle Style => new ImageViewStyle(this);
277 /// Creates an initialized ImageView.
279 /// <since_tizen> 3 </since_tizen>
280 public ImageView() : this(Interop.ImageView.New(), true)
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
286 [EditorBrowsable(EditorBrowsableState.Never)]
287 public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.New(), true, viewStyle)
292 /// Creates an initialized ImageView with setting the status of shown or hidden.
294 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
295 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
296 [EditorBrowsable(EditorBrowsableState.Never)]
297 public ImageView(bool shown) : this(Interop.ImageView.New(), true)
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 /// Creates an initialized ImageView from a URL to an image resource.<br />
305 /// If the string is empty, ImageView will not display anything.<br />
307 /// <param name="url">The URL of the image resource to display.</param>
308 /// <since_tizen> 3 </since_tizen>
309 public ImageView(string url) : this(Interop.ImageView.New(url), true)
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
319 /// <param name="url">The URL of the image resource to display.</param>
320 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
321 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
322 [EditorBrowsable(EditorBrowsableState.Never)]
323 public ImageView(string url, bool shown) : this(Interop.ImageView.New(url), true)
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.New(url, Uint16Pair.getCPtr(size)), true)
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(Interop.ImageView.Upcast(cPtr), cMemoryOwn, viewStyle)
349 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(Interop.ImageView.Upcast(cPtr), cMemoryOwn, null)
357 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
358 private delegate void ResourceReadyEventCallbackType(IntPtr data);
359 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
360 private delegate void _resourceLoadedCallbackType(IntPtr view);
363 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
364 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
365 /// Most resources are only loaded when the control is placed on the stage.<br />
367 /// <since_tizen> 3 </since_tizen>
368 public event EventHandler<ResourceReadyEventArgs> ResourceReady
372 if (_resourceReadyEventHandler == null)
374 _resourceReadyEventCallback = OnResourceReady;
375 ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
378 _resourceReadyEventHandler += value;
383 _resourceReadyEventHandler -= value;
385 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
387 ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
392 internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
396 if (_resourceLoadedEventHandler == null)
398 _resourceLoadedCallback = OnResourceLoaded;
399 this.ResourceReadySignal(this).Connect(_resourceLoadedCallback);
402 _resourceLoadedEventHandler += value;
406 _resourceLoadedEventHandler -= value;
408 if (_resourceLoadedEventHandler == null && this.ResourceReadySignal(this).Empty() == false)
410 this.ResourceReadySignal(this).Disconnect(_resourceLoadedCallback);
416 /// Enumeration for LoadingStatus of image.
418 /// <since_tizen> 5 </since_tizen>
419 public enum LoadingStatusType
422 /// Loading preparing status.
424 /// <since_tizen> 5 </since_tizen>
427 /// Loading ready status.
429 /// <since_tizen> 5 </since_tizen>
432 /// Loading failed status.
434 /// <since_tizen> 5 </since_tizen>
439 /// ImageView ResourceUrl, type string.
440 /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
441 /// When it is set as null, it gives empty string ("") to be read.
443 /// <since_tizen> 3 </since_tizen>
444 public string ResourceUrl
448 return (string)GetValue(ResourceUrlProperty);
452 SetValue(ResourceUrlProperty, value);
453 resourceUrlSelector.UpdateIfNeeds(this, value);
454 NotifyPropertyChanged();
459 /// This will be deprecated, please use Image instead. <br />
460 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
462 /// <since_tizen> 3 </since_tizen>
463 [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
464 [EditorBrowsable(EditorBrowsableState.Never)]
465 public PropertyMap ImageMap
471 PropertyMap temp = new PropertyMap();
472 GetProperty(ImageView.Property.IMAGE).Get(temp);
484 SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
485 NotifyPropertyChanged();
491 /// ImageView Image, type PropertyMap
493 /// <since_tizen> 4 </since_tizen>
494 public PropertyMap Image
500 return (PropertyMap)GetValue(ImageProperty);
511 SetValue(ImageProperty, value);
512 NotifyPropertyChanged();
518 /// ImageView PreMultipliedAlpha, type Boolean.<br />
519 /// Image must be initialized.<br />
521 /// <since_tizen> 3 </since_tizen>
522 public bool PreMultipliedAlpha
526 return (bool)GetValue(PreMultipliedAlphaProperty);
530 SetValue(PreMultipliedAlphaProperty, value);
531 NotifyPropertyChanged();
536 /// ImageView PixelArea, type Vector4 (Animatable property).<br />
537 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
540 /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
542 /// <since_tizen> 3 </since_tizen>
543 public RelativeVector4 PixelArea
547 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
548 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
552 SetValue(PixelAreaProperty, value);
553 NotifyPropertyChanged();
558 /// The border of the image in the order: left, right, bottom, top.<br />
559 /// If set, ImageMap will be ignored.<br />
560 /// For N-Patch images only.<br />
564 /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
566 /// <since_tizen> 3 </since_tizen>
567 public Rectangle Border
571 Rectangle temp = (Rectangle)GetValue(BorderProperty);
578 return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
583 SetValue(BorderProperty, value);
584 borderSelector.UpdateIfNeeds(this, value);
585 NotifyPropertyChanged();
590 /// Gets or sets whether to draw the borders only (if true).<br />
591 /// If not specified, the default is false.<br />
592 /// For N-Patch images only.<br />
595 /// <since_tizen> 3 </since_tizen>
596 public bool BorderOnly
600 return (bool)GetValue(BorderOnlyProperty);
604 SetValue(BorderOnlyProperty, value);
605 NotifyPropertyChanged();
610 /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
612 /// <since_tizen> 3 </since_tizen>
613 public bool SynchronosLoading
617 return (bool)GetValue(SynchronosLoadingProperty);
621 SetValue(SynchronosLoadingProperty, value);
622 NotifyPropertyChanged();
627 /// Gets or sets whether to automatically correct the orientation of an image.<br />
629 /// <since_tizen> 5 </since_tizen>
630 public bool OrientationCorrection
634 return (bool)GetValue(OrientationCorrectionProperty);
638 SetValue(OrientationCorrectionProperty, value);
639 NotifyPropertyChanged();
644 /// Gets the loading state of the visual resource.
646 /// <since_tizen> 5 </since_tizen>
647 public ImageView.LoadingStatusType LoadingStatus
651 return (ImageView.LoadingStatusType)Interop.View.GetVisualResourceStatus(swigCPtr, (int)Property.IMAGE);
656 /// Downcasts a handle to imageView handle.
658 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
659 /// Please do not use! this will be deprecated!
660 /// Instead please use as keyword.
661 /// <since_tizen> 3 </since_tizen>
662 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
664 "BaseHandle handle = new ImageView(imagePath); " +
665 "ImageView image = handle as ImageView")]
666 [EditorBrowsable(EditorBrowsableState.Never)]
667 public static ImageView DownCast(BaseHandle handle)
671 throw new ArgumentNullException(nameof(handle));
673 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
674 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
679 /// Sets this ImageView from the given URL.<br />
680 /// If the URL is empty, ImageView will not display anything.<br />
682 /// <param name="url">The URL to the image resource to display.</param>
683 /// <exception cref="ArgumentNullException"> Thrown when url is null. </exception>
684 /// <since_tizen> 3 </since_tizen>
685 public void SetImage(string url)
689 throw new ArgumentNullException(nameof(url));
692 if (url.Contains(".json"))
694 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
698 Interop.ImageView.SetImage(swigCPtr, url);
699 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
705 /// Queries if all resources required by a control are loaded and ready.<br />
706 /// Most resources are only loaded when the control is placed on the stage.<br />
707 /// True if the resources are loaded and ready, false otherwise.<br />
709 /// <since_tizen> 3 </since_tizen>
710 public new bool IsResourceReady()
712 bool ret = Interop.View.IsResourceReady(swigCPtr);
713 if (NDalicPINVOKE.SWIGPendingException.Pending)
714 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
719 /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
721 /// <since_tizen> 5 </since_tizen>
724 this.DoAction(ImageView.Property.IMAGE, Property.ActionReload, new PropertyValue(0));
728 /// Plays the animated GIF. This is also the default playback mode.
730 /// <since_tizen> 5 </since_tizen>
733 this.DoAction(ImageView.Property.IMAGE, Property.ActionPlay, new PropertyValue(0));
737 /// Pauses the animated GIF.
739 /// <since_tizen> 5 </since_tizen>
742 this.DoAction(ImageView.Property.IMAGE, Property.ActionPause, new PropertyValue(0));
746 /// Stops the animated GIF.
748 /// <since_tizen> 5 </since_tizen>
751 this.DoAction(ImageView.Property.IMAGE, Property.ActionStop, new PropertyValue(0));
755 /// Gets or sets the URL of the alpha mask.<br />
758 /// <since_tizen> 6</since_tizen>
759 [EditorBrowsable(EditorBrowsableState.Never)]
760 public string AlphaMaskURL
765 PropertyMap imageMap = new PropertyMap();
766 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
767 imageMap?.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out ret);
779 _alphaMaskUrl = value;
780 UpdateImage(ImageVisualProperty.AlphaMaskURL, new PropertyValue(value));
786 /// Whether to crop image to mask or scale mask to fit image.
788 /// <since_tizen> 6 </since_tizen>
789 public bool CropToMask
794 PropertyMap imageMap = new PropertyMap();
795 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
796 imageMap?.Find(ImageVisualProperty.CropToMask)?.Get(out ret);
802 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue(value));
806 internal VisualFittingModeType CovertFittingModetoVisualFittingMode(FittingModeType value)
810 case FittingModeType.ShrinkToFit:
811 return VisualFittingModeType.FitKeepAspectRatio;
812 case FittingModeType.ScaleToFill:
813 return VisualFittingModeType.OverFitKeepAspectRatio;
814 case FittingModeType.Center:
815 return VisualFittingModeType.Center;
816 case FittingModeType.Fill:
817 return VisualFittingModeType.Fill;
818 case FittingModeType.FitHeight:
819 return VisualFittingModeType.FitHeight;
820 case FittingModeType.FitWidth:
821 return VisualFittingModeType.FitHeight;
823 return VisualFittingModeType.Fill;
827 internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
831 case VisualFittingModeType.FitKeepAspectRatio:
832 return FittingModeType.ShrinkToFit;
833 case VisualFittingModeType.OverFitKeepAspectRatio:
834 return FittingModeType.ScaleToFill;
835 case VisualFittingModeType.Center:
836 return FittingModeType.Center;
837 case VisualFittingModeType.Fill:
838 return FittingModeType.Fill;
839 case VisualFittingModeType.FitHeight:
840 return FittingModeType.FitHeight;
841 case VisualFittingModeType.FitWidth:
842 return FittingModeType.FitWidth;
844 return FittingModeType.ShrinkToFit;
849 /// Gets or sets fitting options used when resizing images to fit.<br />
850 /// If not supplied, the default is FittingModeType.Fill.<br />
851 /// For normal quad images only.<br />
854 /// <since_tizen> 6 </since_tizen>
855 [EditorBrowsable(EditorBrowsableState.Never)]
856 public FittingModeType FittingMode
860 int ret = (int)VisualFittingModeType.Fill;
861 PropertyMap imageMap = new PropertyMap();
862 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
863 imageMap?.Find(Visual.Property.VisualFittingMode)?.Get(out ret);
864 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
868 VisualFittingModeType ret = CovertFittingModetoVisualFittingMode(value);
869 UpdateImage(Visual.Property.VisualFittingMode, new PropertyValue((int)ret));
876 /// Gets or sets the desired image width.<br />
877 /// If not specified, the actual image width is used.<br />
878 /// For normal quad images only.<br />
881 /// <since_tizen> 6 </since_tizen>
882 [EditorBrowsable(EditorBrowsableState.Never)]
883 public int DesiredWidth
887 PropertyMap imageMap = new PropertyMap();
888 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
889 imageMap?.Find(ImageVisualProperty.DesiredWidth)?.Get(out _desired_width);
891 return _desired_width;
895 if (_desired_width != value)
897 _desired_width = value;
898 UpdateImage(0, null);
904 /// Gets or sets the desired image height.<br />
905 /// If not specified, the actual image height is used.<br />
906 /// For normal quad images only.<br />
909 /// <since_tizen> 6 </since_tizen>
910 [EditorBrowsable(EditorBrowsableState.Never)]
911 public int DesiredHeight
915 PropertyMap imageMap = new PropertyMap();
916 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
917 imageMap?.Find(ImageVisualProperty.DesiredHeight)?.Get(out _desired_height);
919 return _desired_height;
923 if (_desired_height != value)
925 _desired_height = value;
926 UpdateImage(0, null);
932 /// Gets or sets ReleasePolicy for image.<br />
933 /// If not supplied, the default is ReleasePolicyType.Detached.<br />
935 [EditorBrowsable(EditorBrowsableState.Never)]
936 public ReleasePolicyType ReleasePolicy
940 int ret = (int)ReleasePolicyType.Detached;
941 PropertyMap imageMap = new PropertyMap();
942 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
943 imageMap?.Find(ImageVisualProperty.ReleasePolicy)?.Get(out ret);
944 return (ReleasePolicyType)ret;
948 UpdateImage(ImageVisualProperty.ReleasePolicy, new PropertyValue((int)value));
953 /// Gets or sets the wrap mode for the u coordinate.<br />
954 /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
955 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
956 /// For normal quad images only.<br />
959 /// <since_tizen> 6 </since_tizen>
960 [EditorBrowsable(EditorBrowsableState.Never)]
961 public WrapModeType WrapModeU
965 int ret = (int)WrapModeType.Default;
966 PropertyMap imageMap = new PropertyMap();
967 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
968 imageMap?.Find(ImageVisualProperty.WrapModeU)?.Get(out ret);
970 return (WrapModeType)ret;
974 UpdateImage(ImageVisualProperty.WrapModeU, new PropertyValue((int)value));
979 /// Gets or sets the wrap mode for the v coordinate.<br />
980 /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
981 /// 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 />
982 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
983 /// For normal quad images only.
986 /// <since_tizen> 6 </since_tizen>
987 [EditorBrowsable(EditorBrowsableState.Never)]
988 public WrapModeType WrapModeV
992 int ret = (int)WrapModeType.Default;
993 PropertyMap imageMap = new PropertyMap();
994 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
995 imageMap?.Find(ImageVisualProperty.WrapModeV)?.Get(out ret);
997 return (WrapModeType)ret;
1001 UpdateImage(ImageVisualProperty.WrapModeV, new PropertyValue((int)value));
1006 /// Get attribues, it is abstract function and must be override.
1008 /// <since_tizen> 6 </since_tizen>
1009 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
1010 [EditorBrowsable(EditorBrowsableState.Never)]
1011 protected override ViewStyle GetViewStyle()
1013 return new ImageViewStyle();
1016 internal void SetImage(string url, Uint16Pair size)
1018 if (url.Contains(".json"))
1020 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
1024 Interop.ImageView.SetImage(swigCPtr, url, Uint16Pair.getCPtr(size));
1025 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1030 internal ViewResourceReadySignal ResourceReadySignal(View view)
1032 ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
1033 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1037 internal override void ApplyCornerRadius()
1039 base.ApplyCornerRadius();
1041 UpdateImage(0, null);
1044 internal ResourceLoadingStatusType GetResourceStatus()
1046 return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
1050 /// you can override it to clean-up your own resources.
1052 /// <param name="type">DisposeTypes</param>
1053 /// <since_tizen> 3 </since_tizen>
1054 protected override void Dispose(DisposeTypes type)
1061 if (type == DisposeTypes.Explicit)
1064 //Release your own managed resources here.
1065 //You should release all of your own disposable objects here.
1068 borderSelector.Reset(this);
1069 resourceUrlSelector.Reset(this);
1075 /// This will not be public opened.
1076 [EditorBrowsable(EditorBrowsableState.Never)]
1077 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1079 Interop.ImageView.DeleteImageView(swigCPtr);
1082 // Callback for View ResourceReady signal
1083 private void OnResourceReady(IntPtr data)
1085 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1088 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1091 if (_resourceReadyEventHandler != null)
1093 _resourceReadyEventHandler(this, e);
1097 private void UpdateImageMap(PropertyMap fromMap)
1099 PropertyMap imageMap = new PropertyMap();
1100 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
1101 imageMap.Merge(fromMap);
1103 SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
1106 private void UpdateImage(int key, PropertyValue value)
1108 PropertyMap temp = new PropertyMap();
1110 if (_alphaMaskUrl != null)
1112 temp.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(_alphaMaskUrl));
1115 if (_resourceUrl == "")
1117 temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl));
1118 SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp));
1122 if (_border == null)
1124 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
1128 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
1129 temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1132 temp.Insert(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(_synchronosLoading));
1134 if (backgroundExtraData != null && backgroundExtraData.CornerRadius > 0)
1136 temp.Insert(Visual.Property.CornerRadius, new PropertyValue(backgroundExtraData.CornerRadius));
1141 temp.Insert(key, value);
1144 // Do Fitting Buffer when desired dimension is set
1145 if (_desired_width != -1 && _desired_height != -1)
1147 if (_resourceUrl != null)
1149 Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl);
1151 int adjustedDesiredWidth, adjustedDesiredHeight;
1152 float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
1153 float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
1154 if( aspectOfImageSize > aspectOfDesiredSize)
1156 adjustedDesiredWidth = _desired_width;
1157 adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
1161 adjustedDesiredWidth = imageSize.Width * _desired_height/ imageSize.Height;
1162 adjustedDesiredHeight = _desired_height;
1164 temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue(adjustedDesiredWidth));
1165 temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue(adjustedDesiredHeight));
1166 temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)FittingModeType.ScaleToFill));
1170 UpdateImageMap(temp);
1177 private void OnResourceLoaded(IntPtr view)
1179 ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1180 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
1182 if (_resourceLoadedEventHandler != null)
1184 _resourceLoadedEventHandler(this, e);
1189 /// Event arguments of resource ready.
1191 /// <since_tizen> 3 </since_tizen>
1192 public class ResourceReadyEventArgs : EventArgs
1197 /// The view whose resource is ready.
1199 /// <since_tizen> 3 </since_tizen>
1213 internal class ResourceLoadedEventArgs : EventArgs
1215 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1216 public ResourceLoadingStatusType Status
1229 internal new class Property
1231 internal static readonly int IMAGE = Interop.ImageView.ImageGet();
1232 internal static readonly int PreMultipliedAlpha = Interop.ImageView.PreMultipliedAlphaGet();
1233 internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet();
1234 internal static readonly int ActionReload = Interop.ImageView.ImageVisualActionReloadGet();
1235 internal static readonly int ActionPlay = Interop.ImageView.ImageVisualActionPlayGet();
1236 internal static readonly int ActionPause = Interop.ImageView.ImageVisualActionPauseGet();
1237 internal static readonly int ActionStop = Interop.ImageView.ImageVisualActionStopGet();
1240 private enum ImageType
1243 /// For Normal Image.
1248 /// For normal image, with synchronous loading and orientation correction property
1253 /// For nine-patch image
1258 private void OnBorderChanged(int x, int y, int width, int height)
1260 Border = new Rectangle(x, y, width, height);
1262 private void OnPixelAreaChanged(float x, float y, float z, float w)
1264 PixelArea = new RelativeVector4(x, y, z, w);