Example #1
0
        public void SwitchTimerMode(bool previous = false)
        {
            StopCountDown();

            if (previous)
            {
                timerModeIndex--;
                if (timerModeIndex < 0)
                {
                    timerModeIndex = timerModes.Length - 1;
                }
            }
            else
            {
                timerModeIndex++;
                if (timerModeIndex >= timerModes.Length)
                {
                    timerModeIndex = 0;
                }
            }
            currentTimerMode = timerModes[timerModeIndex];
            ResetTimer();
            this.descText.Content = currentTimerMode.Description;
            if (!string.IsNullOrWhiteSpace(currentTimerMode.AlertSoundFilePath))
            {
                alertSoundPlayer.Stop();
                alertSoundPlayer.Open(new Uri(currentTimerMode.AlertSoundFilePath));
            }
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();
            this.KeyDown          += MainWindow_KeyDown;
            this.MouseDoubleClick += MainWindow_MouseDoubleClick;
            this.preciseTimer      = new Stopwatch();

            timer = new DispatcherTimer(DispatcherPriority.Render)
            {
                Interval = TimeSpan.FromMilliseconds(10)
            };
            timer.Tick += Timer_Tick;


            timerModes = TimerMode.ReadFromConfig();
            if (timerModes.Length == 0)
            {
                timerModes = new TimerMode[]
                {
                    new TimerMode
                    {
                        Name               = "Default",
                        Description        = "Default Mode",
                        Duration           = TimeSpan.FromSeconds(10),
                        IsCountDown        = true,
                        TimeToAlert        = TimeSpan.Zero,
                        AlertSoundFilePath = ""
                    }
                };
            }

            timerModeIndex = -1;
            SwitchTimerMode(false);

            tickSoundPlayer.Open(new Uri("pack://siteoforigin:,,,/sounds/tick.mp3"));
            tickSoundPlayer.MediaEnded += TickSoundPlayer_MediaEnded;
        }