Update emscripten mouse handling
This commit is contained in:
parent
b98c4e031d
commit
3a25602074
1 changed files with 6 additions and 20 deletions
|
|
@ -1723,32 +1723,18 @@ static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseE
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Get mouse position in canvas CSS pixels
|
// Get mouse position in canvas CSS pixels
|
||||||
float mouseCssX = (float)mouseEvent->canvasX;
|
float mouseCssX = (float)mouseEvent->targetX;
|
||||||
float mouseCssY = (float)mouseEvent->canvasY;
|
float mouseCssY = (float)mouseEvent->targetY;
|
||||||
|
|
||||||
// Get canvas sizes
|
// Get canvas sizes
|
||||||
double cssWidth = 0.0;
|
double cssWidth = 0.0;
|
||||||
double cssHeight = 0.0;
|
double cssHeight = 0.0;
|
||||||
emscripten_get_element_css_size(platform.canvasId, &cssWidth, &cssHeight);
|
emscripten_get_element_css_size(platform.canvasId, &cssWidth, &cssHeight);
|
||||||
|
|
||||||
int fbWidth = 0;
|
float normalizedX = mouseCssX/(float)cssWidth;
|
||||||
int fbHeight = 0;
|
float normalizedY = mouseCssY/(float)cssHeight;
|
||||||
emscripten_get_canvas_element_size(platform.canvasId, &fbWidth, &fbHeight);
|
CORE.Input.Mouse.currentPosition.x = normalizedX*(float)CORE.Window.screen.width;
|
||||||
|
CORE.Input.Mouse.currentPosition.y = normalizedY*(float)CORE.Window.screen.height;
|
||||||
// Convert CSS to framebuffer coordinates
|
|
||||||
float scaleX = (float)fbWidth/(float)cssWidth;
|
|
||||||
float scaleY = (float)fbHeight/(float)cssHeight;
|
|
||||||
|
|
||||||
int mouseX = (int)(mouseCssX*scaleX);
|
|
||||||
int mouseY = (int)(mouseCssY*scaleY);
|
|
||||||
|
|
||||||
CORE.Input.Mouse.currentPosition.x = mouseX;//(float)mouseEvent->canvasX;
|
|
||||||
CORE.Input.Mouse.currentPosition.y = mouseY;//(float)mouseEvent->canvasY;
|
|
||||||
|
|
||||||
// Shorter alternative:
|
|
||||||
//double dpr = emscripten_get_device_pixel_ratio();
|
|
||||||
//int mouseX = (int)(e->canvasX*dpr);
|
|
||||||
//int mouseY = (int)(e->canvasY*dpr);
|
|
||||||
|
|
||||||
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue