get a window showing

This commit is contained in:
UnknownShadow200 2019-09-08 22:19:47 +10:00
parent 672eeb904c
commit d44177806e

View File

@ -3658,61 +3658,32 @@ void GLContext_SetFpsLimit(bool vsync, float minFrameMs) {
#ifdef CC_BUILD_COCOA #ifdef CC_BUILD_COCOA
#include <objc/message.h> #include <objc/message.h>
#include <objc/runtime.h> #include <objc/runtime.h>
#include <stdlib.h> #include <ApplicationServices/ApplicationServices.h>
#include <stdio.h>
static id appHandle; static id appHandle;
static id winHandle; static id winHandle;
//extern id NSApp;
typedef struct FailRect_ {
// TODO: use CGFloat because that works with 32 bit
double x, y;
double width, height;
} FailRect;
id Cocoa_SendIntPtr(id receiver, SEL op) {
IMP func = objc_msg_lookup(receiver, op);
return func(receiver, op);
}
id Cocoa_SendIntPtr_I(id receiver, SEL op, int a1) {
IMP func = objc_msg_lookup(receiver, op);
return func(receiver, op, a1);
}
id Cocoa_SendIntPtr_P(id receiver, SEL op, id a1) {
IMP func = objc_msg_lookup(receiver, op);
return func(receiver, op, a1);
}
void Cocoa_SendIntPtr_R(id receiver, SEL op, FailRect* r) {
IMP func = objc_msg_lookup(receiver, op);
func(receiver, op, r);
}
id cmacs_window_init_msgSend(id receiver, SEL op, FailRect a1, int a2, int a3, bool a4) {
IMP func = objc_msg_lookup(receiver, op);
return func(receiver, op, a1, a2, a3, a4);
}
void Window_Init(void) { void Window_Init(void) {
id screen, screens; id screen, screens;
int count; int count;
FailRect rect = { 1, 2, 3, 4 }; CGRect rect = { 1, 2, 3, 4 };
Platform_LogConst("hi world"); Platform_LogConst("hi world");
appHandle = Cocoa_SendIntPtr((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication")); appHandle = objc_msgSend((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
Platform_LogConst("all gudd!!"); Platform_LogConst("all good!");
// TODO: why's this bit of code completely stuffed // TODO: why's this bit of code completely stuffed
screens = Cocoa_SendIntPtr((id)objc_getClass("NSScreen"), sel_registerName("screens")); screens = objc_msgSend((id)objc_getClass("NSScreen"), sel_registerName("screens"));
count = Cocoa_SendIntPtr(screens, sel_registerName("count")); count = objc_msgSend(screens, sel_registerName("count"));
Platform_Log1("COUNT: %i", &count); Platform_Log1("COUNT: %i", &count);
screen = Cocoa_SendIntPtr_I(screens, sel_registerName("objectAtIndex:"), 0); Display_Bounds.Width = 1024;
Cocoa_SendIntPtr_R(screen, sel_registerName("frame"), &rect); Display_Bounds.Height = 768;
Platform_LogConst("GOT FRAME"); //screen = objc_msgSend(screens, sel_registerName("objectAtIndex:"), 0);
printf("STUFF: %f,%f,%f,%f", rect.x, rect.y, rect.width, rect.height); //objc_msgSend_stret(&rect, screen, sel_registerName("frame"));
//Platform_LogConst("GOT FRAME");
//printf("STUFF: %f,%f,%f,%f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
//Platform_LogConst("printed rect");
} }
#define NSTitledWindowMask (1 << 0) #define NSTitledWindowMask (1 << 0)
@ -3721,19 +3692,22 @@ void Window_Init(void) {
#define NSResizableWindowMask (1 << 3) #define NSResizableWindowMask (1 << 3)
void Window_Create(int width, int height) { void Window_Create(int width, int height) {
id window; Window_Width = width;
Window_Width = width;
Window_Height = height; Window_Height = height;
Window_Exists = true; Window_Exists = true;
winHandle = Cocoa_SendIntPtr((id)objc_getClass("NSWindow"), sel_registerName("alloc")); Platform_Log1("create: %x", &appHandle);
winHandle = cmacs_window_init_msgSend(winHandle, sel_getUid("initWithContentRect:styleMask:backing:defer:"), (FailRect) { 0, 0, 1024, 460 }, (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask), 0, false); winHandle = objc_msgSend((id)objc_getClass("NSWindow"), sel_registerName("alloc"));
Platform_Log1("alloc: %x", &winHandle);
winHandle = objc_msgSend(winHandle, sel_registerName("initWithContentRect:styleMask:backing:defer:"), (CGRect) { 0, 0, 1024, 460 }, (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask)$
Platform_Log1("made: %x", &winHandle);
// TODO: move to setVisible // TODO: move to setVisible
Cocoa_SendIntPtr_P(winHandle, sel_registerName("makeKeyAndOrderFront:"), appHandle); objc_msgSend(winHandle, sel_registerName("makeKeyAndOrderFront:"), appHandle);
Platform_LogConst("made window"); Platform_LogConst("made window");
Platform_Log1("WIN: %x", &winHandle);
} }
void Window_SetTitle(const String* title) { } void Window_SetTitle(const String* title) { }
void Clipboard_GetText(String* value) { } void Clipboard_GetText(String* value) { }
void Clipboard_SetText(const String* value) { } void Clipboard_SetText(const String* value) { }