Exemplo n.º 1
0
    /// <summary>
    /// Returns a panel for adding controls to the Options window.
    /// </summary>
    /// <param name="tabName">The name of the tab page.</param>
    /// <param name="tabIndex">The index of the tab page.</param>
    /// <returns>
    /// The panel that hosts the UI controls in the Options window.
    /// Add the new controls to this panel!
    /// </returns>
    public Panel AddOptions(string tabName, int tabIndex)
    {
      // Check if tab control already contains the specified tab.
      var optionsPanel = _optionsTabControl.Items
                                           .Where(tabItem => tabItem.Name == tabName)
                                           .Select(tabItem => (Panel)(((ScrollViewer)tabItem.TabPage).Content))
                                           .FirstOrDefault();
      if (optionsPanel == null)
        optionsPanel = SampleHelper.AddTabItem(_optionsTabControl, tabName, tabIndex);

      return optionsPanel;
    }
Exemplo n.º 2
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.");
        }