Esempio n. 1
0
        private void CreateNoesisGUI()
        {
            var rootPath        = Path.Combine(Environment.CurrentDirectory, "Data");
            var providerManager = new NoesisProviderManager(
                new FolderXamlProvider(rootPath),
                new FolderFontProvider(rootPath),
                new FolderTextureProvider(rootPath, this.GraphicsDevice));

            var config = new NoesisConfig(
                this.Window,
                this.graphics,
                providerManager,
                rootXamlFilePath: "Grid.xaml", //"../Data_old/Samples/TextBox.xaml", //"TextBox.xaml",
                themeXamlFilePath: "Theme/NoesisTheme.DarkBlue.xaml",
                // uncomment this line to use theme file
                //themeXamlFilePath: "Themes/WindowsStyle.xaml",
                currentTotalGameTime: this.lastUpdateTotalGameTime);

            config.SetupInputFromWindows();

            this.noesisWrapper = new NoesisWrapper(config);
            //this.noesisWrapper.View.IsPPAAEnabled = true;


            this.noesisWrapper.View.GetView().SetFlags(Noesis.RenderFlags.PPAA | Noesis.RenderFlags.LCD);

            string[] fonts = new string[] { "Theme/Fonts/#PT Root UI", "Arial", "Segoe UI Emoji" };

            Noesis.GUI.LoadApplicationResources("Theme/NoesisTheme.DarkBlue.xaml");
            Noesis.GUI.SetFontFallbacks(fonts);
            Noesis.GUI.SetFontDefaultProperties(15, Noesis.FontWeight.Normal, Noesis.FontStretch.Normal, Noesis.FontStyle.Normal);
        }
 private void Shutdown()
 {
     this.DestroyRoot();
     this.Theme = null;
     this.providerManager.Dispose();
     this.providerManager = null;
     GUI.UnregisterNativeTypes();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="NoesisWrapper" /> class.
        /// </summary>
        public NoesisWrapper(NoesisConfig config)
        {
            config.Validate();
            this.config     = config;
            this.gameWindow = config.GameWindow;

            // setup Noesis Debug callbacks
            Log.LogCallback = this.NoesisLogCallbackHandler;

            this.graphicsDevice  = config.Graphics.GraphicsDevice;
            this.providerManager = config.NoesisProviderManager;
            var provider = this.providerManager.Provider;

            GUI.SetFontProvider(provider.FontProvider);
            GUI.SetTextureProvider(provider.TextureProvider);
            GUI.SetXamlProvider(provider.XamlProvider);

            // setup theme
            if (config.ThemeXamlFilePath != null)
            {
                var themeResourceDictionary = (ResourceDictionary)GUI.LoadXaml(config.ThemeXamlFilePath);
                if (themeResourceDictionary == null)
                {
                    throw new Exception(
                              $"Theme is not found or was not able to load by NoesisGUI: {config.ThemeXamlFilePath}");
                }

                GUI.SetApplicationResources(themeResourceDictionary);
                this.Theme = themeResourceDictionary;
            }

            // create and prepare view
            var controlTreeRoot = (FrameworkElement)GUI.LoadXaml(config.RootXamlFilePath);

            this.ControlTreeRoot = controlTreeRoot
                                   ?? throw new Exception(
                                             $"UI file \"{config.RootXamlFilePath}\" is not found - cannot initialize UI");

            this.view = new NoesisViewWrapper(
                controlTreeRoot,
                this.graphicsDevice,
                this.config.CurrentTotalGameTime);
            this.RefreshSize();

            this.inputManager = this.view.CreateInputManager(config);

            // subscribe to MonoGame events
            this.EventsSubscribe();
        }
Esempio n. 4
0
        private void CreateNoesisGUI()
        {
            var rootPath        = Path.Combine(Environment.CurrentDirectory, "Data");
            var providerManager = new NoesisProviderManager(
                new FolderXamlProvider(rootPath),
                new FolderFontProvider(rootPath),
                new FolderTextureProvider(rootPath, this.GraphicsDevice));

            var config = new NoesisConfig(
                this.Window,
                this.graphics,
                providerManager,
                rootXamlFilePath: "Samples/TextBox.xaml",
                themeXamlFilePath: null,
                // uncomment this line to use theme file
                //themeXamlFilePath: "Themes/WindowsStyle.xaml",
                currentTotalGameTime: this.lastUpdateTotalGameTime);

            config.SetupInputFromWindows();

            this.noesisWrapper = new NoesisWrapper(config);
            this.noesisWrapper.View.IsPPAAEnabled = true;
        }
        /// <param name="gameWindow">The MonoGame GameWindow instance.</param>
        /// <param name="graphics">Graphics device manager of the game instance.</param>
        /// <param name="noesisProviderManager">NoesisGUI Provider Manager (create it before calling this method).</param>
        /// <param name="rootXamlFilePath">Local XAML file path - will be used as the UI root element.</param>
        /// <param name="themeXamlFilePath">
        /// (can be null) Local XAML file path - will be used as global ResourceDictionary (UI
        /// style).
        /// </param>
        /// <param name="checkIfElementIgnoresHitTest">
        /// Callback to invoke when element is tested for hit test (if callback returns true hit is ignored).
        /// It has default implementation so you can skip this.
        /// </param>
        /// <param name="onErrorMessageReceived">Callback to invoke when error message received from NoesisGUI.</param>
        /// <param name="onExceptionThrown">
        /// Callback to invoke when exception thrown from NoesisGUI context (can be in event
        /// handler, etc).
        /// </param>
        /// <param name="currentTotalGameTime">Current game time (needed to do proper Update() calls).</param>
        /// <param name="isEnableDirectionalNavigation">
        /// Is directional (arrow) keys navigation should be enabled? If it's disabled (by default)
        /// arrow key presses will be not passed to NoesisGUI unless it's focused on a textbox.
        /// </param>
        /// <param name="isProcessMouseMiddleButton">
        /// Enable processing of the middle (scrollwheel) mouse button (disabled by
        /// default).
        /// </param>
        public NoesisConfig(
            GameWindow gameWindow,
            GraphicsDeviceManager graphics,
            NoesisProviderManager noesisProviderManager,
            string rootXamlFilePath,
            string themeXamlFilePath,
            TimeSpan currentTotalGameTime,
            HitTestIgnoreDelegate checkIfElementIgnoresHitTest = null,
            Action <string> onErrorMessageReceived             = null,
            Action <Exception> onExceptionThrown = null,
            bool isEnableDirectionalNavigation   = false,
            bool isProcessMouseMiddleButton      = false)
        {
            if (string.IsNullOrEmpty(rootXamlFilePath))
            {
                throw new ArgumentNullException(
                          nameof(rootXamlFilePath),
                          "File path to the root xaml element cannot be null");
            }

            this.GameWindow = gameWindow ?? throw new ArgumentNullException(nameof(gameWindow));
            this.Graphics   = graphics ?? throw new ArgumentNullException(nameof(graphics));

            this.RootXamlFilePath  = rootXamlFilePath.Replace('/', '\\');
            this.ThemeXamlFilePath = themeXamlFilePath?.Replace('/', '\\');

            this.CheckIfElementIgnoresHitTest = checkIfElementIgnoresHitTest
                                                ?? this.DefaultCheckIfElementIgnoresHitTest;

            this.OnErrorMessageReceived        = onErrorMessageReceived;
            this.OnExceptionThrown             = onExceptionThrown;
            this.CurrentTotalGameTime          = currentTotalGameTime;
            this.IsProcessMouseMiddleButton    = isProcessMouseMiddleButton;
            this.NoesisProviderManager         = noesisProviderManager;
            this.IsEnableDirectionalNavigation = isEnableDirectionalNavigation;
        }