Get rid of Window_CreateSimple and just have Window_Create work out x/y instead

This commit is contained in:
UnknownShadow200 2019-07-28 13:12:07 +10:00
parent 824e43a1ea
commit 7fc6007e49
4 changed files with 28 additions and 31 deletions

View File

@ -726,7 +726,7 @@ static void Game_RunLoop(void) {
#endif #endif
void Game_Run(int width, int height, const String* title) { void Game_Run(int width, int height, const String* title) {
Window_CreateSimple(width, height); Window_Create(width, height);
Window_SetTitle(title); Window_SetTitle(title);
Window_SetVisible(true); Window_SetVisible(true);

View File

@ -216,7 +216,7 @@ static void Launcher_Free(void) {
void Launcher_Run(void) { void Launcher_Run(void) {
static const String title = String_FromConst(GAME_APP_TITLE); static const String title = String_FromConst(GAME_APP_TITLE);
Window_CreateSimple(640, 400); Window_Create(640, 400);
Window_SetTitle(&title); Window_SetTitle(&title);
Window_SetVisible(true); Window_SetVisible(true);

View File

@ -14,17 +14,8 @@ Rect2D Display_Bounds;
int Window_X, Window_Y, Window_Width, Window_Height; int Window_X, Window_Y, Window_Width, Window_Height;
bool Window_Exists, Window_Focused; bool Window_Exists, Window_Focused;
const void* Window_Handle; const void* Window_Handle;
#define Window_CentreX(width) (Display_Bounds.X + (Display_Bounds.Width - width) / 2)
void Window_CreateSimple(int width, int height) { #define Window_CentreY(height) (Display_Bounds.Y + (Display_Bounds.Height - height) / 2)
struct GraphicsMode mode;
int x, y;
x = Display_Bounds.X + (Display_Bounds.Width - width) / 2;
y = Display_Bounds.Y + (Display_Bounds.Height - height) / 2;
GraphicsMode_MakeDefault(&mode);
Window_Create(x, y, width, height, &mode);
}
#ifndef CC_BUILD_WEBCANVAS #ifndef CC_BUILD_WEBCANVAS
void Clipboard_RequestText(RequestClipboardCallback callback, void* obj) { void Clipboard_RequestText(RequestClipboardCallback callback, void* obj) {
@ -360,13 +351,15 @@ void Window_Init(void) {
ReleaseDC(NULL, hdc); ReleaseDC(NULL, hdc);
} }
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode) { void Window_Create(int width, int height) {
RECT r;
win_instance = GetModuleHandle(NULL); win_instance = GetModuleHandle(NULL);
/* TODO: UngroupFromTaskbar(); */ /* TODO: UngroupFromTaskbar(); */
/* Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). */ /* Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). */
RECT rect = { x, y, x + width, y + height }; r.left = Window_CentreX(width); r.right = r.left + width;
AdjustWindowRect(&rect, CC_WIN_STYLE, false); r.top = Window_CentreY(height); r.bottom = r.top + height;
AdjustWindowRect(&r, CC_WIN_STYLE, false);
WNDCLASSEX wc = { 0 }; WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(WNDCLASSEX); wc.cbSize = sizeof(WNDCLASSEX);
@ -385,8 +378,7 @@ void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mod
if (!atom) Logger_Abort2(GetLastError(), "Failed to register window class"); if (!atom) Logger_Abort2(GetLastError(), "Failed to register window class");
win_handle = CreateWindowEx(0, MAKEINTATOM(atom), NULL, CC_WIN_STYLE, win_handle = CreateWindowEx(0, MAKEINTATOM(atom), NULL, CC_WIN_STYLE,
rect.left, rect.top, Rect_Width(rect), Rect_Height(rect), r.left, r.top, Rect_Width(r), Rect_Height(r), NULL, NULL, win_instance, NULL);
NULL, NULL, win_instance, NULL);
if (!win_handle) Logger_Abort2(GetLastError(), "Failed to create window"); if (!win_handle) Logger_Abort2(GetLastError(), "Failed to create window");
Window_RefreshBounds(); Window_RefreshBounds();
@ -801,11 +793,16 @@ void Window_Init(void) {
Display_BitsPerPixel = DefaultDepth(display, screen); Display_BitsPerPixel = DefaultDepth(display, screen);
} }
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode) { void Window_Create(int width, int height) {
XSetWindowAttributes attributes = { 0 }; XSetWindowAttributes attributes = { 0 };
XSizeHints hints = { 0 }; XSizeHints hints = { 0 };
struct GraphicsMode mode;
uintptr_t addr; uintptr_t addr;
int supported; int supported, x, y;
x = Window_CentreX(width);
y = Window_CentreY(height);
GraphicsMode_MakeDefault(&mode);
/* Open a display connection to the X server, and obtain the screen and root window */ /* Open a display connection to the X server, and obtain the screen and root window */
addr = (uintptr_t)win_display; addr = (uintptr_t)win_display;
@ -1746,13 +1743,13 @@ void Window_Init(void) {
Display_BitsPerPixel = CGDisplayBitsPerPixel(display); Display_BitsPerPixel = CGDisplayBitsPerPixel(display);
} }
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode) { void Window_Create(int width, int height) {
Rect r; Rect r;
OSStatus res; OSStatus res;
ProcessSerialNumber psn; ProcessSerialNumber psn;
r.left = x; r.right = x + width; r.left = Window_CentreX(width); r.right = r.left + width;
r.top = y; r.bottom = y + height; r.top = Window_CentreY(height); r.bottom = r.top + height;
res = CreateNewWindow(kDocumentWindowClass, res = CreateNewWindow(kDocumentWindowClass,
kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute |
kWindowInWindowMenuAttribute | kWindowLiveResizeAttribute, &r, &win_handle); kWindowInWindowMenuAttribute | kWindowLiveResizeAttribute, &r, &win_handle);
@ -2039,7 +2036,10 @@ void Window_Init(void) {
Display_BitsPerPixel = SDL_BITSPERPIXEL(mode.format); Display_BitsPerPixel = SDL_BITSPERPIXEL(mode.format);
} }
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode) { void Window_Create(int width, int height) {
int x = Window_CentreX(width);
int y = Window_CentreY(height);
/* TODO: Don't set this flag for launcher window */ /* TODO: Don't set this flag for launcher window */
win_handle = SDL_CreateWindow(NULL, x, y, width, height, SDL_WINDOW_OPENGL); win_handle = SDL_CreateWindow(NULL, x, y, width, height, SDL_WINDOW_OPENGL);
if (!win_handle) Window_SDLFail("creating window"); if (!win_handle) Window_SDLFail("creating window");
@ -2654,7 +2654,7 @@ void Window_Init(void) {
); );
} }
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode) { void Window_Create(int width, int height) {
Window_Exists = true; Window_Exists = true;
Window_Focused = true; Window_Focused = true;
Window_HookEvents(); Window_HookEvents();
@ -2998,7 +2998,7 @@ void Window_Init(void) {
Display_DpiY = JavaCallInt(env, "getDpiY", "()I", NULL); Display_DpiY = JavaCallInt(env, "getDpiY", "()I", NULL);
} }
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode) { void Window_Create(int width, int height) {
Window_Exists = true; Window_Exists = true;
/* actual window creation is done when APP_CMD_INIT_WINDOW is received */ /* actual window creation is done when APP_CMD_INIT_WINDOW is received */
} }

View File

@ -64,11 +64,8 @@ extern const void* Window_Handle;
void Window_Init(void); void Window_Init(void);
/* Creates a GraphicsMode compatible with the default display device. */ /* Creates a GraphicsMode compatible with the default display device. */
void GraphicsMode_MakeDefault(struct GraphicsMode* m); void GraphicsMode_MakeDefault(struct GraphicsMode* m);
/* Creates the window as the given size at centre of the screen. */
/* Creates the window as the given size at centre of the screen, with default graphics mode. */ void Window_Create(int width, int height);
void Window_CreateSimple(int width, int height);
/* Creates the window as the given size at the given position on screen. */
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode);
/* Sets the text of the titlebar above the window. */ /* Sets the text of the titlebar above the window. */
CC_API void Window_SetTitle(const String* title); CC_API void Window_SetTitle(const String* title);
/* TODO: IMPLEMENT void Window_SetIcon(Bitmap* bmp); */ /* TODO: IMPLEMENT void Window_SetIcon(Bitmap* bmp); */