Page 1 of 1

Mouse cursor

Posted: Tue Aug 25, 2009 7:49 am
by izidor
How to set a different mouse cursor?

Posted: Tue Aug 25, 2009 3:10 pm
by burger2227
What did you have in mind?

Posted: Tue Aug 25, 2009 7:23 pm
by coma8coma1
when I was using CALL ABSOLUTE to do interrupts (which was right until i found qb64 two weeks ago) i would simple turn off the cursor and draw my own at the mouse's x,y. it helps to have a small graphics array set aside to capture the background with a GET and then you PUT it back whenever the mouse moves, then capture it again before drawing the mouse cursor again. i think that's how i did it.

Posted: Wed Aug 26, 2009 5:57 am
by izidor
Yes!
Thank you coma8coma1.

Here is what I did (in QB64).

Code: Select all

SCREEN 9
DIM SHARED back

_MOUSEHIDE

LINE (0,0)-(640,350),2,BF
LINE (0,350)-(640,40),6,BF
LINE (0,0)-(640,350),3

GET (0,0)-(639,349),back

DO
DO
LOOP UNTIL _MOUSEINPUT

CALL redraw

cur=_LOADIMAGE("cursor.png") ' 16 * 16 cursor
_PUTIMAGE(__MOUSEX,_MOUSEY),cur

LOOP



SUB redraw
PUT (0,0),back,PSET
END SUB

This is QB64 code.

And once again thanks coma8coma1 (you will be credited).

Posted: Wed Aug 26, 2009 1:30 pm
by burger2227
You don't need to redraw the entire background.

Just GET the 16 X 16 area of the background before you PUT the cursor image. When the cursor needs to move, PUT the old background back and GET the area where the next move will be. That way, you essentially erase the old position each move.

The following code shows how it works with the mouse in QB64. DIM arrays for BG and Cursor.

Code: Select all

X = __MOUSEX: Y = _MOUSEY  
GET (X, Y)-(X + 15, Y + 15), BG 'get first BG area
PUT (X, Y), Cursor, PSET
PX = X: PY = Y
DO
    X = __MOUSEX: Y = _MOUSEY  
   IF X <> PX OR Y <> PY THEN      'look for a changed coordinate value
     PUT (PX, PY), BG, PSET  'replace previous BG first
     GET (X, Y)-(X + 15, Y + 15), BG  'GET BG at new position next
     'PUT (X, Y), Mask, AND      '2 lines of code if using a mask
     'PUT (X, Y), Cursor            'XOR is default with mask
     PUT (X, Y), Cursor, PSET    'PUT cursor image at new position
   END IF
   PX = X: PY = Y                    'previous coordinates
LOOP UNTIL INKEY$ = CHR$(27)
Pete's editor changes _ M O U S E X to _MOUSEX. STRANGE!

If part of your cursor image is black background, create a mask for it and PUT with AND before your cursor PUT using XOR instead of PSET . POINT scan your cursor image and change black to 15 with all other colors being black.

Code: Select all

FOR xx = 280 TO 83 + 280                        
    FOR yy = 200 TO 260
      IF POINT(xx, yy) = 0 THEN PSET (xx, yy), 15 ELSE PSET (xx, yy), 0
    NEXT yy
NEXT xx
GET (280, 200)-(83 + 280, 260), Mask(0)
That way, your background will show through the old black areas. If there are black areas you don't want to have it show through set another color attribute to RGB 0. Then change those 0 pixels to 8.