def printChar(self, c, bg_buf=None): # get the charactes pixel bitmap and dimensions if self.text_font: fmv, rows, cols = self.text_font.get_ch(c) else: raise AttributeError('No font selected') cbytes, cbits = divmod(cols, 8) # Not in packed format dcols = (cbytes + 1) * 8 if cbits else cbytes * 8 # cols for display pix_count = dcols * rows # number of bits in the char # test char fit if self.text_x + cols > self.text_width: # does the char fit on the screen? if self.text_scroll: self.printCR() # No, then CR self.printNewline(True) # NL: advance to the next line else: return 0 # Retrieve Background data if transparency is required if self.transparency: # in case of transpareny, the frame buffer content is needed if bg_buf is None: # buffer allocation needed? if len(self.bg_buf) < pix_count * 3: del(self.bg_buf) gc.collect() self.bg_buf = bytearray(pix_count * 3) # Make it bigger bg_buf = self.bg_buf self.setXY(self.text_x, self.text_y, self.text_x + dcols - 1, self.text_y + rows - 1) # set area TFT_io.tft_read_cmd_data_AS(0x2e, bg_buf, pix_count * 3) # read background data else: bg_buf = 0 # dummy assignment, since None is not accepted # Set XY range & print char self.setXY(self.text_x, self.text_y, self.text_x + dcols - 1, self.text_y + rows - 1) # set area TFT_io.displaySCR_charbitmap(addressof(fmv), pix_count, self.text_color, bg_buf) # display char! #advance pointer self.text_x += (cols + self.text_gap) return cols + self.text_gap
def show(self): tft = self.tft width = self.width dx = 5 x0 = self.x0 x1 = self.x1 y0 = self.y0 y1 = self.y1 height = y1 - y0 if self.divisions > 0: dy = height / (self.divisions) # Tick marks for tick in range(self.divisions + 1): ypos = int(y0 + dy * tick) tft.draw_hline(x0, ypos, dx, self.fgcolor) tft.draw_hline(x1 - dx, ypos, dx, self.fgcolor) if self.legends is not None and self.font is not None: # Legends if len(self.legends) <= 1: dy = 0 else: dy = height / (len(self.legends) - 1) yl = self.y1 # Start at bottom for legend in self.legends: print_centered(tft, int(self.x0 + self.width / 2), int(yl), legend, self.fontcolor, self.font) yl -= dy if self.ptr_y is not None: # Restore background if it was saved tft.setXY(x0, self.ptr_y, x1, self.ptr_y) TFT_io.tft_write_data_AS(self.ptrbuf, self.ptrbytes) self.ptr_y = int(self.y1 - self._value * height) # y position of slider tft.setXY(x0, self.ptr_y, x1, self.ptr_y) # Read background TFT_io.tft_read_cmd_data_AS(0x2e, self.ptrbuf, self.ptrbytes) tft.draw_hline(x0, self.ptr_y, width, self.pointercolor) # Draw pointer
def save_background(self, tft): # Read background under slide if self.slide_y is not None: tft.setXY(*self.slide_coords()) TFT_io.tft_read_cmd_data_AS(0x2e, self.slidebuf, self.slidebytes)