Example #1
0
        /// <summary>
        /// Close canvas.
        /// </summary>
        private void CloseSushiBar()
        {
            // Finish current animation.
            var currentHeight = this.AbortSushiBarAnimation();

            Debug.WriteLine("CloseSushiBar: Begin: " + showingState);

            canvasHeightAnimation = new DelegatedAnimation(
                this,
                new PropertyPath("(Canvas.Height)"),
                currentHeight,
                0,
                SushiRotatorResources.CanvasClosingDuration / SushiRotatorResources.CanvasHeight * currentHeight);

            canvasHeightAnimation.Completed += (s, e) =>
            {
                Debug.WriteLine("CloseSushiBar: Finished: " + showingState);

                if (showingState != ShowingStates.Closing)
                {
                    this.Visibility = Visibility.Collapsed;
                }
                showingState = ShowingStates.Closed;

                // Start reopen timer.
                canvasReopenTimer.Interval =
                    TimeSpan.FromMilliseconds(SushiRotatorResources.CanvasReopenDelay);
                canvasReopenTimer.Start();
            };

            // Start animation.
            showingState = ShowingStates.Closing;
            canvasHeightAnimation.Begin();
        }
Example #2
0
        /// <summary>
        /// Open canvas.
        /// </summary>
        private void OpenSushiBar()
        {
            // Finish current animation.
            var currentHeight = this.AbortSushiBarAnimation();

            Debug.WriteLine("OpenSushiBar: Begin: " + showingState);

            canvasHeightAnimation = new DelegatedAnimation(
                this,
                new PropertyPath("(Canvas.Height)"),
                currentHeight,
                SushiRotatorResources.CanvasHeight,
                SushiRotatorResources.CanvasReopenDuration / SushiRotatorResources.CanvasHeight * (SushiRotatorResources.CanvasHeight - currentHeight));

            canvasHeightAnimation.Completed += (s, e) =>
            {
                Debug.WriteLine("OpenSushiBar: Finished: " + showingState);
                showingState = ShowingStates.Opened;
            };

            // Start animation.
            this.Visibility = Visibility.Visible;
            showingState    = ShowingStates.Opening;
            canvasHeightAnimation.Begin();

            // Stop reopen timer.
            canvasReopenTimer.Stop();
        }
Example #3
0
        /// <summary>
        /// Timer reached (Generate sushi)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SushiGeneratorTimer_Tick(object sender, EventArgs e)
        {
            // Generate sushi.
            var element = this.GenerateSushi();

            this.Children.Add(element);

            this.ForceCalculate();

            // Calculate next timeout.
            var delay =
                r.Next(3000) +
                ((element.ActualWidth * 1.5) / SushiRotatorResources.PixelsPerSecond * 1000.0);

            // Create animation.
            var width = this.ActualWidth + 10;
            var sushiRotateAnimation = new DelegatedAnimation(
                element,
                new PropertyPath("(Canvas.Left)"),
                width,
                0 - width,
                width / SushiRotatorResources.PixelsPerSecond * 1000.0);

            sushiRotateAnimation.Completed += (s, e2) => this.Children.Remove(element);

            // Start animation.
            sushiRotateAnimation.Begin();

            // Schedule next timeout.
            sushiGeneratorTimer.Interval = TimeSpan.FromMilliseconds(delay);
            sushiGeneratorTimer.Start();
        }