mirror of
https://github.com/encounter/SDL.git
synced 2025-12-10 05:57:44 +00:00
Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.
This allows an app to know when a set of drops are coming in a grouping of some sort (for example, a user selected multiple files and dropped them all on the window with a single drag), and when that set is complete. This also adds a window ID to the drop events, so the app can determine to which window a given drop was delivered. For application-level drops (for example, you launched an app by dropping a file on its icon), the window ID will be zero.
This commit is contained in:
@@ -26,34 +26,69 @@
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_dropevents_c.h"
|
||||
|
||||
#include "../video/SDL_sysvideo.h" /* for SDL_Window internals. */
|
||||
|
||||
|
||||
static int
|
||||
SDL_SendDrop(const SDL_EventType evtype, const char *data)
|
||||
SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
|
||||
{
|
||||
int posted;
|
||||
static SDL_bool app_is_dropping = SDL_FALSE;
|
||||
int posted = 0;
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(evtype) == SDL_ENABLE) {
|
||||
const SDL_bool need_begin = window ? !window->is_dropping : !app_is_dropping;
|
||||
SDL_Event event;
|
||||
|
||||
if (need_begin) {
|
||||
SDL_zero(event);
|
||||
event.type = SDL_DROPBEGIN;
|
||||
event.drop.windowID = window->id;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
if (!posted) {
|
||||
return 0;
|
||||
}
|
||||
if (window) {
|
||||
window->is_dropping = SDL_TRUE;
|
||||
} else {
|
||||
app_is_dropping = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_zero(event);
|
||||
event.type = evtype;
|
||||
event.drop.file = SDL_strdup(data);
|
||||
event.drop.file = data ? SDL_strdup(data) : NULL;
|
||||
event.drop.windowID = window ? window->id : 0;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
|
||||
if (posted && (evtype == SDL_DROPCOMPLETE)) {
|
||||
if (window) {
|
||||
window->is_dropping = SDL_FALSE;
|
||||
} else {
|
||||
app_is_dropping = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return posted;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendDropFile(const char *file)
|
||||
SDL_SendDropFile(SDL_Window *window, const char *file)
|
||||
{
|
||||
return SDL_SendDrop(SDL_DROPFILE, file);
|
||||
return SDL_SendDrop(window, SDL_DROPFILE, file);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendDropText(const char *text)
|
||||
SDL_SendDropText(SDL_Window *window, const char *text)
|
||||
{
|
||||
return SDL_SendDrop(SDL_DROPTEXT, text);
|
||||
return SDL_SendDrop(window, SDL_DROPTEXT, text);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendDropComplete(SDL_Window *window)
|
||||
{
|
||||
return SDL_SendDrop(window, SDL_DROPCOMPLETE, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -23,8 +23,9 @@
|
||||
#ifndef _SDL_dropevents_c_h
|
||||
#define _SDL_dropevents_c_h
|
||||
|
||||
extern int SDL_SendDropFile(const char *file);
|
||||
extern int SDL_SendDropText(const char *text);
|
||||
extern int SDL_SendDropFile(SDL_Window *window, const char *file);
|
||||
extern int SDL_SendDropText(SDL_Window *window, const char *text);
|
||||
extern int SDL_SendDropComplete(SDL_Window *window);
|
||||
|
||||
#endif /* _SDL_dropevents_c_h */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user