Emscripten: refactor cursor handling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c
index 15e0b4c..2d39487 100644
--- a/src/video/emscripten/SDL_emscriptenmouse.c
+++ b/src/video/emscripten/SDL_emscriptenmouse.c
@@ -32,9 +32,8 @@
#include "../../events/SDL_mouse_c.h"
#include "SDL_assert.h"
-
static SDL_Cursor*
-Emscripten_CreateDefaultCursor()
+Emscripten_CreateCursorFromString(const char* cursor_str)
{
SDL_Cursor* cursor;
Emscripten_CursorData *curdata;
@@ -48,7 +47,7 @@ Emscripten_CreateDefaultCursor()
return NULL;
}
- curdata->system_cursor = "default";
+ curdata->system_cursor = cursor_str;
cursor->driverdata = curdata;
}
else {
@@ -58,6 +57,12 @@ Emscripten_CreateDefaultCursor()
return cursor;
}
+static SDL_Cursor*
+Emscripten_CreateDefaultCursor()
+{
+ return Emscripten_CreateCursorFromString("default");
+}
+
/*
static SDL_Cursor*
Emscripten_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
@@ -69,8 +74,6 @@ Emscripten_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
static SDL_Cursor*
Emscripten_CreateSystemCursor(SDL_SystemCursor id)
{
- SDL_Cursor *cursor;
- Emscripten_CursorData *curdata;
const char *cursor_name = NULL;
switch(id) {
@@ -114,22 +117,7 @@ Emscripten_CreateSystemCursor(SDL_SystemCursor id)
return NULL;
}
- cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
- if (!cursor) {
- SDL_OutOfMemory();
- return NULL;
- }
- curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
- if (!curdata) {
- SDL_OutOfMemory();
- SDL_free(cursor);
- return NULL;
- }
-
- curdata->system_cursor = cursor_name;
- cursor->driverdata = curdata;
-
- return cursor;
+ return Emscripten_CreateCursorFromString(cursor_name);
}
static void