Estructura SDL_DropEvent
typedef struct SDL_DropEvent
{
Uint32 type; /**< ::SDL_DROPBEGIN or ::SDL_DROPFILE or ::SDL_DROPTEXT or ::SDL_DROPCOMPLETE */
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
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 */
} SDL_DropEvent;
Miembros
- type
- El tipo de evento: SDL_DROPFILE, SDL_DROPTEXT, SDL_DROPBEGIN o SDL_DROPCOMPLETE.
- timestamp
- Marca de tiempo en milisegundos.
- file
- El nombre del fichero, que debería ser liberado con SDL_free(), es NULL en BEGIN/COMPLETE.
- windowID
- La ventana sobre la que se dejó caer, en su caso.
Observaciones
SDL_DropEvent es un miembro de la unión SDL_Event y se utiliza cuando se notifica un evento de tipo SDL_DROPFILE, SDL_DROPTEXT, SDL_DROPBEGIN o SDL_DROPCOMPLETE. Se accedería a él a través del campo drop del evento.
Estos eventos están activados por defecto. Se pueden deshabilitar con SDL_EventState().
Si estos eventos están habilitados se debe liberar el nombre de archivo en los eventos usando SDL_free().
SDL_DROPTEXT, SDL_DROPBEGIN, y SDL_DROPCOMPLETE están disponibles desde SDL 2.0.5.
Mac OS X
Para activar la función de arrastrar y soltar en su aplicación SDL, también debe editar su archivo info.plist. Añadir/modificar tipos de documento. Por ejemplo, para habilitar todos los tipos de documento, añada el tipo mime "public.data" como tipo de documento.
Todos los tipos de documento o URL registrados a través de CFBundleDocumentTypes o CFBundleURLTypes se notifican como eventos SDL_DROPFILE.
Ejemplo
// Example program:
// SDL_DropEvent usage
#include "SDL.h"
int main(int argc, char *argv[]) {
SDL_bool done;
SDL_Window *window;
SDL_Event event; // Declare event handle
char* dropped_filedir; // Pointer for directory of dropped file
SDL_Init(SDL_INIT_VIDEO); // SDL2 initialization
window = SDL_CreateWindow( // Create a window
"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...
SDL_Log("Could not create window: %s", SDL_GetError());
SDL_Quit();
return 1;
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
done = SDL_FALSE;
while (!done) { // Program loop
while (!done && SDL_PollEvent(&event)) {
switch (event.type) {
case (SDL_QUIT): { // In case of exit
done = SDL_TRUE;
break;
}
case (SDL_DROPFILE): { // 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
);
SDL_free(dropped_filedir); // Free dropped_filedir memory
break;
}
}
}
SDL_Delay(0);
}
SDL_DestroyWindow(window); // Close and destroy the window
SDL_Quit(); // Clean up
return 0;
}