private void UpdateElevation()
        {
            if (!Element.IsShadowCompatible)
            {
                _shadowHost.Fill = Color.Transparent.ToBrush();

                if (_shadowVisual != null)
                {
                    ElementCompositionPreview.SetElementChildVisual(_shadowHost, null);
                    _shadowVisual.Dispose();
                    _shadowVisual = null;
                }

                if (Element.MaterialTheme == MaterialFrame.Theme.Dark)
                {
                    _grid.Background = Element.ElevationToColor().ToBrush();
                }

                return;
            }

            if (Element.Width < 1 || Element.Height < 1)
            {
                return;
            }

            // https://docs.microsoft.com/en-US/windows/uwp/composition/using-the-visual-layer-with-xaml
            bool isAcrylicTheme = Element.MaterialTheme == MaterialFrame.Theme.Acrylic;

            float blurRadius = isAcrylicTheme ? MaterialFrame.AcrylicElevation : Element.Elevation;
            int   elevation  = isAcrylicTheme ? MaterialFrame.AcrylicElevation / 3 : Element.Elevation / 2;
            float opacity    = isAcrylicTheme ? 0.12f : 0.16f;

            int width  = (int)Element.Width;
            int height = (int)Element.Height;

            _shadowHost.Fill   = Color.White.ToBrush();
            _shadowHost.Width  = width;
            _shadowHost.Height = height;

            if (_compositor == null)
            {
                Visual hostVisual = ElementCompositionPreview.GetElementVisual(_grid);
                _compositor = hostVisual.Compositor;
            }

            var dropShadow = _compositor.CreateDropShadow();

            dropShadow.BlurRadius = blurRadius;
            dropShadow.Opacity    = opacity;
            dropShadow.Color      = Color.Black.ToWindowsColor();
            dropShadow.Offset     = new Vector3(0, elevation, 0);
            dropShadow.Mask       = _shadowHost.GetAlphaMask();

            _shadowVisual        = _compositor.CreateSpriteVisual();
            _shadowVisual.Size   = new Vector2(width, height);
            _shadowVisual.Shadow = dropShadow;

            ElementCompositionPreview.SetElementChildVisual(_shadowHost, _shadowVisual);
        }
Esempio n. 2
0
        private void StartOpacityAnimations(VisualImage visualImage)
        {
            var batch            = visualImage.ForegroundVisual.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
            var opacityAnimation = visualImage.ForegroundVisual.Compositor.CreateScalarKeyFrameAnimation();

            opacityAnimation.InsertKeyFrame(0f, 0f);
            opacityAnimation.InsertKeyFrame(1f, 1f);
            opacityAnimation.Duration = TimeSpan.FromMilliseconds(400);

            var visual = ElementCompositionPreview.GetElementVisual(visualImage);

            visual.StartAnimation(nameof(Visual.Opacity), opacityAnimation);

            var opacityHideAnimation = _floatingVisual.Compositor.CreateScalarKeyFrameAnimation();

            opacityHideAnimation.InsertKeyFrame(0f, 1f);
            opacityHideAnimation.InsertKeyFrame(1f, 0f);
            opacityHideAnimation.Duration = TimeSpan.FromMilliseconds(400);

            _floatingVisual.StartAnimation(nameof(Visual.Opacity), opacityHideAnimation);

            batch.Completed += (sender, args) =>
            {
                ElementCompositionPreview.SetElementChildVisual(_hostFrame, null);
                _floatingVisual?.Dispose();
                _floatingVisual = null;
            };
            batch.End();
        }
Esempio n. 3
0
 private void OnBatchCompleted(object sender, CompositionBatchCompletedEventArgs args)
 {
     _visual.Dispose();
     _brush.Dispose();
     _visual = null;
     _brush  = null;
 }
Esempio n. 4
0
        private void CompImage_Unloaded(object sender, RoutedEventArgs e)
        {
            // The Unloaded event can be fired asynchronously, and can occur spuriously, while we are still connected into the tree.
            // In that case, we don't want to unload our surface and visual because this will result in the displayed image
            // not being displayed.   Since we don't actually reparent this control in any samples, we can detect the Unloaded event we
            // actually care about by checking our Parent for null - it will be null when the UI tree is being torn down, at which point
            // it is appropriate to actually free our resources.

            if (Parent != null)
            {
                return;
            }


            _unloaded = true;

            ReleaseSurface();

            if (_sprite != null)
            {
                ElementCompositionPreview.SetElementChildVisual(this, null);

                _sprite.Dispose();
                _sprite = null;
            }
        }
        private void Uninitialize()
        {
            if (!IsInitialized)
            {
                return;
            }

            IsInitialized = false;

            Parent.OnElementContextUninitialized(this);

            if (SpriteVisual != null)
            {
                SpriteVisual.Shadow = null;
                SpriteVisual.Dispose();
            }

            Shadow?.Dispose();

            ElementCompositionPreview.SetElementChildVisual(Element, null);

            Element.SizeChanged -= OnElementSizeChanged;

            SpriteVisual  = null;
            Shadow        = null;
            ElementVisual = null;
        }
        // This animation has constant duration, speedy changes depending on the distance
        // between sourceElement and targetElement.
        public async Task StartAnimation2(FrameworkElement sourceElement, FrameworkElement targetElement)
        {
            Point point = sourceElement.TransformToVisual(_rootElement).TransformPoint(new Point(0, 0));

            CompositionDrawingSurface surface = await CompositionDrawingSurfaceFacade1.GetCompositionDrawingSurface(sourceElement, _compositor);

            SpriteVisual spriteVisual = _compositor.CreateSpriteVisual();

            spriteVisual.Brush  = _compositor.CreateSurfaceBrush(surface);
            spriteVisual.Size   = new Vector2((float)surface.Size.Width, (float)surface.Size.Height);
            spriteVisual.Offset = new Vector3((float)point.X, (float)point.Y, 0f);
            _containerVisual.Children.InsertAtBottom(spriteVisual);

            Vector3 targetOffset = GetTargetOffset(targetElement);
            Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();

            Vector2 targetSize = GetTargetSize(targetElement);
            Vector2KeyFrameAnimation sizeAnimation = _compositor.CreateVector2KeyFrameAnimation();

            var newWidth  = (float)(sourceElement.ActualWidth * 1.3);
            var newHeight = (float)(sourceElement.ActualHeight * 1.3);
            var newX      = (float)(point.X - (newWidth - sourceElement.ActualWidth) / 2);
            var newY      = (float)(point.Y - (newHeight - sourceElement.ActualHeight) / 2);

            double sizeDurationInMs      = 250;
            double distance              = Math.Sqrt(Math.Pow(targetOffset.X - newX, 2) + Math.Pow(targetOffset.Y - newY, 2));
            double offsetDurationInMs    = distance / 2;
            double animationDurationInMs = sizeDurationInMs + offsetDurationInMs;

            sizeAnimation.Duration   = TimeSpan.FromMilliseconds(animationDurationInMs);
            offsetAnimation.Duration = TimeSpan.FromMilliseconds(animationDurationInMs);

            SetAnimationDefautls(offsetAnimation);
            SetAnimationDefautls(sizeAnimation);

            var normalizedProgressKey0 = (float)(sizeDurationInMs / animationDurationInMs);

            offsetAnimation.InsertKeyFrame(normalizedProgressKey0, new Vector3(newX, newY, 0f));
            sizeAnimation.InsertKeyFrame(normalizedProgressKey0, new Vector2(newWidth, newHeight));

            const float normalizedProgressKey1 = 1f;

            offsetAnimation.InsertKeyFrame(normalizedProgressKey1, targetOffset, _compositor.CreateLinearEasingFunction());
            sizeAnimation.InsertKeyFrame(normalizedProgressKey1, targetSize, _compositor.CreateLinearEasingFunction());

            CompositionScopedBatch myScopedBatch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
            var batchCompletitionAwaiter         = new BatchCompletitionAwaiter(myScopedBatch);

            spriteVisual.StartAnimation("Offset", offsetAnimation);
            spriteVisual.StartAnimation("Size", sizeAnimation);
            myScopedBatch.End();
            await batchCompletitionAwaiter.Completed();

            myScopedBatch.Dispose();
            spriteVisual.Dispose();
            surface.Dispose();
            offsetAnimation.Dispose();
            sizeAnimation.Dispose();
        }
Esempio n. 7
0
        private void TurnOffGlass()
        {
            if (!IsGlassOn)
            {
                return;
            }

            ElementCompositionPreview.SetElementChildVisual(GlassHost, null); //turn off the glass

            if (glassVisual != null)
            {
                glassVisual.Dispose();
                glassVisual = null;
            }

            IsGlassOn = false;
        }
        public void Dispose()
        {
            _acrylicVisual.Dispose();
            _noiseSurfaceBrush.Dispose();

            _canvasDevice.Dispose();
            _compositionGraphicsDevice.Dispose();
        }
Esempio n. 9
0
 public void Dispose()
 {
     StopCapture();
     compositor = null;
     root.Dispose();
     content.Dispose();
     brush.Dispose();
     device.Dispose();
 }
 public void Dispose()
 {
     StopCapture();
     __compositor = null;
     __root.Dispose();
     __content.Dispose();
     __brush.Dispose();
     __device.Dispose();
 }
Esempio n. 11
0
 public void Dispose()
 {
     StopCapture();
     compositor = null;
     containerVisual.Dispose();
     spriteVisual.Dispose();
     brush.Dispose();
     device.Dispose();
 }
        public new void Dispose()
        {
            base.Dispose();

            acrylicVisual.Dispose();
            noiseSurfaceBrush.Dispose();

            canvasDevice.Dispose();
            compositionGraphicsDevice.Dispose();
        }
 void RemoveShadowVisual()
 {
     if (hostElement == null || shadowVisual == null)
     {
         return;
     }
     ElementCompositionPreview.SetElementChildVisual(hostElement, null);
     shadowVisual.Dispose();
     shadowVisual = null;
 }
        protected override void CustomRemoveEffect()
        {
            if (_animatedVisual != null)
            {
                _animatedVisual.Dispose();
                _animatedVisual = null;
            }

            TargetElement.SizeChanged -= this.TargetElement_SizeChanged;
        }
        private void CompImage_Unloaded(object sender, RoutedEventArgs e)
        {
            _unloaded = true;

            if (_sprite != null)
            {
                _sprite.Dispose();
                _sprite = null;
            }
        }
Esempio n. 16
0
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            // Dispose the sprite and unparent it
            ElementCompositionPreview.SetElementChildVisual(ThumbnailList, null);

            if (_destinationSprite != null)
            {
                _destinationSprite.Dispose();
                _destinationSprite = null;
            }
        }
Esempio n. 17
0
        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            CleanUp();

            if (glassVisual != null)
            {
                glassVisual.Dispose();
            }

            unloaded = true;
        }
Esempio n. 18
0
        private void Dispose()
        {
            ThumbnailSpriteVisual?.Dispose();
            ThumbnailSpriteVisual = null;

            ThumbnailSurfaceBrush?.Dispose();
            ThumbnailSurfaceBrush = null;

            SubMediaList  = null;
            MainMediaList = null;
            contentlist   = null;
        }
        private void CompImage_Unloaded(object sender, RoutedEventArgs e)
        {
            _unloaded = true;

            ReleaseSurface();

            if (_sprite != null)
            {
                ElementCompositionPreview.SetElementChildVisual(this, null);

                _sprite.Dispose();
                _sprite = null;
            }
        }
Esempio n. 20
0
        private void CompImage_Unloaded(object sender, RoutedEventArgs e)
        {
            _unloaded = true;

            // TODO: Remove this workaround after 14332
            ReleaseSurface();

            if (_sprite != null)
            {
                // TODO: Remove this workaround after 14332
                ElementCompositionPreview.SetElementChildVisual(this, null);

                _sprite.Dispose();
                _sprite = null;
            }
        }
Esempio n. 21
0
        public void RemoveEffect()
        {
            _targetElement.SizeChanged -= TargetElementOnSizeChanged;

            if (_effectVisual != null)
            {
                _effectVisual.Dispose();
                _effectBrush = null;
            }

            if (_effectBrush != null)
            {
                _effectBrush.Dispose();
                _effectBrush = null;
            }

            CustomRemoveEffect();
        }
Esempio n. 22
0
        private void Dispose(bool IsDisposing)
        {
            _visual?.Dispose();
            _visual = null;

            _brush?.Dispose();
            _brush = null;

            _surface?.Dispose();
            _surface = null;

            _animations?.Dispose();
            _animations = null;

            if (IsDisposing)
            {
                GC.SuppressFinalize(this);
            }
        }
        protected override void OnDetached()
        {
            if (state != ShadowEffectState.Attached)
            {
                return;
            }

            if (View != null)
            {
                View.SizeChanged -= ViewSizeChanged;
            }

            shadow?.Dispose();
            shadow = null;
            spriteVisual?.Dispose();
            spriteVisual = null;

            state = ShadowEffectState.PanelCreated;
        }
Esempio n. 24
0
        private void LoadMazeRunnerVisual()
        {
            if (_mazeRunnerVisual != null)
            {
                _mazeRunnerVisual.Dispose();
            }

            _mazeRunnerVisual      = _compositor.CreateSpriteVisual();
            _mazeRunnerVisual.Size = new Vector2(_cellSize, _cellSize);

            LoadedImageSurface      loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/luna.png"), new Size(_cellSize, _cellSize));
            CompositionSurfaceBrush surfaceBrush  = _compositor.CreateSurfaceBrush();

            surfaceBrush.Surface    = loadedSurface;
            _mazeRunnerVisual.Brush = surfaceBrush;

            ElementCompositionPreview.SetElementChildVisual(MazeGrid, _mazeRunnerVisual);
            _mazeRunnerVisual.IsVisible = true;
            _mazeRunnerVisual.Opacity   = 1;
        }
Esempio n. 25
0
        public void Dispose()
        {
            imageFactory = null;
            imageSource  = null;


            if (effect != null)
            {
                effect.Dispose();
                effect = null;
            }

            if (surfaceBrush != null)
            {
                surfaceBrush.Surface = null;
                surfaceBrush.Dispose();
                surfaceBrush = null;
            }

            //if (visual != null)
            //{
            //    if(spriteVisual!=null) visual.Children.Remove(spriteVisual);
            //    visual.Dispose();
            //    visual = null;
            //}

            if (effectBrush != null)
            {
                effectBrush.SetSourceParameter(EffectSource, null);
                effectBrush.Dispose();
                effectBrush = null;
            }

            if (spriteVisual != null)
            {
                spriteVisual.Brush = null;
                spriteVisual.Dispose();
                spriteVisual = null;
            }
        }
Esempio n. 26
0
 private void DisposeShadow()
 {
     if (_shadowAmbient != null)
     {
         _shadowAmbient.Dispose();
         _shadowAmbient = null;
     }
     if (_shadowAmbientVisual != null)
     {
         _shadowAmbientVisual.Dispose();
         _shadowAmbientVisual = null;
     }
     if (_shadowDirectional != null)
     {
         _shadowDirectional.Dispose();
         _shadowDirectional = null;
     }
     if (_shadowDirectionalVisual != null)
     {
         _shadowDirectionalVisual.Dispose();
         _shadowDirectionalVisual = null;
     }
 }
Esempio n. 27
0
 private void disableAcrylicAccent(Panel transparentArea)
 {
     _hostSprite.Dispose();
 }