summaryrefslogtreecommitdiff
path: root/asciifarm/client/display/fieldpad.py
diff options
context:
space:
mode:
authortroido <troido@hotmail.com>2017-12-30 01:35:41 +0100
committertroido <troido@hotmail.com>2017-12-30 01:35:41 +0100
commitb63f38d654814d6be7a56ee7c8c6c6567755e0b4 (patch)
tree8cc169590bccda80f1d3d246166f002d84cb5fba /asciifarm/client/display/fieldpad.py
parent29149f398986620cf13ba1fc4d2d7cca139bead0 (diff)
tried a new approach to remove code duplication in display
Diffstat (limited to 'asciifarm/client/display/fieldpad.py')
-rw-r--r--asciifarm/client/display/fieldpad.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/asciifarm/client/display/fieldpad.py b/asciifarm/client/display/fieldpad.py
index a7c5c45..bb15a0e 100644
--- a/asciifarm/client/display/fieldpad.py
+++ b/asciifarm/client/display/fieldpad.py
@@ -12,27 +12,30 @@ class FieldPad:
self.center = (0, 0)
self.colours = colours
self.changed = False
- self.win = None
+ self.widget = None
- def setWin(self, win):
- self.win = win
+ def setWidget(self, widget):
+ self.widget = widget
def resize(self, width, height):
self.size = (width, height)
self.pad.resize(height+1, width*self.charSize)
- if self.win:
- self.win.erase()
- self.win.noutrefresh()
+ self.widget.change()
+ win = self.widget.getWin()
+ if win:
+ win.erase()
+ win.noutrefresh()
def changeCell(self, x, y, char, colour=None, bgcolour=0):
if colour != None and self.colours:
self.pad.addstr(y, x*self.charSize, char, self.colours.get(colour, bgcolour))
else:
self.pad.addstr(y, x*self.charSize, char)
- self.changed = True
+ self.widget.change()
def setCenter(self, pos):
self.center = pos
+ self.widget.change()
def getWidth(self):
return self.size[0]*self.charSize
@@ -43,10 +46,8 @@ class FieldPad:
def _roundWidth(self, x):
return x // self.charSize * self.charSize
- def update(self, force):
- if not self.changed and not force or not self.win:
- return
- win = self.win
+ def update(self):
+ win = self.widget.getWin()
height, width = win.getmaxyx()
y, x = win.getparyx()
xmax = x + width
@@ -60,4 +61,3 @@ class FieldPad:
x + max(0, (width - self.getWidth()) // 2),
ymax,
xmax)
- self.changed = False