Exemple #1
0
        private async Task <ManagedSurface> LoadFromUriAsyncWorker(Uri uri, Size size, LoadTimeEffectHandler handler)
        {
            ManagedSurface surface = new ManagedSurface(CreateSurface(size));
            await surface.Draw(_graphicsDevice, _drawingLock, new BitmapDrawer(uri, handler));

            return(surface);
        }
Exemple #2
0
        public ManagedSurface LoadText(string text, Size size, CanvasTextFormat textFormat, Color textColor, Color bgColor)
        {
            ManagedSurface surface = new ManagedSurface(CreateSurface(size));
            var            ignored = surface.Draw(_graphicsDevice, _drawingLock, new TextDrawer(text, textFormat, textColor, bgColor));

            return(surface);
        }
Exemple #3
0
        public ManagedSurface LoadCircle(float radius, Color color)
        {
            ManagedSurface surface = new ManagedSurface(CreateSurface(new Size(radius * 2, radius * 2)));
            var            ignored = surface.Draw(_graphicsDevice, _drawingLock, new CircleDrawer(radius, color));

            return(surface);
        }
Exemple #4
0
        public ManagedSurface LoadFromUri(Uri uri, Size size, LoadTimeEffectHandler handler)
        {
            ManagedSurface surface = new ManagedSurface(CreateSurface(size));
            var            ignored = surface.Draw(_graphicsDevice, _drawingLock, new BitmapDrawer(uri, handler));

            return(surface);
        }
Exemple #5
0
#pragma warning disable 1998
        private async void OnLoading(FrameworkElement sender, object args)
        {
            this.SizeChanged += OnSizeChanged;
            OnSizeChanged(this, null);

#if SDKVERSION_14393
            m_noiseSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Assets/Noise.png"));
            m_noiseSurface.Brush.Stretch = CompositionStretch.UniformToFill;
            m_blurBrush.SetSourceParameter("NoiseImage", m_noiseSurface.Brush);
#endif
        }
Exemple #6
0
 private void ReleaseSurface()
 {
     if (_surface != null)
     {
         // If no one has asked to share, dispose it to free the memory
         if (!_sharedSurface)
         {
             _surface.Dispose();
             _surfaceBrush.Surface = null;
         }
         else
         {
             // No longer being managed
             ImageLoader.Instance.UnregisterSurface(_surface);
         }
         _surface = null;
     }
 }
Exemple #7
0
        private async void LoadSurface()
        {
            // If we're clearing out the content, return
            if (_uri == null)
            {
                ReleaseSurface();
                return;
            }

            try
            {
                // Start a timer to enable the placeholder image if requested
                if (_surface == null && _placeholderDelay >= TimeSpan.Zero)
                {
                    _timer          = new DispatcherTimer();
                    _timer.Interval = _placeholderDelay;
                    _timer.Tick    += Timer_Tick;
                    _timer.Start();
                }

                // Load the image asynchronously
                ManagedSurface surface = await ImageLoader.Instance.LoadFromUriAsync(_uri, Size.Empty, _loadEffectDelegate);

                if (_surface != null)
                {
                    ReleaseSurface();
                }

                _surface = surface;

                // The surface has changed, so we need to re-measure with the new surface dimensions
                InvalidateMeasure();

                // Async operations may take a while.  If we've unloaded, return now.
                if (_unloaded)
                {
                    ReleaseSurface();
                    return;
                }

                // Update the brush
                UpdateBrush();

                // Success, fire the Opened event
                if (ImageOpened != null)
                {
                    ImageOpened(this, null);
                }

                //
                // If we created the loading placeholder, now that the image has loaded
                // cross-fade it out.
                //

                if (_sprite != null && _sprite.Children.Count > 0)
                {
                    Debug.Assert(_timer == null);
                    StartCrossFade();
                }
                else if (_timer != null)
                {
                    // We didn't end up loading the placeholder, so just stop the timer
                    _timer.Stop();
                    _timer = null;
                }
            }
            catch (FileNotFoundException)
            {
                if (ImageFailed != null)
                {
                    ImageFailed(this, null);
                }
            }
        }
Exemple #8
0
 public void UnregisterSurface(ManagedSurface surface)
 {
     _deviceReplacedEvent -= surface.OnDeviceReplaced;
 }