Exemple #1
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);
            }
        }
Exemple #2
0
 public void OnButtonDragCompleted(ClockButton sender, DragCompletedEventArgs e)
 {
     if (this.DisplayMode == ClockItemMember.Hours)
     {
         this.DisplayMode = ClockItemMember.Minutes;
     }
     else
     {
         if (this.TimeSelected != null)
         {
             this.TimeSelected(this, EventArgs.Empty);
         }
     }
 }
Exemple #3
0
        protected override void OnApplyTemplate()
        {
            this.textBlockHours = this.GetTemplateChild("PART_TextBlockHours") as TextBlock;
            if (this.textBlockHours == null)
            {
                throw new NotSupportedException("Could not find PART_TextBlockHours in the control template");
            }

            this.textBlockMinutes = this.GetTemplateChild("PART_TextBlockMinutes") as TextBlock;
            if (this.textBlockMinutes == null)
            {
                throw new NotSupportedException("Could not find PART_TextBlockMinutes in the control template");
            }

            var textBlockAmPm = this.GetTemplateChild("PART_TextBlockAmPmIndicator") as TextBlock;

            if (textBlockAmPm == null)
            {
                throw new NotSupportedException("Could not find PART_TextBlockAmPmIndicator in the control template");
            }
            textBlockAmPm.Tapped += (s, e) => this.IsPostMeridiem = !this.IsPostMeridiem;

            this.hoursCanvas = this.GetTemplateChild("PART_HoursCanvas") as Canvas;
            if (this.hoursCanvas == null)
            {
                throw new NotSupportedException("Could not find PART_HoursCanvas in the control template");
            }

            this.minutesCanvas = this.GetTemplateChild("PART_MinutesCanvas") as Canvas;
            if (this.minutesCanvas == null)
            {
                throw new NotSupportedException("Could not find PART_MinutesCanvas in the control template");
            }

            this.hoursLine = this.GetTemplateChild("PART_HoursLine") as Line;
            if (this.hoursLine == null)
            {
                throw new NotSupportedException("Could not find PART_HoursLine in the control template");
            }

            this.textBlockHours.Tapped   += (s, e) => this.DisplayMode = ClockItemMember.Hours;
            this.textBlockMinutes.Tapped += (s, e) => this.DisplayMode = ClockItemMember.Minutes;

            this.GenerateButtons();

            this.DisplayMode = ClockItemMember.Hours;
            this.UpdateHeaderDisplay();
            this.SelectAppropriateButtons();
        }
        public ClockButton(ClockItemMember mode, int value, double centerX, double centerY, bool isInner, IClock owner)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            this.Mode    = mode;
            this.IsInner = isInner;
            this.Value   = value;

            this.centerX = centerX;
            this.centerY = centerY;
            this.owner   = owner;
        }
Exemple #5
0
 protected override void OnKeyUp(KeyRoutedEventArgs e)
 {
     if (e.Key == VirtualKey.Up || e.Key == VirtualKey.Down)
     {
         this.DeltaCurrentDisplayMode(e.Key == VirtualKey.Up);
     }
     else if ((e.Key == VirtualKey.Enter || e.Key == VirtualKey.Right) && this.DisplayMode == ClockItemMember.Hours)
     {
         this.DisplayMode = ClockItemMember.Minutes;
     }
     else if (e.Key == VirtualKey.Left && this.DisplayMode == ClockItemMember.Minutes)
     {
         this.DisplayMode = ClockItemMember.Hours;
     }
 }
Exemple #6
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);
        }
Exemple #7
0
        private ClockButton GetClockButtonForTime(ClockItemMember member)
        {
            Canvas canvas;
            Func <ClockButton, bool> predicate;

            if (member == ClockItemMember.Hours)
            {
                canvas    = this.hoursCanvas;
                predicate = button =>
                {
                    int hours = this.Time.Hour;
                    if (this.Is24HoursEnabled)
                    {
                        if (hours == 0)
                        {
                            hours = 24;
                        }
                    }
                    else if (hours == 0)
                    {
                        hours = 12;
                    }
                    else if (hours > 12)
                    {
                        hours = hours - 12;
                    }

                    return(button.Value == hours);
                };
            }
            else
            {
                canvas    = this.minutesCanvas;
                predicate = button => button.Value % 60 == this.Time.Minute;
            }

            return(canvas.Children.OfType <ClockButton>().First(predicate));
        }
Exemple #8
0
 public void OnButtonDragCompleted(ClockButton sender, DragCompletedEventArgs e)
 {
     this.DisplayMode = ClockItemMember.Minutes;
 }
Exemple #9
0
 private void SetDisplayMode(ClockItemMember mode)
 {
     this.displayMode = mode;
     VisualStateManager.GoToState(this, mode == ClockItemMember.Hours ? "Normal" : "Minutes", true);
 }