-rw-r--r-- qtools/borders/frame.py
1 """ 2 This is the 'frame' border style. 3 """ 4 5 6 import functools 7 import xcffib 8 9 10 def frame(self, inner_w, inner_h, borderwidths, bordercolors): 11 """ 12 The "frame" style accepts one border width and two colours. 13 14 The first colour is the sides and the second is top and bottom. 15 _________ 16 |\_______/| 17 || || 18 || || 19 || || 20 ||_______|| 21 |/_______\| 22 23 """ 24 if len(bordercolors) == 1: 25 self.set_attribute(borderpixel=bordercolors[0]) 26 return 27 28 core = self.conn.conn.core 29 self.borderwidth = sum(borderwidths) 30 outer_w = inner_w + self.borderwidth * 2 31 outer_h = inner_h + self.borderwidth * 2 32 33 pixmap = self.conn.conn.generate_id() 34 core.CreatePixmap( 35 self.conn.default_screen.root_depth, pixmap, self.wid, outer_w, outer_h 36 ) 37 gc = self.conn.conn.generate_id() 38 core.CreateGC(gc, pixmap, xcffib.xproto.GC.Foreground, [bordercolors[0]]) 39 rect = xcffib.xproto.RECTANGLE.synthetic(0, 0, outer_w, outer_h) 40 core.PolyFillRectangle(pixmap, gc, 1, [rect]) 41 42 core.ChangeGC(gc, xcffib.xproto.GC.Foreground, [bordercolors[1]]) 43 core.FillPoly( 44 pixmap, gc, 2, 0, 4, _frame_trapezium_top(self.borderwidth, outer_w) 45 ) 46 core.FillPoly( 47 pixmap, gc, 2, 0, 4, _frame_trapezium_bottom(self.borderwidth, outer_w, outer_h) 48 ) 49 50 self.set_borderpixmap(pixmap, gc, outer_w, outer_h) 51 core.FreePixmap(pixmap) 52 core.FreeGC(gc) 53 return 54 55 56 @functools.lru_cache() 57 def _frame_trapezium_top(borderwidth, width): 58 points = [ 59 xcffib.xproto.POINT.synthetic(0, 0), 60 xcffib.xproto.POINT.synthetic(borderwidth, borderwidth), 61 xcffib.xproto.POINT.synthetic(width - borderwidth, borderwidth), 62 xcffib.xproto.POINT.synthetic(width, 0), 63 ] 64 return points 65 66 67 @functools.lru_cache() 68 def _frame_trapezium_bottom(borderwidth, width, bottom): 69 points = [ 70 xcffib.xproto.POINT.synthetic(0, bottom), 71 xcffib.xproto.POINT.synthetic(borderwidth, bottom - borderwidth), 72 xcffib.xproto.POINT.synthetic(width - borderwidth, bottom - borderwidth), 73 xcffib.xproto.POINT.synthetic(width, bottom), 74 ] 75 return points 76