Esempio n. 1
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor      = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image       = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader      = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png"));

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();

            mask.Surface = _imageMaskSurface.Surface;

            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush        = _compositor.CreateMaskBrush();
            _maskBrush.Mask   = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask
            _isMaskEnabled = false;
        }
 /// <summary>
 /// Creates the circle used in the circle brush if not already created.
 /// </summary>
 private void EnsureCircleBrush()
 {
     if (_circleBrush == null)
     {
         _imageLoader   = ImageLoaderFactory.CreateImageLoader(_compositor);
         _circleSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri(CircleImagePath));
         _circleBrush   = _compositor.CreateSurfaceBrush(_circleSurface.Surface);
     }
 }
        /// <summary>
        /// Creates an instance of the ColorBloomTransitionHelper. 
        /// Any visuals to be later created and animated will be hosted within the specified UIElement.
        /// </summary>
        public ColorBloomTransitionHelper(UIElement hostForVisual)
        {
            this.hostForVisual = hostForVisual;

            // we have an element in the XAML tree that will host our Visuals
            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);
            _compositor = visual.Compositor;

            // create a container
            // adding children to this container adds them to the live visual tree
            _containerForVisuals = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);

            // initialize the ImageLoader and create the circle mask
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/TransitionAnimation-ColorBloom/CircleOpacityMask.png"));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates an instance of the ColorBloomTransitionHelper.
        /// Any visuals to be later created and animated will be hosted within the specified UIElement.
        /// </summary>
        public ColorBloomTransitionHelper(UIElement hostForVisual)
        {
            this.hostForVisual = hostForVisual;

            // we have an element in the XAML tree that will host our Visuals
            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);

            _compositor = visual.Compositor;

            // create a container
            // adding children to this container adds them to the live visual tree
            _containerForVisuals = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);

            // initialize the ImageLoader and create the circle mask
            _imageLoader       = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleOpacityMask.png"));
        }
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor      = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image       = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;

            // Add drop shadow to image visual
            _shadow             = _compositor.CreateDropShadow();
            _imageVisual.Shadow = _shadow;

            // Initialize sliders to shadow defaults - with the exception of offset
            BlurRadiusSlider.Value = _shadow.BlurRadius;    //defaults to 9.0f
            OffsetXSlider.Value    = _shadow.Offset.X;      //defaults to 0
            OffsetYSlider.Value    = _shadow.Offset.Y;      //defaults to 0
            RedSlider.Value        = _shadow.Color.R;       //defaults to 0 (black.R)
            GreenSlider.Value      = _shadow.Color.G;       //defaults to 0 (black.G)
            BlueSlider.Value       = _shadow.Color.B;       //defaults to 0 (black.B)

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader      = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png"));

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();

            mask.Surface = _imageMaskSurface.Surface;

            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush        = _compositor.CreateMaskBrush();
            _maskBrush.Mask   = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask and animation to false
            _isMaskEnabled      = false;
            _isAnimationEnabled = false;
        }
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;
           
            // Add drop shadow to image visual
            _shadow = _compositor.CreateDropShadow();
            _imageVisual.Shadow = _shadow;

            // Initialize sliders to shadow defaults - with the exception of offset
            BlurRadiusSlider.Value  = _shadow.BlurRadius;   //defaults to 9.0f
            OffsetXSlider.Value     = _shadow.Offset.X;     //defaults to 0
            OffsetYSlider.Value     = _shadow.Offset.Y;     //defaults to 0
            RedSlider.Value         = _shadow.Color.R;      //defaults to 0 (black.R)
            GreenSlider.Value       = _shadow.Color.G;      //defaults to 0 (black.G) 
            BlueSlider.Value        = _shadow.Color.B;      //defaults to 0 (black.B) 

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png"));

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
            mask.Surface = _imageMaskSurface.Surface;
            
            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush = _compositor.CreateMaskBrush();
            _maskBrush.Mask = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask and animation to false
            _isMaskEnabled = false;
            _isAnimationEnabled = false;
          
        }
 /// <summary>
 /// Creates the circle used in the circle brush if not already created.
 /// </summary>
 private void EnsureCircleBrush()
 {
     if (_circleBrush == null)
     {
         _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
         _circleSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri(CircleImagePath));
         _circleBrush = _compositor.CreateSurfaceBrush(_circleSurface.Surface);
     }
 }
Esempio n. 8
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Compositor      compositor  = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;
            IImageLoader    imageLoader = ImageLoaderFactory.CreateImageLoader(compositor);
            ContainerVisual container   = compositor.CreateContainerVisual();

            ElementCompositionPreview.SetElementChildVisual(MyGrid, container);


            //
            // Create a couple of SurfaceBrushes for the orbiters and center
            //

            CompositionSurfaceBrush redBrush = compositor.CreateSurfaceBrush();

            _redBallSurface  = imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png"));
            redBrush.Surface = _redBallSurface.Surface;

            CompositionSurfaceBrush blueBrush = compositor.CreateSurfaceBrush();

            _blueBallSurface  = imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png"));
            blueBrush.Surface = _blueBallSurface.Surface;


            //
            // Create the center and orbiting sprites
            //

            SpriteVisual redSprite = compositor.CreateSpriteVisual();

            redSprite.Brush  = redBrush;
            redSprite.Size   = new Vector2(100f, 100f);
            redSprite.Offset = new Vector3(200f, 200f, 0f);
            container.Children.InsertAtTop(redSprite);

            SpriteVisual blueSprite = compositor.CreateSpriteVisual();

            blueSprite.Brush  = blueBrush;
            blueSprite.Size   = new Vector2(25f, 25f);
            blueSprite.Offset = new Vector3(0f, 0f, 0f);
            container.Children.InsertAtTop(blueSprite);

            //
            // Create the expression.  This expression positions the orbiting sprite relative to the center of
            // of the red sprite's center.  As we animate the red sprite's position, the expression will read
            // the current value of it's offset and keep the blue sprite locked in orbit.
            //

            ExpressionAnimation expressionAnimation = compositor.CreateExpressionAnimation("visual.Offset + " +
                                                                                           "propertySet.CenterPointOffset + " +
                                                                                           "Vector3(cos(ToRadians(propertySet.Rotation)) * 150," +
                                                                                           "sin(ToRadians(propertySet.Rotation)) * 75, 0)");

            //
            // Create the PropertySet.  This property bag contains all the value referenced in the expression.  We can
            // animation these property leading to the expression being re-evaluated per frame.
            //

            CompositionPropertySet propertySet = compositor.CreatePropertySet();

            propertySet.InsertScalar("Rotation", 0f);
            propertySet.InsertVector3("CenterPointOffset", new Vector3(redSprite.Size.X / 2 - blueSprite.Size.X / 2,
                                                                       redSprite.Size.Y / 2 - blueSprite.Size.Y / 2, 0));

            // Set the parameters of the expression animation
            expressionAnimation.SetReferenceParameter("propertySet", propertySet);
            expressionAnimation.SetReferenceParameter("visual", redSprite);

            // Start the expression animation!
            blueSprite.StartAnimation("Offset", expressionAnimation);


            // Now animate the rotation property in the property bag, this generates the orbitting motion.
            var linear       = compositor.CreateLinearEasingFunction();
            var rotAnimation = compositor.CreateScalarKeyFrameAnimation();

            rotAnimation.InsertKeyFrame(1.0f, 360f, linear);
            rotAnimation.Duration          = TimeSpan.FromMilliseconds(4000);
            rotAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            propertySet.StartAnimation("Rotation", rotAnimation);

            // Lastly, animation the Offset of the red sprite to see the expression track appropriately
            var offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0f, new Vector3(125f, 50f, 0f));
            offsetAnimation.InsertKeyFrame(.5f, new Vector3(125f, 200f, 0f));
            offsetAnimation.InsertKeyFrame(1f, new Vector3(125f, 50f, 0f));
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(4000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            redSprite.StartAnimation("Offset", offsetAnimation);
        }