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); }
async private void LoadImages() { int loadedImageCount = 0; // Create the loader _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); // // Populate/load our unique list of image textures. // for (int i = 0; i < (int)NamedImage.Count; i++) { var name = (NamedImage)i; Uri uri = new Uri($"ms-appx:///Assets/Photos/{name.ToString()}.jpg"); _managedSurfaces[i] = _imageLoader.CreateManagedSurfaceFromUri(uri); var surface = await _imageLoader.LoadImageFromUriAsync(uri); _imageBrushes[i] = _compositor.CreateSurfaceBrush(surface); loadedImageCount++; } // // Populate/load our unique list of "text" image textures. // _textBrushes = new CompositionSurfaceBrush[_textNodes.Length]; for (int i = 0; i < _textNodes.Length; i++) { var textNode = _textNodes[i]; var textSurface = SurfaceLoader.LoadText(textNode.Text, new Size(textNode.TextureSize.X, textNode.TextureSize.Y), textNode.TextFormat, Colors.Black, Colors.Transparent); _textBrushes[i] = _compositor.CreateSurfaceBrush(textSurface); // // Remember the index of the brush so that we can refer to it later. // textNode.BrushIndex = i; loadedImageCount++; } // // Once we've loaded all of the images, we can continue populating the world. // if (loadedImageCount == _imageBrushes.Length + _textBrushes.Length) { PopulateWorld(); } }