ComponentFactory.Krypton.Toolkit.ViewDrawMonthDays.RenderBefore C# (CSharp) Method

RenderBefore() public method

Perform rendering before child elements are rendered.
public RenderBefore ( RenderContext context ) : void
context RenderContext Rendering context.
return void
        public override void RenderBefore(RenderContext context)
        {
            Debug.Assert(context != null);

            // Get the current date values
            DateTime minDate = _calendar.MinDate.Date;
            DateTime maxDate = _calendar.MaxDate.Date;
            DateTime selectStart = _calendar.SelectionStart.Date;
            DateTime selectEnd = _calendar.SelectionEnd.Date;

            int layoutXCell = ClientLocation.X;
            int layoutXDay = ClientLocation.X + (_months.SizeDays.Width - _months.SizeDay.Width) / 2;
            Rectangle drawRectCell = new Rectangle(layoutXCell, ClientLocation.Y, _months.SizeDays.Width, _months.SizeDays.Height);
            Rectangle drawRectDay = new Rectangle(layoutXDay, ClientLocation.Y, _months.SizeDay.Width, _months.SizeDays.Height);

            // Draw each week as a row
            DateTime todayDate = _calendar.TodayDate;
            DateTime displayDate = _firstDay;
            for (int j = 0; j < WEEKS; j++)
            {
                // Draw each day as a column
                for (int i = 0; i < WEEKDAYS; i++)
                {
                    // Memento index
                    int index = j * WEEKDAYS + i;

                    // Draw using memento cached from the layout call
                    if (_dayMementos[index] != null)
                    {
                        bool skip = false;
                        PaletteState paletteState = PaletteState.Normal;
                        IPaletteTriple paletteTriple = _calendar.OverrideNormal;

                        // If the display date is not within the allowed range, do not draw it
                        if ((displayDate < minDate) || (displayDate > maxDate))
                            skip = true;
                        else
                        {
                            _calendar.SetFocusOverride(false);
                            _calendar.SetBoldedOverride(BoldedDate(displayDate));
                            _calendar.SetTodayOverride(_months.ShowTodayCircle && (displayDate == todayDate));

                            // If the day is not actually in the month we are drawing
                            if (displayDate.Month != _month.Month)
                            {
                                // If we need to show this day but disabled
                                if (((j < 3) && _firstMonth) || ((j > 3) && _lastMonth))
                                {
                                    paletteState = PaletteState.Disabled;
                                    paletteTriple = _calendar.OverrideDisabled;
                                }
                                else
                                    skip = true;
                            }
                            else
                            {
                                // Is this day part of the selection?
                                if ((displayDate >= selectStart) && (displayDate <= selectEnd))
                                {
                                    _calendar.SetFocusOverride(((_months.FocusDay != null) && (_months.FocusDay.Value == displayDate)));

                                    if (_months.TrackingDay.HasValue && (_months.TrackingDay.Value == displayDate))
                                    {
                                        paletteState = PaletteState.CheckedTracking;
                                        paletteTriple = _calendar.OverrideCheckedTracking;
                                    }
                                    else
                                    {
                                        paletteState = PaletteState.CheckedNormal;
                                        paletteTriple = _calendar.OverrideCheckedNormal;
                                    }
                                }
                                else
                                {
                                    if (_months.TrackingDay.HasValue && (_months.TrackingDay.Value == displayDate))
                                    {
                                        paletteState = PaletteState.Tracking;
                                        paletteTriple = _calendar.OverrideTracking;
                                    }
                                }
                            }
                        }

                        if (!skip)
                        {
                            // Do we need to draw the background?
                            if (paletteTriple.PaletteBack.GetBackDraw(paletteState) == InheritBool.True)
                            {
                                using (GraphicsPath path = context.Renderer.RenderStandardBorder.GetBackPath(context, drawRectCell, paletteTriple.PaletteBorder,
                                                                                                             VisualOrientation.Top, paletteState))
                                {
                                    context.Renderer.RenderStandardBack.DrawBack(context, drawRectCell, path, paletteTriple.PaletteBack, VisualOrientation.Top, paletteState, null);
                                }
                            }

                            // Do we need to draw the border?
                            if (paletteTriple.PaletteBorder.GetBorderDraw(paletteState) == InheritBool.True)
                            {
                                context.Renderer.RenderStandardBorder.DrawBorder(context, drawRectCell, paletteTriple.PaletteBorder, VisualOrientation.Top, paletteState);
                            }

                            // Do we need to draw the content?
                            if (paletteTriple.PaletteContent.GetContentDraw(paletteState) == InheritBool.True)
                            {
                                context.Renderer.RenderStandardContent.DrawContent(context, drawRectDay, paletteTriple.PaletteContent, _dayMementos[index],
                                                                                   VisualOrientation.Top, paletteState, false, true);
                            }
                        }
                    }

                    // Move across to next column
                    drawRectCell.X += _months.SizeDays.Width;
                    drawRectDay.X += _months.SizeDays.Width;

                    // Move to next day
                    displayDate += TIMESPAN_1DAY;
                }

                // Move to start of the next row
                drawRectCell.X = layoutXCell;
                drawRectCell.Y += _months.SizeDays.Height;
                drawRectDay.X = layoutXDay;
                drawRectDay.Y += _months.SizeDays.Height;
            }
        }