Skip to content

changes for blit refactor to bitmaptools. #87

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 23 additions & 6 deletions adafruit_displayio_layout/widgets/flip_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import time
import displayio
from terminalio import FONT

import bitmaptools
from adafruit_display_shapes.triangle import Triangle

from adafruit_display_text import bitmap_label
Expand All @@ -43,7 +43,6 @@
except ImportError:
pass


__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout.git"

Expand Down Expand Up @@ -381,7 +380,12 @@ def _update_value(self, new_value: int, animate: bool = True) -> None:
start_bitmap = displayio.Bitmap(
self._label.bitmap.width, self._label.bitmap.height, 2
) # color depth 2
start_bitmap.blit(0, 0, self._label.bitmap)

# CircuitPython Versions <= 8.2.0
# start_bitmap.blit(0, 0, self._label.bitmap)

# CircuitPython Versions >= 9.0.0
bitmaptools.blit(start_bitmap, self._label.bitmap, 0, 0)

# get the bitmap1 position offsets
bitmap1_offset = (
Expand Down Expand Up @@ -555,11 +559,20 @@ def _draw_position(

if position == 0.0:
target_bitmap.fill(0)
target_bitmap.blit(x_offset1, y_offset1, bitmap1)

# CircuitPython Versions <= 8.2.0
# target_bitmap.blit(x_offset1, y_offset1, bitmap1)

# CircuitPython Versions >= 9.0.0
bitmaptools.blit(target_bitmap, bitmap1, x_offset1, y_offset1)
return
if position == 1.0:
target_bitmap.fill(0)
target_bitmap.blit(x_offset2, y_offset2, bitmap2)
# CircuitPython Versions <= 8.2.0
# target_bitmap.blit(x_offset2, y_offset2, bitmap2)

# CircuitPython Versions >= 9.0.0
bitmaptools.blit(target_bitmap, bitmap2, x_offset2, y_offset2)
return

if horizontal:
Expand Down Expand Up @@ -641,7 +654,11 @@ def _blit_constrained(
):
return

target.blit(x, y, source, x1=x1, y1=y1, x2=x2, y2=y2)
# CircuitPython Versions <= 8.2.0
# target.blit(x, y, source, x1=x1, y1=y1, x2=x2, y2=y2)

# CircuitPython Versions >= 9.0.0
bitmaptools.blit(target, source, x, y, x1=x1, y1=y1, x2=x2, y2=y2)


# _animate_bitmap - performs animation of scrolling between two bitmaps
Expand Down
24 changes: 17 additions & 7 deletions adafruit_displayio_layout/widgets/icon_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@
except ImportError:
pass


__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout.git"


class IconAnimated(IconWidget):

"""
An animated touch enabled widget that holds an icon image loaded with
OnDiskBitmap and a text label centered beneath it. Includes optional
Expand Down Expand Up @@ -80,6 +78,7 @@ class IconAnimated(IconWidget):
# pylint: disable=too-many-arguments, unused-argument

display = None

# The other Class variables are created in Class method `init_class`:
# max_scale, bitmap_buffer, palette_buffer

Expand Down Expand Up @@ -226,11 +225,22 @@ def zoom_animation(self, touch_point: Tuple[int, int, Optional[int]]) -> None:

# create the zoom bitmap larger than the original image to allow for zooming
animation_bitmap.fill(len(animation_palette) - 1) # transparent fill
animation_bitmap.blit(
(animation_bitmap.width - _image.width) // 2,
(animation_bitmap.height - _image.height) // 2,
_image,
) # blit the image into the center of the zoom_bitmap

if hasattr(animation_bitmap, "blit"):
# CircuitPython Versions <= 8.2.0
animation_bitmap.blit(
(animation_bitmap.width - _image.width) // 2,
(animation_bitmap.height - _image.height) // 2,
_image,
) # blit the image into the center of the zoom_bitmap
elif hasattr(bitmaptools, "blit"):
# CircuitPython Versions >= 9.0.0
bitmaptools.blit(
animation_bitmap,
_image,
(animation_bitmap.width - _image.width) // 2,
(animation_bitmap.height - _image.height) // 2,
)

# place zoom_bitmap at same location as image
animation_tilegrid = TileGrid(
Expand Down