using System; using System.Drawing; using Blacklight.Core; using Glass; using Glass.Blacklight; using Prism; using Prism.Glass; namespace Konis.Testbed { /// /// A texture one pixel tall that shows a gradient, with the material that draws it. /// public class GradientBar { private readonly WindowHandle window; private readonly Texture texture; private readonly byte[] pixels; private readonly int length; /// /// Makes a bar pixels wide, which shows nothing until it is given a gradient. /// public GradientBar(WindowHandle window, int length) { this.window = window ?? throw new ArgumentNullException(nameof(window)); this.length = length; pixels = new byte[Rgba.ByteCount(length, 1)]; texture = window.CreateDynamicTexture(new DecodedImage(pixels, new Size(length, 1))); Material = new TextureMaterial { Texture = new BlacklightGlassTexture { Texture = texture } }; } /// /// Gets the material that draws the bar. /// public Glass.Material Material { get; } /// /// Replaces the bar's pixels, which must be pixels and as many as the bar is wide. /// public void Upload(byte[] rgba) { window.UpdateTexture(texture, rgba); } /// /// Draws a gradient along the bar. /// public void Show(Gradient gradient) { ColorStrips.FillGradient(pixels, length, gradient); Upload(pixels); } } }