Emscripten: Deactivated custom cursor support because it created system cursors.
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
23 #include "../../SDL_internal.h"
25 #if SDL_VIDEO_DRIVER_EMSCRIPTEN
27 #include <emscripten/emscripten.h>
28 #include <emscripten/html5.h>
30 #include "SDL_emscriptenmouse.h"
32 #include "../../events/SDL_mouse_c.h"
33 #include "SDL_assert.h"
37 Emscripten_CreateDefaultCursor()
40 Emscripten_CursorData *curdata;
42 cursor = SDL_calloc(1, sizeof(SDL_Cursor));
44 curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
51 curdata->system_cursor = "default";
52 cursor->driverdata = curdata;
63 Emscripten_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
65 return Emscripten_CreateDefaultCursor();
70 Emscripten_CreateSystemCursor(SDL_SystemCursor id)
73 Emscripten_CursorData *curdata;
74 const char *cursor_name = NULL;
77 case SDL_SYSTEM_CURSOR_ARROW:
78 cursor_name = "default";
80 case SDL_SYSTEM_CURSOR_IBEAM:
83 case SDL_SYSTEM_CURSOR_WAIT:
86 case SDL_SYSTEM_CURSOR_CROSSHAIR:
87 cursor_name = "crosshair";
89 case SDL_SYSTEM_CURSOR_WAITARROW:
90 cursor_name = "progress";
92 case SDL_SYSTEM_CURSOR_SIZENWSE:
93 cursor_name = "nwse-resize";
95 case SDL_SYSTEM_CURSOR_SIZENESW:
96 cursor_name = "nesw-resize";
98 case SDL_SYSTEM_CURSOR_SIZEWE:
99 cursor_name = "ew-resize";
101 case SDL_SYSTEM_CURSOR_SIZENS:
102 cursor_name = "ns-resize";
104 case SDL_SYSTEM_CURSOR_SIZEALL:
106 case SDL_SYSTEM_CURSOR_NO:
107 cursor_name = "not-allowed";
109 case SDL_SYSTEM_CURSOR_HAND:
110 cursor_name = "pointer";
117 cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
122 curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
129 curdata->system_cursor = cursor_name;
130 cursor->driverdata = curdata;
136 Emscripten_FreeCursor(SDL_Cursor* cursor)
138 Emscripten_CursorData *curdata;
140 curdata = (Emscripten_CursorData *) cursor->driverdata;
142 if (curdata != NULL) {
143 SDL_free(cursor->driverdata);
151 Emscripten_ShowCursor(SDL_Cursor* cursor)
153 Emscripten_CursorData *curdata;
154 if (SDL_GetMouseFocus() != NULL) {
155 if(cursor && cursor->driverdata) {
156 curdata = (Emscripten_CursorData *) cursor->driverdata;
158 if(curdata->system_cursor) {
160 if (Module['canvas']) {
161 Module['canvas'].style['cursor'] = Module['Pointer_stringify']($0);
164 }, curdata->system_cursor);
169 if (Module['canvas']) {
170 Module['canvas'].style['cursor'] = 'none';
179 Emscripten_WarpMouse(SDL_Window* window, int x, int y)
185 Emscripten_SetRelativeMouseMode(SDL_bool enabled)
187 /* TODO: pointer lock isn't actually enabled yet */
189 if(emscripten_request_pointerlock(NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
193 if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {
201 Emscripten_InitMouse()
203 SDL_Mouse* mouse = SDL_GetMouse();
206 mouse->CreateCursor = Emscripten_CreateCursor;
208 mouse->ShowCursor = Emscripten_ShowCursor;
209 mouse->FreeCursor = Emscripten_FreeCursor;
210 mouse->WarpMouse = Emscripten_WarpMouse;
211 mouse->CreateSystemCursor = Emscripten_CreateSystemCursor;
212 mouse->SetRelativeMouseMode = Emscripten_SetRelativeMouseMode;
214 SDL_SetDefaultCursor(Emscripten_CreateDefaultCursor());
218 Emscripten_FiniMouse()
220 SDL_Mouse* mouse = SDL_GetMouse();
222 Emscripten_FreeCursor(mouse->def_cursor);
223 mouse->def_cursor = NULL;
225 mouse->CreateCursor = NULL;
226 mouse->ShowCursor = NULL;
227 mouse->FreeCursor = NULL;
228 mouse->WarpMouse = NULL;
229 mouse->CreateSystemCursor = NULL;
230 mouse->SetRelativeMouseMode = NULL;
233 #endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
235 /* vi: set ts=4 sw=4 expandtab: */