Ejemplo n.º 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;
        }
Ejemplo n.º 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);
                }
            }
        }