test/testdropfile.c
changeset 7807 73da2747c268
child 8149 681eb46b8ac4
equal deleted inserted replaced
7806:03e6aaea8347 7807:73da2747c268
       
     1 /*
       
     2   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
       
     3 
       
     4   This software is provided 'as-is', without any express or implied
       
     5   warranty.  In no event will the authors be held liable for any damages
       
     6   arising from the use of this software.
       
     7 
       
     8   Permission is granted to anyone to use this software for any purpose,
       
     9   including commercial applications, and to alter it and redistribute it
       
    10   freely.
       
    11 */
       
    12 
       
    13 #include <stdlib.h>
       
    14 #include <stdio.h>
       
    15 
       
    16 #include "SDL_test_common.h"
       
    17 
       
    18 static SDLTest_CommonState *state;
       
    19 
       
    20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
       
    21 static void
       
    22 quit(int rc)
       
    23 {
       
    24     SDLTest_CommonQuit(state);
       
    25     exit(rc);
       
    26 }
       
    27 
       
    28 int
       
    29 main(int argc, char *argv[])
       
    30 {
       
    31     int i, done;
       
    32     SDL_Event event;
       
    33 
       
    34 	/* Enable standard application logging */
       
    35     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
       
    36 
       
    37     /* Initialize test framework */
       
    38     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
       
    39     if (!state) {
       
    40         return 1;
       
    41     }
       
    42 
       
    43     for (i = 1; i < argc;) {
       
    44         int consumed;
       
    45 
       
    46         consumed = SDLTest_CommonArg(state, i);
       
    47         if (consumed == 0) {
       
    48             consumed = -1;
       
    49         }
       
    50         if (consumed < 0) {
       
    51             SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
       
    52             quit(1);
       
    53         }
       
    54         i += consumed;
       
    55     }
       
    56     if (!SDLTest_CommonInit(state)) {
       
    57         quit(2);
       
    58     }
       
    59 
       
    60     for (i = 0; i < state->num_windows; ++i) {
       
    61         SDL_Renderer *renderer = state->renderers[i];
       
    62         SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
       
    63         SDL_RenderClear(renderer);
       
    64         SDL_RenderPresent(renderer);
       
    65     }
       
    66 
       
    67     /* Main render loop */
       
    68     done = 0;
       
    69     while (!done) {
       
    70         /* Check for events */
       
    71         while (SDL_PollEvent(&event)) {
       
    72             SDLTest_CommonEvent(state, &event, &done);
       
    73 
       
    74             if (event.type == SDL_DROPFILE) {
       
    75                 char *dropped_filedir = event.drop.file;
       
    76                 SDL_Log("File dropped on window: %s", dropped_filedir);
       
    77                 SDL_free(dropped_filedir);
       
    78             }
       
    79         }
       
    80     }
       
    81 
       
    82     quit(0);
       
    83     /* keep the compiler happy ... */
       
    84     return(0);
       
    85 }
       
    86 
       
    87 /* vi: set ts=4 sw=4 expandtab: */