Ejemplo n.º 1
0
    public NormalUIScreen(IUIRenderer renderer)
      : base("Normal", renderer)
    {
      Image = new Image
      {
        Width = 800,
        Height = 450,
      };

      _window = new Window
      {
        X = 100,
        Y = 50,
        Title = "3D Scene (Click scene to control camera. Press <Esc> to leave scene.)",
        CanResize = true,
        CloseButtonStyle = null,     // Hide close button.
        Content = new ScrollViewer
        {
          HorizontalAlignment = HorizontalAlignment.Stretch,
          VerticalAlignment = VerticalAlignment.Stretch,
          Content = Image
        },
      };
      _window.Show(this);
    }
Ejemplo n.º 2
0
    private void OpenDialogFromCode(object sender, EventArgs eventArgs)
    {
      // ----- Create dialog.
      var text = new TextBlock
      {
        Text = "This layout was defined in code.",
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Center,
      };

      var button = new Button
      {
        Content = new TextBlock { Text = "Ok" },
        IsCancel = true,       // Cancel buttons are clicked when the user presses ESC (or BACK or B on the gamepad).
        IsDefault = true,      // Default buttons are clicked when the user presses ENTER or SPACE (or START or A on the gamepad).
        Margin = new Vector4F(4),
        Width = 60,
        HorizontalAlignment = HorizontalAlignment.Center,
      };

      var stackPanel = new StackPanel { Margin = new Vector4F(4) };
      stackPanel.Children.Add(text);
      stackPanel.Children.Add(button);

      var window = new Window
      {
        CanResize = false,
        IsModal = true,             // Modal dialogs consume all input until the window is closed.
        Content = stackPanel,
        MinHeight = 0,
        Title = "A modal dialog from code",
      };

      button.Click += (s, e) => window.Close();

      // ----- Show the window in the center of the screen.
      // First, we need to open the window. 
      window.Show(this);

      // The window is now part of the visual tree of controls and can be measured. (The 
      // window does not have a fixed size. Window.Width and Window.Height are NaN. The 
      // size is calculated automatically depending on its content.)
      window.Measure(new Vector2F(float.PositiveInfinity));

      // Measure computes DesiredWidth and DesiredHeight. With this info we can center the 
      // window on the screen.
      window.X = Screen.ActualWidth / 2 - window.DesiredWidth / 2;
      window.Y = Screen.ActualHeight / 2 - window.DesiredHeight / 2;
    }
Ejemplo n.º 3
0
    public TilingSample(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.
      var 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/TilingSample/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);

      // Create a window using the default style "Window".
      var stretchedWindow = new Window
      {
        X = 100,
        Y = 100,
        Width = 480,
        Height = 320,
        CanResize = true,
      };
      _uiScreen.Children.Add(stretchedWindow);

      // Create a window using the style "TiledWindow".
      var tiledWindow = new Window
      {
        X = 200,
        Y = 200,
        Width = 480,
        Height = 320,
        CanResize = true,
        Style = "TiledWindow",
      };
      _uiScreen.Children.Add(tiledWindow);

      // Check file TilingSampleContent/Theme.xml to see how the styles are defined.
    }
Ejemplo n.º 4
0
    private void CreateHelpWindow()
    {
      if (_helpWindow != null)
        return;

      // Window
      //   ScrollViewer
      //     TextBlock

      _helpTextBlock = new TextBlock(); // Text is set in UpdateHelpText().

      var scrollViewer = new ScrollViewer
      {
        Content = _helpTextBlock,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
      };

      _helpWindow = new Window
      {
        Name = "HelpWindow",
        Title = "HELP",
        Content = scrollViewer,
        X = 50,
        Y = 50,
        Width = 640,
        Height = 480,
        CanResize = true,
        HideOnClose = true,
        IsVisible = false,
      };
      _helpWindow.Closed += OnWindowClosed;
    }
Ejemplo n.º 5
0
    private void CreateOptionsWindow()
    {
      if (_optionsWindow != null)
        return;

      // Add the Options window (v-sync, fixed/variable timing, parallel game loop).

      // Window
      //   TabControl

      _optionsWindow = new Window
      {
        Name = "OptionsWindow",
        Title = "Options",
        X = 50,
        Y = 50,
        Width = 400,
        MaxHeight = 640,
        HideOnClose = true,
        IsVisible = false,
      };
      _optionsWindow.Closed += OnWindowClosed;

      _optionsTabControl = new TabControl
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        Margin = new Vector4F(SampleHelper.Margin),
      };
      _optionsWindow.Content = _optionsTabControl;

      var panel = SampleHelper.AddTabItem(_optionsTabControl, "General");
      var graphicsDeviceManager = _services.GetInstance<GraphicsDeviceManager>();
      SampleHelper.AddCheckBox(
        panel,
        "Use fixed frame rate",
        _game.IsFixedTimeStep,
        value => _game.IsFixedTimeStep = value);

      SampleHelper.AddCheckBox(
        panel,
        "Enable V-Sync",
        graphicsDeviceManager.SynchronizeWithVerticalRetrace,
        value =>
        {
          graphicsDeviceManager.SynchronizeWithVerticalRetrace = value;
          graphicsDeviceManager.ApplyChanges();
        });

      SampleHelper.AddCheckBox(
        panel,
        "Enable parallel game loop",
        _game.EnableParallelGameLoop,
        value => _game.EnableParallelGameLoop = value);

      SampleHelper.AddButton(
        panel,
        "GC.Collect()",
        GC.Collect,
        "Force an immediate garbage collection.");
    }
Ejemplo n.º 6
0
    private void CreateProfilerWindow()
    {
      if (_profilerWindow != null)
        return;

      // Window
      //   ScrollViewer
      //     TextView

      _profilerTextBlock = new TextBlock
      {
        // Text is set in UpdateHelpText().
        Font = "Console",
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };

      var scrollViewer = new ScrollViewer
      {
        Content = _profilerTextBlock,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };

      _profilerWindow = new Window
      {
        Name = "ProfilerWindow",
        Title = "Profile",
        Content = scrollViewer,
        X = 50,
        Y = 50,
        Width = 640,
        Height = 480,
        CanResize = true,
        HideOnClose = true,
        IsVisible = false,
      };
      _profilerWindow.Closed += OnWindowClosed;
    }
Ejemplo n.º 7
0
    private void CreateMenuWindow()
    {
      if (_menuWindow != null)
        return;

      // Window
      //   StackPanel (vertical)
      //     StackPanel (horizontal)
      //       Buttons
      //     TextBlock 
      //     TabControl
      //       TabItem                      * per category
      //         ScrollViewer
      //           StackPanel (vertical)
      //             StackPanel (vertical)  * per sample
      //               Button
      //               TextBlock

      _menuWindow = new Window
      {
        Name = "MenuWindow",
        Title = "Sample Browser",
        X = 50,
        Y = 50,
        IsVisible = false,
        HideOnClose = true
      };
      _menuWindow.Closed += OnWindowClosed;

      var panel = new StackPanel
      {
        Margin = new Vector4F(10),
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch
      };
      _menuWindow.Content = panel;

      var buttonsPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal
      };
      panel.Children.Add(buttonsPanel);

      AddButton(buttonsPanel, "Resume (Esc)", CloseWindows);
      AddButton(buttonsPanel, "Help (F1)", ShowHelpWindow);
      AddButton(buttonsPanel, "Profile (F3)", ShowProfilerWindow);
      AddButton(buttonsPanel, "Options (F4)", ShowOptionsWindow);
#if !NETFX_CORE && !IOS
      AddButton(buttonsPanel, "Exit (Alt-F4)", _game.Exit);
#endif

      var label = new TextBlock
      {
        Text = "Select Sample:",
        Margin = new Vector4F(2, 10, 0, 0)
      };
      panel.Children.Add(label);

      var tabControl = new TabControl
      {
        Margin = new Vector4F(0, 3, 0, 0),
        Width = 580,
#if WINDOWS_PHONE || ANDROID || IOS
        Height = 300
#else
        Height = 400
#endif
      };
      panel.Children.Add(tabControl);

      // Each tab shows a sample category (Base, Mathematics, Geometry, ...).
      var samplesByCategory = _samples.GroupBy(t => SampleAttribute.GetSampleAttribute(t).Category);
      int category = -1;
      foreach (var grouping in samplesByCategory)
      {
        category++;

        var tabItem = new TabItem
        {
          Content = new TextBlock { Text = grouping.Key.ToString() },
        };
        tabControl.Items.Add(tabItem);

        var scrollViewer = new ScrollViewer
        {
          HorizontalAlignment = HorizontalAlignment.Stretch,
          VerticalAlignment = VerticalAlignment.Stretch,
          HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
        };
        tabItem.TabPage = scrollViewer;

        var itemsPanel = new StackPanel
        {
          Orientation = Orientation.Vertical,
          Margin = new Vector4F(5),
          HorizontalAlignment = HorizontalAlignment.Stretch,
          VerticalAlignment = VerticalAlignment.Stretch
        };
        scrollViewer.Content = itemsPanel;

        foreach (Type sample in grouping)
        {
          var item = new StackPanel
          {
            Orientation = Orientation.Vertical
          };
          itemsPanel.Children.Add(item);

          string title = sample.Name;
          var button = new Button
          {
            Content = new TextBlock { Text = title },
            Width = 200,
#if WINDOWS_PHONE || ANDROID || IOS
            Padding = new Vector4F(10),
#else
            Padding = new Vector4F(0, 5, 0, 5),
#endif
          };
          int sampleIndex = _samples.IndexOf(sample);
          button.Click += (s, e) =>
                          {
                            _nextSampleIndex = sampleIndex;
                            CloseWindows();
                          };
          item.Children.Add(button);

          string summary = SampleAttribute.GetSampleAttribute(sample).Summary;
          summary = summary.Replace("\r\n", " ");
          var summaryTextBlock = new TextBlock
          {
            Margin = new Vector4F(0, 3, 0, 12),
            Text = summary,
            WrapText = true
          };
          item.Children.Add(summaryTextBlock);
        }
      }
    }
Ejemplo n.º 8
0
        private void AddWindowComponents()
        {
            var menuWindow = new Window
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            _screen.Children.Add(menuWindow);

            var stackPanel = new StackPanel
            {
                Orientation = Orientation.Vertical,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Vector4F(150, 0, 0, 0),
            };
            menuWindow.Content = stackPanel;

            var startButton = new Button
            {
                Name = "StartButton",
                Content = new TextBlock { Text = "Start" },
                FocusWhenMouseOver = true,
            };
            startButton.Click += OnStartButtonClicked;

            stackPanel.Children.Add(startButton);

            startButton.Focus();

            _game.ResetElapsedTime();
        }
Ejemplo n.º 9
0
    /// <summary>
    /// Called when "SubMenu" state is exited.
    /// </summary>
    private void OnExitSubMenuScreen(object sender, StateEventArgs eventArgs)
    {
      // Clean up.
      _subMenuExitAnimationController.Stop();
      _subMenuExitAnimationController.Recycle();
      _subMenuExitAnimationIsPlaying = false;

      _uiScreen.Children.Remove(_subMenuWindow);
      _subMenuWindow = null;
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Called when "SubMenu" state is entered.
    /// </summary>
    private void OnEnterSubMenuScreen(object sender, StateEventArgs eventArgs)
    {
      // Similar to OnEnterMenuScreen.
      _subMenuWindow = new Window
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };
      _uiScreen.Children.Add(_subMenuWindow);

      var stackPanel = new StackPanel
      {
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
        Margin = new Vector4F(150, 0, 0, 200)
      };
      _subMenuWindow.Content = stackPanel;

      var button1 = new Button
      {
        Name = "Item1Button",
        Content = new TextBlock { Text = "Item 1" },
        FocusWhenMouseOver = true,
      };
      var button2 = new Button
      {
        Name = "Item2Button",
        Content = new TextBlock { Text = "Item 2" },
        FocusWhenMouseOver = true,
      };
      var button3 = new Button
      {
        Name = "Item3Button",
        Content = new TextBlock { Text = "Item 3" },
        FocusWhenMouseOver = true,
      };
      var backButton = new Button
      {
        Name = "BackButton",
        Content = new TextBlock { Text = "Back" },
        FocusWhenMouseOver = true,
      };
      backButton.Click += OnBackButtonClicked;

      stackPanel.Children.Add(button1);
      stackPanel.Children.Add(button2);
      stackPanel.Children.Add(button3);
      stackPanel.Children.Add(backButton);

      button1.Focus();

      // Fade-in the buttons from the right.
      AnimateFrom(stackPanel.Children, 0, new Vector2F(300, 0));
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Called when "Menu" state is entered.
    /// </summary>
    private void OnEnterMenuScreen(object sender, StateEventArgs eventArgs)
    {
      // Show a main menu consisting of several buttons.

      // The user should be able to select individual buttons by using the 
      // D-pad on the gamepad or the arrow keys. Therefore we need to create
      // a Window. A Window manages the currently selected ("focused") control 
      // and automatically handles focus movement.
      // In this example the Window is invisible (no chrome) and stretches across 
      // the entire screen.
      _menuWindow = new Window
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };
      _uiScreen.Children.Add(_menuWindow);

      // The content of the Window is a vertical StackPanel containing several buttons.
      var stackPanel = new StackPanel
      {
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
        Margin = new Vector4F(150, 0, 0, 200)
      };
      _menuWindow.Content = stackPanel;

      // The "Start" button starts the "Game" state.
      var startButton = new Button
      {
        Name = "StartButton",
        Content = new TextBlock { Text = "Start" },
        FocusWhenMouseOver = true,
      };
      startButton.Click += OnStartButtonClicked;

      // The buttons "Sub menu 1" and "Sub menu 2" show a dummy sub-menu.
      var subMenu1Button = new Button
      {
        Name = "SubMenu1Button",
        Content = new TextBlock { Text = "Sub-menu 1" },
        FocusWhenMouseOver = true,
      };
      subMenu1Button.Click += OnSubMenuButtonClicked;

      var subMenu2Button = new Button
      {
        Name = "SubMenu2Button",
        Content = new TextBlock { Text = "Sub-menu 2" },
        FocusWhenMouseOver = true,
      };
      subMenu2Button.Click += OnSubMenuButtonClicked;

      // The "Exit" button closes the application.
      var exitButton = new Button
      {
        Name = "ExitButton",
        Content = new TextBlock { Text = "Exit" },
        FocusWhenMouseOver = true,
      };
      exitButton.Click += OnExitButtonClicked;

      stackPanel.Children.Add(startButton);
      stackPanel.Children.Add(subMenu1Button);
      stackPanel.Children.Add(subMenu2Button);
      stackPanel.Children.Add(exitButton);

      // By default, the first button should be selected.
      startButton.Focus();

      // Slide the buttons in from the left (off screen) to make things more dynamic.
      AnimateFrom(stackPanel.Children, 0, new Vector2F(-300, 0));

      // The first time initialization of the GUI can take a short time. If we reset the elapsed 
      // time of the XNA game timer, the animation will start a lot smoother. 
      // (This works only if the XNA game uses a variable time step.)
      Game.ResetElapsedTime();
    }