mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Consolidate window configuration
This commit is contained in:
parent
950ac31b9b
commit
9e77b0dcdd
3 changed files with 43 additions and 38 deletions
|
@ -319,17 +319,40 @@ def get_window_config(args: Namespace, global_config: dict) -> dict:
|
|||
except screeninfo.ScreenInfoError:
|
||||
# Default fallback
|
||||
monitors = [screeninfo.Monitor(width=1920, height=1080)]
|
||||
mon_index = global_config["window_monitor"]
|
||||
mon_index = global_config["window"]["monitor"]
|
||||
monitor = monitors[min(mon_index, len(monitors) - 1)]
|
||||
|
||||
width, height = get_resolution(args, global_config)
|
||||
|
||||
aspect_ratio = width / height
|
||||
window_width = monitor.width
|
||||
if not (args.full_screen or global_config["full_screen"]):
|
||||
if not (args.full_screen or global_config["window"]["full_screen"]):
|
||||
window_width //= 2
|
||||
window_height = int(window_width / aspect_ratio)
|
||||
return dict(size=(window_width, window_height))
|
||||
|
||||
# Find position (Perhaps factor this out)
|
||||
pos_str = global_config["window"]["position"]
|
||||
# Position might be specified with a string of the form
|
||||
# x,y for integers x and y
|
||||
if "," in pos_str:
|
||||
default_position = tuple(map(int, pos_str.split(",")))
|
||||
else:
|
||||
# Alternatively, it might be specified with a string like
|
||||
# UR, OO, DL, etc. specifying 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
|
||||
x_step = char_to_n[pos_str[1]] * width_diff // 2
|
||||
y_step = char_to_n[pos_str[0]] * height_diff // 2
|
||||
default_position = (
|
||||
monitor.x + x_step,
|
||||
-monitor.y + y_step,
|
||||
)
|
||||
|
||||
return dict(
|
||||
size=(window_width, window_height),
|
||||
default_position=default_position
|
||||
)
|
||||
|
||||
|
||||
def get_camera_config(args: Optional[Namespace] = None, global_config: Optional[dict] = None) -> dict:
|
||||
|
|
|
@ -25,18 +25,15 @@ directories:
|
|||
# it stores this saved data to whatever directory appdirs.user_cache_dir("manim") returns,
|
||||
# but here a user can specify a different cache location
|
||||
cache: ""
|
||||
universal_import_line: "from manimlib import *"
|
||||
style:
|
||||
tex_template: "default"
|
||||
font: "Consolas"
|
||||
text_alignment: "LEFT"
|
||||
background_color: "#333333"
|
||||
# Set the position of preview window, you can use directions, e.g. UL/DR/OL/OO/...
|
||||
# also, you can also specify the position(pixel) of the upper left corner of
|
||||
# the window on the monitor, e.g. "960,540"
|
||||
window_position: UR
|
||||
window_monitor: 0
|
||||
full_screen: False
|
||||
window:
|
||||
# Set the position of window on screen, you can use directions, e.g. UL/DR/OL/OO/...
|
||||
# also, you can also specify the position(pixel) of the upper left corner of
|
||||
# the window on the monitor, e.g. "960,540"
|
||||
position: UR
|
||||
# If using multiple monitors, which one should show the window?
|
||||
monitor: 0
|
||||
# If not full screen, the default to give it half the screen width
|
||||
full_screen: False
|
||||
file_writer_config:
|
||||
# If break_into_partial_movies is set to True, then many small
|
||||
# files will be written corresponding to each Scene.play and
|
||||
|
@ -49,6 +46,11 @@ file_writer_config:
|
|||
pixel_format: "yuv420p"
|
||||
saturation: 1.0
|
||||
gamma: 1.0
|
||||
style:
|
||||
tex_template: "default"
|
||||
font: "Consolas"
|
||||
text_alignment: "LEFT"
|
||||
background_color: "#333333"
|
||||
camera_resolutions:
|
||||
low: "854x480"
|
||||
med: "1280x720"
|
||||
|
@ -56,6 +58,7 @@ camera_resolutions:
|
|||
4k: "3840x2160"
|
||||
default_resolution: "high"
|
||||
fps: 30
|
||||
universal_import_line: "from manimlib import *"
|
||||
embed_exception_mode: "Verbose"
|
||||
embed_error_sound: False
|
||||
ignore_manimlib_modules_on_reload: True
|
||||
|
|
|
@ -31,13 +31,14 @@ class Window(PygletWindow):
|
|||
self,
|
||||
scene: Optional[Scene] = None,
|
||||
size: tuple[int, int] = (1280, 720),
|
||||
default_position: tuple[int, int] = (0, 0),
|
||||
samples: int = 0
|
||||
):
|
||||
super().__init__(size=size, samples=samples)
|
||||
|
||||
self.scene = scene
|
||||
self.default_size = size
|
||||
self.default_position = self.find_initial_position(size)
|
||||
self.default_position = default_position
|
||||
self.pressed_keys = set()
|
||||
self.size = size
|
||||
|
||||
|
@ -86,28 +87,6 @@ class Window(PygletWindow):
|
|||
self.size = (w - 1, h - 1)
|
||||
self.size = (w, h)
|
||||
|
||||
def find_initial_position(self, size: tuple[int, int]) -> tuple[int, int]:
|
||||
global_config = get_global_config()
|
||||
custom_position = global_config["window_position"]
|
||||
mon_index = global_config["window_monitor"]
|
||||
monitors = get_monitors()
|
||||
monitor = monitors[min(mon_index, len(monitors) - 1)]
|
||||
window_width, window_height = 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. specifying 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 (
|
||||
monitor.x + char_to_n[custom_position[1]] * width_diff // 2,
|
||||
-monitor.y + char_to_n[custom_position[0]] * height_diff // 2,
|
||||
)
|
||||
|
||||
# Delegate event handling to scene
|
||||
def pixel_coords_to_space_coords(
|
||||
self,
|
||||
|
|
Loading…
Add table
Reference in a new issue