Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 016: _MOUSEINPUT
#18
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!

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
Reply


Messages In This Thread
DAY 016: _MOUSEINPUT - by SMcNeill - 11-21-2022, 11:27 PM
RE: DAY 016: _MOUSEINPUT - by bplus - 11-21-2022, 11:41 PM
RE: DAY 016: _MOUSEINPUT - by SMcNeill - 11-22-2022, 12:09 AM
RE: DAY 016: _MOUSEINPUT - by PhilOfPerth - 11-22-2022, 12:16 AM
RE: DAY 016: _MOUSEINPUT - by james2464 - 11-22-2022, 12:20 AM
RE: DAY 016: _MOUSEINPUT - by SMcNeill - 11-22-2022, 12:32 AM
RE: DAY 016: _MOUSEINPUT - by mnrvovrfc - 11-21-2022, 11:54 PM
RE: DAY 016: _MOUSEINPUT - by PhilOfPerth - 11-22-2022, 12:08 AM
RE: DAY 016: _MOUSEINPUT - by james2464 - 11-22-2022, 12:38 AM
RE: DAY 016: _MOUSEINPUT - by SMcNeill - 11-22-2022, 12:49 AM
RE: DAY 016: _MOUSEINPUT - by mnrvovrfc - 11-22-2022, 12:46 AM
RE: DAY 016: _MOUSEINPUT - by Pete - 11-22-2022, 01:32 AM
RE: DAY 016: _MOUSEINPUT - by SMcNeill - 11-22-2022, 02:00 AM
RE: DAY 016: _MOUSEINPUT - by OldMoses - 12-06-2022, 01:39 AM
RE: DAY 016: _MOUSEINPUT - by Pete - 12-06-2022, 02:28 AM
RE: DAY 016: _MOUSEINPUT - by Pete - 11-22-2022, 02:59 AM
RE: DAY 016: _MOUSEINPUT - by SMcNeill - 11-22-2022, 03:47 AM
RE: DAY 016: _MOUSEINPUT - by Pete - 11-22-2022, 07:54 AM
RE: DAY 016: _MOUSEINPUT - by mnrvovrfc - 12-05-2022, 02:03 PM
RE: DAY 016: _MOUSEINPUT - by Pete - 12-05-2022, 04:02 PM
RE: DAY 016: _MOUSEINPUT - by SMcNeill - 12-05-2022, 04:55 PM
RE: DAY 016: _MOUSEINPUT - by Pete - 12-05-2022, 07:45 PM
RE: DAY 016: _MOUSEINPUT - by OldMoses - 12-06-2022, 02:26 PM
RE: DAY 016: _MOUSEINPUT - by Pete - 12-06-2022, 03:23 PM
RE: DAY 016: _MOUSEINPUT - by NasaCow - 12-10-2022, 12:28 PM
RE: DAY 016: _MOUSEINPUT - by Pete - 12-10-2022, 05:08 PM



Users browsing this thread: 6 Guest(s)