using Annulus; using Azimuth; using Blacklight.Core; namespace Glass.Blacklight { /// /// Draws a in the rect it is given. Register Render on a renderer before drawing one. /// public record PictureMaterial : Material { public Picture Picture { get; init; } /// /// The size this asks its parent for, so a control that sizes itself from its material, such as a scroll bar /// button, comes out as large as the picture is meant to be. Null asks for nothing. /// public Vector? NaturalSize { get; init; } protected override Vector PreferredSizeInModelSpace(Constraints constraints) { return NaturalSize ?? constraints.MinSize; } public static void Render(Renderer renderer, Cel context, PictureMaterial material, Rect rect, in DrawState drawState) { if (material.Picture == null || rect.Width <= 0 || rect.Height <= 0) { return; } // GDI+ puts pixel centers on whole coordinates and Blacklight puts them on halves. Half a pixel over makes // the original's coordinates land on the pixels they did there. rect.Position += new Vector(0.5, 0.5); material.Picture.Draw(context, rect, in drawState); } } }