def paint(self,s): r = pygame.Rect(0,0,s.get_width(),s.get_height()) v = self.value.style.background if is_color(v): s.fill(v) else: self.theme.render(s,v,r)
def paint(self, s): r = pygame.Rect(0, 0, s.get_width(), s.get_height()) v = self.value.style.background if is_color(v): s.fill(v) else: self.theme.render(s, v, r)
def render(self,s,box,r): """Interface method - render a special widget feature. Arguments: s -- a pygame surface box -- box data, a value returned from Theme.get, typically a surface r -- pygame.Rect with the size that the box data should be rendered """ if box == 0: return if is_color(box): s.fill(box,r) return x,y,w,h=r.x,r.y,r.w,r.h ww,hh=box.get_width()/3,box.get_height()/3 xx,yy=x+w,y+h src = pygame.rect.Rect(0,0,ww,hh) dest = pygame.rect.Rect(0,0,ww,hh) s.set_clip(pygame.Rect(x+ww,y+hh,w-ww*2,h-hh*2)) src.x,src.y = ww,hh for dest.y in xrange(y+hh,yy-hh,hh): for dest.x in xrange(x+ww,xx-ww,ww): s.blit(box,dest,src) s.set_clip(pygame.Rect(x+ww,y,w-ww*3,hh)) src.x,src.y,dest.y = ww,0,y for dest.x in xrange(x+ww,xx-ww*2,ww): s.blit(box,dest,src) dest.x = xx-ww*2 s.set_clip(pygame.Rect(x+ww,y,w-ww*2,hh)) s.blit(box,dest,src) s.set_clip(pygame.Rect(x+ww,yy-hh,w-ww*3,hh)) src.x,src.y,dest.y = ww,hh*2,yy-hh for dest.x in xrange(x+ww,xx-ww*2,ww): s.blit(box,dest,src) dest.x = xx-ww*2 s.set_clip(pygame.Rect(x+ww,yy-hh,w-ww*2,hh)) s.blit(box,dest,src) s.set_clip(pygame.Rect(x,y+hh,xx,h-hh*3)) src.y,src.x,dest.x = hh,0,x for dest.y in xrange(y+hh,yy-hh*2,hh): s.blit(box,dest,src) dest.y = yy-hh*2 s.set_clip(pygame.Rect(x,y+hh,xx,h-hh*2)) s.blit(box,dest,src) s.set_clip(pygame.Rect(xx-ww,y+hh,xx,h-hh*3)) src.y,src.x,dest.x=hh,ww*2,xx-ww for dest.y in xrange(y+hh,yy-hh*2,hh): s.blit(box,dest,src) dest.y = yy-hh*2 s.set_clip(pygame.Rect(xx-ww,y+hh,xx,h-hh*2)) s.blit(box,dest,src) s.set_clip() src.x,src.y,dest.x,dest.y = 0,0,x,y s.blit(box,dest,src) src.x,src.y,dest.x,dest.y = ww*2,0,xx-ww,y s.blit(box,dest,src) src.x,src.y,dest.x,dest.y = 0,hh*2,x,yy-hh s.blit(box,dest,src) src.x,src.y,dest.x,dest.y = ww*2,hh*2,xx-ww,yy-hh s.blit(box,dest,src)
def render(self,surf,box,r,size=None,offset=None): """Renders a box using an image. Arguments: surf -- the target pygame surface box -- pygame surface or color r -- pygame rect describing the size of the image to render If 'box' is a surface, it is interpreted as a 3x3 grid of tiles. The corner tiles are rendered in the corners of the box. The side tiles are used to fill the top, bottom and sides of the box. The centre tile is used to fill the interior of the box. """ if box == 0: return if is_color(box): surf.fill(box,r) return x,y,w,h=r.x,r.y,r.w,r.h if (size and offset): pass # destx = x # desty = y # Calculate the size of each tile tilew, tileh = int(box.get_width()/3), int(box.get_height()/3) xx, yy = x+w, y+h src = pygame.rect.Rect(0, 0, tilew, tileh) dest = pygame.rect.Rect(0, 0, tilew, tileh) # Render the interior of the box surf.set_clip(pygame.Rect(x+tilew, y+tileh, w-tilew*2, h-tileh*2)) src.x,src.y = tilew,tileh for dest.y in range(y+tileh,yy-tileh,tileh): for dest.x in range(x+tilew,xx-tilew,tilew): surf.blit(box,dest,src) # Render the top side of the box surf.set_clip(pygame.Rect(x+tilew,y,w-tilew*2,tileh)) src.x,src.y,dest.y = tilew,0,y for dest.x in range(x+tilew, xx-tilew*2+tilew, tilew): surf.blit(box,dest,src) # Render the bottom side surf.set_clip(pygame.Rect(x+tilew,yy-tileh,w-tilew*2,tileh)) src.x,src.y,dest.y = tilew,tileh*2,yy-tileh for dest.x in range(x+tilew,xx-tilew*2+tilew,tilew): surf.blit(box,dest,src) # Render the left side surf.set_clip(pygame.Rect(x,y+tileh,xx,h-tileh*2)) src.y,src.x,dest.x = tileh,0,x for dest.y in range(y+tileh,yy-tileh*2+tileh,tileh): surf.blit(box,dest,src) # Render the right side surf.set_clip(pygame.Rect(xx-tilew,y+tileh,xx,h-tileh*2)) src.y,src.x,dest.x=tileh,tilew*2,xx-tilew for dest.y in range(y+tileh,yy-tileh*2+tileh,tileh): surf.blit(box,dest,src) # Render the upper-left corner surf.set_clip() src.x,src.y,dest.x,dest.y = 0,0,x,y surf.blit(box,dest,src) # Render the upper-right corner src.x,src.y,dest.x,dest.y = tilew*2,0,xx-tilew,y surf.blit(box,dest,src) # Render the lower-left corner src.x,src.y,dest.x,dest.y = 0,tileh*2,x,yy-tileh surf.blit(box,dest,src) # Render the lower-right corner src.x,src.y,dest.x,dest.y = tilew*2,tileh*2,xx-tilew,yy-tileh surf.blit(box,dest,src)
def render(self, s, box, r): """Interface method - render a special widget feature. Arguments: s -- a pygame surface box -- box data, a value returned from Theme.get, typically a surface r -- pygame.Rect with the size that the box data should be rendered """ if box == 0: return if is_color(box): s.fill(box, r) return x, y, w, h = r.x, r.y, r.w, r.h ww, hh = box.get_width() / 3, box.get_height() / 3 xx, yy = x + w, y + h src = pygame.rect.Rect(0, 0, ww, hh) dest = pygame.rect.Rect(0, 0, ww, hh) s.set_clip(pygame.Rect(x + ww, y + hh, w - ww * 2, h - hh * 2)) src.x, src.y = ww, hh for dest.y in xrange(y + hh, yy - hh, hh): for dest.x in xrange(x + ww, xx - ww, ww): s.blit(box, dest, src) s.set_clip(pygame.Rect(x + ww, y, w - ww * 3, hh)) src.x, src.y, dest.y = ww, 0, y for dest.x in xrange(x + ww, xx - ww * 2, ww): s.blit(box, dest, src) dest.x = xx - ww * 2 s.set_clip(pygame.Rect(x + ww, y, w - ww * 2, hh)) s.blit(box, dest, src) s.set_clip(pygame.Rect(x + ww, yy - hh, w - ww * 3, hh)) src.x, src.y, dest.y = ww, hh * 2, yy - hh for dest.x in xrange(x + ww, xx - ww * 2, ww): s.blit(box, dest, src) dest.x = xx - ww * 2 s.set_clip(pygame.Rect(x + ww, yy - hh, w - ww * 2, hh)) s.blit(box, dest, src) s.set_clip(pygame.Rect(x, y + hh, xx, h - hh * 3)) src.y, src.x, dest.x = hh, 0, x for dest.y in xrange(y + hh, yy - hh * 2, hh): s.blit(box, dest, src) dest.y = yy - hh * 2 s.set_clip(pygame.Rect(x, y + hh, xx, h - hh * 2)) s.blit(box, dest, src) s.set_clip(pygame.Rect(xx - ww, y + hh, xx, h - hh * 3)) src.y, src.x, dest.x = hh, ww * 2, xx - ww for dest.y in xrange(y + hh, yy - hh * 2, hh): s.blit(box, dest, src) dest.y = yy - hh * 2 s.set_clip(pygame.Rect(xx - ww, y + hh, xx, h - hh * 2)) s.blit(box, dest, src) s.set_clip() src.x, src.y, dest.x, dest.y = 0, 0, x, y s.blit(box, dest, src) src.x, src.y, dest.x, dest.y = ww * 2, 0, xx - ww, y s.blit(box, dest, src) src.x, src.y, dest.x, dest.y = 0, hh * 2, x, yy - hh s.blit(box, dest, src) src.x, src.y, dest.x, dest.y = ww * 2, hh * 2, xx - ww, yy - hh s.blit(box, dest, src)