/// <summary> /// resets the variables needed to restart the animation /// </summary> private void ResetAnimation() { try { Children.RemoveRange(globalInitialChildCount, Children.Count); } catch (Exception e) { DebugMessageHandler.SetDebugMessage(this, e.Message); } globalInitialChildCount = -1; animationCurrentFrame = 0; ChildEllipseHolder.Clear(); ChildEllipsePointHolder.Clear(); //_dispatchTimer.Stop(); }
/// <summary> /// Indicates the way in which the pattern was drawn by means of animation /// </summary> /// <param name="stroke">The Collection of Expert Strokes</param> private void DisplayStrokesPatterns(Stroke stroke) { //if its the first run remember the default number of children and set AnimationPlaying to true; if (globalInitialChildCount < 0) { AnimationPlaying = true; globalInitialChildCount = this.Children.Count; DebugMessageHandler.SetDebugMessage(this, "Global Child count: " + globalInitialChildCount.ToString()); return; } //create a single large stroke collecting all the styluspoint collection //StylusPointCollection spc = new StylusPointCollection(); //for (int i = 0; i < stroke.Count; i++) //{ // spc.Add(stroke[i].StylusPoints); //} //Stroke s = new Stroke(spc); //if the animation frame of animation is less than the count of stylus points and the number of ellipses if (animationCurrentFrame < stroke.StylusPoints.Count + maxEllipses) { //if the animation frame is less than the number of children if (animationCurrentFrame < stroke.StylusPoints.Count - 1) { //get the styluspoint location according to the frame Point p = stroke.StylusPoints[animationCurrentFrame].ToPoint(); //add the point to the EllipseChildHolder ChildEllipsePointHolder.Add(p); //draw an ellipse in that point Ellipse ellipse = new Ellipse { Width = 10, Height = 10 }; double left = p.X - (ellipse.Width / 2); double top = p.Y - (ellipse.Height / 2); //change the color according to the sequence Color EllipseColor = Color.FromArgb(255, 128, 0, 128); ellipse.Fill = new SolidColorBrush(EllipseColor); ellipse.Margin = new Thickness(left, top, 0, 0); //this.Children.Insert(0,ellipse); ellipse.Tag = "animation"; this.Children.Add(ellipse); ChildEllipseHolder.Add(ellipse); } if (animationCurrentFrame >= maxEllipses) { try { //for making the following ellipse smaller. for (int i = ChildEllipseHolder.Count - 1; i > 0; i--) { ChildEllipseHolder[i].Width -= 0.25; ChildEllipseHolder[i].Height -= 0.25; ChildEllipseHolder[i].Margin = new Thickness( ChildEllipsePointHolder[i].X - ChildEllipseHolder[i].Width / 2, ChildEllipsePointHolder[i].Y - ChildEllipseHolder[i].Height / 2, 0, 0); } this.Children.RemoveAt(globalInitialChildCount); ChildEllipseHolder.RemoveAt(0); ChildEllipsePointHolder.RemoveAt(0); } catch { DebugMessageHandler.SetDebugMessage(this, "ExpertInkCanvas/ChildrenCount= " + this.Children.Count); } } animationCurrentFrame += 1; } else { AnimationPlaying = false; ResetAnimation(); } }