SDL_CreateWindow() has been simplified and no longer takes a window position.

This commit is contained in:
Sam Lantinga
2023-03-05 14:44:38 -08:00
parent 7905254087
commit 698dbd8464
51 changed files with 106 additions and 326 deletions

View File

@@ -165,14 +165,14 @@ SDL_DYNAPI_PROC(SDL_Palette*,SDL_CreatePalette,(int a),(a),return)
SDL_DYNAPI_PROC(SDL_PixelFormat*,SDL_CreatePixelFormat,(Uint32 a),(a),return)
SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRenderer,(SDL_Window *a, const char *b, Uint32 c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_sem*,SDL_CreateSemaphore,(Uint32 a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateShapedWindow,(const char *a, unsigned int b, unsigned int c, unsigned int d, unsigned int e, Uint32 f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateShapedWindow,(const char *a, int b, int c, Uint32 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateSoftwareRenderer,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurface,(int a, int b, Uint32 c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurfaceFrom,(void *a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateSystemCursor,(SDL_SystemCursor a),(a),return)
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, Uint32 b, int c, int d, int e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindow,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),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(SDL_Window*,SDL_CreateWindowFrom,(const void *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_CursorVisible,(void),(),return)

View File

@@ -727,9 +727,7 @@ static int SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event)
int SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags, SDL_Window **window, SDL_Renderer **renderer)
{
*window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width, height, window_flags);
*window = SDL_CreateWindow(NULL, width, height, window_flags);
if (!*window) {
*renderer = NULL;
return -1;

View File

@@ -81,7 +81,7 @@ SDLTest_CommonCreateState(char **argv, Uint32 flags)
state->argv = argv;
state->flags = flags;
state->window_title = argv[0];
state->window_flags = 0;
state->window_flags = SDL_WINDOW_HIDDEN;
state->window_x = SDL_WINDOWPOS_UNDEFINED;
state->window_y = SDL_WINDOWPOS_UNDEFINED;
state->window_w = DEFAULT_WINDOW_WIDTH;
@@ -1278,10 +1278,6 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
}
SDL_free(displays);
if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->displayID);
state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->displayID);
}
if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->displayID);
state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->displayID);
@@ -1326,13 +1322,15 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
} else {
SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
}
state->windows[i] =
SDL_CreateWindow(title, r.x, r.y, r.w, r.h, state->window_flags);
state->windows[i] = SDL_CreateWindow(title, r.w, r.h, state->window_flags);
if (!state->windows[i]) {
SDL_Log("Couldn't create window: %s\n",
SDL_GetError());
return SDL_FALSE;
}
if (r.x != SDL_WINDOWPOS_UNDEFINED || r.y != SDL_WINDOWPOS_UNDEFINED) {
SDL_SetWindowPosition(state->windows[i], r.x, r.y);
}
if (state->window_minW || state->window_minH) {
SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
}

View File

@@ -24,10 +24,10 @@
#include "SDL_shape_internals.h"
SDL_Window *
SDL_CreateShapedWindow(const char *title, unsigned int x, unsigned int y, unsigned int w, unsigned int h, Uint32 flags)
SDL_CreateShapedWindow(const char *title, int w, int h, Uint32 flags)
{
SDL_Window *result = NULL;
result = SDL_CreateWindow(title, -1000, -1000, w, h, (flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE));
result = SDL_CreateWindow(title, w, h, (flags | SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE));
if (result != NULL) {
if (SDL_GetVideoDevice()->shape_driver.CreateShaper == NULL) {
SDL_DestroyWindow(result);
@@ -35,8 +35,6 @@ SDL_CreateShapedWindow(const char *title, unsigned int x, unsigned int y, unsign
}
result->shaper = SDL_GetVideoDevice()->shape_driver.CreateShaper(result);
if (result->shaper != NULL) {
result->shaper->userx = x;
result->shaper->usery = y;
result->shaper->mode.mode = ShapeModeDefault;
result->shaper->mode.parameters.binarizationCutoff = 1;
result->shaper->hasshape = SDL_FALSE;
@@ -271,11 +269,9 @@ int SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape, SDL_WindowShapeMo
window->shaper->mode = *shape_mode;
}
result = _this->shape_driver.SetWindowShape(window->shaper, shape, shape_mode);
window->shaper->hasshape = SDL_TRUE;
if (window->shaper->userx != 0 && window->shaper->usery != 0) {
SDL_SetWindowPosition(window, window->shaper->userx, window->shaper->usery);
window->shaper->userx = 0;
window->shaper->usery = 0;
if (result == 0) {
window->shaper->hasshape = SDL_TRUE;
SDL_ShowWindow(window);
}
return result;
}

View File

@@ -42,9 +42,6 @@ struct SDL_WindowShaper
/* The window associated with the shaper */
SDL_Window *window;
/* The user's specified coordinates for the window, for once we give it a shape. */
Uint32 userx, usery;
/* The parameters for shape calculation. */
SDL_WindowShapeMode mode;
@@ -59,7 +56,6 @@ struct SDL_ShapeDriver
{
SDL_WindowShaper *(*CreateShaper)(SDL_Window *window);
int (*SetWindowShape)(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode);
int (*ResizeWindowShape)(SDL_Window *window);
};
typedef struct SDL_WindowUserData

View File

@@ -1651,10 +1651,12 @@ static int SDL_DllNotSupported(const char *name)
return SDL_SetError("No dynamic %s support in current SDL video driver (%s)", name, _this->name);
}
SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
SDL_Window *SDL_CreateWindow(const char *title, int w, int h, Uint32 flags)
{
SDL_Window *window;
Uint32 type_flags, graphics_flags;
int x = SDL_WINDOWPOS_UNDEFINED;
int y = SDL_WINDOWPOS_UNDEFINED;
SDL_bool undefined_x = SDL_FALSE;
SDL_bool undefined_y = SDL_FALSE;

View File

@@ -34,6 +34,5 @@
extern SDL_WindowShaper *Cocoa_CreateShaper(SDL_Window *window);
extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode);
extern int Cocoa_ResizeWindowShape(SDL_Window *window);
#endif /* SDL_cocoashape_h_ */

View File

@@ -44,7 +44,6 @@ Cocoa_CreateShaper(SDL_Window *window)
@autoreleasepool {
SDL_WindowShaper *result;
SDL_ShapeData *data;
int resized_properly;
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
@@ -60,7 +59,6 @@ Cocoa_CreateShaper(SDL_Window *window)
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
result->userx = result->usery = 0;
window->shaper = result;
data = [[SDL_ShapeData alloc] init];
@@ -71,8 +69,6 @@ Cocoa_CreateShaper(SDL_Window *window)
/* TODO: There's no place to release this... */
result->driverdata = (void *)CFBridgingRetain(data);
resized_properly = Cocoa_ResizeWindowShape(window);
SDL_assert(resized_properly == 0);
return result;
}
}
@@ -117,13 +113,4 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
}
}
int Cocoa_ResizeWindowShape(SDL_Window *window)
{
@autoreleasepool {
SDL_ShapeData *data = (__bridge SDL_ShapeData *)window->shaper->driverdata;
SDL_assert(data != NULL);
return 0;
}
}
#endif /* SDL_VIDEO_DRIVER_COCOA */

View File

@@ -121,7 +121,6 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
device->shape_driver.CreateShaper = Cocoa_CreateShaper;
device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
device->shape_driver.ResizeWindowShape = Cocoa_ResizeWindowShape;
#if SDL_VIDEO_OPENGL_CGL
device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;

View File

@@ -816,10 +816,6 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
w = (int)rect.size.width;
h = (int)rect.size.height;
if (SDL_IsShapedWindow(window)) {
Cocoa_ResizeWindowShape(window);
}
ScheduleContextUpdates(_data);
/* The window can move during a resize event, such as when maximizing

View File

@@ -96,10 +96,6 @@ static SDL_VideoDevice * HAIKU_CreateDevice(void)
device->UpdateWindowFramebuffer = HAIKU_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = HAIKU_DestroyWindowFramebuffer;
device->shape_driver.CreateShaper = NULL;
device->shape_driver.SetWindowShape = NULL;
device->shape_driver.ResizeWindowShape = NULL;
#if SDL_VIDEO_OPENGL
device->GL_LoadLibrary = HAIKU_GL_LoadLibrary;
device->GL_GetProcAddress = HAIKU_GL_GetProcAddress;

View File

@@ -1131,10 +1131,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int max_w, max_h;
BOOL constrain_max_size;
if (SDL_IsShapedWindow(data->window)) {
Win32_ResizeWindowShape(data->window);
}
/* If this is an expected size change, allow it */
if (data->expected_resize) {
break;

View File

@@ -28,7 +28,6 @@
SDL_WindowShaper *
Win32_CreateShaper(SDL_Window *window)
{
int resized_properly;
SDL_WindowShaper *result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
if (result == NULL) {
SDL_OutOfMemory();
@@ -37,7 +36,6 @@ Win32_CreateShaper(SDL_Window *window)
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
result->userx = result->usery = 0;
result->hasshape = SDL_FALSE;
result->driverdata = (SDL_ShapeData *)SDL_calloc(1, sizeof(SDL_ShapeData));
if (!result->driverdata) {
@@ -46,14 +44,6 @@ Win32_CreateShaper(SDL_Window *window)
return NULL;
}
window->shaper = result;
/* Put some driver-data here. */
resized_properly = Win32_ResizeWindowShape(window);
if (resized_properly != 0) {
SDL_free(result->driverdata);
SDL_free(result);
window->shaper = NULL;
return NULL;
}
return result;
}
@@ -98,28 +88,4 @@ int Win32_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo
return 0;
}
int Win32_ResizeWindowShape(SDL_Window *window)
{
SDL_ShapeData *data;
if (window == NULL) {
return -1;
}
data = (SDL_ShapeData *)window->shaper->driverdata;
if (data == NULL) {
return -1;
}
if (data->mask_tree != NULL) {
SDL_FreeShapeTree(&data->mask_tree);
}
if (window->shaper->hasshape == SDL_TRUE) {
window->shaper->userx = window->x;
window->shaper->usery = window->y;
SDL_SetWindowPosition(window, -1000, -1000);
}
return 0;
}
#endif /* SDL_VIDEO_DRIVER_WINDOWS */

View File

@@ -34,6 +34,5 @@ typedef struct
extern SDL_WindowShaper *Win32_CreateShaper(SDL_Window *window);
extern int Win32_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode);
extern int Win32_ResizeWindowShape(SDL_Window *window);
#endif /* SDL_windowsshape_h_ */

View File

@@ -205,7 +205,6 @@ static SDL_VideoDevice *WIN_CreateDevice(void)
device->shape_driver.CreateShaper = Win32_CreateShaper;
device->shape_driver.SetWindowShape = Win32_SetWindowShape;
device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
#endif
#if SDL_VIDEO_OPENGL_WGL

View File

@@ -44,7 +44,6 @@ X11_CreateShaper(SDL_Window *window)
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
result->userx = result->usery = 0;
data = SDL_malloc(sizeof(SDL_ShapeData));
if (data == NULL) {
SDL_free(result);
@@ -55,45 +54,12 @@ X11_CreateShaper(SDL_Window *window)
data->bitmapsize = 0;
data->bitmap = NULL;
window->shaper = result;
if (X11_ResizeWindowShape(window) != 0) {
SDL_free(result);
SDL_free(data);
window->shaper = NULL;
return NULL;
}
}
#endif
return result;
}
int X11_ResizeWindowShape(SDL_Window *window)
{
SDL_ShapeData *data = window->shaper->driverdata;
unsigned int bitmapsize = window->w / 8;
SDL_assert(data != NULL);
if (window->w % 8 > 0) {
bitmapsize += 1;
}
bitmapsize *= window->h;
if (data->bitmapsize != bitmapsize || data->bitmap == NULL) {
data->bitmapsize = bitmapsize;
SDL_free(data->bitmap);
data->bitmap = SDL_malloc(data->bitmapsize);
if (data->bitmap == NULL) {
return SDL_OutOfMemory();
}
}
SDL_memset(data->bitmap, 0, data->bitmapsize);
window->shaper->userx = window->x;
window->shaper->usery = window->y;
SDL_SetWindowPosition(window, -1000, -1000);
return 0;
}
int X11_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
{
#if SDL_VIDEO_DRIVER_X11_XSHAPE

View File

@@ -32,7 +32,6 @@ typedef struct
} SDL_ShapeData;
extern SDL_WindowShaper *X11_CreateShaper(SDL_Window *window);
extern int X11_ResizeWindowShape(SDL_Window *window);
extern int X11_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode);
#endif /* SDL_x11shape_h_ */

View File

@@ -260,7 +260,6 @@ static SDL_VideoDevice *X11_CreateDevice(void)
device->shape_driver.CreateShaper = X11_CreateShaper;
device->shape_driver.SetWindowShape = X11_SetWindowShape;
device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;
#if SDL_VIDEO_OPENGL_GLX
device->GL_LoadLibrary = X11_GL_LoadLibrary;

View File

@@ -941,9 +941,6 @@ void X11_SetWindowSize(_THIS, SDL_Window *window)
orig_w = attrs.width;
orig_h = attrs.height;
if (SDL_IsShapedWindow(window)) {
X11_ResizeWindowShape(window);
}
if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
/* Apparently, if the X11 Window is set to a 'non-resizable' window, you cannot resize it using the X11_XResizeWindow, thus
we must set the size hints to adjust the window size. */