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