blitz-foundation / monkey2

zlib License
3 stars 0 forks source link

Small conflict Mouse vs Touch using emscriptem on Touch device #68

Open Pharmhaus-2 opened 5 years ago

Pharmhaus-2 commented 5 years ago

Original Author: abakobo

On a touch device running an emscriptem mx2 app, the "Mouse" constant will return Mouse.ButtonDown(MouseButton.Left)=True while touched but the Mouse.Location will be (0,0) so it is not usable for that device+target combination (mobile+emscriptem) Touch is working great though, but the mouse is not activating touch.

So it would be nice if Mouse.Location() was returning the touch position of Finger(0). Or, if not possible, that Mouse.ButtonPressed/Down/Released was not returning true when the screen is touched.

This would avoid some hacky control code lines (if Mouse.Location<>Vec2(0,0)) when dealing with emscriptem apps as they are supposed to be used on both desktop and mobiles and there is no way (afaik) to know for sure if we are on a desktop or a mobile when running an emscriptem app.

Pharmhaus-2 commented 5 years ago

@abakobo Can this be reproduced using one of the bananas?

abakobo commented 5 years ago

Any banana using mouse.Buttonxxx() and Mouse.Location() will do the trick. Basically you can do the following.

#Import "<std>"
#Import "<mojo>"

Using std..
Using mojo..

Class MyWindow Extends Window

    Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )

        Super.New( title,width,height,flags )
    End

    Method OnRender( canvas:Canvas ) Override

        App.RequestRender()
        canvas.DrawText("click or touch to see mouse/touch coordinates",10,10)
        If Mouse.ButtonDown(MouseButton.Left) Then canvas.DrawText( "touch/mouse Location"+Mouse.Location,Width/2,Height/2,.5,.5 )
    End
End

Function Main()
    New AppInstance
    New MyWindow
    App.Run()
End