private void StartTransition(VisualView view, VisualMap target, string property, bool activate) { if (_animation) { _animation.Stop(); _animation.Finished += OnTransitionFinished; } if (activate) { if (property == "Position") { _animation = view.AnimateVisual(target, property, new Position2D(20, 20), 0, 1000, AlphaFunction.BuiltinFunctions.Linear, new Position2D(40, 40)); } else if (property == "Opacity") { _animation = view.AnimateVisual(target, property, 0.0f, 0, 1000, AlphaFunction.BuiltinFunctions.Linear); } else if (property == "MixColor") { _animation = view.AnimateVisual(target, property, Color.Green, 0, 1000, AlphaFunction.BuiltinFunctions.Linear); } } else { if (property == "Position") { _animation = view.AnimateVisual(target, property, new Position2D(5, 5), 0, 1000); } else if (property == "Opacity") { _animation = view.AnimateVisual(target, property, 1.0f, 0, 1000); } else if (property == "MixColor") { _animation = view.AnimateVisual(target, property, Color.Red, 0, 1000); } } if (_animation) { _animation.Finished += OnTransitionFinished; _transitionInProgress = true; _animation.Play(); } }
/// <summary> /// Move selector to certain direction /// </summary> /// <param name="moveOnly">whether only move</param> /// <param name="instant">Whether instant,default is false</param> /// <param name="direction">move direction</param> private void MoveSelector(bool moveOnly, bool instant = false, View.FocusDirection direction = View.FocusDirection.Right) { int targetIconPosition = _focusedIcon; int viewIcon = targetIconPosition; int showSelectorStartTime = 0; bool delaySelectorPositionChange = false; if (!moveOnly) { switch (direction) { case View.FocusDirection.Left: { if (_active) { _focusedIcon = _maxIconIndex; targetIconPosition = _focusedIcon; } break; } case View.FocusDirection.Right: { if (!_active) { targetIconPosition = _maxIconIndex + 1; _focusedIcon = -1; } break; } case View.FocusDirection.Up: { if (!_active) { instant = true; targetIconPosition = _maxIconIndex + 1; } break; } case View.FocusDirection.Down: { if (_active) { if (_focusedIcon == -1) { _focusedIcon = _maxIconIndex; targetIconPosition = _focusedIcon; } showSelectorStartTime = Constants.SystemMenuAnimationDuration; delaySelectorPositionChange = true; } break; } } viewIcon = _focusedIcon; if (viewIcon > _maxIconIndex) { viewIcon = _maxIconIndex; } if (viewIcon == -1) { viewIcon = 0; } } float selectorWidth = (Constants.SystemMenuWidth / (float)_systemIcons.Length); float iconX = _active ? (Constants.SystemMenuWidth / (float)_systemIcons.Length) * (float)(targetIconPosition - (_systemIcons.Length / 2)) : (Constants.SystemMenuWidth - selectorWidth); int startTime = 0; _systemSelectorAnimation.Clear(); // Handle the selector color & transparency. if (instant) { // We are hiding instantly, set the color to transparent and set the position directly (without animating). _systemSelectorColor.Color = new Color(1.0f, 1.0f, 1.0f, 0.0f); _systemSelector.PositionX = iconX; } else { // We animate the fade if we are showing, or if we are hiding *gradually* - IE. not moving the position instantly. Color targetColor = _active ? _systemSelectorColors[viewIcon] : new Color(1.0f, 1.0f, 0.0f, 0.0f); // We set the endtime to starttime + duration so, if necessary, the selector animation can start *after* the menu animation ends _systemSelectorAnimation = _systemSelector.AnimateVisual(_systemSelectorColor, "mixColor", targetColor, showSelectorStartTime, showSelectorStartTime + Constants.SystemMenuAnimationDuration, AlphaFunction.BuiltinFunctions.EaseOutSine); if (delaySelectorPositionChange) { startTime = Constants.SystemMenuSelectorAnimationDuration; } // We allow the start time to be modified but fix the end time. // This allows us to delay a property set if required (by starting and finishing the animation after the menu animation ends). _systemSelectorAnimation.AnimateTo(_systemSelector, "PositionX", iconX, startTime, Constants.SystemMenuSelectorAnimationDuration, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine)); _systemSelectorAnimation.Play(); } }