Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is _WHEEL not working?
#1
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
Reply
#2
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
Reply
#3
(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
Reply
#4
My mouse only has 1 wheel and it registers as Wheel(3) on your code.

Yet the code counts 3 Wheels so what, are wheel(1) and wheel(2) are x, y axis wheels?
b = b + ...
Reply
#5
(04-17-2023, 07:57 PM)bplus Wrote: My mouse only has 1 wheel and it registers as Wheel(3) on your code.

Yet the code counts 3 Wheels so what, are wheel(1) and wheel(2) are x, y axis wheels?

Yes, according to wiki when mouse is in relative mode.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#6
As I recall _MouseMovement never did work or work correctly. It might have been worked on after v2.0 though.
b = b + ...
Reply
#7
(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
Reply
#8
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 hope this feedback is useful
Reply
#9
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.

Code: (Select All)
'Possible iOS clone?
'
'By Terry Ritchie
'
'Public domain
'

CONST FALSE = 0, TRUE = NOT FALSE

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

REDIM Icon(0) AS ICON
DIM WallPaper&

WallPaper& = _LOADIMAGE("wallpaper.png", 32)
SCREEN WallPaper&
_SCREENMOVE _MIDDLE

icon1% = MAKEICON("Icon", "icon1_64.png")
icon2% = MAKEICON("Icon", "icon2_64.png")
icon3% = MAKEICON("Icon", "icon3_64.png")
icon4% = MAKEICON("Icon", "icon1_64.png")
icon5% = MAKEICON("Icon", "icon2_64.png")
icon6% = MAKEICON("Icon", "icon3_64.png")
icon7% = MAKEICON("Icon", "icon1_64.png")
icon8% = MAKEICON("Icon", "icon2_64.png")
icon9% = MAKEICON("Icon", "icon3_64.png")
icon10% = MAKEICON("Icon", "icon1_64.png")
icon11% = MAKEICON("Icon", "icon2_64.png")
icon12% = MAKEICON("Icon", "icon3_64.png")
icon13% = MAKEICON("Icon", "icon1_64.png")
icon14% = MAKEICON("Icon", "icon2_64.png")
icon15% = MAKEICON("Icon", "icon3_64.png")
icon16% = MAKEICON("Icon", "icon1_64.png")
icon17% = MAKEICON("Icon", "icon2_64.png")
icon18% = MAKEICON("Icon", "icon3_64.png")
icon19% = MAKEICON("Icon", "icon1_64.png")
icon20% = MAKEICON("Icon", "icon2_64.png")
icon21% = MAKEICON("Icon", "icon3_64.png")
icon22% = MAKEICON("Icon", "icon1_64.png")
icon23% = MAKEICON("Icon", "icon2_64.png")
icon24% = MAKEICON("Icon", "icon3_64.png")

'ico1% = MAKEICON("Icon", "icon1_64.png")
'ico2% = MAKEICON("Icon", "icon2_64.png")
'ico3% = MAKEICON("Icon", "icon3_64.png")
'ico4% = MAKEICON("Icon", "icon1_64.png")
'ico5% = MAKEICON("Icon", "icon2_64.png")
'ico6% = MAKEICON("Icon", "icon3_64.png")
'ico7% = MAKEICON("Icon", "icon1_64.png")
'ico8% = MAKEICON("Icon", "icon2_64.png")
'ico9% = MAKEICON("Icon", "icon3_64.png")
'ico10% = MAKEICON("Icon", "icon1_64.png")
'ico11% = MAKEICON("Icon", "icon2_64.png")
'ico12% = MAKEICON("Icon", "icon3_64.png")
'ico13% = MAKEICON("Icon", "icon1_64.png")
'ico14% = MAKEICON("Icon", "icon2_64.png")
'ico15% = MAKEICON("Icon", "icon3_64.png")
'ico16% = MAKEICON("Icon", "icon1_64.png")
'ico17% = MAKEICON("Icon", "icon2_64.png")
'ico18% = MAKEICON("Icon", "icon3_64.png")
'ico19% = MAKEICON("Icon", "icon1_64.png")
'ico20% = MAKEICON("Icon", "icon2_64.png")
'ico21% = MAKEICON("Icon", "icon3_64.png")
'ico22% = MAKEICON("Icon", "icon1_64.png")
'ico23% = MAKEICON("Icon", "icon2_64.png")
'ico24% = MAKEICON("Icon", "icon3_64.png")

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

END FUNCTION

'------------------------------------------------------------------------------

FUNCTION ICONLOCATION% (x%, y%)

    SHARED Icon() AS ICON

    DIM Count% '                                                                             generic counter
    DIM Offset%

    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%

END FUNCTION

'------------------------------------------------------------------------------

SUB MOVEICON (handle%, xoffset%, yoffset%)

    SHARED Icon() AS ICON

    DIM Count% '                                                                             generic counter

    _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

END SUB

'------------------------------------------------------------------------------

SUB HandleMouse () STATIC

    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


Attached Files
.zip   iOS Clone.zip (Size: 18.4 KB / Downloads: 28)
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#10
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
Reply




Users browsing this thread: 3 Guest(s)