SDL  2.0
testdropfile.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 1997-2020 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 
19 
20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
21 static void
22 quit(int rc)
23 {
25  exit(rc);
26 }
27 
28 int
29 main(int argc, char *argv[])
30 {
31  int i, done;
33 
34  /* Enable standard application logging */
36 
37  /* Initialize test framework */
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  /* needed voodoo to allow app to launch via OS X Finder */
48  if (SDL_strncmp(argv[i], "-psn", 4)==0) {
49  consumed = 1;
50  }
51  if (consumed == 0) {
52  consumed = -1;
53  }
54  if (consumed < 0) {
56  quit(1);
57  }
58  i += consumed;
59  }
60  if (!SDLTest_CommonInit(state)) {
61  quit(2);
62  }
63 
64  for (i = 0; i < state->num_windows; ++i) {
66  SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
69  }
70 
72 
73  /* Main render loop */
74  done = 0;
75  while (!done) {
76  /* Check for events */
77  while (SDL_PollEvent(&event)) {
78  if (event.type == SDL_DROPBEGIN) {
79  SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
80  } else if (event.type == SDL_DROPCOMPLETE) {
81  SDL_Log("Drop complete on window %u", (unsigned int) event.drop.windowID);
82  } else if ((event.type == SDL_DROPFILE) || (event.type == SDL_DROPTEXT)) {
83  const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
84  char *dropped_filedir = event.drop.file;
85  SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
86  /* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
87  /*SDL_free(dropped_filedir);*/
88  }
89 
91  }
92  }
93 
94  quit(0);
95  /* keep the compiler happy ... */
96  return(0);
97 }
98 
99 /* vi: set ts=4 sw=4 expandtab: */
SDL_RenderPresent
#define SDL_RenderPresent
Definition: SDL_dynapi_overrides.h:346
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:122
NULL
#define NULL
Definition: begin_code.h:167
SDLTest_CommonState
Definition: SDL_test_common.h:52
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:760
SDL_strncmp
#define SDL_strncmp
Definition: SDL_dynapi_overrides.h:418
SDLTest_CommonState::renderers
SDL_Renderer ** renderers
Definition: SDL_test_common.h:84
main
int main(int argc, char *argv[])
Definition: testdropfile.c:29
SDLTest_CommonCreateState
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
Definition: SDL_test_common.c:59
SDLTest_CommonQuit
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
Definition: SDL_test_common.c:1910
SDLTest_CommonState::num_windows
int num_windows
Definition: SDL_test_common.h:77
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2652
SDL_Renderer
Definition: SDL_sysrender.h:110
done
int done
Definition: checkkeys.c:28
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:31
SDL_test_common.h
SDL_DROPCOMPLETE
@ SDL_DROPCOMPLETE
Definition: SDL_events.h:144
SDL_LOG_CATEGORY_APPLICATION
@ SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
SDL_DROPTEXT
@ SDL_DROPTEXT
Definition: SDL_events.h:142
SDLTest_CommonArg
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
Definition: SDL_test_common.c:117
state
static SDLTest_CommonState * state
Definition: testdropfile.c:18
quit
static void quit(int rc)
Definition: testdropfile.c:22
SDLTest_CommonLogUsage
void SDLTest_CommonLogUsage(SDLTest_CommonState *state, const char *argv0, const char **options)
Logs command line usage info.
Definition: SDL_test_common.c:498
SDL_DROPBEGIN
@ SDL_DROPBEGIN
Definition: SDL_events.h:143
SDLTest_CommonInit
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
Definition: SDL_test_common.c:835
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:80
SDL_LOG_PRIORITY_INFO
@ SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
renderer
static SDL_Renderer * renderer
Definition: testaudiocapture.c:21
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:236
SDL_RenderClear
#define SDL_RenderClear
Definition: SDL_dynapi_overrides.h:334
SDL_SetRenderDrawColor
#define SDL_SetRenderDrawColor
Definition: SDL_dynapi_overrides.h:330
SDL_EventState
#define SDL_EventState
Definition: SDL_dynapi_overrides.h:131
SDL_Event
General event structure.
Definition: SDL_events.h:559
SDLTest_CommonEvent
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
Definition: SDL_test_common.c:1579
SDL_DROPFILE
@ SDL_DROPFILE
Definition: SDL_events.h:141
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50