Hexworks / zircon

Zircon is an extensible and user-friendly, multiplatform tile engine.
https://hexworks.org/projects/zircon/
Apache License 2.0
753 stars 137 forks source link

MouseEventType.MOUSE_WHEEL_ROTATED_UP not getting triggered #321

Closed sku0x20 closed 4 years ago

sku0x20 commented 4 years ago

Describe the bug MouseEventType.MOUSE_WHEEL_ROTATED_UP is not getting triggered, whereas MouseEventType.MOUSE_WHEEL_ROTATED_DOWN works just fine. I tried both 'handleMouseEvents' and 'processMouseEvents' but nothing seems working.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'ScrollBarExample.kt' provided in examples
  2. Add handleMouseEvents or processMouseEvents on scrollbar1
  3. Run the example
  4. See if MouseEventType.MOUSE_WHEEL_ROTATED_UP is triggered when scroll wheel is scrolled up

Expected behavior MouseEventType.MOUSE_WHEEL_ROTATED_UP should be triggered

Screenshots NONE

Desktop (please complete the following information):

Smartphone (please complete the following information): NONE

Additional context I tried using LibgdxApplications in place of SwingApplications but still same result moreover now MOUSE_WHEEL_ROTATED_DOWN is also broken.

adam-arold commented 4 years ago

@siddhantkumar20 did you try this on a regular Ubuntu? I'm gonna fire up a live cd to reproduce this but I don't know how ZorinOS works.

sku0x20 commented 4 years ago

@adam-arold hey I found the cause. The bug was occurring due to

(0..e.preciseWheelRotation.toInt()).forEach {  
    processMouseEvent(actionType, e)  
}

in function "mouseWheelMoved" in file "MouseEventListener.kt" in zircon.jvm.swing. When e.preciseWheelRotation() is negative the forEach loop does not get executed therefore processMouseEvent(actionType, e) is unable to run, causing this issue. In my simple solution, I wrapped the e.preciseWheelRotation.toInt() with abs() function and everything seems to work fine.

(0..abs(e.preciseWheelRotation.toInt())).forEach {
    processMouseEvent(actionType, e)
}

Thanks for responding so fast to this issue.

adam-arold commented 4 years ago

I'm gonna take a look into this. We have to make sure that your proposed fix doesn't break other platforms. Thanks for looking into this, your help is invaluable! 👍

adam-arold commented 4 years ago

@siddhantkumar20 can you open a PR with your changes? Then I can test them on other platforms and we can call it a day if it works.

sku0x20 commented 4 years ago

@adam-arold I am a beginner and I am just learning things, I created the pull request #322 but I do not know if its the right way to do. Thanks for paying attention to this issue. I hope to become like you guys someday.

adam-arold commented 4 years ago

Don't worry what you did is exactly what was needed! I'm gonna try the examples and see whether it breaks something then we can merge your PR.