SRL Archive - SRL Suggestions

Mouse within points


trojan

2011-05-10 07:18:02

Is there a function in SRL to see if the mouse is within co-ordinates, or a certain distance from a point? If not can these be added to the Includes?


//Checks if the current mouse position is to the right of x1, left of x2, below y1 and above y2
//Example use if not MouseWithin(MIX1, MIY1, MIX2, MIY2) then MMouse(MIX1 + 15, MIY1 + 20, 5, 5);
Function MouseWithin(x1, y1, x2, y2 :integer) :boolean;
var
x, y:integer;
begin
Result := False;
GetMousePos(x, y);
if (x > x1) and (x < x2) then
if (y > y1) and (y < y2) then
Result := True;
end;


//Checks if the current mouse position is within a certain distance from the point specified
//an example use is if not MouseDistancePoint(MSCX, MSCY, 20) then MMouse(MSCX, MSCY, 5, 5);
Function MouseDistancePoint(Rx, Ry, Distance :integer) :boolean;
var
x, y :integer;
begin
Result := False;
GetMousePos(x, y);
if (x > Rx - Distance) and (x < Rx + Distance) then
if (y > Ry - Distance) and (y < Ry + Distance) then
Result := True;
end;


If they already exist sorry for creating this post, I just couldn't find them anywhere :/

Gu3st...

2011-05-10 07:33:37

I'm unsure if they exist, but it's better to use PointInBox in this case:
function MouseInBox(X1, Y1, X2, Y2 : Integer): Boolean;
var X, Y : Integer;
begin
GetMousePos(X, Y);
Result := PointInBox(Point(X, Y), IntToBox(X1, Y1, X2, Y2));
end;

function MouseInBoxDistance(rX, rY, Distance): Boolean;
begin
Result := MouseInBox(rX - Distance, rY - Distance, rX + Distance, rY + Distance);
end;

trojan

2011-05-10 07:46:06

ahhh it was point in box I needed, thanks :)

i luffs yeww

2011-05-10 09:41:03

;) I think you may want MouseBox(x1, y1, x2, y2, clicktype (0 for move, no click, 1 for left click, 2 for right, I think));

Gu3st...

2011-05-10 12:28:32

From: i luffs yeww
;) I think you may want MouseBox(x1, y1, x2, y2, clicktype (0 for move, no click, 1 for left click, 2 for right, I think));
That would move the mouse (and click if you told it to), this simply checks if it's in the box or not

Coh3n

2011-05-10 13:42:21

There's also a Distance() function in Simba that returns the distance from point A to point B.

i luffs yeww

2011-05-10 15:23:22

From: Zyt3x
That would move the mouse (and click if you told it to), this simply checks if it's in the box or not


Oh, I thought from the thread title he meant "do Mouse() within points." :p

But yeah, PointInBox and GetMousePos would do the trick. :)