@@ -46,8 +46,6 @@ var LibrarySDL = {
46
46
textInput : false ,
47
47
48
48
startTime : null ,
49
- mouseX : 0 ,
50
- mouseY : 0 ,
51
49
buttonState : 0 ,
52
50
DOMButtons : [ 0 , 0 , 0 ] ,
53
51
@@ -515,54 +513,22 @@ var LibrarySDL = {
515
513
}
516
514
// fall through
517
515
case 'mousemove' : {
518
- if ( Browser . pointerLock ) {
519
- // When the pointer is locked, calculate the coordinates
520
- // based on the movement of the mouse.
521
- // Workaround for Firefox bug 764498
522
- if ( event . type != 'mousemove' &&
523
- ( 'mozMovementX' in event ) ) {
524
- var movementX = 0 , movementY = 0 ;
525
- } else {
526
- var movementX = Browser . getMovementX ( event ) ;
527
- var movementY = Browser . getMovementY ( event ) ;
528
- }
529
- var x = SDL . mouseX + movementX ;
530
- var y = SDL . mouseY + movementY ;
531
- } else {
532
- // Otherwise, calculate the movement based on the changes
533
- // in the coordinates.
534
- var rect = Module [ "canvas" ] . getBoundingClientRect ( ) ;
535
- var x = event . pageX - ( window . scrollX + rect . left ) ;
536
- var y = event . pageY - ( window . scrollY + rect . top ) ;
537
-
538
- // the canvas might be CSS-scaled compared to its backbuffer;
539
- // SDL-using content will want mouse coordinates in terms
540
- // of backbuffer units.
541
- var cw = Module [ "canvas" ] . width ;
542
- var ch = Module [ "canvas" ] . height ;
543
- x = x * ( cw / rect . width ) ;
544
- y = y * ( ch / rect . height ) ;
545
-
546
- var movementX = x - SDL . mouseX ;
547
- var movementY = y - SDL . mouseY ;
548
- }
516
+ Browser . calculateMouseMove ( event ) ;
549
517
if ( event . type != 'mousemove' ) {
550
518
var down = event . type === 'mousedown' ;
551
519
{ { { makeSetValue ( 'ptr' , 'SDL.structs.MouseButtonEvent.type' , 'SDL.DOMEventToSDLEvent[event.type]' , 'i32' ) } } } ;
552
520
{ { { makeSetValue ( 'ptr' , 'SDL.structs.MouseButtonEvent.button' , 'event.button+1' , 'i8' ) } } } ; // DOM buttons are 0-2, SDL 1-3
553
521
{ { { makeSetValue ( 'ptr' , 'SDL.structs.MouseButtonEvent.state' , 'down ? 1 : 0' , 'i8' ) } } } ;
554
- { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseButtonEvent.x' , 'x ' , 'i32' ) } } } ;
555
- { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseButtonEvent.y' , 'y ' , 'i32' ) } } } ;
522
+ { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseButtonEvent.x' , 'Browser.mouseX ' , 'i32' ) } } } ;
523
+ { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseButtonEvent.y' , 'Browser.mouseY ' , 'i32' ) } } } ;
556
524
} else {
557
525
{ { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.type' , 'SDL.DOMEventToSDLEvent[event.type]' , 'i32' ) } } } ;
558
526
{ { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.state' , 'SDL.buttonState' , 'i8' ) } } } ;
559
- { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.x' , 'x ' , 'i32' ) } } } ;
560
- { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.y' , 'y ' , 'i32' ) } } } ;
561
- { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.xrel' , 'movementX ' , 'i32' ) } } } ;
562
- { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.yrel' , 'movementY ' , 'i32' ) } } } ;
527
+ { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.x' , 'Browser.mouseX ' , 'i32' ) } } } ;
528
+ { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.y' , 'Browser.mouseY ' , 'i32' ) } } } ;
529
+ { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.xrel' , 'Browser.mouseMovementX ' , 'i32' ) } } } ;
530
+ { { { makeSetValue ( 'ptr' , 'SDL.structs.MouseMotionEvent.yrel' , 'Browser.mouseMovementY ' , 'i32' ) } } } ;
563
531
}
564
- SDL . mouseX = x ;
565
- SDL . mouseY = y ;
566
532
break ;
567
533
}
568
534
case 'unload' : {
@@ -924,8 +890,8 @@ var LibrarySDL = {
924
890
} ,
925
891
926
892
SDL_GetMouseState : function ( x , y ) {
927
- if ( x ) { { { makeSetValue ( 'x' , '0' , 'SDL .mouseX' , 'i32' ) } } } ;
928
- if ( y ) { { { makeSetValue ( 'y' , '0' , 'SDL .mouseY' , 'i32' ) } } } ;
893
+ if ( x ) { { { makeSetValue ( 'x' , '0' , 'Browser .mouseX' , 'i32' ) } } } ;
894
+ if ( y ) { { { makeSetValue ( 'y' , '0' , 'Browser .mouseY' , 'i32' ) } } } ;
929
895
return SDL . buttonState ;
930
896
} ,
931
897
0 commit comments