コード例 #1
0
        public Texture GetStretchableTexture(
            WndWindowDefinition wndWindow,
            WndDrawData wndDrawData,
            int leftIndex,
            int middleIndex,
            int rightIndex)
        {
            var cacheKey = new WndImageKey
            {
                DestinationSize = wndWindow.ScreenRect.ToRectangle().Size,
                LeftImage       = wndDrawData.Items[leftIndex].Image,
                MiddleImage     = wndDrawData.Items[middleIndex].Image,
                RightImage      = wndDrawData.Items[rightIndex].Image
            };

            if (!_cache.TryGetValue(cacheKey, out var result))
            {
                var leftMappedImageTexture   = GetMappedImage(cacheKey.LeftImage);
                var middleMappedImageTexture = GetMappedImage(cacheKey.MiddleImage);
                var rightMappedImageTexture  = GetMappedImage(cacheKey.RightImage);

                if (leftMappedImageTexture != null &&
                    middleMappedImageTexture != null &&
                    rightMappedImageTexture != null)
                {
                    result = CreateTexture(
                        cacheKey,
                        drawingContext =>
                    {
                        var leftWidth  = leftMappedImageTexture.SourceRect.Width;
                        var rightWidth = rightMappedImageTexture.SourceRect.Width;
                        var leftRect   = new Rectangle(0, 0, leftWidth, cacheKey.DestinationSize.Height);
                        drawingContext.DrawImage(
                            leftMappedImageTexture.Texture,
                            leftMappedImageTexture.SourceRect,
                            leftRect);
                        var middleRect = new Rectangle(leftRect.Right, 0, cacheKey.DestinationSize.Width - leftWidth - rightWidth, cacheKey.DestinationSize.Height);
                        drawingContext.DrawImage(
                            middleMappedImageTexture.Texture,
                            middleMappedImageTexture.SourceRect,
                            middleRect);
                        var rightRect = new Rectangle(middleRect.Right, 0, rightWidth, cacheKey.DestinationSize.Height);
                        drawingContext.DrawImage(
                            rightMappedImageTexture.Texture,
                            rightMappedImageTexture.SourceRect,
                            rightRect);
                    });
                }
                else
                {
                    result = null;
                }

                _cache.Add(cacheKey, result);
            }

            return(result);
        }
コード例 #2
0
        public Image CreateNormalImage(
            WndDrawData wndDrawData,
            int index)
        {
            var leftImage          = wndDrawData.Items[index].Image;
            var mappedImageTexture = GetMappedImage(leftImage);

            if (mappedImageTexture != null)
            {
                return(new Image(mappedImageTexture.SourceRect.Size, size =>
                {
                    var cacheKey = new WndImageKey
                    {
                        DestinationSize = size,
                        LeftImage = leftImage
                    };

                    if (!_cache.TryGetValue(cacheKey, out var result))
                    {
                        result = CreateTexture(
                            cacheKey,
                            spriteBatch =>
                        {
                            spriteBatch.DrawImage(
                                mappedImageTexture.Texture,
                                mappedImageTexture.SourceRect,
                                new Rectangle(Point2D.Zero, size).ToRectangleF(),
                                ColorRgbaF.White);
                        });

                        _cache.Add(cacheKey, result);
                    }

                    return result;
                }));
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public Image CreateNormalImage(string mappedImageName)
        {
            var leftImage          = mappedImageName;
            var mappedImageTexture = GetMappedImage(leftImage);

            if (mappedImageTexture != null)
            {
                bool requiresFlip = !_contentManager.GraphicsDevice.IsUvOriginTopLeft;

                return(new Image(mappedImageName, mappedImageTexture.SourceRect.Size, size =>
                {
                    var cacheKey = new WndImageKey
                    {
                        DestinationSize = size,
                        LeftImage = leftImage
                    };

                    if (!_cache.TryGetValue(cacheKey, out var result))
                    {
                        result = CreateTexture(
                            cacheKey,
                            spriteBatch =>
                        {
                            spriteBatch.DrawImage(
                                mappedImageTexture.Texture,
                                mappedImageTexture.SourceRect,
                                new Rectangle(Point2D.Zero, size).ToRectangleF(),
                                ColorRgbaF.White);
                        });

                        _cache.Add(cacheKey, result);
                    }

                    return result;
                }, requiresFlip));
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public Image CreateFileImage(string fileImageName)
        {
            bool requiresFlip = !_contentManager.GraphicsDevice.IsUvOriginTopLeft;
            var  texture      = _contentManager.Load <Texture>(fileImageName);

            return(new Image(fileImageName, new Size((int)texture.Width, (int)texture.Height), size =>
            {
                var cacheKey = new WndImageKey
                {
                    DestinationSize = size,
                    LeftImage = fileImageName,
                };

                if (!_cache.TryGetValue(cacheKey, out var result))
                {
                    result = texture;

                    _cache.Add(cacheKey, result);
                }

                return result;
            }, requiresFlip));
        }
コード例 #5
0
        public Texture GetNormalTexture(
            WndWindowDefinition wndWindow,
            WndDrawData wndDrawData,
            int index)
        {
            var cacheKey = new WndImageKey
            {
                DestinationSize = wndWindow.ScreenRect.ToRectangle().Size,
                LeftImage       = wndDrawData.Items[index].Image
            };

            if (!_cache.TryGetValue(cacheKey, out var result))
            {
                var mappedImageTexture = GetMappedImage(cacheKey.LeftImage);

                if (mappedImageTexture != null)
                {
                    result = CreateTexture(
                        cacheKey,
                        drawingContext =>
                    {
                        drawingContext.DrawImage(
                            mappedImageTexture.Texture,
                            mappedImageTexture.SourceRect,
                            new Rectangle(Point2D.Zero, cacheKey.DestinationSize));
                    });
                }
                else
                {
                    result = null;
                }

                _cache.Add(cacheKey, result);
            }

            return(result);
        }
コード例 #6
0
        public Image CreateStretchableImage(
            WndDrawData wndDrawData,
            int leftIndex,
            int middleIndex,
            int rightIndex)
        {
            var leftImage   = wndDrawData.Items[leftIndex].Image;
            var middleImage = wndDrawData.Items[middleIndex].Image;
            var rightImage  = wndDrawData.Items[rightIndex].Image;

            var leftMappedImageTexture   = GetMappedImage(leftImage);
            var middleMappedImageTexture = GetMappedImage(middleImage);
            var rightMappedImageTexture  = GetMappedImage(rightImage);

            if (leftMappedImageTexture != null &&
                middleMappedImageTexture != null &&
                rightMappedImageTexture != null)
            {
                var naturalSize = new Size(
                    leftMappedImageTexture.SourceRect.Width + middleMappedImageTexture.SourceRect.Width + rightMappedImageTexture.SourceRect.Width,
                    leftMappedImageTexture.SourceRect.Height);

                return(new Image(naturalSize, size =>
                {
                    var cacheKey = new WndImageKey
                    {
                        DestinationSize = size,
                        LeftImage = leftImage,
                        MiddleImage = middleImage,
                        RightImage = rightImage
                    };

                    if (!_cache.TryGetValue(cacheKey, out var result))
                    {
                        result = CreateTexture(
                            cacheKey,
                            spriteBatch =>
                        {
                            var leftWidth = leftMappedImageTexture.SourceRect.Width;
                            var rightWidth = rightMappedImageTexture.SourceRect.Width;
                            var leftRect = new Rectangle(0, 0, leftWidth, cacheKey.DestinationSize.Height);
                            spriteBatch.DrawImage(
                                leftMappedImageTexture.Texture,
                                leftMappedImageTexture.SourceRect,
                                leftRect.ToRectangleF(),
                                ColorRgbaF.White);
                            var middleRect = new Rectangle(leftRect.Right, 0, cacheKey.DestinationSize.Width - leftWidth - rightWidth, cacheKey.DestinationSize.Height);
                            spriteBatch.DrawImage(
                                middleMappedImageTexture.Texture,
                                middleMappedImageTexture.SourceRect,
                                middleRect.ToRectangleF(),
                                ColorRgbaF.White);
                            var rightRect = new Rectangle(middleRect.Right, 0, rightWidth, cacheKey.DestinationSize.Height);
                            spriteBatch.DrawImage(
                                rightMappedImageTexture.Texture,
                                rightMappedImageTexture.SourceRect,
                                rightRect.ToRectangleF(),
                                ColorRgbaF.White);
                        });

                        _cache.Add(cacheKey, result);
                    }

                    return result;
                }));
            }
            else
            {
                return(null);
            }
        }
コード例 #7
0
ファイル: WndImageLoader.cs プロジェクト: hcll123456/OpenSAGE
        public Image CreateStretchableImage(
            WndDrawData wndDrawData,
            int leftIndex,
            int middleIndex,
            int rightIndex)
        {
            var leftImage   = wndDrawData.Items[leftIndex].Image;
            var middleImage = wndDrawData.Items[middleIndex].Image;
            var rightImage  = wndDrawData.Items[rightIndex].Image;

            var leftMappedImageTexture   = GetMappedImage(leftImage);
            var middleMappedImageTexture = GetMappedImage(middleImage);
            var rightMappedImageTexture  = GetMappedImage(rightImage);

            if (leftMappedImageTexture != null &&
                middleMappedImageTexture != null &&
                rightMappedImageTexture != null)
            {
                var naturalSize = new Size(
                    leftMappedImageTexture.Coords.Width + middleMappedImageTexture.Coords.Width + rightMappedImageTexture.Coords.Width,
                    leftMappedImageTexture.Coords.Height);

                bool requiresFlip = !_contentManager.GraphicsDevice.IsUvOriginTopLeft;

                return(new Image("WndImage", naturalSize, size =>
                {
                    var cacheKey = new WndImageKey
                    {
                        DestinationSize = size,
                        LeftImage = leftImage,
                        MiddleImage = middleImage,
                        RightImage = rightImage
                    };

                    if (!_cache.TryGetValue(cacheKey, out var result))
                    {
                        result = CreateTexture(
                            cacheKey,
                            spriteBatch =>
                        {
                            var leftWidth = leftMappedImageTexture.Coords.Width;
                            var rightWidth = rightMappedImageTexture.Coords.Width;
                            var leftRect = new Rectangle(0, 0, leftWidth, cacheKey.DestinationSize.Height);
                            spriteBatch.DrawImage(
                                leftMappedImageTexture.Texture.Value,
                                leftMappedImageTexture.Coords,
                                leftRect.ToRectangleF(),
                                ColorRgbaF.White,
                                requiresFlip);
                            var middleRect = new Rectangle(leftRect.Right, 0, cacheKey.DestinationSize.Width - leftWidth - rightWidth, cacheKey.DestinationSize.Height);
                            spriteBatch.DrawImage(
                                middleMappedImageTexture.Texture.Value,
                                middleMappedImageTexture.Coords,
                                middleRect.ToRectangleF(),
                                ColorRgbaF.White,
                                requiresFlip);
                            var rightRect = new Rectangle(middleRect.Right, 0, rightWidth, cacheKey.DestinationSize.Height);
                            spriteBatch.DrawImage(
                                rightMappedImageTexture.Texture.Value,
                                rightMappedImageTexture.Coords,
                                rightRect.ToRectangleF(),
                                ColorRgbaF.White,
                                requiresFlip);
                        });

                        _cache.Add(cacheKey, result);
                    }

                    return result;
                }));
            }
            else
            {
                return(null);
            }
        }