testdropfile.c
Go to the documentation of this file.
/*
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#include <stdlib.h>
#include <stdio.h>
#include "SDL_test_common.h"
static SDLTest_CommonState *state;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDLTest_CommonQuit(state);
exit(rc);
}
int
main(int argc, char *argv[])
{
int i, done;
SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
/* needed voodoo to allow app to launch via OS X Finder */
if (SDL_strncmp(argv[i], "-psn", 4)==0) {
consumed = 1;
}
if (consumed == 0) {
consumed = -1;
}
if (consumed < 0) {
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
quit(1);
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
quit(2);
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
/* Main render loop */
done = 0;
while (!done) {
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
if (event.type == SDL_DROPFILE) {
char *dropped_filedir = event.drop.file;
SDL_Log("File dropped on window: %s", dropped_filedir);
SDL_free(dropped_filedir);
}
}
}
quit(0);
/* keep the compiler happy ... */
return(0);
}
/* vi: set ts=4 sw=4 expandtab: */
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:128
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:36
SDLTest_CommonArg
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
Definition: SDL_test_common.c:83
SDL_Renderer
Definition: SDL_sysrender.h:76
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
SDL_test_common.h
SDLTest_CommonInit
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
Definition: SDL_test_common.c:645
SDL_strncmp
#define SDL_strncmp
Definition: SDL_dynapi_overrides.h:424
SDLTest_CommonState::num_windows
int num_windows
Definition: SDL_test_common.h:77
renderer
SDL_Renderer * renderer
Definition: testautomation_render.c:27
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:37
SDLTest_CommonEvent
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
Definition: SDL_test_common.c:1295
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_free
void SDL_free(void *mem)
done
int done
Definition: checkkeys.c:28
SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
SDLTest_CommonUsage
const char * SDLTest_CommonUsage(SDLTest_CommonState *state)
Returns common usage information.
Definition: SDL_test_common.c:451
SDLTest_CommonState
Definition: SDL_test_common.h:51
SDLTest_CommonState::renderers
SDL_Renderer ** renderers
Definition: SDL_test_common.h:84
SDL_DROPFILE
Definition: SDL_events.h:138
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:42
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:242
SDL_RenderClear
#define SDL_RenderClear
Definition: SDL_dynapi_overrides.h:340
SDL_EventState
#define SDL_EventState
Definition: SDL_dynapi_overrides.h:137
quit
static void quit(int rc)
Definition: testdropfile.c:22
SDL_Event
General event structure.
Definition: SDL_events.h:521
SDL_SetRenderDrawColor
#define SDL_SetRenderDrawColor
Definition: SDL_dynapi_overrides.h:336
state
static SDLTest_CommonState * state
Definition: testdropfile.c:18
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
SDLTest_CommonQuit
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
Definition: SDL_test_common.c:1560
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77
SDL_RenderPresent
#define SDL_RenderPresent
Definition: SDL_dynapi_overrides.h:352
SDL_Event::type
Uint32 type
Definition: SDL_events.h:523