From f1e099641f5a1eeb6eb25b0799f17cbc6286b664 Mon Sep 17 00:00:00 2001 From: TheFGFSEagle Date: Fri, 20 Jan 2023 21:59:23 +0100 Subject: [PATCH] Center canvas windows on screen upon creation, add methods to center canvas window on screen and to get their current position --- Nasal/canvas/gui.nas | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Nasal/canvas/gui.nas b/Nasal/canvas/gui.nas index f614a3984..039a9dd60 100644 --- a/Nasal/canvas/gui.nas +++ b/Nasal/canvas/gui.nas @@ -109,10 +109,7 @@ var Window = { m.setInt("content-size[1]", size[1]); m.setDouble("aspect-ratio", size[0]/size[1]); m.setBool("lock-aspect-ratio", 0); - - var desktopSize = [props.globals.getValue("/sim/gui/canvas/size[0]"), props.globals.getValue("/sim/gui/canvas/size[1]")]; - var pos = [desktopSize[0] / 2 - size[0] / 2 + 10, desktopSize[1] / 2 - size[1] / 2 + 30]; - m.move(pos[0], pos[1]); + m.centerOnScreen(); if (destroy_on_close) { m.setFocus(); @@ -271,6 +268,14 @@ var Window = { me.setInt("tf/t[1]", y); return me; }, + getPosition: func { + return [me.get("tf/t[0]"), me.get("tf/t[1]")]; + }, + centerOnScreen: func { + var desktopSize = [props.globals.getValue("/sim/gui/canvas/size[0]"), props.globals.getValue("/sim/gui/canvas/size[1]")]; + var pos = [desktopSize[0] / 2 - me.getSize()[0] / 2 - 1, desktopSize[1] / 2 - me.getSize()[1] / 2 - 12]; + me.setPosition(pos); + }, setSize: func { if( size(arg) == 1 )