testdropfile.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright (C) 1997-2019 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 voodoo 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. SDLTest_CommonLogUsage(state, argv[0], NULL);
  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. if (event.type == SDL_DROPBEGIN) {
  65. SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
  66. } else if (event.type == SDL_DROPCOMPLETE) {
  67. SDL_Log("Drop complete on window %u", (unsigned int) event.drop.windowID);
  68. } else if ((event.type == SDL_DROPFILE) || (event.type == SDL_DROPTEXT)) {
  69. const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
  70. char *dropped_filedir = event.drop.file;
  71. SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
  72. /* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
  73. /*SDL_free(dropped_filedir);*/
  74. }
  75. SDLTest_CommonEvent(state, &event, &done);
  76. }
  77. }
  78. quit(0);
  79. /* keep the compiler happy ... */
  80. return(0);
  81. }
  82. /* vi: set ts=4 sw=4 expandtab: */