Ejemplo n.º 1
0
        public void Button_StateChangesOnMouseEvent_Test()
        {
            var button = new Button(new TestHelpers.RootElement(), AssetManager)
            {
                DestRect = new Rectangle(0.0f, 0.0f, 0.5f, 0.5f)
            };

            // We need to check that "template" does not consume our event.
            var block = new TextBlock(button, AssetManager) { Name = "Normal TextBlock" };
            button.SetTemplate(ButtonState.Normal, block.Name);

            button.InjectMouseMoveEvent(0.0f, 0.0f);
            Assert.AreEqual(ButtonState.Hover, button.State);

            button.InjectMouseDownEvent(0.0f, 0.0f, MouseButton.Left);
            Assert.AreEqual(ButtonState.Pushed, button.State);

            button.InjectMouseUpEvent(0.0f, 0.0f, MouseButton.Left);
            Assert.AreEqual(ButtonState.Hover, button.State);

            button.InjectMouseDownEvent(0.0f, 0.0f, MouseButton.Right);
            Assert.AreEqual(ButtonState.Hover, button.State);

            button.InjectMouseMoveEvent(button.AbsRect.Left - 1, button.AbsRect.Top - 1);
            Assert.AreEqual(ButtonState.Normal, button.State);
        }
Ejemplo n.º 2
0
        public void RocketCommanderGame_Mouse_Test()
        {
            var game = new TestGame();

            Layout layout = null;
            game.Initialized += (o, e) =>
                {
                    layout = new Layout("MouseState", game.Framework.AssetManager)
                    {
                        DestRect = new Rectangle(0.0f, 0.1f, 1.0f, 1.0f)
                    };

                    var mouseBlock = new TextBlock(layout, game.Framework.AssetManager)
                    {
                        Font = game.Framework.AssetManager.DefaultFont,
                        Foreground = Color.Red,
                        Name = "MouseBlock"
                    };

                    game.AddLayout(layout);
                };
            game.Mouse.MouseMove += (o, e) =>
                {
                    var mouseBlock = layout.GetElement("MouseBlock") as TextBlock;
                    mouseBlock.Text = game.Mouse.Position.ToString();
                };

            game.Run();
        }
Ejemplo n.º 3
0
        public void Button_Render_Test()
        {
            var button = new Button(new TestHelpers.RootElement(), AssetManager);
            TestHelpers.RenderSprite(Device, (s) => Assert.IsFalse((button as ISprite).Render(s)));

            var block = new TextBlock(button, AssetManager) { Name = "Normal TextBlock" };
            button.SetTemplate(ButtonState.Normal, block.Name);
            TestHelpers.RenderSprite(Device, s => Assert.IsTrue((button as ISprite).Render(s)));
        }
Ejemplo n.º 4
0
        public void Button_SetTemplate_Test()
        {
            var button = new Button(new TestHelpers.RootElement(), AssetManager);
            var block = new TextBlock(button, AssetManager) { Name = "Normal TextBlock" };

            Assert.IsTrue(button.SetTemplate(ButtonState.Normal, block.Name));
            Assert.IsFalse(block.IsLogical);
            Assert.AreEqual(block, button.GetTemplate(ButtonState.Normal));

            Assert.IsFalse(button.SetTemplate(ButtonState.Normal, "NonExistingChildName"));

            Assert.IsTrue(button.SetTemplate(ButtonState.Normal, null));
            Assert.IsTrue(block.IsLogical);
        }
Ejemplo n.º 5
0
 private void AddDebugLayout()
 {
     this.debugLayout = new Layout("Debug", this.framework.AssetManager);
     var fpsText = new TextBlock(debugLayout, this.framework.AssetManager)
     {
         Font = framework.AssetManager.DefaultFont,
         Name = fpsTextName,
         Foreground = Color.White
     };
     AddLayout(this.debugLayout);
 }
Ejemplo n.º 6
0
 private void AddTextBlock()
 {
     var textBlock = new TextBlock(Element, this.assetManager)
     {
         Font = this.assetManager.DefaultFont
     };
     Childs.Add(UIElementEditor.Create(this, textBlock, this.assetManager));
 }
Ejemplo n.º 7
0
 private void AddButton()
 {
     var button = new Button(Element, this.assetManager);
     var textBlock = new TextBlock(button, assetManager) { Name = "NormalTemplate" };
     button.SetTemplate(ButtonState.Normal, textBlock.Name);
     Childs.Add(UIElementEditor.Create(this, button, this.assetManager));
 }
Ejemplo n.º 8
0
        public void Button_State_Test()
        {
            var button = new Button(new TestHelpers.RootElement(), AssetManager);
            var block = new TextBlock(button, AssetManager) { Name = "Normal TextBlock" };
            var img = new Image(button, AssetManager) { Name = "Hover Image" };

            button.SetTemplate(ButtonState.Normal, block.Name);
            button.SetTemplate(ButtonState.Hover, img.Name);

            Assert.AreEqual(ButtonState.Normal, button.State);
            Assert.IsTrue(block.IsVisible);
            Assert.IsFalse(img.IsVisible);

            button.State = ButtonState.Hover;
            Assert.IsFalse(block.IsVisible);
            Assert.IsTrue(img.IsVisible);
        }
Ejemplo n.º 9
0
        public void Button_XmlSerialize_Test()
        {
            var parent = new TestHelpers.RootElement();
            var expected = new Button(parent, AssetManager);
            var block = new TextBlock(expected, AssetManager) { Name = "Normal TextBlock" };
            expected.SetTemplate(ButtonState.Normal, block.Name);

            var stream = new MemoryStream();
            using (var xmlWriter = XmlWriter.Create(stream))
            {
                expected.WriteXml(xmlWriter);
            }

            stream.Position = 0;
            var actual = new Button(parent, AssetManager);
            using (var xmlReader = XmlReader.Create(stream))
            {
                actual.ReadXml(xmlReader);
            }

            Assert.AreEqual(block.Name, actual.GetTemplate(ButtonState.Normal).Name);
            Assert.IsNull(actual.GetTemplate(ButtonState.Hover));
        }