From aff4a783e04cc01b3146e9413738395dc5b45457 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Tue, 31 Dec 2019 01:56:12 +0200 Subject: [PATCH] Implemented system_get_screen_scale_factor. --- platform_mac/mac_4ed.mm | 16 +++++++++++++--- platform_mac/mac_4ed_functions.mm | 15 +++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/platform_mac/mac_4ed.mm b/platform_mac/mac_4ed.mm index db01684c..22947925 100644 --- a/platform_mac/mac_4ed.mm +++ b/platform_mac/mac_4ed.mm @@ -124,6 +124,7 @@ struct Mac_Vars { NSWindow* window; OpenGLView* view; + f32 screen_scale_factor; mach_timebase_info_data_t timebase_info; @@ -266,10 +267,12 @@ mac_free_object(Mac_Object *object){ [self requestDisplay]; } +/* - (void)mouseMoved:(NSEvent*)event{ printf("Mouse Moved!\n"); [self requestDisplay]; } +*/ - (void)mouseDown:(NSEvent*)event{ printf("Mouse Down!\n"); @@ -329,9 +332,16 @@ main(int arg_count, char **args){ dll_init_sentinel(&mac_vars.free_mac_objects); dll_init_sentinel(&mac_vars.timer_objects); - Arena test_arena = make_arena_malloc(); - Plat_Handle timer = system_wake_up_timer_create(); - system_wake_up_timer_set(timer, 5000); + // NOTE(yuval): Screen scale factor calculation + { + NSScreen* screen = [NSScreen mainScreen]; + NSDictionary* desc = [screen deviceDescription]; + NSSize size = [[desc valueForKey:NSDeviceResolution] sizeValue]; + f32 max_dpi = Max(size.width, size.height); + mac_vars.screen_scale_factor = (max_dpi / 72.0f); + } + + printf("screen scale factor: %f\n", system_get_screen_scale_factor()); // NOTE(yuval): Start the app's run loop #if 1 diff --git a/platform_mac/mac_4ed_functions.mm b/platform_mac/mac_4ed_functions.mm index f1938a76..1da70846 100644 --- a/platform_mac/mac_4ed_functions.mm +++ b/platform_mac/mac_4ed_functions.mm @@ -406,12 +406,18 @@ system_wake_up_timer_set_sig(){ function system_signal_step_sig(){ - NotImplemented; + [mac_vars.view requestDisplay]; } function system_sleep_sig(){ - NotImplemented; + u64 nanoseconds = (microseconds * Thousand(1)); + u64 abs_sleep_time = (u64)((f64)nanoseconds * + (f64)mac_vars.timebase_info.denom / + (f64)mac_vars.timebase_info.numer); + + u64 now = mach_absolute_time(); + mach_wait_until(now + abs_sleep_time); } //////////////////////////////// @@ -464,10 +470,7 @@ system_open_color_picker_sig(){ function system_get_screen_scale_factor_sig(){ - f32 result = 0.0f; - - NotImplemented; - + f32 result = mac_vars.screen_scale_factor; return(result); }