def render_border(self): w,h = self.content_size() getstyle = self.getstyle bd = getstyle("bd") border = getstyle("border") margin = getstyle("bd_margin",0) if type(margin) in (int,float): marginx = margin marginy = margin else: marginx,marginy = margin radii = getstyle("bd_radius",0) round = getstyle("bd_round",0) points = border_points( w + 2*marginx, h + 2*marginy, radii, round) glDisable(GL_TEXTURE_2D) glEnable(GL_LINE_SMOOTH) glColor4f(*bd) v = glVertex3f z = -0.01 glLineWidth(border) with gl_begin(GL_LINE_LOOP): for (x,y) in points: v(x,y,z)
def render_background(self): w,h = self.content_size() getstyle = self.getstyle bg = getstyle("bg") has_texture = bool(self.tex) margin = getstyle("bg_margin",0) if type(margin) in (int,float): marginx = margin marginy = margin else: marginx,marginy = margin radii = getstyle("bg_radius",0) round = getstyle("bg_round",0) points = border_points( w + 2*marginx, h + 2*marginy, radii, round) if has_texture: rep = getstyle("texture_repeat","scale") if rep == "scale": rep = 1.0 if type(rep) in (int,float): aspect = w/h rep = (rep*aspect,rep) rx,ry = rep tw = rx / (w + 2*marginx) th = ry / (h + 2*marginy) tpoints = [(x*tw + 0.5, y*th + 0.5) for x,y in points] glBindTexture(GL_TEXTURE_2D,self.tex_id) glEnable(GL_TEXTURE_2D) else: glDisable(GL_TEXTURE_2D) tpoints = [] glColor4f(*bg) v = glVertex3f tc = glTexCoord2f z = -0.02 with gl_begin(GL_TRIANGLE_FAN): tc(0.5,0.5); v(0,0,z) if tpoints: for (x,y),(s,t) in zip(points,tpoints): tc(s,t) v(x,y,z) else: for (x,y) in points: v(x,y,z)
def render_background(self): w, h = self.content_size() getstyle = self.getstyle bg = getstyle("bg") has_texture = bool(self.tex) margin = getstyle("bg_margin", 0) if type(margin) in (int, float): marginx = margin marginy = margin else: marginx, marginy = margin radii = getstyle("bg_radius", 0) round = getstyle("bg_round", 0) points = border_points(w + 2 * marginx, h + 2 * marginy, radii, round) if has_texture: rep = getstyle("texture_repeat", "scale") if rep == "scale": rep = 1.0 if type(rep) in (int, float): aspect = w / h rep = (rep * aspect, rep) rx, ry = rep tw = rx / (w + 2 * marginx) th = ry / (h + 2 * marginy) tpoints = [(x * tw + 0.5, y * th + 0.5) for x, y in points] glBindTexture(GL_TEXTURE_2D, self.tex_id) glEnable(GL_TEXTURE_2D) else: glDisable(GL_TEXTURE_2D) tpoints = [] glColor4f(*bg) v = glVertex3f tc = glTexCoord2f z = -0.02 with gl_begin(GL_TRIANGLE_FAN): tc(0.5, 0.5) v(0, 0, z) if tpoints: for (x, y), (s, t) in zip(points, tpoints): tc(s, t) v(x, y, z) else: for (x, y) in points: v(x, y, z)
def render_border(self): w, h = self.content_size() getstyle = self.getstyle bd = getstyle("bd") border = getstyle("border") margin = getstyle("bd_margin", 0) if type(margin) in (int, float): marginx = margin marginy = margin else: marginx, marginy = margin radii = getstyle("bd_radius", 0) round = getstyle("bd_round", 0) points = border_points(w + 2 * marginx, h + 2 * marginy, radii, round) glDisable(GL_TEXTURE_2D) glEnable(GL_LINE_SMOOTH) glColor4f(*bd) v = glVertex3f z = -0.01 glLineWidth(border) with gl_begin(GL_LINE_LOOP): for (x, y) in points: v(x, y, z)