From 14f584a94bfd49cf1524db75bf3c419fdf9436cd Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 25 Apr 2024 19:37:19 -0700 Subject: [PATCH] SDL_CreateWindowAndRenderer() takes the window title as the first parameter Fixes https://github.com/libsdl-org/SDL/issues/9626 --- docs/README-migration.md | 2 ++ include/SDL3/SDL_render.h | 3 ++- src/dynapi/SDL_dynapi_procs.h | 2 +- src/render/SDL_render.c | 4 ++-- test/testaudiocapture.c | 2 +- test/testdialog.c | 2 +- test/testspriteminimal.c | 6 +----- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/README-migration.md b/docs/README-migration.md index b0b1f5c74..7d45e93e7 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -1092,6 +1092,8 @@ which index is the "opengl" or whatnot driver, you can just pass that string dir here, now. Passing NULL is the same as passing -1 here in SDL2, to signify you want SDL to decide for you. +SDL_CreateWindowAndRenderer() now takes the window title as the first parameter. + Mouse and touch events are no longer filtered to change their coordinates, instead you can call SDL_ConvertEventToRenderCoordinates() to explicitly map event coordinates into the rendering viewport. diff --git a/include/SDL3/SDL_render.h b/include/SDL3/SDL_render.h index d5d8b853d..95aa16c38 100644 --- a/include/SDL3/SDL_render.h +++ b/include/SDL3/SDL_render.h @@ -196,6 +196,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetRenderDriver(int index); /** * Create a window and default renderer. * + * \param title the title of the window, in UTF-8 encoding * \param width the width of the window * \param height the height of the window * \param window_flags the flags used to create the window (see @@ -210,7 +211,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetRenderDriver(int index); * \sa SDL_CreateRenderer * \sa SDL_CreateWindow */ -extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer); +extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer); /** * Create a 2D rendering context for a window. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index bec117dd2..b319dddb1 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -151,7 +151,7 @@ SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, SDL_PixelFormat SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureWithProperties,(SDL_Renderer *a, SDL_PropertiesID b),(a,b),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindow,(const char *a, int b, int c, Uint32 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer **e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(const char *a, int b, int c, Uint32 d, SDL_Window **e, SDL_Renderer **f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowWithProperties,(SDL_PropertiesID a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_CursorVisible,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_DXGIGetOutputInfo,(SDL_DisplayID a, int *b, int *c),(a,b,c),return) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 3763eedec..b7d992f66 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -826,7 +826,7 @@ static int SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event) return 0; } -int SDL_CreateWindowAndRenderer(int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer) +int SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer) { SDL_bool hidden = (window_flags & SDL_WINDOW_HIDDEN) != 0; @@ -840,7 +840,7 @@ int SDL_CreateWindowAndRenderer(int width, int height, SDL_WindowFlags window_fl // Hide the window so if the renderer recreates it, we don't get a visual flash on screen window_flags |= SDL_WINDOW_HIDDEN; - *window = SDL_CreateWindow(NULL, width, height, window_flags); + *window = SDL_CreateWindow(title, width, height, window_flags); if (!*window) { *renderer = NULL; return -1; diff --git a/test/testaudiocapture.c b/test/testaudiocapture.c index 82027019e..a1a88be2b 100644 --- a/test/testaudiocapture.c +++ b/test/testaudiocapture.c @@ -69,7 +69,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv) return 1; } - if (SDL_CreateWindowAndRenderer(320, 240, 0, &window, &renderer) < 0) { + if (SDL_CreateWindowAndRenderer("testaudiocapture", 320, 240, 0, &window, &renderer) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window and renderer: %s\n", SDL_GetError()); return 1; } diff --git a/test/testdialog.c b/test/testdialog.c index 218db653a..333ebb503 100644 --- a/test/testdialog.c +++ b/test/testdialog.c @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) { SDL_Log("SDL_Init failed (%s)", SDL_GetError()); return 1; } - if (SDL_CreateWindowAndRenderer(640, 480, 0, &w, &r) < 0) { + if (SDL_CreateWindowAndRenderer("testdialog", 640, 480, 0, &w, &r) < 0) { SDL_Log("Failed to create window and/or renderer: %s\n", SDL_GetError()); SDL_Quit(); return 1; diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c index e1591a99b..8849b8916 100644 --- a/test/testspriteminimal.c +++ b/test/testspriteminimal.c @@ -122,15 +122,11 @@ int main(int argc, char *argv[]) goto quit; } - if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) { + if (SDL_CreateWindowAndRenderer("testspriteminimal", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) { return_code = 2; goto quit; } - if (SDL_SetWindowTitle(window, argv[0]) < 0) { - SDL_Log("SDL_SetWindowTitle: %s", SDL_GetError()); - } - sprite = CreateTexture(renderer, icon_bmp, icon_bmp_len, &sprite_w, &sprite_h); if (!sprite) {