From 8b2cfb34d5bc23d53aaf3676f75a227c8ad51506 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 25 Aug 2015 00:03:59 +0200 Subject: gui.draw_bar() --- gui.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/gui.py b/gui.py index cf68bc5..57b08c5 100644 --- a/gui.py +++ b/gui.py @@ -29,13 +29,38 @@ marker_updated = [True, True, True] screensize=(1280, 800) screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE) + +def draw_bar(rect, val, thresh=None, min=0, max=1, color=(0,0,0), barcolor=None, exceedcolor=(255,0,0), threshcolor=None): + v = (val-min)/(max-min) + t = (thresh-min)/(max-min) + + if barcolor == None: + barcolor_=color + else: + barcolor_=barcolor + if thresh != None and threshcolor==None: + threshcolor_ = ((128+color[0])//2, (128+color[1])//2, (128+color[2])//2) + else: + threshcolor_ = threshcolor + + for i in range(0, 1 if v= t: + draw_box(((rect[0][0]+2 + (rect[1][0]-4)*t , rect[0][1]+2) , ((rect[1][0]-4)*(v-t) , rect[1][1]-4)), exceedcolor, True, False) + + draw_line((rect[0][0]+2+(rect[1][0]-4)*t, rect[0][1]+1), (rect[0][0]+2+(rect[1][0]-4)*t, rect[0][1]+rect[1][1]-1), threshcolor_, False) + + def draw_line(p1, p2, color, global_coords=True): if global_coords: p1 = world_to_win_pt(p1, c.player.center) p2 = world_to_win_pt(p2, c.player.center) - gfxdraw.line(screen, p1[0], p1[1], p2[0], p2[1], color) + gfxdraw.line(screen, int(p1[0]), int(p1[1]), int(p2[0]), int(p2[1]), color) def draw_box(rect, color, filled=False, global_coords=True): if global_coords: -- cgit v1.2.3