Omri Vidal
Omri Vidal

Reputation: 47

Assembly-TASM: on-screen button in graphic mode

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

Answers (1)

Sep Roland
Sep Roland

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

Related Questions