Example #1
0
        protected override void OnAfterRender(bool firstRender)
        {
            if (firstRender)
            {
                Threading.Dispatcher.UIThread.Post(async() =>
                {
                    _inputHelper  = await InputHelperInterop.ImportAsync(Js, _inputElement);
                    _canvasHelper = await InputHelperInterop.ImportAsync(Js, _htmlCanvas);

                    _inputHelper.Hide();
                    _canvasHelper.SetCursor("default");
                    _topLevelImpl.SetCssCursor = x =>
                    {
                        _inputHelper.SetCursor(x);  //macOS
                        _canvasHelper.SetCursor(x); //windows
                    };

                    Console.WriteLine("starting html canvas setup");
                    _interop = await SKHtmlCanvasInterop.ImportAsync(Js, _htmlCanvas, OnRenderFrame);

                    Console.WriteLine("Interop created");
                    _jsGlInfo = _interop.InitGL();

                    Console.WriteLine("jsglinfo created - init gl");

                    _sizeWatcher = await SizeWatcherInterop.ImportAsync(Js, _htmlCanvas, OnSizeChanged);
                    _dpiWatcher  = await DpiWatcherInterop.ImportAsync(Js, OnDpiChanged);

                    Console.WriteLine("watchers created.");

                    // create the SkiaSharp context
                    if (_context == null)
                    {
                        Console.WriteLine("create glcontext");
                        _glInterface = GRGlInterface.Create();
                        _context     = GRContext.CreateGl(_glInterface);

                        var options = AvaloniaLocator.Current.GetService <SkiaOptions>();
                        // bump the default resource cache limit
                        _context.SetResourceCacheLimit(options?.MaxGpuResourceSizeBytes ?? 32 * 1024 * 1024);
                        Console.WriteLine("glcontext created and resource limit set");
                    }

                    _topLevelImpl.SetSurface(_context, _jsGlInfo, ColorType,
                                             new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi);

                    _initialised = true;

                    _topLevel.Prepare();

                    _topLevel.Renderer.Start();
                    Invalidate();
                });
            }
        }
Example #2
0
        public void SetActive(bool active)
        {
            _inputHelper.Clear();

            if (active)
            {
                _inputHelper.Show();
                _inputHelper.Focus();
            }
            else
            {
                _inputHelper.Hide();
            }
        }