Esempio n. 1
0
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            m_hwnd = new WindowInteropHelper(this).Handle;

            Int32 windowStyle = GetWindowLongPtr(m_hwnd, GWL_STYLE);

            SetWindowLongPtr(m_hwnd, GWL_STYLE, windowStyle & ~WS_MAXIMIZEBOX);

            m_bIsSupportTaskbarManager = true;
            this.TaskbarItemInfo.ThumbnailClipMargin = new Thickness(0, 0, 0, 0);

            try
            {
                DateTime restoreStart = DateTime.Parse(TomatoTimerWPF.TimerSettings.Default.TimerRestoreDateTime);
                m_TimeDateStart      = restoreStart;
                m_TimeDatePauseStart = restoreStart;
                //m_TimeDateStart = DateTime.Now;
                //m_TimeDatePauseStart = DateTime.Now;

                m_mode = (TimerMode)TomatoTimerWPF.TimerSettings.Default.TimerRestoreMode;
            }
            catch (Exception)
            {
                m_TimeDateStart      = DateTime.Now;
                m_TimeDatePauseStart = DateTime.Now;
            }

            m_pageButtons       = new Page_Buttons(this);
            m_pageSettings      = new Page_Settings(this);
            m_pageSoundSettings = new Page_SoundSettings(this);

            btnAlwaysOnTop.IsChecked = TomatoTimerWPF.TimerSettings.Default.AlwaysOnTop;
            if (btnAlwaysOnTop.IsChecked == true)
            {
                this.ToggleAlwaysOnTop();
            }

            spWindowControlStackPanel.Margin = new Thickness(0, -this.Height, 0, 0);
            m_sbAniOut.Begin(spWindowControlStackPanel);

            this.ucContent.Children.Add(m_pageButtons);
            UpdateUI();

            m_timer          = new System.Windows.Forms.Timer();
            m_timer.Interval = 1000;
            m_timer.Tick    += new EventHandler(Timer_Tick);
            m_timer.Start();
        }
Esempio n. 2
0
        private void Storyboard_Completed(object sender, EventArgs e)
        {
            if (pages.Count != 0)
            {
                UserControl page = pages.Pop();

                Page_Buttons pageButtons = page as Page_Buttons;
                if (pageButtons != null)
                {
                    UpdateUI();
                    btnAlwaysOnTop.Visibility = Visibility.Visible;
                }
                else
                {
                    btnAlwaysOnTop.Visibility = Visibility.Collapsed;
                }
                ucContent.Children.Clear();
                ucContent.Children.Add(page);

                m_sbAniIn.Begin(page);
            }
        }
Esempio n. 3
0
        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.GetIsMouseDown())
                {
                    if (pageButtons.btnRelax.IsPressed)
                    {
                        progressValue = pageButtons.GetLongMouseDownPercentage();
                        pageButtons.labelTime_small.Content = progressValue >= 100 ? "Long rest" : time;
                    }
                    else if (pageButtons.btnReset.IsPressed && m_mode == TimerMode.MODE_WORK)
                    {
                        progressValue = pageButtons.GetLongMouseDownPercentage();
                        pageButtons.labelTime_small.Content = progressValue >= 100 ? "Skip GCal" : time;
                    }
                    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.DarkRed, 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;
                    if (this.TaskbarItemInfo.ProgressValue != 1)
                    {
                        this.TaskbarItemInfo.ProgressValue = 1;
                    }
                }
                else if (m_bIsOverTime)
                {
                    if (m_mode == TimerMode.MODE_WORK)
                    {
                        this.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Paused;
                    }
                    else
                    {
                        this.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error;
                    }
                    if (this.TaskbarItemInfo.ProgressValue != 1)
                    {
                        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.Collapsed;
                    ThumbButtonTakeABreak.Visibility = Visibility.Visible;
                    ThumbButtonPause.Visibility      = !m_bIsPause ? Visibility.Visible : Visibility.Collapsed;
                    ThumbButtonPlay.Visibility       = m_bIsPause ? Visibility.Visible : Visibility.Collapsed;
                }
                else
                {
                    ThumbButtonGoToWork.Visibility   = Visibility.Visible;
                    ThumbButtonTakeABreak.Visibility = Visibility.Collapsed;
                    ThumbButtonPause.Visibility      = Visibility.Collapsed;
                    ThumbButtonPlay.Visibility       = Visibility.Collapsed;
                }
            }
        }