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)
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");
92 var
image = ctx.createImageData(w, h);
93 var
data = image.data;
94 var
src = pixels >> 2;
97 if (typeof CanvasPixelArray !==
'undefined' && data instanceof CanvasPixelArray) {
105 data[
dst ] = val & 0xff;
106 data[dst+1] = (val >> 8) & 0xff;
107 data[dst+2] = (val >> 16) & 0xff;
108 data[dst+3] = (val >> 24) & 0xff;
113 var data32 =
new Int32Array(data.buffer);
115 data32.set(HEAP32.subarray(src, src + num));
118 ctx.putImageData(image, 0, 0);
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";
170 cursor_name =
"not-allowed";
173 cursor_name =
"pointer";
180 return Emscripten_CreateCursorFromString(cursor_name,
SDL_FALSE);
190 if (curdata !=
NULL) {
211 if (Module[
'canvas']) {
212 Module[
'canvas'].style[
'cursor'] = Module[
'Pointer_stringify']($0);
220 if (Module[
'canvas']) {
221 Module[
'canvas'].style[
'cursor'] =
'none';
240 if(emscripten_request_pointerlock(
NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
244 if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {
#define SDL_ConvertSurfaceFormat
SDL_Mouse * SDL_GetMouse(void)
int(* ShowCursor)(SDL_Cursor *cursor)
GLint GLint GLint GLint GLint x
int(* SetRelativeMouseMode)(SDL_bool enabled)
void Emscripten_FiniMouse()
GLfloat GLfloat GLfloat GLfloat h
A collection of pixels used in software blitting.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
GLubyte GLubyte GLubyte GLubyte w
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
GLint GLint GLint GLint GLint GLint y
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
GLenum GLenum GLsizei const GLuint GLboolean enabled
void(* FreeCursor)(SDL_Cursor *cursor)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
#define SDL_GetMouseFocus
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
void(* WarpMouse)(SDL_Window *window, int x, int y)
const char * system_cursor
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
#define SDL_Unsupported()
void Emscripten_InitMouse()
int uint32_t uint32_t uint32_t uint32_t uint32_t int drmModeModeInfoPtr mode int uint32_t uint32_t uint32_t uint32_t int32_t hot_x