23 #include "../../SDL_internal.h"
25 #if SDL_VIDEO_DRIVER_EMSCRIPTEN
27 #include <emscripten/emscripten.h>
28 #include <emscripten/html5.h>
32 #include "../../events/SDL_mouse_c.h"
36 Emscripten_CreateCursorFromString(
const char* cursor_str,
SDL_bool is_custom)
39 Emscripten_CursorData *curdata;
43 curdata = (Emscripten_CursorData *)
SDL_calloc(1,
sizeof(*curdata));
50 curdata->system_cursor = cursor_str;
51 curdata->is_custom = is_custom;
62 Emscripten_CreateDefaultCursor()
64 return Emscripten_CreateCursorFromString(
"default",
SDL_FALSE);
70 const char *cursor_url =
NULL;
79 cursor_url = (
const char *)EM_ASM_INT({
86 var canvas = document.createElement(
"canvas");
90 var
ctx = canvas.getContext(
"2d");
97 if (typeof CanvasPixelArray !==
'undefined' &&
data instanceof CanvasPixelArray) {
113 var data32 =
new Int32Array(
data.buffer);
115 data32.set(HEAP32.subarray(
src,
src +
num));
119 var url =
hot_x === 0 && hot_y === 0
120 ?
"url(" + canvas.toDataURL() +
"), auto"
121 :
"url(" + canvas.toDataURL() +
") " +
hot_x +
" " + hot_y +
", auto";
123 var urlBuf = _malloc(url.length + 1);
124 stringToUTF8(url, urlBuf, url.length + 1);
131 return Emscripten_CreateCursorFromString(cursor_url,
SDL_TRUE);
137 const char *cursor_name =
NULL;
141 cursor_name =
"default";
144 cursor_name =
"text";
147 cursor_name =
"wait";
150 cursor_name =
"crosshair";
153 cursor_name =
"progress";
156 cursor_name =
"nwse-resize";
159 cursor_name =
"nesw-resize";
162 cursor_name =
"ew-resize";
165 cursor_name =
"ns-resize";
168 cursor_name =
"move";
171 cursor_name =
"not-allowed";
174 cursor_name =
"pointer";
181 return Emscripten_CreateCursorFromString(cursor_name,
SDL_FALSE);
187 Emscripten_CursorData *curdata;
191 if (curdata !=
NULL) {
192 if (curdata->is_custom) {
193 SDL_free((
char *)curdata->system_cursor);
205 Emscripten_CursorData *curdata;
210 if(curdata->system_cursor) {
212 if (Module[
'canvas']) {
213 Module[
'canvas'].style[
'cursor'] = UTF8ToString($0);
216 }, curdata->system_cursor);
221 if (Module[
'canvas']) {
222 Module[
'canvas'].style[
'cursor'] =
'none';
241 if(emscripten_request_pointerlock(
NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
245 if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {