12-05-2022, 04:02 PM
Which leads into yet another discussion, how to save yourself from an unintended exit. So to demonstrate how this is done, try the following...
If you press the left mouse button down, over the exit icon, but then move the cursor off it before you release the button, you avoid the system action with this mini-mouse routine!
Pete
If you press the left mouse button down, over the exit icon, but then move the cursor off it before you release the button, you avoid the system action with this mini-mouse routine!
Code: (Select All)
DIM mse AS mm ' Let's do a TYPE instead of passing all variables or doing a DIM SHARE.
WIDTH 25, 25
TYPE mm
my AS INTEGER
mx AS INTEGER
oldmy AS INTEGER
oldmx AS INTEGER
lb AS INTEGER
END TYPE
COLOR 9, 1: CLS
COLOR 0, 7
icon_x = _WIDTH - 1 ' Row.
icon_y = 2 ' Column.
LOCATE icon_y, icon_x: PRINT "X"; ' Place an exit symbol on the screen.
'
DO
_LIMIT 30
mini_mouse mse ' Poll the mini mouse routine.
' Highlight the exit icon on hover, but only once so it isn't going on and off like hell. The oldmx variables insure this once and done action.
IF mse.my = icon_y AND mse.mx = icon_x AND mse_old.my <> mse.my AND mse_old.mx <> mse.mx THEN
hotspot = ((mse.my - 1) * _WIDTH + mse.mx - 1) + 1 ' Matrix the screen to combine the row and column values as a single variable.
trigger = hotspot ' Just a shorthand way so we don't keep using ((mse.my - 1) * _WIDTH + mse.mx - 1) + 1
PALETTE 7, 4: PALETTE 0, 63
ELSE ' When no longer hovering on exit icon reset the variables and lose the highlighting.
hotspot = 0: trigger = 0
PALETTE 7, 7: PALETTE 0, 0
END IF
IF mse.lb THEN ' Left button down.
IF trigger = hotspot THEN activate = hotspot ' Setting activate means we mouse clicked down on it but haven't released yet.
ELSE
IF activate THEN ' When button is released we check to see if the exit icon was clicked and if the mouse pointer is still on the icon.
IF activate = hotspot THEN
SYSTEM ' Quit.
ELSE
activate = 0: trigger = 0: hotspot = 0 ' The mouse cursor got moved so the exit was avoided.
END IF
END IF
END IF
REM LOCATE 7, 1: PRINT mse.my; mse.mx; mse_old.my; mse_old.mx; trigger; hotspot; activate; " ";
LOOP
SUB mini_mouse (mse AS mm)
mse_old.my = mse.my: mse_old.mx = mse.mx
WHILE _MOUSEINPUT: WEND
mse.mx = _MOUSEX
mse.my = _MOUSEY
mse.lb = _MOUSEINPUT(1)
IF mse.lb AND _MOUSEBUTTON(1) = 0 THEN
mse.lb = 0
ELSE
IF mse.lb = 0 AND _MOUSEBUTTON(1) THEN
mse.lb = -1
END IF
END IF
END SUB
Pete