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

GetBorderDisplayPadding() public method

Gets the padding used to position display elements completely inside border drawing.
public GetBorderDisplayPadding ( IPaletteBorder palette, PaletteState state, VisualOrientation orientation ) : Padding
palette IPaletteBorder Palette used for drawing.
state PaletteState State associated with rendering.
orientation VisualOrientation Visual orientation of the border.
return Padding
        public override Padding GetBorderDisplayPadding(IPaletteBorder palette,
                                                        PaletteState state,
                                                        VisualOrientation orientation)
        {
            Debug.Assert(palette != null);

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

            PaletteDrawBorders borders = palette.GetBorderDrawBorders(state);

            // If there is at least one border to be drawn
            if (CommonHelper.HasABorder(borders))
            {
                int borderWidth = palette.GetBorderWidth(state);

                // Divide the rounding effect by PI to get the actual pixel distance needed
                // for offseting. But add 2 so it starts indenting on a rounding of just 1.
                int roundPadding = Convert.ToInt16((palette.GetBorderRounding(state) + borderWidth + 2) / Math.PI);

                // If not involving rounding then padding for an edge is just the border width
                int squarePadding = borderWidth;

                // Borders thicker than 1 need extra offsetting, by half the extra width
                if (borderWidth > 1)
                {
                    int halfExtra = borderWidth / 2;
                    roundPadding += halfExtra;
                }

                // Enforce the width of the border as the minimum to ensure
                // it still works as expected for small values of rounding
                if (roundPadding < borderWidth)
                    roundPadding = borderWidth;

                switch (borders)
                {
                    case PaletteDrawBorders.Bottom:
                        return new Padding(0, 0, 0, squarePadding);
                    case PaletteDrawBorders.BottomLeft:
                        return new Padding(roundPadding, 0, 0, roundPadding);
                    case PaletteDrawBorders.BottomLeftRight:
                        return new Padding(roundPadding, 0, roundPadding, roundPadding);
                    case PaletteDrawBorders.BottomRight:
                        return new Padding(0, 0, roundPadding, roundPadding);
                    case PaletteDrawBorders.Left:
                        return new Padding(squarePadding, 0, 0, 0);
                    case PaletteDrawBorders.LeftRight:
                        return new Padding(squarePadding, 0, squarePadding, 0);
                    case PaletteDrawBorders.Top:
                        return new Padding(0, squarePadding, 0, 0);
                    case PaletteDrawBorders.Right:
                        return new Padding(0, 0, squarePadding, 0);
                    case PaletteDrawBorders.TopBottom:
                        return new Padding(0, squarePadding, 0, squarePadding);
                    case PaletteDrawBorders.TopBottomLeft:
                        return new Padding(roundPadding, roundPadding, 0, roundPadding);
                    case PaletteDrawBorders.TopBottomRight:
                        return new Padding(0, roundPadding, roundPadding, roundPadding);
                    case PaletteDrawBorders.TopLeft:
                        return new Padding(roundPadding, roundPadding, 0, 0);
                    case PaletteDrawBorders.TopLeftRight:
                        return new Padding(roundPadding, roundPadding, roundPadding, 0);
                    case PaletteDrawBorders.TopRight:
                        return new Padding(0, roundPadding, roundPadding, 0);
                    case PaletteDrawBorders.All:
                        return new Padding(roundPadding);
                    default:
                        // Should never happen!
                        Debug.Assert(false);
                        return Padding.Empty;
                }
            }
            else
                return Padding.Empty;
        }
RenderStandard