Skip to content

Commit

Permalink
Emscripten: use cursor hotspot
Browse files Browse the repository at this point in the history
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
  • Loading branch information
olydis committed Nov 4, 2017
1 parent bb8c3a9 commit 1724313
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/video/emscripten/SDL_emscriptenmouse.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1724313

Please sign in to comment.