Exemple #1
0
        private void EndTimer()
        {
            timerFinished = true;
            FadeInBkgRectAnimation.Begin();
            FadeOutBackgroundTimer.Begin();
            ScaleBkgRect.ScaleX    = 0.2;
            ScaleBkgRect.ScaleY    = 0.2;
            RotateBkgRect.Duration = 3000;
            RotateBkgRect.Value    = -100;

            FadeOutClockAnimation.Begin();

            doneGrid.Visibility = Visibility.Visible;
            FadeInDoneButton.Begin();
        }
Exemple #2
0
        private void Timer_Tick(object sender, object e)
        {
            prevTime = currTime;
            currTime = DateTime.Now;

            int extraTicks = 0;

            if (timerFinished)
            {
                if (!outroSmall)
                {
                    if (outroLoopCount >= 10)
                    {
                        soundPlayer.PlayRandomSound();
                        outroLoopCount = 0;
                    }

                    ScaleBkgRect.ScaleX   = 1.2;
                    ScaleBkgRect.ScaleY   = 1.2;
                    RotateBkgRect.Value  -= 110;
                    LightBkgRect.Distance = 100;
                    outroSmall            = true;
                    return;
                }
                else
                {
                    ScaleBkgRect.ScaleX   = 0.7;
                    ScaleBkgRect.ScaleY   = 0.7;
                    RotateBkgRect.Value  -= 60;
                    LightBkgRect.Distance = 30;
                    outroLoopCount++;
                    outroSmall = false;
                    return;
                }
            }

            if (!timerCanStart)
            {
                if (introCount == 0)
                {
                    FadeInBkgRectAnimation.Begin();
                }

                if (introCount < 3)
                {
                    if (Settings.Current.SoundModeIndex > 0)
                    {
                        soundPlayer.PlaySound((Settings.Current.SoundModeIndex - 1) * 2);
                    }

                    RotateBkgRect.Value   += 90;
                    ScaleBkgRect.ScaleX   += 0.15;
                    ScaleBkgRect.ScaleY   += 0.15;
                    LightBkgRect.Distance += 15;

                    introCount++;

                    FadeOutClockAnimation.Begin();

                    return;
                }
                else
                {
                    if (Settings.Current.SoundModeIndex > 0)
                    {
                        soundPlayer.PlaySound(((Settings.Current.SoundModeIndex - 1) * 2) + 1);
                    }

                    clockGrid.Opacity = 1;
                    FadeOutBkgRectAnimation.Begin();
                    RotateBkgRect.Value += 150;
                    ScaleBkgRect.ScaleX += 1.5;
                    ScaleBkgRect.ScaleY += 1.5;

                    if (Settings.Current.PlacementModeIndex == 1)
                    {
                        OffsetClock.StartAnimation();
                        ScaleClock.StartAnimation();
                    }

                    timerCanStart = true;

                    pauseButton.Visibility = Visibility.Visible;
                    FadeInPauseButtonAnimation.Begin();
                }
            }

            // in order to keep the clock honest, we check that the current tick time and
            // previous tick time are less than 2 seconds apart
            // this is important in case the app gets minimized,
            // which sometimes causes the tick code to not run
            if ((currTime - prevTime) > TimeSpan.FromSeconds(2))
            {
                TimeSpan diffTime = currTime - prevTime;

                double diffTotalSeconds = Math.Floor(diffTime.TotalSeconds);

                // keep track of extra needed ticks
                // we'll need these to catch up the background animation
                extraTicks = (int)diffTotalSeconds;

                // if we haven't passed a minute mark, simply decrement the seconds wiht the diff time
                if (diffTotalSeconds <= countdownCurrTime.Seconds)
                {
                    countdownCurrTime.Seconds -= diffTime.Seconds;
                }
                else
                {
                    // otherwise, do some math to figure out how many minutes and seconds to decrement
                    int diffMinutes = ((int)Math.Floor((diffTotalSeconds - countdownCurrTime.Seconds) / 60) + 1);
                    int diffSeconds = ((int)diffTotalSeconds - countdownCurrTime.Seconds - (60 * (diffMinutes - 1)));

                    countdownCurrTime.Minutes -= diffMinutes;
                    countdownCurrTime.Seconds  = 60 - diffSeconds;
                }
            }

            if (countdownCurrTime.Seconds <= 0)
            {
                if (countdownCurrTime.Minutes <= 0)
                {
                    EndTimer();
                    return;
                }
                countdownCurrTime.Minutes--;
                countdownCurrTime.Seconds = 59;
            }
            else
            {
                countdownCurrTime.Seconds--;
            }

            // increment the elapsed time percentage to update the background animation
            if (extraTicks > 0)
            {
                // something got off, so we need to account for the lost time
                // by artificially adding extra ticks
                for (int i = 0; i < extraTicks; i++)
                {
                    timeBackground.TimeElapsedPercentage += percentageInterval;
                }

                // reset our extra ticks variable
                extraTicks = 0;
            }
            else
            {
                // just a normal tick
                timeBackground.TimeElapsedPercentage += percentageInterval;
            }

            // update the clock
            clockMinuteText.Text = ((countdownCurrTime.Minutes < 10 && !minutesOnly) ? "0" : "") + countdownCurrTime.Minutes.ToString();
            clockSecondText.Text = ((countdownCurrTime.Seconds < 10) ? "0" : "") + countdownCurrTime.Seconds.ToString();
        }