diff --git a/Menu/GameShell/10_Settings/Wifi/textarea.py b/Menu/GameShell/10_Settings/Wifi/textarea.py index 0957264..dfbc875 100644 --- a/Menu/GameShell/10_Settings/Wifi/textarea.py +++ b/Menu/GameShell/10_Settings/Wifi/textarea.py @@ -19,10 +19,13 @@ class Textarea: _BackgroundColor = pygame.Color(229,229,229) _CanvasHWND = None _MyWords = [] + _BlitWords = [] _FontObj = None _LineNumber = 0 + _TextLimit = 63 _TextFull = False _TextIndex = 0 + _BlitIndex = 0 def __init__(self): pass @@ -68,32 +71,71 @@ class Textarea: else: print("is Full %s" % "".join(self._MyWords)) + def BuildBlitText(self): + blit_rows = [[]] + w = 0 + xmargin = 5 + endmargin = 15 + x = self._PosX+xmargin + linenumber = 0 + cursor_row = 0 + + for i, v in enumerate(self._MyWords): + t = self._FontObj.render(v, True, (8, 135, 174)) + t_width = t.get_width() + w += t_width + del(t) + + blit_rows[linenumber].append(v) + + if i == self._TextIndex - 1: + cursor_row = linenumber + + if w + t_width >= self._Width-endmargin: + x = self._PosX+xmargin + w = 0 + linenumber += 1 + blit_rows.append([]) + + # only paint 2 rows + if len(blit_rows) == 1: + self._BlitWords = blit_rows[0] + self._BlitIndex = self._TextIndex + elif len(blit_rows) == 2 or cursor_row < 2: + self._BlitWords = blit_rows[0] + blit_rows[1] + self._BlitIndex = self._TextIndex + else: + self._BlitWords = blit_rows[cursor_row - 1] + blit_rows[cursor_row] + self._BlitIndex = self._TextIndex + for i,v in enumerate(blit_rows): + if i == cursor_row - 1: + break + self._BlitIndex -= len(v) def BlitText(self): """ blit every single word into surface and calc the width ,check multi line """ + # build up blitwords + self.BuildBlitText() + w = 0 xmargin = 5 endmargin = 15 x = self._PosX+xmargin y = self._PosY linenumber = 0 - self._TextFull = False - for i,v in enumerate(self._MyWords): + self._TextFull = len(self._MyWords) > self._TextLimit + for i, v in enumerate(self._BlitWords): t = self._FontObj.render(v,True,(8,135,174)) w += t.get_width() if w >= self._Width-endmargin and linenumber == 0: - x = self._PosX+xmargin - y = self._PosY+ t.get_height() - w = 0 linenumber +=1 + x = self._PosX+xmargin + y = self._PosY + t.get_height() * linenumber + w = 0 - if w >= self._Width-endmargin*4 and linenumber > 0: - self._TextFull = True - self._CanvasHWND.blit(t, (x,y)) - break self._CanvasHWND.blit(t, (x,y)) x += t.get_width() @@ -104,7 +146,7 @@ class Textarea: x = self._PosX+xmargin y = self._PosY linenumber = 0 - for i,v in enumerate(self._MyWords[:self._TextIndex]): + for i,v in enumerate(self._BlitWords[:self._BlitIndex]): t = self._FontObj.render(v,True,(8,135,174)) w += t.get_width()