Skip to content

Commit 6219aa0

Browse files
authored
Merge pull request #8 from DavePutz/master
Changes to shape objects to explicitly set opaque property when changing colors
2 parents 3819526 + 262ce19 commit 6219aa0

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

adafruit_display_shapes/rect.py

+6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1):
7676

7777
if fill is not None:
7878
self._palette[0] = fill
79+
self._palette.make_opaque(0)
7980
else:
81+
self._palette[0] = 0
8082
self._palette.make_transparent(0)
8183
super().__init__(self._bitmap, pixel_shader=self._palette, x=x, y=y)
8284

@@ -89,9 +91,11 @@ def fill(self):
8991
@fill.setter
9092
def fill(self, color):
9193
if color is None:
94+
self._palette[0] = 0
9295
self._palette.make_transparent(0)
9396
else:
9497
self._palette[0] = color
98+
self._palette.make_opaque(0)
9599

96100
@property
97101
def outline(self):
@@ -102,6 +106,8 @@ def outline(self):
102106
@outline.setter
103107
def outline(self, color):
104108
if color is None:
109+
self._palette[1] = 0
105110
self._palette.make_transparent(1)
106111
else:
107112
self._palette[1] = color
113+
self._palette.make_opaque(1)

adafruit_display_shapes/roundrect.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,8 @@
2323
`roundrect`
2424
================================================================================
2525
26-
Various common shapes for use with displayio - Rounded Rectangle shape!
27-
28-
29-
* Author(s): Limor Fried
30-
31-
Implementation Notes
32-
--------------------
33-
34-
**Software and Dependencies:**
35-
36-
* Adafruit CircuitPython firmware for the supported boards:
37-
https://github.com/adafruit/circuitpython/releases
26+
A slightly modified version of Adafruit_CircuitPython_Display_Shapes that includes
27+
an explicit call to palette.make_opaque() in the fill color setter function.
3828
3929
"""
4030

@@ -65,16 +55,18 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1)
6555
self._palette = displayio.Palette(3)
6656
self._palette.make_transparent(0)
6757
self._bitmap = displayio.Bitmap(width, height, 3)
58+
for i in range(0, width): # draw the center chunk
59+
for j in range(r, height - r): # draw the center chunk
60+
self._bitmap[i, j] = 2
61+
self._helper(r, r, r, color=2, fill=True,
62+
x_offset=width-2*r-1, y_offset=height-2*r-1)
6863

6964
if fill is not None:
70-
for i in range(0, width): # draw the center chunk
71-
for j in range(r, height - r): # draw the center chunk
72-
self._bitmap[i, j] = 2
73-
self._helper(r, r, r, color=2, fill=True,
74-
x_offset=width-2*r-1, y_offset=height-2*r-1)
7565
self._palette[2] = fill
66+
self._palette.make_opaque(2)
7667
else:
7768
self._palette.make_transparent(2)
69+
self._palette[2] = 0
7870

7971
if outline is not None:
8072
self._palette[1] = outline
@@ -148,9 +140,11 @@ def fill(self):
148140
@fill.setter
149141
def fill(self, color):
150142
if color is None:
143+
self._palette[2] = 0
151144
self._palette.make_transparent(2)
152145
else:
153146
self._palette[2] = color
147+
self._palette.make_opaque(2)
154148

155149
@property
156150
def outline(self):
@@ -161,6 +155,8 @@ def outline(self):
161155
@outline.setter
162156
def outline(self, color):
163157
if color is None:
158+
self._palette[1] = 0
164159
self._palette.make_transparent(1)
165160
else:
166161
self._palette[1] = color
162+
self._palette.make_opaque(2)

adafruit_display_shapes/triangle.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None):
8989
self._palette.make_transparent(2)
9090

9191
if outline is not None:
92-
print("outline")
92+
# print("outline")
9393
self._palette[1] = outline
9494
self._line(x0 - min(xs), 0, x1 - min(xs), y1 - y0, 1)
9595
self._line(x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0, 1)
@@ -186,9 +186,11 @@ def fill(self):
186186
@fill.setter
187187
def fill(self, color):
188188
if color is None:
189+
self._palette[2] = 0
189190
self._palette.make_transparent(2)
190191
else:
191192
self._palette[2] = color
193+
self._palette.make_opaque(2)
192194

193195
@property
194196
def outline(self):
@@ -199,6 +201,8 @@ def outline(self):
199201
@outline.setter
200202
def outline(self, color):
201203
if color is None:
204+
self._palette[1] = 0
202205
self._palette.make_transparent(1)
203206
else:
204207
self._palette[1] = color
208+
self._palette.make_opaque(1)

0 commit comments

Comments
 (0)