Esempio n. 1
0
        private void Start()
        {
            // Create application display
            Display = CreateDisplay();

            // Redirect integration callbacks to display
            GUI.SetSoftwareKeyboardCallback((UIElement focused, bool open) =>
            {
                if (open)
                {
                    Display.OpenSoftwareKeyboard(focused);
                }
                else
                {
                    Display.CloseSoftwareKeyboard();
                }
            });

            GUI.SetCursorCallback((View view, Cursor cursor) =>
            {
                Display.SetCursor(cursor);
            });

            GUI.SetOpenUrlCallback((string url) =>
            {
                Display.OpenUrl(url);
            });

            GUI.SetPlaySoundCallback((string filename, float volume) =>
            {
                Display.PlaySound(filename, volume);
            });

            // Set resource providers
            Type type = this.GetType();

            GUI.SetXamlProvider(new EmbeddedXamlProvider(type.Assembly, type.Namespace, CreateXamlProvider()));
            GUI.SetTextureProvider(new EmbeddedTextureProvider(type.Assembly, type.Namespace, CreateTextureProvider()));
            GUI.SetFontProvider(new EmbeddedFontProvider(type.Assembly, type.Namespace, CreateFontProvider()));

            // Load App.xaml
            if (string.IsNullOrEmpty(Uri))
            {
                throw new InvalidOperationException("App xaml uri not defined");
            }

            GUI.LoadComponent(this, Uri);
            GUI.SetApplicationResources(Resources);

            // Load StartupUri xaml as MainWindow
            if (string.IsNullOrEmpty(StartupUri))
            {
                throw new InvalidOperationException("Startup window not defined");
            }

            object root = GUI.LoadXaml(StartupUri);

            MainWindow = root as Window;

            if (MainWindow == null)
            {
                // non window roots are allowed
                MainWindow         = new Window();
                MainWindow.Content = root;
                MainWindow.Title   = Title;
            }

            uint samples = Samples;
            bool vsync   = VSync;
            bool sRGB    = StandardRGB;
            bool ppaa    = PPAA;

            RenderContext renderContext = CreateRenderContext();

            renderContext.Init(Display.NativeHandle, Display.NativeWindow, samples, vsync, sRGB);
            renderContext.Device.OffscreenSampleCount = samples;

            Display.NativeHandleChanged += (Display display, IntPtr window) =>
            {
                renderContext.SetWindow(window);
            };

            MainWindow.Init(Display, renderContext, samples, ppaa);

            StartupEventArgs e = new StartupEventArgs();

            OnStartup(e);
        }
Esempio n. 2
0
        private void Start()
        {
            // Create application display
            Display = CreateDisplay();

            // Redirect integration callbacks to display
            GUI.SetSoftwareKeyboardCallback((UIElement focused, bool open) =>
            {
                if (open)
                {
                    Display.OpenSoftwareKeyboard(focused);
                }
                else
                {
                    Display.CloseSoftwareKeyboard();
                }
            });

            GUI.SetCursorCallback((View view, Cursor cursor) =>
            {
                Display.SetCursor(cursor);
            });

            GUI.SetOpenUrlCallback((string url) =>
            {
                Display.OpenUrl(url);
            });

            GUI.SetPlayAudioCallback((Uri uri, float volume) =>
            {
                Display.PlayAudio(uri, volume);
            });

            // Set resource providers
            Type appType = typeof(Application);
            EmbeddedXamlProvider xamlProvider = new EmbeddedXamlProvider(appType.Assembly, appType.Namespace, CreateXamlProvider());

            Type type = this.GetType();

            XamlProvider    = new EmbeddedXamlProvider(type.Assembly, type.Namespace, xamlProvider);
            FontProvider    = new EmbeddedFontProvider(type.Assembly, type.Namespace, CreateFontProvider());
            TextureProvider = new EmbeddedTextureProvider(type.Assembly, type.Namespace, CreateTextureProvider());

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

            // Load App.xaml
            if (string.IsNullOrEmpty(Uri))
            {
                throw new InvalidOperationException("App xaml uri not defined");
            }

            GUI.SetFontFallbacks(GetFontFallbacks());
            GUI.SetFontDefaultProperties(GetDefaultFontSize(), GetDefaultFontWeight(), GetDefaultFontStretch(), GetDefaultFontStyle());

            GUI.LoadComponent(this, Uri);
            GUI.SetApplicationResources(Resources);

            // Load StartupUri xaml as MainWindow
            if (string.IsNullOrEmpty(StartupUri))
            {
                throw new InvalidOperationException("Startup window not defined");
            }

            object root = GUI.LoadXaml(StartupUri);

            MainWindow = root as Window;

            if (MainWindow == null)
            {
                // non window roots are allowed
                MainWindow         = new Window();
                MainWindow.Content = root;
                MainWindow.Title   = Title;
            }

            bool vsync                      = VSync;
            bool sRGB                       = StandardRGB;
            bool ppaa                       = PPAA;
            bool lcd                        = LCD;
            bool emulateTouch               = EmulateTouch;
            uint holdingTimeThreshold       = HoldingTimeThreshold;
            uint holdingDistanceThreshold   = HoldingDistanceThreshold;
            uint doubleTapTimeThreshold     = DoubleTapTimeThreshold;
            uint doubleTapDistanceThreshold = DoubleTapDistanceThreshold;
            uint samples                    = Samples;

            RenderContext renderContext = CreateRenderContext();

            renderContext.Init(Display.NativeHandle, Display.NativeWindow, samples, vsync, sRGB);
            renderContext.Device.OffscreenSampleCount        = samples;
            renderContext.Device.OffscreenWidth              = OffscreenWidth;
            renderContext.Device.OffscreenHeight             = OffscreenHeight;
            renderContext.Device.OffscreenDefaultNumSurfaces = OffscreenDefaultNumSurfaces;
            renderContext.Device.OffscreenMaxNumSurfaces     = OffscreenMaxNumSurfaces;
            renderContext.Device.GlyphCacheWidth             = GlyphCacheWidth;
            renderContext.Device.GlyphCacheHeight            = GlyphCacheHeight;

            Display.NativeHandleChanged += (Display display, IntPtr window) =>
            {
                renderContext.SetWindow(window);
            };

            MainWindow.Init(Display, renderContext, samples, ppaa, lcd, emulateTouch,
                            holdingTimeThreshold, holdingDistanceThreshold,
                            doubleTapTimeThreshold, doubleTapDistanceThreshold);

            StartupEventArgs e = new StartupEventArgs();

            OnStartup(e);
        }