From 1724313349b598711af4d7ce87efa2e7dbf8e2be Mon Sep 17 00:00:00 2001 From: Johannes Bader Date: Sat, 4 Nov 2017 11:16:49 +0000 Subject: [PATCH] Emscripten: use cursor hotspot the cursor's hotspot simply wasn't translated to it's CSS equivalent, yet see https://developer.mozilla.org/en-US/docs/Web/CSS/cursor?v=example#Syntax. no explicit hotspot if (0|0) for compatibility with Edge and IE, which indeed don't support custom hot spots --- src/video/emscripten/SDL_emscriptenmouse.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c index 8232dac32..837acd61f 100644 --- a/src/video/emscripten/SDL_emscriptenmouse.c +++ b/src/video/emscripten/SDL_emscriptenmouse.c @@ -79,7 +79,9 @@ Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y) cursor_url = (const char *)EM_ASM_INT({ var w = $0; var h = $1; - var pixels = $2; + var hot_x = $2; + var hot_y = $3; + var pixels = $4; var canvas = document.createElement("canvas"); canvas.width = w; @@ -114,13 +116,15 @@ Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y) } ctx.putImageData(image, 0, 0); - var url = "url(" + canvas.toDataURL() + "), auto"; + var url = hot_x === 0 && hot_y === 0 + ? "url(" + canvas.toDataURL() + "), auto" + : "url(" + canvas.toDataURL() + ") " + hot_x + " " + hot_y + ", auto"; var urlBuf = _malloc(url.length + 1); stringToUTF8(url, urlBuf, url.length + 1); return urlBuf; - }, surface->w, surface->h, conv_surf->pixels); + }, surface->w, surface->h, hot_x, hot_y, conv_surf->pixels); SDL_FreeSurface(conv_surf);