From 9a502cd83b219bd90cc75f7ac62264fc7b872d94 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 19 Jan 2021 11:35:25 -0800 Subject: [PATCH] Move window position logic into window --- manimlib/config.py | 27 ++++----------------------- manimlib/window.py | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/manimlib/config.py b/manimlib/config.py index 05419859..bb1c3275 100644 --- a/manimlib/config.py +++ b/manimlib/config.py @@ -208,31 +208,12 @@ def get_configuration(args): # Default to putting window in the upper right of screen, # but make it full screen if -f is passed in monitor = get_monitors()[0] - if args.full_screen: - window_width = monitor.width - else: - window_width = monitor.width / 2 - window_height = window_width * 9 / 16 - custom_position = custom_defaults["window_position"] - if "," in custom_position: - posx, posy = map(int, custom_position.split(",")) - else: - if custom_position[1] == "L": - posx = 0 - elif custom_position[1] == "O": - posx = int((monitor.width - window_width) / 2) - elif custom_position[1] == "R": - posx = int(monitor.width - window_width) - if custom_position[0] == "U": - posy = 0 - elif custom_position[0] == "O": - posy = int((monitor.height - window_height) / 2) - elif custom_position[0] == "D": - posy = int(monitor.height - window_height) - window_position = (posx, posy) + window_width = monitor.width + if not args.full_screen: + window_width //= 2 + window_height = window_width * 9 // 16 config["window_config"] = { "size": (window_width, window_height), - "position": window_position, } # Arguments related to skipping diff --git a/manimlib/window.py b/manimlib/window.py index 7d7503d9..5612478b 100644 --- a/manimlib/window.py +++ b/manimlib/window.py @@ -1,8 +1,10 @@ import moderngl_window as mglw from moderngl_window.context.pyglet.window import Window as PygletWindow from moderngl_window.timers.clock import Timer +from screeninfo import get_monitors from manimlib.utils.config_ops import digest_config +from manimlib.utils.customization import get_customization class Window(PygletWindow): @@ -18,16 +20,33 @@ class Window(PygletWindow): digest_config(self, kwargs) self.scene = scene self.title = str(scene) - if "position" in kwargs: - self.position = kwargs["position"] - self.pressed_keys = set() + self.position = self.get_position() mglw.activate_context(window=self) self.timer = Timer() self.config = mglw.WindowConfig(ctx=self.ctx, wnd=self, timer=self.timer) self.timer.start() + def get_position(self): + custom_position = get_customization()["window_position"] + monitor = get_monitors()[0] + window_width, window_height = self.size + # Position might be specified with a string of the form + # x,y for integers x and y + if "," in custom_position: + return tuple(map(int, custom_position.split(","))) + + # Alternatively, it might be specified with a string like + # UR, OO, DL, etc. specifiying what corner it should go to + char_to_n = {"L": 0, "U": 0, "O": 1, "R": 2, "D": 2} + width_diff = monitor.width - window_width + height_diff = monitor.height - window_height + return ( + char_to_n[custom_position[1]] * width_diff // 2, + char_to_n[custom_position[0]] * height_diff // 2, + ) + # Delegate event handling to scene def pixel_coords_to_space_coords(self, px, py, relative=False): return self.scene.camera.pixel_coords_to_space_coords(px, py, relative)