Fixed on GIT MouseZ is always zero on MacOS...

SimonVD

Member
Tutorial Author
Joined
Dec 22, 2019
MouseZ value is always zero on MacOS, Mojave 10.14.6

Tested on targets: GLFW, HTML5 (Firefox and Safari)


Mouse Test:
Import mojo

Class MyApp Extends App

    
    Method OnRender()
    
        DrawText(("X: " + MouseX() + "~nY: " + MouseY() + "~nZ: " + MouseZ()).Split("~n"), DeviceWidth()/2, DeviceHeight()/2)
    
    End
End

Function Main()
    New MyApp
End
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
It only works on glfw and the value is always the difference to the last update, so you have to track the values somehow.
Try this one:

Cerberus X:
Import mojo

Class MyApp Extends App
    Field mouseRollCnt:Int = 0
   
    Method OnRender()
        Cls()
        mouseRollCnt +=MouseZ()
        DrawText(("X: " + MouseX() + "~nY: " + MouseY() + "~nZ: " + mouseRollCnt).Split("~n"), DeviceWidth()/2, DeviceHeight()/2)
   
    End
End

Function Main()
    New MyApp
End
 

SimonVD

Member
Tutorial Author
Joined
Dec 22, 2019
I quickly tried something like this for HTML5 target and it works but I'm open to suggestions.


Native/mousez_html5.js:
JS_MOUSE_Z = 0;

const trackWheel = function (e) {
    JS_MOUSE_Z = e.deltaY;
}

window.addEventListener("wheel", trackWheel);

MouseZ.cxs:
Import mojo

Import "native/mousez_html5.js"

Extern

Global JS_MOUSE_Z:Int= "JS_MOUSE_Z"



Public


Class MyApp Extends App
 
    Method OnRender()
        Cls()
        DrawText(("X: " + MouseX() + "~nY: " + MouseY() + "~nZ: " + JS_MOUSE_Z).Split("~n"), DeviceWidth()/2, DeviceHeight()/2)
       
    End
End

Function Main()
    New MyApp
End
 
Last edited:

wick

Member
3rd Party Module Dev
Patreon Bronze
Joined
Jul 17, 2017
Location
oakland
This works for me without having to do any extern/js stuff myself. Probably works for mojo1 as well?
Tested on GLFW, HTML5 (Chrome)

Key lines are:
- Import diddy
- MouseZInit() — somewhere in OnCreate
- diddy.externfunctions.MouseZ() — Difference in z since the last time you called this; should probably always cache it

Code:
Strict

Import mojo2
Import diddy

Class myApp Extends App

    Field myCanvas:Canvas
    field mouse_z:Float
    field scrolled:Int

    Method OnCreate:Int()   
        myCanvas = New Canvas()           

        MouseZInit()
       
        SetUpdateRate(0)
        Return 0
    End   
       
    Method OnUpdate:Int()
       
        mouse_z = diddy.externfunctions.MouseZ()
       
        scrolled += (20 * mouse_z)
       
        Return 0
    End

    Method OnRender:Int()
        myCanvas.Clear(0.2, 0.2, 0.2)
   
        myCanvas.SetColor(1,1,1)
        myCanvas.DrawText("X: " + MouseY() + "   Y: " + MouseX() + "   Z: " + mouse_z, 100,100)
        myCanvas.DrawText("Scrolled : " + scrolled, 100,200)
   
        myCanvas.SetColor(1,0,0)
        myCanvas.DrawRect(300, 300 - scrolled, 50,50)
       
        myCanvas.Flush()
        Return 0
    End

End


Function Main:Int()
    New myApp()
    Return 0
End
mousez.gif
 
Top Bottom