Example #1
0
        private void CreateMainMenuUI()
        {
            var xenkoLogo = new ImageElement { Source = SpriteFromSheet.Create(UIImages, "xk_logo") };

            xenkoLogo.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            xenkoLogo.SetCanvasRelativeSize(new Vector3(0.75f, 0.5f, 1f));
            xenkoLogo.SetCanvasRelativePosition(new Vector3(0.5f, 0.3f, 1f));

            StartButton = new Button
            {
                Content = new TextBlock {Font = Font, Text = "Touch to Start", TextColor = Color.Black, 
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                NotPressedImage = buttonImage,
                PressedImage = buttonImage,
                MouseOverImage = buttonImage,
                Padding = new Thickness(77, 30, 25, 30),
                MinimumWidth = 250f,
            };

            StartButton.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            StartButton.SetCanvasRelativePosition(new Vector3(0.5f, 0.7f, 0f));

            var mainMenuCanvas = new Canvas();
            mainMenuCanvas.Children.Add(xenkoLogo);
            mainMenuCanvas.Children.Add(StartButton);

            mainMenuRoot = new ModalElement
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Content = mainMenuCanvas
            };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var background = new Entity { new BackgroundComponent { Texture = Content.Load<Texture>("XenkoBackground") } };
            Scene.Entities.Add(background);

            var text1 = new TextBlock { Text = "text block button 1", Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true };
            ApplyTextBlockDefaultStyle(text1);
            button1 = new Button { Content = text1 };
            ApplyButtonDefaultStyle(button1);
            button1.SetCanvasRelativePosition(new Vector3(0.025f, 0.05f, 0f));

            edit1 = new EditText() { Text = "Edit text 1", Font = Content.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true, };
            ApplyEditTextDefaultStyle(edit1);
            edit1.SetCanvasRelativePosition(new Vector3(0.025f, 0.15f, 0f));

            var text2 = new TextBlock { Text = "text block button 2", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), SynchronousCharacterGeneration = true };
            ApplyTextBlockDefaultStyle(text2);
            button2 = new Button { Content = text2 };
            ApplyButtonDefaultStyle(button2);
            edit2 = new EditText() { Text = "Edit text 2", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), };
            ApplyEditTextDefaultStyle(edit2);

            stackPanel = new StackPanel
            {
                Children = { button2, edit2 }, 
                HorizontalAlignment = HorizontalAlignment.Center, 
                VerticalAlignment = VerticalAlignment.Center, 
                Orientation = Orientation.Horizontal
            };
            stackPanel.SetCanvasRelativePosition(new Vector3(0.5f, 0.5f, 0f));
            stackPanel.SetCanvasPinOrigin(new Vector3(.5f));

            canvas = new Canvas { Children = {button1, edit1, stackPanel}, CanBeHitByUser = true };

            button1.MouseOverStateChanged += (sender, args) => { triggeredButton1 = true; oldValueButton1 = args.OldValue; newValueButton1 = args.NewValue;};
            button2.MouseOverStateChanged += (sender, args) => { triggeredButton2 = true;};
            edit1.MouseOverStateChanged += (sender, args) => { triggeredEdit1 = true;};
            edit2.MouseOverStateChanged += (sender, args) => { triggeredEdit2 = true;};
            canvas.MouseOverStateChanged += (sender, args) => { triggeredCanvas = true;};
            stackPanel.MouseOverStateChanged += (sender, args) => { triggeredStackPanel = true;};

            canvas.UIElementServices = new UIElementServices { Services = this.Services };

            UIComponent.Page = new Engine.UIPage { RootElement = canvas };
        }
Example #3
0
        private void CreateGameOverUI()
        {
            MenuButton = new Button
            {
                Content = new TextBlock { Font = Font, Text = "Menu", TextColor = Color.Black, 
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                PressedImage = buttonImage,
                NotPressedImage = buttonImage,
                MouseOverImage = buttonImage,
                Padding = new Thickness(77, 30, 25, 30),
                MinimumWidth = 190f,
            };

            MenuButton.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            MenuButton.SetCanvasRelativePosition(new Vector3(0.70f, 0.7f, 0f));

            RetryButton = new Button
            {
                Content = new TextBlock { Font = Font, Text = "Retry", TextColor = Color.Black, 
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                Padding = new Thickness(74, 30, 25, 30),
                MinimumWidth = 190f,
                PressedImage = buttonImage,
                MouseOverImage = buttonImage,
                NotPressedImage = buttonImage
            };

            RetryButton.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            RetryButton.SetCanvasRelativePosition(new Vector3(0.3f, 0.7f, 0f));

            var gameOverCanvas = new Canvas();
            gameOverCanvas.Children.Add(MenuButton);
            gameOverCanvas.Children.Add(RetryButton);
            
            gameOverRoot = new ModalElement
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Content = gameOverCanvas
            };
        }
Example #4
0
        private Button CreateButton(string text, SpriteFont font, int offset)
        {
            var button = new Button
            {
                Name = text,
                Padding = Thickness.UniformRectangle(15),
                HorizontalAlignment = HorizontalAlignment.Left,
                Content = new TextBlock { Text = text, Font = font, TextSize = 35, TextColor = new Color(200, 200, 200, 255) },
                BackgroundColor = new Color(new Vector4(0.2f, 0.2f, 0.2f, 0.2f)),
            };
            button.Click += (sender, args) => ChangeConstraint(offset);
            button.SetCanvasPinOrigin(new Vector3(offset > 0 ? 1 : 0, 0.5f, 0));
            button.SetCanvasRelativePosition(new Vector3(offset > 0 ? 0.87f : 0.13f, 0.93f, 0));

            return button;
        }
Example #5
0
        public void TestComputeAvailableSize()
        {
            var child = new Button();
            child.SetCanvasPinOrigin(new Vector3(0, 0.5f, 1));

            // tests in the cases position is absolute
            var availableSize = new Vector3(100, 150, 200);
            child.SetCanvasAbsolutePosition(new Vector3(-1, -2, -3));
            Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasAbsolutePosition(new Vector3(0, 0, 0));
            Utilities.AreExactlyEqual(new Vector3(100, 0, 0), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasAbsolutePosition(new Vector3(1, 2, 3));
            Utilities.AreExactlyEqual(new Vector3(99, 4, 3), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasAbsolutePosition(availableSize);
            Utilities.AreExactlyEqual(new Vector3(0, 0, 200), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasAbsolutePosition(availableSize + new Vector3(1, 2, 3));
            Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false));

            // tests in the cases position is relative
            child.SetCanvasRelativePosition(new Vector3(-1, -2, -3));
            Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasRelativePosition(new Vector3(0, 0, 0));
            Utilities.AreExactlyEqual(new Vector3(100, 0, 0), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasRelativePosition(new Vector3(0.1f, 0.2f, 0.4f));
            Utilities.AreExactlyEqual(new Vector3(90, 60, 80), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasRelativePosition(new Vector3(1f));
            Utilities.AreExactlyEqual(new Vector3(0, 0, 200), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasRelativePosition(new Vector3(1.1f, 2f, 3f));
            Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false));

            // tests in the case available size are infinite
            availableSize = new Vector3(float.PositiveInfinity);
            child.SetCanvasAbsolutePosition(new Vector3(-1, -2, -3));
            Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasAbsolutePosition(new Vector3(1, 2, 3));
            Utilities.AreExactlyEqual(new Vector3(float.PositiveInfinity, 4, 3), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasRelativePosition(new Vector3(-1f, -2f, -3f));
            Utilities.AreExactlyEqual(new Vector3(0), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasRelativePosition(new Vector3(1f, 2f, 3f));
            Utilities.AreExactlyEqual(new Vector3(float.PositiveInfinity), ComputeAvailableSize(child, availableSize, false));
            child.SetCanvasRelativeSize(new Vector3(0, 0.5f, 1.5f));
            Utilities.AreExactlyEqual(new Vector3(0, float.PositiveInfinity, float.PositiveInfinity), ComputeAvailableSize(child, availableSize, false));
        }
Example #6
0
        public void TestComputeAbsolutePinPosition()
        {
            var child = new Button();

            // directly set the values
            var parentSize = new Vector3(2);
            child.SetCanvasRelativePosition(new Vector3(float.NaN));
            child.SetCanvasAbsolutePosition(new Vector3(-1.5f, 0, 1.5f));
            Assert.AreEqual(child.GetCanvasAbsolutePosition(), ComputeAbsolutePinPosition(child, ref parentSize));
            child.SetCanvasAbsolutePosition(new Vector3(float.NaN));
            child.SetCanvasRelativePosition(new Vector3(-1.5f, 0, 1.5f));
            Assert.AreEqual(2*child.GetCanvasRelativePosition(), ComputeAbsolutePinPosition(child, ref parentSize));

            // indirectly set the value
            child.SetCanvasAbsolutePosition(new Vector3(-1.5f, 0, 1.5f));
            child.SetCanvasRelativePosition(new Vector3(float.NaN));
            Assert.AreEqual(child.GetCanvasAbsolutePosition(), ComputeAbsolutePinPosition(child, ref parentSize));
            child.SetCanvasRelativePosition(new Vector3(-1.5f, 0, 1.5f));
            child.SetCanvasAbsolutePosition(new Vector3(float.NaN));
            Assert.AreEqual(2*child.GetCanvasRelativePosition(), ComputeAbsolutePinPosition(child, ref parentSize));

            // indirect/direct mix
            child.SetCanvasAbsolutePosition(new Vector3(-1.5f, float.NaN, 1.5f));
            child.SetCanvasRelativePosition(new Vector3(float.NaN, 1, float.NaN));
            Assert.AreEqual(new Vector3(-1.5f, 2, 1.5f), ComputeAbsolutePinPosition(child, ref parentSize));
            child.SetCanvasRelativePosition(new Vector3(-1.5f, float.NaN, 1.5f));
            child.SetCanvasAbsolutePosition(new Vector3(float.NaN, 1, float.NaN));
            Assert.AreEqual(new Vector3(-3f, 1, 3f), ComputeAbsolutePinPosition(child, ref parentSize));

            // infinite values
            parentSize = new Vector3(float.PositiveInfinity);
            child.SetCanvasRelativePosition(new Vector3(-1.5f, 0, 1.5f));
            Utilities.AreExactlyEqual(new Vector3(float.NegativeInfinity, 0f, float.PositiveInfinity), ComputeAbsolutePinPosition(child, ref parentSize));
        }