fady
2015-04-28 09:33:39
So I want to make a script that checks whether my mouse position is in multiple boxes. I'm trying to do it without having to do long if statements.
in this example by Tboxes are labeled: North, South, East, West, NEast, NWest, SEast, SWest.
I need help making a script that will check which box my mouse is in.
So far this is what I could come up with:
I was wondering if there was a cleaner way to do this. I tried to make a case statement for it, but I couldn't figure it out.
Thanks
in this example by Tboxes are labeled: North, South, East, West, NEast, NWest, SEast, SWest.
I need help making a script that will check which box my mouse is in.
So far this is what I could come up with:
procedure whichBox();
var
x, y: Integer;
MPos: Tpoint;
North, South, East, West, NEast, NWest, SEast, SWest: Tbox;
begin
getMousePos(x, y);
MPos.create(x, y);
//Here Id define all the TBoxes
if North.isPointInside(MPos) then
writeLn('Mouse is North')
else
if South.isPointInside(MPos) then
writeLn('Mouse is South')
else
if East.isPointInside(MPos) then
writeLn('Mouse is East');
//And so on....
end;I was wondering if there was a cleaner way to do this. I tried to make a case statement for it, but I couldn't figure it out.
Thanks