test/testdropfile.c
changeset 7807 73da2747c268
child 8149 681eb46b8ac4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testdropfile.c	Sat Oct 12 11:21:40 2013 -0400
     1.3 @@ -0,0 +1,87 @@
     1.4 +/*
     1.5 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.6 +
     1.7 +  This software is provided 'as-is', without any express or implied
     1.8 +  warranty.  In no event will the authors be held liable for any damages
     1.9 +  arising from the use of this software.
    1.10 +
    1.11 +  Permission is granted to anyone to use this software for any purpose,
    1.12 +  including commercial applications, and to alter it and redistribute it
    1.13 +  freely.
    1.14 +*/
    1.15 +
    1.16 +#include <stdlib.h>
    1.17 +#include <stdio.h>
    1.18 +
    1.19 +#include "SDL_test_common.h"
    1.20 +
    1.21 +static SDLTest_CommonState *state;
    1.22 +
    1.23 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.24 +static void
    1.25 +quit(int rc)
    1.26 +{
    1.27 +    SDLTest_CommonQuit(state);
    1.28 +    exit(rc);
    1.29 +}
    1.30 +
    1.31 +int
    1.32 +main(int argc, char *argv[])
    1.33 +{
    1.34 +    int i, done;
    1.35 +    SDL_Event event;
    1.36 +
    1.37 +	/* Enable standard application logging */
    1.38 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.39 +
    1.40 +    /* Initialize test framework */
    1.41 +    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    1.42 +    if (!state) {
    1.43 +        return 1;
    1.44 +    }
    1.45 +
    1.46 +    for (i = 1; i < argc;) {
    1.47 +        int consumed;
    1.48 +
    1.49 +        consumed = SDLTest_CommonArg(state, i);
    1.50 +        if (consumed == 0) {
    1.51 +            consumed = -1;
    1.52 +        }
    1.53 +        if (consumed < 0) {
    1.54 +            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
    1.55 +            quit(1);
    1.56 +        }
    1.57 +        i += consumed;
    1.58 +    }
    1.59 +    if (!SDLTest_CommonInit(state)) {
    1.60 +        quit(2);
    1.61 +    }
    1.62 +
    1.63 +    for (i = 0; i < state->num_windows; ++i) {
    1.64 +        SDL_Renderer *renderer = state->renderers[i];
    1.65 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.66 +        SDL_RenderClear(renderer);
    1.67 +        SDL_RenderPresent(renderer);
    1.68 +    }
    1.69 +
    1.70 +    /* Main render loop */
    1.71 +    done = 0;
    1.72 +    while (!done) {
    1.73 +        /* Check for events */
    1.74 +        while (SDL_PollEvent(&event)) {
    1.75 +            SDLTest_CommonEvent(state, &event, &done);
    1.76 +
    1.77 +            if (event.type == SDL_DROPFILE) {
    1.78 +                char *dropped_filedir = event.drop.file;
    1.79 +                SDL_Log("File dropped on window: %s", dropped_filedir);
    1.80 +                SDL_free(dropped_filedir);
    1.81 +            }
    1.82 +        }
    1.83 +    }
    1.84 +
    1.85 +    quit(0);
    1.86 +    /* keep the compiler happy ... */
    1.87 +    return(0);
    1.88 +}
    1.89 +
    1.90 +/* vi: set ts=4 sw=4 expandtab: */