protected override async Task LoadContent()
        {
            await base.LoadContent();


            textScroller = new ScrollingText
            {
                Name = "Text Scroller", 
                DesiredCharacterNumber = 25, 
                Text = InitialText,
                TextColor = Color.Black,
                Font = Content.Load<SpriteFont>("CourierNew12"), 
                IsEnabled = IsAutomatic,
                SynchronousCharacterGeneration = true
            };
            
            decorator = new ContentDecorator
            {
                Name = "ContentDecorator", 
                Content = textScroller, 
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                BackgroundImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("DumbWhite"))
            };

            UIComponent.Page = new Engine.UIPage { RootElement = decorator };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            UIComponent.Resolution = new Vector3(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height, 500);
            
            textBlock = new TextBlock
            {
                WrapText = true,
                TextSize = 15,
                TextColor = Color.Black,
                Font = Content.Load<SpriteFont>("HanSans13"),
                Text = @"This is a very long sentence that will hopefully be wrapped up. 
Does it work with kanjis too? let's see that in the following line. Here we goes.
漢字も大丈夫そうですね!良かった!でも、文章の切る所は本当に合ってますか?どうかな。。
やった!",
                SynchronousCharacterGeneration = true,
            };
            var decorator = new ContentDecorator
            {
                Width = 200,
                Content = textBlock, 
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                BackgroundImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("DumbWhite"))
            };

            UIComponent.Page = new Engine.UIPage { RootElement = decorator };
        }
        protected  Entity GetUIEntity(SpriteFont font, bool fixedSize, Vector3 position)
        {
            // Create and initialize "Touch Screen to Start"
            var touchStartLabel = new ContentDecorator
            {
                Content = new TextBlock
                {
                    Font = font,
                    TextSize = 32,
                    Text = (fixedSize) ? "Fixed Size UI" : "Regular UI",
                    TextColor = Color.White
                },
                Padding = new Thickness(30, 20, 30, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            //touchStartLabel.SetPanelZIndex(1);

            var grid = new Grid
            {
                BackgroundColor = (fixedSize) ? new Color(255, 0, 255) : new Color(255, 255, 0),
                MaximumWidth = 100,
                MaximumHeight = 100,
                MinimumWidth = 100,
                MinimumHeight = 100,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(touchStartLabel);

            // Add the background
            var background = new ImageElement { StretchType = StretchType.Fill };
            background.SetPanelZIndex(-1);

            var uiEntity = new Entity();

            // Create a procedural model with a diffuse material
            var uiComponent = new UIComponent
            {
                Page = new UIPage
                {
                    RootElement = new UniformGrid { Children = { background, grid } }
                },
                //IsBillboard = true,
                IsFixedSize = fixedSize,
                IsFullScreen = false,
                Resolution = new Vector3(100, 100, 100), // Same size as the inner grid
                Size = new Vector3(0.1f), // 10% of the vertical resolution
            };
            uiEntity.Add(uiComponent);

            uiEntity.Transform.Position = position;

            return uiEntity;
        }
示例#4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var uiGroup = Content.Load<SpriteSheet>("UIImages");

            element4 = new ContentDecorator
            {
                Name = "4",
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Width = 200, Height = 100,
                LocalMatrix = Matrix.Translation(-50, -50, 0),
                BackgroundImage = SpriteFromSheet.Create(uiGroup, "uvNotRotated")
            };

            element3 = new ContentDecorator
            {
                Name = "3",
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Width = 300, Height = 150,
                Content = element4,
                LocalMatrix = Matrix.Translation(-200, -100, 0),
                BackgroundImage = SpriteFromSheet.Create(uiGroup, "uvRotated90")
            };
            
            element2 = new ContentDecorator
            {
                Name = "2",
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Width = 600, Height = 300,
                Content = element3,
                BackgroundImage = SpriteFromSheet.Create(uiGroup, "BorderButton")
            };
            element2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(400, 200, 0));
            element2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            element1 = new ContentDecorator
            {
                Name = "1",
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Width = 600, Height = 300,
                BackgroundImage = SpriteFromSheet.Create(uiGroup, "GameScreen")
            };

            var canvas = new Canvas();
            canvas.Children.Add(element1);
            canvas.Children.Add(element2);

            UIComponent.Page = new Engine.UIPage { RootElement = canvas };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();
            
            textBlock = new TextBlock
            {
                TextColor = Color.Black,
                Font = Asset.Load<SpriteFont>("MSMincho10"),
                Text = @"Simple sample text surrounded by decorator.",
                SynchronousCharacterGeneration = true
            };

            var decorator = new ContentDecorator
            {
                Content = textBlock, 
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                BackgroundImage = new Sprite(Asset.Load<Texture>("DumbWhite"))
            };

            UIComponent.RootElement = decorator;
        }
示例#6
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

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

            element4 = new ContentDecorator
            {
                Name = "4", 
                Width = 200, 
                Height = 100, 
                LocalMatrix = Matrix.Translation(-50, -50, 0),
                BackgroundImage = uiGroup["uvNotRotated"],
            };

            element3 = new ContentDecorator
            {
                Name = "3", 
                Width = 300,
                Height = 150,
                Content = element4,
                LocalMatrix = Matrix.Translation(-200, -100, 0),
                BackgroundImage = uiGroup["uvRotated90"],
            };

            var borderImage = uiGroup["BorderButton"];
            element2 = new ContentDecorator { Name = "2", Width = 600, Height = 300, Content = element3, BackgroundImage = borderImage };
            element2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(400, 200, 0));
            element2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            element1 = new ContentDecorator { Name = "1", Width = 600, Height = 300, BackgroundImage = uiGroup["GameScreen"] };

            var canvas = new Canvas();
            canvas.Children.Add(element1);
            canvas.Children.Add(element2);

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

            var sprites = Content.Load<SpriteSheet>("UIImages");

            var img1 = new ImageElement { Name = "UV 1 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img2 = new ImageElement { Name = "UV 2 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            img3 = new ImageElement { Name = "UV 3 stack panel", Source = (SpriteFromTexture)new Sprite(Content.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 = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img5 = new ImageElement { Name = "UV grid 2", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img6 = new ImageElement { Name = "Game screen grid", Source = SpriteFromSheet.Create(sprites, "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.Page = new Engine.UIPage { RootElement = contentDecorator };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            textBlock = new TextBlock
                {
                    Font = Content.Load<SpriteFont>("HanSans13"), 
                    Text = "Simple Text - 簡単な文章。", 
                    TextColor = Color.Black,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    SynchronousCharacterGeneration = true
                };

            decorator = new ContentDecorator
            {
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                BackgroundImage = (SpriteFromTexture)new Sprite(Content.Load<Texture>("DumbWhite")),
                Content = textBlock
            };

            UIComponent.Page = new Engine.UIPage { RootElement = decorator };
        }
示例#9
0
        public void TestScrolling()
        {
            const float elementWidth = 100;
            const float elementHeight = 200;
            const float elementDepth = 300;

            var rand = new Random();
            var scrollViewer = new ScrollViewer { ScrollMode = ScrollingMode.HorizontalVertical, Width = elementWidth, Height = elementHeight, Depth = elementDepth };
            scrollViewer.Measure(Vector3.Zero);
            scrollViewer.Arrange(Vector3.Zero, false);

            // tests that no crashes happen with no content
            scrollViewer.ScrollTo(rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollOf(rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);

            // tests with an arranged element
            const float contentWidth = 1000;
            const float contentHeight = 2000;
            const float contentDepth = 3000;
            var content = new ContentDecorator { Width = contentWidth, Height = contentHeight, Depth = contentDepth };
            scrollViewer.Content = content;
            scrollViewer.Measure(Vector3.Zero);
            scrollViewer.Arrange(Vector3.Zero, false);

            var scrollValue = new Vector3(123, 456, 789);
            scrollViewer.ScrollTo(scrollValue);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.Vertical);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            Assert.AreEqual(new Vector3(0, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollOf(scrollValue);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            // tests with an not arranged element
            content.InvalidateArrange();
            scrollViewer.ScrollTo(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            content.InvalidateArrange();
            scrollViewer.ScrollOf(2*scrollValue);
            scrollViewer.ScrollTo(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            scrollViewer.ScrollToEnd(Orientation.Vertical);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            content.InvalidateArrange();
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(2*scrollValue.X, 2*scrollValue.Y, 0), scrollViewer.ScrollPosition);
        }
示例#10
0
文件: UIScript.cs 项目: cg123/xenko
        private void CreateGameUI()
        {
            scoreTextBlock = new TextBlock
            {
                Font = Font, TextColor = Color.Black, VerticalAlignment = VerticalAlignment.Center
            };
            scoreTextBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 1f));
            scoreTextBlock.SetCanvasRelativePosition(new Vector3(0.2f, 0.05f, 0f));

            var scoreBoard = new ContentDecorator
            {
                BackgroundImage = SpriteFromSheet.Create(UIImages, "score_bg"),
                Content = scoreTextBlock,
                Padding = new Thickness(60, 31, 25, 35),
                MinimumWidth = 190f // Set the minimum width of score button so that it wont modify when the content (text) changes, and less than minimum.
            };

            gameRoot = new Canvas();
            gameRoot.Children.Add(scoreBoard);
        }
示例#11
0
        protected override void LoadScene()
        {
            // Allow user to resize the window with the mouse.
            Game.Window.AllowUserResizing = true;

            // Create and initialize "Xenko Samples" Text
            var xenkoSampleTextBlock = new ContentDecorator
            {
                BackgroundImage = SpriteFromSheet.Create(SplashScreenImages, "xenko_sample_text_bg"),
                Content = new TextBlock
                {
                    Font = WesternFont,
                    TextSize = 60,
                    Text = "Xenko UI Particles",
                    TextColor = Color.White,
                },
                Padding = new Thickness(35, 15, 35, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            xenkoSampleTextBlock.SetPanelZIndex(1);
            

            //*********************************
            // Confetti button
            var buttonImage = SpriteFromSheet.Create(SplashScreenImages, "button_long");

            var xenkoButtonConfetti = new Button
            {
                NotPressedImage = buttonImage,
                PressedImage = buttonImage,
                MouseOverImage = buttonImage,

                Content = new TextBlock
                {
                    Font = WesternFont,
                    TextColor = Color.White,
                    Text = "Click here to start the game over",
                    TextSize = 24
                },

                HorizontalAlignment = HorizontalAlignment.Right,
                Padding = new Thickness(90, 22, 25, 35),
//                BackgroundColor = Color.DarkOrchid
            };

            xenkoButtonConfetti.SetPanelZIndex(1);
            xenkoButtonConfetti.SetGridRow(1);

            xenkoButtonConfetti.Click += delegate
            {
                fusePercentage = 1f;
                desiredState = GameState.NewGame;
                var effectOffset = new Vector3(45 - xenkoButtonConfetti.RenderSize.X / 2, -5, 0);
                SpawnParticles(xenkoButtonConfetti.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f);
            };
            //*********************************

            //*********************************
            // Stars button
            var buttonStars = SpriteFromSheet.Create(SplashScreenImages, "button_short");

            var xenkoButtonStars = new Button
            {
                NotPressedImage = buttonStars,
                PressedImage = buttonStars,
                MouseOverImage = buttonStars,

                Content = new TextBlock
                {
                    Font = WesternFont,
                    TextColor = Color.White,
                    Text = "Congratulations",
                    TextSize = 24
                },

                HorizontalAlignment = HorizontalAlignment.Right,
                Padding = new Thickness(90, 22, 25, 35),
//                BackgroundColor = Color.DarkOrchid

            };

            xenkoButtonStars.SetPanelZIndex(1);
            xenkoButtonStars.SetGridRow(4);

            xenkoButtonStars.Click += delegate
            {
                desiredState = GameState.EndGame;
                var effectOffset = new Vector3(45 - xenkoButtonStars.RenderSize.X / 2, -5, 0);
                SpawnParticles(xenkoButtonStars.WorldMatrix.TranslationVector + effectOffset, Prefab, 2f);
            };
            //*********************************

            var bottomBar = CreateBottomBar();
            bottomBar.SetPanelZIndex(1);
            bottomBar.SetGridRow(6);

            var grid = new Grid
            {
                MaximumWidth = virtualWidth,
                MaximumHeight = virtualHeight,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 0
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 1
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 2
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 3
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); // 4
            grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 100)); // 5
            grid.RowDefinitions.Add(new StripDefinition(StripType.Fixed, 50)); // 5
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(xenkoSampleTextBlock);
            grid.Children.Add(xenkoButtonConfetti);
            grid.Children.Add(xenkoButtonStars);
            grid.Children.Add(bottomBar);

            // Add the background
            var background = new ImageElement { Source = SpriteFromSheet.Create(SplashScreenImages, "background_uiimage"), StretchType = StretchType.Fill };
            background.SetPanelZIndex(-1);

            Entity.Get<UIComponent>().Page = new UIPage { RootElement = new UniformGrid { Children = { background, grid } } };
        }