def getRects(self, view_clip=None, exclude=None): '''Determine the drawing parameters for this element and its children. Returns a list of (element, (x, y, z, clipped)) where: (x, y, z) is the screen location to render at clipped is the relative rectangle to render ''' if not self.is_visible: return [] # figure my rect r = util.Rect(self._x, self._y, self._width, self._height) if view_clip is not None: r = r.intersect(view_clip) if r is None: return [] x, y, z = self._x, self._y, self._z # translate the view clip into this element's coordinate space clipped = self.rect clipped.x -= x clipped.y -= y if view_clip: view_clip = view_clip.copy() view_clip.x -= x view_clip.y -= y clipped = clipped.intersect(view_clip) if not clipped: return [] rects = [] if not self.is_transparent: rects.append((self, (x, y, z, clipped))) if not self.children: return rects # shift child elements and view clip for left & bottom padding pad = self._padding x += pad y += pad if view_clip is not None: view_clip = view_clip.copy() view_clip.x -= pad view_clip.y -= pad # clip by this element's view clip if self.view_clip is not None: if view_clip is not None: view_clip = view_clip.intersect(self.view_clip) else: view_clip = self.view_clip if not view_clip: return rects for child in self.children: if exclude is child: continue for obj, (ox, oy, oz, c) in child.getRects(view_clip, exclude): rects.append((obj, (ox + x, oy + y, oz + z, c))) return rects
def render(self, rect): image = self.image if image is None: return ir = util.Rect(image.x, image.y, image.width, image.height) if ir.clippedBy(rect): rect = ir.intersect(rect) if rect is None: return image = image.get_region(rect.x, rect.y, rect.width, rect.height) attrib = 0 if not self.isEnabled(): attrib = GL_CURRENT_BIT elif self.blend_color and self.color is not None: attrib = GL_CURRENT_BIT if self.is_blended: attrib |= GL_ENABLE_BIT if attrib: glPushAttrib(attrib) if attrib & GL_ENABLE_BIT: # blend with background glEnable(GL_BLEND) if attrib & GL_CURRENT_BIT: if not self.isEnabled(): # blend with gray colour to wash out glColor4f(.7, .7, .7, 1.) else: glColor4f(*self.color) # XXX alignment # blit() handles enabling GL_TEXTURE_2D and binding image.blit(rect.x, rect.y, 0) if attrib: glPopAttrib()
def get_inner_rect(self): p = self.padding font_size = self.getStyle().font_size return util.Rect(p, p, self.width - p * 2, self.height - p * 2 - font_size)
def get_inner_rect(self): if self.have_buttons: bw = ArrowButtonLeft.get_arrow().width return util.Rect(bw, 0, self.width - bw * 2, self.height) else: return util.Rect(0, 0, self.width, self.height)
def get_inner_rect(self): if self.have_buttons: bh = ArrowButtonLeft.get_arrow().height return util.Rect(0, bh, self.width, self.height - bh * 2) else: return util.Rect(0, 0, self.width, self.height)
def setViewClip(self, rect): self.view_clip = util.Rect(*rect)
def get_inner_rect(self): p = self._padding return util.Rect(int(p), int(p), intceil(self._width - p * 2), intceil(self._height - p * 2))
def get_rect(self): return util.Rect(int(self._x), int(self._y), self.width, self.height)