ComponentFactory.Krypton.Toolkit.RenderStandard.DrawContent C# (CSharp) Method

DrawContent() public method

Perform draw of content using provided memento.
public DrawContent ( RenderContext context, Rectangle displayRect, IPaletteContent palette, IDisposable memento, VisualOrientation orientation, PaletteState state, bool composition, bool allowFocusRect ) : void
context RenderContext Render context.
displayRect System.Drawing.Rectangle Display area available for drawing.
palette IPaletteContent Content palette details.
memento IDisposable Cached values from layout call.
orientation VisualOrientation Visual orientation of the content.
state PaletteState State associated with rendering.
composition bool Drawing onto a composition element.
allowFocusRect bool Allow drawing of focus rectangle.
return void
        public override void DrawContent(RenderContext context, 
										 Rectangle displayRect,
										 IPaletteContent palette,
										 IDisposable memento,
										 VisualOrientation orientation,
										 PaletteState state,
                                         bool composition,
                                         bool allowFocusRect)
        {
            Debug.Assert(context != null);
            Debug.Assert(memento != null);
            Debug.Assert(memento is StandardContentMemento);

            // Validate parameter references
            if (context == null) throw new ArgumentNullException("context");
            if (palette == null) throw new ArgumentNullException("palette");

            Debug.Assert(context.Control != null);
            Debug.Assert(!context.Control.IsDisposed);

            // Cast the incoming memento to the correct type
            StandardContentMemento standard = (StandardContentMemento)memento;

            if (standard.DrawImage)
            {
                DrawImageHelper(context,
                                standard.Image,
                                standard.ImageTransparentColor,
                                standard.ImageRect,
                                orientation,
                                palette.GetContentImageEffect(state),
                                palette.GetContentImageColorMap(state),
                                palette.GetContentImageColorTo(state));
            }

            if (standard.DrawShortText)
            {
                using (GraphicsTextHint hint = new GraphicsTextHint(context.Graphics, standard.ShortTextHint))
                {
                    // Get the rectangle to use when dealing with gradients
                    Rectangle gradientRect = context.GetAlignedRectangle(palette.GetContentShortTextColorAlign(state), standard.ShortTextRect);

                    // Use standard helper routine to create appropriate color brush
                    Color color1 = palette.GetContentShortTextColor1(state);
                    PaletteColorStyle colorStyle = palette.GetContentShortTextColorStyle(state);
                    using (Brush colorBrush = CreateColorBrush(gradientRect,
                                                               color1,
                                                               palette.GetContentShortTextColor2(state),
                                                               colorStyle,
                                                               palette.GetContentShortTextColorAngle(state),
                                                               orientation))
                    {
                        if (!AccurateText.DrawString(context.Graphics,
                                                     colorBrush,
                                                     standard.ShortTextRect,
                                                     context.Control.RightToLeft,
                                                     standard.Orientation,
                                                     composition,
                                                     state,
                                                     standard.ShortTextMemento))
                        {
                            // Failed to draw means the font is likely to be invalid, get a fresh font
                            standard.ShortTextMemento.Font = palette.GetContentShortTextNewFont(state);

                            // Try again using the new font
                            AccurateText.DrawString(context.Graphics,
                                                    colorBrush,
                                                    standard.ShortTextRect,
                                                    context.Control.RightToLeft,
                                                    standard.Orientation,
                                                    composition,
                                                    state,
                                                    standard.ShortTextMemento);
                        }
                    }

                    Image shortImage = palette.GetContentShortTextImage(state);
                    PaletteImageStyle shortImageStyle = palette.GetContentShortTextImageStyle(state);

                    // Do we need to draw the image?
                    if (ShouldDrawImage(shortImage))
                    {
                        // Get the rectangle to use when dealing with gradients
                        Rectangle imageRect = context.GetAlignedRectangle(palette.GetContentShortTextImageAlign(state), standard.ShortTextRect);

                        // Use standard helper routine to create appropriate image brush
                        using (Brush imageBrush = CreateImageBrush(imageRect, shortImage, shortImageStyle))
                        {
                            if (!AccurateText.DrawString(context.Graphics,
                                                         imageBrush,
                                                         standard.ShortTextRect,
                                                         context.Control.RightToLeft,
                                                         standard.Orientation,
                                                         composition,
                                                         state,
                                                         standard.ShortTextMemento))
                            {
                                // Failed to draw means the font is likely to be invalid, get a fresh font
                                standard.ShortTextMemento.Font = palette.GetContentShortTextNewFont(state);

                                AccurateText.DrawString(context.Graphics,
                                                        imageBrush,
                                                        standard.ShortTextRect,
                                                        context.Control.RightToLeft,
                                                        standard.Orientation,
                                                        composition,
                                                        state,
                                                        standard.ShortTextMemento);
                            }
                        }
                    }
                }
            }

            if (standard.DrawLongText)
            {
                using (GraphicsTextHint hint = new GraphicsTextHint(context.Graphics, standard.LongTextHint))
                {
                    // Get the rectangle to use when dealing with gradients
                    Rectangle gradientRect = context.GetAlignedRectangle(palette.GetContentLongTextColorAlign(state), standard.LongTextRect);

                    // Use standard helper routine to create appropriate color brush
                    Color color1 = palette.GetContentLongTextColor1(state);
                    PaletteColorStyle colorStyle = palette.GetContentLongTextColorStyle(state);
                    using (Brush colorBrush = CreateColorBrush(gradientRect,
                                                               color1,
                                                               palette.GetContentLongTextColor2(state),
                                                               colorStyle,
                                                               palette.GetContentLongTextColorAngle(state),
                                                               orientation))
                    {
                        if (!AccurateText.DrawString(context.Graphics,
                                                     colorBrush,
                                                     standard.LongTextRect,
                                                     context.Control.RightToLeft,
                                                     standard.Orientation,
                                                     composition,
                                                     state,
                                                     standard.LongTextMemento))
                        {
                            // Failed to draw means the font is likely to be invalid, get a fresh font
                            standard.LongTextMemento.Font = palette.GetContentLongTextNewFont(state);

                            AccurateText.DrawString(context.Graphics,
                                                    colorBrush,
                                                    standard.LongTextRect,
                                                    context.Control.RightToLeft,
                                                    standard.Orientation,
                                                    composition,
                                                    state,
                                                    standard.LongTextMemento);
                        }
                    }

                    Image longImage = palette.GetContentLongTextImage(state);
                    PaletteImageStyle longImageStyle = palette.GetContentLongTextImageStyle(state);

                    // Do we need to draw the image?
                    if (ShouldDrawImage(longImage))
                    {
                        // Get the rectangle to use when dealing with gradients
                        Rectangle imageRect = context.GetAlignedRectangle(palette.GetContentLongTextImageAlign(state), standard.LongTextRect);

                        // Use standard helper routine to create appropriate image brush
                        using (Brush imageBrush = CreateImageBrush(imageRect, longImage, longImageStyle))
                        {
                            if (!AccurateText.DrawString(context.Graphics,
                                                         imageBrush,
                                                         standard.LongTextRect,
                                                         context.Control.RightToLeft,
                                                         standard.Orientation,
                                                         composition,
                                                         state,
                                                         standard.LongTextMemento))
                            {
                                // Failed to draw means the font is likely to be invalid, get a fresh font
                                standard.LongTextMemento.Font = palette.GetContentLongTextNewFont(state);

                                AccurateText.DrawString(context.Graphics,
                                                        imageBrush,
                                                        standard.LongTextRect,
                                                        context.Control.RightToLeft,
                                                        standard.Orientation,
                                                        composition,
                                                        state,
                                                        standard.LongTextMemento);
                            }
                        }
                    }
                }
            }

            // Do we need to show this content has the focus?
            if (allowFocusRect && (palette.GetContentDrawFocus(state) == InheritBool.True))
            {
                // Place the rectangle 1 pixel inside the content display area
                displayRect.Inflate(-1, -1);

                // Use window forms provided helper class for drawing
                ControlPaint.DrawFocusRectangle(context.Graphics, displayRect);
            }
        }
RenderStandard