public override void OnMouseMove(MouseEventArgs e) { if (TilesetSelection == Rectangle.Empty) { return; } Point location = RelativePoint(e.Location); // don't need to do anything if the position hasn't changed if (lastMouseMove == location) { return; } // calculated the center offset of the selection. Point selectionOffset = new Point( (int)Math.Floor((float)(TilesetSelection.Width / TileSize.Width) / 2.0f), (int)Math.Floor((float)(TilesetSelection.Height / TileSize.Height) / 2.0f) ); // set the brush preview location relative to the world brushRect.Location = location.Minus(selectionOffset).Minus(World.ViewportOffset).Multiplied(TileSize).Plus(World.ViewportPadding); // paint onto the world if the left button is down. // we render a line to ensure there are no // skips when moving the mouse quickly if (e.Button == MouseButtons.Left) { renderLine(lastMouseMove, location); } // redraw the canvas to show changes World.InvalidateCanvas(); lastMouseMove = location; }