mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-08-06 14:19:52 +08:00
fix(windows): enhance resolution in fullscreen mode
This commit is contained in:
@ -1,9 +1,13 @@
|
|||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from enum import Enum
|
from enum import IntEnum, auto, unique
|
||||||
|
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
import ctypes
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import cv2
|
import cv2
|
||||||
@ -14,29 +18,22 @@ from .config import Config
|
|||||||
from .defaults import CONFIG_PATH, FOLDER_PATH
|
from .defaults import CONFIG_PATH, FOLDER_PATH
|
||||||
|
|
||||||
|
|
||||||
class State(Enum):
|
@unique
|
||||||
PLAYING = 0
|
class State(IntEnum):
|
||||||
PAUSED = 1
|
PLAYING = auto()
|
||||||
WAIT = 2
|
PAUSED = auto()
|
||||||
END = 3
|
WAIT = auto()
|
||||||
|
END = auto()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.value == 0:
|
return self.name.capitalize()
|
||||||
return "Playing"
|
|
||||||
if self.value == 1:
|
|
||||||
return "Paused"
|
|
||||||
if self.value == 2:
|
|
||||||
return "Wait"
|
|
||||||
if self.value == 3:
|
|
||||||
return "End"
|
|
||||||
return "..."
|
|
||||||
|
|
||||||
|
|
||||||
def now():
|
def now() -> int:
|
||||||
return round(time.time() * 1000)
|
return round(time.time() * 1000)
|
||||||
|
|
||||||
|
|
||||||
def fix_time(x):
|
def fix_time(x: float) -> float:
|
||||||
return x if x > 0 else 1
|
return x if x > 0 else 1
|
||||||
|
|
||||||
|
|
||||||
@ -171,12 +168,26 @@ class Display:
|
|||||||
self.lag = 0
|
self.lag = 0
|
||||||
self.last_time = now()
|
self.last_time = now()
|
||||||
|
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
user32 = ctypes.windll.user32
|
||||||
|
self.screen_width, self.screen_height = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
|
||||||
|
|
||||||
if fullscreen:
|
if fullscreen:
|
||||||
cv2.namedWindow("Video", cv2.WND_PROP_FULLSCREEN)
|
cv2.namedWindow("Video", cv2.WND_PROP_FULLSCREEN)
|
||||||
cv2.setWindowProperty(
|
cv2.setWindowProperty(
|
||||||
"Video", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN
|
"Video", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def resize_frame_to_screen(self, frame: np.ndarray):
|
||||||
|
frame_height, frame_width = frame.shape
|
||||||
|
|
||||||
|
scale_height = self.screen_height / frame_height
|
||||||
|
scale_width = self.screen_width / frame_width
|
||||||
|
|
||||||
|
scale = min(scale_height, scale_width)
|
||||||
|
|
||||||
|
return cv2.resize(frame, (int(scale * frame_height, scale * frame_width)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_presentation(self):
|
def current_presentation(self):
|
||||||
return self.presentations[self.current_presentation_i]
|
return self.presentations[self.current_presentation_i]
|
||||||
@ -203,7 +214,13 @@ class Display:
|
|||||||
def show_video(self):
|
def show_video(self):
|
||||||
self.lag = now() - self.last_time
|
self.lag = now() - self.last_time
|
||||||
self.last_time = now()
|
self.last_time = now()
|
||||||
cv2.imshow("Video", self.lastframe)
|
|
||||||
|
frame = self.lastframe
|
||||||
|
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
frame = self.resize_frame_to_screen(frame)
|
||||||
|
|
||||||
|
cv2.imshow("Video", frame)
|
||||||
|
|
||||||
def show_info(self):
|
def show_info(self):
|
||||||
info = np.zeros((130, 420), np.uint8)
|
info = np.zeros((130, 420), np.uint8)
|
||||||
|
Reference in New Issue
Block a user