Screen is resizable (but please be nice with it)
This commit is contained in:
parent
d50c775e0f
commit
e9ac448854
|
@ -10,6 +10,7 @@ class Display:
|
|||
y: int
|
||||
width: int
|
||||
height: int
|
||||
pad: Any
|
||||
|
||||
def __init__(self, screen: Any, pack: Optional[TexturePack] = None):
|
||||
self.screen = screen
|
||||
|
@ -23,6 +24,8 @@ class Display:
|
|||
self.y = y
|
||||
self.width = width
|
||||
self.height = height
|
||||
if self.pad:
|
||||
self.pad.resize(height - 1, width - 1)
|
||||
|
||||
def refresh(self, *args) -> None:
|
||||
if len(args) == 4:
|
||||
|
|
|
@ -34,14 +34,13 @@ class DisplayManager:
|
|||
self.rows // 5, self.cols)
|
||||
if self.game.state == GameMode.MAINMENU:
|
||||
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
|
||||
self.resize_window()
|
||||
|
||||
def ensure_resized(self, *pads) -> bool:
|
||||
def resize_window(self) -> bool:
|
||||
"""
|
||||
If the window got resized, ensure that the pads are also resized.
|
||||
If the window got resized, ensure that the screen size got updated.
|
||||
"""
|
||||
y, x = self.screen.getmaxyx() if self.screen else (0, 0)
|
||||
for pad in pads:
|
||||
pad.resize(y, x)
|
||||
if self.screen and curses.is_term_resized(self.rows, self.cols):
|
||||
curses.resizeterm(y, x)
|
||||
return True
|
||||
|
|
|
@ -44,8 +44,8 @@ class MenuDisplay(Display):
|
|||
self.width + self.x)
|
||||
self.update_pad()
|
||||
self.pad.refresh(cornery, 0, self.y + 1, self.x + 2,
|
||||
self.height - 1 + self.y,
|
||||
self.width - 1 + self.x)
|
||||
self.height - 2 + self.y,
|
||||
self.width - 2 + self.x)
|
||||
|
||||
@property
|
||||
def preferred_width(self) -> int:
|
||||
|
|
|
@ -69,7 +69,6 @@ class Game:
|
|||
self.display_refresh()
|
||||
key = screen.getkey()
|
||||
self.handle_key_pressed(self.translate_key(key))
|
||||
self.display_refresh()
|
||||
|
||||
def translate_key(self, key: str) -> KeyValues:
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue