Add a MultiLineStringRenderer (can handle \n)

master
LEdoian 8 months ago
parent b0ebc86a9a
commit eea3379477

@ -12,3 +12,26 @@ class DrawItemNameRenderer(Renderer):
result.blit(rendered, pos) result.blit(rendered, pos)
return result return result
class MultiLineStringRenderer(Renderer):
def __init__(self, linespacing=1.5, fontsize=25):
self.linespacing = linespacing
self.font_size = fontsize
def render(self, string, w, h):
print(string)
result = pg.Surface((w, h))
font = pgft.Font(None, size=self.font_size)
# This is a complete typographical blasphemy. We are going to space
# text by its centers, not baselines.
lines = string.split('\n')
n = len(lines)
for i, line in enumerate(lines):
rendered, _brect = font.render(line, fgcolor=(255,255,255)) #white.
cpos = align(result, rendered)
x, cy = cpos
y = cy - (n-2*i-1)*self.linespacing*self.font_size//2
pos = x, y
print(pos)
result.blit(rendered, pos)
return result

Loading…
Cancel
Save