示例#1
0
        /// <summary>
        /// Draws the month header row.
        /// </summary>
        private void DrawMonthTitle(MonthInfo month, ref float topOffset)
        {
            // calcs the rect to draw the month title row
            SizeF      monthTitleRowSize = CalendarData.GetMonthTitleRowSize(MonthAreaSize);
            RectangleF monthRowRect      = new RectangleF(
                CalendarArea.X, CalendarArea.Y + topOffset,
                monthTitleRowSize.Width, monthTitleRowSize.Height);
            float borderWidth = CalendarData.MonthTitleBorderStyle.LineWidth.ToTwips() / 2;

            // get month name to draw
            string monthTitle = string.Format(CalendarData.Culture,
                                              CalendarData.FormatString(new DateTime(month.Year, month.Month, 1), CalendarData.MonthTitleFormat));

            // fill the area
            using (BrushEx brush = Canvas.CreateSolidBrush(CalendarData.MonthTitleBackcolor))
                Canvas.FillRectangle(brush, monthRowRect);
            // draw month title string
            var font = CalendarData.MonthTitleFontStyle.CreateFontInfo();

            using (BrushEx brush = Canvas.CreateSolidBrush(CalendarData.MonthTitleFontStyle.FontColor))
            {
                RectangleF titleRect = new RectangleF(
                    monthRowRect.X + borderWidth, monthRowRect.Y + borderWidth,
                    monthRowRect.Width - 2 * borderWidth, monthRowRect.Height - 2 * borderWidth);

                // HACK: we should consider the issue with drawing string later. the issue comes about in the designer when caledar has small width to fit titles. --SergeyP
                Canvas.PushState();
                Canvas.DrawString(monthTitle, font, brush, titleRect, ToEx(CalendarData.MonthTitleStringFormat));
                Canvas.PopState();
            }
            // draw the borders
            using (PenEx pen = LineStyle.CreatePen(Canvas, CalendarData.MonthTitleBorderStyle))
            {
                pen.Alignment = PenAlignment.Center;
                DrawRectangle(Canvas, pen, monthRowRect.X, monthRowRect.Y,
                              monthRowRect.Width, monthRowRect.Height - borderWidth);           // shift the bottom border to avoid overlapping
            }

            // set offset
            topOffset += monthTitleRowSize.Height;
        }
示例#2
0
        /// <summary>
        /// Draws the appointments of a specified week.
        /// </summary>
        private void RenderAppointments(MonthInfo month, IEnumerable <DayInfo> days, SizeF dayCellSize)
        {
            const float ImagePadding = 0.02f;

            for (int week = 0; week < CalendarData.WeeksInMonth; week++)
            {
                DateTime weekStartDate = month.GetDateOfDay(week, CalendarData.FirstDayOfWeek, CalendarData.FirstDayOfWeek);
                DateTime weekEndDate   = month.GetDateOfDay(week, CalendarData.LastDayOfWeek, CalendarData.FirstDayOfWeek, true);

                CalendarData.AppointmentLayoutHelper layoutHelper = new CalendarData.AppointmentLayoutHelper(CalendarData.FirstDayOfWeek, CalendarData.AppointmentGap);
                foreach (Appointment appointment in CalendarData.GetAppointmentsInWeek(month, week))
                {
                    int apptWeekDaysCount = appointment.GetDurationInPeriod(weekStartDate, weekEndDate);
                    Debug.Assert(apptWeekDaysCount > 0, "The appointment should belong to the rendering week.");

                    DateTime appStartDate    = appointment.ArrangeStartDate(weekStartDate);
                    DayInfo  appStartDayInfo = DayInfo.FindDayInfo(days, appStartDate);
                    Debug.Assert(appStartDayInfo != null, "Day have to be found in the collection.");

                    SizeF      appSize   = CalendarData.MeasureAppointment(appointment, weekStartDate, weekEndDate, dayCellSize);
                    float      appOffset = layoutHelper.Add(appStartDate, appStartDate.AddDays(apptWeekDaysCount - 1), appSize.Height);
                    RectangleF appointmentRect;
                    if (!_rightToLeft)
                    {
                        appointmentRect = new RectangleF(
                            appStartDayInfo.Bounds.X,
                            appStartDayInfo.Bounds.Y + appStartDayInfo.HeaderSize.Height + appOffset,
                            apptWeekDaysCount * dayCellSize.Width,
                            appSize.Height);
                    }
                    else
                    {
                        appointmentRect = new RectangleF(
                            appStartDayInfo.Bounds.X - ((apptWeekDaysCount - 1) * dayCellSize.Width),
                            appStartDayInfo.Bounds.Y + appStartDayInfo.HeaderSize.Height + appOffset,
                            apptWeekDaysCount * dayCellSize.Width,
                            appSize.Height);
                    }

                    AddActionToInteractivityMap(appointment, appointmentRect);

                    using (BrushEx backcolorBrush = Canvas.CreateSolidBrush(appointment.Backcolor))
                    {
                        Canvas.FillRectangle(backcolorBrush, appointmentRect);
                    }
                    // draw image!
                    Image      img         = CalendarData.GetAppointmentImage(appointment);
                    RectangleF appTextRect = new RectangleF(appointmentRect.X, appointmentRect.Y, appointmentRect.Width, appointmentRect.Height);
                    bool       drawImage   = appointment.StartDate >= weekStartDate && appointment.StartDate <= weekEndDate;
                    if (img != null && drawImage)
                    {
                        var imageStream = new MemoryStream();
                        img.Save(imageStream, ImageFormat.Png);
                        imageStream.Position = 0;
                        using (ImageEx image = Canvas.CreateImage(new ImageInfo(imageStream, "image/png")))
                        {
                            float imgHeight = Math.Min(CalendarData.GetAppointmentImageSize(appointment), appointmentRect.Width);
                            float imgWidth  = imgHeight;
                            float imgLeft;
                            if (!_rightToLeft)
                            {
                                imgLeft = appointmentRect.X;
                            }
                            else
                            {
                                imgLeft = appointmentRect.Right - imgWidth;
                            }
                            float imgTop = appointmentRect.Y + ImagePadding;
                            //Fix for case 44294
                            Canvas.PushState();
                            Canvas.IntersectClip(new RectangleF(imgLeft, imgTop, imgWidth, imgHeight));
                            SizeF imgSz = CalendarData.GetAppointmentImageRealSize(appointment);
                            Canvas.DrawImage(image, imgLeft, imgTop, imgSz.Width, imgSz.Height);
                            Canvas.PopState();
                            if (imgHeight == appointmentRect.Width)
                            {
                                appTextRect.Y      += imgHeight;
                                appTextRect.Height -= imgHeight;
                            }
                            else
                            {
                                if (!_rightToLeft)
                                {
                                    appTextRect.X = appointmentRect.X + imgWidth;
                                }
                                appTextRect.Width = appointmentRect.Width - imgWidth;
                            }
                        }
                    }
                    // HACK: we should consider the issue with drawing string later. the issue comes about in the designer when caledar has small width to fit titles. --SergeyP
                    using (StringFormat sf = Components.Calendar.CalendarData.GetAppointmentFormat(appointment, _rightToLeft))
                    {
                        TextStyle fontStyle = new TextStyle(appointment.FontFamily, appointment.FontSize,
                                                            appointment.FontStyle, appointment.FontWeight, appointment.FontDecoration,
                                                            appointment.FontColor);
                        Canvas.PushState();
                        var font = fontStyle.CreateFontInfo();
                        using (BrushEx forecolorBrush = Canvas.CreateSolidBrush(fontStyle.FontColor))
                        {
                            string value = CalendarData.FormatString(appointment.Value, appointment.Format);
                            Canvas.DrawString(value, font, forecolorBrush, appTextRect, ToEx(sf));
                        }
                        Canvas.PopState();
                    }
                    LineStyle borderStyle = new LineStyle(appointment.BorderColor);
                    using (PenEx pen = LineStyle.CreatePen(Canvas, borderStyle))
                    {
                        pen.Width = 1;                         // HACK: temporary hack because the width is turned off for appointments
                        DrawRectangle(Canvas, pen,
                                      appointmentRect.X, appointmentRect.Y, appointmentRect.Width, appointmentRect.Height);
                    }

                    RenderAction(appointment, Canvas, appointmentRect);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Draws the days.
        /// </summary>
        /// <param name="days">a sorted list of days to draw</param>
        private void RenderDays(IEnumerable <DayInfo> days)
        {
            foreach (DayInfo day in days)
            {
                RectangleF dayRect = day.Bounds;

                var headerBorderPath = new PathEx();
                var borderPath       = new PathEx();
                {
                    // create day-box area
                    borderPath.AddLines(
                        new PointF[]
                    {
                        new PointF(dayRect.X, dayRect.Y),
                        new PointF(dayRect.X + dayRect.Width, dayRect.Y),
                        new PointF(dayRect.X + dayRect.Width, dayRect.Y + dayRect.Height),
                        new PointF(dayRect.X, dayRect.Y + dayRect.Height),
                    });
                    borderPath.CloseAllFigures();

                    //Fix for case 44962
                    headerBorderPath.AddLines(
                        new PointF[]
                    {
                        new PointF(dayRect.X, dayRect.Y),
                        new PointF(dayRect.X + dayRect.Width, dayRect.Y),
                        new PointF(dayRect.X + dayRect.Width, dayRect.Y + day.HeaderSize.Height),
                        new PointF(dayRect.X, dayRect.Y + day.HeaderSize.Height),
                    });
                    headerBorderPath.CloseAllFigures();

                    // fill day-box area
                    using (BrushEx brush = Canvas.CreateSolidBrush(CalendarData.GetDayBackcolor(day.DayKind)))
                    {
                        Canvas.DrawAndFillPath(null, brush, borderPath);
                        Canvas.DrawAndFillPath(null, brush, headerBorderPath);
                    }
                    // draw the day label
                    TextStyle fontStyle = CalendarData.GetDayFontStyle(day.DayKind);
                    var       font      = fontStyle.CreateFontInfo();
                    using (BrushEx brush = Canvas.CreateSolidBrush(fontStyle.FontColor))
                    {
                        float      borderWidth  = CalendarData.GetDayBorderStyle(day.DayKind).LineWidth.ToTwips() / 2;
                        RectangleF dayLabelRect = new RectangleF(
                            dayRect.X + borderWidth, dayRect.Top + borderWidth,
                            day.Bounds.Width - 2 * borderWidth, day.HeaderSize.Height - 2 * borderWidth);

                        // HACK: we should consider the issue with drawing string later. the issue comes about in the designer when caledar has small width to fit titles. --SergeyP
                        Canvas.PushState();
                        Canvas.DrawString(day.Label, font, brush, dayLabelRect, ToEx(CalendarData.GetDayStringFormat(day.DayKind)));
                        Canvas.PopState();
                    }
                    // draw borders
                    using (PenEx pen = LineStyle.CreatePen(Canvas, CalendarData.GetDayBorderStyle(day.DayKind)))
                    {
                        Canvas.DrawAndFillPath(pen, null, borderPath);
                        Canvas.DrawAndFillPath(pen, null, headerBorderPath);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Draws the week day names.
        /// </summary>
        private void DrawWeekDays(ref float topOffset)
        {
            // calc the rect of the week day names row
            SizeF      weekDaysRowSize = CalendarData.GetDaysOfWeekRowSize(MonthAreaSize);
            RectangleF weekDaysRowRect = new RectangleF(
                CalendarArea.X, CalendarArea.Y + topOffset,
                weekDaysRowSize.Width, weekDaysRowSize.Height);

            SizeF dayCellSize = CalendarData.GetDayCellSize(weekDaysRowSize);

            using (BrushEx brush = Canvas.CreateSolidBrush(CalendarData.DayHeadersBackcolor))
                Canvas.FillRectangle(brush, weekDaysRowRect);

            // draw the week days how they represented in month
            var font = CalendarData.DayHeadersFontStyle.CreateFontInfo();

            using (BrushEx brush = Canvas.CreateSolidBrush(CalendarData.DayHeadersFontStyle.FontColor))
                using (PenEx pen = LineStyle.CreatePen(Canvas, CalendarData.DayHeadersBorderStyle))
                {
                    for (int i = 0; i < CalendarData.DaysInWeek; i++)
                    {
                        RectangleF dayCellRect;
                        if (!_rightToLeft)
                        {
                            dayCellRect = new RectangleF(
                                weekDaysRowRect.X + (i * dayCellSize.Width),
                                weekDaysRowRect.Y,
                                dayCellSize.Width,
                                dayCellSize.Height);
                        }
                        else
                        {
                            dayCellRect = new RectangleF(
                                (weekDaysRowRect.X + weekDaysRowRect.Width) - ((i + 1) * dayCellSize.Width),
                                weekDaysRowRect.Y,
                                dayCellSize.Width,
                                dayCellSize.Height);
                        }
                        var borderPath = new PathEx();
                        {
                            // create day-box area
                            borderPath.AddLines(
                                new PointF[]
                            {
                                new PointF(dayCellRect.X, dayCellRect.Y),
                                new PointF(dayCellRect.X + dayCellRect.Width, dayCellRect.Y),
                                new PointF(dayCellRect.X + dayCellRect.Width, dayCellRect.Y + dayCellRect.Height),
                                new PointF(dayCellRect.X, dayCellRect.Y + dayCellRect.Height),
                            });
                            borderPath.CloseAllFigures();

                            // the day name to draw
                            string weekDayName = CalendarData.Culture.DateTimeFormat.GetDayName(CalendarData.WeekDays[i]);
                            // HACK: we should consider the issue with drawing string later. the issue comes about in the designer when caledar has small width to fit titles. --SergeyP
                            {
                                Canvas.PushState();
                                Canvas.DrawString(weekDayName, font, brush, dayCellRect, ToEx(CalendarData.DayHeadersFormat));
                                Canvas.PopState();
                            }
                            Canvas.DrawAndFillPath(pen, null, borderPath);
                            //RenderUtils.DrawRectangle(Canvas, pen, dayCellRect.X, dayCellRect.Y, dayCellRect.Width, dayCellRect.Height);
                        }
                    }
                }

            // set offset
            topOffset += weekDaysRowSize.Height;
        }