using Annulus; using Azimuth; using Blacklight.Core; using Glass.Blacklight; namespace Glass.Testbed { /// /// Labels tinted by a rainbow texture, so each glyph takes its color from where it sits rather than one color for /// the whole text. /// public class RainbowTextTestCase : TestCase { // A power of two, since D3D9 hardware with only conditional non-power-of-two support can't repeat other sizes. private const int PixelsPerCycle = 512; private const string Paragraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua."; private readonly World world; public RainbowTextTestCase(string name, World world) : base(name) { this.world = world; } /// /// Returns a one pixel tall strip running once through the rainbow, for a tint texture to repeat across the /// screen. /// private BlacklightGlassTexture RainbowStrip() { var rgba = new byte[PixelsPerCycle * DecodedImage.BytesPerPixel]; for (int x = 0; x < PixelsPerCycle; ++x) { System.Drawing.Color color = RainbowMaterial.Hue((double)x / PixelsPerCycle); int offset = x * DecodedImage.BytesPerPixel; rgba[offset] = color.R; rgba[offset + 1] = color.G; rgba[offset + 2] = color.B; rgba[offset + 3] = 255; } var image = new DecodedImage(rgba, new System.Drawing.Size(PixelsPerCycle, 1)); return new BlacklightGlassTexture { Texture = world.window.CreateTexture(image, generateMipmaps: false) }; } protected override void Populate() { AddCaption("Tinted by a rainbow texture repeating across the screen, so color follows position"); var rainbow = new TextStyle { Font = Fonts.Philosopher64, TintColor = System.Drawing.Color.White, TintTexture = RainbowStrip(), Multiline = false, }; var title = new Label(rainbow, "Rainbow text", Constraints.Unbounded); title.Bounds = title.Bounds.WithPosition(ContentAggregator.NewRow(title.Bounds.Height).TopLeft); Add(title); AddCaption("Wrapped, so the colors line up down the lines too"); var paragraph = new Label(rainbow with { Font = Fonts.Philosopher32, Multiline = true }, Paragraph, Constraints.Loose(new Vector(PixelsPerCycle, Scalar.PositiveInfinity))); paragraph.Bounds = paragraph.Bounds.WithPosition(ContentAggregator.NewRow(paragraph.Bounds.Height).TopLeft); Add(paragraph); } } }