Example #1
0
        /// <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;

            // not implemented in NoesisGUI yet
            // setup Noesis Debug callbacks
            //Debug.ExceptionThrown = this.NoesisExceptionThrownHandler;
            //Debug.ErrorMessageReceived = this.NoesisErrorMessageReceivedHandler;

            this.graphicsDevice = config.Graphics.GraphicsDevice;
            this.FixAntiAliasingMode(ref this.antiAliasingMode);
            this.deviceD3D11 = (Device)this.graphicsDevice.Handle;

            this.deviceState = new DeviceStateHelperD3D11((Device)this.graphicsDevice.Handle);

            // setup resource providerManager
            if (config.NoesisFileSystemProviderRootFolderPath != null)
            {
                GUI.SetResourceProvider(config.NoesisFileSystemProviderRootFolderPath);
            }
            else
            {
                this.providerManager = config.CreateNoesisProviderManagerDelegate();
                GUI.SetResourceProvider(this.providerManager.Provider);
            }

            // 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.SetTheme(themeResourceDictionary);
                this.Theme = themeResourceDictionary;
            }

            // create and prepare view
            this.view         = this.CreateView(config.RootXamlFilePath);
            this.viewRenderer = this.view.Renderer;
            this.UpdateSize();

            // prepare input
            this.inputManager = new InputManager(
                this.view,
                this.ControlTreeRoot,
                config);

            // subscribe to XNA events
            this.EventsSubscribe();

            // call update with zero delta time to prepare the view for rendering
            this.startupTotalGameTime = config.CurrentTotalGameTime;
            this.Update(new GameTime(this.startupTotalGameTime, elapsedGameTime: TimeSpan.Zero), isWindowActive: true);
        }
Example #2
0
        /// <summary>
        /// Create view wrapper.
        /// <param name="currentTotalGameTime">Current game time (needed to do proper Update() calls).</param>
        /// <param name="rootElement">Root UI element.</param>
        /// <param name="graphicsDevice">MonoGame Graphics Device instance.</param>
        /// </summary>
        public NoesisViewWrapper(
            FrameworkElement rootElement,
            GraphicsDevice graphicsDevice,
            TimeSpan currentTotalGameTime)
        {
            this.graphicsDevice = graphicsDevice;
            var deviceD3D11 = (Device)this.graphicsDevice.Handle;

            this.deviceState = new DeviceStateHelperD3D11(deviceD3D11);

            this.view     = this.CreateView(rootElement, deviceD3D11);
            this.renderer = this.view.Renderer;

            this.ApplyQualitySetting();
            this.ApplyAntiAliasingSetting();
            this.ApplyRenderingFlagsSetting();

            this.startupTotalGameTime = this.lastUpdateTotalGameTime = currentTotalGameTime;
        }