Move window position logic into window

This commit is contained in:
Grant Sanderson 2021-01-19 11:35:25 -08:00
parent 78ac18496d
commit 9a502cd83b
2 changed files with 26 additions and 26 deletions

View file

@ -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

View file

@ -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)