using Amphora; using Annulus; using Azimuth; using Blacklight.Core; using Glass.Blacklight; using System; namespace Glass.Testbed { /// /// Text whose tint texture slides along by age, drawn with the tint transform a render callback sets. /// public record ScrollingTintText : BakedTextMaterial { public ScrollingTintText(TextMaterialStyle style, StringView text, Scalar pixelsPerSecond, Scalar textureWidth) : base(style, text) { PixelsPerSecond = pixelsPerSecond; TextureWidth = textureWidth; } public Scalar PixelsPerSecond { get; } /// /// Gets the distance after which the tint texture repeats, which keeps the slide from growing without bound. /// public Scalar TextureWidth { get; } public static void Render(Renderer renderer, Cel context, ScrollingTintText material, Rect rect, in DrawState drawState) { if (rect.Width == 0 || rect.Height == 0 || material.Style.Font == null) { return; } double slide = drawState.Age.TotalSeconds * material.PixelsPerSecond; double width = material.TextureWidth; DrawState scrolled = drawState; scrolled.TintTransform = new AffineMatrix(0, new Vector(slide - Math.Floor(slide / width) * width, 0)); var blacklightRenderer = (BlacklightRenderer)renderer; blacklightRenderer.FontRendererFor(material.Style.Font).Render(context, material, rect, in scrolled); } } }