Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom MouseMovement Example
#1
There's been several discussions here recently about _MouseMovementX and _MouseMovementY, and how they don't work 100% as expected in Linux and Mac.  Unfortunately, the problem here is an underlying issue with glut itself not reporting that relative movement back to us.

The only real solution at the moment is for one to write their own routine to handle this type of situation, so I thought I'd take a few minutes and write up a quick example of how to do that for someone:

Code: (Select All)
DIM SHARED AS LONG MouseMoveX, MouseMoveY, MouseX, MouseY

SCREEN _NEWIMAGE(800, 600, 32)
_SCREENMOVE _MIDDLE


DO
    CLS
    Mouse
    TMMX = TMMX + MouseMoveX: TMMY = TMMY + MouseMoveY
    PRINT "Mouse x:"; MouseX
    PRINT "Mouse y:"; MouseY
    PRINT "MouseMoveX:"; MouseMoveX
    PRINT "MouseMoveY:"; MouseMoveY
    PRINT "Total MouseMoveX:"; TMMX
    PRINT "TOtal MouseMoveY:"; TMMY
    _LIMIT 30
    _DISPLAY
LOOP UNTIL _MOUSEBUTTON(2)
SYSTEM



SUB Mouse
    STATIC AS LONG CurrentX, CurrentY
    STATIC AS LONG Pointer 'We need a pointer of some sort for a manual pointer.  Here's a cheesy one by default.
    STATIC AS INTEGER Init

    WHILE _MOUSEINPUT: WEND 'catch up to the current mouse's position so we sync properly
    X = _MOUSEX: Y = _MOUSEY
    MouseMoveX = 0: MouseMoveY = 0

    IF Init = 0 THEN
        Init = -1
        CurrentX = _WIDTH \ 2: CurrentY = _HEIGHT \ 2
        _MOUSEHIDE
        _MOUSEMOVE _WIDTH \ 2, _HEIGHT \ 2
        Pointer = _NEWIMAGE(16, 8, 32)
        COLOR -1, 0
        _PRINTSTRING (0, 0), CHR$(24), Pointer
    ELSE
        IF X <> _WIDTH \ 2 OR Y <> _HEIGHT \ 2 THEN
            MouseMoveX = X - _WIDTH \ 2: MouseMoveY = Y - _HEIGHT \ 2
            CurrentX = CurrentX + MouseMoveX
            CurrentY = CurrentY + MouseMoveY
            IF CurrentX < 0 THEN CurrentX = 0
            IF CurrentX >= _WIDTH THEN CurrentX = _WIDTH - 1
            IF CurrentY < 0 THEN CurrentY = 0
            IF CurrentY >= _HEIGHT THEN CurrentY = _HEIGHT - 1
        END IF
    END IF
    _PUTIMAGE (CurrentX - 8, CurrentY - 8)-STEP(32, 32), Pointer
    _MOUSEMOVE _WIDTH / 2, _HEIGHT / 2
    MouseX = CurrentX: MouseY = CurrentY
END SUB

Test that out and see if it doesn't keep track of the current mouse position, while also allowing for mouse movement to take place regardless of the edge of the screen.

Feel free to ask/add any questions, comments, or insights into the process here, but I'm thinking this should work on all OSes without any issues.  (As long as _MouseHide works on all OSes...  I didn't think to check to see if it does or doesn't, to be honest.)
Reply


Messages In This Thread
Custom MouseMovement Example - by SMcNeill - 02-25-2024, 05:37 PM
RE: Custom MouseMovement Example - by NakedApe - 02-26-2024, 01:18 AM
RE: Custom MouseMovement Example - by SMcNeill - 02-26-2024, 03:29 AM
RE: Custom MouseMovement Example - by SMcNeill - 02-26-2024, 03:45 AM
RE: Custom MouseMovement Example - by NakedApe - 02-26-2024, 06:00 AM
RE: Custom MouseMovement Example - by NakedApe - 02-26-2024, 05:35 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 07:15 AM
RE: Custom MouseMovement Example - by GareBear - 02-27-2024, 01:06 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 01:28 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 01:47 PM
RE: Custom MouseMovement Example - by NakedApe - 02-27-2024, 04:59 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 05:06 PM
RE: Custom MouseMovement Example - by MasterGy - 02-27-2024, 05:18 PM
RE: Custom MouseMovement Example - by NakedApe - 02-27-2024, 07:17 PM
RE: Custom MouseMovement Example - by MasterGy - 02-27-2024, 08:53 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 08:58 PM
RE: Custom MouseMovement Example - by MasterGy - 02-27-2024, 09:07 PM
RE: Custom MouseMovement Example - by NakedApe - 02-28-2024, 02:40 AM



Users browsing this thread: 3 Guest(s)