Emscripten: use cursor hotspot
authorJohannes Bader <olydis@users.noreply.github.com>
Sat, 04 Nov 2017 11:16:49 +0000
changeset 116739c7602bf7385
parent 11672 cf6fe791a6ee
child 11674 3f1de86751e4
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
     1.1 --- a/src/video/emscripten/SDL_emscriptenmouse.c	Thu Nov 02 10:41:55 2017 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenmouse.c	Sat Nov 04 11:16:49 2017 +0000
     1.3 @@ -79,7 +79,9 @@
     1.4      cursor_url = (const char *)EM_ASM_INT({
     1.5          var w = $0;
     1.6          var h = $1;
     1.7 -        var pixels = $2;
     1.8 +        var hot_x = $2;
     1.9 +        var hot_y = $3;
    1.10 +        var pixels = $4;
    1.11  
    1.12          var canvas = document.createElement("canvas");
    1.13          canvas.width = w;
    1.14 @@ -114,13 +116,15 @@
    1.15          }
    1.16  
    1.17          ctx.putImageData(image, 0, 0);
    1.18 -        var url = "url(" + canvas.toDataURL() + "), auto";
    1.19 +        var url = hot_x === 0 && hot_y === 0
    1.20 +            ? "url(" + canvas.toDataURL() + "), auto"
    1.21 +            : "url(" + canvas.toDataURL() + ") " + hot_x + " " + hot_y + ", auto";
    1.22  
    1.23          var urlBuf = _malloc(url.length + 1);
    1.24          stringToUTF8(url, urlBuf, url.length + 1);
    1.25  
    1.26          return urlBuf;
    1.27 -    }, surface->w, surface->h, conv_surf->pixels);
    1.28 +    }, surface->w, surface->h, hot_x, hot_y, conv_surf->pixels);
    1.29  
    1.30      SDL_FreeSurface(conv_surf);
    1.31