Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ See docs/process.md for more on how version tagging works.
3.1.33 (in development)
-----------------------
- Update SDL2_ttf port to 2.20.2 (#18804)
- Update glfw header to 3.3.8 (#18826)
- The `LLD_REPORT_UNDEFINED` setting has been removed. It's now essentially
always enabled. (#18342)

Expand Down
134 changes: 134 additions & 0 deletions src/library_glfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ var LibraryGLFW = {
this.windowRefreshFunc = null; // GLFWwindowrefreshfun
this.windowFocusFunc = null; // GLFWwindowfocusfun
this.windowIconifyFunc = null; // GLFWwindowiconifyfun
this.windowMaximizeFunc = null; // GLFWwindowmaximizefun
this.framebufferSizeFunc = null; // GLFWframebuffersizefun
this.windowContentScaleFunc = null; // GLFWwindowcontentscalefun
this.mouseButtonFunc = null; // GLFWmousebuttonfun
this.cursorPosFunc = null; // GLFWcursorposfun
this.cursorEnterFunc = null; // GLFWcursorenterfun
Expand All @@ -95,6 +97,7 @@ var LibraryGLFW = {
errorFunc: null, // GLFWerrorfun
monitorFunc: null, // GLFWmonitorfun
active: null, // active window
scale: null,
windows: null,
monitors: null,
monitorString: null,
Expand All @@ -108,6 +111,8 @@ var LibraryGLFW = {
0x00020003:1, // GLFW_RESIZABLE
0x00020004:1, // GLFW_VISIBLE
0x00020005:1, // GLFW_DECORATED
0x0002000A:0, // GLFW_TRANSPARENT_FRAMEBUFFER
0x0002200C:0, // GLFW_SCALE_TO_MONITOR. can we emulate this?

0x00021001:8, // GLFW_RED_BITS
0x00021002:8, // GLFW_GREEN_BITS
Expand Down Expand Up @@ -350,6 +355,7 @@ var LibraryGLFW = {
if (win.keys[341]) mod |= 0x0002; // GLFW_MOD_CONTROL
if (win.keys[342]) mod |= 0x0004; // GLFW_MOD_ALT
if (win.keys[343]) mod |= 0x0008; // GLFW_MOD_SUPER
// add caps and num lock keys? only if lock_key_mod is set
return mod;
},

Expand Down Expand Up @@ -609,6 +615,15 @@ var LibraryGLFW = {
#endif
},

onWindowContentScaleChanged: function(scale) {
GLFW.scale = scale;
if (!GLFW.active) return;

#if USE_GLFW == 3
{{{ makeDynCall('viff', 'GLFW.active.windowContentScaleFunc') }}}(GLFW.active.id, GLFW.scale, GLFW.scale);
#endif
},

getTime: function() {
return _emscripten_get_now() / 1000;
},
Expand Down Expand Up @@ -873,6 +888,14 @@ var LibraryGLFW = {
out("glfwSetInputMode called with GLFW_STICKY_MOUSE_BUTTONS mode not implemented.");
break;
}
case 0x00033004: { // GLFW_LOCK_KEY_MODS
out("glfwSetInputMode called with GLFW_LOCK_KEY_MODS mode not implemented.");
break;
}
case 0x000330005: { // GLFW_RAW_MOUSE_MOTION
out("glfwSetInputMode called with GLFW_RAW_MOUSE_MOTION mode not implemented.");
break;
}
default: {
out("glfwSetInputMode called with unknown mode parameter value: " + mode + ".");
break;
Expand Down Expand Up @@ -1098,6 +1121,7 @@ var LibraryGLFW = {
/*******************************************************************************
* GLFW FUNCTIONS
******************************************************************************/
glfwInit__deps: ['emscripten_get_device_pixel_ratio'],
glfwInit__sig: 'i',
glfwInit: function() {
if (GLFW.windows) return 1; // GL_TRUE
Expand All @@ -1106,13 +1130,22 @@ var LibraryGLFW = {
GLFW.hints = GLFW.defaultHints;
GLFW.windows = new Array()
GLFW.active = null;
GLFW.scale = _emscripten_get_device_pixel_ratio();


window.addEventListener("gamepadconnected", GLFW.onGamepadConnected, true);
window.addEventListener("gamepaddisconnected", GLFW.onGamepadDisconnected, true);
window.addEventListener("keydown", GLFW.onKeydown, true);
window.addEventListener("keypress", GLFW.onKeyPress, true);
window.addEventListener("keyup", GLFW.onKeyup, true);
window.addEventListener("blur", GLFW.onBlur, true);
// from https://stackoverflow.com/a/70514686/7484780 . maybe add this to browser.js?
// no idea how to remove this listener.
(function updatePixelRatio(){
window.matchMedia("(resolution: " + window.devicePixelRatio + "dppx)")
.addEventListener('change', updatePixelRatio, {once: true});
GLFW.onWindowContentScaleChanged(_emscripten_get_device_pixel_ratio());
})();
Module["canvas"].addEventListener("touchmove", GLFW.onMousemove, true);
Module["canvas"].addEventListener("touchstart", GLFW.onMouseButtonDown, true);
Module["canvas"].addEventListener("touchcancel", GLFW.onMouseButtonUp, true);
Expand Down Expand Up @@ -1257,6 +1290,15 @@ var LibraryGLFW = {
{{{ makeSetValue('y', '0', '0', 'i32') }}};
},

glfwGetMonitorWorkarea__sig: 'viiiii',
glfwGetMonitorWorkarea: function(monitor, x, y, w, h) {
{{{ makeSetValue('x', '0', '0', 'i32') }}};
{{{ makeSetValue('y', '0', '0', 'i32') }}};

{{{ makeSetValue('w', '0', 'screen.availWidth', 'i32') }}};
{{{ makeSetValue('h', '0', 'screen.availHeight', 'i32') }}};
},

glfwGetMonitorPhysicalSize__sig: 'viii',
glfwGetMonitorPhysicalSize: function(monitor, width, height) {
// AFAIK there is no way to do this in javascript
Expand All @@ -1267,6 +1309,12 @@ var LibraryGLFW = {
{{{ makeSetValue('height', '0', '0', 'i32') }}};
},

glfwGetMonitorContentScale__sig: 'viii',
glfwGetMonitorContentScale: function(monitor, x, y) {
{{{ makeSetValue('x', '0', 'GLFW.scale', 'float') }}};
{{{ makeSetValue('y', '0', 'GLFW.scale', 'float') }}};
},

glfwGetMonitorName__sig: 'ii',
glfwGetMonitorName: function(mon) {
if (!GLFW.monitorString) {
Expand Down Expand Up @@ -1317,6 +1365,13 @@ var LibraryGLFW = {
GLFW.hints[target] = hint;
},

glfwWindowHintString__sig: 'vii',
glfwWindowHintString: function(hint, value) {
// from glfw docs -> we just ignore this.
// Some hints are platform specific. These may be set on any platform but they
// will only affect their specific platform. Other platforms will ignore them.
},

glfwCreateWindow__sig: 'iiiiii',
glfwCreateWindow: function(width, height, title, monitor, share) {
return GLFW.createWindow(width, height, title, monitor, share);
Expand Down Expand Up @@ -1386,6 +1441,24 @@ var LibraryGLFW = {
}
},

glfwGetWindowContentScale__sig: 'viii',
glfwGetWindowContentScale: function(winid, x, y) {
// winid doesn't matter. all windows will use same scale anyway.
// hope i used this makeSetValue correctly
{{{ makeSetValue('x', '0', 'GLFW.scale', 'float') }}};
{{{ makeSetValue('y', '0', 'GLFW.scale', 'float') }}};
},

glfwGetWindowOpacity__sig: 'fi',
glfwGetWindowOpacity: function(winid) {
return 1.0;
},

glfwSetWindowOpacity__sig: 'vif',
glfwSetWindowOpacity: function(winid, opacity) {
// error
},

glfwIconifyWindow__sig: 'vi',
glfwIconifyWindow: function(winid) {
#if ASSERTIONS
Expand Down Expand Up @@ -1420,6 +1493,13 @@ var LibraryGLFW = {
return win.attributes[attrib];
},

glfwSetWindowAttrib__sig: 'viii',
glfwSetWindowAttrib: function(winid, attrib, value) {
var win = GLFW.WindowFromId(winid);
if (!win) return;
win.attributes[attrib] = value;
},

glfwSetWindowUserPointer__sig: 'vii',
glfwSetWindowUserPointer: function(winid, ptr) {
var win = GLFW.WindowFromId(winid);
Expand Down Expand Up @@ -1476,6 +1556,15 @@ var LibraryGLFW = {
return prevcbfun;
},

glfwSetWindowMaximizeCallback__sig: 'iii',
glfwSetWindowMaximizeCallback: function(winid, cbfun) {
var win = GLFW.WindowFromId(winid);
if (!win) return null;
var prevcbfun = win.windowMaximizeFunc;
win.windowMaximizeFunc = cbfun;
return prevcbfun;
},

glfwSetWindowIcon__sig: 'viii',
glfwSetWindowIcon: function(winid, count, images) {},

Expand All @@ -1494,6 +1583,9 @@ var LibraryGLFW = {
glfwFocusWindow__sig: 'vi',
glfwFocusWindow: function(winid) {},

glfwRequestWindowAttention__sig: 'vi',
glfwRequestWindowAttention: function(winid) {}, // maybe do window.focus()?

glfwSetWindowMonitor__sig: 'viiiiiii',
glfwSetWindowMonitor: function(winid, monitor, xpos, ypos, width, height, refreshRate) { throw "glfwSetWindowMonitor not implemented."; },

Expand All @@ -1518,6 +1610,15 @@ var LibraryGLFW = {
return prevcbfun;
},

glfwSetWindowContentScaleCallback_sig: 'iii',
glfwSetWindowContentScaleCallback: function(winid, cbfun) {
var win = GLFW.WindowFromId(winid);
if (!win) return null;
var prevcbfun = win.windowContentScaleFunc;
win.windowContentScaleFunc = cbfun;
return prevcbfun;
},

glfwGetInputMode__sig: 'iii',
glfwGetInputMode: function(winid, mode) {
var win = GLFW.WindowFromId(winid);
Expand All @@ -1541,6 +1642,11 @@ var LibraryGLFW = {
GLFW.setInputMode(winid, mode, value);
},

glfwRawMouseMotionSupported__sig: 'i',
glfwRawMouseMotionSupported: function() {
return 0;
},

glfwGetKey__sig: 'iii',
glfwGetKey: function(winid, key) {
return GLFW.getKey(winid, key);
Expand All @@ -1549,6 +1655,9 @@ var LibraryGLFW = {
glfwGetKeyName__sig: 'iii',
glfwGetKeyName: function(key, scancode) { throw "glfwGetKeyName not implemented."; },

glfwGetKeyScancode__sig: 'ii',
glfwGetKeyScancode: function(key) { throw "glfwGetKeyScancode not implemented."; },

glfwGetMouseButton__sig: 'iii',
glfwGetMouseButton: function(winid, button) {
return GLFW.getMouseButton(winid, button);
Expand Down Expand Up @@ -1665,6 +1774,11 @@ var LibraryGLFW = {
return state.buttons;
},

glfwGetJoystickHats__sig: 'iii',
glfwGetJoystickHats: function(joy, count) {
throw "glfwGetJoystickHats is not implemented";
},

glfwGetJoystickName__sig: 'ii',
glfwGetJoystickName: function(joy) {
if (GLFW.joys[joy]) {
Expand All @@ -1673,6 +1787,26 @@ var LibraryGLFW = {
return 0;
},

glfwGetJoystickGUID__sig: 'ii',
glfwGetJoystickGUID: function(jid) {
throw "glfwGetJoystickGUID not implemented";
},

glfwSetJoystickUserPointer__sig: 'vii',
glfwSetJoystickUserPointer: function(jid, ptr) {
throw "glfwSetJoystickUserPointer not implemented";
},

glfwGetJoystickUserPointer__sig: 'ii',
glfwGetJoystickUserPointer: function(jid) {
throw "glfwSetJoystickUserPointer not implemented";
},

glfwJoystickIsGamepad__sig: 'ii',
glfwJoystickIsGamepad: function(jid) {
throw "glfwSetJoystickUserPointer not implemented";
},

glfwSetJoystickCallback__sig: 'ii',
glfwSetJoystickCallback: function(cbfun) {
GLFW.setJoystickCallback(cbfun);
Expand Down
Loading