2020-11-06 14:34:24 +00:00
|
|
|
import curses
|
2020-11-10 19:43:30 +00:00
|
|
|
from typing import Any, Optional, Union
|
2020-11-08 22:40:03 +00:00
|
|
|
|
2020-11-10 19:43:30 +00:00
|
|
|
from dungeonbattle.display.texturepack import TexturePack
|
2020-11-08 22:40:03 +00:00
|
|
|
from dungeonbattle.tests.screen import FakePad
|
2020-11-10 17:08:06 +00:00
|
|
|
|
2020-11-06 14:34:24 +00:00
|
|
|
|
|
|
|
class Display:
|
2020-11-10 19:34:22 +00:00
|
|
|
x: int
|
|
|
|
y: int
|
|
|
|
width: int
|
|
|
|
height: int
|
2020-11-10 20:20:11 +00:00
|
|
|
pad: Any
|
2020-11-10 19:34:22 +00:00
|
|
|
|
2020-11-10 19:43:30 +00:00
|
|
|
def __init__(self, screen: Any, pack: Optional[TexturePack] = None):
|
2020-11-06 14:34:24 +00:00
|
|
|
self.screen = screen
|
2020-11-10 19:43:30 +00:00
|
|
|
self.pack = pack or TexturePack.get_pack("ascii")
|
2020-11-08 22:40:03 +00:00
|
|
|
|
|
|
|
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
2020-11-08 22:48:26 +00:00
|
|
|
return curses.newpad(height, width) if self.screen else FakePad()
|
2020-11-08 23:44:08 +00:00
|
|
|
|
2020-11-10 19:34:22 +00:00
|
|
|
def resize(self, y: int, x: int, height: int, width: int) -> None:
|
2020-11-10 17:08:06 +00:00
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.width = width
|
|
|
|
self.height = height
|
2020-11-10 20:20:11 +00:00
|
|
|
if self.pad:
|
|
|
|
self.pad.resize(height - 1, width - 1)
|
2020-11-10 17:08:06 +00:00
|
|
|
|
2020-11-10 19:34:22 +00:00
|
|
|
def refresh(self, *args) -> None:
|
2020-11-10 17:08:06 +00:00
|
|
|
if len(args) == 4:
|
|
|
|
self.resize(*args)
|
|
|
|
self.display()
|
2020-11-10 19:34:22 +00:00
|
|
|
|
|
|
|
def display(self) -> None:
|
|
|
|
raise NotImplementedError
|
2020-11-08 23:44:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def rows(self) -> int:
|
|
|
|
return curses.LINES if self.screen else 42
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cols(self) -> int:
|
|
|
|
return curses.COLS if self.screen else 42
|