コード例 #1
0
ファイル: tft.py プロジェクト: peterhinch/micropython-tft-gui
    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
コード例 #2
0
    def printChar(self, c, bg_buf=None):
# get the charactes pixel bitmap and dimensions
        if self.text_font:
            fontptr, rows, cols = self.text_font.get_ch(ord(c))
        else:
            raise AttributeError('No font selected')
        pix_count = cols * 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?
                bg_buf = bytearray(pix_count * 3) # sigh...
            self.setXY(self.text_x, self.text_y, self.text_x + cols - 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 + cols - 1, self.text_y + rows - 1) # set area
        TFT_io.displaySCR_charbitmap(fontptr, pix_count, self.text_color, bg_buf) # display char!
#advance pointer
        self.text_x += (cols + self.text_gap)
        return cols + self.text_gap
コード例 #3
0
    def printChar(self, c, bg_buf=None):
        # get the charactes pixel bitmap and dimensions
        if self.text_font:
            fontptr, rows, cols = self.text_font.get_ch(ord(c))
        else:
            raise AttributeError('No font selected')
        pix_count = cols * 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?
                bg_buf = bytearray(pix_count * 3)  # sigh...
            self.setXY(self.text_x, self.text_y, self.text_x + cols - 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 + cols - 1,
                   self.text_y + rows - 1)  # set area
        TFT_io.displaySCR_charbitmap(fontptr, pix_count, self.text_color,
                                     bg_buf)  # display char!
        #advance pointer
        self.text_x += (cols + self.text_gap)
        return cols + self.text_gap
コード例 #4
0
ファイル: tft.py プロジェクト: watrt/micropython-tft-gui
    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