Split Window_Create into Window_Create2D/3D

This commit is contained in:
UnknownShadow200 2021-09-14 07:01:31 +10:00
parent f595a5bca8
commit 50ee66a6f8
11 changed files with 35 additions and 16 deletions

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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 */

View File

@ -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];

View File

@ -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];

View File

@ -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) {

View File

@ -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];

View File

@ -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];

View File

@ -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];

View File

@ -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) { }