Exemple #1
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            Sprites = Asset.Load<SpriteSheet>("UIImages");

            var lifeBar = new ImageElement { Source = Sprites["Logo"], HorizontalAlignment = HorizontalAlignment.Center };
            lifeBar.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);

            var quitGameButton = new Button
                {
                    Content = new TextBlock { Text = "Quit Game", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") },
                    VerticalAlignment = VerticalAlignment.Bottom,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Padding = Thickness.UniformRectangle(10),
                };
            quitGameButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            quitGameButton.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            quitGameButton.Click += (sender, args) => Exit();

            modalButton1Text = new TextBlock { Text = "Close Modal window 1", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") };
            var modalButton1 = new Button
            {
                Name = "Button Modal 1",
                Content = modalButton1Text,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding = Thickness.UniformRectangle(10),
            };
            modalButton1.Click += ModalButton1OnClick;
            modal1 = new ModalElement { Content = modalButton1, Name = "Modal 1"};
            modal1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            modal1.OutsideClick += Modal1OnOutsideClick;

            modalButton2Text = new TextBlock { Text = "Close Modal window 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") };
            var modalButton2 = new Button
            {
                Name = "Button Modal 2",
                Content = modalButton2Text,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding = Thickness.UniformRectangle(10),
            };
            modalButton2.Click += ModalButton2OnClick;
            modal2 = new ModalElement { Content = modalButton2, Name = "Modal 2" };
            modal2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2);
            modal2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal2.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            modal2.OutsideClick += Modal2OnOutsideClick;

            uniformGrid = new UniformGrid { Columns = 3, Rows = 3 };
            uniformGrid.Children.Add(modal1);
            uniformGrid.Children.Add(modal2);
            uniformGrid.Children.Add(lifeBar);
            uniformGrid.Children.Add(quitGameButton);
            
            UIComponent.RootElement = uniformGrid;
        }
Exemple #2
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            imageElement = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv"))};
            UIComponent.RootElement = imageElement;
        }
        public void TestEventFreezing()
        {
            // check that values can freely be modified by default
            Assert.AreEqual(false, IsBeingRouted);
            var image = new ImageElement();
            var routedEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("test", RoutingStrategy.Tunnel, typeof(RoutedEventArgsTest));
            Source = image;
            Assert.AreEqual(image, Source);
            Source = null;
            Assert.AreEqual(null, Source);
            RoutedEvent = routedEvent;
            Assert.AreEqual(routedEvent, RoutedEvent);
            RoutedEvent = null;
            Assert.AreEqual(null, RoutedEvent);

            // check that value of IsBeingRouted is updated
            StartEventRouting();
            Assert.AreEqual(true, IsBeingRouted);

            // check that modifications are now prohibited
            Assert.Throws<InvalidOperationException>(() => Source = null);
            Assert.Throws<InvalidOperationException>(() => RoutedEvent = null);

            // check that value of IsBeingRouted is update
            EndEventRouting();
            Assert.AreEqual(false, IsBeingRouted);
        }
Exemple #4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprites = Asset.Load<SpriteSheet>("RotatedImages");
            var img1 = new ImageElement { Source = sprites["NRNR"], StretchType = StretchType.Fill };
            var img2 = new ImageElement { Source = sprites["RNR"], StretchType = StretchType.Fill };
            var img3 = new ImageElement { Source = sprites["NRR"], StretchType = StretchType.Fill };
            var img4 = new ImageElement { Source = sprites["RR"], StretchType = StretchType.Fill };

            img1.SetGridColumnSpan(2);
            img2.SetGridColumnSpan(2);
            img2.SetGridRow(1);
            img3.SetGridRowSpan(2);
            img3.SetGridColumn(2);
            img4.SetGridRowSpan(2);
            img4.SetGridColumn(3);

            var grid = new UniformGrid
            {
                Rows = 2, 
                Columns = 4,
                Children = { img1, img2, img3, img4 }
            };

            UIComponent.RootElement = grid;
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var cube = Asset.Load<Entity>("cube");
            cube.Transform.Scale = new Vector3(10000);
            cube.Transform.Position = new Vector3(0, 0, 10);
            Scene.AddChild(cube);

            var imageElement = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")) };
            var imageEntity = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(150) } };
            imageEntity.Transform.Position = new Vector3(-500, 0, 0);
            Scene.AddChild(imageEntity);

            var imageEntity2 = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(200) } };
            imageEntity2.Transform.Position = new Vector3(0, 250, 0);
            Scene.AddChild(imageEntity2);

            var imageEntity3 = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(250) } };
            imageEntity3.Transform.Position = new Vector3(0, 0, -500);
            Scene.AddChild(imageEntity3);
            
            // setup the camera
            var camera = new TestCamera { Yaw = MathUtil.Pi/4, Pitch = MathUtil.Pi/4, Position = new Vector3(500, 500, 500), MoveSpeed = 100 };
            camera.SetTarget(cube, true);
            CameraComponent = camera.Camera;
            Script.Add(camera);
        }
        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);
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var uiImages = Asset.Load<UIImageGroup>("RotatedImages");
            var img1 = new ImageElement { Source = uiImages["NotRotated"], StretchType = StretchType.Fill };
            var img2 = new ImageElement { Source = uiImages["Rotated90"], StretchType = StretchType.Fill };

            img2.DependencyProperties.Set(GridBase.RowPropertyKey, 1);

            var grid = new UniformGrid { Rows = 2 };
            grid.Children.Add(img1);
            grid.Children.Add(img2);

            UIComponent.RootElement = grid;
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

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

            var bi1 = new ImageElement { Source = uiImage, Height = 150 };
            var bi2 = new ImageElement { Source = uiImage, Height = 300 };
            var bi3 = new ImageElement { Source = uiImage, 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 };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var image1 = new ImageElement
            {
                Source = new UIImage(Asset.Load<Texture>("BorderButtonCentered")) { Region = new Rectangle(256, 128, 512, 256), Borders = new Vector4(0.125f, 0.125f, 0.25f, 0.25f) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image2 = new ImageElement
            {
                Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(0, 0, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image3 = new ImageElement
            {
                Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(512, 0, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image4 = new ImageElement
            {
                Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(0, 512, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var image5 = new ImageElement
            {
                Source = new UIImage(Asset.Load<Texture>("uv")) { Region = new Rectangle(512, 512, 512, 512) },
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            stackPanel.Children.Add(image1);
            stackPanel.Children.Add(image2);
            stackPanel.Children.Add(image3);
            stackPanel.Children.Add(image4);
            stackPanel.Children.Add(image5);

            UIComponent.RootElement = new ScrollViewer { Content = stackPanel };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var uiImages = Asset.Load<UIImageGroup>("UIImages");

            var img1 = new ImageElement { Name = "UV 1 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) };
            var img2 = new ImageElement { Name = "UV 2 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) };
            img3 = new ImageElement { Name = "UV 3 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) };

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            stackPanel.Children.Add(img1);
            stackPanel.Children.Add(img2);
            stackPanel.Children.Add(img3);

            var img4 = new ImageElement { Name = "UV grid", Source = new UIImage(Asset.Load<Texture>("uv")) };
            var img5 = new ImageElement { Name = "UV grid 2", Source = new UIImage(Asset.Load<Texture>("uv")) };
            var img6 = new ImageElement { Name = "Game screen grid", Source = uiImages["GameScreen"] };

            img4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img4.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img5.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            img5.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            img6.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);

            grid = new UniformGrid { Columns = 2, Rows = 2 };
            grid.Children.Add(img4);
            grid.Children.Add(img5);
            grid.Children.Add(img6);

            scrollViewer = new ScrollViewer { Content = grid, ScrollMode = ScrollingMode.HorizontalVertical};

            contentDecorator = new ContentDecorator { Content = scrollViewer };

            UIComponent.RootElement = contentDecorator;
        }
Exemple #11
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var imgElt = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.Fill };
            imgElt.DependencyProperties.Set(GridBase.RowSpanPropertyKey, 2);
            imgElt.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            imgElt.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            imgElt.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            var button1 = new Button();
            button1.DependencyProperties.Set(GridBase.RowPropertyKey, 3);
            button1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);

            var button2 = new Button();
            button2.DependencyProperties.Set(GridBase.RowPropertyKey, 3);
            button2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 3);

            var text = new TextBlock
            {
                Text = "Test Uniform Grid", 
                Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), 
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };
            text.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            text.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            text.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            var grid = new UniformGrid { Rows = 4, Columns = 4};
            grid.Children.Add(imgElt);
            grid.Children.Add(button1);
            grid.Children.Add(button2);
            grid.Children.Add(text);

            UIComponent.RootElement = grid;
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var uiImages = Asset.Load<UIImageGroup>("UIImages");

            var imgElt1 = new ImageElement { Source = uiImages["GameScreen"], StretchType = StretchType.Fill };
            imgElt1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 0);
            imgElt1.DependencyProperties.Set(GridBase.RowSpanPropertyKey, 3);
            imgElt1.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);
            imgElt1.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            imgElt1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);

            var imgElt2 = new ImageElement { Source = uiImages["Logo"], StretchType = StretchType.Fill };
            imgElt2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);
            imgElt2.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            imgElt2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);

            var imgElt3 = new ImageElement { Source = uiImages["Logo"], StretchType = StretchType.Fill };
            imgElt3.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2);
            imgElt3.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            imgElt3.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);

            var imgElt4 = new ImageElement { Source = uiImages["BorderButton"], StretchType = StretchType.Fill };
            imgElt4.DependencyProperties.Set(Panel.ZIndexPropertyKey, 3);
            imgElt4.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            imgElt4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            var grid = new UniformGrid { Rows = 3, Columns = 3 };
            grid.Children.Add(imgElt1);
            grid.Children.Add(imgElt2);
            grid.Children.Add(imgElt3);
            grid.Children.Add(imgElt4);

            UIComponent.RootElement = grid;
        }
        private UIElement CreateMainScreneTopBar()
        {
            // Create Life bar
            lifeBarGaugeImage = mainScreneImages["life_bar"];
            var lifeBarCoverImage = mainScreneImages["character_frame"];
            gaugeBarRegion = lifeBarGaugeImage.Region;

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

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

            var lifebarForeground = new ImageElement
            {
                Name = "LifeBarForeGround",
                Source = lifeBarCoverImage,
                StretchType = StretchType.Fill,
            };
            lifebarForeground.SetGridColumnSpan(3);
            lifebarForeground.SetGridRowSpan(3);
            lifebarForeground.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f));

            // Life count
            lifeCounter = new TextBlock
            {
                Text = CreateLifeCountText(),
                TextColor = Color.Gold,
                Font = westernFont,
                TextSize = 32,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            lifeCounter.SetCanvasAbsolutePosition(new Vector3(lifeBarCoverImage.Borders.X, float.NaN, float.NaN));
            lifeCounter.SetCanvasRelativePosition(new Vector3(float.NaN, 0.44f, 0f));
            lifeCounter.SetPanelZIndex(1);
            LifeStatus = 3;

            // Bonus items
            var bonusIcon = new ImageElement
            {
                Source = mainScreneImages["gold_icon"],
                Name = "bonus Icon",
                VerticalAlignment = VerticalAlignment.Center
            };
            bonusCounter = new TextBlock
            {
                Text = CreateBonusCountText(),
                TextColor = Color.White,
                TextSize = 27,
                Font = westernFont,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(10, 0, 0, 0)
            };

            // Money 
            var moneyIcon = new ImageElement
            {
                Source = mainScreneImages["money_icon"],
                Name = "money Icon",
                Margin = new Thickness(20, 0, 0, 0),
                VerticalAlignment = VerticalAlignment.Center
            };
            moneyCounter = new TextBlock
            {
                Text = CreateMoneyCountText(),
                TextColor = Color.White,
                TextSize = 27,
                Font = westernFont,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(10, 0, 0, 0)
            };

            // Stack panel containing the bonus and money counters
            var moneyBonusStackPanel = new StackPanel
            {
                Name = "MoneyBonusStackPanel",
                Orientation = Orientation.Horizontal,
            };
            moneyBonusStackPanel.Children.Add(bonusIcon);
            moneyBonusStackPanel.Children.Add(bonusCounter);
            moneyBonusStackPanel.Children.Add(moneyIcon);
            moneyBonusStackPanel.Children.Add(moneyCounter);
            moneyBonusStackPanel.SetCanvasRelativePosition(new Vector3(0.93f, 0.44f, 0f));
            moneyBonusStackPanel.SetCanvasRelativeSize(new Vector3(float.NaN, 0.4f, 1f));
            moneyBonusStackPanel.SetCanvasPinOrigin(new Vector3(1f, 0f, 0f));
            moneyBonusStackPanel.SetPanelZIndex(1);

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

            mainLayer.Children.Add(lifeBarGrid);
            mainLayer.Children.Add(lifebarForeground);
            mainLayer.Children.Add(lifeCounter);
            mainLayer.Children.Add(moneyBonusStackPanel);

            return mainLayer;
        }
        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);
        }
        protected override void LoadScene()
        {
            // Allow user to resize the window with the mouse.
            Game.Window.AllowUserResizing = true;

            var arial = LoadAsset<SpriteFont>("WesternFont");
            var uiImages = LoadAsset<SpriteSheet>("SplashScreenImages");

            // Create and initialize "Paradox Samples" Text
            var paradoxSampleTextBlock = new ContentDecorator
            {
                BackgroundImage = uiImages["paradox_sample_text_bg"],
                Content = new TextBlock
                {
                    Font = arial,
                    TextSize = 60,
                    Text = "Paradox Samples",
                    TextColor = Color.White,
                },
                Padding = new Thickness(35, 15, 35, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            paradoxSampleTextBlock.SetPanelZIndex(1);

            // Create and initialize "UI" Text
            var uiTextBlock = new ContentDecorator
            {
                BackgroundImage = uiImages["ui_text_bg"],
                Content = new TextBlock
                {
                    Font = arial,
                    TextSize = 60,
                    Text = "UI",
                    TextColor = Color.White,
                },
                Padding = new Thickness(15, 4, 15, 7),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            uiTextBlock.SetPanelZIndex(1);
            uiTextBlock.SetGridRow(1);

            // Create and initialize Paradox Logo
            var paradoxLogoImageElement = new ImageElement
            {
                Source = uiImages["Logo"],
                HorizontalAlignment = HorizontalAlignment.Center
            };

            paradoxLogoImageElement.SetPanelZIndex(1);
            paradoxLogoImageElement.SetGridRow(3);

            // Create and initialize "Touch Screen to Start"
            var touchStartLabel = new ContentDecorator
            {
                BackgroundImage = uiImages["touch_start_frame"],
                Content = new TextBlock
                {
                    Font = arial,
                    TextSize = 42,
                    Text = "Touch Screen to Start",
                    TextColor = Color.White
                },
                Padding = new Thickness(30, 20, 30, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            touchStartLabel.SetPanelZIndex(1);
            touchStartLabel.SetGridRow(5);

            var grid = new Grid
            {
                MaximumWidth = 600,
                MaximumHeight = 900,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Star, 5));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(paradoxSampleTextBlock);
            grid.Children.Add(uiTextBlock);
            grid.Children.Add(paradoxLogoImageElement);
            grid.Children.Add(touchStartLabel);

            // Add the background
            var background = new ImageElement { Source = uiImages["background_uiimage"], StretchType = StretchType.Fill };
            background.SetPanelZIndex(-1);

            Entity.Get<UIComponent>().RootElement = new UniformGrid { Children = { background, grid } };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var resolution = (Vector3)UIComponent.VirtualResolution;

            var canvas = new Canvas();
            var imgElt = new ImageElement { Name = "UV image", Source = new Sprite(Asset.Load<Texture>("uv")), Width = resolution.X / 5, Height = resolution.Y / 5, StretchType = StretchType.Fill };
            imgElt.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One);
            imgElt.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 10, resolution.Y / 10, 0));
            imgElt.DependencyProperties.Set(Panel.ZIndexPropertyKey, -1);

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };

            scrollViewer = new ScrollViewer { ScrollMode = ScrollingMode.Vertical };
            scrollViewer.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 4, resolution.Y / 10, 0));
            scrollViewer.Content = stackPanel;

            var button1 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5), LocalMatrix = Matrix.Scaling(2, 2, 2) };
            var textOnly = new TextBlock { Text = "Text only button", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextColor = new Color(1f, 0, 0, 0.5f) };
            button1.Content = textOnly;

            var button2 = new Button { Name = "Button2", Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) };
            var imageContent = new ImageElement { Name = "Image Button2", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 50 };
            button2.Content = imageContent;

            var button3 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) };
            var stackContent = new StackPanel { Orientation = Orientation.Horizontal };
            var stackImage = new ImageElement { Name = "Image stack panel", Source = new Sprite(Asset.Load<Texture>("uv")), MaximumHeight = 50 };
            var stackText = new TextBlock { Text = "button text", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Margin = Thickness.UniformRectangle(5) };
            stackContent.Children.Add(stackImage);
            stackContent.Children.Add(stackText);
            button3.Content = stackContent;

            var button4 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Right, Padding = Thickness.UniformRectangle(5) };
            var imageContent2 = new ImageElement { Name = "button 4 uv image", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 40, Opacity = 0.5f };
            button4.Content = imageContent2;

            var button5 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(5) };
            var textOnly2 = new TextBlock { Text = "Left aligned", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") };
            button5.Content = textOnly2;

            var button6 = new ImageButton
            {
                Height = 50,
                Margin = Thickness.UniformRectangle(5),
                HorizontalAlignment = HorizontalAlignment.Center,
                PressedImage = new Sprite(Asset.Load<Texture>("ImageButtonPressed")),
                NotPressedImage = new Sprite(Asset.Load<Texture>("ImageButtonNotPressed")),
            };

            toggle = new ToggleButton
            {
                Content = new TextBlock { Text = "Toggle button test", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") },
                IsThreeState = true
            };

            scrollingText = new ScrollingText { Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Text = "<<<--- Scrolling text in a button ", IsEnabled = IsUpdateAutomatic };
            var button7 = new Button { Margin = Thickness.UniformRectangle(5), Content = scrollingText };

            var uniformGrid = new UniformGrid { Rows = 2, Columns = 2 };
            var gridText = new TextBlock { Text = "Uniform grid", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center};
            gridText.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            var buttonLeft = new Button { Content = new TextBlock { Text = "unif-grid left", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } };
            buttonLeft.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            var buttonRight = new Button { Content = new TextBlock { Text = "unif-grid right", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } };
            buttonRight.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            buttonRight.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            uniformGrid.Children.Add(gridText);
            uniformGrid.Children.Add(buttonLeft);
            uniformGrid.Children.Add(buttonRight);

            stackPanel.Children.Add(button1);
            stackPanel.Children.Add(button2);
            stackPanel.Children.Add(button3);
            stackPanel.Children.Add(button4);
            stackPanel.Children.Add(button5);
            stackPanel.Children.Add(button6);
            stackPanel.Children.Add(toggle);
            stackPanel.Children.Add(button7);
            stackPanel.Children.Add(uniformGrid);

            canvas.Children.Add(imgElt);
            canvas.Children.Add(scrollViewer);

            UIComponent.RootElement = canvas;
        }
Exemple #17
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var random = new Random(0);

            var Sprites = Asset.Load<SpriteSheet>("UIImages");
            var img1 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")) };
            var img2 = new ImageElement { Source = Sprites["GameScreenLeft"] };
            var img3 = new ImageElement { Source = Sprites["GameScreenRight"] };

            stackPanel1 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            stackPanel1.Children.Add(img1);
            stackPanel1.Children.Add(img2);
            stackPanel1.Children.Add(img3);

            stackPanel2 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            for (var i = 0; i < 1000; i++)
                stackPanel2.Children.Add(new Button { Name = "" + i, Height = 75, Content = new TextBlock { Text = "button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } });

            stackPanel3 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true, VerticalAlignment = VerticalAlignment.Center };
            for (var i = 0; i < 103; i++)
                stackPanel3.Children.Add(new Button { Name = "" + i, Height = 50 + 500 * random.NextFloat(), Content = new TextBlock { Text = "random button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } });

            stackPanel4 = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            for (var i = 0; i < 5; i++)
                stackPanel4.Children.Add(new Button { Name = "" + i, Height = i * 30, Content = new TextBlock { Text = "random button number " + i, Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") } });

            currentStackPanel = stackPanel1;

            scrollViewer = new ScrollViewer { Name = "sv", Content = currentStackPanel, ScrollMode = ScrollingMode.Vertical };

            UIComponent.RootElement = scrollViewer;
        }
        protected override void LoadScene()
        {
            mainScreneImages = LoadAsset<SpriteSheet>("MainSceneImages");
            westernFont = LoadAsset<SpriteFont>("WesternFont");
            popupWindowImage = mainScreneImages["popup_window"];

            // Preload stars
            starSprites.Add(mainScreneImages["star0"]);
            starSprites.Add(mainScreneImages["star1"]);
            starSprites.Add(mainScreneImages["star2"]);
            starSprites.Add(mainScreneImages["star3"]);
            borderStarImages.Add(mainScreneImages["bstar0"]);
            borderStarImages.Add(mainScreneImages["bstar1"]);
            borderStarImages.Add(mainScreneImages["bstar2"]);
            borderStarImages.Add(mainScreneImages["bstar3"]);

            // Create space ships
            var random = new Random();
            for (var i = 0; i < ShipNameList.Count; i++)
            {
                shipList.Add(new SpaceShip
                {
                    Name = ShipNameList[i],
                    Power = random.Next(4),
                    Control = random.Next(4),
                    Speed = random.Next(4),
                    IsLocked = (i % 3) == 2,
                });
            }

            var mainStackPanel = CreateMainScene();
            CreateWelcomePopup();
            CreateShipSelectionPopup();

            // Create the background
            var background = new ImageElement { Source = mainScreneImages["background_uiimage"], StretchType = StretchType.Fill };
            background.SetPanelZIndex(-1);

            // Overlay pop-ups and the main screen
            var overlay = new UniformGrid();
            overlay.Children.Add(background);
            overlay.Children.Add(mainStackPanel);
            overlay.Children.Add(welcomePopup);
            overlay.Children.Add(shipSelectPopup);

            // Set the root element to the overall overlay
            var uiComponent = Entity.Get<UIComponent>();
            uiComponent.RootElement = overlay;

            Script.AddTask(FillLifeBar);
        }
        private UniformGrid CreateShipButtonElement(SpaceShip spaceShip)
        {
            // Put the stat text block in a vertical uniform grid
            var statusTextGrid = new UniformGrid { Rows = 3, Margin = new Thickness(5f, -6f, 0, 0)};
            statusTextGrid.Children.Add(CreateShipStatusTextBlock("Power", 0));
            statusTextGrid.Children.Add(CreateShipStatusTextBlock("Control", 1));
            statusTextGrid.Children.Add(CreateShipStatusTextBlock("Speed", 2));

            // Put the stat stars in a vertical uniform grid
            spaceShip.PowerImageElement = CreateShipStatusStar(0);
            spaceShip.ControlImageElement = CreateShipStatusStar(1);
            spaceShip.SpeedImageElement = CreateShipStatusStar(2);

            var starGrid = new UniformGrid { Rows = 3 };
            starGrid.Children.Add(spaceShip.PowerImageElement);
            starGrid.Children.Add(spaceShip.ControlImageElement);
            starGrid.Children.Add(spaceShip.SpeedImageElement);
            starGrid.SetGridColumn(2);

            // Ship image
            var shipSprite = mainScreneImages[spaceShip.Name];
            var shipImageElement = new ImageElement { Source = shipSprite };
            shipImageElement.SetGridColumn(4);

            // Create the horizontal grid with two blank stretchable columns and add the text blocks, the starts and the ship image
            var shipContent = new Grid();
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Star));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Star));
            shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            shipContent.RowDefinitions.Add(new StripDefinition());
            shipContent.LayerDefinitions.Add(new StripDefinition());

            shipContent.Children.Add(statusTextGrid);
            shipContent.Children.Add(starGrid);
            shipContent.Children.Add(shipImageElement);

            //
            var shipSelectFrameSprite = mainScreneImages["weapon_select_frame"];

            var shipButton = new Button
            {
                Name = spaceShip.Name,
                Content = shipContent,
                PressedImage = shipSelectFrameSprite,
                NotPressedImage = shipSelectFrameSprite,
                MouseOverImage = shipSelectFrameSprite,
                Padding = new Thickness(60, 20, 20, 20)
            };

            shipButton.Click += delegate
            {
                currentShipImage.Source = shipSprite;

                activeShipIndex = shipList.FindIndex(w => w.Name == spaceShip.Name);

                PowerStatus = spaceShip.Power;
                ControlStatus = spaceShip.Control;
                SpeedStatus = spaceShip.Speed;

                CloseShipSelectPopup();
            };

            shipButton.IsEnabled = !spaceShip.IsLocked;
            shipButton.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f));

            var buttonGrid = new UniformGrid { MaximumHeight = 100 };
            buttonGrid.Children.Add(shipButton);

            if (spaceShip.IsLocked)
            {
                var lockIconImage = mainScreneImages["lock_icon"];
                var lockIconElement = new ImageElement { Source = lockIconImage, StretchType = StretchType.Fill, };
                lockIconElement.SetPanelZIndex(1);
                buttonGrid.Children.Add(lockIconElement);
            }

            return buttonGrid;
        }
        private ImageElement CreateShipStatusStar(int elementIndex)
        {
            var starImage = new ImageElement { VerticalAlignment = VerticalAlignment.Center };
            starImage.SetGridRow(elementIndex);

            return starImage;
        }
        public void TestArrangeOverride()
        {
            var rand = new Random();
            var imageSize = new Vector3(100, 50, 0);
            var uiImage = new UIImage { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = uiImage };

            // 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);
        }
Exemple #22
0
        private void CreateMainMenuUI()
        {
            var paradoxLogo = new ImageElement { Source = uiImages["pdx_logo"] };

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

            StartButton = new Button
            {
                Content = new TextBlock { Font = spriteFont, Text = "Touch to Start", TextColor = Color.Black,
                    HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center},
                NotPressedImage = buttonImage,
                PressedImage = buttonImage,
                MouseOverImage = buttonImage,
                Padding = new Thickness(80, 27, 25, 35),
                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(paradoxLogo);
            mainMenuCanvas.Children.Add(StartButton);

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

            const float relativeSize = 1 / 6f;

            var canvas = new Canvas();
            canvas.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            // left/top
            var image1 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image1.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image1.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 0, 0));
            image1.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0, 0));
            canvas.Children.Add(image1);

            // right/top
            var image2 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image2.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image2.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 0, 0));
            image2.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 0, 0));
            canvas.Children.Add(image2);

            // left/bottom
            var image3 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image3.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image3.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 1, 0));
            image3.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 1, 0));
            canvas.Children.Add(image3);

            // 1/3 right/bottom
            var image4 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image4.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image4.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 1, 0));
            image4.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 1, 0));
            canvas.Children.Add(image4);

            // 1/3 left/top middle centered
            var image5 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image5.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image5.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 1/3f, 0));
            image5.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0));
            canvas.Children.Add(image5);

            // 1/3 right/top right aligned 
            var image6 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image6.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image6.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2 / 3f, 1 / 3f, 0));
            image6.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0.5f, 0));
            canvas.Children.Add(image6);

            // 1/3 left/bottom bottom aligned
            var image7 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image7.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image7.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 2/3f, 0));
            image7.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0, 0));
            canvas.Children.Add(image7);

            // 1/3 right/bottom top aligned
            var image8 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image8.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image8.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2/3f, 2/3f, 0));
            image8.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 1, 0));
            canvas.Children.Add(image8);
            
            var grid = new UniformGrid { Rows = 3, Columns = 3 };
            for (int c = 0; c < 3; c++)
                for (int r = 0; r < 3; r++)
                    CreateAndInsertButton(grid, c, r);

            var baseGrid = new UniformGrid();
            baseGrid.Children.Add(grid);
            baseGrid.Children.Add(canvas);

            UIComponent.RootElement = baseGrid;
        }
        private UIElement CreateMainScene()
        {
            // the top life bar
            var topBar = CreateMainScreneTopBar();

            // Create Name label
            nameTextBlock = new TextBlock
            {
                Font = westernFont,
                TextSize = 52,
                TextColor = Color.LightGreen,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(50, 0, 50, 0)
            };
            var nameLabel = new ContentDecorator
            {
                BackgroundImage = mainScreneImages["tex_edit_inactivated_background"],
                Content = nameTextBlock,
                Padding = new Thickness(20, 15, 20, 20),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };
            nameLabel.SetGridRow(1);

            // Create Character image
            var characterImage = new ImageElement
            {
                Name = "HeroImage",
                Source = mainScreneImages["character"],
                HorizontalAlignment = HorizontalAlignment.Center,
            };
            characterImage.SetGridRow(2);

            // Create Explanation TextBlock
            var explanationLabel = new ContentDecorator
            {
                BackgroundImage = mainScreneImages["description_frame"],
                HorizontalAlignment = HorizontalAlignment.Center,
                Content = new TextBlock
                {
                    Font = LoadAsset<SpriteFont>("JapaneseFont"),
                    TextSize = 34,
                    TextColor = Color.White,
                    Text = "Pictogram-based alphabets are easily supported.\n日本語も簡単に入れることが出来ます。",
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    WrapText = true
                },
                Padding = new Thickness(50, 30, 50, 40),
            };
            explanationLabel.SetGridRow(3);

            // The ship status panel
            var shipStatusPanel = CreateMainSceneShipStatusPanel();
            shipStatusPanel.SetGridRow(4);

            // Create quit button (Last element)
            var quitButton = CreateTextButton("Quit Sample");
            quitButton.HorizontalAlignment = HorizontalAlignment.Center;
            quitButton.VerticalAlignment = VerticalAlignment.Center;
            quitButton.Click += delegate { UIGame.Exit(); };
            quitButton.SetGridRow(5);

            // Put region together in the main grid
            var mainLayout = new Grid();
            mainLayout.ColumnDefinitions.Add(new StripDefinition());
            mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 15));
            mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 10));
            mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 20));
            mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 20));
            mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 25));
            mainLayout.RowDefinitions.Add(new StripDefinition(StripType.Star, 10));
            mainLayout.LayerDefinitions.Add(new StripDefinition());

            // set minimal and maximal size of rows
            mainLayout.RowDefinitions[0].MaximumSize = topBar.MaximumHeight;
            mainLayout.RowDefinitions[1].MinimumSize = 100;
            mainLayout.RowDefinitions[3].MinimumSize = 120;
            mainLayout.RowDefinitions[5].MinimumSize = 90;

            mainLayout.Children.Add(topBar);
            mainLayout.Children.Add(nameLabel);
            mainLayout.Children.Add(characterImage);
            mainLayout.Children.Add(explanationLabel);
            mainLayout.Children.Add(shipStatusPanel);
            mainLayout.Children.Add(quitButton);


            return mainLayout;
        }
        private UIElement CreateMainSceneShipStatusPanel()
        {
            // Status star bars {Power, Life, Speed}
            var powerStatusDecorator = CreateMainSceneShipStatusStars("power", powerStatusStar, 0);
            var controlStatusDecorator = CreateMainSceneShipStatusStars("control", controlStatusStar, 1);
            var speedStatusDecorator = CreateMainSceneShipStatusStars("speed", speedStatusStar, 2);
            PowerStatus = shipList[activeShipIndex].Power;
            ControlStatus = shipList[activeShipIndex].Control;
            SpeedStatus = shipList[activeShipIndex].Speed;

            // Put the stats (Stars) in 3x1 uniform grid
            var statusPanel = new UniformGrid { Rows = 3 };
            statusPanel.Children.Add(powerStatusDecorator);
            statusPanel.Children.Add(controlStatusDecorator);
            statusPanel.Children.Add(speedStatusDecorator);
            statusPanel.SetGridColumn(1);

            // SpaceShip Button
            currentShipImage = new ImageElement { Source = mainScreneImages[shipList[activeShipIndex].Name], };
            currentShipImage.SetGridRow(1);

            var shipImageSpacerGrid = new Grid { HorizontalAlignment = HorizontalAlignment.Center };
            shipImageSpacerGrid.Children.Add(currentShipImage);
            shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2));
            shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 6));
            shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2));
            shipImageSpacerGrid.ColumnDefinitions.Add(new StripDefinition());
            shipImageSpacerGrid.LayerDefinitions.Add(new StripDefinition());

            var shipButtonDesign = mainScreneImages["display_element"];
            var currentShipButton = new Button
            {
                NotPressedImage = shipButtonDesign,
                PressedImage = shipButtonDesign,
                MouseOverImage = shipButtonDesign,
                Content = shipImageSpacerGrid,
                Padding = new Thickness(45, 20, 10, 25),
                VerticalAlignment = VerticalAlignment.Center
            };
            currentShipButton.Click += delegate
            {
                // Once click, update the SpaceShip status pop-up and show it.
                UpdateShipStatus();
                ShowShipSelectionPopup();
            };
            currentShipButton.SetGridColumn(3);

            // Status upgrade buttons
            var powerUpgradeButton = CreateIncreaseStatusButton("P", 0, 0, 2, 0, () => PowerStatus, () => PowerStatus++);
            var controlUpgradeButton = CreateIncreaseStatusButton("C", 0, 1, 2, 0, () => ControlStatus, () => ControlStatus++);
            var speedUpgradeButton = CreateIncreaseStatusButton("S", 1, 0, 2, 0, () => SpeedStatus, () => SpeedStatus++);
            var lifeUpgradeButton = CreateIncreaseStatusButton("L", 1, 1, 1, 1, () => 0, () => LifeStatus++);

            // Arrange the status up buttons in a 2x2 Uniform grid.
            var statusUpgradeGridPanel = new UniformGrid
            {
                Rows = 2,
                Columns = 2,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            statusUpgradeGridPanel.Children.Add(powerUpgradeButton);
            statusUpgradeGridPanel.Children.Add(controlUpgradeButton);
            statusUpgradeGridPanel.Children.Add(speedUpgradeButton);
            statusUpgradeGridPanel.Children.Add(lifeUpgradeButton);
            statusUpgradeGridPanel.SetGridColumn(5);

            // Put together bottom region in horizontal Stack panel, arranging it from left to right
            var mainPanel = new Grid();
            mainPanel.RowDefinitions.Add(new StripDefinition());
            mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // space
            mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 4));
            mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 25)); // space
            mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 4));
            mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 25)); // space
            mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 3));
            mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // space
            mainPanel.LayerDefinitions.Add(new StripDefinition());

            mainPanel.Children.Add(statusPanel);
            mainPanel.Children.Add(currentShipButton);
            mainPanel.Children.Add(statusUpgradeGridPanel);

            return mainPanel;
        }
        public void TestMeasureOverrideInfiniteValues(StretchType stretch)
        {
            var imageSize = new Vector3(100, 50, 0);
            var uiImage = new UIImage { Region = new Rectangle(0, 0, (int)imageSize.X, (int)imageSize.Y), Borders = new Vector4(1, 2, 3, 4) };
            var image = new ImageElement { Source = uiImage, 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);
        }