From 19b369e6e710174612bcfa1fa1bdf40d645f3b6f Mon Sep 17 00:00:00 2001 From: peterhinch Date: Mon, 1 May 2023 10:11:16 +0100 Subject: [PATCH] Use standard writer.py: create_color() matches nano-gui. --- gui/core/colors.py | 13 +++---------- gui/core/writer.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/gui/core/colors.py b/gui/core/colors.py index 4535015..c4db598 100644 --- a/gui/core/colors.py +++ b/gui/core/colors.py @@ -1,20 +1,13 @@ # colors.py Micropython GUI library for TFT displays: colors and shapes # Released under the MIT License (MIT). See LICENSE. -# Copyright (c) 2019-2021 Peter Hinch +# Copyright (c) 2019-2023 Peter Hinch from hardware_setup import SSD +from gui.core.writer import CWriter # Code can be portable between 4-bit and other drivers by calling create_color def create_color(idx, r, g, b): - c = SSD.rgb(r, g, b) - if not hasattr(SSD, 'lut'): - return c - if not 0 <= idx <= 15: - raise ValueError('Color nos must be 0..15') - x = idx << 1 - SSD.lut[x] = c & 0xff - SSD.lut[x + 1] = c >> 8 - return idx + return CWriter.create_color(SSD, idx, r, g, b) if hasattr(SSD, 'lut'): # Colors defined by LUT BLACK = create_color(0, 0, 0, 0) diff --git a/gui/core/writer.py b/gui/core/writer.py index 0414211..48f5e14 100644 --- a/gui/core/writer.py +++ b/gui/core/writer.py @@ -1,6 +1,7 @@ # writer.py Implements the Writer class. # Handles colour, word wrap and tab stops +# V0.5.1 Dec 2022 Support 4-bit color display drivers. # V0.5.0 Sep 2021 Color now requires firmware >= 1.17. # V0.4.3 Aug 2021 Support for fast blit to color displays (PR7682). # V0.4.0 Jan 2021 Improved handling of word wrap and line clip. Upside-down @@ -25,7 +26,7 @@ from uctypes import bytearray_at, addressof from sys import implementation import os -__version__ = (0, 5, 0) +__version__ = (0, 5, 1) fast_mode = True # Does nothing. Kept to avoid breaking code. @@ -255,6 +256,17 @@ class Writer(): # Writer for colour displays. class CWriter(Writer): + @staticmethod + def create_color(ssd, idx, r, g, b): + c = ssd.rgb(r, g, b) + if not hasattr(ssd, 'lut'): + return c + if not 0 <= idx <= 15: + raise ValueError('Color nos must be 0..15') + x = idx << 1 + ssd.lut[x] = c & 0xff + ssd.lut[x + 1] = c >> 8 + return idx def __init__(self, device, font, fgcolor=None, bgcolor=None, verbose=True): if not hasattr(device, 'palette'):