InRectangle(x, y, x1, y1, x2, y2)The function checks if a point (x, y) is inside rectangle (x1, y1, x2, y2). If you use a function like DrawRectangle to draw a button, you can later use function InRectangle to check if user clicked or moved a mouse over such button. Example below demonstrates that:
$button.color = "white"
$button.text = "Click me"
$button.textColor = "blue"
$button.fontSize = 20
$button.x1 = 10
$button.y1 = 10
SetFontSize($button.fontSize)
$button.x2 = $button.x1 + GetTextWidth($button.text)
$button.y2 = $button.x1 + GetTextHeight($button.text)
function DrawButton()
SetColor($button.color)
DrawRectangle ($button.x1, $button.y1, $button.x2, $button.y2)
SetColor($button.textColor)
DrawText($button.x1, $button.y1, $button.text)
end function
function OnMouseMove(x, y)
if InRectangle(x, y, $button.x1, $button.y1, $button.x2, $button.y2)
SetCursor("hand")
else
SetCursor("Arrow")
end if
end function
function OnMouseUp(x, y)
if InRectangle(x, y, $button.x1, $button.y1, $button.x2, $button.y2)
$button.text = "Clicked"
DrawButton()
end if
end function
DrawButton()
See also: