testdropfile.c 2.3 KB

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