From d9ee0f388d8a621b4fcd894aedb110e5a5eae3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Sat, 8 Jul 2017 20:07:42 +0200 Subject: [PATCH] improved drawing text for area drawing --- gfxlcd/abstract/chip.py | 10 ---------- gfxlcd/drawing/area.py | 24 ++++++++++++++++++++++++ gfxlcd/drawing/pixel.py | 8 ++++++-- gfxlcd/driver/hd44780.py | 2 +- gfxlcd/driver/ili9325/ili9325.py | 16 ---------------- gfxlcd/driver/ili9486/ili9486.py | 16 ---------------- gfxlcd/driver/nju6450/nju6450.py | 8 -------- gfxlcd/driver/ssd1306/ssd1306.py | 8 -------- 8 files changed, 31 insertions(+), 61 deletions(-) diff --git a/gfxlcd/abstract/chip.py b/gfxlcd/abstract/chip.py index fd8c55a..6e1eb64 100644 --- a/gfxlcd/abstract/chip.py +++ b/gfxlcd/abstract/chip.py @@ -30,16 +30,6 @@ class Chip(metaclass=abc.ABCMeta): else: return self._width - # @abc.abstractmethod - # def _converted_background_color(self): - # """convert RGB background to available color""" - # pass - # - # @abc.abstractmethod - # def _converted_color(self): - # """convert RGB color to available color""" - # pass - @abc.abstractmethod def _convert_color(self, color): """convert color to avaible one""" diff --git a/gfxlcd/drawing/area.py b/gfxlcd/drawing/area.py index de4fae8..092c4f6 100644 --- a/gfxlcd/drawing/area.py +++ b/gfxlcd/drawing/area.py @@ -160,3 +160,27 @@ class Area(Pixel): return True return False + + def _draw_letter(self, pos_x, pos_y, letter, with_background=False): + """draw a letter""" + if not with_background: + super()._draw_letter(pos_x, pos_y, letter, with_background) + else: + font = self.options['font'] + self._set_area( + pos_x, + pos_y, + pos_x + font.size[0] - 1, + pos_y + font.size[1] - 1 + ) + + bits = font.size[0] + color = self._convert_color(self.options['color']) + background_color = self._convert_color(self.options['background_color']) + for row, data in enumerate(font.get(letter)): + for bit in range(bits): + if data & 0x01: + self.driver.data(color, None) + elif with_background: + self.driver.data(background_color, None) + data >>= 1 diff --git a/gfxlcd/drawing/pixel.py b/gfxlcd/drawing/pixel.py index 209ad3f..4dca13d 100644 --- a/gfxlcd/drawing/pixel.py +++ b/gfxlcd/drawing/pixel.py @@ -152,8 +152,12 @@ class Pixel(object): for row, data in enumerate(font.get(letter)): for bit in range(bits): if data & 0x01: - self.draw_pixel(pos_x + bit, pos_y + row) + self.draw_pixel( + pos_x + bit, pos_y + row, self.color + ) elif with_background: - self.draw_pixel(pos_x + bit, pos_y + row) + self.draw_pixel( + pos_x + bit, pos_y + row, self.background_color + ) data >>= 1 diff --git a/gfxlcd/driver/hd44780.py b/gfxlcd/driver/hd44780.py index 7423805..3386c1e 100644 --- a/gfxlcd/driver/hd44780.py +++ b/gfxlcd/driver/hd44780.py @@ -60,7 +60,7 @@ class HD44780(BaseDriver): def char(self, char, enable=0): """write char to lcd""" self.gfxlcd.draw_text( - self.position['x'], self.position['y'], char + self.position['x'], self.position['y'], char, True ) self._increase_x() diff --git a/gfxlcd/driver/ili9325/ili9325.py b/gfxlcd/driver/ili9325/ili9325.py index 1bdd5fb..2cc68a0 100644 --- a/gfxlcd/driver/ili9325/ili9325.py +++ b/gfxlcd/driver/ili9325/ili9325.py @@ -33,22 +33,6 @@ class ILI9325(Area, Chip): Chip.__init__(self, width, height, driver, True) Area.__init__(self, driver) - # def _converted_background_color(self): - # """color from 8-8-8 to 5-6-5""" - # rgb = self.options['background_color']['R'] << 16 | \ - # self.options['background_color']['G'] << 8 | \ - # self.options['background_color']['B'] - # return ((rgb & 0x00f80000) >> 8) |\ - # ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) - # - # def _converted_color(self): - # """color from 8-8-8 to 5-6-5""" - # rgb = self.options['color']['R'] << 16 | \ - # self.options['color']['G'] << 8 | \ - # self.options['color']['B'] - # return ((rgb & 0x00f80000) >> 8) |\ - # ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) - def _convert_color(self, color): """color from 8-8-8 to 5-6-5""" rgb = color['R'] << 16 | \ diff --git a/gfxlcd/driver/ili9486/ili9486.py b/gfxlcd/driver/ili9486/ili9486.py index b32843b..2d5d693 100644 --- a/gfxlcd/driver/ili9486/ili9486.py +++ b/gfxlcd/driver/ili9486/ili9486.py @@ -12,22 +12,6 @@ class ILI9486(Area, Chip): Chip.__init__(self, width, height, driver, True) Area.__init__(self, driver) - # def _converted_background_color(self): - # """color from 8-8-8 to 5-6-5""" - # rgb = self.options['background_color']['R'] << 16 | \ - # self.options['background_color']['G'] << 8 | \ - # self.options['background_color']['B'] - # return ((rgb & 0x00f80000) >> 8) |\ - # ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) - # - # def _converted_color(self): - # """color from 8-8-8 to 5-6-5""" - # rgb = self.options['color']['R'] << 16 | \ - # self.options['color']['G'] << 8 | \ - # self.options['color']['B'] - # return ((rgb & 0x00f80000) >> 8) |\ - # ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) - def _convert_color(self, color): """color from 8-8-8 to 5-6-5""" rgb = color['R'] << 16 | \ diff --git a/gfxlcd/driver/nju6450/nju6450.py b/gfxlcd/driver/nju6450/nju6450.py index e4be7e1..682f8ae 100644 --- a/gfxlcd/driver/nju6450/nju6450.py +++ b/gfxlcd/driver/nju6450/nju6450.py @@ -36,14 +36,6 @@ class NJU6450(Page, Chip): self.driver.cmd(0xB8 | pos_y, 1) self.driver.cmd(0x00 | (pos_x - width//2), 1) - # def _converted_background_color(self): - # """convert RGB background to available color""" - # return 1 - # - # def _converted_color(self): - # """convert RGB color to available color""" - # return 1 - def _convert_color(self, color): """convert color to avaiable one""" if color['R'] == 0 and color['G'] == 0 and color['B'] == 0: diff --git a/gfxlcd/driver/ssd1306/ssd1306.py b/gfxlcd/driver/ssd1306/ssd1306.py index a5b40dd..2f3b8c4 100644 --- a/gfxlcd/driver/ssd1306/ssd1306.py +++ b/gfxlcd/driver/ssd1306/ssd1306.py @@ -76,14 +76,6 @@ class SSD1306(Page, Chip): self.driver.cmd(0x14) # enable charge pump self.driver.cmd(0xaf) # turn on panel - # def _converted_background_color(self): - # """convert RGB background to available color""" - # return 1 - # - # def _converted_color(self): - # """convert RGB color to available color""" - # return 1 - def _convert_color(self, color): """convert color to avaiable one""" if color['R'] == 0 and color['G'] == 0 and color['B'] == 0: