From e160f6e7d28749df17739ac62e0b1534a14fcbbb Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 3 Dec 2020 23:17:00 +0100 Subject: [PATCH] gg: screen_size() --- vlib/gg/gg.v | 9 +++++++++ vlib/gg/gg_darwin.c.v | 4 ++++ vlib/gg/gg_darwin.m | 14 ++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 vlib/gg/gg_darwin.c.v create mode 100644 vlib/gg/gg_darwin.m diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index afb3a61083..66d5cfb0a6 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -581,6 +581,15 @@ pub fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, w f32, h f32, radius sgl.end() } + +pub fn screen_size() Size { + $if macos { + return C.gg_get_screen_size() + } + // TODO windows, linux, etc + return Size{} +} + fn C.WaitMessage() /* diff --git a/vlib/gg/gg_darwin.c.v b/vlib/gg/gg_darwin.c.v new file mode 100644 index 0000000000..808cd5fbed --- /dev/null +++ b/vlib/gg/gg_darwin.c.v @@ -0,0 +1,4 @@ +module gg + +#include "@VROOT/vlib/gg/gg_darwin.m" +fn C.gg_get_screen_size() Size diff --git a/vlib/gg/gg_darwin.m b/vlib/gg/gg_darwin.m new file mode 100644 index 0000000000..83b1a09284 --- /dev/null +++ b/vlib/gg/gg_darwin.m @@ -0,0 +1,14 @@ +#include + +gg__Size gg_get_screen_size() { + NSScreen *screen = [NSScreen mainScreen]; + NSDictionary *description = [screen deviceDescription]; + NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; + CGSize displayPhysicalSize = CGDisplayScreenSize( + [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); + gg__Size res; + res.width = displayPixelSize.width; + res.height = displayPixelSize.height; + return res; +} +