mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-20 22:35:41 +00:00
Changed main callback return values to an enumeration
Fixes https://github.com/libsdl-org/SDL/issues/10515
This commit is contained in:
@@ -42,7 +42,7 @@ static int fillerup(void)
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char *filename = NULL;
|
||||
@@ -120,12 +120,12 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
return (event->type == SDL_EVENT_QUIT) ? SDL_APP_SUCCESS : SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void *appstate)
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
return fillerup();
|
||||
}
|
||||
|
||||
@@ -1073,7 +1073,7 @@ static void WindowResized(const int newwinw, const int newwinh)
|
||||
state->window_h = newwinh;
|
||||
}
|
||||
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -1131,7 +1131,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
|
||||
static SDL_bool saw_event = SDL_FALSE;
|
||||
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
Thing *thing = NULL;
|
||||
|
||||
@@ -1254,7 +1254,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
return SDLTest_CommonEventMainCallbacks(state, event);
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void *appstate)
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
if (app_ready_ticks == 0) {
|
||||
app_ready_ticks = SDL_GetTicks();
|
||||
|
||||
@@ -21,7 +21,7 @@ static SDL_AudioStream *stream_in = NULL;
|
||||
static SDL_AudioStream *stream_out = NULL;
|
||||
static SDLTest_CommonState *state = NULL;
|
||||
|
||||
int SDL_AppInit(void **appstate, int argc, char **argv)
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv)
|
||||
{
|
||||
SDL_AudioDeviceID *devices;
|
||||
SDL_AudioSpec outspec;
|
||||
@@ -149,7 +149,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
if (event->type == SDL_EVENT_QUIT) {
|
||||
return SDL_APP_SUCCESS;
|
||||
@@ -173,7 +173,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void *appstate)
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
if (!SDL_AudioDevicePaused(SDL_GetAudioStreamDevice(stream_in))) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||
|
||||
@@ -46,7 +46,7 @@ static void PrintCameraSpecs(SDL_CameraID camera_id)
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
char window_title[128];
|
||||
int devcount = 0;
|
||||
@@ -216,7 +216,7 @@ static int FlipCamera(void)
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
switch (event->type) {
|
||||
case SDL_EVENT_KEY_DOWN: {
|
||||
@@ -262,7 +262,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
return SDLTest_CommonEventMainCallbacks(state, event);
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void *appstate)
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
iterate_count++;
|
||||
|
||||
|
||||
@@ -22,51 +22,8 @@ typedef struct {
|
||||
unsigned int windowID;
|
||||
} dropfile_dialog;
|
||||
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
dropfile_dialog *dialog = appstate;
|
||||
if (event->type == SDL_EVENT_DROP_BEGIN) {
|
||||
SDL_Log("Drop beginning on window %u at (%f, %f)", (unsigned int)event->drop.windowID, event->drop.x, event->drop.y);
|
||||
} else if (event->type == SDL_EVENT_DROP_COMPLETE) {
|
||||
dialog->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);
|
||||
} 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";
|
||||
SDL_Log("%s dropped on window %u: %s at (%f, %f)", typestr, (unsigned int)event->drop.windowID, event->drop.data, event->drop.x, event->drop.y);
|
||||
} else if (event->type == SDL_EVENT_DROP_POSITION) {
|
||||
dialog->is_hover = SDL_TRUE;
|
||||
dialog->x = event->drop.x;
|
||||
dialog->y = event->drop.y;
|
||||
dialog->windowID = event->drop.windowID;
|
||||
SDL_Log("Drop position on window %u at (%f, %f) data = %s", (unsigned int)event->drop.windowID, event->drop.x, event->drop.y, event->drop.data);
|
||||
}
|
||||
|
||||
return SDLTest_CommonEventMainCallbacks(dialog->state, event);
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void *appstate)
|
||||
{
|
||||
dropfile_dialog *dialog = appstate;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dialog->state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = dialog->state->renderers[i];
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
if (dialog->is_hover) {
|
||||
if (dialog->windowID == SDL_GetWindowID(SDL_GetRenderWindow(renderer))) {
|
||||
int len = 2000;
|
||||
SDL_SetRenderDrawColor(renderer, 0x0A, 0x0A, 0x0A, 0xFF);
|
||||
SDL_RenderLine(renderer, dialog->x, dialog->y - len, dialog->x, dialog->y + len);
|
||||
SDL_RenderLine(renderer, dialog->x - len, dialog->y, dialog->x + len, dialog->y);
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
||||
int i;
|
||||
dropfile_dialog *dialog;
|
||||
SDLTest_CommonState *state;
|
||||
@@ -113,6 +70,50 @@ onerror:
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
dropfile_dialog *dialog = appstate;
|
||||
if (event->type == SDL_EVENT_DROP_BEGIN) {
|
||||
SDL_Log("Drop beginning on window %u at (%f, %f)", (unsigned int)event->drop.windowID, event->drop.x, event->drop.y);
|
||||
} else if (event->type == SDL_EVENT_DROP_COMPLETE) {
|
||||
dialog->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);
|
||||
} 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";
|
||||
SDL_Log("%s dropped on window %u: %s at (%f, %f)", typestr, (unsigned int)event->drop.windowID, event->drop.data, event->drop.x, event->drop.y);
|
||||
} else if (event->type == SDL_EVENT_DROP_POSITION) {
|
||||
dialog->is_hover = SDL_TRUE;
|
||||
dialog->x = event->drop.x;
|
||||
dialog->y = event->drop.y;
|
||||
dialog->windowID = event->drop.windowID;
|
||||
SDL_Log("Drop position on window %u at (%f, %f) data = %s", (unsigned int)event->drop.windowID, event->drop.x, event->drop.y, event->drop.data);
|
||||
}
|
||||
|
||||
return SDLTest_CommonEventMainCallbacks(dialog->state, event);
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
dropfile_dialog *dialog = appstate;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dialog->state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = dialog->state->renderers[i];
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
if (dialog->is_hover) {
|
||||
if (dialog->windowID == SDL_GetWindowID(SDL_GetRenderWindow(renderer))) {
|
||||
int len = 2000;
|
||||
SDL_SetRenderDrawColor(renderer, 0x0A, 0x0A, 0x0A, 0xFF);
|
||||
SDL_RenderLine(renderer, dialog->x, dialog->y - len, dialog->x, dialog->y + len);
|
||||
SDL_RenderLine(renderer, dialog->x - len, dialog->y, dialog->x + len, dialog->y);
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
void SDL_AppQuit(void *appstate)
|
||||
{
|
||||
dropfile_dialog *dialog = appstate;
|
||||
|
||||
@@ -34,7 +34,7 @@ static SDL_Texture *white_pixel = NULL;
|
||||
static Pen pens;
|
||||
|
||||
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -107,7 +107,7 @@ static Pen *FindPen(SDL_PenID which)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
Pen *pen = NULL;
|
||||
|
||||
@@ -259,7 +259,7 @@ static void DrawOnePen(Pen *pen, int num)
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void *appstate)
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
int num = 0;
|
||||
Pen *pen;
|
||||
|
||||
@@ -385,46 +385,7 @@ static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
return SDLTest_CommonEventMainCallbacks(state, event);
|
||||
}
|
||||
|
||||
int SDL_AppIterate(void *appstate)
|
||||
{
|
||||
Uint64 now;
|
||||
int i;
|
||||
int active_windows = 0;
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL ||
|
||||
(suspend_when_occluded && (SDL_GetWindowFlags(state->windows[i]) & SDL_WINDOW_OCCLUDED))) {
|
||||
continue;
|
||||
}
|
||||
++active_windows;
|
||||
MoveSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
|
||||
/* If all windows are occluded, throttle the event polling to 15hz. */
|
||||
if (!active_windows) {
|
||||
SDL_DelayNS(SDL_NS_PER_SECOND / 15);
|
||||
}
|
||||
|
||||
frames++;
|
||||
now = SDL_GetTicks();
|
||||
if (now >= next_fps_check) {
|
||||
/* Print out some timing information */
|
||||
const Uint64 then = next_fps_check - fps_check_delay;
|
||||
const double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
next_fps_check = now + fps_check_delay;
|
||||
frames = 0;
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_Rect safe_area;
|
||||
int i;
|
||||
@@ -488,7 +449,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
|
||||
cycle_alpha = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if(SDL_strcasecmp(argv[i], "--suspend-when-occluded") == 0) {
|
||||
} else if (SDL_strcasecmp(argv[i], "--suspend-when-occluded") == 0) {
|
||||
suspend_when_occluded = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--use-rendergeometry") == 0) {
|
||||
@@ -589,3 +550,42 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
|
||||
{
|
||||
return SDLTest_CommonEventMainCallbacks(state, event);
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
Uint64 now;
|
||||
int i;
|
||||
int active_windows = 0;
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL ||
|
||||
(suspend_when_occluded && (SDL_GetWindowFlags(state->windows[i]) & SDL_WINDOW_OCCLUDED))) {
|
||||
continue;
|
||||
}
|
||||
++active_windows;
|
||||
MoveSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
|
||||
/* If all windows are occluded, throttle the event polling to 15hz. */
|
||||
if (!active_windows) {
|
||||
SDL_DelayNS(SDL_NS_PER_SECOND / 15);
|
||||
}
|
||||
|
||||
frames++;
|
||||
now = SDL_GetTicks();
|
||||
if (now >= next_fps_check) {
|
||||
/* Print out some timing information */
|
||||
const Uint64 then = next_fps_check - fps_check_delay;
|
||||
const double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
next_fps_check = now + fps_check_delay;
|
||||
frames = 0;
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user