using Blacklight.Core; using System.Reflection; namespace Glass.Blacklight { /// /// Keeps a host's cursor showing whichever one the UI asks for under the pointer. /// public class CursorSync { private readonly ICursorSurface surface; private readonly int scale; private readonly Assembly artAssembly; // The cursor last handed to the surface, so a pointer resting on a control doesn't decode its art every frame. private SpriteCursor applied = null; /// The host's cursor. /// How many times larger than its art a cursor is drawn. /// The assembly that embeds the cursors' sprite sheet. public CursorSync(ICursorSurface surface, int scale, Assembly artAssembly) { this.surface = surface; this.scale = scale; this.artAssembly = artAssembly; } /// /// Shows , or hands the cursor back to the host when it isn't a sprite cursor. /// public void Apply(Cursor wanted) { var sprite = wanted as SpriteCursor; if (ReferenceEquals(sprite, applied)) { return; } applied = sprite; if (sprite == null) { surface.ClearCursor(); } else { surface.TrySetCursor(sprite.ImageFor(scale, artAssembly)); } } } }