What is a good way of implementing a RTS selection box for tiles on a grid? I'm making a game with some similarities to Evil Genius, the building in particular. In that game you click one place, drag the cursor somewhere else and something similar to the GIF below shows.
To do so a grid and a way of translating
mousePosition to the correct cell is needed. Then a set of
for loops (one for x and one for y) for executing the necessary action on each cell. My main problem is accounting for the direction of dragging, and in particular when shrinking. My current solution (hastebin here) is rather crude, and I would like a more elegant solution for a more civilized age. Hopefully someone else can think of a easier way of accounting for drag direction, I surely can't.
Any help appreciated.