Topic: Why no response to mouse wheel?

Trying to interact with the mouse on graphics primitives.  Program below recognizes Mouse-LB-down. But it cannot sense movement of the mouse wheel. Why?

program main
use appgraphics
implicit none
    integer::screen
    integer::x, y, r, i
    logical::pt=.FALSE.,whL=.FALSE.
    common whL, r
    x=10
    y=10
    r=20   
    screen = initwindow(800, 600)
    call registermousehandler(MOUSE_LB_DOWN,mcirc)
    call registermousehandler(MOUSE_WHEEL,mcirc)   
    call settextstyle(1,0,20)   
    do while(x <= 800)
      call clearviewport
      call mcirc
      IF (whL) THEN
        y=y-40
      ENDIF
      call circle(x,y,r)     
      call outtextxy(x,y,char(r),pt)
      i=0
      do while(i < 20000000)
         i=i+1
      end do
      x=x+5
      y=y+5
      r=r+1
    end do
    call delay(1)
    call closewindow(screen)
end program main

subroutine mcirc
use appgraphics
    implicit none
    integer mx, my, r
    logical whL
    common whL, r
    if (ismouseclick(MOUSE_WHEEL)) THEN
        whL = .TRUE.
    endif
    if (ismouseclick(MOUSE_LB_DOWN)) then
        mx = mousex()
        my = mousey()
        call circle(mx,my,2*r)
        call clearmouseclick(MOUSE_LB_DOWN)
        ! call clearmouseclick(MOUSE_WHEEL)
    endif       
end subroutine mcirc

Re: Why no response to mouse wheel?

The documentation for whatever reason doesn't explain this behaivor, but ismouseclick always returns .false. for MOUSE_WHEEL events.  I think the reasoning on this decision is that a wheel event certainly isn't a "click."  I would suggest using a separate subroutine to catch the mouse wheel events.

By the way, the subroutine mcirc should accept two integer arguments that specify the mouse position or, in the case of a mouse wheel even, the change in x and zero.

I'll make sure the documentation is updated and maybe look through the mouse handling code to see that everything is consistent.  Thank you for pointing this out.

Jeff Armstrong
Approximatrix, LLC

Re: Why no response to mouse wheel?

Looking through the underlying code a bit more, the MOUSE_WHEEL events are not queued, in contrast to clicks, which are queued.  The call to the callback procedure is the only way to handle wheel events.  Clicks, on the other hand, could be handled elsewhere.  The ismouseclick and getmouseclick subroutines rely on calls to the queues, which wouldn't apply in this case.

The API isn't ideal, but it should have been documented better.

Jeff Armstrong
Approximatrix, LLC

Re: Why no response to mouse wheel?

Umm . . . "the call to the callback procedure" ??

Re: Why no response to mouse wheel?

Still do not see how I can know if the mouse wheel has been turned.  And, if turned, in which direction. Are you saying that I should have used  Getmouseclick(kind, x,y) ?

Re: Why no response to mouse wheel?

Perhaps a new function?  "Getmousewheel()"   It could return an integer: -1 = backward motion, 0 = no motion, +1 = forward motion.

Re: Why no response to mouse wheel?

Sorry, I meant that you should connect a different subroutine to the mouse wheel events, like this:

program main
use appgraphics
implicit none
    integer::screen
    integer::x, y, r, i
    logical::pt=.FALSE.,whL=.FALSE.
    common whL, r
    
    interface
        subroutine mouseclick(mx, my)
        integer::mx, my
        end subroutine mouseclick
    end interface
    
    interface
        subroutine mousewheel(wx, wignored)
        integer::wx, wignored
        end subroutine mousewheel
    end interface
    
    x=10
    y=10
    r=20   
    screen = initwindow(800, 600)
    call registermousehandler(MOUSE_LB_DOWN,mouseclick)
    call registermousehandler(MOUSE_WHEEL,mousewheel)   
    call settextstyle(1,0,20)   
    do while(x <= 800)
      call clearviewport
      IF (whL) THEN
        y=y-40
      ENDIF
      call circle(x,y,r)     
      call outtextxy(x,y,char(r),pt)
      i=0
      do while(i < 20000000)
         i=i+1
      end do
      x=x+5
      y=y+5
      r=r+1
    end do
    call delay(1)
    call closewindow(screen)
end program main

subroutine mouseclick(mx, my)
use appgraphics
    implicit none
    integer mx, my, r
    logical whL
    common whL, r
    if (ismouseclick(MOUSE_LB_DOWN)) then
        call circle(mx,my,2*r)
        call clearmouseclick(MOUSE_LB_DOWN)
        ! call clearmouseclick(MOUSE_WHEEL)
    endif       
end subroutine mouseclick

subroutine mousewheel(wx, wignored)
use appgraphics
    implicit none
    integer wx, wignored, r
    logical whL
    common whL, r
        whL = .TRUE.
end subroutine mousewheel

Note that the calls to registermousehandler use two different subroutines.  Also, the click handler is passed in the coordinates at the time of the click.

Jeff Armstrong
Approximatrix, LLC

Re: Why no response to mouse wheel?

Thanks Jeff.  Appreciate all the work.