Wiki Page Content

Differences between revisions 11 and 12
Revision 11 as of 2014-11-12 21:50:02
Size: 3177
Comment: Replaced printf() with SDL_Log() to remove stdio.h dependency.
Revision 12 as of 2014-11-12 21:51:45
Size: 3158
Comment: Remved spaces in example.
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
    SDL_Event event; //  Declare event handle
    char* dropped_filedir; //  Pointer for directory of dropped file
    SDL_Event event; // Declare event handle
    char* dropped_filedir; // Pointer for directory of dropped file
Line 27: Line 27:
    SDL_Init(SDL_INIT_VIDEO); //  SDL2 initialization     SDL_Init(SDL_INIT_VIDEO); // SDL2 initialization
Line 29: Line 29:
    window = SDL_CreateWindow( //  Create a window     window = SDL_CreateWindow( // Create a window
Line 47: Line 47:
    while (!done) {       //  Program loop     while (!done) { // Program loop
Line 50: Line 50:
                case (SDL_QUIT): { //  In case of exit                 case (SDL_QUIT): { // In case of exit
Line 55: Line 55:
                case (SDL_DROPFILE): { //  In case if dropped file                 case (SDL_DROPFILE): { // In case if dropped file
Line 57: Line 57:
                    //  Shows directory of dropped file                     // Shows directory of dropped file
Line 64: Line 64:
                    SDL_free(dropped_filedir); //  Free dropped_filedir memory                     SDL_free(dropped_filedir); // Free dropped_filedir memory
Line 72: Line 72:
    SDL_DestroyWindow(window); //  Close and destroy the window     SDL_DestroyWindow(window); // Close and destroy the window
Line 74: Line 74:
    SDL_Quit(); //  Clean up     SDL_Quit(); // Clean up
Line 82: Line 82:
This event is disabled by default. You can enable it with [[SDL_EventState]]().   This event is disabled by default. You can enable it with [[SDL_EventState]]().

SDL_DropEvent

A structure that contains an event used to request a file open by the system.

Data Fields

Uint32

type

the event type; SDL_DROPFILE

Uint32

timestamp

timestamp of the event

char*

file

the file name, which should be freed with SDL_free()

Code Examples

// 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;
    }

    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;
}

Remarks

SDL_DropEvent is a member of the SDL_Event union and is used when an event of type SDL_DROPFILE is reported. You would access it through the event's drop field.

This event is disabled by default. You can enable it with SDL_EventState().

If you enable this event you must free the filename in the event.

Mac OS X

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.


CategoryStruct, CategoryEvents

None: SDL_DropEvent (last edited 2016-10-13 20:51:29 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit