X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/346a9b8e1fcfe30629f0d1ee4675e9e8f89890cf..4c4732c6ed8cb0aaa70fb2d4c6e5a958868c5349:/src/pgu/text.py diff --git a/src/pgu/text.py b/src/pgu/text.py deleted file mode 100644 index 1010a87..0000000 --- a/src/pgu/text.py +++ /dev/null @@ -1,61 +0,0 @@ -"""a collection of text rendering functions -""" -def write(s,font,pos,color,text,border=1): - """write text to a surface with a black border - -
write(s,font,pos,color,text,border=1)
- """ - i = font.render(text,1,(0,0,0)) - si = border - dirs = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)] - for dx,dy in dirs: s.blit(i,(pos[0]+dx*si,pos[1]+dy*si)) - i = font.render(text,1,color) - s.blit(i,pos) - -def writec(s,font,color,text,border=1): - """write centered text to a surface with a black border - -
writec(s,font,color,text,border=1)
- """ - w,h = font.size(text) - x = (s.get_width()-w)/2 - y = (s.get_height()-h)/2 - write(s,font,(x,y),color,text,border) - -def writepre(s,font,rect,color,text): - """write preformatted text - -
writepre(s,font,rect,color,text)
- """ - r,c,txt = rect,color,text - txt = txt.replace("\t"," ") - i = font.render(" ",1,c) - sw,sh = i.get_width(),i.get_height() - y = r.top - for sentence in txt.split("\n"): - x = r.left - i = font.render(sentence,1,c) - s.blit(i,(x,y)) - y += sh - -def writewrap(s,font,rect,color,text): - """write wrapped text - -
writewrap(s,font,rect,color,text)
- """ - r,c,txt = rect,color,text - txt = txt.replace("\t"," ") - i = font.render(" ",1,c) - sw,sh = i.get_width(),i.get_height() - y = r.top - for sentence in txt.split("\n"): - x = r.left - for word in sentence.split(" "): - i = font.render(word,1,c) - iw,ih = i.get_width(),i.get_height() - if x+iw > r.right: x,y = r.left,y+sh - s.blit(i,(x,y)) - x += iw+sw - y += sh - -# vim: set filetype=python sts=4 sw=4 noet si :