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.CreateCircleSurface(200, Colors.White); // 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; }
public void Initialize(UIElement host, CompositionImage sourceElement, object payload) { _host = host; _parent = host; _payload = payload; // Make a copy of the sourceElement's sprite so we can hand it off to the next page SpriteVisual sourceSprite = sourceElement.SpriteVisual; Compositor compositor = sourceSprite.Compositor; _sprite = compositor.CreateSpriteVisual(); _sprite.Size = sourceSprite.Size; _sprite.Brush = sourceElement.SurfaceBrush; // We're going to use the backing surface, make sure it doesn't get released sourceElement.SharedSurface = true; // Determine the offset from the host to the source element used in the transition GeneralTransform coordinate = sourceElement.TransformToVisual(_parent); Point position = coordinate.TransformPoint(new Point(0, 0)); // Set the sprite to that offset relative to the host _sprite.Offset = new Vector3((float)position.X, (float)position.Y, 0); // Set the sprite as the content under the host ElementCompositionPreview.SetElementChildVisual(_parent, _sprite); }
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 SetImageEffect(CompositionImage image) { // Create the effect brush and bind the normal map CompositionEffectBrush brush = _effectFactory.CreateBrush(); ComboBoxItem item = LightingSelection.SelectedValue as ComboBoxItem; switch ((LightingTypes)item.Tag) { case LightingTypes.SpotLightSpecular: case LightingTypes.PointSpecular: case LightingTypes.DistantDiffuse: case LightingTypes.DistantSpecular: brush.SetSourceParameter("NormalMap", _circleNormalsBrush); break; default: brush.SetSourceParameter("NormalMap", _flatNormalsBrush); break; } // Update the CompositionImage to use the custom effect brush image.Brush = brush; }
public void Start(UIElement newParent, CompositionImage targetImage, ScrollViewer scrollViewer, UIElement animationTarget) { Visual transitionVisual = ElementCompositionPreview.GetElementChildVisual(_parent); ElementCompositionPreview.SetElementChildVisual(_parent, null); // // We need to reparent the transition visual under the new parent. This is important to ensure // it's propertly clipped, etc. // GeneralTransform coordinate = newParent.TransformToVisual(_parent); Point position = coordinate.TransformPoint(new Point(0, 0)); Vector3 currentOffset = transitionVisual.Offset; currentOffset.X -= (float)position.X; currentOffset.Y -= (float)position.Y; transitionVisual.Offset = currentOffset; _parent = newParent; _targetImage = targetImage; // Move the transition visual to it's new parent ElementCompositionPreview.SetElementChildVisual(_parent, transitionVisual); // Hide the target Image now since the handoff visual is still transitioning targetImage.Opacity = 0f; // Load image if necessary _imageLoaded = targetImage.IsContentLoaded; if (!_imageLoaded) { targetImage.ImageOpened += CompositionImage_ImageOpened; } // // Create a scoped batch around the animations. When the batch completes, we know the animations // have finished and we can cleanup the transition related objects. // Compositor compositor = transitionVisual.Compositor; _scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); // // Determine the offset between the parent and the target UIElement. This will be used to calculate the // target position we are animating to. // coordinate = targetImage.TransformToVisual(_parent); position = coordinate.TransformPoint(new Point(0, 0)); TimeSpan totalDuration = TimeSpan.FromMilliseconds(1000); Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); if (scrollViewer != null) { CompositionPropertySet scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); // Include the scroller offset as that is a factor position.X += scrollViewer.HorizontalOffset; position.Y += scrollViewer.VerticalOffset; // // Since the target position is relative to the target UIElement which can move, we need to construct // an expression to bind the target's position to the end position of our animation. // string expression = "Vector3(scrollingProperties.Translation.X, scrollingProperties.Translation.Y, 0) + itemOffset"; offsetAnimation.InsertExpressionKeyFrame(1f, expression); offsetAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); offsetAnimation.SetVector3Parameter("itemOffset", new Vector3((float)position.X, (float)position.Y, 0)); offsetAnimation.Duration = totalDuration; } else { offsetAnimation.InsertKeyFrame(1, new Vector3((float)position.X, (float)position.Y, 0)); offsetAnimation.Duration = totalDuration; } // Create size animation to change size of the visual Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation(); sizeAnimation.InsertKeyFrame(1f, new Vector2((float)targetImage.ActualWidth, (float)targetImage.ActualHeight)); sizeAnimation.Duration = totalDuration; // Create the fade in animation for the other page content if (animationTarget != null) { Visual fadeVisual = ElementCompositionPreview.GetElementVisual(animationTarget); ScalarKeyFrameAnimation fadeIn = compositor.CreateScalarKeyFrameAnimation(); fadeIn.InsertKeyFrame(0f, 0.0f); fadeIn.InsertKeyFrame(1f, 1.0f); fadeIn.Duration = totalDuration; fadeVisual.StartAnimation("Opacity", fadeIn); } //Start Animations _sprite.StartAnimation("Size", sizeAnimation); _sprite.StartAnimation("Offset", offsetAnimation); //Scoped batch completed event _scopeBatch.Completed += ScopeBatch_Completed; _scopeBatch.End(); // Clear the flag _animationCompleted = false; }
private void Complete(bool forceComplete) { // If we're forcing completion, make sure the scope batch is cleaned up if (forceComplete && (_scopeBatch != null)) { CleanupScopeBatch(); } // If we've completed the transition or we're forcing completion, cleanup if (forceComplete || (_imageLoaded && _animationCompleted)) { _sprite = null; // Clear the sprite from the UIElement ElementCompositionPreview.SetElementChildVisual(_parent, null); // Clean up the image and show it if (_targetImage != null) { _targetImage.ImageOpened -= CompositionImage_ImageOpened; _targetImage.Opacity = 1f; _targetImage = null; } } }
private async void ApplyEffect(CompositionImage image) { Task<CompositionDrawingSurface> task = null; // If we've requested a load time effect input, kick it off now if (_currentTechnique.LoadTimeEffectHandler != null) { task = SurfaceLoader.LoadFromUri(image.Source, Size.Empty, _currentTechnique.LoadTimeEffectHandler); } // Create the new brush, set the inputs and set it on the image CompositionEffectBrush brush = _currentTechnique.CreateBrush(); brush.SetSourceParameter("ImageSource", image.SurfaceBrush); image.Brush = brush; // If we've got an active task, wait for it to finish if (task != null) { CompositionDrawingSurface effectSurface = await task; // Set the effect surface as input brush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(effectSurface)); } }
public override void OnPointerExit(Vector2 pointerPosition, CompositionImage image) { _propertySet.StartAnimation("Translate", _exitAnimation); _propertySet.StopAnimation("Scale"); }
public override void OnPointerMoved(Vector2 pointerPosition, CompositionImage image) { Vector2 positionNormalized = new Vector2((pointerPosition.X / (float)image.Width) - .5f, (pointerPosition.Y / (float)image.Height) - .5f); _propertySet.InsertVector2("Translate", positionNormalized); }
public virtual void OnPointerMoved(Vector2 pointerPosition, CompositionImage image) { }
public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image) { _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertScalar("Scale", 1f); Vector2 positionNormalized = new Vector2((pointerPosition.X / (float)image.Width) - .5f, (pointerPosition.Y / (float)image.Height) - .5f); _propertySet.InsertVector2("Translate", positionNormalized); _propertySet.InsertVector2("CenterPointOffset", new Vector2(128, 128)); _transformExpression.SetReferenceParameter("props", _propertySet); image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression); _propertySet.StartAnimation("Scale", _enterAnimation); }
public abstract void OnPointerExit(Vector2 pointerPosition, CompositionImage image);
public override void OnPointerExit(Vector2 pointerPosition, CompositionImage image) { _propertySet.StartAnimation("Rotation", _exitAnimation); }
public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image) { _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertScalar("Scale", 1.25f); _propertySet.InsertScalar("Rotation", 0f); _propertySet.InsertVector2("Translate", new Vector2(0f, 0f)); _propertySet.InsertVector2("CenterPointOffset", new Vector2((float)_lightMap.Size.Width / 2f, 0f)); _transformExpression.SetReferenceParameter("props", _propertySet); image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression); _propertySet.StartAnimation("Rotation", _enterAnimation); }
public override void OnPointerExit(Vector2 pointerPosition, CompositionImage image) { image.Brush.StartAnimation("Arithmetic.Source1Amount", _animationIncreasing); image.Brush.StartAnimation("Arithmetic.Source2Amount", _animationDecreasing); }
public override void OnPointerExit(Vector2 pointerPosition, CompositionImage image) { image.Brush.StartAnimation(_targetProperty, _exitAnimation); }