Example #1
0
        /// <summary>
        /// updates the cached geometry.
        /// </summary>
        private void CacheGeometry()
        {
            d_cachedGeometryValid = true;
            DestroyGeometryBuffers();

            // if no image, nothing more to do.
            if (d_indicatorImage == null)
            {
                return;
            }

            if (Math.Abs(d_customSize.Width - 0.0f) > float.Epsilon ||
                Math.Abs(d_customSize.Height - 0.0f) > float.Epsilon)
            {
                CalculateCustomOffset();
                var imgRenderSettings = new ImageRenderSettings(new Rectf(d_customOffset, d_customSize));
                d_geometryBuffers.AddRange(d_indicatorImage.CreateRenderGeometry(imgRenderSettings));
            }
            else
            {
                var imgRenderSettings = new ImageRenderSettings(new Rectf(Lunatics.Mathematics.Vector2.Zero, d_indicatorImage.GetRenderedSize()));
                d_geometryBuffers.AddRange(d_indicatorImage.CreateRenderGeometry(imgRenderSettings));
            }

            // TODO: const Rectf clipping_area(glm::vec2(0, 0), System::getSingleton().getRenderer()->getDisplaySize());
            var clipping_area = new Rectf(Lunatics.Mathematics.Vector2.Zero,
                                          System.GetSingleton().GetRenderer().GetDisplaySize());

            UpdateGeometryBuffersClipping(clipping_area);
            UpdateGeometryBuffersTranslation();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="nextGlyphPosX">
        /// The x-coordinate where subsequent text should be rendered to ensure correct
        /// positioning (which is not possible to determine accurately by using the
        /// extent measurement functions).</param>
        /// <param name="position"></param>
        /// <param name="clipRect"></param>
        /// <param name="clippingEnabled"></param>
        /// <param name="colours"></param>
        /// <param name="spaceExtra"></param>
        /// <param name="xScale"></param>
        /// <param name="yScale"></param>
        /// <returns>
        /// Returns a list of GeometryBuffers representing the render geometry of the text.
        /// </returns>
        public List <GeometryBuffer> CreateRenderGeometryForText(string text,
                                                                 out float nextGlyphPosX,
                                                                 Lunatics.Mathematics.Vector2 position,
                                                                 Rectf?clipRect,
                                                                 bool clippingEnabled,
                                                                 ColourRect colours,
                                                                 float spaceExtra = 0.0f,
                                                                 float xScale     = 1.0f,
                                                                 float yScale     = 1.0f)
        {
            var            baseY              = position.Y + GetBaseline(yScale);
            var            glyphPos           = position;
            var            lastChar           = (char)0;
            var            geomBuffers        = new List <GeometryBuffer>();
            GeometryBuffer textGeometryBuffer = null;

            var imgRenderSettings = new ImageRenderSettings(Rectf.Zero, clipRect, clippingEnabled, colours);

            foreach (var c in text)
            {
                var glyph = GetGlyphData(c);
                if (glyph != null)
                {
                    var img = glyph.GetImage();
                    glyphPos.X += GetKerningAmount(lastChar, c);
                    glyphPos.Y  = baseY - (img.GetRenderedOffset().Y - img.GetRenderedOffset().Y *yScale);

                    imgRenderSettings.DestArea = new Rectf(glyphPos, glyph.GetSize(xScale, yScale));

                    if (textGeometryBuffer == null)
                    {
                        var currentGeombuffs = img.CreateRenderGeometry(imgRenderSettings);
                        Debug.Assert(currentGeombuffs.Count <= 1, "Glyphs are expected to be built from a single GeometryBuffer (or none)");
                        if (currentGeombuffs.Count == 1)
                        {
                            textGeometryBuffer = currentGeombuffs[0];
                        }
                    }
                    else
                    {
                        // Else we add geometry to the rendering batch of the existing geometry
                        img.AddToRenderGeometry(textGeometryBuffer, ref imgRenderSettings.DestArea, ref clipRect, colours);
                    }

                    glyphPos.X += glyph.GetAdvance(xScale);
                    // apply extra spacing to space chars
                    if (c == ' ')
                    {
                        glyphPos.X += spaceExtra;
                    }
                }

                lastChar = c;
            }

            if (textGeometryBuffer != null)
            {
                geomBuffers.Add(textGeometryBuffer);
            }

            nextGlyphPosX = glyphPos.X;

            // Adding a single geometry buffer containing the batched glyphs
            return(geomBuffers);
        }
Example #3
0
        // implemets abstract from base
        protected override void AddImageRenderGeometryToWindowImpl(Window srcWindow, Rectf destRect, ColourRect modColours, Rectf?clipper, bool clipToDisplay)
        {
            // get final image to use.
            var img = IsImageFetchedFromProperty()
                          ? srcWindow.GetProperty <Image>(ImagePropertyName)
                          : Image;

            // do not draw anything if image is not set.
            if (img == null)
            {
                return;
            }

            var horzFormatting = HorizontalFormatting.Get(srcWindow);
            var vertFormatting = VerticalFormatting.Get(srcWindow);

            int   horzTiles, vertTiles;
            float xpos, ypos;

            var imgSz = img.GetRenderedSize();

            // calculate final colours to be used
            ColourRect finalColours;

            InitColoursRect(srcWindow, modColours, out finalColours);

            // calculate initial x co-ordinate and horizontal tile count according to formatting options
            switch (horzFormatting)
            {
            case Base.HorizontalFormatting.Stretched:
                imgSz.Width = destRect.Width;
                xpos        = destRect.Left;
                horzTiles   = 1;
                break;

            case Base.HorizontalFormatting.Tiled:
                xpos      = destRect.Left;
                horzTiles = Math.Abs((int)((destRect.Width + (imgSz.Width - 1)) / imgSz.Width));
                break;

            case Base.HorizontalFormatting.LeftAligned:
                xpos      = destRect.Left;
                horzTiles = 1;
                break;

            case Base.HorizontalFormatting.CentreAligned:
                xpos      = destRect.Left + CoordConverter.AlignToPixels((destRect.Width - imgSz.Width) * 0.5f);
                horzTiles = 1;
                break;

            case Base.HorizontalFormatting.RightAligned:
                xpos      = destRect.Right - imgSz.Width;
                horzTiles = 1;
                break;

            default:
                throw new InvalidRequestException("An unknown HorizontalFormatting value was specified.");
            }

            // calculate initial y co-ordinate and vertical tile count according to formatting options
            switch (vertFormatting)
            {
            case Base.VerticalFormatting.Stretched:
                imgSz.Height = destRect.Height;
                ypos         = destRect.Top;
                vertTiles    = 1;
                break;

            case Base.VerticalFormatting.Tiled:
                ypos      = destRect.Top;
                vertTiles = Math.Abs((int)((destRect.Height + (imgSz.Height - 1)) / imgSz.Height));
                break;

            case Base.VerticalFormatting.TopAligned:
                ypos      = destRect.Top;
                vertTiles = 1;
                break;

            case Base.VerticalFormatting.CentreAligned:
                ypos      = destRect.Top + CoordConverter.AlignToPixels((destRect.Height - imgSz.Height) * 0.5f);
                vertTiles = 1;
                break;

            case Base.VerticalFormatting.BottomAligned:
                ypos      = destRect.Bottom - imgSz.Height;
                vertTiles = 1;
                break;

            default:
                throw new InvalidRequestException("An unknown VerticalFormatting value was specified.");
            }

            // perform final rendering (actually is now a caching of the images which will be drawn)
            var imgRenderSettings = new ImageRenderSettings(Rectf.Zero, null, !clipToDisplay, finalColours);

            imgRenderSettings.DestArea.Top    = ypos;
            imgRenderSettings.DestArea.Bottom = ypos + imgSz.Height;

            for (uint row = 0; row < vertTiles; ++row)
            {
                imgRenderSettings.DestArea.Left  = xpos;
                imgRenderSettings.DestArea.Right = xpos + imgSz.Width;

                for (uint col = 0; col < horzTiles; ++col)
                {
                    // use custom clipping for right and bottom edges when tiling the imagery
                    if (((vertFormatting == Base.VerticalFormatting.Tiled) && row == vertTiles - 1) ||
                        ((horzFormatting == Base.HorizontalFormatting.Tiled) && col == horzTiles - 1))
                    {
                        imgRenderSettings.ClipArea = clipper.HasValue
                                                             ? clipper.Value.GetIntersection(destRect)
                                                             : destRect;
                    }
                    // not tiliing, or not on far edges, just used passed in clipper (if any).
                    else
                    {
                        imgRenderSettings.ClipArea = clipper;
                    }

                    // add geometry for image to the target window.
                    var geomBuffers = img.CreateRenderGeometry(imgRenderSettings);
                    srcWindow.AppendGeometryBuffers(geomBuffers);

                    imgRenderSettings.DestArea.d_min.X += imgSz.Width;
                    imgRenderSettings.DestArea.d_max.X += imgSz.Width;
                }

                imgRenderSettings.DestArea.d_min.Y += imgSz.Height;
                imgRenderSettings.DestArea.d_max.Y += imgSz.Height;
            }
        }
Example #4
0
 public ImageRenderSettings(ImageRenderSettings source)
     : this(source.DestArea, source.ClipArea, source.IsClippingEnabled, source.MultiplyColours, source.Alpha)
 {
 }
Example #5
0
        public override List <GeometryBuffer> CreateRenderGeometry(ImageRenderSettings renderSettings)
        {
            Rectf texRect = Rectf.Zero, finalRect;

            var isFullClipped = CalculateTextureAndRenderAreas(renderSettings.DestArea, ref renderSettings.ClipArea, out finalRect, ref texRect);

            if (isFullClipped)
            {
                return(new List <GeometryBuffer>());
            }

            var vbuffer = new TexturedColouredVertex[6];
            var colours = renderSettings.MultiplyColours;

            CreateTexturedQuadVertices(vbuffer, colours, ref finalRect, ref texRect);

            #region original code
            var buffer = System.GetSingleton().GetRenderer().CreateGeometryBufferTextured();

            buffer.SetClippingActive(renderSettings.IsClippingEnabled);
            if (renderSettings.IsClippingEnabled && renderSettings.ClipArea.HasValue)
            {
                buffer.SetClippingRegion(renderSettings.ClipArea.Value);
            }
            buffer.SetTexture("texture0", _texture);
            buffer.AppendGeometry(vbuffer);
            buffer.SetAlpha(renderSettings.Alpha);

            var geomBuffers = new List <GeometryBuffer> {
                buffer
            };
            return(geomBuffers);

            #endregion

            #region xdinos new code

            //GeometryBuffer buffer = imageGeometryBuffers.Count > 0
            //                                ? imageGeometryBuffers[imageGeometryBuffers.Count - 1]
            //                                : null;
            //if (buffer != null)
            //{
            //    if (_lastTexture != _texture ||
            //        (_lastClippingEnabled.HasValue && _lastClippingEnabled.Value != renderSettings.clippingEnabled) ||
            //        (_lastClipArea != renderSettings.clipArea) ||
            //        (_lastAlpha.HasValue && _lastAlpha.Value != renderSettings.alpha))
            //        buffer = null;
            //}

            //if (buffer == null)
            //{
            //    buffer = System.GetSingleton().GetRenderer().CreateGeometryBufferTextured();
            //    imageGeometryBuffers.Add(buffer);

            //    buffer.SetClippingActive(renderSettings.clippingEnabled);
            //    if (renderSettings.clippingEnabled && renderSettings.clipArea.HasValue)
            //        buffer.SetClippingRegion(renderSettings.clipArea.Value);
            //    buffer.SetTexture("texture0", _texture);
            //    buffer.SetAlpha(renderSettings.alpha);

            //    _lastClippingEnabled = renderSettings.clippingEnabled;
            //    _lastClipArea = renderSettings.clipArea;
            //    _lastAlpha = renderSettings.alpha;
            //    _lastTexture = _texture;
            //}

            //buffer.AppendGeometry(vbuffer);

            #endregion
        }
Example #6
0
 /// <summary>
 /// Creates a container of GeometryBuffers based on the Image, providing the
 /// geometry data needed for rendering.
 /// </summary>
 /// <param name="renderSettings">
 /// The ImageRenderSettings that contain render settings for new GeometryBuffers.
 /// </param>
 public abstract List <GeometryBuffer> CreateRenderGeometry(ImageRenderSettings renderSettings);
        public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Vector2 position, ColourRect modColours, Rectf?clipRect, float verticalSpace, float spaceExtra)
        {
            var fnt = GetEffectiveFont(refWnd);

            if (fnt == null)
            {
                return(new List <GeometryBuffer>());
            }

            var finalPos = position;
            var yScale   = 1.0f;

            // handle formatting options
            switch (d_verticalFormatting)
            {
            case VerticalFormatting.BottomAligned:
                finalPos.Y += verticalSpace - GetPixelSize(refWnd).Height;
                break;

            case VerticalFormatting.CentreAligned:
                finalPos.Y += (verticalSpace - GetPixelSize(refWnd).Height) / 2;
                break;

            case VerticalFormatting.Stretched:
                yScale = verticalSpace / GetPixelSize(refWnd).Height;
                break;

            case VerticalFormatting.TopAligned:
                // nothing additional to do for this formatting option.
                break;

            default:
                throw new InvalidRequestException("unknown VerticalFormatting option specified.");
            }

            // apply padding to position:
            finalPos += d_padding.Position;

            // apply modulative colours if needed.
            var finalCols = d_colours;

            if (modColours != null)
            {
                finalCols *= modColours;
            }

            // render selection
            if (d_selectionImage != null && d_selectionLength != 0)
            {
                float selStartExtent = 0f, selEndExtent = 0f;

                if (d_selectionStart > 0)
                {
                    selStartExtent = fnt.GetTextExtent(d_text.CEGuiSubstring(0, d_selectionStart));
                }

                selEndExtent = fnt.GetTextExtent(d_text.CEGuiSubstring(0, d_selectionStart + d_selectionLength));

                var selRect = new Rectf(position.X + selStartExtent,
                                        position.Y,
                                        position.X + selEndExtent,
                                        position.Y + verticalSpace);
                var imgRenderSetting = new ImageRenderSettings(selRect, clipRect, true, new ColourRect(0xFF002FFF));
                d_selectionImage.CreateRenderGeometry(imgRenderSetting);
            }

            // draw the text string.
            return(fnt.CreateRenderGeometryForText(d_text, finalPos, clipRect, true, finalCols, spaceExtra, 1.0f, yScale));
        }
Example #8
0
        protected List <GeometryBuffer> CreateRenderGeometryForImage(Image image, VerticalFormatting vertFmt, HorizontalFormatting horzFmt, Rectf destRect, ColourRect colours, Rectf?clipper, bool clipToDisplay)
        {
            int   horzTiles, vertTiles;
            float xpos, ypos;

            var imgSz = image.GetRenderedSize();

            // calculate initial x co-ordinate and horizontal tile count according to formatting options
            switch (horzFmt)
            {
            case HorizontalFormatting.Stretched:
                imgSz.Width = destRect.Width;
                xpos        = destRect.Left;
                horzTiles   = 1;
                break;

            case HorizontalFormatting.Tiled:
                xpos      = destRect.Left;
                horzTiles = Math.Abs((int)((destRect.Width + (imgSz.Width - 1)) / imgSz.Width));
                break;

            case HorizontalFormatting.LeftAligned:
                xpos      = destRect.Left;
                horzTiles = 1;
                break;

            case HorizontalFormatting.CentreAligned:
                xpos      = destRect.Left + CoordConverter.AlignToPixels((destRect.Width - imgSz.Width) * 0.5f);
                horzTiles = 1;
                break;

            case HorizontalFormatting.RightAligned:
                xpos      = destRect.Right - imgSz.Width;
                horzTiles = 1;
                break;

            default:
                throw new InvalidRequestException("An unknown HorizontalFormatting value was specified.");
            }

            // calculate initial y co-ordinate and vertical tile count according to formatting options
            switch (vertFmt)
            {
            case VerticalFormatting.Stretched:
                imgSz.Height = destRect.Height;
                ypos         = destRect.Top;
                vertTiles    = 1;
                break;

            case VerticalFormatting.Tiled:
                ypos      = destRect.Top;
                vertTiles = Math.Abs((int)((destRect.Height + (imgSz.Height - 1)) / imgSz.Height));
                break;

            case VerticalFormatting.TopAligned:
                ypos      = destRect.Top;
                vertTiles = 1;
                break;

            case VerticalFormatting.CentreAligned:
                ypos      = destRect.Top + CoordConverter.AlignToPixels((destRect.Height - imgSz.Height) * 0.5f);
                vertTiles = 1;
                break;

            case VerticalFormatting.BottomAligned:
                ypos      = destRect.Bottom - imgSz.Height;
                vertTiles = 1;
                break;

            default:
                throw new InvalidRequestException("An unknown VerticalFormatting value was specified.");
            }

            // Create the render geometry
            var geomBuffers    = new List <GeometryBuffer>();
            var renderSettings = new ImageRenderSettings(Rectf.Zero, null, !clipToDisplay, colours);

            renderSettings.DestArea.d_min.Y = ypos;
            renderSettings.DestArea.d_max.Y = ypos + imgSz.Height;

            for (uint row = 0; row < vertTiles; ++row)
            {
                renderSettings.DestArea.d_min.X = xpos;
                renderSettings.DestArea.d_max.X = xpos + imgSz.Width;

                for (uint col = 0; col < horzTiles; ++col)
                {
                    // use custom clipping for right and bottom edges when tiling the imagery
                    if (((vertFmt == VerticalFormatting.Tiled) && row == vertTiles - 1) ||
                        ((horzFmt == HorizontalFormatting.Tiled) && col == horzTiles - 1))
                    {
                        renderSettings.ClipArea = clipper.HasValue ? clipper.Value.GetIntersection(destRect) : destRect;
                    }
                    else
                    {
                        // not tiling, or not on far edges, just used passed in clipper (if any).
                        renderSettings.ClipArea = clipper;
                    }

                    geomBuffers.AddRange(image.CreateRenderGeometry(renderSettings));

                    renderSettings.DestArea.d_min.X += imgSz.Width;
                    renderSettings.DestArea.d_max.X += imgSz.Width;
                }

                renderSettings.DestArea.d_min.Y += imgSz.Height;
                renderSettings.DestArea.d_max.Y += imgSz.Height;
            }

            return(geomBuffers);
        }
Example #9
0
        // implemets abstract from base
        protected override void AddImageRenderGeometryToWindowImpl(Window srcWindow, Rectf destRect, ColourRect modColours, Rectf?clipper,
                                                                   bool clipToDisplay)
        {
            var   backgroundRect = destRect;
            Sizef imageSize;

            Lunatics.Mathematics.Vector2 imageOffsets;
            float leftfactor, rightfactor, topfactor, bottomfactor;
            bool  calcColoursPerImage;

            // vars we use to track what to do with the side pieces.
            float topOffset = 0, bottomOffset = 0, leftOffset = 0, rightOffset = 0;
            float topWidth, bottomWidth, leftHeight, rightHeight;

            topWidth   = bottomWidth = destRect.Width;
            leftHeight = rightHeight = destRect.Height;

            // calculate final overall colours to be used
            ColourRect renderSettingFinalColours;

            InitColoursRect(srcWindow, modColours, out renderSettingFinalColours);

            var renderSettings = new ImageRenderSettings(Rectf.Zero, clipper, !clipToDisplay, renderSettingFinalColours);

            //var renderSettingDestArea = renderSettings.destArea;
            //var renderSettingMultiplyColours = renderSettings.multiplyColours;

            calcColoursPerImage = !renderSettingFinalColours.IsMonochromatic();

            // top-left image
            var componentImage = GetImage(FrameImageComponent.TopLeftCorner, srcWindow);

            if (componentImage != null)
            {
                // calculate final destination area
                imageSize    = componentImage.GetRenderedSize();
                imageOffsets = componentImage.GetRenderedOffset();
                renderSettings.DestArea.d_min = destRect.d_min;
                renderSettings.DestArea.Size  = imageSize;
                renderSettings.DestArea       = destRect.GetIntersection(renderSettings.DestArea);

                // update adjustments required to edges do to presence of this element.
                topOffset  += imageSize.Width + imageOffsets.X;
                leftOffset += imageSize.Height + imageOffsets.Y;
                topWidth   -= topOffset;
                leftHeight -= leftOffset;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + imageOffsets.X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + imageOffsets.Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this element and append it to the Window's geometry
                var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            // top-right image
            componentImage = GetImage(FrameImageComponent.TopRightCorner, srcWindow);
            if (componentImage != null)
            {
                // calculate final destination area
                imageSize    = componentImage.GetRenderedSize();
                imageOffsets = componentImage.GetRenderedOffset();
                renderSettings.DestArea.Left = destRect.Right - imageSize.Width;
                renderSettings.DestArea.Top  = destRect.Top;
                renderSettings.DestArea.Size = imageSize;
                renderSettings.DestArea      = destRect.GetIntersection(renderSettings.DestArea);

                // update adjustments required to edges do to presence of this element.
                rightOffset += imageSize.Height + imageOffsets.Y;
                topWidth    -= imageSize.Width - imageOffsets.X;
                rightHeight -= rightOffset;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + imageOffsets.X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + imageOffsets.Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this element and append it to the Window's geometry
                var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            // bottom-left image
            componentImage = GetImage(FrameImageComponent.BottomLeftCorner, srcWindow);
            if (componentImage != null)
            {
                // calculate final destination area
                imageSize    = componentImage.GetRenderedSize();
                imageOffsets = componentImage.GetRenderedOffset();
                renderSettings.DestArea.Left = destRect.Left;
                renderSettings.DestArea.Top  = destRect.Bottom - imageSize.Height;
                renderSettings.DestArea.Size = imageSize;
                renderSettings.DestArea      = destRect.GetIntersection(renderSettings.DestArea);

                // update adjustments required to edges do to presence of this element.
                bottomOffset += imageSize.Width + imageOffsets.X;
                bottomWidth  -= bottomOffset;
                leftHeight   -= imageSize.Height - imageOffsets.Y;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + imageOffsets.X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + imageOffsets.Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this element and append it to the Window's geometry
                var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            // bottom-right image
            componentImage = GetImage(FrameImageComponent.BottomRightCorner, srcWindow);
            if (componentImage != null)
            {
                // calculate final destination area
                imageSize    = componentImage.GetRenderedSize();
                imageOffsets = componentImage.GetRenderedOffset();
                renderSettings.DestArea.Left = destRect.Right - imageSize.Width;
                renderSettings.DestArea.Top  = destRect.Bottom - imageSize.Height;
                renderSettings.DestArea.Size = imageSize;
                renderSettings.DestArea      = destRect.GetIntersection(renderSettings.DestArea);

                // update adjustments required to edges do to presence of this element.
                bottomWidth -= imageSize.Width - imageOffsets.X;
                rightHeight -= imageSize.Height - imageOffsets.Y;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this element and append it to the Window's geometry
                var imageGeomBuffers = componentImage.CreateRenderGeometry(renderSettings);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            // top image
            componentImage = GetImage(FrameImageComponent.TopEdge, srcWindow);
            if (componentImage != null)
            {
                // calculate final destination area
                imageSize = componentImage.GetRenderedSize();
                renderSettings.DestArea.Left   = destRect.Left + topOffset;
                renderSettings.DestArea.Right  = (renderSettings.DestArea.Left + topWidth);
                renderSettings.DestArea.Top    = destRect.Top;
                renderSettings.DestArea.Bottom = renderSettings.DestArea.Top + imageSize.Height;
                renderSettings.DestArea        = destRect.GetIntersection(renderSettings.DestArea);

                // adjust background area to miss this edge
                backgroundRect.d_min.Y += imageSize.Height + componentImage.GetRenderedOffset().Y;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this image and append it to the Window's geometry
                var imageGeomBuffers = CreateRenderGeometryForImage(componentImage,
                                                                    VerticalFormatting.TopAligned,
                                                                    TopEdgeFormatting.Get(srcWindow),
                                                                    renderSettings.DestArea,
                                                                    renderSettings.MultiplyColours,
                                                                    clipper,
                                                                    clipToDisplay);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            // bottom image
            componentImage = GetImage(FrameImageComponent.BottomEdge, srcWindow);
            if (componentImage != null)
            {
                // calculate final destination area
                imageSize = componentImage.GetRenderedSize();
                renderSettings.DestArea.Left   = destRect.Left + bottomOffset;
                renderSettings.DestArea.Right  = renderSettings.DestArea.Left + bottomWidth;
                renderSettings.DestArea.Bottom = destRect.Bottom;
                renderSettings.DestArea.Top    = renderSettings.DestArea.Bottom - imageSize.Height;
                renderSettings.DestArea        = destRect.GetIntersection(renderSettings.DestArea);

                // adjust background area to miss this edge
                backgroundRect.d_max.Y -= imageSize.Height - componentImage.GetRenderedOffset().Y;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this image and append it to the Window's geometry
                var imageGeomBuffers = CreateRenderGeometryForImage(componentImage,
                                                                    VerticalFormatting.BottomAligned,
                                                                    BottomEdgeFormatting.Get(srcWindow),
                                                                    renderSettings.DestArea,
                                                                    renderSettings.MultiplyColours,
                                                                    clipper,
                                                                    clipToDisplay);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            // left image
            componentImage = GetImage(FrameImageComponent.LeftEdge, srcWindow);
            if (componentImage != null)
            {
                // calculate final destination area
                imageSize = componentImage.GetRenderedSize();
                renderSettings.DestArea.Left   = destRect.Left;
                renderSettings.DestArea.Right  = renderSettings.DestArea.Left + imageSize.Width;
                renderSettings.DestArea.Top    = destRect.Top + leftOffset;
                renderSettings.DestArea.Bottom = renderSettings.DestArea.Top + leftHeight;
                renderSettings.DestArea        = destRect.GetIntersection(renderSettings.DestArea);

                // adjust background area to miss this edge
                backgroundRect.d_min.X += imageSize.Width + componentImage.GetRenderedOffset().X;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this image and append it to the Window's geometry
                var imageGeomBuffers = CreateRenderGeometryForImage(componentImage,
                                                                    LeftEdgeFormatting.Get(srcWindow),
                                                                    HorizontalFormatting.LeftAligned,
                                                                    renderSettings.DestArea,
                                                                    renderSettings.MultiplyColours,
                                                                    clipper,
                                                                    clipToDisplay);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            // right image
            componentImage = GetImage(FrameImageComponent.RightEdge, srcWindow);
            if (componentImage != null)
            {
                // calculate final destination area
                imageSize = componentImage.GetRenderedSize();
                renderSettings.DestArea.Top    = destRect.Top + rightOffset;
                renderSettings.DestArea.Bottom = renderSettings.DestArea.Top + rightHeight;
                renderSettings.DestArea.Right  = destRect.Right;
                renderSettings.DestArea.Left   = renderSettings.DestArea.Right - imageSize.Width;
                renderSettings.DestArea        = destRect.GetIntersection(renderSettings.DestArea);

                // adjust background area to miss this edge
                backgroundRect.d_max.X -= imageSize.Width - componentImage.GetRenderedOffset().X;

                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (renderSettings.DestArea.Left + componentImage.GetRenderedOffset().X) / destRect.Width;
                    rightfactor  = leftfactor + renderSettings.DestArea.Width / destRect.Width;
                    topfactor    = (renderSettings.DestArea.Top + componentImage.GetRenderedOffset().Y) / destRect.Height;
                    bottomfactor = topfactor + renderSettings.DestArea.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                // create render geometry for this image and append it to the Window's geometry
                var imageGeomBuffers = CreateRenderGeometryForImage(componentImage,
                                                                    RightEdgeFormatting.Get(srcWindow),
                                                                    HorizontalFormatting.RightAligned,
                                                                    renderSettings.DestArea,
                                                                    renderSettings.MultiplyColours,
                                                                    clipper,
                                                                    clipToDisplay);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }

            componentImage = GetImage(FrameImageComponent.Background, srcWindow);
            if (componentImage != null)
            {
                // calculate colours that are to be used to this component image
                if (calcColoursPerImage)
                {
                    leftfactor   = (backgroundRect.Left + componentImage.GetRenderedOffset().X) / destRect.Width;
                    rightfactor  = leftfactor + backgroundRect.Width / destRect.Width;
                    topfactor    = (backgroundRect.Top + componentImage.GetRenderedOffset().Y) / destRect.Height;
                    bottomfactor = topfactor + backgroundRect.Height / destRect.Height;

                    renderSettings.MultiplyColours = renderSettingFinalColours.GetSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor);
                }

                var horzFormatting = BackgroundHorzFormatting.Get(srcWindow);
                var vertFormatting = BackgroundVertFormatting.Get(srcWindow);

                var imageGeomBuffers = CreateRenderGeometryForImage(componentImage,
                                                                    vertFormatting,
                                                                    horzFormatting,
                                                                    backgroundRect,
                                                                    renderSettings.MultiplyColours,
                                                                    clipper,
                                                                    clipToDisplay);
                srcWindow.AppendGeometryBuffers(imageGeomBuffers);
            }
        }
        public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Vector2 position, ColourRect modColours, Rectf?clipRect, float verticalSpace, float spaceExtra)
        {
            var window = GetEffectiveWindow(refWnd);

            if (window == null)
            {
                return(new List <GeometryBuffer>());
            }

            var geomBuffers = new List <GeometryBuffer>();

            // HACK: re-adjust for inner-rect of parent
            float xAdj = 0, yAdj = 0;
            var   parent = window.GetParent();

            if (parent != null)
            {
                var outer = parent.GetUnclippedOuterRect().Get();
                var inner = parent.GetUnclippedInnerRect().Get();
                xAdj = inner.d_min.X - outer.d_min.X;
                yAdj = inner.d_min.Y - outer.d_min.Y;
            }
            // HACK: re-adjust for inner-rect of parent (Ends)

            var finalPos = position;

            // handle formatting options
            switch (d_verticalFormatting)
            {
            case VerticalFormatting.BottomAligned:
                finalPos.Y += verticalSpace - GetPixelSize(refWnd).Height;
                break;

            case VerticalFormatting.Stretched:
            case VerticalFormatting.CentreAligned:
                if (d_verticalFormatting == VerticalFormatting.Stretched)
                {
                    System.GetSingleton().Logger.LogEvent("RenderedStringWidgetComponent::draw: " +
                                                          "VerticalFormatting.Stretched specified but is unsupported for Widget types; " +
                                                          "defaulting to VerticalFormatting.CentreAligned instead.");
                }

                finalPos.Y += (verticalSpace - GetPixelSize(refWnd).Height) / 2;
                break;

            case VerticalFormatting.TopAligned:
                // nothing additional to do for this formatting option.
                break;

            default:
                throw new InvalidRequestException("unknown VerticalFormatting option specified.");
            }

            // render the selection if needed
            if (d_selectionImage != null && d_selected)
            {
                var selectArea        = new Rectf(position, GetPixelSize(refWnd));
                var imgRenderSettings = new ImageRenderSettings(selectArea, clipRect, true, new ColourRect(0xFF002FFF));
                geomBuffers.AddRange(d_selectionImage.CreateRenderGeometry(imgRenderSettings));
            }

            // we do not actually draw the widget, we just move it into position.
            var wpos = new UVector2(new UDim(0, finalPos.X + d_padding.d_min.X - xAdj),
                                    new UDim(0, finalPos.Y + d_padding.d_min.Y - yAdj));

            window.SetPosition(wpos);

            return(geomBuffers);
        }