04-17-2023, 05:36 PM (This post was last modified: 04-17-2023, 05:40 PM by TerryRitchie.)
In the wiki under _WHEEL the following example code is given. If I'm understanding this correctly when you issue the command:
ignore = _MOUSEMOVEMENTX
this is supposed to put the mouse into a relative movement mode allowing _WHEEL(1) and _WHEEL(2) to read the mouse x,y movements. However, no matter what I try I can't seem to get this working? Any suggestions? I went back as far as version 0.8.2 and it doesn't work there either.
Code: (Select All)
ignore = _MOUSEMOVEMENTX 'dummy call to put mouse into relative movement mode
PRINT "Move your mouse and/or your mouse wheel (ESC to exit)"
d = _DEVICES ' always read number of devices to enable device input
DO: _LIMIT 30 'main loop
DO WHILE _DEVICEINPUT(2) 'loop only runs during a device 2 mouse event
PRINT _WHEEL(1), _WHEEL(2), _WHEEL(3)
LOOP
LOOP UNTIL INKEY$ = CHR$(27)
New to QB64pe? Visit the QB64 tutorial to get started. QB64 Tutorial
(04-17-2023, 05:47 PM)Jack Wrote: hello TerryRitchie
the third column seems to work for me, if I roll toward the monitor I get -1, roll toward me I get 1
the first 2 columns remain 0
Correct, _WHEEL(3) works fine but I can never get _WHEEL(1) or _WHEEL(2) to work. I've tried putting ignore = _MOUSEMOVEMENTX inside the loop as well but nothing. I also tried _MOUSEMOVEMENTY but still nothing.
New to QB64pe? Visit the QB64 tutorial to get started. QB64 Tutorial
(04-17-2023, 08:50 PM)bplus Wrote: As I recall _MouseMovement never did work or work correctly. It might have been worked on after v2.0 though.
_MOUSEMOVEMENTX and _MOUSEMOVEMENTY did work at one time long, long ago. I write an iOS desktop clone that relied on those two statements to move icons from one place to another after a click-and-hold was performed on them. I'll need to dig that code out and see if it works in the latest versions of QB64.
New to QB64pe? Visit the QB64 tutorial to get started. QB64 Tutorial
Hi Terry
running the code on #1 on my Lenovo Ideapad con touchpad
I have no wheel in hardware, but using touchpad if I do "the two fingers" movement used to scrolling pages I get -1/1 (as _wheel works) on the third column.
I found that code I referenced earlier. The _MOUSEMOVEMENTX and _MOUSEMOVEMENTY statements are in line 235. I wrote this in QB64 v0.954 back in 2012 and it works fine in that version. However, any version 1.3 and higher the commands act strange and don't sync with the movements of the mouse.
So I can confirm these two statements are not working as intended now. The attached zip file contains the code and icon images if you want to try it for yourself.
TYPE ICON
image AS LONG ' icon image
x AS INTEGER ' x coordinate of moving icon
y AS INTEGER ' y coordinate of moving icon
xspot AS INTEGER ' x coordinate of icon
yspot AS INTEGER ' y coordinate of icon
width AS INTEGER ' width of icon image
height AS INTEGER ' height of icon image
twidth AS INTEGER ' width of overall icon with text
theight AS INTEGER ' height of overall icon with text
text AS STRING * 255 ' label text
bgimage AS LONG ' background image behind icon
selected AS INTEGER ' flag indicating icon selected
END TYPE
DO
IF _MOUSEINPUT THEN HandleMouse
LOOP UNTIL INKEY$ <> ""
'------------------------------------------------------------------------------
FUNCTION MAKEICON% (Text$, Image$)
SHARED Icon() AS ICON
DIM UpNext% ' next handle number available
DIM Columns% ' number of columns available on screen
DIM TmpIcon& ' temporary image holder to create icon
UpNext% = UBOUND(Icon) + 1 ' get next available handle
REDIM _PRESERVE Icon(UpNext%) AS ICON ' increase the size of the icon array
Icon(UpNext%).image = _LOADIMAGE(Image$, 32) ' get the icon image
Icon(UpNext%).width = _WIDTH(Icon(UpNext%).image) ' calculate the icon width
Icon(UpNext%).height = _HEIGHT(Icon(UpNext%).image) ' calculate the icon height
Icon(UpNext%).twidth = Icon(UpNext%).width * 1.5 ' calculate width for text
Icon(UpNext%).theight = Icon(UpNext%).height * 2 ' calculate height for text
TmpIcon& = _NEWIMAGE(Icon(UpNext%).twidth, Icon(UpNext%).theight, 32) ' create a temp image based on text width/height
_SETALPHA 0, _RGBA32(0, 0, 0, 0), TmpImage& ' set the background color transparent
_PUTIMAGE (Icon(UpNext%).width \ 4, 0), Icon(UpNext%).image, TmpIcon& ' put the icon on the temp image
_FREEIMAGE Icon(UpNext%).image ' free the icon image
Icon(UpNext%).image = _COPYIMAGE(TmpIcon&) ' get the new icon image
_FREEIMAGE TmpIcon& ' free the temp icon image
Columns% = _WIDTH(_DEST) \ Icon(UpNext%).twidth ' calculate the number of columns on screen
IF UpNext% MOD Columns% = 0 THEN ' is this icon going to be in rightmost column?
x% = (Icon(UpNext%).twidth * (Columns% - 1)) ' yes, calculate the x coordinate of icon
y% = (((UpNext% \ Columns%) - 1) * Icon(UpNext%).theight) ' calculate the y coordinate of icon
ELSE ' no, calculate the icon position
x% = ((UpNext% MOD Columns% - 1) * Icon(UpNext%).twidth) ' calculate the x coordinate of icon
y% = ((UpNext% \ Columns%) * Icon(UpNext%).theight) ' calculate the y coordinate of the icon
END IF
Icon(UpNext%).x = x% ' save the icon x coordinate
Icon(UpNext%).y = y% ' save the icon y coordinate
Icon(UpNext%).xspot = x% ' save this column's x coordinate
Icon(UpNext%).yspot = y% ' save this column's y coordinate
Icon(UpNext%).text = Text$ + CHR$(0) ' save the icon's label
Icon(UpNext%).selected = FALSE ' this icon is not yet selected
Icon(UpNext%).bgimage = _NEWIMAGE(Icon(UpNext%).twidth, Icon(UpNext%).theight, 32) ' create background image holder
_PUTIMAGE , _DEST, Icon(UpNext%).bgimage, (x%, y%)-(x% + Icon(UpNext%).twidth - 1, y% + Icon(UpNext%).theight - 1) ' save the background where icon will be
_PUTIMAGE (x%, y%), Icon(UpNext%).image ' place the icon on screen
MAKEICON = UpNext% ' return the handle number
ICONLOCATION = 0 ' assume no icon located here
FOR Count% = 1 TO UBOUND(Icon) ' cycle through the icon array
Offset% = (Icon(Count%).twidth - Icon(Count%).width) \ 2
IF (x% >= Icon(Count%).x + Offset%) AND (x% <= Icon(Count%).x + Icon(Count%).width - 1 + Offset%) AND (y% >= Icon(Count%).y) AND (y% <= Icon(Count%).y + Icon(Count%).height - 1) THEN ' icon here?
ICONLOCATION = Count% ' yes, return the icon's handle
EXIT FOR ' no reason to check any further
END IF
NEXT Count%
_MOUSESHOW ' show mouse on screen
_PUTIMAGE (Icon(handle%).x, Icon(handle%).y), Icon(handle%).bgimage ' restore the background
IF xoffset% = -32767 THEN ' do we need to pop icon back to position?
Icon(handle%).x = Icon(handle%).xspot ' yes, set icon's x position to column x coordinate
Icon(handle%).y = Icon(handle%).yspot ' set icon's y position to column y coordinate
ELSE ' no, user is still moving icon around
Icon(handle%).x = Icon(handle%).x + xoffset% ' move mouse horizontally
Icon(handle%).y = Icon(handle%).y + yoffset% ' move mouse vertically
END IF
IF yoffset% <> -32767 THEN ' should a collision with another icon be checked?
FOR Count% = 1 TO UBOUND(Icon) ' yes, cycle through the icon array
IF Count% <> handle% THEN ' don't check for collision with self
IF Icon(handle%).x <= Icon(Count%).xspot + Icon(Count%).twidth - (Icon(Count%).twidth / 1.25) THEN ' check icon's corners for intrusion into another icon
IF Icon(handle%).x + Icon(handle%).twidth >= Icon(Count%).xspot + (Icon(Count%).twidth / 1.25) THEN
IF Icon(handle%).y <= Icon(Count%).yspot + Icon(Count%).theight - (Icon(Count%).theight / 1.25) THEN
IF Icon(handle%).y + Icon(handle%).theight >= Icon(Count%).yspot + (Icon(Count%).theight / 1.25) THEN
SWAP Icon(handle%).xspot, Icon(Count%).xspot ' we have a collision, swap column x positions
SWAP Icon(handle%).yspot, Icon(Count%).yspot ' swap column y positions
MOVEICON Count%, -32767, -32767 ' move the icon we ran into, but don't do collicion detection (recurse)
EXIT FOR ' no need to check any further
END IF
END IF
END IF
END IF
END IF
NEXT Count%
END IF
_PUTIMAGE , _DEST, Icon(handle%).bgimage, (Icon(handle%).x, Icon(handle%).y)-(Icon(handle%).x + Icon(handle%).twidth - 1, Icon(handle%).y + Icon(handle%).theight - 1) ' get background image
_PUTIMAGE (Icon(handle%).x, Icon(handle%).y), Icon(handle%).image ' place the icon on screen
DIM LeftButton% ' flag indicating left button press state
DIM RightButton% ' flag indicating right button press state
DIM Xclick% ' x coordinate of left click
DIM Yclick% ' y coordinate of left click
DIM Xmouse% ' x coordinate of current mouse x location
DIM Ymouse% ' y coordinate of current mouse y location
DIM FirstCall% ' flag indicating the first time subroutine called
DIM IconClicked% ' value of icon left clicked on
DIM BoxImage& ' background image of current box selection area
DIM Xul% ' upper left x coordinate of box selection area
DIM Yul% ' upper left y coordinate of box selection area
DIM Xlr% ' lower right x coordinate of box selection area
DIM Ylr% ' lower right y coordinate of box selection area
IF NOT FirstCall% THEN ' first time this subroutine called?
FirstCall% = NOT FirstCall% ' yes, set flag indicating routine has been called
_MOUSESHOW ' show the mouse
_MOUSEMOVE _WIDTH(_DEST) \ 2, _HEIGHT(_DEST) \ 2 ' move mouse to middle of screen
END IF
Xmouse% = _MOUSEX ' save current mouse x location
Ymouse% = _MOUSEY ' save current mouse y location
IF NOT LeftButton% THEN ' was the left mouse button pressed last time here?
IF _MOUSEBUTTON(1) THEN ' no, is the left mouse button pressed now?
LeftButton% = NOT LeftButton% ' yes, set flag indicating that left button pressed
Xclick% = Xmouse% ' save the x location where click occured
Yclick% = Ymouse% ' save the y location where click occured
IconClicked% = ICONLOCATION(Xclick%, Yclick%) ' save the icon number if one was clicked on
IF NOT IconClicked% THEN ' was an icon clicked on?
BoxImage& = _NEWIMAGE(1, 1, 32) ' no, initiate the background restore image holder
Xul% = Xclick% ' set the upper left x location
Yul% = Yclick% ' set the upper left y location
Xlr% = Xclick% ' set the lower right x location
Ylr% = Yclick% ' set the lower right y location
_PUTIMAGE , _DEST, BoxImage&, (Xul%, Yul%)-(Xlr%, Ylr%) ' get the initial background image
END IF
EXIT SUB ' mouse event updated - leave sub
END IF
ELSE ' yes, the left mouse button was pressed last time
IF _MOUSEBUTTON(1) THEN ' is the left mouse button still pressed?
IF IconClicked% THEN ' was an icon clicked on originally?
MOVEICON IconClicked%, _MOUSEMOVEMENTX, _MOUSEMOVEMENTY
ELSE ' no, an icon was not clicked on originally
_PUTIMAGE (Xul%, Yul%), BoxImage& ' restore the original screen
IF Xclick% <> Xmouse% AND Yclick% <> Ymouse% THEN ' has the mouse moved since last time here?
_FREEIMAGE BoxImage& ' yes, free image memory
IF Xclick% <= Xmouse% THEN ' original x click point <= current mouse x position?
Xul% = Xclick% ' yes, set upper left x coordinate
Xlr% = Xmouse% ' set lower right x coordinate
ELSE ' no
Xul% = Xmouse% ' set upper left x coordinate
Xlr% = Xclick% ' set lower right x coordinate
END IF
IF Yclick% <= Ymouse% THEN ' original y click point <= current mouse y position?
Yul% = Yclick% ' yes, set upper left y coordinate
Ylr% = Ymouse% ' set lower right y coordinate
ELSE ' no
Yul% = Ymouse% ' set upper left y coordinate
Ylr% = Yclick% ' set lower right y coordinate
END IF
BoxImage& = _NEWIMAGE(Xlr% - Xul% + 1, Ylr% - Yul% + 1, 32) ' create the background restore image holder
_PUTIMAGE , _DEST, BoxImage&, (Xul%, Yul%)-(Xlr%, Ylr%) ' save the background image
END IF
LINE (Xul%, Yul%)-(Xlr%, Ylr%), _RGBA32(0, 0, 255, 127), BF ' draw a translucent blue selection area filled box
LINE (Xul%, Yul%)-(Xlr%, Ylr%), _RGB32(255, 255, 255), B , 43690 ' draw a dashed selection area box
END IF
ELSE ' no, the left button is no longer pressed
IF IconClicked% THEN ' was an icon being moved previously?
MOVEICON IconClicked%, -32767, 0
IconClicked% = 0 ' yes, set flag to show it no longer is
ELSE ' No, an icon was not being moved
_PUTIMAGE (Xul%, Yul%), BoxImage& ' restore the original screen
_FREEIMAGE BoxImage& ' free image memory
END IF
LeftButton% = NOT LeftButton% ' reset the left button flag
END IF
END IF
'IF NOT RightButton% THEN IF _MOUSEBUTTON(2) THEN RightButton% = NOT RightButton%
_DISPLAY
END SUB
New to QB64pe? Visit the QB64 tutorial to get started. QB64 Tutorial
04-20-2023, 09:09 AM (This post was last modified: 04-20-2023, 09:11 AM by Jack.)
Hello TerryRitchie
I can click and drag the icons but the mouse pointer moves faster than the icon being dragged, it does not stay on the icon but moves further and further away from the icon as you move it