public void StartRelax() { if (m_bIsOverTime && m_mode == TimerMode.MODE_WORK && TomatoTimerWPF.TimerSettings.Default.GoogleCal_EnableEvent) { OpenGoogleCalender(m_TimeDateStart, DateTime.Now); } SetWindowFlash(false); m_TimeDateStart = DateTime.Now; m_TimeDatePauseStart = DateTime.Now; m_TimeSpanPause = TimeSpan.FromMinutes(0); m_TimeSpan = TimeSpan.FromMinutes(0); m_mode = TimerMode.MODE_RELAX; if (m_pageButtons != null) { if (m_pageButtons.GetIsLongMouseDown()) { m_mode = TimerMode.MODE_RELAX_LONG; } } m_bIsPause = false; //if (menuClose.Visibility == System.Windows.Visibility.Visible) //{ // menuClose.Visibility = System.Windows.Visibility.Collapsed; // btnClose.Visibility = System.Windows.Visibility.Visible; //} UpdateUI(); }
public void UpdateUI() { TimeSpan pauseSpan = m_TimeSpanPause; if (m_bIsPause) { pauseSpan += DateTime.Now - m_TimeDatePauseStart; } TimeSpan timerSpan, modeSpan; if (m_mode == TimerMode.MODE_WORK) { modeSpan = TimeSpan.FromMinutes(TomatoTimerWPF.TimerSettings.Default.Work_Time) + 800.Milliseconds(); } else if (m_mode == TimerMode.MODE_RELAX) { modeSpan = TimeSpan.FromMinutes(TomatoTimerWPF.TimerSettings.Default.Relax_Time) + 800.Milliseconds(); } else if (m_mode == TimerMode.MODE_RELAX_LONG) { modeSpan = TimeSpan.FromMinutes(TomatoTimerWPF.TimerSettings.Default.Relax_Time_Long) + 800.Milliseconds(); } else { modeSpan = 1.Seconds(); } if (m_bIsPause) { timerSpan = modeSpan - m_TimeSpan; } else { timerSpan = modeSpan - (DateTime.Now - m_TimeDateStart); } if (!m_bIsOverTime && timerSpan.IsNegativeOrZero()) { SetWindowFlash(true); if (m_mode == TimerMode.MODE_WORK) { m_pageSoundSettings.playSound(Page_SoundSettings.SoundType.WorkDone); } else { m_pageSoundSettings.playSound(Page_SoundSettings.SoundType.RestTimeOut); } } m_bIsOverTime = timerSpan.IsNegativeOrZero(); double progressValue = 100.0 - ((timerSpan.TotalMilliseconds * 100.0 / modeSpan.TotalMilliseconds)); if (progressValue < 0.0) { progressValue = 0.0; } else if (progressValue > 100.0) { progressValue = 100.0; } Page_Buttons pageButtons = m_pageButtons;//pageTransitionControl.CurrentPage as Page_Buttons; if (pageButtons != null) { if (m_mode == TimerMode.MODE_WORK) { pageButtons.btnWork.Visibility = false.ToVisibility(); pageButtons.btnWork.IsEnabled = false; pageButtons.btnRelax.Visibility = true.ToVisibility(); pageButtons.btnRelax.IsEnabled = true; if (m_bIsPause) { pageButtons.btnPause.Visibility = false.ToVisibility(); pageButtons.btnPause.IsEnabled = false; pageButtons.btnPlay.Visibility = true.ToVisibility(); pageButtons.btnPlay.IsEnabled = true; pageButtons.labelTime.Opacity = 0.5; } else { pageButtons.btnPause.Visibility = (!m_bIsPause).ToVisibility(); pageButtons.btnPause.IsEnabled = (!m_bIsPause); pageButtons.btnPlay.Visibility = false.ToVisibility(); pageButtons.btnPlay.IsEnabled = false; pageButtons.labelTime.Opacity = 1; } } else { pageButtons.btnWork.Visibility = true.ToVisibility(); pageButtons.btnWork.IsEnabled = true; pageButtons.btnRelax.Visibility = false.ToVisibility(); pageButtons.btnRelax.IsEnabled = false; pageButtons.btnPause.Visibility = false.ToVisibility(); pageButtons.btnPause.IsEnabled = false; pageButtons.btnPlay.Visibility = false.ToVisibility(); pageButtons.btnPlay.IsEnabled = false; pageButtons.labelTime.Opacity = 1; } String info, time; if (m_TimeDateStart.Day != DateTime.Now.Day || m_TimeDateStart.Month != DateTime.Now.Month) { info = m_TimeDateStart.ToString("MM/dd H:mm"); } else { info = "Start @ " + m_TimeDateStart.ToString("H:mm"); } if (!pauseSpan.IsNegativeOrZero()) { if (pauseSpan.Hours != 0 || pauseSpan.Days != 0) { info += "\r\nPause: {0}:{1:00}:{2:00}".ToFormat(Math.Abs(pauseSpan.Hours + pauseSpan.Days * 24), Math.Abs(pauseSpan.Minutes), Math.Abs(pauseSpan.Seconds)); } else { info += "\r\nPause: {0}:{1:00}".ToFormat(Math.Abs(pauseSpan.Minutes), Math.Abs(pauseSpan.Seconds)); } } pageButtons.labelInfo.Content = info; TextBlock timeText = new TextBlock(); if (m_mode == TimerMode.MODE_WORK) { time = "Work "; //timeText.Inlines.Add(new Bold(new Run("W"))); timeText.Inlines.Add("Work "); } else if (m_mode == TimerMode.MODE_RELAX || m_mode == TimerMode.MODE_RELAX_LONG) { time = "Rest "; //timeText.Inlines.Add(new Bold(new Run("R"))); timeText.Inlines.Add("Rest "); } else { time = ""; } if (timerSpan.Hours != 0 || timerSpan.Days != 0) { if ((timerSpan.Seconds & 0x1) == 0) { time += "{0}:{1:00} {2:00}".ToFormat(Math.Abs(timerSpan.Hours + timerSpan.Days * 24), Math.Abs(timerSpan.Minutes), Math.Abs(timerSpan.Seconds)); } else { time += "{0}:{1:00}:{2:00}".ToFormat(Math.Abs(timerSpan.Hours + timerSpan.Days * 24), Math.Abs(timerSpan.Minutes), Math.Abs(timerSpan.Seconds)); } timeText.Inlines.Add("{0}:{1:00}".ToFormat(Math.Abs(timerSpan.Hours + timerSpan.Days * 24), Math.Abs(timerSpan.Minutes))); //Run minText = new Run("{0:00}".ToFormat(Math.Abs(timerSpan.Minutes))); //minText.FontFamily = new System.Windows.Media.FontFamily("/TomatoTimerWPF;component/Resource/#Roboto"); //minText.FontWeight = FontWeights.Black; //timeText.Inlines.Add(new Bold(minText)); timeText.Inlines.Add((timerSpan.Seconds & 0x1) == 0 ? ":" : " "); timeText.Inlines.Add("{0:00}".ToFormat(Math.Abs(timerSpan.Seconds))); } else { if ((timerSpan.Seconds & 0x1) == 0) { time += "{0} {1:00}".ToFormat(Math.Abs(timerSpan.Minutes), Math.Abs(timerSpan.Seconds)); } else { time += "{0}:{1:00}".ToFormat(Math.Abs(timerSpan.Minutes), Math.Abs(timerSpan.Seconds)); } Run minText = new Run("{0}".ToFormat(Math.Abs(timerSpan.Minutes))); minText.FontFamily = new System.Windows.Media.FontFamily("/TomatoTimerWPF;component/Resource/#Roboto"); minText.FontWeight = FontWeights.Black; timeText.Inlines.Add(new Bold(minText)); timeText.Inlines.Add((timerSpan.Seconds & 0x1) == 0?":":" "); timeText.Inlines.Add("{0:00}".ToFormat(Math.Abs(timerSpan.Seconds))); } if (pageButtons.labelTimeWhite.Visibility == Visibility.Visible) { pageButtons.labelTimeWhite.Content = time; pageButtons.labelTime.Content = time; } else { pageButtons.labelTime.Content = timeText; } if (pageButtons.GetIsLongMouseDown()) { if (pageButtons.btnRelax.IsPressed) { pageButtons.labelTime_small.Content = "Long rest"; } else if (pageButtons.btnReset.IsPressed && m_mode == TimerMode.MODE_WORK) { pageButtons.labelTime_small.Content = "Skip GCal"; } else { pageButtons.labelTime_small.Content = time; } } else { pageButtons.labelTime_small.Content = time; } if (m_bIsPause) { pageButtons.pbarTimer.Foreground = System.Windows.Media.Brushes.Green; pageButtons.pbarTimer.IsIndeterminate = true; pageButtons.pbarTimer.Value = progressValue; pageButtons.labelTimeWhite.Opacity = 0; } else if (m_bIsOverTime) { pageButtons.pbarTimer.Foreground = System.Windows.Media.Brushes.Red; pageButtons.pbarTimer.IsIndeterminate = false; pageButtons.pbarTimer.Value = 100; pageButtons.labelTimeWhite.Opacity = 1; } else { if (progressValue > 80) { pageButtons.pbarTimer.Foreground = System.Windows.Media.Brushes.Yellow; pageButtons.labelTimeWhite.Opacity = 0; } else { pageButtons.pbarTimer.Foreground = System.Windows.Media.Brushes.Green; pageButtons.labelTimeWhite.Opacity = 1; } pageButtons.pbarTimer.IsIndeterminate = false; pageButtons.pbarTimer.Value = progressValue; } } int tMin = timerSpan.Hours * 24 + timerSpan.Minutes; if (m_bIsSupportTaskbarManager) { if (m_OverlayIconLastMin != (tMin == 0 ? timerSpan.Seconds : tMin) + (timerSpan.IsNegativeOrZero() ? 1 : 0) + (m_bIsPause ? 3 : 1)) { Bitmap bmp = new Bitmap(16, 16); using (Graphics g = Graphics.FromImage(bmp)) { g.FillRectangle(System.Drawing.Brushes.Black, 0, 0, 16, 16); if (m_bIsPause) { g.FillRectangle(System.Drawing.Brushes.Gray, 1, 1, 14, 14); } else if (timerSpan.IsNegativeOrZero()) { g.FillRectangle(System.Drawing.Brushes.Red, 1, 1, 14, 14); } else if (m_mode == TimerMode.MODE_WORK) { g.FillRectangle(System.Drawing.Brushes.BlueViolet, 1, 1, 14, 14); } else { g.FillRectangle(System.Drawing.Brushes.MediumSeaGreen, 1, 1, 14, 14); } if (timerSpan.Hours != 0 || timerSpan.Days != 0) { if (Math.Abs(timerSpan.Hours + timerSpan.Days * 24) <= 99) { g.DrawString("{0:00}".ToFormat(Math.Abs(timerSpan.Hours + timerSpan.Days * 24)), new Font("Arial", 6), new SolidBrush(System.Drawing.Color.White), 2, -1); g.DrawString("{0:00}".ToFormat(Math.Abs(timerSpan.Minutes)), new Font("Arial", 6), new SolidBrush(System.Drawing.Color.White), 2, 6); } else { g.DrawString("99", new Font("Impact", 6), new SolidBrush(System.Drawing.Color.White), 2, -1); g.DrawString("59", new Font("Impact", 6), new SolidBrush(System.Drawing.Color.White), 2, 6); } } else if (tMin == 0 && !timerSpan.IsNegativeOrZero() && !m_bIsPause) { g.DrawString("{0:00}".ToFormat(Math.Abs(timerSpan.Seconds)), new Font("Courier New", 9), new SolidBrush(timerSpan.Seconds % 2 == 0 ? System.Drawing.Color.White : System.Drawing.Color.Black), -1, 0); } else { g.DrawString("{0:00}".ToFormat(Math.Abs(timerSpan.Minutes)), new Font("Courier New", 9), new SolidBrush(System.Drawing.Color.White), -1, 0); } IntPtr hBitmap = bmp.GetHbitmap(); this.TaskbarItemInfo.Overlay = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height)); DeleteObject(hBitmap); } m_OverlayIconLastMin = (tMin == 0 ? timerSpan.Seconds : tMin) + (timerSpan.IsNegativeOrZero() ? 1 : 0) + (m_bIsPause ? 3 : 1); } if (m_bIsPause) { this.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Indeterminate; this.TaskbarItemInfo.ProgressValue = 1; } else if (m_bIsOverTime) { this.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error; this.TaskbarItemInfo.ProgressValue = 1; } else { if (progressValue > 80) { this.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Paused; } else { this.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal; } this.TaskbarItemInfo.ProgressValue = progressValue / 100; } if (m_mode == TimerMode.MODE_WORK) { ThumbButtonGoToWork.Visibility = Visibility.Hidden; ThumbButtonTakeABreak.Visibility = Visibility.Visible; ThumbButtonPause.Visibility = !m_bIsPause ? Visibility.Visible : Visibility.Hidden; ThumbButtonPlay.Visibility = m_bIsPause ? Visibility.Visible : Visibility.Hidden; } else { ThumbButtonGoToWork.Visibility = Visibility.Visible; ThumbButtonTakeABreak.Visibility = Visibility.Hidden; ThumbButtonPause.Visibility = Visibility.Hidden; ThumbButtonPlay.Visibility = Visibility.Hidden; } } }