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