2015-06-21 15:33:46 +00:00
|
|
|
/*
|
2023-01-09 17:41:41 +00:00
|
|
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
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>
|
|
|
|
|
2022-11-27 04:43:38 +00:00
|
|
|
#include <SDL3/SDL_test_common.h>
|
2022-12-15 04:58:20 +00:00
|
|
|
#include <SDL3/SDL_main.h>
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
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);
|
2023-04-12 09:07:28 +00:00
|
|
|
/* Let 'main()' return normally */
|
|
|
|
if (rc != 0) {
|
|
|
|
exit(rc);
|
|
|
|
}
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
int main(int argc, char *argv[])
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
|
|
|
int i, done;
|
|
|
|
SDL_Event event;
|
2023-03-06 10:16:18 +00:00
|
|
|
SDL_bool is_hover = SDL_FALSE;
|
|
|
|
float x = 0.0f, y = 0.0f;
|
|
|
|
unsigned int windowID = 0;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
/* Initialize test framework */
|
|
|
|
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
2022-11-27 16:38:43 +00:00
|
|
|
if (state == NULL) {
|
2015-06-21 15:33:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-03-16 23:25:39 +00:00
|
|
|
/* Enable standard application logging */
|
|
|
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
|
|
|
|
2015-06-21 15:33:46 +00:00
|
|
|
for (i = 1; i < argc;) {
|
|
|
|
int consumed;
|
|
|
|
|
|
|
|
consumed = SDLTest_CommonArg(state, i);
|
2022-11-26 00:00:06 +00:00
|
|
|
/* needed voodoo to allow app to launch via macOS Finder */
|
2022-11-30 20:51:59 +00:00
|
|
|
if (SDL_strncmp(argv[i], "-psn", 4) == 0) {
|
2015-06-21 15:33:46 +00:00
|
|
|
consumed = 1;
|
|
|
|
}
|
|
|
|
if (consumed == 0) {
|
|
|
|
consumed = -1;
|
|
|
|
}
|
|
|
|
if (consumed < 0) {
|
2019-05-28 21:39:13 +00:00
|
|
|
SDLTest_CommonLogUsage(state, argv[0], NULL);
|
2015-06-21 15:33:46 +00:00
|
|
|
quit(1);
|
|
|
|
}
|
|
|
|
i += consumed;
|
|
|
|
}
|
|
|
|
if (!SDLTest_CommonInit(state)) {
|
|
|
|
quit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-24 01:54:09 +00:00
|
|
|
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, SDL_TRUE);
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
/* Main render loop */
|
|
|
|
done = 0;
|
|
|
|
while (!done) {
|
|
|
|
/* Check for events */
|
|
|
|
while (SDL_PollEvent(&event)) {
|
2023-01-24 01:54:09 +00:00
|
|
|
if (event.type == SDL_EVENT_DROP_BEGIN) {
|
2023-03-06 10:16:18 +00:00
|
|
|
SDL_Log("Drop beginning on window %u at (%f, %f)", (unsigned int)event.drop.windowID, event.drop.x, event.drop.y);
|
2023-01-24 01:54:09 +00:00
|
|
|
} else if (event.type == SDL_EVENT_DROP_COMPLETE) {
|
2023-03-06 10:16:18 +00:00
|
|
|
is_hover = SDL_FALSE;
|
|
|
|
SDL_Log("Drop complete on window %u at (%f, %f)", (unsigned int)event.drop.windowID, event.drop.x, event.drop.y);
|
2023-01-24 01:54:09 +00:00
|
|
|
} else if ((event.type == SDL_EVENT_DROP_FILE) || (event.type == SDL_EVENT_DROP_TEXT)) {
|
|
|
|
const char *typestr = (event.type == SDL_EVENT_DROP_FILE) ? "File" : "Text";
|
2015-06-21 15:33:46 +00:00
|
|
|
char *dropped_filedir = event.drop.file;
|
2023-03-06 10:16:18 +00:00
|
|
|
SDL_Log("%s dropped on window %u: %s at (%f, %f)", typestr, (unsigned int)event.drop.windowID, dropped_filedir, event.drop.x, event.drop.y);
|
2019-07-03 09:37:15 +00:00
|
|
|
/* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
|
|
|
|
/*SDL_free(dropped_filedir);*/
|
2023-03-06 10:16:18 +00:00
|
|
|
} else if (event.type == SDL_EVENT_DROP_POSITION) {
|
|
|
|
is_hover = SDL_TRUE;
|
|
|
|
x = event.drop.x;
|
|
|
|
y = event.drop.y;
|
|
|
|
windowID = event.drop.windowID;
|
|
|
|
SDL_Log("Drop position on window %u at (%f, %f) file = %s", (unsigned int)event.drop.windowID, event.drop.x, event.drop.y, event.drop.file);
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
2019-07-03 09:37:15 +00:00
|
|
|
|
|
|
|
SDLTest_CommonEvent(state, &event, &done);
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
2023-03-06 10:16:18 +00:00
|
|
|
|
|
|
|
for (i = 0; i < state->num_windows; ++i) {
|
|
|
|
SDL_Renderer *renderer = state->renderers[i];
|
|
|
|
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
|
|
|
SDL_RenderClear(renderer);
|
|
|
|
if (is_hover) {
|
|
|
|
if (windowID == SDL_GetWindowID(SDL_GetRenderWindow(renderer))) {
|
|
|
|
int len = 2000;
|
|
|
|
SDL_SetRenderDrawColor(renderer, 0x0A, 0x0A, 0x0A, 0xFF);
|
|
|
|
SDL_RenderLine(renderer, x, y - len, x, y + len);
|
|
|
|
SDL_RenderLine(renderer, x - len, y, x + len, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_RenderPresent(renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Delay(16);
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
quit(0);
|
|
|
|
/* keep the compiler happy ... */
|
2022-11-27 16:38:43 +00:00
|
|
|
return 0;
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|