touchtest.monkey2 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. Using std..
  5. Using mojo..
  6. Class MyWindow Extends Window
  7. Field gesturing:Bool
  8. Field g0:AffineMat3f
  9. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )
  10. Super.New( title,width,height,flags )
  11. End
  12. Method GestureMatrix:AffineMat3f( p0:Vec2f,p1:Vec2f )
  13. Local d:=p1-p0,r:=-ATan2( d.y,d.x ),s:=d.Length
  14. Return New AffineMat3f().Translate( p0 ).Rotate( r ).Scale( s,s )
  15. End
  16. Method OnRender( canvas:Canvas ) Override
  17. App.RequestRender()
  18. Local gmatrix:=New AffineMat3f
  19. If Not gesturing And Touch.FingerDown( 0 ) And Touch.FingerDown( 1 )
  20. 'begin gesturing
  21. g0=-GestureMatrix( Touch.FingerLocation( 0 ),Touch.FingerLocation( 1 ) )
  22. gesturing=True
  23. Endif
  24. If gesturing And Touch.FingerDown( 0 ) And Touch.FingerDown( 1 )
  25. 'gesturing...
  26. gmatrix=GestureMatrix( Touch.FingerLocation( 0 ),Touch.FingerLocation( 1 ) ) * g0
  27. Else If gesturing
  28. 'end gesturing
  29. gesturing=False
  30. Endif
  31. canvas.PushMatrix()
  32. canvas.Matrix=gmatrix
  33. For Local i:=0 Until 8
  34. For Local j:=0 Until 8
  35. canvas.Color= (i~j)&1 ? Color.Yellow Else Color.Grey
  36. canvas.DrawRect( New Recti( i*Width/8,j*Height/8,(i+1)*Width/8,(j+1)*Height/8 ) )
  37. Next
  38. Next
  39. canvas.PopMatrix()
  40. canvas.Color=Color.White
  41. canvas.Scale( 2,2 )
  42. For Local i:=0 Until 10
  43. canvas.DrawText( "Finger "+i+": down="+Int( Touch.FingerDown(i) )+", location="+Touch.FingerLocation(i)+", pressure="+Touch.FingerPressure(i),0,i*canvas.Font.Height )
  44. Next
  45. End
  46. End
  47. Function Main()
  48. New AppInstance
  49. New MyWindow
  50. App.Run()
  51. End