From 50ee66a6f8f8e104cb1fb706cddf68e46cea87b0 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 14 Sep 2021 07:01:31 +1000 Subject: [PATCH] Split Window_Create into Window_Create2D/3D --- src/Game.c | 2 +- src/Launcher.c | 2 +- src/Window.h | 8 ++++++-- src/Window_Android.c | 4 +++- src/Window_Carbon.c | 4 +++- src/Window_SDL.c | 7 ++++--- src/Window_Web.c | 4 +++- src/Window_Win.c | 8 +++++--- src/Window_X11.c | 4 +++- src/interop_cocoa.m | 4 +++- src/interop_ios.m | 4 +++- 11 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/Game.c b/src/Game.c index 9fbddb225..2cb330e44 100644 --- a/src/Game.c +++ b/src/Game.c @@ -663,7 +663,7 @@ static void Game_RunLoop(void) { #endif void Game_Run(int width, int height, const cc_string* title) { - Window_Create(width, height); + Window_Create3D(width, height); Window_SetTitle(title); Window_Show(); diff --git a/src/Launcher.c b/src/Launcher.c index 2f72dc05c..d24eac962 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -278,7 +278,7 @@ static void Launcher_Free(void) { void Launcher_Run(void) { static const cc_string title = String_FromConst(GAME_APP_TITLE); - Window_Create(640, 400); + Window_Create2D(640, 400); #ifdef CC_BUILD_MOBILE Window_LockLandscapeOrientation(Options_GetBool(OPT_LANDSCAPE_MODE, false)); #endif diff --git a/src/Window.h b/src/Window.h index dc9e9ca0b..d27be24c9 100644 --- a/src/Window.h +++ b/src/Window.h @@ -79,8 +79,12 @@ CC_VAR extern struct _WinData { /* Initialises state for window. Also sets Display_ members. */ void Window_Init(void); -/* Creates the window as the given size at centre of the screen. */ -void Window_Create(int width, int height); +/* Creates a window of the given size at centre of the screen. */ +/* NOTE: The created window is compatible with 2D drawing */ +void Window_Create2D(int width, int height); +/* Creates a window of the given size at centre of the screen. */ +/* NOTE: The created window is compatible with 3D rendering */ +void Window_Create3D(int width, int height); /* Sets the text of the titlebar above the window. */ CC_API void Window_SetTitle(const cc_string* title); diff --git a/src/Window_Android.c b/src/Window_Android.c index 83651af23..585246b7f 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -254,13 +254,15 @@ static void Window_RemakeSurface(void) { Platform_LogConst("OK window created.."); } -void Window_Create(int width, int height) { +static void DoCreateWindow(void) { WindowInfo.Exists = true; /* actual window creation is done when processSurfaceCreated is received */ Window_RemakeSurface(); /* always start as fullscreen */ Window_EnterFullscrene(); } +void Window_Create2D(int width, int height) { DoCreateWindow(); } +void Window_Create3D(int width, int height) { DoCreateWindow(); } void Window_SetTitle(const cc_string* title) { /* TODO: Implement this somehow */ diff --git a/src/Window_Carbon.c b/src/Window_Carbon.c index d894c17b6..bf102acb0 100644 --- a/src/Window_Carbon.c +++ b/src/Window_Carbon.c @@ -479,7 +479,7 @@ static void ApplyIcon(void) { static void ApplyIcon(void) { } #endif -void Window_Create(int width, int height) { +static void DoCreateWindow(int width, int height) { Rect r; OSStatus res; ProcessSerialNumber psn; @@ -507,6 +507,8 @@ void Window_Create(int width, int height) { winId = GetNativeWindowFromWindowRef(win_handle); ApplyIcon(); } +void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } +void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } void Window_SetTitle(const cc_string* title) { UInt8 str[NATIVE_STR_LEN]; diff --git a/src/Window_SDL.c b/src/Window_SDL.c index 269f78681..51baa1e10 100644 --- a/src/Window_SDL.c +++ b/src/Window_SDL.c @@ -35,18 +35,19 @@ void Window_Init(void) { DisplayInfo.ScaleY = 1; } -void Window_Create(int width, int height) { +static void DoCreateWindow(int width, int height, int flags) { int x = Display_CentreX(width); int y = Display_CentreY(height); - /* 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, flags); if (!win_handle) Window_SDLFail("creating window"); RefreshWindowBounds(); WindowInfo.Exists = true; WindowInfo.Handle = win_handle; } +void Window_Create2D(int width, int height) { DoCreateWindow(width, height, 0); } +void Window_Create3D(int width, int height) { DoCreateWindow(width, height, SDL_WINDOW_OPENGL); } void Window_SetTitle(const cc_string* title) { char str[NATIVE_STR_LEN]; diff --git a/src/Window_Web.c b/src/Window_Web.c index 85c3c32fa..c6d22b8fc 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -376,7 +376,7 @@ void Window_Init(void) { } extern void interop_InitContainer(void); -void Window_Create(int width, int height) { +static void DoCreateWindow(void) { WindowInfo.Exists = true; WindowInfo.Focused = true; HookEvents(); @@ -385,6 +385,8 @@ void Window_Create(int width, int height) { WindowInfo.Height = interop_CanvasHeight(); interop_InitContainer(); } +void Window_Create2D(int width, int height) { DoCreateWindow(); } +void Window_Create3D(int width, int height) { DoCreateWindow(); } extern void interop_SetPageTitle(const char* title); void Window_SetTitle(const cc_string* title) { diff --git a/src/Window_Win.c b/src/Window_Win.c index 3c63ba51a..0adea55ab 100644 --- a/src/Window_Win.c +++ b/src/Window_Win.c @@ -285,7 +285,7 @@ static ATOM DoRegisterClass(void) { return RegisterClassExA((const WNDCLASSEXA*)&wc); } -static void DoCreateWindow(ATOM atom, int width, int height) { +static void CreateWindowHandle(ATOM atom, int width, int height) { cc_result res; RECT r; /* Calculate final window rectangle after window decorations are added (titlebar, borders etc) */ @@ -307,7 +307,7 @@ static void DoCreateWindow(ATOM atom, int width, int height) { Logger_Abort2(res, "Failed to create window"); } -void Window_Create(int width, int height) { +static void DoCreateWindow(int width, int height) { ATOM atom; win_instance = GetModuleHandleA(NULL); /* TODO: UngroupFromTaskbar(); */ @@ -315,7 +315,7 @@ void Window_Create(int width, int height) { height = Display_ScaleY(height); atom = DoRegisterClass(); - DoCreateWindow(atom, width, height); + CreateWindowHandle(atom, width, height); RefreshWindowBounds(); win_DC = GetDC(win_handle); @@ -323,6 +323,8 @@ void Window_Create(int width, int height) { WindowInfo.Exists = true; WindowInfo.Handle = win_handle; } +void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } +void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } void Window_SetTitle(const cc_string* title) { WCHAR str[NATIVE_STR_LEN]; diff --git a/src/Window_X11.c b/src/Window_X11.c index bb5fd248f..7b96ce1f4 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -278,7 +278,7 @@ static void ApplyIcon(void) { static void ApplyIcon(void) { } #endif -void Window_Create(int width, int height) { +static void DoCreateWindow(int width, int height) { XSetWindowAttributes attributes = { 0 }; XSizeHints hints = { 0 }; Atom protocols[2]; @@ -340,6 +340,8 @@ void Window_Create(int width, int height) { XGetInputFocus(win_display, &focus, &focusRevert); if (focus == win_handle) WindowInfo.Focused = true; } +void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } +void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } void Window_SetTitle(const cc_string* title) { char str[NATIVE_STR_LEN]; diff --git a/src/interop_cocoa.m b/src/interop_cocoa.m index d189e17b2..e3acc3d3b 100644 --- a/src/interop_cocoa.m +++ b/src/interop_cocoa.m @@ -262,7 +262,7 @@ static void ApplyIcon(void) { } #endif #define WIN_MASK (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask) -void Window_Create(int width, int height) { +static void DoCreateWindow(void) { CCWindowDelegate* del; NSRect rect; @@ -287,6 +287,8 @@ void Window_Create(int width, int height) { MakeContentView(); ApplyIcon(); } +void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } +void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } void Window_SetTitle(const cc_string* title) { char raw[NATIVE_STR_LEN]; diff --git a/src/interop_ios.m b/src/interop_ios.m index 200ac2dcd..11a1b39ee 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -123,7 +123,7 @@ void Window_Init(void) { DisplayInfo.ScaleY = 1; // TODO dpi scale } -void Window_Create(int width, int height) { +static void DoCreateWindow(void) { CGRect bounds = UIScreen.mainScreen.bounds; controller = [CCViewController alloc]; winHandle = [[CCWindow alloc] initWithFrame:bounds]; @@ -134,6 +134,8 @@ void Window_Create(int width, int height) { WindowInfo.Width = bounds.size.width; WindowInfo.Height = bounds.size.height; } +void Window_Create2D(int width, int height) { DoCreateWindow(); } +void Window_Create3D(int width, int height) { DoCreateWindow(); } void Window_SetSize(int width, int height) { } void Window_Close(void) { }