@@ -467,7 +467,7 @@ var LibraryGLFW = {
467
467
Browser . calculateMouseEvent ( event ) ;
468
468
}
469
469
470
- if ( event . target != Module [ 'canvas' ] || ! GLFW . active . cursorPosFunc ) return ;
470
+ if ( event . target != Browser . getCanvas ( ) || ! GLFW . active . cursorPosFunc ) return ;
471
471
472
472
if ( GLFW . active . cursorPosFunc ) {
473
473
#if USE_GLFW == 2
@@ -496,7 +496,7 @@ var LibraryGLFW = {
496
496
onMouseenter : ( event ) => {
497
497
if ( ! GLFW . active ) return ;
498
498
499
- if ( event . target != Module [ 'canvas' ] ) return ;
499
+ if ( event . target != Browser . getCanvas ( ) ) return ;
500
500
501
501
#if USE_GLFW == 3
502
502
if ( GLFW . active . cursorEnterFunc ) {
@@ -508,7 +508,7 @@ var LibraryGLFW = {
508
508
onMouseleave : ( event ) => {
509
509
if ( ! GLFW . active ) return ;
510
510
511
- if ( event . target != Module [ 'canvas' ] ) return ;
511
+ if ( event . target != Browser . getCanvas ( ) ) return ;
512
512
513
513
#if USE_GLFW == 3
514
514
if ( GLFW . active . cursorEnterFunc ) {
@@ -520,7 +520,7 @@ var LibraryGLFW = {
520
520
onMouseButtonChanged : ( event , status ) => {
521
521
if ( ! GLFW . active ) return ;
522
522
523
- if ( event . target != Module [ 'canvas' ] ) return ;
523
+ if ( event . target != Browser . getCanvas ( ) ) return ;
524
524
525
525
// Is this from a touch event?
526
526
const isTouchType = event . type === 'touchstart' || event . type === 'touchend' || event . type === 'touchcancel' ;
@@ -602,7 +602,7 @@ var LibraryGLFW = {
602
602
delta = ( delta == 0 ) ? 0 : ( delta > 0 ? Math . max ( delta , 1 ) : Math . min ( delta , - 1 ) ) ; // Quantize to integer so that minimum scroll is at least +/- 1.
603
603
GLFW . wheelPos += delta ;
604
604
605
- if ( ! GLFW . active || ! GLFW . active . scrollFunc || event . target != Module [ 'canvas' ] ) return ;
605
+ if ( ! GLFW . active || ! GLFW . active . scrollFunc || event . target != Browser . getCanvas ( ) ) return ;
606
606
#if USE_GLFW == 2
607
607
{ { { makeDynCall ( 'vi' , 'GLFW.active.scrollFunc' ) } } } ( GLFW . wheelPos ) ;
608
608
#endif
@@ -923,8 +923,9 @@ var LibraryGLFW = {
923
923
} ,
924
924
925
925
onClickRequestPointerLock : ( e ) => {
926
- if ( ! Browser . pointerLock && Module [ 'canvas' ] . requestPointerLock ) {
927
- Module [ 'canvas' ] . requestPointerLock ( ) ;
926
+ var canvas = Browser . getCanvas ( ) ;
927
+ if ( ! Browser . pointerLock && canvas . requestPointerLock ) {
928
+ canvas . requestPointerLock ( ) ;
928
929
e . preventDefault ( ) ;
929
930
}
930
931
} ,
@@ -935,11 +936,12 @@ var LibraryGLFW = {
935
936
936
937
switch ( mode ) {
937
938
case 0x00033001 : { // GLFW_CURSOR
939
+ var canvas = Browser . getCanvas ( ) ;
938
940
switch ( value ) {
939
941
case 0x00034001 : { // GLFW_CURSOR_NORMAL
940
942
win . inputModes [ mode ] = value ;
941
- Module [ ' canvas' ] . removeEventListener ( 'click' , GLFW . onClickRequestPointerLock , true ) ;
942
- Module [ ' canvas' ] . exitPointerLock ( ) ;
943
+ canvas . removeEventListener ( 'click' , GLFW . onClickRequestPointerLock , true ) ;
944
+ canvas . exitPointerLock ( ) ;
943
945
break ;
944
946
}
945
947
case 0x00034002 : { // GLFW_CURSOR_HIDDEN
@@ -948,8 +950,8 @@ var LibraryGLFW = {
948
950
}
949
951
case 0x00034003 : { // GLFW_CURSOR_DISABLED
950
952
win . inputModes [ mode ] = value ;
951
- Module [ ' canvas' ] . addEventListener ( 'click' , GLFW . onClickRequestPointerLock , true ) ;
952
- Module [ ' canvas' ] . requestPointerLock ( ) ;
953
+ canvas . addEventListener ( 'click' , GLFW . onClickRequestPointerLock , true ) ;
954
+ canvas . requestPointerLock ( ) ;
953
955
break ;
954
956
}
955
957
default : {
@@ -1088,6 +1090,9 @@ var LibraryGLFW = {
1088
1090
for ( i = 0 ; i < GLFW . windows . length && GLFW . windows [ i ] == null ; i ++ ) {
1089
1091
// no-op
1090
1092
}
1093
+
1094
+ const canvas = Browser . getCanvas ( ) ;
1095
+
1091
1096
var useWebGL = GLFW . hints [ 0x00022001 ] > 0 ; // Use WebGL when we are told to based on GLFW_CLIENT_API
1092
1097
if ( i == GLFW . windows . length ) {
1093
1098
if ( useWebGL ) {
@@ -1101,7 +1106,7 @@ var LibraryGLFW = {
1101
1106
// TODO: Make GLFW explicitly aware of whether it is being proxied or not, and set these to true only when proxying is being performed.
1102
1107
GL . enableOffscreenFramebufferAttributes ( contextAttributes ) ;
1103
1108
#endif
1104
- Browser . createContext ( Module [ ' canvas' ] , /*useWebGL=*/ true , /*setInModule=*/ true , contextAttributes ) ;
1109
+ Browser . createContext ( canvas , /*useWebGL=*/ true , /*setInModule=*/ true , contextAttributes ) ;
1105
1110
} else {
1106
1111
Browser . init ( ) ;
1107
1112
}
@@ -1111,7 +1116,6 @@ var LibraryGLFW = {
1111
1116
if ( ! Module [ 'ctx' ] && useWebGL ) return 0 ;
1112
1117
1113
1118
// Initializes the framebuffer size from the canvas
1114
- const canvas = Module [ 'canvas' ] ;
1115
1119
var win = new GLFW_Window ( id , width , height , canvas . width , canvas . height , title , monitor , share ) ;
1116
1120
1117
1121
// Set window to array
@@ -1157,7 +1161,7 @@ var LibraryGLFW = {
1157
1161
if ( typeof Browser . lockPointer == 'undefined' ) Browser . lockPointer = true ;
1158
1162
if ( typeof Browser . resizeCanvas == 'undefined' ) Browser . resizeCanvas = false ;
1159
1163
1160
- var canvas = Module [ 'canvas' ] ;
1164
+ var canvas = Browser . getCanvas ( ) ;
1161
1165
function fullscreenChange ( ) {
1162
1166
Browser . isFullscreen = false ;
1163
1167
var canvasContainer = canvas . parentNode ;
@@ -1262,7 +1266,7 @@ var LibraryGLFW = {
1262
1266
calculateMouseCoords ( pageX , pageY ) {
1263
1267
// Calculate the movement based on the changes
1264
1268
// in the coordinates.
1265
- const rect = Module [ 'canvas' ] . getBoundingClientRect ( ) ;
1269
+ const rect = Browser . getCanvas ( ) . getBoundingClientRect ( ) ;
1266
1270
1267
1271
// Neither .scrollX or .pageXOffset are defined in a spec, but
1268
1272
// we prefer .scrollX because it is currently in a spec draft.
@@ -1319,7 +1323,7 @@ var LibraryGLFW = {
1319
1323
1320
1324
adjustCanvasDimensions ( ) {
1321
1325
if ( GLFW . active ) {
1322
- Browser . updateCanvasDimensions ( Module [ 'canvas' ] , GLFW . active . width , GLFW . active . height ) ;
1326
+ Browser . updateCanvasDimensions ( Browser . getCanvas ( ) , GLFW . active . width , GLFW . active . height ) ;
1323
1327
Browser . updateResizeListeners ( ) ;
1324
1328
}
1325
1329
} ,
@@ -1395,19 +1399,20 @@ var LibraryGLFW = {
1395
1399
GLFW . devicePixelRatioMQL = window . matchMedia ( '(resolution: ' + GLFW . getDevicePixelRatio ( ) + 'dppx)' ) ;
1396
1400
GLFW . devicePixelRatioMQL . addEventListener ( 'change' , GLFW . onDevicePixelRatioChange ) ;
1397
1401
1398
- Module [ 'canvas' ] . addEventListener ( 'touchmove' , GLFW . onMousemove , true ) ;
1399
- Module [ 'canvas' ] . addEventListener ( 'touchstart' , GLFW . onMouseButtonDown , true ) ;
1400
- Module [ 'canvas' ] . addEventListener ( 'touchcancel' , GLFW . onMouseButtonUp , true ) ;
1401
- Module [ 'canvas' ] . addEventListener ( 'touchend' , GLFW . onMouseButtonUp , true ) ;
1402
- Module [ 'canvas' ] . addEventListener ( 'mousemove' , GLFW . onMousemove , true ) ;
1403
- Module [ 'canvas' ] . addEventListener ( 'mousedown' , GLFW . onMouseButtonDown , true ) ;
1404
- Module [ 'canvas' ] . addEventListener ( 'mouseup' , GLFW . onMouseButtonUp , true ) ;
1405
- Module [ 'canvas' ] . addEventListener ( 'wheel' , GLFW . onMouseWheel , true ) ;
1406
- Module [ 'canvas' ] . addEventListener ( 'mousewheel' , GLFW . onMouseWheel , true ) ;
1407
- Module [ 'canvas' ] . addEventListener ( 'mouseenter' , GLFW . onMouseenter , true ) ;
1408
- Module [ 'canvas' ] . addEventListener ( 'mouseleave' , GLFW . onMouseleave , true ) ;
1409
- Module [ 'canvas' ] . addEventListener ( 'drop' , GLFW . onDrop , true ) ;
1410
- Module [ 'canvas' ] . addEventListener ( 'dragover' , GLFW . onDragover , true ) ;
1402
+ var canvas = Browser . getCanvas ( ) ;
1403
+ canvas . addEventListener ( 'touchmove' , GLFW . onMousemove , true ) ;
1404
+ canvas . addEventListener ( 'touchstart' , GLFW . onMouseButtonDown , true ) ;
1405
+ canvas . addEventListener ( 'touchcancel' , GLFW . onMouseButtonUp , true ) ;
1406
+ canvas . addEventListener ( 'touchend' , GLFW . onMouseButtonUp , true ) ;
1407
+ canvas . addEventListener ( 'mousemove' , GLFW . onMousemove , true ) ;
1408
+ canvas . addEventListener ( 'mousedown' , GLFW . onMouseButtonDown , true ) ;
1409
+ canvas . addEventListener ( "mouseup" , GLFW . onMouseButtonUp , true ) ;
1410
+ canvas . addEventListener ( 'wheel' , GLFW . onMouseWheel , true ) ;
1411
+ canvas . addEventListener ( 'mousewheel' , GLFW . onMouseWheel , true ) ;
1412
+ canvas . addEventListener ( 'mouseenter' , GLFW . onMouseenter , true ) ;
1413
+ canvas . addEventListener ( 'mouseleave' , GLFW . onMouseleave , true ) ;
1414
+ canvas . addEventListener ( 'drop' , GLFW . onDrop , true ) ;
1415
+ canvas . addEventListener ( 'dragover' , GLFW . onDragover , true ) ;
1411
1416
1412
1417
// Overriding implementation to account for HiDPI
1413
1418
Browser . requestFullscreen = GLFW . requestFullscreen ;
@@ -1416,7 +1421,7 @@ var LibraryGLFW = {
1416
1421
1417
1422
Browser . resizeListeners . push ( ( width , height ) => {
1418
1423
if ( GLFW . isHiDPIAware ( ) ) {
1419
- var canvas = Module [ 'canvas' ] ;
1424
+ var canvas = Browser . getCanvas ( ) ;
1420
1425
GLFW . onCanvasResize ( canvas . clientWidth , canvas . clientHeight , width , height ) ;
1421
1426
} else {
1422
1427
GLFW . onCanvasResize ( width , height , width , height ) ;
@@ -1433,24 +1438,25 @@ var LibraryGLFW = {
1433
1438
window . removeEventListener ( 'keypress' , GLFW . onKeyPress , true ) ;
1434
1439
window . removeEventListener ( 'keyup' , GLFW . onKeyup , true ) ;
1435
1440
window . removeEventListener ( 'blur' , GLFW . onBlur , true ) ;
1436
- Module [ 'canvas' ] . removeEventListener ( 'touchmove' , GLFW . onMousemove , true ) ;
1437
- Module [ 'canvas' ] . removeEventListener ( 'touchstart' , GLFW . onMouseButtonDown , true ) ;
1438
- Module [ 'canvas' ] . removeEventListener ( 'touchcancel' , GLFW . onMouseButtonUp , true ) ;
1439
- Module [ 'canvas' ] . removeEventListener ( 'touchend' , GLFW . onMouseButtonUp , true ) ;
1440
- Module [ 'canvas' ] . removeEventListener ( 'mousemove' , GLFW . onMousemove , true ) ;
1441
- Module [ 'canvas' ] . removeEventListener ( 'mousedown' , GLFW . onMouseButtonDown , true ) ;
1442
- Module [ 'canvas' ] . removeEventListener ( 'mouseup' , GLFW . onMouseButtonUp , true ) ;
1443
- Module [ 'canvas' ] . removeEventListener ( 'wheel' , GLFW . onMouseWheel , true ) ;
1444
- Module [ 'canvas' ] . removeEventListener ( 'mousewheel' , GLFW . onMouseWheel , true ) ;
1445
- Module [ 'canvas' ] . removeEventListener ( 'mouseenter' , GLFW . onMouseenter , true ) ;
1446
- Module [ 'canvas' ] . removeEventListener ( 'mouseleave' , GLFW . onMouseleave , true ) ;
1447
- Module [ 'canvas' ] . removeEventListener ( 'drop' , GLFW . onDrop , true ) ;
1448
- Module [ 'canvas' ] . removeEventListener ( 'dragover' , GLFW . onDragover , true ) ;
1441
+ var canvas = Browser . getCanvas ( ) ;
1442
+ canvas . removeEventListener ( 'touchmove' , GLFW . onMousemove , true ) ;
1443
+ canvas . removeEventListener ( 'touchstart' , GLFW . onMouseButtonDown , true ) ;
1444
+ canvas . removeEventListener ( 'touchcancel' , GLFW . onMouseButtonUp , true ) ;
1445
+ canvas . removeEventListener ( 'touchend' , GLFW . onMouseButtonUp , true ) ;
1446
+ canvas . removeEventListener ( 'mousemove' , GLFW . onMousemove , true ) ;
1447
+ canvas . removeEventListener ( 'mousedown' , GLFW . onMouseButtonDown , true ) ;
1448
+ canvas . removeEventListener ( 'mouseup' , GLFW . onMouseButtonUp , true ) ;
1449
+ canvas . removeEventListener ( 'wheel' , GLFW . onMouseWheel , true ) ;
1450
+ canvas . removeEventListener ( 'mousewheel' , GLFW . onMouseWheel , true ) ;
1451
+ canvas . removeEventListener ( 'mouseenter' , GLFW . onMouseenter , true ) ;
1452
+ canvas . removeEventListener ( 'mouseleave' , GLFW . onMouseleave , true ) ;
1453
+ canvas . removeEventListener ( 'drop' , GLFW . onDrop , true ) ;
1454
+ canvas . removeEventListener ( 'dragover' , GLFW . onDragover , true ) ;
1449
1455
1450
1456
if ( GLFW . devicePixelRatioMQL )
1451
1457
GLFW . devicePixelRatioMQL . removeEventListener ( 'change' , GLFW . onDevicePixelRatioChange ) ;
1452
1458
1453
- Module [ ' canvas' ] . width = Module [ ' canvas' ] . height = 1 ;
1459
+ canvas . width = canvas . height = 1 ;
1454
1460
GLFW . windows = null ;
1455
1461
GLFW . active = null ;
1456
1462
} ,
0 commit comments