예제 #1
0
        private void MinuteGrab_MouseMove(object sender, MouseEventArgs e)
        {
            if (MinuteGrabMouseIsDown)
            {
                // Use positions relative to the hours display (centre is fixed with clock centre).
                var mousePosition = e.GetPosition(EllipseHoursAm);

                // Use the position to calculate the angle and hence required time
                var a = GetAngle(mousePosition, EllipseHoursAm.Width / 2, EllipseHoursAm.Height / 2);

                var minute = a / MinuteHandDegreesPerMinute;


                minute = Math.Round(minute);

                // The current Minute will be in the range 0 to 59
                // Work out whether to transition up or down an hour

                var displayMinute = DisplayTime.Minute;

                if (displayMinute < 15 && minute > 45)
                {
                    // Drag transition back an hour
                    minute = minute - MinutesInHour;
                }
                else if (displayMinute > 45 && minute < 15)
                {
                    // Drag transition forward an hour
                    minute = minute + MinutesInHour;
                }

                DisplayTime = DisplayTime.AddMinutes(minute - DisplayTime.Minute);
            }
        }
예제 #2
0
        private void HourGrab_MouseMove(object sender, MouseEventArgs e)
        {
            if (hourGrabMouseIsDown)
            {
                // Use positions relative to the hours display (centre is fixed with clock centre).
                var mousePosition = e.GetPosition(EllipseHoursAm);

                // Use the position to calculate the angle and hence required time
                var a = GetAngle(mousePosition, EllipseHoursAm.Width / 2, EllipseHoursAm.Height / 2);

                var hour = a / HourHandDegreesPerHour;

                var minutes = Math.Round(hour * 60 % 60);
                hour = Math.Floor(hour);

                // The current hour will be in the range 0 to 11 (i.e. morning).
                // The current display time could be morning or afternoon and if the
                // display time is near midnight this could be a transition to another day.

                var dayOffset   = 0;
                var displayHour = DisplayTime.Hour;

                if (displayHour < 3 && hour > 9)
                {
                    // Drag transition back a day
                    dayOffset = -1;
                    hour     += HoursPerRevolution; // Adjust time to afternoon
                }
                else if (displayHour > 21 && hour < 3)
                {
                    // Drag transition forward a day
                    dayOffset = 1;
                }
                else if (displayHour > 9 && displayHour < 12 &&
                         hour < 3)
                {
                    // Drag transition between morning and afternoon
                    hour += HoursPerRevolution;
                }
                else if (displayHour >= 12)
                {
                    // Dragging in the afternoon

                    // Add 12 hours if not transition to am!
                    if (!(displayHour < 15 && hour > 9))
                    {
                        hour += HoursPerRevolution;
                    }
                }

                DisplayTime = DisplayTime.AddHours(hour - DisplayTime.Hour);
                DisplayTime = DisplayTime.AddMinutes(minutes - DisplayTime.Minute);
                if (dayOffset != 0)
                {
                    DisplayTime = DisplayTime.AddDays(dayOffset);
                }
            }
        }
예제 #3
0
        private void EllipseMinutes_MouseDown(object sender, MouseButtonEventArgs e)
        {
            mouseDownPoint = e.GetPosition(sender as IInputElement);

            // Use the down position to calculate the angle and hence required time
            var a = GetAngle(mouseDownPoint, EllipseMinutes.Width / 2, EllipseMinutes.Height / 2);

            var minutes = (int)Math.Round(a / MinuteHandDegreesPerMinute);

            DisplayTime = DisplayTime.AddMinutes(minutes - DisplayTime.Minute);

            // Now treat as a drag
            MinuteGrabMouseIsDown = true;
            Mouse.Capture(MinuteHandle);
        }