@@ -68,7 +68,9 @@ var LibraryGLFW = {
68
68
this . windowRefreshFunc = null ; // GLFWwindowrefreshfun
69
69
this . windowFocusFunc = null ; // GLFWwindowfocusfun
70
70
this . windowIconifyFunc = null ; // GLFWwindowiconifyfun
71
+ this . windowMaximizeFunc = null ; // GLFWwindowmaximizefun
71
72
this . framebufferSizeFunc = null ; // GLFWframebuffersizefun
73
+ this . windowContentScaleFunc = null ; // GLFWwindowcontentscalefun
72
74
this . mouseButtonFunc = null ; // GLFWmousebuttonfun
73
75
this . cursorPosFunc = null ; // GLFWcursorposfun
74
76
this . cursorEnterFunc = null ; // GLFWcursorenterfun
@@ -95,6 +97,7 @@ var LibraryGLFW = {
95
97
errorFunc : null , // GLFWerrorfun
96
98
monitorFunc : null , // GLFWmonitorfun
97
99
active : null , // active window
100
+ scale : null ,
98
101
windows : null ,
99
102
monitors : null ,
100
103
monitorString : null ,
@@ -108,6 +111,8 @@ var LibraryGLFW = {
108
111
0x00020003 :1 , // GLFW_RESIZABLE
109
112
0x00020004 :1 , // GLFW_VISIBLE
110
113
0x00020005 :1 , // GLFW_DECORATED
114
+ 0x0002000A :0 , // GLFW_TRANSPARENT_FRAMEBUFFER
115
+ 0x0002200C :0 , // GLFW_SCALE_TO_MONITOR. can we emulate this?
111
116
112
117
0x00021001 :8 , // GLFW_RED_BITS
113
118
0x00021002 :8 , // GLFW_GREEN_BITS
@@ -350,6 +355,7 @@ var LibraryGLFW = {
350
355
if ( win . keys [ 341 ] ) mod |= 0x0002 ; // GLFW_MOD_CONTROL
351
356
if ( win . keys [ 342 ] ) mod |= 0x0004 ; // GLFW_MOD_ALT
352
357
if ( win . keys [ 343 ] ) mod |= 0x0008 ; // GLFW_MOD_SUPER
358
+ // add caps and num lock keys? only if lock_key_mod is set
353
359
return mod ;
354
360
} ,
355
361
@@ -609,6 +615,15 @@ var LibraryGLFW = {
609
615
#endif
610
616
} ,
611
617
618
+ onWindowContentScaleChanged : function ( scale ) {
619
+ GLFW . scale = scale ;
620
+ if ( ! GLFW . active ) return ;
621
+
622
+ #if USE_GLFW == 3
623
+ { { { makeDynCall ( 'viff' , 'GLFW.active.windowContentScaleFunc' ) } } } ( GLFW . active . id , GLFW . scale , GLFW . scale ) ;
624
+ #endif
625
+ } ,
626
+
612
627
getTime : function ( ) {
613
628
return _emscripten_get_now ( ) / 1000 ;
614
629
} ,
@@ -873,6 +888,14 @@ var LibraryGLFW = {
873
888
out ( "glfwSetInputMode called with GLFW_STICKY_MOUSE_BUTTONS mode not implemented." ) ;
874
889
break ;
875
890
}
891
+ case 0x00033004 : { // GLFW_LOCK_KEY_MODS
892
+ out ( "glfwSetInputMode called with GLFW_LOCK_KEY_MODS mode not implemented." ) ;
893
+ break ;
894
+ }
895
+ case 0x000330005 : { // GLFW_RAW_MOUSE_MOTION
896
+ out ( "glfwSetInputMode called with GLFW_RAW_MOUSE_MOTION mode not implemented." ) ;
897
+ break ;
898
+ }
876
899
default : {
877
900
out ( "glfwSetInputMode called with unknown mode parameter value: " + mode + "." ) ;
878
901
break ;
@@ -1098,6 +1121,7 @@ var LibraryGLFW = {
1098
1121
/*******************************************************************************
1099
1122
* GLFW FUNCTIONS
1100
1123
******************************************************************************/
1124
+ glfwInit__deps : [ 'emscripten_get_device_pixel_ratio' ] ,
1101
1125
glfwInit__sig : 'i' ,
1102
1126
glfwInit : function ( ) {
1103
1127
if ( GLFW . windows ) return 1 ; // GL_TRUE
@@ -1106,13 +1130,22 @@ var LibraryGLFW = {
1106
1130
GLFW . hints = GLFW . defaultHints ;
1107
1131
GLFW . windows = new Array ( )
1108
1132
GLFW . active = null ;
1133
+ GLFW . scale = _emscripten_get_device_pixel_ratio ( ) ;
1134
+
1109
1135
1110
1136
window . addEventListener ( "gamepadconnected" , GLFW . onGamepadConnected , true ) ;
1111
1137
window . addEventListener ( "gamepaddisconnected" , GLFW . onGamepadDisconnected , true ) ;
1112
1138
window . addEventListener ( "keydown" , GLFW . onKeydown , true ) ;
1113
1139
window . addEventListener ( "keypress" , GLFW . onKeyPress , true ) ;
1114
1140
window . addEventListener ( "keyup" , GLFW . onKeyup , true ) ;
1115
1141
window . addEventListener ( "blur" , GLFW . onBlur , true ) ;
1142
+ // from https://stackoverflow.com/a/70514686/7484780 . maybe add this to browser.js?
1143
+ // no idea how to remove this listener.
1144
+ ( function updatePixelRatio ( ) {
1145
+ window . matchMedia ( "(resolution: " + window . devicePixelRatio + "dppx)" )
1146
+ . addEventListener ( 'change' , updatePixelRatio , { once : true } ) ;
1147
+ GLFW . onWindowContentScaleChanged ( _emscripten_get_device_pixel_ratio ( ) ) ;
1148
+ } ) ( ) ;
1116
1149
Module [ "canvas" ] . addEventListener ( "touchmove" , GLFW . onMousemove , true ) ;
1117
1150
Module [ "canvas" ] . addEventListener ( "touchstart" , GLFW . onMouseButtonDown , true ) ;
1118
1151
Module [ "canvas" ] . addEventListener ( "touchcancel" , GLFW . onMouseButtonUp , true ) ;
@@ -1257,6 +1290,15 @@ var LibraryGLFW = {
1257
1290
{ { { makeSetValue ( 'y' , '0' , '0' , 'i32' ) } } } ;
1258
1291
} ,
1259
1292
1293
+ glfwGetMonitorWorkarea__sig : 'viiiii' ,
1294
+ glfwGetMonitorWorkarea : function ( monitor , x , y , w , h ) {
1295
+ { { { makeSetValue ( 'x' , '0' , '0' , 'i32' ) } } } ;
1296
+ { { { makeSetValue ( 'y' , '0' , '0' , 'i32' ) } } } ;
1297
+
1298
+ { { { makeSetValue ( 'w' , '0' , 'screen.availWidth' , 'i32' ) } } } ;
1299
+ { { { makeSetValue ( 'h' , '0' , 'screen.availHeight' , 'i32' ) } } } ;
1300
+ } ,
1301
+
1260
1302
glfwGetMonitorPhysicalSize__sig : 'viii' ,
1261
1303
glfwGetMonitorPhysicalSize : function ( monitor , width , height ) {
1262
1304
// AFAIK there is no way to do this in javascript
@@ -1267,6 +1309,12 @@ var LibraryGLFW = {
1267
1309
{ { { makeSetValue ( 'height' , '0' , '0' , 'i32' ) } } } ;
1268
1310
} ,
1269
1311
1312
+ glfwGetMonitorContentScale__sig : 'viii' ,
1313
+ glfwGetMonitorContentScale : function ( monitor , x , y ) {
1314
+ { { { makeSetValue ( 'x' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1315
+ { { { makeSetValue ( 'y' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1316
+ } ,
1317
+
1270
1318
glfwGetMonitorName__sig : 'ii' ,
1271
1319
glfwGetMonitorName : function ( mon ) {
1272
1320
if ( ! GLFW . monitorString ) {
@@ -1317,6 +1365,13 @@ var LibraryGLFW = {
1317
1365
GLFW . hints [ target ] = hint ;
1318
1366
} ,
1319
1367
1368
+ glfwWindowHintString__sig : 'vii' ,
1369
+ glfwWindowHintString : function ( hint , value ) {
1370
+ // from glfw docs -> we just ignore this.
1371
+ // Some hints are platform specific. These may be set on any platform but they
1372
+ // will only affect their specific platform. Other platforms will ignore them.
1373
+ } ,
1374
+
1320
1375
glfwCreateWindow__sig : 'iiiiii' ,
1321
1376
glfwCreateWindow : function ( width , height , title , monitor , share ) {
1322
1377
return GLFW . createWindow ( width , height , title , monitor , share ) ;
@@ -1386,6 +1441,24 @@ var LibraryGLFW = {
1386
1441
}
1387
1442
} ,
1388
1443
1444
+ glfwGetWindowContentScale__sig : 'viii' ,
1445
+ glfwGetWindowContentScale : function ( winid , x , y ) {
1446
+ // winid doesn't matter. all windows will use same scale anyway.
1447
+ // hope i used this makeSetValue correctly
1448
+ { { { makeSetValue ( 'x' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1449
+ { { { makeSetValue ( 'y' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1450
+ } ,
1451
+
1452
+ glfwGetWindowOpacity__sig : 'fi' ,
1453
+ glfwGetWindowOpacity : function ( winid ) {
1454
+ return 1.0 ;
1455
+ } ,
1456
+
1457
+ glfwSetWindowOpacity__sig : 'vif' ,
1458
+ glfwSetWindowOpacity : function ( winid , opacity ) {
1459
+ // error
1460
+ } ,
1461
+
1389
1462
glfwIconifyWindow__sig : 'vi' ,
1390
1463
glfwIconifyWindow : function ( winid ) {
1391
1464
#if ASSERTIONS
@@ -1420,6 +1493,13 @@ var LibraryGLFW = {
1420
1493
return win . attributes [ attrib ] ;
1421
1494
} ,
1422
1495
1496
+ glfwSetWindowAttrib__sig : 'viii' ,
1497
+ glfwSetWindowAttrib : function ( winid , attrib , value ) {
1498
+ var win = GLFW . WindowFromId ( winid ) ;
1499
+ if ( ! win ) return ;
1500
+ win . attributes [ attrib ] = value ;
1501
+ } ,
1502
+
1423
1503
glfwSetWindowUserPointer__sig : 'vii' ,
1424
1504
glfwSetWindowUserPointer : function ( winid , ptr ) {
1425
1505
var win = GLFW . WindowFromId ( winid ) ;
@@ -1476,6 +1556,15 @@ var LibraryGLFW = {
1476
1556
return prevcbfun ;
1477
1557
} ,
1478
1558
1559
+ glfwSetWindowMaximizeCallback__sig : 'iii' ,
1560
+ glfwSetWindowMaximizeCallback : function ( winid , cbfun ) {
1561
+ var win = GLFW . WindowFromId ( winid ) ;
1562
+ if ( ! win ) return null ;
1563
+ var prevcbfun = win . windowMaximizeFunc ;
1564
+ win . windowMaximizeFunc = cbfun ;
1565
+ return prevcbfun ;
1566
+ } ,
1567
+
1479
1568
glfwSetWindowIcon__sig : 'viii' ,
1480
1569
glfwSetWindowIcon : function ( winid , count , images ) { } ,
1481
1570
@@ -1494,6 +1583,9 @@ var LibraryGLFW = {
1494
1583
glfwFocusWindow__sig : 'vi' ,
1495
1584
glfwFocusWindow : function ( winid ) { } ,
1496
1585
1586
+ glfwRequestWindowAttention__sig : 'vi' ,
1587
+ glfwRequestWindowAttention : function ( winid ) { } , // maybe do window.focus()?
1588
+
1497
1589
glfwSetWindowMonitor__sig : 'viiiiiii' ,
1498
1590
glfwSetWindowMonitor : function ( winid , monitor , xpos , ypos , width , height , refreshRate ) { throw "glfwSetWindowMonitor not implemented." ; } ,
1499
1591
@@ -1518,6 +1610,15 @@ var LibraryGLFW = {
1518
1610
return prevcbfun ;
1519
1611
} ,
1520
1612
1613
+ glfwSetWindowContentScaleCallback_sig : 'iii' ,
1614
+ glfwSetWindowContentScaleCallback : function ( winid , cbfun ) {
1615
+ var win = GLFW . WindowFromId ( winid ) ;
1616
+ if ( ! win ) return null ;
1617
+ var prevcbfun = win . windowContentScaleFunc ;
1618
+ win . windowContentScaleFunc = cbfun ;
1619
+ return prevcbfun ;
1620
+ } ,
1621
+
1521
1622
glfwGetInputMode__sig : 'iii' ,
1522
1623
glfwGetInputMode : function ( winid , mode ) {
1523
1624
var win = GLFW . WindowFromId ( winid ) ;
@@ -1541,6 +1642,11 @@ var LibraryGLFW = {
1541
1642
GLFW . setInputMode ( winid , mode , value ) ;
1542
1643
} ,
1543
1644
1645
+ glfwRawMouseMotionSupported__sig : 'i' ,
1646
+ glfwRawMouseMotionSupported : function ( ) {
1647
+ return 0 ;
1648
+ } ,
1649
+
1544
1650
glfwGetKey__sig : 'iii' ,
1545
1651
glfwGetKey : function ( winid , key ) {
1546
1652
return GLFW . getKey ( winid , key ) ;
@@ -1549,6 +1655,9 @@ var LibraryGLFW = {
1549
1655
glfwGetKeyName__sig : 'iii' ,
1550
1656
glfwGetKeyName : function ( key , scancode ) { throw "glfwGetKeyName not implemented." ; } ,
1551
1657
1658
+ glfwGetKeyScancode__sig : 'ii' ,
1659
+ glfwGetKeyScancode : function ( key ) { throw "glfwGetKeyScancode not implemented." ; } ,
1660
+
1552
1661
glfwGetMouseButton__sig : 'iii' ,
1553
1662
glfwGetMouseButton : function ( winid , button ) {
1554
1663
return GLFW . getMouseButton ( winid , button ) ;
@@ -1665,6 +1774,11 @@ var LibraryGLFW = {
1665
1774
return state . buttons ;
1666
1775
} ,
1667
1776
1777
+ glfwGetJoystickHats__sig : 'iii' ,
1778
+ glfwGetJoystickHats : function ( joy , count ) {
1779
+ throw "glfwGetJoystickHats is not implemented" ;
1780
+ } ,
1781
+
1668
1782
glfwGetJoystickName__sig : 'ii' ,
1669
1783
glfwGetJoystickName : function ( joy ) {
1670
1784
if ( GLFW . joys [ joy ] ) {
@@ -1673,6 +1787,26 @@ var LibraryGLFW = {
1673
1787
return 0 ;
1674
1788
} ,
1675
1789
1790
+ glfwGetJoystickGUID__sig : 'ii' ,
1791
+ glfwGetJoystickGUID : function ( jid ) {
1792
+ throw "glfwGetJoystickGUID not implemented" ;
1793
+ } ,
1794
+
1795
+ glfwSetJoystickUserPointer__sig : 'vii' ,
1796
+ glfwSetJoystickUserPointer : function ( jid , ptr ) {
1797
+ throw "glfwSetJoystickUserPointer not implemented" ;
1798
+ } ,
1799
+
1800
+ glfwGetJoystickUserPointer__sig : 'ii' ,
1801
+ glfwGetJoystickUserPointer : function ( jid ) {
1802
+ throw "glfwSetJoystickUserPointer not implemented" ;
1803
+ } ,
1804
+
1805
+ glfwJoystickIsGamepad__sig : 'ii' ,
1806
+ glfwJoystickIsGamepad : function ( jid ) {
1807
+ throw "glfwSetJoystickUserPointer not implemented" ;
1808
+ } ,
1809
+
1676
1810
glfwSetJoystickCallback__sig : 'ii' ,
1677
1811
glfwSetJoystickCallback : function ( cbfun ) {
1678
1812
GLFW . setJoystickCallback ( cbfun ) ;
0 commit comments