def draw_label(self, dx=0, dy=0): '''Method to draw the label. Accept dx/dy to be added on label position. This can be used to draw shadow for example.''' # because the anchor_x/anchor_y is propagated to the drawLabel, # we don't care about the internal label size. pos = list(self.center) if self.anchor_x == 'left': pos[0] = self.x elif self.anchor_x == 'right': pos[0] = self.x + self.width if self.anchor_y == 'top': pos[1] = self.y + self.height elif self.anchor_y == 'bottom': pos[1] = self.y pos[0] += dx pos[1] += dy # ensure multiline if self.multiline: self.kwargs['size'] = (self.width, None) # force autosize if self.autosize or self.autowidth or self.autoheight: if 'size' in self.kwargs: del self.kwargs['size'] w, h = drawLabel(label=self.label, pos=pos, **self.kwargs) self._used_label = getLastLabel() self._update_size(w, h)
def draw_label(self, dx=0, dy=0): '''Method to draw the label. Accept dx/dy to be added on label position. This can be used to draw shadow for example.''' # because the anchor_x/anchor_y is propagated to the drawLabel, # we don't care about the internal label size. kwargs = self.kwargs pos = list(self.center) if self.anchor_x == 'left': pos[0] = self.x elif self.anchor_x == 'right': pos[0] = self.x + self.width if self.anchor_y == 'top': pos[1] = self.y + self.height elif self.anchor_y == 'bottom': pos[1] = self.y pos[0] += dx pos[1] += dy # ensure multiline if self.multiline: kwargs['size'] = (self.width, None) # force autosize if self.autosize or self.autowidth or self.autoheight: if 'size' in kwargs: if self.autoheight: kwargs['size'] = (kwargs['size'][0], None) else: del kwargs['size'] else: # FIXME: found a way to cache this information # and not calculate it every frame. w, h = self.size px = self._used_label.options['padding_x'] py = self._used_label.options['padding_y'] w -= px * 2 h -= py * 2 kwargs['viewport_size'] = (w, h) w, h = drawLabel(label=self.label, pos=pos, **kwargs) self._used_label = getLastLabel() self._update_size(w, h)
def _do_update(self, mode=None): # we absolutly want mode to update displaylist. if mode not in ('background', 'keys'): return # don't update background if it's already compiled if mode == 'background' and self._current_cache['background'].is_compiled(): return # calculate margin s = self.scale w, h = self.container_width, self.container_height if mode == 'background': s = 1. w, h = self.size mtop, mright, mbottom, mleft = map(lambda x: x * s, self.style['margin']) self.texsize = Vector(w - mleft - mright, h - mtop - mbottom) kx, ky = self.layout.SIZE self.keysize = Vector(self.texsize.x / kx, self.texsize.y / ky) m = 3 * s x, y = 0, self.texsize.y - self.keysize.y # update display list self._current_cache['usedlabel'] = [] with self._current_cache[mode]: # draw lines for index in xrange(1, ky + 1): line = self.layout.__getattribute__('%s_%d' % (self.mode, index)) # draw keys for key in line: displayed_str, internal_str, internal_action, scale = key kw = self.keysize.x * scale # don't display empty keys if displayed_str is not None: set_color(*self.style['key-color']) if mode == 'background': if internal_action is not None: set_color(*self.style['syskey-color']) drawCSSRectangle( pos=(x+m, y+m), size=(kw-m*2, self.keysize.y-m*2), style=self.style, prefix='key') elif mode == 'keys': font_size = int(14 * s) if font_size < 8: font_size = 8 color = self.style['color'] if internal_action is not None: color = self.style['color-syskey'] drawLabel(label=displayed_str, pos=(x + kw / 2., y + self.keysize.y / 2.), font_size=font_size, bold=False, font_name=self.style.get('font-name'), color=color) self._current_cache['usedlabel'].append(getLastLabel()) # advance X x += kw # advance Y y -= self.keysize.y x = 0 # update completed self._need_update = None