2019-12-24 14:57:05 +00:00
|
|
|
/* Mac Objective C layer for 4coder */
|
|
|
|
|
|
|
|
#include "4coder_base_types.h"
|
2019-12-25 01:17:12 +00:00
|
|
|
|
2019-12-26 15:54:06 +00:00
|
|
|
#if 0
|
2019-12-26 01:39:40 +00:00
|
|
|
#include "4coder_table.h"
|
|
|
|
#include "4coder_events.h"
|
|
|
|
#include "4coder_types.h"
|
2019-12-26 15:54:06 +00:00
|
|
|
#endif
|
2019-12-26 01:39:40 +00:00
|
|
|
|
2019-12-24 20:31:24 +00:00
|
|
|
#include "mac_objective_c_to_cpp_links.h"
|
2019-12-24 14:57:05 +00:00
|
|
|
|
2019-12-24 20:31:24 +00:00
|
|
|
#undef function
|
|
|
|
#undef internal
|
|
|
|
#undef global
|
|
|
|
#undef external
|
|
|
|
#include <Cocoa/Cocoa.h>
|
2019-12-24 14:57:05 +00:00
|
|
|
|
2019-12-25 01:17:12 +00:00
|
|
|
#include <libproc.h> // NOTE(yuval): Used for proc_pidpath
|
|
|
|
|
2019-12-25 21:31:21 +00:00
|
|
|
#include <sys/types.h> // NOTE(yuval): Used for pid_t
|
2019-12-25 01:17:12 +00:00
|
|
|
#include <unistd.h> // NOTE(yuval): Used for getpid
|
|
|
|
|
|
|
|
#define external extern "C"
|
|
|
|
|
2019-12-24 00:53:25 +00:00
|
|
|
@interface App_Delegate : NSObject<NSApplicationDelegate, NSWindowDelegate>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation App_Delegate
|
|
|
|
- (void)applicationDidFinishLaunching:(id)sender{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)notification{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)windowWillResize:(NSWindow*)window toSize:(NSSize)frame_size{
|
|
|
|
// frame_size.height = ((f32)frame_size.width / global_aspect_ratio);
|
|
|
|
return frame_size;
|
|
|
|
}
|
|
|
|
|
2019-12-24 14:57:05 +00:00
|
|
|
- (void)windowWillClose:(id)sender{
|
2019-12-24 00:53:25 +00:00
|
|
|
// global_running = false;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2019-12-26 15:54:06 +00:00
|
|
|
#if 0
|
2019-12-26 01:16:34 +00:00
|
|
|
external File_List
|
|
|
|
mac_get_file_list(Arena* arena, String_Const_u8 directory){
|
|
|
|
File_List result = {};
|
|
|
|
|
|
|
|
NSString *directory_ns_string =
|
|
|
|
[[NSString alloc]
|
|
|
|
initWithBytes:directory.data length:directory.size encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
NSFileManager *file_manager = [NSFileManager defaultManager];
|
|
|
|
NSDirectoryEnumerator *dirEnum = [file_manager enumeratorAtPath:directory_ns_string];
|
|
|
|
|
|
|
|
NSString *filename;
|
|
|
|
while ((filename = [dirEnum nextObject])){
|
2019-12-26 15:54:06 +00:00
|
|
|
NSLog(@"%@", filename);
|
2019-12-26 01:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[directory_ns_string release];
|
|
|
|
}
|
2019-12-26 15:54:06 +00:00
|
|
|
#endif
|
2019-12-26 01:16:34 +00:00
|
|
|
|
2019-12-25 21:31:21 +00:00
|
|
|
external String_Const_u8
|
|
|
|
mac_standardize_path(Arena* arena, String_Const_u8 path){
|
|
|
|
NSString *path_ns_str =
|
|
|
|
[[NSString alloc] initWithBytes:path.data length:path.size encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
NSString *standardized_path_ns_str = [path_ns_str stringByStandardizingPath];
|
2019-12-25 22:19:50 +00:00
|
|
|
String_Const_u8 standardized_path = mac_SCu8((u8*)[standardized_path_ns_str UTF8String],[standardized_path_ns_str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
|
2019-12-25 21:31:21 +00:00
|
|
|
|
2019-12-25 22:19:50 +00:00
|
|
|
String_Const_u8 result = mac_push_string_copy(arena, standardized_path);
|
2019-12-25 21:31:21 +00:00
|
|
|
|
2019-12-25 22:19:50 +00:00
|
|
|
[path_ns_str release];
|
2019-12-25 21:31:21 +00:00
|
|
|
|
2019-12-25 22:19:50 +00:00
|
|
|
return(result);
|
2019-12-25 21:31:21 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 01:17:12 +00:00
|
|
|
external i32
|
|
|
|
mac_get_binary_path(void *buffer, u32 size){
|
|
|
|
pid_t pid = getpid();
|
|
|
|
i32 bytes_read = proc_pidpath(pid, buffer, size);
|
|
|
|
|
2019-12-25 22:19:50 +00:00
|
|
|
return(bytes_read);
|
2019-12-25 01:17:12 +00:00
|
|
|
}
|
|
|
|
|
2019-12-23 00:39:44 +00:00
|
|
|
int
|
|
|
|
main(int arg_count, char **args){
|
2019-12-23 23:22:56 +00:00
|
|
|
@autoreleasepool{
|
2019-12-24 14:57:05 +00:00
|
|
|
// NOTE(yuval): Create NSApplication & Delegate
|
2019-12-23 23:22:56 +00:00
|
|
|
NSApplication* app = [NSApplication sharedApplication];
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
|
|
|
|
App_Delegate* app_delegate = [[App_Delegate alloc] init];
|
|
|
|
[app setDelegate:app_delegate];
|
|
|
|
|
|
|
|
[NSApp finishLaunching];
|
|
|
|
|
2019-12-24 20:31:24 +00:00
|
|
|
mac_init();
|
2019-12-24 14:57:05 +00:00
|
|
|
|
2019-12-24 20:31:24 +00:00
|
|
|
#if 0
|
2019-12-23 23:22:56 +00:00
|
|
|
// NOTE(yuval): Application Core Update
|
|
|
|
Application_Step_Result result = {};
|
|
|
|
if (app.step != 0){
|
|
|
|
result = app.step(mac_vars.tctx, &target, base_ptr, &input);
|
|
|
|
}
|
2019-12-24 20:31:24 +00:00
|
|
|
#endif
|
2019-12-23 00:39:44 +00:00
|
|
|
}
|
|
|
|
}
|