Reputation: 47
I was wondering what's the simplest way to know whether a mouse was clicked between a certain range of pixels, i.e to display a rectangular button in graphic mode and find out if the user clicked on it.
Thanks!
Upvotes: 1
Views: 243
Reputation: 39166
The same mouse driver function that informs you about the mouse being clicked, also tells you where the mouse was at that moment.
Next code waits for a left button click:
NoLeftClick:
mov ax, 0003h ; MOUSE.GetMousePosition
int 33h ; -> BX CX DX
test bx, 1 ; Is left button down?
jz NoLeftClick ; No
Once the click arrives you start comparing the coordinates that you got in CX
(X) and DX
(Y) with the coordinates of the rectangle that interests you:
cmp cx, UpperLeftCornerX
jb Outside
cmp cx, LowerRightCornerX
ja Outside
cmp dx, UpperLeftCornerY
jb Outside
cmp dx, LowerRightCornerY
ja Outside
Inside:
...
Outside:
...
For more info about the mouse api consult http://stanislavs.org/helppc/int_33.html
Upvotes: 3