Skip to content

Commit

Permalink
fix(cli): resize only on fullscreen (#12)
Browse files Browse the repository at this point in the history
* fix(cli): resize only on fullscreen

Closes #10

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jeertmans and pre-commit-ci[bot] authored Sep 14, 2022
1 parent 5f73059 commit 2ba0d48
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions manim_slides/present.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from .defaults import CONFIG_PATH, FOLDER_PATH
from .slide import reverse_video_path

WINDOW_NAME = "Manim Slides"


@unique
class State(IntEnum):
Expand Down Expand Up @@ -186,6 +188,8 @@ def __init__(
self.start_paused = start_paused
self.config = config
self.skip_all = skip_all
self.fullscreen = fullscreen
self.is_windows = platform.system() == "Windows"

self.state = State.PLAYING
self.lastframe = None
Expand All @@ -194,16 +198,16 @@ def __init__(
self.lag = 0
self.last_time = now()

if platform.system() == "Windows":
if self.is_windows:
user32 = ctypes.windll.user32
self.screen_width, self.screen_height = user32.GetSystemMetrics(
0
), user32.GetSystemMetrics(1)

if fullscreen:
cv2.namedWindow("Video", cv2.WND_PROP_FULLSCREEN)
if self.fullscreen:
cv2.namedWindow(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(
"Video", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN
WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN
)

def resize_frame_to_screen(self, frame: np.ndarray):
Expand Down Expand Up @@ -245,10 +249,10 @@ def show_video(self):

frame = self.lastframe

if platform.system() == "Windows":
if self.is_windows and self.fullscreen:
frame = self.resize_frame_to_screen(frame)

cv2.imshow("Video", frame)
cv2.imshow(WINDOW_NAME, frame)

def show_info(self):
info = np.zeros((130, 420), np.uint8)
Expand Down Expand Up @@ -284,7 +288,7 @@ def show_info(self):
*font_args,
)

cv2.imshow("Info", info)
cv2.imshow(f"{WINDOW_NAME}: Info", info)

def handle_key(self):
sleep_time = math.ceil(1000 / self.current_presentation.fps)
Expand Down

0 comments on commit 2ba0d48

Please sign in to comment.