Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add `window_size` flag. (#1760)

Laith Bahodi044889e742b7
diff --git a/docs/source/tutorials/configuration.rst b/docs/source/tutorials/configuration.rst
index efc5e5e3c..b109788d7 100644
--- a/docs/source/tutorials/configuration.rst
+++ b/docs/source/tutorials/configuration.rst
@@ -353,7 +353,7 @@ A list of all config options
'tex_template', 'tex_template_file', 'text_dir', 'top', 'transparent',
'upto_animation_number', 'use_opengl_renderer', 'use_webgl_renderer',
'verbosity', 'video_dir', 'webgl_renderer_path', 'window_position',
- 'window_monitor', 'write_all', 'write_to_movie']
+ 'window_monitor', 'window_size', 'write_all', 'write_to_movie']
A list of all CLI flags
diff --git a/manim/_config/default.cfg b/manim/_config/default.cfg
index 95be685fe..dfcd97585 100644
--- a/manim/_config/default.cfg
+++ b/manim/_config/default.cfg
@@ -112,6 +112,11 @@ fullscreen = False
# --window_position
window_position = UR
+# Manually adjust the size of the window, or use default to automatically scale the window based on
+# the dimensions of the monitor.
+# --window_size
+window_size = default
+
# --window_monitor
window_monitor = 0
diff --git a/manim/_config/utils.py b/manim/_config/utils.py
index afafa243e..7ee1e5c79 100644
--- a/manim/_config/utils.py
+++ b/manim/_config/utils.py
@@ -291,6 +291,7 @@ class ManimConfig(MutableMapping):
"video_dir",
"fullscreen",
"window_position",
+ "window_size",
"window_monitor",
"write_all",
"write_to_movie",
@@ -578,6 +579,13 @@ class ManimConfig(MutableMapping):
gui_location = tuple(map(int, re.split(";|,|-", parser["CLI"]["gui_location"])))
setattr(self, "gui_location", gui_location)
+ window_size = parser["CLI"][
+ "window_size"
+ ] # if not "default", get a tuple of the position
+ if window_size != "default":
+ window_size = tuple(map(int, re.split(";|,|-", window_size)))
+ setattr(self, "window_size", window_size)
+
# plugins
self.plugins = parser["CLI"].get("plugins", fallback="", raw=True).split(",")
# the next two must be set AFTER digesting pixel_width and pixel_height
@@ -1171,6 +1179,12 @@ class ManimConfig(MutableMapping):
doc="Set the position of preview window. You can use directions, e.g. UL/DR/ORIGIN/LEFT...or the position(pixel) of the upper left corner of the window, e.g. '960,540'",
)
+ window_size = property(
+ lambda self: self._d["window_size"],
+ lambda self, val: self._d.__setitem__("window_size", val),
+ doc="The size of the opengl window. 'default' to automatically scale the window based on the display monitor.",
+ )
+
def resolve_movie_file_extension(self, is_transparent):
if is_transparent:
self.movie_file_extension = ".webm" if self.format == "webm" else ".mov"
diff --git a/manim/renderer/opengl_renderer_window.py b/manim/renderer/opengl_renderer_window.py
index 6ba3d0be5..962ae087d 100644
--- a/manim/renderer/opengl_renderer_window.py
+++ b/manim/renderer/opengl_renderer_window.py
@@ -13,22 +13,26 @@ class Window(PygletWindow):
vsync = True
cursor = True
- def __init__(self, renderer, size=None, **kwargs):
- if size is None:
- # Default to making window half the screen size
- # but make it full screen if --fullscreen is passed in
- monitors = get_monitors()
- mon_index = config.window_monitor
- monitor = monitors[min(mon_index, len(monitors) - 1)]
- window_width = monitor.width
+ def __init__(self, renderer, size=config.window_size, **kwargs):
+ monitors = get_monitors()
+ mon_index = config.window_monitor
+ monitor = monitors[min(mon_index, len(monitors) - 1)]
+
+ if size == "default":
+ # make window_width half the width of the monitor
+ # but make it full screen if --fullscreen
+ window_width = monitor.width
if not config.fullscreen:
window_width //= 2
+ # by default window_height = 9/16 * window_width
window_height = int(
window_width * config.frame_height // config.frame_width
)
size = (window_width, window_height)
+ else:
+ size = tuple(size)
super().__init__(size=size)