DAY 016: _MOUSEINPUT
#24
LOL!

Well, if you are ever faced with a situation where you need to keep track of the time your cat is and is not on your mouse, you can't be stuck in a loop. That's why I made the more complicated routine, CATWATCH!

Code: (Select All)
DIM mse AS mm ' Let's do a TYPE instead of passing all variables or doing a DIM SHARE.
WIDTH 50, 25
_FONT 16
TYPE mm
    my AS INTEGER
    mx AS INTEGER
    oldmy AS INTEGER
    oldmx AS INTEGER
    lb AS INTEGER
END TYPE
PALETTE 1, 8
COLOR 9, 1: CLS

COLOR 0, 7
PALETTE 5, 63: PALETTE 6, 63
icon_x = _WIDTH - 1 ' Row.
icon_y = 2 ' Column.
COLOR 0, 6: LOCATE icon_y, 1: PRINT SPACE$(_WIDTH);
COLOR 0, 5: LOCATE icon_y, icon_x: PRINT "X"; ' Place an exit symbol on the screen.
VIEW PRINT 4 TO _HEIGHT
z1 = TIMER
DO
    _LIMIT 30

    mini_mouse mse ' Poll the mini mouse routine.

    IF mse.lb THEN ' Left button down.
        IF catwatch THEN
            SOUND 200, .2
            COLOR 15, 1: LOCATE 5, 1: PRINT " Miss Whiskers has her kitty-butt on your mouse!"
            catwatch = 1 - catwatch: z1 = TIMER
            IF trigger = hotspot THEN activate = hotspot ' Setting activate means we mouse clicked down on it but haven't released yet.
        END IF
    ELSE
        ' 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 5, 4: PALETTE 0, 63
        ELSE ' When no longer hovering on exit icon reset the variables and lose the highlighting.
            hotspot = 0: trigger = 0
            PALETTE 5, 63: PALETTE 0, 0
        END IF

        IF catwatch = 0 THEN
            COLOR 15, 1: LOCATE 5, 1: PRINT " Miss Whiskers is eyeballing your laptop...      ";
            catwatch = 1 - catwatch: z1 = TIMER
        END IF

        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
    LOCATE 7, 2: PRINT "Cat Watch Timer: "; INT(ABS(z1 - TIMER))
    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

Oh, I also moved the highlighting routine from the first snippet into the mouse button NOT down condition. That way, if someone drags the held down mouse to the "X" the "X" won't be highlighted. It can now only be highlighted when hovering with the left mouse button up.

Pete
If eggs are brain food, Biden takes his scrambled.
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: 9 Guest(s)