Skip to content

Changes to shape objects to explicitly set opaque property when changing colors #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions adafruit_display_shapes/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1):

if fill is not None:
self._palette[0] = fill
self._palette.make_opaque(0)
else:
self._palette[0] = 0
self._palette.make_transparent(0)
super().__init__(self._bitmap, pixel_shader=self._palette, x=x, y=y)

Expand All @@ -89,9 +91,11 @@ def fill(self):
@fill.setter
def fill(self, color):
if color is None:
self._palette[0] = 0
self._palette.make_transparent(0)
else:
self._palette[0] = color
self._palette.make_opaque(0)

@property
def outline(self):
Expand All @@ -102,6 +106,8 @@ def outline(self):
@outline.setter
def outline(self, color):
if color is None:
self._palette[1] = 0
self._palette.make_transparent(1)
else:
self._palette[1] = color
self._palette.make_opaque(1)
32 changes: 14 additions & 18 deletions adafruit_display_shapes/roundrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`roundrect`
`my_roundrect`
================================================================================

Various common shapes for use with displayio - Rounded Rectangle shape!


* Author(s): Limor Fried

Implementation Notes
--------------------

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
A slightly modified version of Adafruit_CircuitPython_Display_Shapes that includes
an explicit call to palette.make_opaque() in the fill color setter function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true. It should document what a roundrect is.


"""

Expand Down Expand Up @@ -65,16 +55,18 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1)
self._palette = displayio.Palette(3)
self._palette.make_transparent(0)
self._bitmap = displayio.Bitmap(width, height, 3)
for i in range(0, width): # draw the center chunk
for j in range(r, height - r): # draw the center chunk
self._bitmap[i, j] = 2
self._helper(r, r, r, color=2, fill=True,
x_offset=width-2*r-1, y_offset=height-2*r-1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it failed the checks because a space need to be added to this line.


if fill is not None:
for i in range(0, width): # draw the center chunk
for j in range(r, height - r): # draw the center chunk
self._bitmap[i, j] = 2
self._helper(r, r, r, color=2, fill=True,
x_offset=width-2*r-1, y_offset=height-2*r-1)
self._palette[2] = fill
self._palette.make_opaque(2)
else:
self._palette.make_transparent(2)
self._palette[2] = 0

if outline is not None:
self._palette[1] = outline
Expand Down Expand Up @@ -148,9 +140,11 @@ def fill(self):
@fill.setter
def fill(self, color):
if color is None:
self._palette[2] = 0
self._palette.make_transparent(2)
else:
self._palette[2] = color
self._palette.make_opaque(2)

@property
def outline(self):
Expand All @@ -161,6 +155,8 @@ def outline(self):
@outline.setter
def outline(self, color):
if color is None:
self._palette[1] = 0
self._palette.make_transparent(1)
else:
self._palette[1] = color
self._palette.make_opaque(2)
6 changes: 5 additions & 1 deletion adafruit_display_shapes/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None):
self._palette.make_transparent(2)

if outline is not None:
print("outline")
# print("outline")
self._palette[1] = outline
self._line(x0 - min(xs), 0, x1 - min(xs), y1 - y0, 1)
self._line(x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0, 1)
Expand Down Expand Up @@ -186,9 +186,11 @@ def fill(self):
@fill.setter
def fill(self, color):
if color is None:
self._palette[2] = 0
self._palette.make_transparent(2)
else:
self._palette[2] = color
self._palette.make_opaque(2)

@property
def outline(self):
Expand All @@ -199,6 +201,8 @@ def outline(self):
@outline.setter
def outline(self, color):
if color is None:
self._palette[1] = 0
self._palette.make_transparent(1)
else:
self._palette[1] = color
self._palette.make_opaque(1)