From 4aa96017b7d7bfdbc464d2ee1f20132e6bd4acae Mon Sep 17 00:00:00 2001 From: sunghyun kim Date: Thu, 9 May 2024 17:32:40 +0900 Subject: [PATCH] [NUI] Add SetTransitionEffectOption for ImageView's transition effect This method allows users to configure the blending of two images(previous and currnet) using alpha values. if only the transition effect is set to true, the default values are used. however, if options are configured through this API, the effect can be applied with the values desired by the user. https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-toolkit/+/310863/ https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-csharp-binder/+/310864/ --- .../src/internal/Interop/Interop.ImageView.cs | 3 + .../src/public/BaseComponents/ImageView.cs | 111 +++++++++++++++++++++ .../BaseComponents/ImageViewBindableProperty.cs | 21 ++++ .../Samples/PlaceHolderImageTest.cs | 1 + 4 files changed, 136 insertions(+) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.ImageView.cs b/src/Tizen.NUI/src/internal/Interop/Interop.ImageView.cs index 1ec3b18..f55871e 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.ImageView.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.ImageView.cs @@ -35,6 +35,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_ImageView_Property_TRANSITION_EFFECT_get")] public static extern int TransitionEffectGet(); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_ImageView_Property_TRANSITION_EFFECT_OPTION_get")] + public static extern int TransitionEffectOptionGet(); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_ImageView_New__SWIG_0")] public static extern global::System.IntPtr New(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index 6ff4035..3d9188a 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -82,6 +82,8 @@ namespace Tizen.NUI.BaseComponents TransitionEffectProperty = BindableProperty.Create(nameof(TransitionEffect), typeof(bool), typeof(ImageView), false, propertyChanged: SetInternalTransitionEffectProperty, defaultValueCreator: GetInternalTransitionEffectProperty); ImageColorProperty = BindableProperty.Create(nameof(ImageColor), typeof(Color), typeof(ImageView), null, propertyChanged: SetInternalImageColorProperty, defaultValueCreator: GetInternalImageColorProperty); + + TransitionEffectOptionProperty = BindableProperty.Create(nameof(TransitionEffectOption), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: SetInternalTransitionEffectOptionProperty, defaultValueCreator: GetInternalTransitionEffectOptionProperty); } } @@ -162,6 +164,8 @@ namespace Tizen.NUI.BaseComponents private RelativeVector4 internalPixelArea; + internal PropertyMap transitionEffectPropertyMap; + /// /// Creates an initialized ImageView. /// @@ -1263,6 +1267,63 @@ namespace Tizen.NUI.BaseComponents } /// + /// This method allows users to configure the blending of two images(previous and currnet) using alpha values. + /// + /// The initial alpha value of the first image. + /// The final alpha value of the second image. + /// The amount of time (in seconds) to wait before applying the blend. + /// The total time (in seconds) taken for the animation to finish + /// An optional built-in alpha function to apply during the blend. If not specified, defaults to no alpha function applied. + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetTransitionEffectOption(object initialImageAlpha,object destinationImageAlpha, float delay, float speed, AlphaFunction.BuiltinFunctions? alphaFunction = null) + { + using (PropertyMap animator = new PropertyMap()) + using (PropertyMap timePeriod = new PropertyMap()) + using (PropertyValue initValue = PropertyValue.CreateFromObject(initialImageAlpha)) + using (PropertyValue destValue = PropertyValue.CreateFromObject(destinationImageAlpha)) + using (PropertyValue pvDelay = new PropertyValue(delay)) + using (PropertyValue pvSpeed = new PropertyValue(speed)) + using (PropertyValue pvProperty = new PropertyValue("opacity")) + using (PropertyValue pvAnimationType = new PropertyValue("BETWEEN")) + using (PropertyMap transition = new PropertyMap()) + { + if (alphaFunction != null) + { + using (PropertyValue pvAlpha = new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction))) + { + animator.Add("alphaFunction", pvAlpha); + } + } + + timePeriod.Add("duration", pvSpeed); + timePeriod.Add("delay", pvDelay); + using (PropertyValue pvTimePeriod = new PropertyValue(timePeriod)) + { + animator.Add("timePeriod", pvTimePeriod); + } + + animator.Add("animationType", pvAnimationType); + + using (PropertyValue pvAnimator = new PropertyValue(animator)) + { + transition.Add("animator", pvAnimator); + } + using(PropertyValue pvTarget = new PropertyValue("image")) + { + transition.Add("target", pvTarget); + } + + transition.Add("property", pvProperty); + transition.Add("initialValue", initValue); + transition.Add("targetValue", destValue); + + SetProperty(ImageView.Property.TransitionEffectOption, new Tizen.NUI.PropertyValue(transition)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + /// /// Gets or sets the desired image width.
/// If not specified, the actual image width is used.
/// For normal quad images only.
@@ -1658,6 +1719,55 @@ namespace Tizen.NUI.BaseComponents } /// + /// Gets or sets whether the image use TransitionEffect or not
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public PropertyMap TransitionEffectOption + { + get + { + if (NUIApplication.IsUsingXaml) + { + return (PropertyMap)GetValue(TransitionEffectOptionProperty); + } + else + { + return GetInternalTransitionEffectOptionProperty(this) as PropertyMap; + } + } + set + { + if (NUIApplication.IsUsingXaml) + { + SetValue(TransitionEffectOptionProperty, value); + } + else + { + SetInternalTransitionEffectOptionProperty(this, null, value); + } + NotifyPropertyChanged(); + } + } + + private PropertyMap InternalTransitionEffectOption + { + get + { + PropertyMap retValue = new PropertyMap(); + PropertyValue transitionEffect = GetProperty(ImageView.Property.TransitionEffectOption); + transitionEffect?.Get(retValue); + transitionEffect?.Dispose(); + return retValue; + } + set + { + PropertyValue setValue = new Tizen.NUI.PropertyValue(value); + SetProperty(ImageView.Property.TransitionEffectOption, setValue); + setValue?.Dispose(); + } + } + + /// /// The mixed color value for the image. /// /// @@ -2307,6 +2417,7 @@ namespace Tizen.NUI.BaseComponents internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet(); internal static readonly int PlaceHolderUrl = Interop.ImageView.PlaceHolderImageGet(); internal static readonly int TransitionEffect = Interop.ImageView.TransitionEffectGet(); + internal static readonly int TransitionEffectOption = Interop.ImageView.TransitionEffectOptionGet(); internal static void Preload() { diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs index a4e3b9b..d2ee098 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageViewBindableProperty.cs @@ -668,5 +668,26 @@ namespace Tizen.NUI.BaseComponents return ret; } + + /// + /// TransitionEffectOptionProperty + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty TransitionEffectOptionProperty = null; + + internal static void SetInternalTransitionEffectOptionProperty(BindableObject bindable, object oldValue, object newValue) + { + var instance = (Tizen.NUI.BaseComponents.ImageView)bindable; + if (newValue != null) + { + instance.InternalTransitionEffectOption = (Tizen.NUI.PropertyMap)newValue; + } + } + + internal static object GetInternalTransitionEffectOptionProperty(BindableObject bindable) + { + var instance = (Tizen.NUI.BaseComponents.ImageView)bindable; + return instance.InternalTransitionEffectOption; + } } } diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PlaceHolderImageTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PlaceHolderImageTest.cs index a8acc8c..3b55136 100644 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PlaceHolderImageTest.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PlaceHolderImageTest.cs @@ -68,6 +68,7 @@ namespace Tizen.NUI.Samples imageViews[i].ResourceUrl = url[i]; imageViews[i].PlaceHolderUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "images/placeholder_image.png"; imageViews[i].TransitionEffect = true; + imageViews[i].SetTransitionEffectOption(0.0f, 1.0f, 0.0f, 3.0f, AlphaFunction.BuiltinFunctions.EaseInOut); mainWin.Add(imageViews[i]); } -- 2.7.4