Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public override float GetValue(Window wnd, Rectf container)
 {
     return(GetValue(wnd));
 }
        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);
        }
Esempio n. 5
0
 /// <summary>
 /// Function to do main render caching work.
 /// </summary>
 /// <param name="srcWindow"></param>
 /// <param name="destRect"></param>
 /// <param name="modColours"></param>
 /// <param name="clipper"></param>
 /// <param name="clipToDisplay"></param>
 protected abstract void AddImageRenderGeometryToWindowImpl(Window srcWindow, Rectf destRect, ColourRect modColours, Rectf?clipper, bool clipToDisplay);
Esempio n. 6
0
 public abstract void BlitFromMemoryARGB(byte[] sourceData, Rectf area);
Esempio n. 7
0
 public abstract void BlitFromMemory(IntPtr sourcePtr, Rectf area);
Esempio n. 8
0
 public override float GetValue(Window wnd, Rectf container)
 {
     // This dimension type does not alter when whithin a container Rect.
     return(GetValue(wnd));
 }
Esempio n. 9
0
 public override float GetValue(Window wnd, Rectf container)
 {
     throw new NotImplementedException();
 }