Added three missing checks for return values of SDL_calloc().
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2014 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;
62 Emscripten_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
64 return Emscripten_CreateDefaultCursor();
68 Emscripten_CreateSystemCursor(SDL_SystemCursor id)
71 Emscripten_CursorData *curdata;
72 const char *cursor_name = NULL;
75 case SDL_SYSTEM_CURSOR_ARROW:
76 cursor_name = "default";
78 case SDL_SYSTEM_CURSOR_IBEAM:
81 case SDL_SYSTEM_CURSOR_WAIT:
84 case SDL_SYSTEM_CURSOR_CROSSHAIR:
85 cursor_name = "crosshair";
87 case SDL_SYSTEM_CURSOR_WAITARROW:
88 cursor_name = "progress";
90 case SDL_SYSTEM_CURSOR_SIZENWSE:
91 cursor_name = "nwse-resize";
93 case SDL_SYSTEM_CURSOR_SIZENESW:
94 cursor_name = "nesw-resize";
96 case SDL_SYSTEM_CURSOR_SIZEWE:
97 cursor_name = "ew-resize";
99 case SDL_SYSTEM_CURSOR_SIZENS:
100 cursor_name = "ns-resize";
102 case SDL_SYSTEM_CURSOR_SIZEALL:
104 case SDL_SYSTEM_CURSOR_NO:
105 cursor_name = "not-allowed";
107 case SDL_SYSTEM_CURSOR_HAND:
108 cursor_name = "pointer";
115 cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
120 curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
127 curdata->system_cursor = cursor_name;
128 cursor->driverdata = curdata;
134 Emscripten_FreeCursor(SDL_Cursor* cursor)
136 Emscripten_CursorData *curdata;
138 curdata = (Emscripten_CursorData *) cursor->driverdata;
140 if (curdata != NULL) {
141 SDL_free(cursor->driverdata);
149 Emscripten_ShowCursor(SDL_Cursor* cursor)
151 Emscripten_CursorData *curdata;
152 if (SDL_GetMouseFocus() != NULL) {
153 if(cursor && cursor->driverdata) {
154 curdata = (Emscripten_CursorData *) cursor->driverdata;
156 if(curdata->system_cursor) {
158 if (Module['canvas']) {
159 Module['canvas'].style['cursor'] = Module['Pointer_stringify']($0);
162 }, curdata->system_cursor);
167 if (Module['canvas']) {
168 Module['canvas'].style['cursor'] = 'none';
177 Emscripten_WarpMouse(SDL_Window* window, int x, int y)
183 Emscripten_SetRelativeMouseMode(SDL_bool enabled)
185 /* TODO: pointer lock isn't actually enabled yet */
187 if(emscripten_request_pointerlock(NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
191 if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {
199 Emscripten_InitMouse()
201 SDL_Mouse* mouse = SDL_GetMouse();
203 mouse->CreateCursor = Emscripten_CreateCursor;
204 mouse->ShowCursor = Emscripten_ShowCursor;
205 mouse->FreeCursor = Emscripten_FreeCursor;
206 mouse->WarpMouse = Emscripten_WarpMouse;
207 mouse->CreateSystemCursor = Emscripten_CreateSystemCursor;
208 mouse->SetRelativeMouseMode = Emscripten_SetRelativeMouseMode;
210 SDL_SetDefaultCursor(Emscripten_CreateDefaultCursor());
214 Emscripten_FiniMouse()
216 SDL_Mouse* mouse = SDL_GetMouse();
218 Emscripten_FreeCursor(mouse->def_cursor);
219 mouse->def_cursor = NULL;
221 mouse->CreateCursor = NULL;
222 mouse->ShowCursor = NULL;
223 mouse->FreeCursor = NULL;
224 mouse->WarpMouse = NULL;
225 mouse->CreateSystemCursor = NULL;
226 mouse->SetRelativeMouseMode = NULL;
229 #endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
231 /* vi: set ts=4 sw=4 expandtab: */