A structure that contains an event used to request a file open by the system.
Uint32 |
type |
the event type; SDL_EVENT_DROP_FILE, SDL_EVENT_DROP_TEXT, SDL_EVENT_DROP_BEGIN, or SDL_EVENT_DROP_COMPLETE |
Uint32 |
timestamp |
timestamp of the event |
char* |
file |
the file name, which should be freed with SDL_free(), is NULL on BEGIN/COMPLETE |
Uint32 |
windowID |
the window that was dropped on, if any |
// Example program:
// SDL_DropEvent usage
#include "SDL.h"
int main(int argc, char *argv[]) {
SDL_bool done;
SDL_Window *window;// Declare event handle
SDL_Event event; char* dropped_filedir; // Pointer for directory of dropped file
// SDL2 initialization
SDL_Init(SDL_INIT_VIDEO);
// Create a window
window = SDL_CreateWindow( "SDL_DropEvent usage, please drop the file on window",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,640,
480,
SDL_WINDOW_OPENGL
);
// Check that the window was successfully made
if (window == NULL) {
// In the event that the window could not be made...
"Could not create window: %s", SDL_GetError());
SDL_Log(
SDL_Quit();return 1;
}
SDL_EventState(SDL_EVENT_DROP_FILE, SDL_ENABLE);
done = SDL_FALSE;while (!done) { // Program loop
while (!done && SDL_PollEvent(&event)) {
switch (event.type) {
case (SDL_EVENT_QUIT): { // In case of exit
done = SDL_TRUE;break;
}
case (SDL_EVENT_DROP_FILE): { // In case if dropped file
dropped_filedir = event.drop.file;// Shows directory of dropped file
SDL_ShowSimpleMessageBox(
SDL_MESSAGEBOX_INFORMATION,"File dropped on window",
dropped_filedir,
window
);// Free dropped_filedir memory
SDL_free(dropped_filedir); break;
}
}
}0);
SDL_Delay(
}
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit(); return 0;
}
SDL_DropEvent is a member of the SDL_Event union and is used when an event of type SDL_EVENT_DROP_FILE, SDL_EVENT_DROP_TEXT, SDL_EVENT_DROP_BEGIN, or SDL_EVENT_DROP_COMPLETE is reported. You would access it through the event's drop
field.
These events are enabled by default. You can disable it with SDL_EventState().
If these events are enabled you must free the filename in the events using SDL_free().
SDL_EVENT_DROP_TEXT, SDL_EVENT_DROP_BEGIN, and SDL_EVENT_DROP_COMPLETE are available since SDL 2.0.5.
To enable drag&drop on your SDL app, you must also edit your info.plist file. Add/Modify Document Types. For example, to enable all document types, add the "public.data" mime type as a document type.
Any document or URL types registered via CFBundleDocumentTypes or CFBundleURLTypes are reported as SDL_EVENT_DROP_FILE events.
This structure is available since SDL 2.0.0.
CategoryStruct, CategoryEvents