From c55510d08b6c43d156f44a866eb3b318eba385f3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 28 Feb 2014 18:07:41 +0100 Subject: basic box drawing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/__main__.py b/src/__main__.py index e5d5e33..ab65f47 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -152,7 +152,35 @@ class Bar: @param y:int The Y position of the bottom of the text @param text:str The text to draw ''' - draw_text(bar.window, bar.gc, x, y, text) + special = '─│┌┐└┘├┤┬┴┼╱╲╳\0' + buf = '' + w = self.text_width('X') + h = self.font_height + y_ = y - self.font_height + for c in text + '\0': + if c in special: + if not buf == '': + self.window.draw_text(self.gc, x, y, buf) + x += self.text_width(buf) + buf = '' + if not c == '\0': + segs = [] + if c in '─┼┬┴': segs.append((0, 1, 2, 1)) + if c in '│┼├┤': segs.append((1, 0, 1, 2)) + if c in '├┌└': segs.append((1, 1, 2, 1)) + if c in '┤┐┘': segs.append((0, 1, 1, 1)) + if c in '┬┌┐': segs.append((1, 1, 1, 2)) + if c in '┴└┘': segs.append((1, 0, 1, 1)) + if c in '╱╳': segs.append((0, 2, 2, 0)) + if c in '╲╳': segs.append((0, 0, 2, 2)) + segs_ = [] + for seg in segs: + (x1, y1, x2, y2) = [c / 2 for c in seg] + segs_.append((int(x1 * w) + x, int(y1 * h) + y_, int(x2 * w) + x, int(y2 * h) + y_)) + self.window.poly_segment(self.gc, segs_) + x += w + else: + buf += c def draw_coloured_text(self, x, y, ascent, descent, text): ''' -- cgit v1.2.3-70-g09d2