def draw(self, surf, pos, hilight): dim = self.getDimensions() surf.blit(self._drawBox(dim, hilight), pos) (x, y) = pos y += self.theme['padding'] (font_w, font_h) = self.font.size(self.text) if self.icon: x += self.theme['padding'] (icon_w, icon_h) = self.icon.get_size() icon_y = y if icon_h < font_h: icon_y += (font_h - icon_h) / 2 else: y += (icon_h - font_h) / 2 surf.blit(self.icon, (x, icon_y)) x += icon_w x += self.theme['padding'] util.drawText(surf, self.font, (x, y), self.text, self.theme['font_color']) return dim
def draw(self, screen): super(FileBrowser, self).draw(screen) (width, height) = self.size() (sb_width, sb_height) = self._scrollbar.size() browser = util.alphaSurface(width, height) # Draw list and render to texture. browser.set_clip((0, self._font.get_linesize(), width - sb_width, height)) list = self._listview.draw(browser, (0, self._font.get_linesize())) browser.set_clip() # Draw the scrollbar if self._getListLength() > self._listview.getViewEntries(): sb_pos = (width - sb_width, self._font.get_linesize()) self._scrollbar.draw(self._listview.getViewEntries(), self._listview.top, self._getListLength(), browser, sb_pos) # Draw border pygame.draw.rect(browser, (0, 0, 0), (0, self._font.get_linesize(), width, height - self._font.get_linesize()), 1) else: # Draw border without scrollbar. pygame.draw.rect(browser, (0, 0, 0), (0, self._font.get_linesize(), width - sb_width, height - self._font.get_linesize()), 1) # Blit it all to screen (screen_width, screen_height) = screen.get_size() x = (screen_width - width) / 2 y = (screen_height - height) / 2 + self._font.get_linesize() screen.blit(browser, (x, y)) # Draw header (directly to screen) header_width = self._font.size(self._path)[0] x = (screen_width - header_width) / 2 util.drawText(screen, self._font, (x, y), self._getTitle(), self.theme['heading_color'])
def after_draw(self, screen): date = time.strftime(self._format) w = self._font.size(date)[0] util.drawText(screen, self._font, (screen.get_size()[0] - w - self._theme['padding'], self._theme['padding']), date, self._theme['font_color'])
def _drawLine(self, line, y): t_w, t_h = self._font.size(line) if self._align == constants.LEFT: x = 0 elif self._align == constants.RIGHT: x = self._w - t_w elif self._align == constants.CENTER: x = (self._w - t_w) / 2 util.drawText(self._surface, self._font, (x, y), line, self._theme['font_color']) return t_h
def _drawContents(self, surf, width, pos): y = self.theme['padding'] + pos[1] x = pos[0] for (i, entry) in itertools.islice(enumerate(self._populator()), self.top, self.top + self.getViewEntries()): if i == self._selected: bar = (x, y, width, self.font.get_linesize()) surf.fill(self.theme['background_selected'], bar) color = self.theme['font_color'] if self.hilight_callback and self.hilight_callback(i, entry): color = self.theme['hilight_color'] util.drawText(surf, self.font, (x + self.theme['padding'], y), entry, color) y += self.font.get_linesize() + self.theme['padding']
def draw(self, screen): super(XkcdBrowser, self).draw(screen) self._downloader.download(self._current_comic) if not self._current_comic: self._current_comic = self._downloader.newest if not self._current_data: self._loadData() self._scrollable_frame.setImage(self._current_data[0]) self._caption_frame.setText(self._current_data[1][1]) w, h = self._heading.size(self._current_data[1][0]) util.drawText(screen, self._heading, ((self._app.screen.get_size()[0] - w) / 2, 0), self._current_data[1][0], self._theme['heading_color']) self._scrollable_frame.draw(screen, (self._frame_x, self._frame_y)) self._caption_frame.draw(screen, (self._caption_x, self._caption_y))