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({
84 var canvas = document.createElement(
"canvas");
88 var
ctx = canvas.getContext(
"2d");
90 var
image = ctx.createImageData(w, h);
91 var
data = image.data;
92 var
src = pixels >> 2;
95 if (typeof CanvasPixelArray !==
'undefined' && data instanceof CanvasPixelArray) {
103 data[
dst ] = val & 0xff;
104 data[dst+1] = (val >> 8) & 0xff;
105 data[dst+2] = (val >> 16) & 0xff;
106 data[dst+3] = (val >> 24) & 0xff;
111 var data32 =
new Int32Array(data.buffer);
113 data32.set(HEAP32.subarray(src, src + num));
116 ctx.putImageData(image, 0, 0);
117 var url =
"url(" + canvas.toDataURL() +
"), auto";
119 var urlBuf = _malloc(url.length + 1);
120 stringToUTF8(url, urlBuf, url.length + 1);
123 }, surface->
w, surface->
h, conv_surf->
pixels);
127 return Emscripten_CreateCursorFromString(cursor_url,
SDL_TRUE);
133 const char *cursor_name =
NULL;
137 cursor_name =
"default";
140 cursor_name =
"text";
143 cursor_name =
"wait";
146 cursor_name =
"crosshair";
149 cursor_name =
"progress";
152 cursor_name =
"nwse-resize";
155 cursor_name =
"nesw-resize";
158 cursor_name =
"ew-resize";
161 cursor_name =
"ns-resize";
166 cursor_name =
"not-allowed";
169 cursor_name =
"pointer";
176 return Emscripten_CreateCursorFromString(cursor_name,
SDL_FALSE);
186 if (curdata !=
NULL) {
207 if (Module[
'canvas']) {
208 Module[
'canvas'].style[
'cursor'] = Module[
'Pointer_stringify']($0);
216 if (Module[
'canvas']) {
217 Module[
'canvas'].style[
'cursor'] =
'none';
236 if(emscripten_request_pointerlock(
NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
240 if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {
#define SDL_ConvertSurfaceFormat
SDL_Mouse * SDL_GetMouse(void)
GLint GLint GLint GLint GLint x
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
void(* FreeCursor)(SDL_Cursor *cursor)
void * SDL_calloc(size_t nmemb, size_t size)
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
int(* ShowCursor)(SDL_Cursor *cursor)
GLubyte GLubyte GLubyte GLubyte w
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
int(* SetRelativeMouseMode)(SDL_bool enabled)
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
#define SDL_assert(condition)
#define SDL_OutOfMemory()
#define SDL_GetMouseFocus
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
const char * system_cursor
#define SDL_Unsupported()
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
void(* WarpMouse)(SDL_Window *window, int x, int y)
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