diff options
Diffstat (limited to 'asciifarm/client/display/fieldpad.py')
| -rw-r--r-- | asciifarm/client/display/fieldpad.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/asciifarm/client/display/fieldpad.py b/asciifarm/client/display/fieldpad.py new file mode 100644 index 0000000..ac69678 --- /dev/null +++ b/asciifarm/client/display/fieldpad.py @@ -0,0 +1,44 @@ + +import curses + + +class FieldPad: + + + + def __init__(self, size=(1,1), charSize=1, colours=False): + self.pad = curses.newpad(size[1]+1, (size[0]+1)*charSize) + self.size = size + self.charSize = charSize + self.center = (0, 0) + self.colours = colours + + def resize(self, width, height): + self.size = (width, height) + self.pad.resize(height+1, width*self.charSize1) + + def changeCell(self, x, y, char, colour=None): + if colour != None and self.colours: + self.pad.addstr(y, x*self.charSize, char, curses.color_pair(colour)) + else: + self.pad.addstr(y, x*self.charSize, char) + + def setCenter(self, pos): + self.center = pos + + def getWidth(self): + return self.size[0]*self.charSize + + def getHeight(self): + return self.size[1] + + def update(self, screen, x, y, xmax, ymax): + width = xmax-x + height = ymax-y + self.pad.noutrefresh( + max(0, min(self.getHeight()-height, self.center[1] - int(height/2))), + max(0, min(self.getWidth()-width, self.center[0]*self.charSize - int(width/2))), + y, + x, + ymax-1, + xmax-1) |
