aboutsummaryrefslogtreecommitdiffstats
path: root/src/__main__.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-28 18:07:41 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-28 18:07:41 +0100
commitc55510d08b6c43d156f44a866eb3b318eba385f3 (patch)
treec7125c41299a368954a57f834706ea7743828a35 /src/__main__.py
parentadd draw_coloured_text (diff)
downloadxpybar-c55510d08b6c43d156f44a866eb3b318eba385f3.tar.gz
xpybar-c55510d08b6c43d156f44a866eb3b318eba385f3.tar.bz2
xpybar-c55510d08b6c43d156f44a866eb3b318eba385f3.tar.xz
basic box drawing
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/__main__.py')
-rwxr-xr-xsrc/__main__.py30
1 files changed, 29 insertions, 1 deletions
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):
'''