Grid one's easy.
Floor( MouseX / N ) * M
Floor( MouseY / N ) * M
Where N and M are the size of grid.
For example, 16x16 grid would be
Floor( MouseX / 16 ) * 16
Floor( MouseY / 16 ) * 16
-Sprite: Set position to Floor( MouseX / 16 ) * 16, Floor( MouseY / 16 ) * 16
And make your own checkbox that says something like "Follow grid" and set the sprite/something to follow the grid (Floor) when checked, and just follow mouse (MouseX, MouseY) when not checked.