Added SDL_AllocateEventString()
This commit is contained in:
@@ -327,7 +327,7 @@ typedef struct SDL_TextEditingEvent
|
|||||||
Uint32 reserved;
|
Uint32 reserved;
|
||||||
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
|
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
|
||||||
SDL_WindowID windowID; /**< The window with keyboard focus, if any */
|
SDL_WindowID windowID; /**< The window with keyboard focus, if any */
|
||||||
char *text; /**< The editing text */
|
const char *text; /**< The editing text */
|
||||||
Sint32 start; /**< The start cursor of selected editing text */
|
Sint32 start; /**< The start cursor of selected editing text */
|
||||||
Sint32 length; /**< The length of selected editing text */
|
Sint32 length; /**< The length of selected editing text */
|
||||||
} SDL_TextEditingEvent;
|
} SDL_TextEditingEvent;
|
||||||
@@ -352,7 +352,7 @@ typedef struct SDL_TextInputEvent
|
|||||||
Uint32 reserved;
|
Uint32 reserved;
|
||||||
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
|
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
|
||||||
SDL_WindowID windowID; /**< The window with keyboard focus, if any */
|
SDL_WindowID windowID; /**< The window with keyboard focus, if any */
|
||||||
char *text; /**< The input text, UTF-8 encoded */
|
const char *text; /**< The input text, UTF-8 encoded */
|
||||||
} SDL_TextInputEvent;
|
} SDL_TextInputEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -733,8 +733,7 @@ typedef struct SDL_PenButtonEvent
|
|||||||
* An event used to drop text or request a file open by the system
|
* An event used to drop text or request a file open by the system
|
||||||
* (event.drop.*)
|
* (event.drop.*)
|
||||||
*
|
*
|
||||||
* The `data` is owned by SDL and should be copied if the application wants to
|
* The `source` and `data` are owned by SDL and should be copied if the application wants to hold onto them beyond the scope of handling this event.
|
||||||
* hold onto it beyond the scope of handling this event. Do not free it!
|
|
||||||
*
|
*
|
||||||
* \since This struct is available since SDL 3.0.0.
|
* \since This struct is available since SDL 3.0.0.
|
||||||
*/
|
*/
|
||||||
@@ -746,8 +745,8 @@ typedef struct SDL_DropEvent
|
|||||||
SDL_WindowID windowID; /**< The window that was dropped on, if any */
|
SDL_WindowID windowID; /**< The window that was dropped on, if any */
|
||||||
float x; /**< X coordinate, relative to window (not on begin) */
|
float x; /**< X coordinate, relative to window (not on begin) */
|
||||||
float y; /**< Y coordinate, relative to window (not on begin) */
|
float y; /**< Y coordinate, relative to window (not on begin) */
|
||||||
char *source; /**< The source app that sent this drop event, or NULL if that isn't available */
|
const char *source; /**< The source app that sent this drop event, or NULL if that isn't available */
|
||||||
char *data; /**< The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events */
|
const char *data; /**< The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events */
|
||||||
} SDL_DropEvent;
|
} SDL_DropEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,16 +59,16 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch
|
|||||||
event.type = evtype;
|
event.type = evtype;
|
||||||
event.common.timestamp = 0;
|
event.common.timestamp = 0;
|
||||||
if (source) {
|
if (source) {
|
||||||
event.drop.source = SDL_strdup(source);
|
event.drop.source = SDL_AllocateEventString(source);
|
||||||
}
|
if (!event.drop.source) {
|
||||||
if (data) {
|
return 0;
|
||||||
size_t size = SDL_strlen(data) + 1;
|
}
|
||||||
event.drop.data = (char *)SDL_AllocateEventMemory(size);
|
}
|
||||||
if (!event.drop.data) {
|
if (data) {
|
||||||
SDL_free(event.drop.source);
|
event.drop.data = SDL_AllocateEventString(data);
|
||||||
|
if (!event.drop.data) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SDL_memcpy(event.drop.data, data, size);
|
|
||||||
}
|
}
|
||||||
event.drop.windowID = window ? window->id : 0;
|
event.drop.windowID = window ? window->id : 0;
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,14 @@ void *SDL_AllocateEventMemory(size_t size)
|
|||||||
return SDL_FreeLater(SDL_malloc(size));
|
return SDL_FreeLater(SDL_malloc(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *SDL_AllocateEventString(const char *string)
|
||||||
|
{
|
||||||
|
if (string) {
|
||||||
|
return SDL_FreeLater(SDL_strdup(string));
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void SDL_FlushEventMemory(Uint32 eventID)
|
static void SDL_FlushEventMemory(Uint32 eventID)
|
||||||
{
|
{
|
||||||
SDL_LockMutex(SDL_event_memory_lock);
|
SDL_LockMutex(SDL_event_memory_lock);
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ extern int SDL_StartEventLoop(void);
|
|||||||
extern void SDL_StopEventLoop(void);
|
extern void SDL_StopEventLoop(void);
|
||||||
extern void SDL_QuitInterrupt(void);
|
extern void SDL_QuitInterrupt(void);
|
||||||
|
|
||||||
|
extern const char *SDL_AllocateEventString(const char *string);
|
||||||
|
|
||||||
extern int SDL_SendAppEvent(SDL_EventType eventType);
|
extern int SDL_SendAppEvent(SDL_EventType eventType);
|
||||||
extern int SDL_SendKeymapChangedEvent(void);
|
extern int SDL_SendKeymapChangedEvent(void);
|
||||||
extern int SDL_SendLocaleChangedEvent(void);
|
extern int SDL_SendLocaleChangedEvent(void);
|
||||||
|
|||||||
@@ -1205,14 +1205,10 @@ int SDL_SendKeyboardText(const char *text)
|
|||||||
event.type = SDL_EVENT_TEXT_INPUT;
|
event.type = SDL_EVENT_TEXT_INPUT;
|
||||||
event.common.timestamp = 0;
|
event.common.timestamp = 0;
|
||||||
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
|
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
|
||||||
|
event.text.text = SDL_AllocateEventString(text);
|
||||||
size_t size = SDL_strlen(text) + 1;
|
|
||||||
event.text.text = (char *)SDL_AllocateEventMemory(size);
|
|
||||||
if (!event.text.text) {
|
if (!event.text.text) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SDL_memcpy(event.text.text, text, size);
|
|
||||||
|
|
||||||
posted = (SDL_PushEvent(&event) > 0);
|
posted = (SDL_PushEvent(&event) > 0);
|
||||||
}
|
}
|
||||||
return posted;
|
return posted;
|
||||||
@@ -1241,14 +1237,10 @@ int SDL_SendEditingText(const char *text, int start, int length)
|
|||||||
event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
|
event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
|
||||||
event.edit.start = start;
|
event.edit.start = start;
|
||||||
event.edit.length = length;
|
event.edit.length = length;
|
||||||
|
event.edit.text = SDL_AllocateEventString(text);
|
||||||
size_t size = SDL_strlen(text) + 1;
|
|
||||||
event.edit.text = (char *)SDL_AllocateEventMemory(size);
|
|
||||||
if (!event.edit.text) {
|
if (!event.edit.text) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SDL_memcpy(event.edit.text, text, size);
|
|
||||||
|
|
||||||
posted = (SDL_PushEvent(&event) > 0);
|
posted = (SDL_PushEvent(&event) > 0);
|
||||||
}
|
}
|
||||||
return posted;
|
return posted;
|
||||||
|
|||||||
Reference in New Issue
Block a user