示例#1
0
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            // Get the top left inner corner (inside margin and border):
            float width  = box.PaddedWidth;
            float height = box.PaddedHeight;
            float top    = box.Y + box.Border.Top;
            float left   = box.X + box.Border.Left;

            // Is it clipped?
            if (renderer.IsInvisible(left, top, width, height))
            {
                // Totally not visible.
                return;
            }

            // Ensure we have a batch (doesn't change graphics or font thus both nulls):
            renderer.SetupBatch(this, null, null);

            // Get the transform:
            Transformation transform = renderer.Transform;

            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    // Add it:
                    MeshBlock block = Add(renderer);

                    // Set the UV to that of the solid block colour pixel:
                    block.SetSolidColourUV();

                    // Set the colour - here we set it unevenly to trigger gradients.
                    // block.SetColour(BackingColour * renderer.ColorOverlay);

                    // BoxRegion clipZone=new BoxRegion(left,top,width,height);

                    // Set the verts too:
                    // block.SetClipped(renderer.ClippingBoundary,clipZone,renderer,box.ZIndex-0.006f);

                    block.Done(transform);
                }
            }
        }
        /// <summary>Draws an underline (or a strikethrough).</summary>
        public virtual void DrawUnderline(Renderman renderer)
        {
            // Ensure we have a batch:
            renderer.SetupBatch(this, null, null);

            // And get our block ready:
            MeshBlock block = Add(renderer);

            // Set the UV to that of the solid block colour pixel:
            block.SetSolidColourUV();

            // Set the colour:
            block.SetColour(renderer.FontColour);

            // Set the verts:
            block.SetClipped(renderer.ClippingBoundary, renderer.CurrentRegion, renderer, renderer.TextDepth);

            // Ok!
            block.Done(renderer.Transform);
        }
示例#3
0
        public void Render(LayoutBox box, Renderman renderer, float cornerX, float cornerY)
        {
            if (OuterArc == null)
            {
                RecomputeArcs(box.Border);
            }
            else if (InnerArc == null)
            {
                RecomputeInnerArc(box.Border);
            }

            // Get the z-Index:
            float zIndex = RoundCorners.Computed.MaxZIndex + 0.006f;

            // Figure out where half way is (divide by 2):
            int halfway = (BlocksRequired >> 1);

            Color colour = Colour;

            // Grab the clipping boundary:
            BoxRegion clip = renderer.ClippingBoundary;

            // Make it relative to the corners location:
            float minClipX = clip.X - cornerX;
            float minClipY = clip.Y - cornerY;
            float maxClipX = clip.MaxX - cornerX;
            float maxClipY = clip.MaxY - cornerY;

            // For each block..
            for (int i = 0; i < BlocksRequired; i++)
            {
                // Read the outer arc:
                Vector2 outerPointA = OuterArc[i];

                // Figure out the bounding box (constant for a particular block).
                float minX = outerPointA.x;
                float maxX = minX;
                float minY = outerPointA.y;
                float maxY = minY;

                Vector2 outerPointB = OuterArc[i + 1];

                // Update the bounding box:
                if (outerPointB.x < minX)
                {
                    minX = outerPointB.x;
                }
                else if (outerPointB.x > maxX)
                {
                    maxX = outerPointB.x;
                }

                if (outerPointB.y < minY)
                {
                    minY = outerPointB.y;
                }
                else if (outerPointB.y > maxY)
                {
                    maxY = outerPointB.y;
                }

                // Line segment A->B on the "outer" arc.

                // Read the inner arc:
                Vector2 innerPointA = InnerArc[i];

                // Update the bounding box:
                if (innerPointA.x < minX)
                {
                    minX = innerPointA.x;
                }
                else if (innerPointA.x > maxX)
                {
                    maxX = innerPointA.x;
                }

                if (innerPointA.y < minY)
                {
                    minY = innerPointA.y;
                }
                else if (innerPointA.y > maxY)
                {
                    maxY = innerPointA.y;
                }

                Vector2 innerPointB = InnerArc[i + 1];

                // Update the bounding box:
                if (innerPointB.x < minX)
                {
                    minX = innerPointB.x;
                }
                else if (innerPointB.x > maxX)
                {
                    maxX = innerPointB.x;
                }

                if (innerPointB.y < minY)
                {
                    minY = innerPointB.y;
                }
                else if (innerPointB.y > maxY)
                {
                    maxY = innerPointB.y;
                }

                // How does our bounding box compare to the clipping region?
                if (maxX < minClipX)
                {
                    continue;
                }
                else if (minX > maxClipX)
                {
                    continue;
                }

                if (maxY < minClipY)
                {
                    continue;
                }
                else if (minY > maxClipY)
                {
                    continue;
                }

                // Line segment A->B on the "inner" arc.

                // Get a block:
                MeshBlock block = Border.Add(renderer);

                // Set the UV to that of the solid block colour pixel:
                block.SetSolidColourUV();

                // Get the border colour:
                if (i == halfway)
                {
                    // Get the next colour:

                    if (Border.BaseColour != null && Border.BaseColour.Count != 1)
                    {
                        colour = Border.BaseColour[ToIndex].GetColour(Border.RenderData, Css.Properties.BorderColor.GlobalProperty) * renderer.ColorOverlay;
                    }
                }

                // Set the border colour:
                block.SetColour(colour);

                // Apply the block region:
                block.VertexTopLeft  = renderer.PixelToWorldUnit(cornerX + outerPointA.x, cornerY + outerPointA.y, zIndex);
                block.VertexTopRight = renderer.PixelToWorldUnit(cornerX + outerPointB.x, cornerY + outerPointB.y, zIndex);

                block.VertexBottomLeft  = renderer.PixelToWorldUnit(cornerX + innerPointA.x, cornerY + innerPointA.y, zIndex);
                block.VertexBottomRight = renderer.PixelToWorldUnit(cornerX + innerPointB.x, cornerY + innerPointB.y, zIndex);

                block.Done(renderer.Transform);
            }
        }
示例#4
0
        protected override void Layout()
        {
            if (Characters == null || FontToDraw == null || Characters.Length == 0)
            {
                return;
            }

            // The blocks we allocate here come from FontToDraw.
            // They use the same renderer and same layout service, but just a different mesh.
            // This is to enable potentially very large font atlases with multiple fonts.
            ComputedStyle computed = Element.Style.Computed;
            Renderman     renderer = Element.Document.Renderer;

            float top  = computed.OffsetTop + computed.StyleOffsetTop;
            float left = computed.OffsetLeft + computed.StyleOffsetLeft;

            // Should we auto-alias the text?

            // Note that this property "drags" to following elements which is correct.
            // We don't really want to break batching chains for aliasing.

            if (Alias == float.MaxValue)
            {
                // Yep! Note all values here are const.
                float aliasing = Fonts.AutoAliasOffset - ((FontSize - Fonts.AutoAliasRelative) * Fonts.AutoAliasRamp);

                if (aliasing > 0.1f)
                {
                    renderer.FontAliasing = aliasing;
                }
            }
            else
            {
                // Write aliasing:
                renderer.FontAliasing = Alias;
            }

            if (Extrude != 0f)
            {
                // Compute the extrude now:
                if (Text3D == null)
                {
                    Text3D = Get3D(FontSize, FontColour, ref left, ref top);
                }
                else
                {
                    // Update it.
                }

                return;
            }
            else
            {
                Text3D = null;
            }


            if (!AllWhitespace)
            {
                // Firstly, make sure the batch is using the right font texture.
                // This may generate a new batch if the font doesn't match the previous or existing font.

                // Get the full shape of the element:
                int width  = computed.PaddedWidth;
                int height = computed.PaddedHeight;
                int minY   = computed.OffsetTop + computed.BorderTop;
                int minX   = computed.OffsetLeft + computed.BorderLeft;

                BoxRegion boundary = new BoxRegion(minX, minY, width, height);

                if (!boundary.Overlaps(renderer.ClippingBoundary))
                {
                    if (Visible)
                    {
                        SetVisibility(false);
                    }

                    return;
                }
                else if (!Visible)
                {
                    // ImageLocation will allocate here if it's needed.
                    SetVisibility(true);
                }
            }

            float     zIndex       = computed.ZIndex;
            BoxRegion screenRegion = new BoxRegion();

            // First up, underline.
            if (TextLine != null)
            {
                // We have one. Locate it next.
                float lineWeight = (FontToDraw.StrikeSize * FontSize);
                float yOffset    = 0f;

                switch (TextLine.Type)
                {
                case TextLineType.Underline:
                    yOffset = Ascender + lineWeight;
                    break;

                case TextLineType.StrikeThrough:
                    yOffset = (FontToDraw.StrikeOffset * FontSize);
                    yOffset = Ascender - yOffset;
                    break;

                case TextLineType.Overline:
                    yOffset = (lineWeight * 2f);
                    break;
                }

                Color lineColour = FontColour;

                if (TextLine.ColourOverride)
                {
                    lineColour = TextLine.Colour;
                }

                screenRegion.Set(left, top + yOffset, computed.PixelWidth, lineWeight);

                if (screenRegion.Overlaps(renderer.ClippingBoundary))
                {
                    // Ensure we have a batch:
                    SetupBatch(null, null);

                    // This region is visible. Clip it:
                    screenRegion.ClipBy(renderer.ClippingBoundary);
                    // And get our block ready:
                    MeshBlock block = Add();
                    // Set the UV to that of the solid block colour pixel:
                    block.SetSolidColourUV();
                    // Set the colour:
                    block.SetColour(lineColour);

                    block.SetClipped(renderer.ClippingBoundary, screenRegion, renderer, zIndex);
                }
            }


            // Next, render the characters.
            // If we're rendering from right to left, flip the punctuation over.

            // Is the word itself rightwards?
            bool rightwardWord = false;

            if (StartPunctuationCount < Characters.Length)
            {
                // Is the first actual character a rightwards one?
                Glyph firstChar = Characters[StartPunctuationCount];

                if (firstChar != null)
                {
                    rightwardWord = firstChar.Rightwards;
                }
            }

            // Right to left (e.g. arabic):
            if (computed.DrawDirection == DirectionType.RTL)
            {
                int end = Characters.Length - EndPunctuationCount;

                // Draw the punctuation from the end of the string first, backwards:
                if (EndPunctuationCount > 0)
                {
                    for (int i = Characters.Length - 1; i >= end; i--)
                    {
                        DrawInvertCharacter(i, ref left, top, renderer, zIndex, screenRegion);
                    }
                }

                if (rightwardWord)
                {
                    // Render the word itself backwards.

                    for (int i = end - 1; i >= StartPunctuationCount; i--)
                    {
                        DrawCharacter(i, ref left, top, renderer, zIndex, screenRegion);
                    }
                }
                else
                {
                    // Draw the middle characters:
                    for (int i = StartPunctuationCount; i < end; i++)
                    {
                        DrawCharacter(i, ref left, top, renderer, zIndex, screenRegion);
                    }
                }

                // Draw the punctuation from the start of the string last, backwards:

                if (StartPunctuationCount > 0)
                {
                    for (int i = StartPunctuationCount - 1; i >= 0; i--)
                    {
                        DrawInvertCharacter(i, ref left, top, renderer, zIndex, screenRegion);
                    }
                }
            }
            else if (rightwardWord)
            {
                // Render the word itself backwards.

                for (int i = Characters.Length - 1; i >= 0; i--)
                {
                    DrawCharacter(i, ref left, top, renderer, zIndex, screenRegion);
                }
            }
            else
            {
                // Draw it as is.

                for (int i = 0; i < Characters.Length; i++)
                {
                    DrawCharacter(i, ref left, top, renderer, zIndex, screenRegion);
                }
            }
        }
        public void Render(float alpha, float cornerX, float cornerY)
        {
            // Grab the renderer:
            Renderman renderer = RoundCorners.Renderer;

            // Get the z-Index:
            float zIndex = renderer.Depth + 0.006f;

            // Figure out where half way is (divide by 2):
            int halfway = (BlocksRequired >> 1);

            Color colour;

            if (Border.Colour == null)
            {
                if (RoundCorners.Computed.Text != null)
                {
                    // Same as the font colour:
                    colour = RoundCorners.Computed.Text.FontColour;
                }
                else
                {
                    // Get the default colour:
                    colour = Color.black;

                    // Alpha is required:
                    colour.a = alpha;
                }
            }
            else if (Border.Colour.Length == 1)
            {
                // Get the only colour:
                colour = Border.Colour[0];
            }
            else
            {
                // Get the first colour:
                colour = Border.Colour[FromIndex];
            }

            // Grab the clipping boundary:
            BoxRegion clip = renderer.ClippingBoundary;

            // Make it relative to the corners location:
            float minClipX = clip.X - cornerX;
            float minClipY = clip.Y - cornerY;
            float maxClipX = clip.MaxX - cornerX;
            float maxClipY = clip.MaxY - cornerY;

            // For each block..
            for (int i = 0; i < BlocksRequired; i++)
            {
                // Get a block:
                MeshBlock block = Border.Add();

                // Read the outer arc:
                Vector2 outerPointA = OuterArc[i];

                // Figure out the bounding box (constant for a particular block).
                float minX = outerPointA.x;
                float maxX = minX;
                float minY = outerPointA.y;
                float maxY = minY;

                Vector2 outerPointB = OuterArc[i + 1];

                // Update the bounding box:
                if (outerPointB.x < minX)
                {
                    minX = outerPointB.x;
                }
                else if (outerPointB.x > maxX)
                {
                    maxX = outerPointB.x;
                }

                if (outerPointB.y < minY)
                {
                    minY = outerPointB.y;
                }
                else if (outerPointB.y > maxY)
                {
                    maxY = outerPointB.y;
                }

                // Line segment A->B on the "outer" arc.

                // Read the inner arc:
                Vector2 innerPointA = InnerArc[i];

                // Update the bounding box:
                if (innerPointA.x < minX)
                {
                    minX = innerPointA.x;
                }
                else if (innerPointA.x > maxX)
                {
                    maxX = innerPointA.x;
                }

                if (innerPointA.y < minY)
                {
                    minY = innerPointA.y;
                }
                else if (innerPointA.y > maxY)
                {
                    maxY = innerPointA.y;
                }

                Vector2 innerPointB = InnerArc[i + 1];

                // Update the bounding box:
                if (innerPointB.x < minX)
                {
                    minX = innerPointB.x;
                }
                else if (innerPointB.x > maxX)
                {
                    maxX = innerPointB.x;
                }

                if (innerPointB.y < minY)
                {
                    minY = innerPointB.y;
                }
                else if (innerPointB.y > maxY)
                {
                    maxY = innerPointB.y;
                }

                // How does our bounding box compare to the clipping region?
                if (maxX < minClipX)
                {
                    continue;
                }
                else if (minX > maxClipX)
                {
                    continue;
                }

                if (maxY < minClipY)
                {
                    continue;
                }
                else if (minY > maxClipY)
                {
                    continue;
                }

                // Line segment A->B on the "inner" arc.

                // Set the UV to that of the solid block colour pixel:
                block.SetSolidColourUV();

                // Get the border colour:
                if (i == halfway)
                {
                    // Get the next colour:

                    if (Border.Colour != null && Border.Colour.Length != 1)
                    {
                        colour = Border.Colour[ToIndex];
                    }
                }

                // Set the border colour:
                block.SetColour(colour);

                // Apply the block region:
                block.VertexTopLeft  = renderer.PixelToWorldUnit(cornerX + outerPointA.x, cornerY + outerPointA.y, zIndex);
                block.VertexTopRight = renderer.PixelToWorldUnit(cornerX + outerPointB.x, cornerY + outerPointB.y, zIndex);

                block.VertexBottomLeft  = renderer.PixelToWorldUnit(cornerX + innerPointA.x, cornerY + innerPointA.y, zIndex);
                block.VertexBottomRight = renderer.PixelToWorldUnit(cornerX + innerPointB.x, cornerY + innerPointB.y, zIndex);
            }
        }
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            // Does the boxes text region overlap our selected range?
            if (box.TextEnd <= StartIndex || EndIndex <= box.TextStart)
            {
                return;
            }

            // It overlaps! We need to figure out which section we're selecting (and how large it is).

            // Get the top left inner corner (inside margin and border):
            // Assume we've selected the whole thing; we remove from the start and remove from the end if needed.
            float width  = box.PaddedWidth;
            float height = box.PaddedHeight;
            float top    = box.Y + box.Border.Top;
            float left   = box.X + box.Border.Left;
            float fs     = Text.FontSize;

            // If the selected indices totally contain the box..
            if (StartIndex > box.TextStart)
            {
                // Trim the start. We need to chop off the width of these characters.

                float characterWidth = 0f;

                int max = StartIndex;

                if (max > Text.Characters.Length)
                {
                    max = Text.Characters.Length;
                }

                for (int i = box.TextStart; i < max; i++)
                {
                    InfiniText.Glyph character = Text.Characters[i];

                    if (character == null)
                    {
                        continue;
                    }

                    // Advance over the glyph:
                    if (Text.Kerning != null)
                    {
                        characterWidth += Text.Kerning[i] * fs;
                    }

                    characterWidth += (character.AdvanceWidth * fs) + Text.LetterSpacing;

                    if (character.Charcode == (int)' ')
                    {
                        characterWidth += Text.WordSpacing;
                    }
                }

                // Chop it off:
                left  += characterWidth;
                width -= characterWidth;
            }

            if (EndIndex < box.TextEnd)
            {
                // Trim the end. We need to chop off the width of these characters.

                float characterWidth = 0f;

                int max = box.TextEnd;

                if (max > Text.Characters.Length)
                {
                    max = Text.Characters.Length;
                }

                for (int i = EndIndex; i < max; i++)
                {
                    InfiniText.Glyph character = Text.Characters[i];

                    if (character == null)
                    {
                        continue;
                    }

                    // Advance over the glyph:
                    if (Text.Kerning != null)
                    {
                        characterWidth += Text.Kerning[i] * fs;
                    }

                    characterWidth += (character.AdvanceWidth * fs) + Text.LetterSpacing;

                    if (character.Charcode == (int)' ')
                    {
                        characterWidth += Text.WordSpacing;
                    }
                }

                // Chop it off:
                width -= characterWidth;
            }

            // Is it clipped?
            if (renderer.IsInvisible(left, top, width, height))
            {
                // Totally not visible.
                return;
            }

            // Ensure we have a batch (doesn't change graphics or font thus both nulls):
            renderer.SetupBatch(this, null, null);

            // Allocate the block:
            MeshBlock block = Add(renderer);

            // Using firstblock as our block here.
            // Set the UV to that of the solid block colour pixel:
            block.SetSolidColourUV();
            // Set the colour:
            block.SetColour(BaseColour);

            // And finally sort out the verts:
            block.SetClipped(renderer.ClippingBoundary, new BoxRegion(left, top, width, height), renderer, RenderData.computedStyle.ZIndex - 0.004f);

            // Flush it:
            block.Done(renderer.Transform);
        }
示例#7
0
        protected override void Layout()
        {
            if (Corners != null)
            {
                Corners.PreLayout();
            }

            ComputedStyle computed = Element.Style.Computed;

            // Find the zIndex:
            // NB: At same depth as BGColour - right at the back.
            float zIndex = (computed.ZIndex - 0.006f);

            // Get the co-ord of the top edge:
            int top  = computed.OffsetTop;
            int left = computed.OffsetLeft;

            // And the dimensions of the lines:
            // Note: boxwidth doesn't include the left/right widths to prevent overlapping.
            int boxWidth  = computed.PaddedWidth;
            int boxHeight = computed.PaddedHeight + WidthTop + WidthBottom;

            BoxRegion screenRegion = new BoxRegion();
            Renderman renderer     = Element.Document.Renderer;

            // Get the default colour - that's the same as the text colour:
            Color colour = Color.black;

            // Is the border multicoloured?
            bool multiColour = false;

            // Does this border have a colour?
            if (Colour == null)
            {
                // Grab the text colour if there is one:
                if (computed.Text != null)
                {
                    // It's the same as the font colour:
                    colour = computed.Text.FontColour;
                }
                else
                {
                    // Nope - We need to set alpha:
                    colour.a = computed.ColorOverlay.a;
                }
            }
            else if (Colour.Length == 1)
            {
                colour = Colour[0];
            }
            else
            {
                multiColour = true;
            }

            for (int i = 0; i < 4; i++)
            {
                int lineHeight = 0;
                int lineWidth  = 0;

                // Co-ords of the top-left corner for our box:
                int cornerY = top;
                int cornerX = left;

                if (i == 0 || i == 2)
                {
                    // Top or bottom:
                    lineWidth  = boxWidth;
                    lineHeight = BorderWidth(i);
                }
                else
                {
                    lineWidth  = BorderWidth(i);
                    lineHeight = boxHeight;
                }

                // Does this border have multiple colours?
                if (multiColour)
                {
                    colour = Colour[i];
                }

                if (Corners != null)
                {
                    Corners.Layout(i, ref cornerX, ref cornerY, ref lineWidth, ref lineHeight);
                }
                else
                {
                    switch (i)
                    {
                    case 0:
                        // Top:
                        cornerX += WidthLeft;

                        break;

                    case 1:
                        // Right:
                        cornerX += boxWidth + WidthLeft;

                        break;

                    case 2:
                        // Bottom:
                        cornerY += boxHeight - WidthBottom;
                        cornerX += WidthLeft;

                        break;
                    }
                }

                screenRegion.Set(cornerX, cornerY, lineWidth, lineHeight);

                if (screenRegion.Overlaps(renderer.ClippingBoundary))
                {
                    // This region is visible. Clip it:
                    screenRegion.ClipBy(renderer.ClippingBoundary);

                    // Ensure we have a batch (doesn't change graphics or font textures, thus both null):
                    SetupBatch(null, null);

                    // And get our block ready:
                    MeshBlock block = Add();

                    // Set the UV to that of the solid block colour pixel:
                    block.SetSolidColourUV();

                    // Set the border colour:
                    block.SetColour(colour);

                    block.SetClipped(renderer.ClippingBoundary, screenRegion, renderer, zIndex);
                }
            }
        }
示例#8
0
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            float width;
            float height;
            float top;
            float left;
            bool  clip = true;

            if (renderer.ViewportBackground)
            {
                // Applying to whole background:
                BoxRegion viewport = renderer.Viewport;

                top    = viewport.Y;
                left   = viewport.X;
                width  = viewport.Width;
                height = viewport.Height;

                renderer.ViewportBackground = false;
                clip = false;
            }
            else
            {
                // Get the top left inner corner (inside margin and border):
                width  = box.PaddedWidth;
                height = box.PaddedHeight;
                top    = box.Y + box.Border.Top;
                left   = box.X + box.Border.Left;

                // Is it clipped?
                if (renderer.IsInvisible(left, top, width, height))
                {
                    // Totally not visible.
                    return;
                }
            }

            // Ensure we have a batch (doesn't change graphics or font thus both nulls):
            renderer.SetupBatch(this, null, null);

            // Allocate the block:
            MeshBlock block = Add(renderer);

            // Using firstblock as our block here.
            // Set the UV to that of the solid block colour pixel:
            block.SetSolidColourUV();
            // Set the (overlay) colour:
            block.SetColour(BaseColour * renderer.ColorOverlay);

            // And finally sort out the verts:
            if (clip)
            {
                block.SetClipped(renderer.ClippingBoundary, new BoxRegion(left, top, width, height), renderer, RenderData.computedStyle.ZIndex - 0.006f);
            }
            else
            {
                block.ApplyVertices(new BoxRegion(left, top, width, height), renderer, RenderData.computedStyle.ZIndex - 0.006f);
            }

            // Flush it:
            block.Done(renderer.Transform);
        }
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            if (Corners != null)
            {
                Corners.PreLayout();
            }

            ComputedStyle computed = RenderData.computedStyle;

            // Find the zIndex:
            // NB: At same depth as BGColour - right at the back.
            float zIndex = (computed.ZIndex - 0.006f);

            // Get the co-ord of the top edge:
            float top  = box.Y;
            float left = box.X;

            // Get the border widths:
            BoxStyle width = box.Border;

            // Move top by the widths:
            top  += width.Top;
            left += width.Left;

            // And the dimensions of the lines:
            float boxWidth  = box.PaddedWidth;
            float boxHeight = box.PaddedHeight;

            // Get the other dimensions:
            float topY    = top - width.Top;
            float right   = left + boxWidth;
            float rightX  = right + width.Right;
            float bottom  = top + boxHeight;
            float bottomY = bottom + width.Bottom;
            float leftX   = left - width.Left;
            int   segment = renderer.Segment;

            Transformation transform = renderer.Transform;

            BoxRegion screenRegion = new BoxRegion();

            // Get the default colour - that's the same as the text colour:
            Color colour = Color.black;

            // Is the border multicoloured?
            bool multiColour = false;

            // Does this border have a colour?
            if (BaseColour == null)
            {
                // Grab the text colour if there is one:
                if (RenderData.Text != null)
                {
                    // It's the same as the font colour:
                    colour = RenderData.Text.BaseColour * renderer.ColorOverlay;
                }
                else
                {
                    // Nope - We need to set alpha:
                    colour.a = renderer.ColorOverlay.a;
                }
            }
            else if (BaseColour.Count == 1)
            {
                colour = BaseColour[0].GetColour(RenderData, Css.Properties.BorderColor.GlobalProperty) * renderer.ColorOverlay;
            }
            else
            {
                multiColour = true;
            }

            // Handle border-radius:
            if (Corners != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (multiColour)
                    {
                        colour = BaseColour[i].GetColour(RenderData, Css.Properties.BorderColor.GlobalProperty) * renderer.ColorOverlay;
                    }

                    Corners.Layout(colour, box, renderer, i);
                }
            }

            // Get clipper:
            BoxRegion clip = renderer.ClippingBoundary;

            float origLeftX   = leftX;
            float origTopY    = topY;
            float origBottomY = bottomY;
            float origRightX  = rightX;

            // top and topY:
            if (top < clip.Y)
            {
                top = clip.Y;
            }
            else if (top > clip.MaxY)
            {
                top = clip.MaxY;
            }

            if (topY < clip.Y)
            {
                topY = clip.Y;
            }

            // bottom and bottomY:
            if (bottom > clip.MaxY)
            {
                bottom = clip.MaxY;
            }
            else if (bottom < clip.Y)
            {
                bottom = clip.Y;
            }

            if (bottomY > clip.MaxY)
            {
                bottomY = clip.MaxY;
            }

            // right and rightX:
            if (right < clip.X)
            {
                right = clip.X;
            }
            else if (right > clip.MaxX)
            {
                right = clip.MaxX;
            }

            // rightX vs clip.MaxX
            if (rightX > clip.MaxX)
            {
                rightX = clip.MaxX;
            }

            // left and leftX:
            if (left < clip.X)
            {
                left = clip.X;
            }
            else if (left > clip.MaxX)
            {
                left = clip.MaxX;
            }

            if (leftX < clip.X)
            {
                leftX = clip.X;
            }

            float cornerPointA;
            float cornerPointB;

            for (int i = 0; i < 4; i++)
            {
                // Does this border have multiple colours?
                if (multiColour)
                {
                    colour = BaseColour[i].GetColour(RenderData, Css.Properties.BorderColor.GlobalProperty) * renderer.ColorOverlay;
                }

                // Add to region:
                switch (i)
                {
                case 0:
                    // Top.
                    screenRegion.SetPoints(leftX, topY, rightX, top);
                    break;

                case 1:
                    // Right.

                    // We only draw the right border if 'segment' includes 'end'
                    if ((segment & LineBoxSegment.End) == 0)
                    {
                        goto NextLine;
                    }

                    screenRegion.SetPoints(right, topY, rightX, bottomY);
                    break;

                case 2:
                    // Bottom.

                    screenRegion.SetPoints(leftX, bottom, rightX, bottomY);
                    break;

                case 3:
                    // Left.

                    // Similarly, we only draw left if segment includes 'start':
                    if ((segment & LineBoxSegment.Start) == 0)
                    {
                        goto NextLine;
                    }

                    screenRegion.SetPoints(leftX, topY, left, bottomY);
                    break;
                }

                if (screenRegion.Overlaps(clip))
                {
                    // It's visible.

                    // Ensure we have a batch (doesn't change graphics or font textures, thus both null):
                    renderer.SetupBatch(this, null, null);

                    // And get our block ready:
                    MeshBlock block = Add(renderer);

                    // Set the UV to that of the solid block colour pixel:
                    block.SetSolidColourUV();

                    // Set the border colour:
                    block.SetColour(colour);

                    // Apply verts:

                    switch (i)
                    {
                    case 0:

                        // Top:
                        if (Corners == null)
                        {
                            block.VertexTopLeft     = renderer.PixelToWorldUnit(leftX, topY, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(rightX, topY, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(left, top, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(right, top, zIndex);
                        }
                        else
                        {
                            // Top left/right corners:
                            cornerPointA = origLeftX + Corners.TopLeftRadius;
                            cornerPointB = origRightX - Corners.TopRightRadius;

                            if (cornerPointA < clip.X)
                            {
                                cornerPointA = clip.X;
                            }

                            if (cornerPointB > clip.MaxX)
                            {
                                cornerPointB = clip.MaxX;
                            }

                            // Note that we use leftX/rightX for all of them.
                            // That's because the corner has a 'straight' edge.
                            block.VertexTopLeft     = renderer.PixelToWorldUnit(cornerPointA, topY, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(cornerPointB, topY, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(cornerPointA, top, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(cornerPointB, top, zIndex);
                        }

                        break;

                    case 1:

                        // Right:
                        if (Corners == null)
                        {
                            block.VertexTopLeft     = renderer.PixelToWorldUnit(right, top, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(rightX, topY, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(right, bottom, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(rightX, bottomY, zIndex);
                        }
                        else
                        {
                            // Top right/ bottom right corners:
                            cornerPointA = origTopY + Corners.TopRightRadius;
                            cornerPointB = origBottomY - Corners.BottomRightRadius;


                            if (cornerPointA < clip.Y)
                            {
                                cornerPointA = clip.Y;
                            }

                            if (cornerPointB > clip.MaxY)
                            {
                                cornerPointB = clip.MaxY;
                            }

                            // Note that we use topY/bottomY for all of them.
                            block.VertexTopLeft     = renderer.PixelToWorldUnit(right, cornerPointA, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(rightX, cornerPointA, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(right, cornerPointB, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(rightX, cornerPointB, zIndex);
                        }

                        break;

                    case 2:

                        // Bottom:
                        if (Corners == null)
                        {
                            block.VertexTopLeft     = renderer.PixelToWorldUnit(left, bottom, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(right, bottom, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(leftX, bottomY, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(rightX, bottomY, zIndex);
                        }
                        else
                        {
                            // Bottom left/ bottom right corners:
                            // Note that we use leftX/rightX for all of them.
                            cornerPointA = origLeftX + Corners.BottomLeftRadius;
                            cornerPointB = origRightX - Corners.BottomRightRadius;

                            if (cornerPointA < clip.X)
                            {
                                cornerPointA = clip.X;
                            }

                            if (cornerPointB > clip.MaxX)
                            {
                                cornerPointB = clip.MaxX;
                            }

                            block.VertexTopLeft     = renderer.PixelToWorldUnit(cornerPointA, bottom, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(cornerPointB, bottom, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(cornerPointA, bottomY, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(cornerPointB, bottomY, zIndex);
                        }

                        break;

                    case 3:

                        // Left:
                        if (Corners == null)
                        {
                            block.VertexTopLeft     = renderer.PixelToWorldUnit(leftX, topY, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(left, top, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(leftX, bottomY, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(left, bottom, zIndex);
                        }
                        else
                        {
                            // Top right/ bottom right corners:
                            cornerPointA = origTopY + Corners.TopLeftRadius;
                            cornerPointB = origBottomY + width.Bottom - Corners.BottomLeftRadius;

                            if (cornerPointA < clip.Y)
                            {
                                cornerPointA = clip.Y;
                            }

                            if (cornerPointB > clip.MaxY)
                            {
                                cornerPointB = clip.MaxY;
                            }

                            block.VertexTopLeft     = renderer.PixelToWorldUnit(leftX, cornerPointA, zIndex);
                            block.VertexTopRight    = renderer.PixelToWorldUnit(left, cornerPointA, zIndex);
                            block.VertexBottomLeft  = renderer.PixelToWorldUnit(leftX, cornerPointB, zIndex);
                            block.VertexBottomRight = renderer.PixelToWorldUnit(left, cornerPointB, zIndex);
                        }

                        break;
                    }

                    // Done!
                    block.Done(transform);
                }

NextLine:
                continue;
            }
        }