Example #1
0
        protected override void OnConnected(UIElement newElement)
        {
            element = newElement;

            compositor = ElementCompositionPreview.GetElementVisual(Window.Current.Content).Compositor;
            var spotlight = compositor.CreateSpotLight();
            spotlight.InnerConeAngleInDegrees = 10f;
            spotlight.OuterConeAngleInDegrees = 20f;
            spotlight.InnerConeColor = Colors.FloralWhite;
            spotlight.OuterConeColor = Colors.FloralWhite;
            spotlight.ConstantAttenuation = 0f;
            spotlight.LinearAttenuation = 0f;
            spotlight.QuadraticAttenuation = 0f;
            CompositionLight = spotlight;

            PropSet = compositor.CreatePropertySet();
            PropSet.InsertScalar("OffsetX", 0f);
            PropSet.InsertScalar("OffsetY", 0f);
            PropSet.InsertScalar("OffsetZ", 300f);

            SpotLightOffsetAnimation = compositor.CreateExpressionAnimation("Vector3(PropSet.OffsetX ,PropSet.OffsetY ,PropSet.OffsetZ)");
            SpotLightOffsetAnimation.SetReferenceParameter("PropSet", PropSet);
            CompositionLight.StartAnimation("Offset", SpotLightOffsetAnimation);
            cbEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.42f, 0f), new Vector2(1f, 1f));
            line = compositor.CreateLinearEasingFunction();
            var an = compositor.CreateScalarKeyFrameAnimation();
            an.InsertKeyFrame(0f, 0f, cbEasing);
            an.InsertKeyFrame(1f, 60f, cbEasing);
            an.Duration = TimeSpan.FromSeconds(10);
            an.IterationBehavior = AnimationIterationBehavior.Forever;
        }
Example #2
0
        // Define and setup the Green Square Visual that will be animated
        public void SetupVisual()
        {
            // Intialize the Compositor
            _compositor = new Compositor();
            _root       = ElementCompositionPreview.GetElementVisual(Container);
            _compositor = _root.Compositor;

            _linear = _compositor.CreateLinearEasingFunction();

            // Create Green Square
            var colorVisual = _compositor.CreateSpriteVisual();

            colorVisual.Brush       = _compositor.CreateColorBrush(Colors.Green);
            colorVisual.Size        = new Vector2(150.0f, 150.0f);
            colorVisual.Offset      = new Vector3(250.0f, 50.0f, 0.0f);
            colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
            _target = colorVisual;

            // Create Blue Square
            var colorVisual2 = _compositor.CreateSpriteVisual();

            colorVisual2.Brush     = _compositor.CreateColorBrush(Colors.Aqua);
            colorVisual2.Size      = new Vector2(200.0f, 150.0f);
            colorVisual2.Offset    = new Vector3(25.0f, 50.0f, 0.0f);
            colorVisual2.IsVisible = false;
            _target2 = colorVisual2;

            // Add the Blue and Green square visuals to the tree
            _mainContainer = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(Container, _mainContainer);
            _mainContainer.Children.InsertAtTop(_target);
            _mainContainer.Children.InsertAtTop(_target2);

            // Create Scoped batch for animations
            _batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            // Add Animation1 to the batch
            Animation1(_target);

            // Suspend the batch to exclude an animation
            _batch.Suspend();

            // Exluding Animation2 from batch
            Animation2(_target);

            // Resuming the batch to collect additional animations
            _batch.Resume();

            // Add Animation3 to the batch
            Animation3(_target);

            // Batch is ended an no objects can be added
            _batch.End();

            // Method triggered when batch completion event fires
            _batch.Completed += OnBatchCompleted;
        }
Example #3
0
        private ScalarKeyFrameAnimation CreateCrossFadeAnimation(Compositor compositor)
        {
            ScalarKeyFrameAnimation animation    = compositor.CreateScalarKeyFrameAnimation();
            LinearEasingFunction    linearEasing = compositor.CreateLinearEasingFunction();

            animation.InsertKeyFrame(0.0f, 0.0f, linearEasing);
            animation.InsertKeyFrame(1.0f, 1.0f, linearEasing);
            animation.Duration = TimeSpan.FromMilliseconds(250);
            return(animation);
        }
Example #4
0
        public async void UpdateThumbnail(Compositor _compositor, BitmapImage imgSource)
        {
            this._compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            var tileVisual = ImgGrid.GetVisual();

            tileVisual.CenterPoint  = new Vector3((float)Img.ActualWidth / 2, (float)Img.ActualHeight / 2, 0);
            tileVisual.RotationAxis = new Vector3(0f, 1f, 0f);


            //Flip Fade out animation group
            var fadeoutAnim = _compositor.CreateAnimationGroup();
            ScalarKeyFrameAnimation rotationAnimation = _compositor.CreateScalarKeyFrameAnimation();
            LinearEasingFunction    linear            = _compositor.CreateLinearEasingFunction();

            rotationAnimation.InsertKeyFrame(0f, 0f, linear);
            rotationAnimation.InsertKeyFrame(1f, 90f, linear);
            rotationAnimation.Duration = TimeSpan.FromMilliseconds(400);
            rotationAnimation.Target   = "RotationAngleInDegrees";
            ScalarKeyFrameAnimation opacityAnimation = _compositor.CreateScalarKeyFrameAnimation();

            opacityAnimation.InsertKeyFrame(1f, 0);
            opacityAnimation.Duration  = TimeSpan.FromMilliseconds(200);
            opacityAnimation.DelayTime = TimeSpan.FromMilliseconds(250);
            opacityAnimation.Target    = "Opacity";
            fadeoutAnim.Add(rotationAnimation);
            fadeoutAnim.Add(opacityAnimation);

            tileVisual.StartAnimationGroup(fadeoutAnim);

            await Task.Delay(500);

            Thumbnail = imgSource;


            tileVisual.StopAnimationGroup(fadeoutAnim);
            var fadeInAnim = _compositor.CreateAnimationGroup();

            ScalarKeyFrameAnimation rotationAnim = _compositor.CreateScalarKeyFrameAnimation();

            rotationAnim.InsertKeyFrame(0f, 270, linear);
            rotationAnim.InsertKeyFrame(1f, 360, linear);
            rotationAnim.Duration  = TimeSpan.FromMilliseconds(550);
            rotationAnim.DelayTime = TimeSpan.FromMilliseconds(200);
            rotationAnim.Target    = "RotationAngleInDegrees";
            ScalarKeyFrameAnimation opacityAnim2 = _compositor.CreateScalarKeyFrameAnimation();

            opacityAnim2.InsertKeyFrame(0f, 0f);
            opacityAnim2.InsertKeyFrame(1f, 1f);
            opacityAnim2.Duration  = TimeSpan.FromMilliseconds(600);
            opacityAnim2.DelayTime = TimeSpan.FromMilliseconds(250);
            opacityAnim2.Target    = "Opacity";
            fadeoutAnim.Add(rotationAnim);
            fadeoutAnim.Add(opacityAnim2);
            tileVisual.StartAnimationGroup(fadeoutAnim);
        }
Example #5
0
        // Define and setup the Green Square Visual that will be animated 
        public void SetupVisual()
        {
            // Intialize the Compositor
            _compositor = new Compositor();
            _root = (ContainerVisual)ElementCompositionPreview.GetElementVisual(Container);
            _compositor = _root.Compositor;

            _linear = _compositor.CreateLinearEasingFunction();

            // Create Green Square
            var colorVisual = _compositor.CreateSpriteVisual();
            colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
            colorVisual.Size = new Vector2(150.0f, 150.0f);
            colorVisual.Offset = new Vector3(250.0f, 50.0f, 0.0f);
            colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
            _target = colorVisual;

            // Create Blue Square
            var colorVisual2 = _compositor.CreateSpriteVisual();
            colorVisual2.Brush = _compositor.CreateColorBrush(Colors.Aqua);
            colorVisual2.Size = new Vector2(200.0f, 150.0f);
            colorVisual2.Offset = new Vector3(25.0f, 50.0f, 0.0f);
            colorVisual2.IsVisible = false; 
            _target2 = colorVisual2;

            // Add the Blue and Green square visuals to the tree
            _mainContainer = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(Container, _mainContainer);
            _mainContainer.Children.InsertAtTop(_target);
            _mainContainer.Children.InsertAtTop(_target2);

            // Create Scoped batch for animations
            _batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            // Add Animation1 to the batch
            Animation1(_target);

            // Suspend the batch to exclude an animation
            _batch.Suspend();

            // Exluding Animation2 from batch
            Animation2(_target);

            // Resuming the batch to collect additional animations
            _batch.Resume();

            // Add Animation3 to the batch
            Animation3(_target);

            // Batch is ended an no objects can be added
            _batch.End();

            // Method triggered when batch completion event fires
            _batch.Completed += OnBatchCompleted;
        }
        internal CompositionObjectFactory(Compositor compositor)
        {
            _compositor = compositor;

            // Initialize singletons.
            _linearEasingFunction   = _compositor.CreateLinearEasingFunction();
            _holdStepEasingFunction = _compositor.CreateStepEasingFunction(1);
            _holdStepEasingFunction.IsFinalStepSingleFrame = true;
            _jumpStepEasingFunction = _compositor.CreateStepEasingFunction(1);
            _jumpStepEasingFunction.IsInitialStepSingleFrame = true;
        }
Example #7
0
        LinearEasingFunction GetLinearEasingFunction(LinearEasingFunction obj)
        {
            if (GetExisting(obj, out LinearEasingFunction result))
            {
                return(result);
            }

            result = CacheAndInitializeCompositionObject(obj, _c.CreateLinearEasingFunction());
            StartAnimationsAndFreeze(obj, result);
            return(result);
        }
Example #8
0
        XElement FromLinearEasingFunction(LinearEasingFunction obj)
        {
            return(new XElement(GetCompositionObjectName(obj), GetContents()));

            IEnumerable <XObject> GetContents()
            {
                foreach (var item in GetCompositionObjectContents(obj))
                {
                    yield return(item);
                }
            }
        }
        private void SamplePage_Loaded(object sender, RoutedEventArgs e)
        {
            //
            // Example 1 - Animate a visual's Z position towards the vanishing point, away from the
            //             view position.
            //

            Visual     visual     = ElementCompositionPreview.GetElementVisual(TextBlock1);
            Compositor compositor = visual.Compositor;

            // Animate the Z offset towards the vanishing point and back again
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0.0f, new Vector3(0, 0, 0));
            offsetAnimation.InsertKeyFrame(0.5f, new Vector3(0, 0, -2000));
            offsetAnimation.InsertKeyFrame(1.0f, new Vector3(0, 0, 0));
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(8000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            visual.StartAnimation("Offset", offsetAnimation);


            //
            // Example 2 - Rotate a rectangular image with perspective applied.
            //

            visual = ElementCompositionPreview.GetElementVisual(RotatedImage);

            // Rotate around the center
            visual.Size        = new Vector2((float)RotatedImage.Width / 2, (float)RotatedImage.Height / 2);
            visual.CenterPoint = new Vector3(visual.Size.X, visual.Size.Y, 0f);

            // Rotate around the Y-axis
            visual.RotationAxis = new Vector3(0, 1, 0);

            // Start the rotation animation
            LinearEasingFunction    linear            = compositor.CreateLinearEasingFunction();
            ScalarKeyFrameAnimation rotationAnimation = compositor.CreateScalarKeyFrameAnimation();

            rotationAnimation.InsertKeyFrame(0, 0, linear);
            rotationAnimation.InsertKeyFrame(1, 360f, linear);
            rotationAnimation.Duration          = TimeSpan.FromMilliseconds(8000);
            rotationAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            visual.StartAnimation("RotationAngleInDegrees", rotationAnimation);

            // Animate up and down to show differences in perspective relative to the vanishing point.
            offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            offsetAnimation.InsertKeyFrame(0.0f, new Vector3(0, 0, -200f));
            offsetAnimation.InsertKeyFrame(0.5f, new Vector3(0, 300f, -200f));
            offsetAnimation.InsertKeyFrame(1.0f, new Vector3(0, 0, -200f));
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(8000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            visual.StartAnimation("Offset", offsetAnimation);
        }
Example #10
0
        public void StartEntranceEffect()
        {
            ContainerVisual container  = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage);
            Compositor      compositor = container.Compositor;

            // 设置缩放和动画
            const float               ScaleFactor = 20f;
            TimeSpan                  duration    = TimeSpan.FromMilliseconds(1200);
            LinearEasingFunction      linearEase  = compositor.CreateLinearEasingFunction();
            CubicBezierEasingFunction easeInOut   = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f));

            // 创建淡出动画
            ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation();

            fadeOutAnimation.InsertKeyFrame(1, 0);
            fadeOutAnimation.Duration = duration;

            // Grid的动画
            Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
            scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1));
            scaleUpGridAnimation.Duration = duration;

            // 初始屏动画
            Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
            scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
            scaleUpSplashAnimation.Duration = duration;

            // 设置Grid的中心缩放视觉
            Visual gridVisual = ElementCompositionPreview.GetElementVisual(UIToShow);

            gridVisual.Size        = UIToShow.ActualSize;
            gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f;

            // 创建一个视觉组,当改组所有视觉执行完后不再显示
            CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            container.StartAnimation("Opacity", fadeOutAnimation);
            container.StartAnimation("Scale.XY", scaleUpSplashAnimation);
            gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation);

            batch.Completed += (s, a) =>
            {
                ElementCompositionPreview.SetElementChildVisual(BasePage, null);
                SurfaceLoader.Uninitialize();
                AnimationCompleted?.Invoke(this, null);
            };
            batch.End();
        }
Example #11
0
        private void HideCustomSplashScreen()
        {
            ContainerVisual container  = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(this);
            Compositor      compositor = container.Compositor;

            // Setup some constants for scaling and animating
            const float               ScaleFactor = 20f;
            TimeSpan                  duration    = TimeSpan.FromMilliseconds(1200);
            LinearEasingFunction      linearEase  = compositor.CreateLinearEasingFunction();
            CubicBezierEasingFunction easeInOut   = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f));

            // Create the fade animation which will target the opacity of the outgoing splash screen
            ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation();

            fadeOutAnimation.InsertKeyFrame(1, 0);
            fadeOutAnimation.Duration = duration;

            // Create the scale up animation for the grid
            Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
            scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1));
            scaleUpGridAnimation.Duration = duration;

            // Create the scale up animation for the Splash screen visuals
            Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
            scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
            scaleUpSplashAnimation.Duration = duration;

            // Configure the grid visual to scale from the center
            Visual gridVisual = ElementCompositionPreview.GetElementVisual(MainFrame);

            gridVisual.Size        = new Vector2((float)MainFrame.ActualWidth, (float)MainFrame.ActualHeight);
            gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f;


            //
            // Create a scoped batch for the animations.  When the batch completes, we can dispose of the
            // splash screen visuals which will no longer be visible.
            //

            CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            container.StartAnimation("Opacity", fadeOutAnimation);
            container.StartAnimation("Scale.XY", scaleUpSplashAnimation);
            gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation);

            batch.Completed += Batch_Completed;
            batch.End();
        }
Example #12
0
        internal CompositionObjectFactory(TranslationContext context, Compositor compositor, uint targetUapVersion)
        {
            _context          = context;
            _compositor       = compositor;
            _targetUapVersion = targetUapVersion;

            // Initialize singletons.
            _linearEasingFunction   = _compositor.CreateLinearEasingFunction();
            _holdStepEasingFunction = _compositor.CreateStepEasingFunction(1);
            _holdStepEasingFunction.IsFinalStepSingleFrame = true;
            _jumpStepEasingFunction = _compositor.CreateStepEasingFunction(1);
            _jumpStepEasingFunction.IsInitialStepSingleFrame = true;
        }
        private void MainPanel_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            Visual     visual     = ElementCompositionPreview.GetElementVisual(CaptionTile);
            Compositor compositor = visual.Compositor;

            visual.Size = new Vector2((float)CaptionTile.Width / 2, (float)CaptionTile.Height / 2);

            // Rotate around the X-axis
            visual.RotationAxis = new Vector3(1, 0, 0);

            // Start the rotation animation
            LinearEasingFunction    linear            = compositor.CreateLinearEasingFunction();
            ScalarKeyFrameAnimation rotationAnimation = compositor.CreateScalarKeyFrameAnimation();

            if (!IsFlipped) // default
            {
                rotationAnimation.InsertKeyFrame(0, 0, linear);
                rotationAnimation.InsertKeyFrame(1, 250f, linear); // flip over
            }
            else
            {
                rotationAnimation.InsertKeyFrame(0, 250f, linear);
                rotationAnimation.InsertKeyFrame(1, 0f, linear);   // flip back
            }
            rotationAnimation.Duration = TimeSpan.FromMilliseconds(800);

            var transaction = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            transaction.Completed += Animation_Completed;

            // we want the CaptionTile visible as it flips back
            if (IsFlipped)
            {
                CaptionTile.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            visual.StartAnimation("RotationAngleInDegrees", rotationAnimation);

            transaction.End();
        }
Example #14
0
        private void CreateTextAndBlendEffect(Vector2 sizeLightBounds)
        {
            //
            // Crete the effect graph, doing a hard light blend of the text over the
            // content already drawn into the backbuffer
            //

            IGraphicsEffect graphicsEffect = new BlendEffect()
            {
                Mode       = BlendEffectMode.HardLight,
                Foreground = new CompositionEffectSourceParameter("Text"),
                Background = new CompositionEffectSourceParameter("Destination"),
            };

            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
            CompositionEffectBrush   brush         = effectFactory.CreateBrush();

            // Bind the destination brush
            brush.SetSourceParameter("Destination", _compositor.CreateBackdropBrush());


            //
            // Create the text surface which we'll scroll over the image with the lighting effect
            //

            // Pick a nice size font depending on target size
            const float maxFontSize = 72;
            const float scaleFactor = 12;
            float       fontSize    = Math.Min(sizeLightBounds.X / scaleFactor, maxFontSize);

            // Create the text format description, then the surface
            CanvasTextFormat textFormat = new CanvasTextFormat
            {
                FontFamily          = "Segoe UI",
                FontSize            = fontSize,
                FontWeight          = FontWeights.Bold,
                WordWrapping        = CanvasWordWrapping.WholeWord,
                HorizontalAlignment = CanvasHorizontalAlignment.Center,
                VerticalAlignment   = CanvasVerticalAlignment.Center
            };

            string text = "Ein bisschen Frieden, ein bisschen Sonne\n" +
                          "für diese Erde, auf der wir wohnen\n" +
                          "Ein bisschen Frieden, ein bisschen Freude\n" +
                          "ein bisschen Wärme, das wünsch' ich mir\n" +
                          "Ein bisschen Frieden, ein bisschen Träumen\n" +
                          "und dass die Menschen nicht so oft weinen\n" +
                          "Ein bisschen Frieden, ein bisschen Liebe\n" +
                          "dass ich die Hoffnung nie mehr verlier";

            // Make the surface twice the height to give us room to scroll
            Vector2        surfaceSize = new Vector2(sizeLightBounds.X, 2f * sizeLightBounds.Y);
            ManagedSurface textSurface = ImageLoader.Instance.LoadText(text, surfaceSize.ToSize(),
                                                                       textFormat, Colors.White, Colors.Transparent);

            brush.SetSourceParameter("Text", textSurface.Brush);

            // Create the sprite and parent it to the panel with the clip
            _textSprite       = _compositor.CreateSpriteVisual();
            _textSprite.Size  = surfaceSize;
            _textSprite.Brush = brush;

            ElementCompositionPreview.SetElementChildVisual(MyPanel, _textSprite);

            // Lastly, setup the slow scrolling animation of the text
            LinearEasingFunction     linear          = _compositor.CreateLinearEasingFunction();
            Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0f, new Vector3(0, 0, 0), linear);
            offsetAnimation.InsertKeyFrame(1f, new Vector3(0, -_textSprite.Size.Y * .5f, 0), linear);
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(30000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            _textSprite.StartAnimation("Offset", offsetAnimation);
        }
Example #15
0
        private void CreateTextAndBlendEffect(Vector2 sizeLightBounds)
        {
            //
            // Crete the effect graph, doing a hard light blend of the text over the
            // content already drawn into the backbuffer
            //

            IGraphicsEffect graphicsEffect = new BlendEffect()
            {
                Mode       = BlendEffectMode.HardLight,
                Foreground = new CompositionEffectSourceParameter("Text"),
                Background = new CompositionEffectSourceParameter("Destination"),
            };

            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
            CompositionEffectBrush   brush         = effectFactory.CreateBrush();

            // Bind the destination brush
            brush.SetSourceParameter("Destination", _compositor.CreateBackdropBrush());


            //
            // Create the text surface which we'll scroll over the image with the lighting effect
            //

            // Pick a nice size font depending on target size
            const float maxFontSize = 72;
            const float scaleFactor = 12;
            float       fontSize    = Math.Min(sizeLightBounds.X / scaleFactor, maxFontSize);

            // Create the text format description, then the surface
            CanvasTextFormat textFormat = new CanvasTextFormat
            {
                FontFamily          = "Segoe UI",
                FontSize            = fontSize,
                FontWeight          = FontWeights.Bold,
                WordWrapping        = CanvasWordWrapping.WholeWord,
                HorizontalAlignment = CanvasHorizontalAlignment.Center,
                VerticalAlignment   = CanvasVerticalAlignment.Center
            };

            string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec efficitur, eros sit amet laoreet scelerisque, " +
                          "nunc odio ultricies metus, ut consectetur nulla massa eu nibh.Phasellus in lorem id nunc euismod tempus.Phasellus et nulla non turpis tempor blandit ut eget turpis." +
                          "Phasellus ac ornare elit, ut scelerisque dolor. Nam vel finibus lorem. Aenean malesuada pulvinar eros id ornare. Fusce blandit ante eget dolor efficitur suscipit." +
                          "Phasellus ac lacus nibh. Aenean eget blandit risus, in lacinia mi. Proin fermentum ante eros, non sollicitudin mi pretium eu. Curabitur suscipit lectus arcu, eget" +
                          "pretium quam sagittis non. Mauris purus mauris, condimentum nec laoreet sit amet, imperdiet sit amet nisi. Sed interdum, urna et aliquam porta, elit velit tincidunt orci," +
                          "vitae vestibulum risus lacus at nulla.Phasellus sapien ipsum, pellentesque varius enim nec, iaculis aliquet enim. Nulla id dapibus ante. Sed hendrerit sagittis leo, commodo" +
                          "fringilla ligula rutrum ut. Nullam sodales, ex ut pellentesque scelerisque, sapien nulla mattis lectus, vel ullamcorper leo enim ac mi.Sed consectetur vitae velit in consequat." +
                          "Pellentesque ac condimentum justo, at feugiat nulla. Sed ut congue neque. Nam gravida quam ac urna porttitor, ut bibendum ante mattis.Cras viverra cursus sapien, et sollicitudin" +
                          "risus fringilla eget. Nulla facilisi. Duis pellentesque scelerisque nisi, facilisis malesuada massa gravida et. Vestibulum ac leo sed orci tincidunt feugiat.Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc id leo vestibulum, vulputate ipsum sit amet, scelerisque velit. Curabitur imperdiet justo et tortor dignissim, sit amet volutpat sem ullamcorper. Nam mollis ullamcorper tellus vitae convallis. Aliquam eleifend elit nec tincidunt pharetra. Aliquam turpis eros, mollis et nunc quis, porta molestie justo. Etiam ultrices sem non turpis imperdiet dictum.Aliquam molestie elit in urna sodales, nec luctus dui laoreet.Curabitur molestie risus vel ligula efficitur, non fringilla urna iaculis.Curabitur neque tortor, facilisis quis dictum facilisis, facilisis et ante. Sed nisl erat, semper vitae efficitur ut, congue vitae quam. Ut auctor lacus sit amet varius placerat.Sed ac tellus tempus, ultricies est quis, tempor felis.Nulla vel faucibus elit, eu tincidunt eros. Nulla blandit id nisl ut porta. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam suscipit tellus a mattis pulvinar. Sed et libero vel ligula elementum suscipit.Ut elementum libero at sagittis pharetra. Fusce ultrices odio sapien, a posuere est consectetur ut.";

            // Make the surface twice the height to give us room to scroll
            Vector2 surfaceSize = new Vector2(sizeLightBounds.X, 2f * sizeLightBounds.Y);
            CompositionDrawingSurface textSurface = SurfaceLoader.LoadText(text, surfaceSize.ToSize(),
                                                                           textFormat, Colors.White, Colors.Transparent);

            brush.SetSourceParameter("Text", _compositor.CreateSurfaceBrush(textSurface));

            // Create the sprite and parent it to the panel with the clip
            _textSprite       = _compositor.CreateSpriteVisual();
            _textSprite.Size  = surfaceSize;
            _textSprite.Brush = brush;

            ElementCompositionPreview.SetElementChildVisual(MyPanel, _textSprite);

            // Lastly, setup the slow scrolling animation of the text
            LinearEasingFunction     linear          = _compositor.CreateLinearEasingFunction();
            Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0f, new Vector3(0, 0, 0), linear);
            offsetAnimation.InsertKeyFrame(1f, new Vector3(0, -_textSprite.Size.Y * .5f, 0), linear);
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(30000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            _textSprite.StartAnimation("Offset", offsetAnimation);
        }
Example #16
0
        private async void CreateImageAndLights(Vector2 sizeLightBounds)
        {
            //
            // Image and effect setup
            //

            // Create the effect graph.  We will combine the desaturated image with two diffuse lights
            IGraphicsEffect graphicsEffect = new CompositeEffect()
            {
                Mode    = Microsoft.Graphics.Canvas.CanvasComposite.Add,
                Sources =
                {
                    new SaturationEffect()
                    {
                        Saturation = 0,
                        Source     = new CompositionEffectSourceParameter("ImageSource")
                    },

                    new PointDiffuseEffect()
                    {
                        Name          = "Light1",
                        DiffuseAmount = 1f,
                        Source        = new CompositionEffectSourceParameter("NormalMap"),
                    },

                    new PointDiffuseEffect()
                    {
                        Name          = "Light2",
                        DiffuseAmount = 1f,
                        Source        = new CompositionEffectSourceParameter("NormalMap"),
                    },
                }
            };

            // Create the normal map.  For this sample, we want a flat surface with no bumps
            CompositionDrawingSurface normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK Insider/NowPlaying/NormalMap.jpg"));

            CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(normalMap);

            surfaceBrush.Stretch = CompositionStretch.Fill;

            // Create the effect factory, we're going to animate the light positions and colors
            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                                     new[] { "Light1.LightPosition", "Light1.LightColor",
                                                                                             "Light2.LightPosition", "Light2.LightColor", });

            // Create the effect brush and bind the normal map
            CompositionEffectBrush brush = effectFactory.CreateBrush();

            brush.SetSourceParameter("NormalMap", surfaceBrush);

            // Update the CompositionImage to use the custom effect brush
            ArtistImage.Brush = brush;


            //
            //  Animation setup
            //

            // Setup the first light's position, top and to the left in general
            LinearEasingFunction     linear            = _compositor.CreateLinearEasingFunction();
            Vector3KeyFrameAnimation positionAnimation = _compositor.CreateVector3KeyFrameAnimation();

            positionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 300f), linear);
            positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 100f), linear);
            positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .25f, sizeLightBounds.Y * .95f, 100f), linear);
            positionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 300f), linear);
            positionAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light1.LightPosition", positionAnimation);


            // Setup the first light's color animation, cycling through some brighter tones
            ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation();

            colorAnimation.InsertKeyFrame(0f, Colors.Orange);
            colorAnimation.InsertKeyFrame(.2f, Colors.Orange);
            colorAnimation.InsertKeyFrame(.3f, Colors.Red);
            colorAnimation.InsertKeyFrame(.5f, Colors.Red);
            colorAnimation.InsertKeyFrame(.6f, Colors.Yellow);
            colorAnimation.InsertKeyFrame(.8f, Colors.Yellow);
            colorAnimation.InsertKeyFrame(.9f, Colors.Orange);
            colorAnimation.InsertKeyFrame(1f, Colors.Orange);
            colorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light1.LightColor", colorAnimation);


            // Setup the second light's position, down and to the right in general
            positionAnimation = _compositor.CreateVector3KeyFrameAnimation();
            positionAnimation.InsertKeyFrame(0f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear);
            positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .7f, sizeLightBounds.Y * .9f, 300f), linear);
            positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .95f, sizeLightBounds.Y * .95f, 100f), linear);
            positionAnimation.InsertKeyFrame(1f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear);
            positionAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light2.LightPosition", positionAnimation);

            // Setup the second light's color animation, cycling through some darker tones
            colorAnimation = _compositor.CreateColorKeyFrameAnimation();
            colorAnimation.InsertKeyFrame(0f, Colors.Blue);
            colorAnimation.InsertKeyFrame(.2f, Colors.Blue);
            colorAnimation.InsertKeyFrame(.3f, Colors.DarkGreen);
            colorAnimation.InsertKeyFrame(.5f, Colors.DarkGreen);
            colorAnimation.InsertKeyFrame(.6f, Colors.DarkBlue);
            colorAnimation.InsertKeyFrame(.8f, Colors.DarkBlue);
            colorAnimation.InsertKeyFrame(.9f, Colors.Blue);
            colorAnimation.InsertKeyFrame(1f, Colors.Blue);
            colorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light2.LightColor", colorAnimation);
        }
Example #17
0
        private void CreateImageAndLights(Vector2 sizeLightBounds)
        {
            //
            // Image and effect setup
            //

            // Create the effect graph.  We will combine the desaturated image with two diffuse lights
            IGraphicsEffect graphicsEffect = new CompositeEffect()
            {
                Mode    = Microsoft.Graphics.Canvas.CanvasComposite.Add,
                Sources =
                {
                    new SaturationEffect()
                    {
                        Saturation = 0,
                        Source     = new CompositionEffectSourceParameter("ImageSource")
                    },

                    new PointDiffuseEffect()
                    {
                        Name          = "Light1",
                        DiffuseAmount = 1f,
                    },

                    new PointDiffuseEffect()
                    {
                        Name          = "Light2",
                        DiffuseAmount = 1f,
                    },
                }
            };

            // Create the effect factory, we're going to animate the light positions and colors
            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                                     new[] { "Light1.LightPosition", "Light1.LightColor",
                                                                                             "Light2.LightPosition", "Light2.LightColor", });

            // Create the effect brush and bind the normal map
            CompositionEffectBrush brush = effectFactory.CreateBrush();

            // Update the CompositionImage to use the custom effect brush
            ArtistImage.Brush = brush;


            //
            //  Animation setup
            //

            // Setup the first light's position, top and to the left in general
            LinearEasingFunction     linear            = _compositor.CreateLinearEasingFunction();
            Vector3KeyFrameAnimation positionAnimation = _compositor.CreateVector3KeyFrameAnimation();

            positionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 300f), linear);
            positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 100f), linear);
            positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .25f, sizeLightBounds.Y * .95f, 100f), linear);
            positionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 300f), linear);
            positionAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light1.LightPosition", positionAnimation);


            // Setup the first light's color animation, cycling through some brighter tones
            ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation();

            colorAnimation.InsertKeyFrame(0f, Colors.MidnightBlue);
            colorAnimation.InsertKeyFrame(.2f, Colors.Indigo);
            colorAnimation.InsertKeyFrame(.3f, Colors.RoyalBlue);
            colorAnimation.InsertKeyFrame(.5f, Colors.CornflowerBlue);
            colorAnimation.InsertKeyFrame(.6f, Colors.Thistle);
            colorAnimation.InsertKeyFrame(.8f, Colors.CornflowerBlue);
            colorAnimation.InsertKeyFrame(.9f, Colors.RoyalBlue);
            colorAnimation.InsertKeyFrame(1f, Colors.Indigo);
            colorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light1.LightColor", colorAnimation);


            // Setup the second light's position, down and to the right in general
            positionAnimation = _compositor.CreateVector3KeyFrameAnimation();
            positionAnimation.InsertKeyFrame(0f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear);
            positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .7f, sizeLightBounds.Y * .9f, 300f), linear);
            positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .95f, sizeLightBounds.Y * .95f, 100f), linear);
            positionAnimation.InsertKeyFrame(1f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear);
            positionAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light2.LightPosition", positionAnimation);

            // Setup the second light's color animation, cycling through some darker tones
            colorAnimation = _compositor.CreateColorKeyFrameAnimation();
            colorAnimation.InsertKeyFrame(0f, Colors.Firebrick);
            colorAnimation.InsertKeyFrame(.2f, Colors.DarkGoldenrod);
            colorAnimation.InsertKeyFrame(.3f, Colors.Chartreuse);
            colorAnimation.InsertKeyFrame(.5f, Colors.ForestGreen);
            colorAnimation.InsertKeyFrame(.6f, Colors.DarkTurquoise);
            colorAnimation.InsertKeyFrame(.8f, Colors.MidnightBlue);
            colorAnimation.InsertKeyFrame(.9f, Colors.DarkViolet);
            colorAnimation.InsertKeyFrame(1f, Colors.DarkSlateGray);
            colorAnimation.Duration          = TimeSpan.FromMilliseconds(20000);
            colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            brush.StartAnimation("Light2.LightColor", colorAnimation);
        }
Example #18
0
 LinearEasingFunction LinearEasingFunction()
 {
     return(_linearEasingFunction = _c.CreateLinearEasingFunction());
 }