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.IMAGE_VISUAL_URL);
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.IMAGE_VISUAL_URL, new PropertyValue(url));
83 PropertyValue alphaMaskUrlValue = map.Find(NDalic.IMAGE_VISUAL_ALPHA_MASK_URL);
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.IMAGE_VISUAL_URL, new PropertyValue(alphaMaskURL));
92 PropertyValue auxiliaryImageURLValue = map.Find(NDalic.IMAGE_VISUAL_AUXILIARY_IMAGE_URL);
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.IMAGE_VISUAL_AUXILIARY_IMAGE_URL, 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("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.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue((bool)newValue));
133 defaultValueCreator: (bindable) =>
135 var imageView = (ImageView)bindable;
137 Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.PRE_MULTIPLIED_ALPHA).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("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.PIXEL_AREA, 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.PIXEL_AREA).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("Border", typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
166 var imageView = (ImageView)bindable;
167 imageView._border = (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("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("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("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 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
237 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
238 private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
239 private _resourceLoadedCallbackType _resourceLoadedCallback;
241 private Rectangle _border;
242 private string _resourceUrl = "";
243 private bool _synchronosLoading = false;
244 private string _alphaMaskUrl = null;
245 private int _desired_width = -1;
246 private int _desired_height = -1;
248 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 public ImageViewStyle Style => ViewStyle as ImageViewStyle;
253 /// Creates an initialized ImageView.
255 /// <since_tizen> 3 </since_tizen>
256 public ImageView() : this(Interop.ImageView.ImageView_New__SWIG_0(), true)
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
262 [EditorBrowsable(EditorBrowsableState.Never)]
263 public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.ImageView_New__SWIG_0(), true, viewStyle)
268 /// Creates an initialized ImageView with setting the status of shown or hidden.
270 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
271 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
272 [EditorBrowsable(EditorBrowsableState.Never)]
273 public ImageView(bool shown) : this(Interop.ImageView.ImageView_New__SWIG_0(), true)
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 /// Creates an initialized ImageView from a URL to an image resource.<br />
281 /// If the string is empty, ImageView will not display anything.<br />
283 /// <param name="url">The URL of the image resource to display.</param>
284 /// <since_tizen> 3 </since_tizen>
285 public ImageView(string url) : this(Interop.ImageView.ImageView_New__SWIG_2(url), true)
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
295 /// <param name="url">The URL of the image resource to display.</param>
296 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
297 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
298 [EditorBrowsable(EditorBrowsableState.Never)]
299 public ImageView(string url, bool shown) : this(Interop.ImageView.ImageView_New__SWIG_2(url), true)
302 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306 internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(Interop.ImageView.ImageView_SWIGUpcast(cPtr), cMemoryOwn, viewStyle)
325 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(Interop.ImageView.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
333 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
334 private delegate void ResourceReadyEventCallbackType(IntPtr data);
335 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
336 private delegate void _resourceLoadedCallbackType(IntPtr view);
339 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
340 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
341 /// Most resources are only loaded when the control is placed on the stage.<br />
343 /// <since_tizen> 3 </since_tizen>
344 public event EventHandler<ResourceReadyEventArgs> ResourceReady
348 if (_resourceReadyEventHandler == null)
350 _resourceReadyEventCallback = OnResourceReady;
351 ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
354 _resourceReadyEventHandler += value;
359 _resourceReadyEventHandler -= value;
361 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
363 ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
368 internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
372 if (_resourceLoadedEventHandler == null)
374 _resourceLoadedCallback = OnResourceLoaded;
375 this.ResourceReadySignal(this).Connect(_resourceLoadedCallback);
378 _resourceLoadedEventHandler += value;
382 _resourceLoadedEventHandler -= value;
384 if (_resourceLoadedEventHandler == null && this.ResourceReadySignal(this).Empty() == false)
386 this.ResourceReadySignal(this).Disconnect(_resourceLoadedCallback);
392 /// Enumeration for LoadingStatus of image.
394 /// <since_tizen> 5 </since_tizen>
395 public enum LoadingStatusType
398 /// Loading preparing status.
400 /// <since_tizen> 5 </since_tizen>
403 /// Loading ready status.
405 /// <since_tizen> 5 </since_tizen>
408 /// Loading failed status.
410 /// <since_tizen> 5 </since_tizen>
415 /// ImageView ResourceUrl, type string.
416 /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
417 /// When it is set as null, it gives empty string ("") to be read.
419 /// <since_tizen> 3 </since_tizen>
420 public string ResourceUrl
424 return (string)GetValue(ResourceUrlProperty);
428 SetValue(ResourceUrlProperty, value);
429 NotifyPropertyChanged();
434 /// This will be deprecated, please use Image instead. <br />
435 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
437 /// <since_tizen> 3 </since_tizen>
438 [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
439 [EditorBrowsable(EditorBrowsableState.Never)]
440 public PropertyMap ImageMap
446 PropertyMap temp = new PropertyMap();
447 GetProperty(ImageView.Property.IMAGE).Get(temp);
459 SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
460 NotifyPropertyChanged();
466 /// ImageView Image, type PropertyMap
468 /// <since_tizen> 4 </since_tizen>
469 public PropertyMap Image
475 return (PropertyMap)GetValue(ImageProperty);
486 SetValue(ImageProperty, value);
487 NotifyPropertyChanged();
493 /// ImageView PreMultipliedAlpha, type Boolean.<br />
494 /// Image must be initialized.<br />
496 /// <since_tizen> 3 </since_tizen>
497 public bool PreMultipliedAlpha
501 return (bool)GetValue(PreMultipliedAlphaProperty);
505 SetValue(PreMultipliedAlphaProperty, value);
506 NotifyPropertyChanged();
511 /// ImageView PixelArea, type Vector4 (Animatable property).<br />
512 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
515 /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
517 /// <since_tizen> 3 </since_tizen>
518 public RelativeVector4 PixelArea
522 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
523 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
527 SetValue(PixelAreaProperty, value);
528 NotifyPropertyChanged();
533 /// The border of the image in the order: left, right, bottom, top.<br />
534 /// If set, ImageMap will be ignored.<br />
535 /// For N-Patch images only.<br />
539 /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
541 /// <since_tizen> 3 </since_tizen>
542 public Rectangle Border
546 Rectangle temp = (Rectangle)GetValue(BorderProperty);
553 return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
558 SetValue(BorderProperty, value);
559 NotifyPropertyChanged();
564 /// Gets or sets whether to draw the borders only (if true).<br />
565 /// If not specified, the default is false.<br />
566 /// For N-Patch images only.<br />
569 /// <since_tizen> 3 </since_tizen>
570 public bool BorderOnly
574 return (bool)GetValue(BorderOnlyProperty);
578 SetValue(BorderOnlyProperty, value);
579 NotifyPropertyChanged();
584 /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
586 /// <since_tizen> 3 </since_tizen>
587 public bool SynchronosLoading
591 return (bool)GetValue(SynchronosLoadingProperty);
595 SetValue(SynchronosLoadingProperty, value);
596 NotifyPropertyChanged();
601 /// Gets or sets whether to automatically correct the orientation of an image.<br />
603 /// <since_tizen> 5 </since_tizen>
604 public bool OrientationCorrection
608 return (bool)GetValue(OrientationCorrectionProperty);
612 SetValue(OrientationCorrectionProperty, value);
613 NotifyPropertyChanged();
618 /// Gets the loading state of the visual resource.
620 /// <since_tizen> 5 </since_tizen>
621 public ImageView.LoadingStatusType LoadingStatus
625 return (ImageView.LoadingStatusType)Interop.View.View_GetVisualResourceStatus(swigCPtr, (int)Property.IMAGE);
630 /// Downcasts a handle to imageView handle.
632 /// Please do not use! this will be deprecated!
633 /// Instead please use as keyword.
634 /// <since_tizen> 3 </since_tizen>
635 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
637 "BaseHandle handle = new ImageView(imagePath); " +
638 "ImageView image = handle as ImageView")]
639 [EditorBrowsable(EditorBrowsableState.Never)]
640 public static ImageView DownCast(BaseHandle handle)
642 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
643 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
648 /// Sets this ImageView from the given URL.<br />
649 /// If the URL is empty, ImageView will not display anything.<br />
651 /// <param name="url">The URL to the image resource to display.</param>
652 /// <since_tizen> 3 </since_tizen>
653 public void SetImage(string url)
655 if(url.Contains(".json"))
657 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
661 Interop.ImageView.ImageView_SetImage__SWIG_1(swigCPtr, url);
662 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
668 /// Queries if all resources required by a control are loaded and ready.<br />
669 /// Most resources are only loaded when the control is placed on the stage.<br />
670 /// True if the resources are loaded and ready, false otherwise.<br />
672 /// <since_tizen> 3 </since_tizen>
673 public new bool IsResourceReady()
675 bool ret = Interop.View.IsResourceReady(swigCPtr);
676 if (NDalicPINVOKE.SWIGPendingException.Pending)
677 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
682 /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
684 /// <since_tizen> 5 </since_tizen>
687 this.DoAction(ImageView.Property.IMAGE, Property.ACTION_RELOAD, new PropertyValue(0));
691 /// Plays the animated GIF. This is also the default playback mode.
693 /// <since_tizen> 5 </since_tizen>
696 this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PLAY, new PropertyValue(0));
700 /// Pauses the animated GIF.
702 /// <since_tizen> 5 </since_tizen>
705 this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PAUSE, new PropertyValue(0));
709 /// Stops the animated GIF.
711 /// <since_tizen> 5 </since_tizen>
714 this.DoAction(ImageView.Property.IMAGE, Property.ACTION_STOP, new PropertyValue(0));
718 /// Gets or sets the URL of the alpha mask.<br />
721 /// <since_tizen> 6</since_tizen>
722 [EditorBrowsable(EditorBrowsableState.Never)]
723 public string AlphaMaskURL
728 PropertyMap imageMap = new PropertyMap();
729 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
730 imageMap?.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out ret);
742 _alphaMaskUrl = value;
743 UpdateImage(ImageVisualProperty.AlphaMaskURL, new PropertyValue(value));
749 /// Whether to crop image to mask or scale mask to fit image.
751 /// <since_tizen> 6 </since_tizen>
752 public bool CropToMask
757 PropertyMap imageMap = new PropertyMap();
758 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
759 imageMap?.Find(ImageVisualProperty.CropToMask)?.Get(out ret);
765 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue(value));
769 internal VisualFittingModeType CovertFittingModetoVisualFittingMode(FittingModeType value)
773 case FittingModeType.ShrinkToFit:
774 return VisualFittingModeType.FitKeepAspectRatio;
775 case FittingModeType.ScaleToFill:
776 return VisualFittingModeType.OverFitKeepAspectRatio;
777 case FittingModeType.Center:
778 return VisualFittingModeType.Center;
779 case FittingModeType.Fill:
780 return VisualFittingModeType.Fill;
781 case FittingModeType.FitHeight:
782 return VisualFittingModeType.FitHeight;
783 case FittingModeType.FitWidth:
784 return VisualFittingModeType.FitHeight;
786 return VisualFittingModeType.Fill;
790 internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
794 case VisualFittingModeType.FitKeepAspectRatio:
795 return FittingModeType.ShrinkToFit;
796 case VisualFittingModeType.OverFitKeepAspectRatio:
797 return FittingModeType.ScaleToFill;
798 case VisualFittingModeType.Center:
799 return FittingModeType.Center;
800 case VisualFittingModeType.Fill:
801 return FittingModeType.Fill;
802 case VisualFittingModeType.FitHeight:
803 return FittingModeType.FitHeight;
804 case VisualFittingModeType.FitWidth:
805 return FittingModeType.FitHeight;
807 return FittingModeType.ShrinkToFit;
812 /// Gets or sets fitting options used when resizing images to fit.<br />
813 /// If not supplied, the default is FittingModeType.Fill.<br />
814 /// For normal quad images only.<br />
817 /// <since_tizen> 6 </since_tizen>
818 [EditorBrowsable(EditorBrowsableState.Never)]
819 public FittingModeType FittingMode
823 int ret = (int)VisualFittingModeType.Fill;
824 PropertyMap imageMap = new PropertyMap();
825 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
826 imageMap?.Find(Visual.Property.VisualFittingMode)?.Get(out ret);
827 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
831 VisualFittingModeType ret = CovertFittingModetoVisualFittingMode(value);
832 UpdateImage(Visual.Property.VisualFittingMode, new PropertyValue((int) ret));
839 /// Gets or sets the desired image width.<br />
840 /// If not specified, the actual image width is used.<br />
841 /// For normal quad images only.<br />
844 /// <since_tizen> 6 </since_tizen>
845 [EditorBrowsable(EditorBrowsableState.Never)]
846 public int DesiredWidth
850 PropertyMap imageMap = new PropertyMap();
851 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
852 imageMap?.Find(ImageVisualProperty.DesiredWidth)?.Get(out _desired_width);
854 return _desired_width;
858 UpdateImage(ImageVisualProperty.DesiredWidth, new PropertyValue(value));
859 _desired_width = value;
864 /// Gets or sets the desired image height.<br />
865 /// If not specified, the actual image height is used.<br />
866 /// For normal quad images only.<br />
869 /// <since_tizen> 6 </since_tizen>
870 [EditorBrowsable(EditorBrowsableState.Never)]
871 public int DesiredHeight
875 PropertyMap imageMap = new PropertyMap();
876 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
877 imageMap?.Find(ImageVisualProperty.DesiredHeight)?.Get(out _desired_height);
879 return _desired_height;
883 UpdateImage(ImageVisualProperty.DesiredHeight, new PropertyValue(value));
884 _desired_height = value;
890 /// Gets or sets the wrap mode for the u coordinate.<br />
891 /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
892 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
893 /// For normal quad images only.<br />
896 /// <since_tizen> 6 </since_tizen>
897 [EditorBrowsable(EditorBrowsableState.Never)]
898 public WrapModeType WrapModeU
902 int ret = (int)WrapModeType.Default;
903 PropertyMap imageMap = new PropertyMap();
904 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
905 imageMap?.Find(ImageVisualProperty.WrapModeU)?.Get(out ret);
907 return (WrapModeType)ret;
911 UpdateImage(ImageVisualProperty.WrapModeU, new PropertyValue((int)value));
916 /// Gets or sets the wrap mode for the v coordinate.<br />
917 /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
918 /// 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 />
919 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
920 /// For normal quad images only.
923 /// <since_tizen> 6 </since_tizen>
924 [EditorBrowsable(EditorBrowsableState.Never)]
925 public WrapModeType WrapModeV
929 int ret = (int)WrapModeType.Default;
930 PropertyMap imageMap = new PropertyMap();
931 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
932 imageMap?.Find(ImageVisualProperty.WrapModeV)?.Get(out ret);
934 return (WrapModeType)ret;
938 UpdateImage(ImageVisualProperty.WrapModeV, new PropertyValue((int)value));
943 /// Get attribues, it is abstract function and must be override.
945 /// <since_tizen> 6 </since_tizen>
946 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
947 [EditorBrowsable(EditorBrowsableState.Never)]
948 protected override ViewStyle GetViewStyle()
950 return new ImageViewStyle();
953 internal void SetImage(string url, Uint16Pair size)
955 if(url.Contains(".json"))
957 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
961 Interop.ImageView.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
962 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
967 internal ViewResourceReadySignal ResourceReadySignal(View view)
969 ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
970 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
974 internal override void UpdateCornerRadius(float value, bool needToListenStateChanged)
976 base.UpdateCornerRadius(value, needToListenStateChanged);
978 UpdateImage(0, null);
981 internal ResourceLoadingStatusType GetResourceStatus()
983 return (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
986 internal static readonly BindableProperty ResourceUrlSelectorProperty = BindableProperty.Create("ResourceUrlSelector", typeof(Selector<string>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
988 var imageView = (ImageView)bindable;
989 imageView.resourceUrlSelector.Clone((Selector<string>)newValue);
991 defaultValueCreator: (bindable) =>
993 var imageView = (ImageView)bindable;
994 return imageView.resourceUrlSelector;
996 private TriggerableSelector<string> _resourceUrlSelector;
997 private TriggerableSelector<string> resourceUrlSelector
1001 if (null == _resourceUrlSelector)
1003 _resourceUrlSelector = new TriggerableSelector<string>(this, ResourceUrlProperty);
1005 return _resourceUrlSelector;
1009 internal static readonly BindableProperty BorderSelectorProperty = BindableProperty.Create("BorderSelector", typeof(Selector<Rectangle>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
1011 var imageView = (ImageView)bindable;
1012 imageView.borderSelector.Clone((Selector<Rectangle>)newValue);
1014 defaultValueCreator: (bindable) =>
1016 var imageView = (ImageView)bindable;
1017 return imageView.borderSelector;
1019 private TriggerableSelector<Rectangle> _borderSelector;
1020 private TriggerableSelector<Rectangle> borderSelector
1024 if (null == _borderSelector)
1026 _borderSelector = new TriggerableSelector<Rectangle>(this, BorderProperty);
1028 return _borderSelector;
1033 /// you can override it to clean-up your own resources.
1035 /// <param name="type">DisposeTypes</param>
1036 /// <since_tizen> 3 </since_tizen>
1037 protected override void Dispose(DisposeTypes type)
1044 if (type == DisposeTypes.Explicit)
1047 //Release your own managed resources here.
1048 //You should release all of your own disposable objects here.
1056 /// This will not be public opened.
1057 [EditorBrowsable(EditorBrowsableState.Never)]
1058 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1060 Interop.ImageView.delete_ImageView(swigCPtr);
1063 // Callback for View ResourceReady signal
1064 private void OnResourceReady(IntPtr data)
1066 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1069 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1072 if (_resourceReadyEventHandler != null)
1074 _resourceReadyEventHandler(this, e);
1078 private void UpdateImageMap(PropertyMap fromMap)
1080 PropertyMap imageMap = new PropertyMap();
1081 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
1082 imageMap.Merge(fromMap);
1084 SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
1087 private void UpdateImage(int key, PropertyValue value)
1089 PropertyMap temp = new PropertyMap();
1091 if(_alphaMaskUrl != null)
1093 temp.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(_alphaMaskUrl));
1096 if (_resourceUrl == "")
1098 temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl));
1099 SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp));
1103 if (_border == null)
1105 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
1109 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
1110 temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1113 temp.Insert(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(_synchronosLoading));
1115 if (backgroundExtraData != null && backgroundExtraData.CornerRadius > 0)
1117 temp.Insert(Visual.Property.CornerRadius, new PropertyValue(backgroundExtraData.CornerRadius));
1122 temp.Insert(key, value);
1125 // Do Fitting Buffer when desired dimension is set
1126 if( _desired_width != -1 && _desired_height != -1)
1128 if(_resourceUrl != null)
1130 Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl);
1132 int ret_width,ret_height;
1133 if( imageSize.Width > imageSize.Height)
1135 ret_width = _desired_width;
1136 ret_height = imageSize.Height * _desired_height /(imageSize.Width);
1140 ret_width = imageSize.Width*_desired_width/(imageSize.Height);
1141 ret_height = _desired_height;
1144 temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue((int)ret_width));
1145 temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue((int)ret_height));
1146 temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int) FittingModeType.ShrinkToFit));
1150 UpdateImageMap(temp);
1157 private void OnResourceLoaded(IntPtr view)
1159 ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1160 e.Status = (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
1162 if (_resourceLoadedEventHandler != null)
1164 _resourceLoadedEventHandler(this, e);
1169 /// Event arguments of resource ready.
1171 /// <since_tizen> 3 </since_tizen>
1172 public class ResourceReadyEventArgs : EventArgs
1177 /// The view whose resource is ready.
1179 /// <since_tizen> 3 </since_tizen>
1193 internal class ResourceLoadedEventArgs : EventArgs
1195 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1196 public ResourceLoadingStatusType Status
1209 internal new class Property
1211 internal static readonly int IMAGE = Interop.ImageView.ImageView_Property_IMAGE_get();
1212 internal static readonly int PRE_MULTIPLIED_ALPHA = Interop.ImageView.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
1213 internal static readonly int PIXEL_AREA = Interop.ImageView.ImageView_Property_PIXEL_AREA_get();
1214 internal static readonly int ACTION_RELOAD = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_RELOAD_get();
1215 internal static readonly int ACTION_PLAY = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PLAY_get();
1216 internal static readonly int ACTION_PAUSE = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PAUSE_get();
1217 internal static readonly int ACTION_STOP = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_STOP_get();
1220 private enum ImageType
1223 /// For Normal Image.
1228 /// For normal image, with synchronous loading and orientation correction property
1233 /// For nine-patch image
1238 private void OnBorderChanged(int x, int y, int width, int height)
1240 Border = new Rectangle(x, y, width, height);
1242 private void OnPixelAreaChanged(float x, float y, float z, float w)
1244 PixelArea = new RelativeVector4(x, y, z, w);