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
This commit is contained in:
Johannes Bader 2017-11-04 11:16:49 +00:00
parent bb8c3a9cc2
commit 1724313349
1 changed files with 7 additions and 3 deletions

View File

@ -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);