Mouse cursor
Mouse cursor
How to set a different mouse cursor?
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
What did you have in mind?
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- coma8coma1
- Veteran
- Posts: 100
- Joined: Sat Dec 08, 2007 5:29 pm
- Location: Maryland, USA
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.
Yes!
Thank you coma8coma1.
Here is what I did (in QB64).
This is QB64 code.
And once again thanks coma8coma1 (you will be credited).
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
And once again thanks coma8coma1 (you will be credited).
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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.
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.
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.
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)
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)
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0