Skip to content

Handle canvas framebuffer scaling. #19844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
61 changes: 33 additions & 28 deletions src/library_glfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ var LibraryGLFW = {

if (GLFW.active.cursorPosFunc) {
#if USE_GLFW == 2
{{{ makeDynCall('vii', 'GLFW.active.cursorPosFunc') }}}(Browser.mouseX, Browser.mouseY);
{{{ makeDynCall('vii', 'GLFW.active.cursorPosFunc') }}}(Browser.mouseX / GLFW.scale, Browser.mouseY / GLFW.scale);
#endif
#if USE_GLFW == 3
{{{ makeDynCall('vidd', 'GLFW.active.cursorPosFunc') }}}(GLFW.active.id, Browser.mouseX, Browser.mouseY);
{{{ makeDynCall('vidd', 'GLFW.active.cursorPosFunc') }}}(GLFW.active.id, Browser.mouseX / GLFW.scale, Browser.mouseY / GLFW.scale);
#endif
}
},
Expand Down Expand Up @@ -918,13 +918,20 @@ var LibraryGLFW = {
},

getCursorPos: function(winid, x, y) {
{{{ makeSetValue('x', '0', 'Browser.mouseX', 'double') }}};
{{{ makeSetValue('y', '0', 'Browser.mouseY', 'double') }}};
var cx = Browser.mouseX / GLFW.scale;
var cy = Browser.mouseY / GLFW.scale;

if (x) {
{{{ makeSetValue('x', '0', 'cx', 'double') }}};
}

if (y) {
{{{ makeSetValue('y', '0', 'cy', 'double') }}};
}
},

getMousePos: function(winid, x, y) {
{{{ makeSetValue('x', '0', 'Browser.mouseX', 'i32') }}};
{{{ makeSetValue('y', '0', 'Browser.mouseY', 'i32') }}};
getCursorPos(winid, x, y);
},

setCursorPos: function(winid, x, y) {
Expand Down Expand Up @@ -957,14 +964,27 @@ var LibraryGLFW = {
},

getWindowSize: function(winid, width, height) {
var ww = 0;
var wh = 0;

var win = GLFW.WindowFromId(winid);
if (win) {
ww = win.width;
wh = win.height;
if (!win) return;

var ww = Module['canvas'].widthNative;
var wh = Module['canvas'].heightNative;

if (width) {
{{{ makeSetValue('width', '0', 'ww', 'i32') }}};
}

if (height) {
{{{ makeSetValue('height', '0', 'wh', 'i32') }}};
}
},

getFramebufferSize: function(winid, width, height) {
var win = GLFW.WindowFromId(winid);
if (!win) return;

var ww = Module['canvas'].width;
var wh = Module['canvas'].height;

if (width) {
{{{ makeSetValue('width', '0', 'ww', 'i32') }}};
Expand Down Expand Up @@ -1387,22 +1407,7 @@ var LibraryGLFW = {
},

glfwGetFramebufferSize: function(winid, width, height) {
var ww = 0;
var wh = 0;

var win = GLFW.WindowFromId(winid);
if (win) {
ww = win.width;
wh = win.height;
}

if (width) {
{{{ makeSetValue('width', '0', 'ww', 'i32') }}};
}

if (height) {
{{{ makeSetValue('height', '0', 'wh', 'i32') }}};
}
GLFW.getFramebufferSize(winid, width, height);
},

glfwGetWindowContentScale: function(winid, x, y) {
Expand Down