using Blacklight.Core; using System.IO; using System.Reflection; namespace Glass.Blacklight { /// /// A cursor backed by one cell of a registered sprite sheet. /// public sealed class SpriteCursor : Cursor { public SpriteMaterial Sprite { get; } /// /// Where the pointer's reported position sits within Sprite's cell, unscaled. /// public Point Hotspot { get; } public SpriteCursor(SpriteMaterial sprite, Point hotspot) { Sprite = sprite; Hotspot = hotspot; } /// /// Crops 's cell out of its sheet and returns cursor pixels, enlarged by , for a host to hand to the OS. /// /// The assembly that embeds the sheet's image. public static CursorImage ImageFor(SpriteMaterial sprite, Point hotspot, int scale, Assembly artAssembly) { SpriteSheetAttribute sheet = sprite.SpriteSheet; var cell = new System.Drawing.Rectangle( sheet.GridOriginX + sprite.CellLocation.X * (sheet.SpriteSize.X + sheet.BorderSize), sheet.GridOriginY + sprite.CellLocation.Y * (sheet.SpriteSize.Y + sheet.BorderSize), sheet.SpriteSize.X, sheet.SpriteSize.Y); using (Stream art = artAssembly.GetManifestResourceStream(sheet.SpriteSheetSource)) { return CursorImage.FromImageStream(art, cell, hotspot, scale); } } /// /// Returns this cursor's pixels, enlarged by . /// /// The assembly that embeds the sheet's image. public CursorImage ImageFor(int scale, Assembly artAssembly) { return ImageFor(Sprite, Hotspot, scale, artAssembly); } } }