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(); }
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 Vector4(40), }); // Add a text label. var textBlock = new TextBlock { Text = "Press button to open window: ", Margin = new Vector4(4) }; // Add buttons that open samples. var button0 = new Button { Content = new TextBlock { Text = "Sample #1: Controls" }, Margin = new Vector4(4), Padding = new Vector4(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 Vector4(4), Padding = new Vector4(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 Vector4(4), Padding = new Vector4(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 Vector4(4), Padding = new Vector4(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 Vector4(4), Padding = new Vector4(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 Vector4(4), Padding = new Vector4(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 Vector4(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(); }