Implemented system_get_screen_scale_factor.

master
Yuval Dolev 2019-12-31 01:56:12 +02:00
parent 912174e725
commit aff4a783e0
2 changed files with 22 additions and 9 deletions

View File

@ -124,6 +124,7 @@ struct Mac_Vars {
NSWindow* window; NSWindow* window;
OpenGLView* view; OpenGLView* view;
f32 screen_scale_factor;
mach_timebase_info_data_t timebase_info; mach_timebase_info_data_t timebase_info;
@ -266,10 +267,12 @@ mac_free_object(Mac_Object *object){
[self requestDisplay]; [self requestDisplay];
} }
/*
- (void)mouseMoved:(NSEvent*)event{ - (void)mouseMoved:(NSEvent*)event{
printf("Mouse Moved!\n"); printf("Mouse Moved!\n");
[self requestDisplay]; [self requestDisplay];
} }
*/
- (void)mouseDown:(NSEvent*)event{ - (void)mouseDown:(NSEvent*)event{
printf("Mouse Down!\n"); 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.free_mac_objects);
dll_init_sentinel(&mac_vars.timer_objects); dll_init_sentinel(&mac_vars.timer_objects);
Arena test_arena = make_arena_malloc(); // NOTE(yuval): Screen scale factor calculation
Plat_Handle timer = system_wake_up_timer_create(); {
system_wake_up_timer_set(timer, 5000); 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 // NOTE(yuval): Start the app's run loop
#if 1 #if 1

View File

@ -406,12 +406,18 @@ system_wake_up_timer_set_sig(){
function function
system_signal_step_sig(){ system_signal_step_sig(){
NotImplemented; [mac_vars.view requestDisplay];
} }
function function
system_sleep_sig(){ 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 function
system_get_screen_scale_factor_sig(){ system_get_screen_scale_factor_sig(){
f32 result = 0.0f; f32 result = mac_vars.screen_scale_factor;
NotImplemented;
return(result); return(result);
} }