Author Topic: WHILE: WEND and _MOUSEWHEEL  (Read 5428 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
WHILE: WEND and _MOUSEWHEEL
« on: November 23, 2020, 09:57:32 pm »
https://www.qb64.org/forum/index.php?topic=3236.msg125173#msg125173

I updated my highlighting routine to include shift + mouse wheel highlighting... but...

I had to change the WHILE _MOUSEINPUT: WEND to wrap around the mouse calls, in order to get the wheel to register.

In other words, this doesn't work with _MOUSEWHEEL

    WHILE _MOUSEINPUT: WEND
        my% = _MOUSEY
        mx% = _MOUSEX
        lb% = _MOUSEBUTTON(1)
        mw% = mw% + _MOUSEWHEEL

but this does...

    WHILE _MOUSEINPUT
        my% = _MOUSEY
        mx% = _MOUSEX
        lb% = _MOUSEBUTTON(1)
        mw% = mw% + _MOUSEWHEEL
    WEND

The first way works fine, if the mouse wheel is not included.

I'm still using v1.3, if that makes any difference. I know the wiki example uses a DO/LOOP instead of WHILE/WEND.

Any thoughts of making the WHILE _MOUSEINPUT: WEND work with _MOUSEWHEEL, like it does with the other mouse calls?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #1 on: November 23, 2020, 10:16:47 pm »
https://www.qb64.org/forum/index.php?topic=3236.msg125173#msg125173

I updated my highlighting routine to include shift + mouse wheel highlighting... but...

I had to change the WHILE _MOUSEINPUT: WEND to wrap around the mouse calls, in order to get the wheel to register.

In other words, this doesn't work with _MOUSEWHEEL

    WHILE _MOUSEINPUT: WEND
        my% = _MOUSEY
        mx% = _MOUSEX
        lb% = _MOUSEBUTTON(1)
        mw% = mw% + _MOUSEWHEEL

but this does...

    WHILE _MOUSEINPUT
        my% = _MOUSEY
        mx% = _MOUSEX
        lb% = _MOUSEBUTTON(1)
        mw% = mw% + _MOUSEWHEEL
    WEND

The first way works fine, if the mouse wheel is not included.

I'm still using v1.3, if that makes any difference. I know the wiki example uses a DO/LOOP instead of WHILE/WEND.

Any thoughts of making the WHILE _MOUSEINPUT: WEND work with _MOUSEWHEEL, like it does with the other mouse calls?

Pete

Yes, that's right _MOUSEWHEEL has to be inside the loop. Learned that from Wiki under _MOUSEWHEEL.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #2 on: November 23, 2020, 10:21:59 pm »
Code: QB64: [Select]
  1.         mw% = mw% + _MOUSEWHEEL
  2. my% = _MOUSEY
  3. mx% = _MOUSEX
  4. lb% = _MOUSEBUTTON(1)

Go this route (points above). 

Think for just a moment on how your mouse works.  How many times do you press the button down in a second?  How many times can that mouse wheel click in a second? 

You’ll never have an event where you need to know what the mouse x/y position is, 1000 times a second, but you do need to count up the number of times that wheel scrolled in that second.

_MOUSEWHEEL is the only event that needs to be inside your update loop.



And from the wiki, you can see why:

“After an event has been read, the value resets to 0 automatically so cumulative position values must be added.”
« Last Edit: November 23, 2020, 10:24:57 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #3 on: November 23, 2020, 10:40:38 pm »
from the wiki on mouseinput

Quote
DO
  DO WHILE _MOUSEINPUT '      Check the mouse status
    PRINT _MOUSEX, _MOUSEY, _MOUSEBUTTON(1), _MOUSEWHEEL
  LOOP
LOOP UNTIL INKEY$ <> "" 

all the parameters are inside the loop what is the difference?
****
Also from the wiki
Quote
To clear all previous mouse data, use _MOUSEINPUT in a loop until it returns 0.
« Last Edit: November 23, 2020, 10:43:50 pm by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #4 on: November 23, 2020, 10:49:45 pm »
The way I learned it, _MOUSEWHEEL is accumulative thing that needs the constant update inside the LOOP with _MOUSEINPUT but the others mouse position or mouse buttons down you just want a snapshot of the latest info which is returned after you exit the _MOUSEINPUT loop usually with WHILE.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #5 on: November 23, 2020, 11:00:15 pm »
 Ya the code works but why?

Why do you need to accumulate the mouse wheel clicks?

a mouse wheel scrolls text one click at a time
****
from code posted above

The _mouseinput has detected mouse activity (_mousewheel) but does not update _mousewheel . Why

Quote
WHILE _MOUSEINPUT: WEND
        my% = _MOUSEY
        mx% = _MOUSEX
        lb% = _MOUSEBUTTON(1)
        mw% = mw% + _MOUSEWHEEL
« Last Edit: November 23, 2020, 11:15:22 pm by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #6 on: November 23, 2020, 11:11:01 pm »
Don't get me wrong, the mouse positions or the mouse buttons info works fine from inside the WHILE _MOUSEINPUT loop but the _MOUSEWHEEL sure doesn't work outside that loop.

As I said, I learned it as a logical rule you only want the latest info on position or button status but _MOUSEWHEEL accumulates a number of clicks only while inside the loop for scroll amounts usually though fun to use for other things as well.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #7 on: November 23, 2020, 11:12:55 pm »
Ya the code works but why?

Why do you need to accumulate the mouse wheel clicks?

When I use the wheel it scrolls one click at a time

Let’s look at the behavior up close.

You check and clear the mouse buffer....

A few milliseconds pass.

You check the buffer again for wheel events:

BUFFER START
wheel normal (0)
wheel down (-1)
wheel normal (0)
wheel down (-1)
wheel normal (0)
BUFFER STOP

As you can see, a mouse wheel isn’t just an “up or down” event.  It tracks “up (+1), down (-1), normal (0)”.  After every click, the wheel resets to normal (0), waiting for the next change.

If you only take that value of that last event state, it’s always going to be 0, as the wheel automatically resets back to 0 (normal) after a scroll.

Your button might have a “click and hold” event, but have you ever considered the wheel working in that same manner?  The wheel and the buttons are two completely different beasts.  (In fact, I think _DEVICES reads thewheel as an _AXIS, rather than a _BUTTON.)

Different tool, different required behavior to interact with it.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #8 on: November 23, 2020, 11:30:24 pm »
What would happen if there was a delay.

would _MOUSEWHEEL be 1 or -1  or 0

WHILE _MOUSEINPUT
        (a delay of one second)
        mw% = mw% + _MOUSEWHEEL
WEND
« Last Edit: November 23, 2020, 11:32:30 pm by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #9 on: November 23, 2020, 11:38:18 pm »
What would happen if there was a delay.

would _MOUSEWHEEL be 1 or -1  or 0

WHILE _MOUSEINPUT
        (a delay of one second)
        mw% = mw% + _MOUSEWHEEL
WEND

Doesn’t matter.  You read several hundred mouse events every few milliseconds...   x/y position, button 1,2,3 position, wheel events...   You toss a 1 second delay in there, it’d take 100 seconds to clear a millisecond’s buffer., which would have MORE events going in much faster than you’re reading them out.

It may not be an endless loop, but the lag would be so great you’d never do anything with your program with it.



You might could try something like:

WHILE  _MOUSEINPUT AND NOT _MOUSEWHEEL: WEND
« Last Edit: November 23, 2020, 11:41:21 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #10 on: November 24, 2020, 12:05:45 am »
Thanks all


**** code
WHILE _MOUSEINPUT: WEND
        my% = _MOUSEY
        mx% = _MOUSEX
        lb% = _MOUSEBUTTON(1)
****
why does it work for
_MOUSEY
 _MOUSEX
 _MOUSEBUTTON(1)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #11 on: November 24, 2020, 12:22:05 am »
Thanks all


**** code
WHILE _MOUSEINPUT: WEND
        my% = _MOUSEY
        mx% = _MOUSEX
        lb% = _MOUSEBUTTON(1)
****
why does it work for
_MOUSEY
 _MOUSEX
 _MOUSEBUTTON(1)

Because those variables hold the last known status of mouse since mouse was polled with:
Code: QB64: [Select]

Notice when read _MOUSEWHEEL here:
Code: QB64: [Select]
  1.         mw% = mw% + _MOUSEWHEEL
  2.  

We don't want to know the last _MOUSEWHEEL reading, no the variable above is counting up ALL the changes _MOUSEWHEEL reported WHILE there was _MOUSEINPUT and that's the info we want to work with the total of + or minus changes.
« Last Edit: November 24, 2020, 12:27:45 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #12 on: November 24, 2020, 12:27:51 am »
why does it work for
_MOUSEY
 _MOUSEX
 _MOUSEBUTTON(1)

We’re reading from a buffer a few nanoseconds long.

We read the buffer with the mouse in the top left corner: X = 0, Y = 0, Wheel = 0

3 nanoseconds later, we read the buffer again:

BUFFER START
0.5 Nanoseconds: Mouse X = 1
1.0 Nanoseconds: Y = 1
1.5 Nanoseconds: X = 2, Y = 2
2.0 Nanoseconds: Wheel = +1 (scrolled up)
2.5 Nanoseconds: Wheel = 0 (back to normal, after it “clicked”)
3.0 Nanoseconds: X = 3
BUFFER STOP

X = 3, Y = 2, Wheel = 0

Who cares what x and y was while in that buffer?  We’re only going to use the value of where it’s at currently in our program.

But that wheel?  At the moment we check it, what’s its current state?  It’s not at that perfect moment of “click”, so it’s back to normal.

You want to know where x/y is after you clear the buffer, but you want to know if the wheel changed at all during the buffer.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #13 on: November 24, 2020, 12:51:33 am »
Ok Thanks
****
 Gets the buffer size as well?
****
DO
IF _MOUSEINPUT  = 0  THEN EXIT DO
mw% = mw% + _MOUSEWHEEL
buffersize% = buffersize% + 1
LOOP

****
« Last Edit: November 24, 2020, 01:43:34 am by NOVARSEG »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: WHILE: WEND and _MOUSEWHEEL
« Reply #14 on: November 24, 2020, 01:40:43 am »
    WHILE _MOUSEINPUT
            mw% = mw% + _MOUSEWHEEL
    WEND
    my% = _MOUSEY
    mx% = _MOUSEX
    lb% = _MOUSEBUTTON(1)

Looks like a winner to me!

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/