Esempio n. 1
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;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Return the current vertical formatting setting for this ImageryComponent.
 /// </summary>
 /// <param name="wnd"></param>
 /// <returns>
 /// One of the VerticalFormatting enumerated values.
 /// </returns>
 public VerticalFormatting GetVerticalFormatting(Window wnd)
 {
     return(VerticalFormatting.Get(wnd));
 }
Esempio n. 3
0
 /// <summary>
 /// Set the vertical formatting setting for this ImageryComponent.
 /// </summary>
 /// <param name="fmt">
 /// One of the VerticalFormatting enumerated values.
 /// </param>
 public void SetVerticalFormatting(VerticalFormatting fmt)
 {
     VerticalFormatting.Set(fmt);
 }
Esempio n. 4
0
 /// <summary>
 /// Set the name of a property that will be used to obtain the vertical
 /// formatting to use for this ImageryComponent.
 /// </summary>
 /// <param name="propertyName"></param>
 public void SetVerticalFormattingPropertySource(string propertyName)
 {
     VerticalFormatting.SetPropertySource(propertyName);
 }
 /// <summary>
 /// Set the VerticalFormatting option for this component.
 /// </summary>
 /// <param name="fmt"></param>
 public void SetVerticalFormatting(VerticalFormatting fmt)
 {
     d_verticalFormatting = fmt;
 }
Esempio n. 6
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. 7
0
 /// <summary>
 /// Set the formatting to be used for the right edge image.
 /// </summary>
 /// <param name="fmt">
 /// One of the VerticalFormatting enumerated values.
 /// </param>
 public void SetRightEdgeFormatting(VerticalFormatting fmt)
 {
     RightEdgeFormatting.Set(fmt);
 }
Esempio n. 8
0
 /// <summary>
 /// Set the formatting to be used for the left edge image.
 /// </summary>
 /// <param name="fmt">
 /// One of the VerticalFormatting enumerated values.
 /// </param>
 public void SetLeftEdgeFormatting(VerticalFormatting fmt)
 {
     LeftEdgeFormatting.Set(fmt);
 }
Esempio n. 9
0
 /// <summary>
 /// Set the vertical formatting to be used for the background image.
 /// </summary>
 /// <param name="fmt">
 /// One of the VerticalFormatting enumerated values.
 /// </param>
 public void SetBackgroundVerticalFormatting(VerticalFormatting fmt)
 {
     BackgroundVertFormatting.Set(fmt);
 }