improved drawing text for area drawing
This commit is contained in:
parent
7be3f9c0af
commit
d9ee0f388d
@ -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"""
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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 | \
|
||||
|
@ -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 | \
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user