private void CreateGui() { // Remove old screen. if (_uiScreen != null) UIService.Screens.Remove(_uiScreen); // Load a UI theme, which defines the appearance and default values of UI controls. string themeName; if (_themeNumber == 0) themeName = "UI Themes/BlendBlue/Theme"; else themeName = "UI Themes/Aero/Theme"; Theme theme = ContentManager.Load<Theme>(themeName); // Create a UI renderer, which uses the theme info to renderer UI controls. UIRenderer renderer = new UIRenderer(Game, theme); // Create a UIScreen and add it to the UI service. The screen is the root of the // tree of UI controls. Each screen can have its own renderer. _uiScreen = new UIScreen("SampleUIScreen", renderer); UIService.Screens.Add(_uiScreen); // Add a text block that displays the frame rate. _uiScreen.Children.Add(new FpsTextBlock { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, Margin = new Vector4F(40), }); // Add a text label. var textBlock = new TextBlock { Text = "Press button to open window: ", Margin = new Vector4F(4) }; // Add buttons that open samples. var button0 = new Button { Content = new TextBlock { Text = "Sample #1: Controls" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch, }; button0.Click += (s, e) => { var allControlsWindow = new AllControlsWindow(ContentManager, renderer); allControlsWindow.Show(_uiScreen); }; var button1 = new Button { Content = new TextBlock { Text = "Sample #2: ScrollViewer" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button1.Click += (s, e) => { var resizableWindow = new ResizableWindow(ContentManager); resizableWindow.Show(_uiScreen); }; var button2 = new Button { Content = new TextBlock { Text = "Sample #3: Transformations" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button2.Click += (s, e) => { var renderTransformWindow = new RenderTransformWindow(); renderTransformWindow.Show(_uiScreen); }; var button3 = new Button { Content = new TextBlock { Text = "Sample #4: Dialogs" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button3.Click += (s, e) => { var dialogDemoWindow = new DialogDemoWindow(); dialogDemoWindow.Show(_uiScreen); }; var button4 = new Button { Content = new TextBlock { Text = "Sample #5: Console" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button4.Click += (s, e) => { var consoleWindow = new ConsoleWindow(); consoleWindow.Show(_uiScreen); }; var button5 = new Button { Content = new TextBlock { Text = "Switch UI Theme" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button5.Click += (s, e) => { // Set a flag. In the next Update() we will load a new theme. // Note: We should not load the theme here because the UI is currently updated. _changeTheme = true; }; var stackPanel = new StackPanel { Margin = new Vector4F(40) }; stackPanel.Children.Add(textBlock); stackPanel.Children.Add(button0); stackPanel.Children.Add(button1); stackPanel.Children.Add(button2); stackPanel.Children.Add(button3); stackPanel.Children.Add(button4); stackPanel.Children.Add(button5); _uiScreen.Children.Add(stackPanel); // Optional: If we want to allow the user to use buttons in the screen with // keyboard or game pad, we have to make it a focus scope. Normally, only // windows are focus scopes. _uiScreen.IsFocusScope = true; _uiScreen.Focus(); }
public UIAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. _graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, _graphicsScreen); // Load a UI theme, which defines the appearance and default values of UI controls. Theme theme = ContentManager.Load<Theme>("UI Themes/BlendBlue/Theme"); // Create a UI renderer, which uses the theme info to renderer UI controls. UIRenderer renderer = new UIRenderer(Game, theme); // Create a UIScreen and add it to the UI service. The screen is the root of the // tree of UI controls. Each screen can have its own renderer. _uiScreen = new UIScreen("SampleUIScreen", renderer); UIService.Screens.Add(_uiScreen); // ----- Add buttons. Button button0 = new Button { Name = "Button0", Content = new TextBlock { Text = "Animate Buttons" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch, }; button0.Click += (s, e) => PlayStartAnimation(); Button button1 = new Button { Name = "Button1", Content = new TextBlock { Text = "Open FadingWindow" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button1.Click += (s, e) => new FadingWindow(Services).Show(_uiScreen); Button button2 = new Button { Name = "Button2", Content = new TextBlock { Text = "Open ScalingWindow" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button2.Click += (s, e) => new ScalingWindow(Services).Show(_uiScreen); Button button3 = new Button { Name = "Button3", Content = new TextBlock { Text = "Open RotatingWindow" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button3.Click += (s, e) => new RotatingWindow(Services).Show(_uiScreen); Button button4 = new Button { Name = "Button4", Content = new TextBlock { Text = "Open EasingWindow" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button4.Click += (s, e) => new EasingWindow(Services).Show(_uiScreen); Button button5 = new Button { Name = "Button5", Content = new TextBlock { Text = "Close All Windows" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button5.Click += (s, e) => CloseWindows(); Button button6 = new Button { Name = "Button6", Content = new TextBlock { Text = "Exit" }, Margin = new Vector4F(4), Padding = new Vector4F(6), HorizontalAlignment = HorizontalAlignment.Stretch }; button6.Click += (s, e) => Exit(); _buttonStackPanel = new StackPanel { Margin = new Vector4F(40) }; _buttonStackPanel.Children.Add(button0); _buttonStackPanel.Children.Add(button1); _buttonStackPanel.Children.Add(button2); _buttonStackPanel.Children.Add(button3); _buttonStackPanel.Children.Add(button4); _buttonStackPanel.Children.Add(button5); _buttonStackPanel.Children.Add(button6); _uiScreen.Children.Add(_buttonStackPanel); // Optional: If we want to allow the user to use buttons in the screen with // keyboard or game pad, we have to make it a focus scope. Normally, only // windows are focus scopes. _uiScreen.IsFocusScope = true; _uiScreen.Focus(); PlayStartAnimation(); }