Beispiel #1
0
        private void SelectAppropriateButtons()
        {
            this.selectedHoursButton           = this.GetClockButtonForTime(ClockItemMember.Hours);
            this.selectedHoursButton.IsChecked = true;

            this.selectedMinutesButton           = this.GetClockButtonForTime(ClockItemMember.Minutes);
            this.selectedMinutesButton.IsChecked = true;
        }
Beispiel #2
0
        public void OnButtonDragDelta(ClockButton sender, DragDeltaEventArgs e)
        {
            this.dragPosition = new Point(
                this.dragPosition.X + e.HorizontalChange,
                this.dragPosition.Y + e.VerticalChange);

            Point delta = new Point(
                this.dragPosition.X - this.canvasCenter.X,
                this.dragPosition.Y - this.canvasCenter.Y);

            var angle = Math.Atan2(delta.X, -delta.Y);

            if (angle < 0)
            {
                angle += 2 * Math.PI;
            }

            DateTime time;

            if (this.DisplayMode == ClockItemMember.Hours)
            {
                if (this.Is24HoursEnabled)
                {
                    double outerBoundary = this.canvasCenter.X * 0.75 + (this.canvasCenter.X * 1 - this.canvasCenter.X * 0.75) / 2;
                    double sqrt          = Math.Sqrt(
                        (this.canvasCenter.X - this.dragPosition.X) * (this.canvasCenter.X - this.dragPosition.X) +
                        (this.canvasCenter.Y - this.dragPosition.Y) * (this.canvasCenter.Y - this.dragPosition.Y));

                    bool localIsPostMeridiem = sqrt > outerBoundary;

                    int hour = (int)Math.Round(6 * angle / Math.PI, MidpointRounding.AwayFromZero) % 12 + (localIsPostMeridiem ? 12 : 0);

                    if (hour == 12)
                    {
                        hour = 0;
                    }
                    else if (hour == 0)
                    {
                        hour = 12;
                    }

                    time = new DateTime(this.Time.Year, this.Time.Month, this.Time.Day, hour, this.Time.Minute, this.Time.Second);
                }
                else
                {
                    time = new DateTime(this.Time.Year, this.Time.Month, this.Time.Day,
                                        (int)Math.Round(6 * angle / Math.PI, MidpointRounding.AwayFromZero) % 12 +
                                        (this.IsPostMeridiem ? 12 : 0), this.Time.Minute, this.Time.Second);
                }
            }
            else
            {
                time = new DateTime(this.Time.Year, this.Time.Month, this.Time.Day, this.Time.Hour, (int)Math.Round(30 * angle / Math.PI, MidpointRounding.AwayFromZero) % 60, this.Time.Second);
            }

            this.Time = time;
        }
Beispiel #3
0
        private void GenerateButtons(Panel canvas, List <int> range, ClockItemMember mode, double innerRatio, string format)
        {
            double anglePerItem   = 360.0 / range.Count;
            double radiansPerItem = anglePerItem * (Math.PI / 180);

            if (canvas.Width < 10.0 || Math.Abs(canvas.Height - canvas.Width) > 0.0)
            {
                return;
            }

            this.canvasCenter = new Point(canvas.Width / 2, canvas.Height / 2);
            double hypotenuseRadius = this.canvasCenter.X * innerRatio;

            foreach (int value in range)
            {
                double adjacent = Math.Cos(value * radiansPerItem) * hypotenuseRadius;
                double opposite = Math.Sin(value * radiansPerItem) * hypotenuseRadius;

                double centerX = this.canvasCenter.X + opposite;
                double centerY = this.canvasCenter.Y - adjacent;

                ClockButton button = new ClockButton(mode, value, centerX, centerY, innerRatio < 1.0, this)
                {
                    Content = (value == 60 ? 0 : (value == 24 ? 0 : value)).ToString(format),
                };

                if (innerRatio < 1.0)
                {
                    button.TextOpacity = 0.7;
                    button.FontSize    = 11;
                }

                if (mode == ClockItemMember.Minutes && (value % 5 != 0))
                {
                    button.Width  = 10;
                    button.Height = 10;
                    button.Style  = this.FindResource <Style>("HintClockButtonStyle");
                }
                else
                {
                    button.Width  = 40;
                    button.Height = 40;
                }

                Canvas.SetLeft(button, centerX - button.Width / 2);
                Canvas.SetTop(button, centerY - button.Height / 2);

                canvas.Children.Add(button);
            }
        }
Beispiel #4
0
        public void OnButtonTapped(ClockButton sender)
        {
            if (sender.Mode == ClockItemMember.Hours)
            {
                int hour = sender.Value;
                if (this.Is24HoursEnabled)
                {
                    if (hour == 12)
                    {
                        hour = 0;
                    }
                    else if (hour == 0)
                    {
                        hour = 12;
                    }
                }
                else
                {
                    hour = (hour % 12);
                    if (this.IsPostMeridiem)
                    {
                        hour += 12;
                    }
                }

                this.Time        = new DateTime(this.Time.Year, this.Time.Month, this.Time.Day, hour, this.Time.Minute, 0);
                this.DisplayMode = ClockItemMember.Minutes;

                if (this.selectedHoursButton != null)
                {
                    this.selectedHoursButton.IsChecked = false;
                }
                this.selectedHoursButton = sender;
            }
            else
            {
                int minute = sender.Value % 60;
                this.Time = new DateTime(this.Time.Year, this.Time.Month, this.Time.Day, this.Time.Hour, minute, 0);

                if (this.selectedMinutesButton != null)
                {
                    this.selectedMinutesButton.IsChecked = false;
                }
                this.selectedMinutesButton = sender;
            }

            this.CheckButton(sender);
        }
Beispiel #5
0
        private void CheckButton(ClockButton button)
        {
            button.IsChecked = !button.IsChecked;
            if (button.Mode != ClockItemMember.Hours)
            {
                return;
            }

            if (button.IsInner)
            {
                // line usually goes from the center (100, 100) to the middle top (100,0)
                // but here, we want to adjust Y2 to use the inner ratio
                this.hoursLine.Y2 = (1 - InnerRatio) * this.hoursCanvas.Height / 2;
            }
            else
            {
                this.hoursLine.Y2 = 0;
            }
        }
Beispiel #6
0
 public void OnButtonDragCompleted(ClockButton sender, DragCompletedEventArgs e)
 {
     this.DisplayMode = ClockItemMember.Minutes;
 }
Beispiel #7
0
 public void OnButtonDragStarted(ClockButton sender, DragStartedEventArgs e)
 {
     this.dragPosition = new Point(e.HorizontalOffset, e.VerticalOffset);
 }