/// <summary> /// Creates an animation entry reading info from the xml node /// </summary> /// <param name="xmlNode">The input xml node</param> /// <returns>Animation entry</returns> private Animation createAndLoadAnimationEntry(XmlNode xmlNode) { var animation = new Animation(); animation.Load(xmlNode); return animation; }
/// <summary> /// Transition to the animation referred to by the /// animation object /// </summary> /// <param name="animation">target animation object</param> public void Transition(Animation animation) { try { Log.Debug("Transition( " + animation.Name + "). _currentPanel: " + _currentPanel.Name); _player.Transition(animation); } catch (Exception ex) { Log.Debug(ex.ToString()); } }
/// <summary> /// Event handler for when an actuator switch is down /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void actuatorManager_EvtSwitchDown(object sender, ActuatorSwitchEventArgs e) { setSwitchState(true); if (_player != null) { _switchDownAnimation = _player.CurrentAnimation; var widget = _player.HighlightedWidget; if (widget != null) { Log.Debug("Highlighted widget: " + widget.UIWidget.Name); _switchDownHighlightedWidget = widget; } else { _switchDownHighlightedWidget = null; } } }
/// <summary> /// Starts the animation sequence for the specified panel. It starts /// with the animation that has the 'start' attribute set to true in /// the xml file /// </summary> /// <param name="panelWidget">Which panel to start the animations for?</param> /// <param name="animationName">Name of the animation sequence</param> public void Start(Widget panelWidget, String animationName = null) { Log.Debug("Start animation for panel " + panelWidget.Name); if (_player != null) { _player.EvtPlayerStateChanged -= _player_EvtPlayerStateChanged; _player.Dispose(); } resetSwitchEventStates(); _currentPanel = panelWidget; subscribeToMouseClickEvents(panelWidget); _player = new AnimationPlayer(panelWidget, _interpreter, _variables); _player.EvtPlayerStateChanged += _player_EvtPlayerStateChanged; _variables.Set(Variables.SelectedWidget, panelWidget); _variables.Set(Variables.CurrentPanel, panelWidget); // get all the animations for the specified animation name. var animations = getAnimations(animationName); if (animations == null) { Log.Error("Could not find animations entry for panel " + panelWidget.Name); return; } // transition to the one that is marked as "first" var firstAnimation = animations.GetFirst(); if (firstAnimation == null) { return; } foreach (var animation in animations.Values) { animation.EvtResolveWidgetChildren += animation_EvtResolveWidgetChildren; } _firstAnimation = firstAnimation; Transition(firstAnimation); }
/// <summary> /// Sets all the variables related to switch events /// </summary> private void resetSwitchEventStates() { _switchDownHighlightedWidget = null; _switchAcceptedHighlightedWidget = null; _switchDownAnimation = null; _switchAcceptedAnimation = null; }
/// <summary> /// Transitions to the specified target animation. Stops the current /// animation and starts the new one. /// </summary> /// <param name="animation">Animation to transition to</param> public void Transition(Animation animation) { if (_syncObj == null) { Log.Debug("_syncObj is null. returning"); return; } try { _lastIteration = false; _timer.Stop(); Log.Debug("Transition to " + animation.Name); setPlayerState(PlayerState.Stopped); Log.Debug("Transition : Before Enter " + _rootWidget.UIControl.Name + ", threadid: " + GetCurrentThreadId()); enter(_transitionSync); Log.Debug("Transition : After Enter " + _rootWidget.UIControl.Name + ", status: " + _syncObj.Status); if (_syncObj.Status == SyncLock.StatusValues.Closing || _syncObj.Status == SyncLock.StatusValues.Closed) { Log.Debug("FORM IS CLOSING. releasing _transitionSync and returning" + _rootWidget.UIControl.Name); release(_transitionSync); return; } _rootWidget.HighlightOff(); if (_currentAnimation != null) { _currentAnimation.Stop(); } _currentAnimation = animation; _currentAnimation.ResolveUIWidgetsReferences(_rootWidget, _variables); _currentAnimation.OnEnterExecutionNotDone = true; _iterationCount = 0; _currentWidgetIndex = getFirstAnimatedWidget(); _highlightedWidget = null; Log.Debug("Transition : Before Release" + _rootWidget.UIControl.Name); release(_transitionSync); Log.Debug("Transition : After Release" + _rootWidget.UIControl.Name); Log.Debug("Start new animation " + animation.Name); if (!animation.AutoStart && animation.OnStart) { animation.OnStart = false; setPlayerState(PlayerState.Timeout); } else if (_timer != null) { _timer.Interval = _currentAnimation.SteppingTime; Log.Debug(_rootWidget.UIControl.Name + ", syncobj.status " + _syncObj.Status); if (_syncObj.Status == SyncLock.StatusValues.None) { timer_Elapsed(null, null); Log.Debug("Starting timer " + _rootWidget.UIControl.Name); _timer.Start(); } else { Log.Debug("******** WILL NOT START TIMER!!!" + _rootWidget.UIControl.Name + ", syncobj.status " + _syncObj.Status); } setPlayerState(PlayerState.Running); } } catch (Exception ex) { Log.Debug(ex.ToString()); } Log.Debug("Returning"); }
/// <summary> /// Resumes paused player and transitions to the /// animation /// </summary> /// <param name="animation">transition to this animation</param> public void Resume(Animation animation) { Log.Debug("Resume(" + _rootWidget.Name + ") +, state: " + _playerState); if ((_playerState == PlayerState.Paused || _playerState == PlayerState.Timeout || _playerState == PlayerState.Interrupted) && _timer != null) { setPlayerState(PlayerState.Running); Log.Debug("In ResumeCalling player transition"); Transition(animation); } }
/// <summary> /// Initializes the player /// </summary> /// <param name="rootWidget">root widget for the scanner</param> /// <param name="interpreter">the interpreter object</param> /// <param name="variables">variables and their values</param> public AnimationPlayer(Widget rootWidget, Interpret interpreter, Variables variables) { Log.Debug("CTOR(" + rootWidget.Name + ")"); if (rootWidget.UIControl is IPanel) { _syncObj = ((IPanel) rootWidget.UIControl).SyncObj; } _transitionSync = _syncObj; _interpreter = interpreter; _timer = new System.Timers.Timer(); _timer.Elapsed += timer_Elapsed; _highlightedWidget = null; _currentAnimation = null; _rootWidget = rootWidget; _playerState = PlayerState.Stopped; _variables = variables; _inTimer = false; IsSwitchActive = false; }