/* * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System.Collections.Generic; using System; using System.ComponentModel; namespace Tizen.NUI { /// /// Define a List of LayoutTransitions /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public class TransitionList : List {} /// /// The properties that can be animated. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public enum AnimatableProperties { /// /// Position property. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] Position, /// /// Size property. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] Size, /// /// Opacity property. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] Opacity } /// /// Parts of the transition that can be configured to provide a custom effect. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public class TransitionComponents { /// /// TransitionComponents default constructor. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public TransitionComponents() { Delay = 0; Duration = 100; AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear); } /// /// TransitionComponents constructor. Stores delay, duration and AlphaFunction. /// /// The delay before the animator starts. /// the duration fo the animator. /// alpha function to use . /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public TransitionComponents(int delay, int duration, AlphaFunction alphaFunction) { Delay = delay; Duration = duration; AlphaFunction = alphaFunction; } /// /// Time the transition should execute. Milliseconds. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public int Duration; /// /// Delay before the transition executes. Milliseconds. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public int Delay; /// /// Function to alter the transition path over time. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public AlphaFunction AlphaFunction; } /// /// LayoutTransition stores the aninmation setting for a transition conidition. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public class LayoutTransition { /// /// LayoutTransition default constructor. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public LayoutTransition() { Condition = TransitionCondition.Unspecified; AnimatableProperty = AnimatableProperties.Position; Animator = null; TargetValue = 0; } /// /// LayoutTransition constructor. /// /// The animatable condition. /// the property to animate. /// target value of the property. /// Components to define the animator. /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public LayoutTransition( TransitionCondition condition, AnimatableProperties animatableProperty, object targetValue, TransitionComponents animator) { Condition = condition; AnimatableProperty = animatableProperty; Animator = animator; TargetValue = targetValue; } /// /// Condition for this Transition /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public TransitionCondition Condition{get; set;} /// /// Property to animate. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public AnimatableProperties AnimatableProperty{get; set;} /// /// Components of the Animator. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public TransitionComponents Animator{get; set;} /// /// Target value to animate to. /// /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed. [EditorBrowsable(EditorBrowsableState.Never)] public object TargetValue{get; set;} } /// /// Class to help manage the adding and updating of transitions. /// internal static class LayoutTransitionsHelper { /// /// Adds the given transition and condition to a transition list. /// /// The list to add the transition to. /// Condition for the transition. /// The transition to add. /// True is set explicitly, false if inherited. static public void AddTransitionForCondition( Dictionary targetTransitionList, TransitionCondition condition, LayoutTransition transition, bool explicitlySet) { bool replaced = false; bool conditionNotInDictionary = false; TransitionList transitionListMatchingCondition; if (targetTransitionList.TryGetValue(condition, out transitionListMatchingCondition)) { for (var index=0; index < transitionListMatchingCondition?.Count; index++ ) { if (transitionListMatchingCondition[index].AnimatableProperty == transition.AnimatableProperty) { if (explicitlySet) { transitionListMatchingCondition[index] = transition; replaced = true; continue; } } } } else { conditionNotInDictionary = true; } if (replaced == false) { if (transitionListMatchingCondition == null) { transitionListMatchingCondition = new TransitionList(); } transitionListMatchingCondition.Add(transition); // Update dictionary with new or replaced entry. if (conditionNotInDictionary) { targetTransitionList.Add(condition, transitionListMatchingCondition); // new entry } else { targetTransitionList[condition] = transitionListMatchingCondition; // replaced } } } /// /// Retreive the transition list for the given condition. /// /// The source collection of transition lists to retrieve. /// Condition for the transition. /// transition list to return as out parameter. /// True if a transition list found for the given condition> static public bool GetTransitionsListForCondition( Dictionary sourceTransitionCollection, TransitionCondition condition, TransitionList transitionsForCondition ) { TransitionCondition resolvedCondition = condition; bool matched = false; // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will // reposition to the new layout not to the insertion/removal of a sibling. if ((condition & TransitionCondition.LayoutChanged) == TransitionCondition.LayoutChanged) { resolvedCondition = TransitionCondition.LayoutChanged; } if (sourceTransitionCollection.TryGetValue(resolvedCondition, out transitionsForCondition)) { matched = true; } return matched; } /// /// Copy the transitions in the source list to the target list /// /// The source transition list. /// The target transition list to copy to. static public void CopyTransitions( TransitionList sourceTransitionList, TransitionList targetTransitionList ) { targetTransitionList.Clear(); foreach (LayoutTransition transitionToApply in sourceTransitionList) { // Overwite existing transitions targetTransitionList.Add(transitionToApply); } } } } // namespace Tizen.NUI