Exemplo n.º 1
0
        public void TestMeasureOverride()
        {
            var rand = new Random();
            var imageSize = new Vector3(100, 50, 0);
            var Sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = Sprite };

            // Fixed sized
            image.StretchType = StretchType.None;
            image.Measure(rand.NextVector3());
            Assert.AreEqual(imageSize, image.DesiredSizeWithMargins);

            // Uniform sized
            image.StretchType = StretchType.Uniform;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(50, 25, 0), image.DesiredSizeWithMargins);

            // Uniform to fill sized
            image.StretchType = StretchType.UniformToFill;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(100, 50, 0), image.DesiredSizeWithMargins);

            // Fill on stretch
            image.StretchType = StretchType.FillOnStretch;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(50, 25, 0), image.DesiredSizeWithMargins);

            // Fill
            image.StretchType = StretchType.Fill;
            image.Measure(new Vector3(50));
            Assert.AreEqual(new Vector3(50, 50, 0), image.DesiredSizeWithMargins);

            // Test minimal size due to borders
            image.StretchType = StretchType.Fill;
            image.Measure(new Vector3());
            Assert.AreEqual(new Vector3(4, 6, 0), image.DesiredSizeWithMargins);

            // Test with infinite value
            for (var type = 0; type < 5; ++type)
                TestMeasureOverrideInfiniteValues((StretchType)type);

            // Test stretch directions
            image.StretchType = StretchType.Fill;
            image.StretchDirection = StretchDirection.DownOnly;
            image.Measure(new Vector3(200, 300, 220));
            Assert.AreEqual(new Vector3(100, 50, 0), image.DesiredSizeWithMargins);
            image.Measure(new Vector3(20, 15, 30));
            Assert.AreEqual(new Vector3(20, 15, 0), image.DesiredSizeWithMargins);
            image.StretchDirection = StretchDirection.UpOnly;
            image.Measure(new Vector3(200, 300, 220));
            Assert.AreEqual(new Vector3(200, 300, 0), image.DesiredSizeWithMargins);
            image.Measure(new Vector3(20, 30, 22));
            Assert.AreEqual(new Vector3(100, 50, 0), image.DesiredSizeWithMargins);
        }
Exemplo n.º 2
0
        private static void InvalidateTrackBackground(object propertyowner, PropertyKey<Sprite> propertykey, Sprite propertyoldvalue)
        {
            var slider = (Slider)propertyowner;

            slider.InvalidateMeasure();

            if (propertyoldvalue != null)
                propertyoldvalue.SizeChanged -= slider.OnSizeChanged;

            if(slider.TrackBackgroundImage != null)
                slider.TrackBackgroundImage.SizeChanged += slider.OnSizeChanged;
        }
        private SpriteFromTexture(Sprite source)
            : this()
        {
            sprite = source;
            isSpriteDirty = false;

            center = sprite.Center;
            centerFromMiddle = false;
            isTransparent = sprite.IsTransparent;
            // FIXME: should we use the Max, Min, average of X and/or Y?
            pixelsPerUnit = sprite.PixelsPerUnit.X;
            texture = sprite.Texture;
        }
        public BackgroundSection(Sprite backgroundSprite, Vector3 screenVirtualResolution, float scrollSpeed, float depth, Vector2 startPos = default(Vector2))
        {
            screenResolution = new Int2((int)screenVirtualResolution.X, (int)screenVirtualResolution.Y);
            screenCenter = new Vector2(screenVirtualResolution.X / 2, screenVirtualResolution.Y /2);

            this.depth = depth;
            firstQuadPos = startPos;
            secondQuadPos = startPos;

            ScrollSpeed = scrollSpeed;
            ScrollPos = 0;

            CreateBackground(backgroundSprite.Texture, backgroundSprite.Region);
        }
Exemplo n.º 5
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprite = new Sprite(Asset.Load<Texture>("BorderButton")) { Borders = new Vector4(64, 64, 64, 64) };

            var bi1 = new ImageElement { Source = sprite, Height = 150 };
            var bi2 = new ImageElement { Source = sprite, Height = 300 };
            var bi3 = new ImageElement { Source = sprite, Height = 500 };

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            stackPanel.Children.Add(bi1);
            stackPanel.Children.Add(bi2);
            stackPanel.Children.Add(bi3);

            UIComponent.RootElement = new ScrollViewer { Content = stackPanel, ScrollMode = ScrollingMode.HorizontalVertical };
        }
Exemplo n.º 6
0
        public void Constructor2Tests()
        {
            PerformTest(game =>
            {
                // texture
                var textureSize = new Vector2(50, 75);
                var texture = Texture.New2D(game.GraphicsDevice, (int)textureSize.X, (int)textureSize.Y, 1, PixelFormat.R8G8B8A8_UNorm);
                var sprite = new Sprite(texture);
                var sprite2 = new Sprite(texture);
                Assert.IsNotNull(sprite.Name);
                Assert.AreNotEqual(sprite.Name, sprite2.Name);
                Assert.AreEqual(ImageOrientation.AsIs, sprite.Orientation);
                Assert.AreEqual(textureSize/2, sprite.Center);
                Assert.AreEqual(Vector4.Zero, sprite.Borders);
                Assert.IsFalse(sprite.HasBorders);
                Assert.AreEqual(texture, sprite.Texture);
                Assert.IsTrue(sprite.IsTransparent);
                Assert.AreEqual(new Vector2(100), sprite.PixelsPerUnit);
                Assert.AreEqual(new RectangleF(0, 0, textureSize.X, textureSize.Y), sprite.Region);
                Assert.AreEqual(textureSize/100, sprite.Size);
                Assert.AreEqual(textureSize, sprite.SizeInPixels);
            });

            PerformTest(game =>
            {
                // texture + name
                var textureSize = new Vector2(50, 75);
                var texture = Texture.New2D(game.GraphicsDevice, (int)textureSize.X, (int)textureSize.Y, 1, PixelFormat.R8G8B8A8_UNorm);
                var sprite = new Sprite(DefaultName, texture);
                Assert.AreEqual(DefaultName, sprite.Name);
                Assert.AreEqual(ImageOrientation.AsIs, sprite.Orientation);
                Assert.AreEqual(textureSize / 2, sprite.Center);
                Assert.AreEqual(Vector4.Zero, sprite.Borders);
                Assert.IsFalse(sprite.HasBorders);
                Assert.AreEqual(texture, sprite.Texture);
                Assert.IsTrue(sprite.IsTransparent);
                Assert.AreEqual(new Vector2(100), sprite.PixelsPerUnit);
                Assert.AreEqual(new RectangleF(0, 0, textureSize.X, textureSize.Y), sprite.Region);
                Assert.AreEqual(textureSize / 100, sprite.Size);
                Assert.AreEqual(textureSize, sprite.SizeInPixels);
            });
        }
Exemplo n.º 7
0
        public void TestBasicInvalidations()
        {
            var source = new Sprite();

            // ReSharper disable ImplicitlyCapturedClosure

            // - test the properties that are supposed to invalidate the object measurement
            UIElementLayeringTests.TestMeasureInvalidation(this, () => StretchType = StretchType.None);
            UIElementLayeringTests.TestMeasureInvalidation(this, () => StretchDirection = StretchDirection.DownOnly);
            UIElementLayeringTests.TestMeasureInvalidation(this, () => Source = source);
            UIElementLayeringTests.TestMeasureInvalidation(this, () => source.Region = new Rectangle(1, 2, 3, 4));
            UIElementLayeringTests.TestMeasureInvalidation(this, () => source.Orientation = ImageOrientation.Rotated90);
            UIElementLayeringTests.TestMeasureInvalidation(this, () => source.Borders = Vector4.One);

            // - test the properties that are not supposed to invalidate the object layout state
            UIElementLayeringTests.TestNoInvalidation(this, () => source.Region = new Rectangle(8, 9, 3, 4)); // if the size of the region does not change we avoid re-measuring
            UIElementLayeringTests.TestNoInvalidation(this, () => source.Orientation = ImageOrientation.Rotated90); // no changes
            UIElementLayeringTests.TestNoInvalidation(this, () => source.Borders = Vector4.One); // no changes

            // ReSharper restore ImplicitlyCapturedClosure
        }
Exemplo n.º 8
0
        public void Constructor1Tests()
        {
            {
                // empty
                var sprite = new Sprite();
                var sprite2 = new Sprite();
                Assert.IsNotNull(sprite.Name);
                Assert.AreNotEqual(sprite.Name, sprite2.Name);
                Assert.AreEqual(ImageOrientation.AsIs, sprite.Orientation);
                Assert.AreEqual(Vector2.Zero, sprite.Center);
                Assert.AreEqual(Vector4.Zero, sprite.Borders);
                Assert.IsFalse(sprite.HasBorders);
                Assert.IsNull(sprite.Texture);
                Assert.IsTrue(sprite.IsTransparent);
                Assert.AreEqual(new Vector2(100), sprite.PixelsPerUnit);
                Assert.AreEqual(new RectangleF(), sprite.Region);
                Assert.AreEqual(Vector2.Zero, sprite.Size);
                Assert.AreEqual(Vector2.Zero, sprite.SizeInPixels);
            }

            {
                // name
                var sprite = new Sprite(DefaultName);
                Assert.AreEqual(DefaultName, sprite.Name);
                Assert.AreEqual(ImageOrientation.AsIs, sprite.Orientation);
                Assert.AreEqual(Vector2.Zero, sprite.Center);
                Assert.AreEqual(Vector4.Zero, sprite.Borders);
                Assert.IsFalse(sprite.HasBorders);
                Assert.IsNull(sprite.Texture);
                Assert.IsTrue(sprite.IsTransparent);
                Assert.AreEqual(new Vector2(100), sprite.PixelsPerUnit);
                Assert.AreEqual(new RectangleF(), sprite.Region);
                Assert.AreEqual(Vector2.Zero, sprite.Size);
                Assert.AreEqual(Vector2.Zero, sprite.SizeInPixels);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Calculates the actual image size from the size that is available.
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="availableSizeWithoutMargins"></param>
        /// <param name="stretchType"></param>
        /// <param name="stretchDirection"></param>
        /// <param name="isMeasuring"></param>
        /// <returns></returns>
        public static Vector3 CalculateImageSizeFromAvailable(Sprite sprite, Vector3 availableSizeWithoutMargins, StretchType stretchType, StretchDirection stretchDirection, bool isMeasuring)
        {
            if (sprite == null) // no associated image -> no region needed
                return Vector3.Zero;

            var idealSize = sprite.SizeInPixels;
            if (idealSize.X <= 0 || idealSize.Y <= 0) // image size null or invalid -> no region needed
                return Vector3.Zero;

            if (float.IsInfinity(availableSizeWithoutMargins.X) && float.IsInfinity(availableSizeWithoutMargins.Y)) // unconstrained available size -> take the best size for the image: the image size
                return new Vector3(idealSize, 0);

            // initialize the desired size with maximum available size
            var desiredSize = availableSizeWithoutMargins;

            // compute the desired image ratios
            var desiredScale = new Vector2(desiredSize.X / idealSize.X, desiredSize.Y / idealSize.Y);

            // when the size along a given axis is free take the same ratio as the constrained axis.
            if (float.IsInfinity(desiredScale.X))
                desiredScale.X = desiredScale.Y;
            if (float.IsInfinity(desiredScale.Y))
                desiredScale.Y = desiredScale.X;

            // adjust the scales depending on the type of stretch to apply
            switch (stretchType)
            {
                case StretchType.None:
                    desiredScale = Vector2.One;
                    break;
                case StretchType.Uniform:
                    desiredScale.X = desiredScale.Y = Math.Min(desiredScale.X, desiredScale.Y);
                    break;
                case StretchType.UniformToFill:
                    desiredScale.X = desiredScale.Y = Math.Max(desiredScale.X, desiredScale.Y);
                    break;
                case StretchType.FillOnStretch:
                    // if we are only measuring we prefer keeping the image resolution than using all the available space.
                    if (isMeasuring)
                        desiredScale.X = desiredScale.Y = Math.Min(desiredScale.X, desiredScale.Y);
                    break;
                case StretchType.Fill:
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(stretchType));
            }

            // adjust the scales depending on the stretch directions
            switch (stretchDirection)
            {
                case StretchDirection.Both:
                    break;
                case StretchDirection.DownOnly:
                    desiredScale.X = Math.Min(desiredScale.X, 1);
                    desiredScale.Y = Math.Min(desiredScale.Y, 1);
                    break;
                case StretchDirection.UpOnly:
                    desiredScale.X = Math.Max(1, desiredScale.X);
                    desiredScale.Y = Math.Max(1, desiredScale.Y);
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(stretchDirection));
            }

            // update the desired size based on the desired scales
            desiredSize = new Vector3(idealSize.X * desiredScale.X, idealSize.Y * desiredScale.Y, 0f);
            
            if (!isMeasuring || !sprite.HasBorders)
                return desiredSize;

            // consider sprite borders
            var borderSum = new Vector2(sprite.BordersInternal.X + sprite.BordersInternal.Z, sprite.BordersInternal.Y + sprite.BordersInternal.W);
            if (sprite.Orientation == ImageOrientation.Rotated90)
                Utilities.Swap(ref borderSum.X, ref borderSum.Y);

            return new Vector3(Math.Max(desiredSize.X, borderSum.X), Math.Max(desiredSize.Y, borderSum.Y), desiredSize.Z);
        }
Exemplo n.º 10
0
        public void TestArrangeOverrideInfiniteValues(StretchType stretch)
        {
            var imageSize = new Vector3(100, 50, 0);
            var Sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = Sprite, StretchType = stretch };

            image.Arrange(new Vector3(float.PositiveInfinity), false);
            Assert.AreEqual(imageSize, image.RenderSize);

            image.Arrange(new Vector3(150, float.PositiveInfinity, 10), false);
            Assert.AreEqual(stretch == StretchType.None ? imageSize : new Vector3(150, 75, 0), image.RenderSize);
        }
Exemplo n.º 11
0
 private static void OnAspectImageInvalidated(object propertyOwner, PropertyKey<Sprite> propertyKey, Sprite propertyOldValue)
 {
     var button = (Button)propertyOwner;
     button.OnAspectImageInvalidated();
 }
Exemplo n.º 12
0
        private void InitializeMainPage()
        {
            var rootElement = page.RootElement;

            // counters
            bonusCounter = rootElement.FindVisualChildOfType<TextBlock>("bonusCounter");
            lifeCounter = rootElement.FindVisualChildOfType<TextBlock>("lifeCounter");
            moneyCounter = rootElement.FindVisualChildOfType<TextBlock>("moneyCounter");
            Bonus = 30;
            LifeStatus = 3;
            Money = 30;

            // lifebar
            lifebarGaugeImage = MainSceneImages["life_bar"];
            lifebarGrid = rootElement.FindVisualChildOfType<Grid>("lifebarGrid");
            gaugeBarRegion = lifebarGaugeImage.Region;

            // character name
            nameTextBlock = rootElement.FindVisualChildOfType<TextBlock>("nameTextBlock");

            // explanation
            // FIXME: UI asset should support multiline text
            var explanationText = rootElement.FindVisualChildOfType<TextBlock>("explanationText");
            explanationText.Text = "Pictogram-based alphabets are easily supported.\n日本語も簡単に入れることが出来ます。";

            // status stars
            var statusPanel = rootElement.FindVisualChildOfType<UniformGrid>("statusPanel");
            powerStatusStar = statusPanel.FindVisualChildOfType<ImageElement>("powerStatusStar");
            controlStatusStar = statusPanel.FindVisualChildOfType<ImageElement>("controlStatusStar");
            speedStatusStar = statusPanel.FindVisualChildOfType<ImageElement>("speedStatusStar");
            PowerStatus = shipList[activeShipIndex].Power;
            ControlStatus = shipList[activeShipIndex].Control;
            SpeedStatus = shipList[activeShipIndex].Speed;

            // ship selection
            var currentShipButton = rootElement.FindVisualChildOfType<Button>("currentShipButton");
            currentShipButton.Click += delegate
            {
                // Once click, update the SpaceShip status pop-up and show it.
                UpdateShipStatus();
                ShowShipSelectionPopup();
            };
            currentShipImage = currentShipButton.FindVisualChildOfType<ImageElement>("currentShipImage");

            // upgrade buttons
            var statusUpgradePanel = rootElement.FindVisualChildOfType<UniformGrid>("statusUpgradePanel");
            SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("powerStatusButton"), 2, 0, () => PowerStatus, () => PowerStatus++);
            SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("controlStatusButton"), 2, 0, () => ControlStatus, () => ControlStatus++);
            SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("speedStatusButton"), 2, 0, () => SpeedStatus, () => SpeedStatus++);
            SetupStatusButton(statusUpgradePanel.FindVisualChildOfType<ButtonBase>("lifeStatusButton"), 1, 1, () => 0, () => LifeStatus++);

            // quit button
            var quitButton = rootElement.FindVisualChildOfType<Button>("quitButton");
            quitButton.Click += delegate { UIGame.Exit(); };
        }
Exemplo n.º 13
0
        public void TestMeasureOverride()
        {
            var slider = new Slider();
            var sprite = new Sprite { Region = new RectangleF(2, 3, 40, 50) };

            slider.Measure(new Vector3(100, 200, 300));
            Assert.AreEqual(new Vector3(0), slider.RenderSize);
            
            slider.TrackBackgroundImage = (SpriteFromTexture)sprite;
            slider.Measure(new Vector3(100, 200, 300));
            Assert.AreEqual(new Vector3(100, 50, 0), slider.DesiredSize);

            slider.Orientation = Orientation.Vertical;
            slider.Measure(new Vector3(100, 200, 300));
            Assert.AreEqual(new Vector3(50, 200, 0), slider.DesiredSize);

            slider.Orientation = Orientation.InDepth;
            slider.Measure(new Vector3(100, 200, 300));
            Assert.AreEqual(new Vector3(50, 50, 300), slider.DesiredSize); // subject to changes

            slider.Orientation = Orientation.Horizontal;
            sprite.Orientation = ImageOrientation.Rotated90;
            slider.Measure(new Vector3(100, 200, 300));
            Assert.AreEqual(new Vector3(100, 40, 0), slider.DesiredSize);
            
            slider.Orientation = Orientation.Vertical;
            slider.Measure(new Vector3(100, 200, 300));
            Assert.AreEqual(new Vector3(40, 200, 0), slider.DesiredSize);

            sprite.Orientation = ImageOrientation.AsIs;
            slider.Measure(new Vector3(100, 200, 300));
            Assert.AreEqual(new Vector3(50, 200, 0), slider.DesiredSize);
        }
Exemplo n.º 14
0
 private void OnSpriteChanged(Sprite currentSprite)
 {
     if (sprite != null)
     {
         sprite.SizeChanged -= InvalidateMeasure;
         sprite.BorderChanged -= InvalidateMeasure;
     }
     sprite = currentSprite;
     InvalidateMeasure();
     if (sprite != null)
     {
         sprite.SizeChanged += InvalidateMeasure;
         sprite.BorderChanged += InvalidateMeasure;
     }
 }
Exemplo n.º 15
0
        public void TestArrangeOverride()
        {
            var rand = new Random();
            var imageSize = new Vector3(100, 50, 0);
            var sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = (SpriteFromTexture)sprite };

            // Fixed sized
            image.StretchType = StretchType.None;
            image.Arrange(rand.NextVector3(), false);
            Assert.AreEqual(imageSize, image.RenderSize);

            // Uniform sized
            image.StretchType = StretchType.Uniform;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(50, 25, 0), image.RenderSize);

            // Uniform to fill sized
            image.StretchType = StretchType.UniformToFill;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(100, 50, 0), image.RenderSize);

            // Fill on stretch
            image.StretchType = StretchType.FillOnStretch;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(50, 50, 0), image.RenderSize);

            // Fill
            image.StretchType = StretchType.Fill;
            image.Arrange(new Vector3(50), false);
            Assert.AreEqual(new Vector3(50, 50, 0), image.RenderSize);

            // Test there is no minimal size due to borders in arrange
            image.StretchType = StretchType.Fill;
            image.Arrange(new Vector3(), false);
            Assert.AreEqual(new Vector3(), image.RenderSize);

            // Test with infinite value
            for (var type = 0; type < 5; ++type)
                TestArrangeOverrideInfiniteValues((StretchType)type);

            // Test stretch directions
            image.StretchType = StretchType.Fill;
            image.StretchDirection = StretchDirection.DownOnly;
            image.Arrange(new Vector3(200, 300, 220), false);
            Assert.AreEqual(new Vector3(100, 50, 0), image.RenderSize);
            image.Arrange(new Vector3(20, 15, 30), false);
            Assert.AreEqual(new Vector3(20, 15, 0), image.RenderSize);
            image.StretchDirection = StretchDirection.UpOnly;
            image.Arrange(new Vector3(200, 300, 220), false);
            Assert.AreEqual(new Vector3(200, 300, 0), image.RenderSize);
            image.Arrange(new Vector3(20, 30, 22), false);
            Assert.AreEqual(new Vector3(100, 50, 0), image.RenderSize);
        }
Exemplo n.º 16
0
 private void OnTrackBackgroundSpriteChanged(Sprite currentSprite)
 {
     if (trackBackgroundSprite != null)
     {
         trackBackgroundSprite.SizeChanged -= InvalidateMeasure;
         trackBackgroundSprite.BorderChanged -= InvalidateMeasure;
     }
     trackBackgroundSprite = currentSprite;
     InvalidateMeasure();
     if (trackBackgroundSprite != null)
     {
         trackBackgroundSprite.SizeChanged += InvalidateMeasure;
         trackBackgroundSprite.BorderChanged += InvalidateMeasure;
     }
 }
Exemplo n.º 17
0
        private UIElement CreateBottomBar()
        {
            // Create Life bar
            lifeBarGaugeImage = ButtonsImages["rope_small"];
            gaugeBarRegion = lifeBarGaugeImage.Region;

            var lifebarGauge = new ImageElement
            {
                Name = "LifeBarBackground",
                Source = SpriteFromSheet.Create(ButtonsImages, "rope_small"),
                StretchType = StretchType.Fill,
            };
            lifebarGauge.SetGridColumn(1);

            lifeBarGrid = new Grid();
            lifeBarGrid.Children.Add(lifebarGauge);
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 8));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 0));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 100));
            lifeBarGrid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 8));
            lifeBarGrid.RowDefinitions.Add(new StripDefinition());
            lifeBarGrid.LayerDefinitions.Add(new StripDefinition());
            lifeBarGrid.SetCanvasRelativePosition(new Vector3(0f, 0.185f, 0f));
            lifeBarGrid.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f));
            lifeBarGrid.SetPanelZIndex(-1);


            // the main grid of the top bar
            var mainLayer = new Canvas
            {
                VerticalAlignment = VerticalAlignment.Top,
                MaximumHeight = 10
            };

            mainLayer.Children.Add(lifeBarGrid);

            return mainLayer;
        }
Exemplo n.º 18
0
 public void TestBasicInvalidations()
 {
     // - test the properties that are not supposed to invalidate the object layout state
     UIElementLayeringTests.TestNoInvalidation(this, () => PressedImage = new Sprite());
     UIElementLayeringTests.TestNoInvalidation(this, () => NotPressedImage = new Sprite());
 }
Exemplo n.º 19
0
        public void TestMeasureOverrideInfiniteValues(StretchType stretch)
        {
            var imageSize = new Vector3(100, 50, 0);
            var sprite = new Sprite { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = (SpriteFromTexture)sprite, StretchType = stretch };
            
            image.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(imageSize, image.DesiredSizeWithMargins);

            image.Measure(new Vector3(150, float.PositiveInfinity, 10));
            Assert.AreEqual(stretch == StretchType.None ? imageSize : new Vector3(150, 75, 0), image.DesiredSizeWithMargins);
        }