예제 #1
0
파일: Hands.cs 프로젝트: tswaters/clocker
        /// <summary>
        /// Draw hands on the clock
        /// </summary>
        /// <param name="graphics">Graphics context</param>
        public void Draw(IGraphicsService graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            var now = _dateTimeService.Now;
            var second = (now.Second / 60d);
            var minute = (now.Minute / 60d) + (second / 60d);
            var hourly = (now.Hour / 12d) + (minute / 12d);

            Array.ForEach(new DrawArgs[] {
                new DrawArgs
                {
                    Brush = _secondBrush,
                    Angle = second,
                    Length = Constants.SecondLength,
                    MaxWidthLength = Constants.SecondMaxWidthLength,
                    Width = Constants.SecondWidth
                },
                new DrawArgs
                {
                    Brush = _minuteBrush,
                    Angle = minute,
                    Length = Constants.MinuteLength,
                    MaxWidthLength = Constants.MinuteMaxWidthLength,
                    Width = Constants.MinuteWidth
                },
                new DrawArgs
                {
                    Brush = _hourlyBrush,
                    Angle = hourly,
                    Length = Constants.HourlyLength,
                    MaxWidthLength = Constants.HourlyMaxWidthLength,
                    Width = Constants.HourlyWidth
                }
            }, x =>
                graphics.FillPolygon(x.Brush, new PointF[] {
                    _mathService.GetPoint(x.Angle + Constants.QuarterCircle, Center.CircleSize / 2),
                    _mathService.GetPoint(x.Angle + x.Width, x.Length * x.MaxWidthLength),
                    _mathService.GetPoint(x.Angle, x.Length),
                    _mathService.GetPoint(x.Angle - x.Width, x.Length * x.MaxWidthLength),
                    _mathService.GetPoint(x.Angle - Constants.QuarterCircle, Center.CircleSize / 2)
                })
            );
        }