Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

FoamyGuy
Copy link
Collaborator

@FoamyGuy FoamyGuy commented May 27, 2022

This adds a tilegrid.contains() function that accepts a touch tuple from adafruit_touchscreen library (or similar) and returns true or false based on whether the touch point is inside the rectangular bounds of this tilegrid.

This function matches the API provided by the display button library: https://github.com/adafruit/Adafruit_CircuitPython_Display_Button

This will allow us to use arbitrary Bitmaps and OnDiskBitmaps as touch interactive objects.

@dhalbert dhalbert requested a review from tannewt May 29, 2022 16:31
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Two minor nitpicks. Thanks for adding this! Group would be cool to do too.

@FoamyGuy
Copy link
Collaborator Author

FoamyGuy commented Jun 3, 2022

Thank you! latest commits make those changes. I retested it successfully on PyPortal Titano with this code:

import board
import displayio
import adafruit_touchscreen

display = board.DISPLAY

ts = adafruit_touchscreen.Touchscreen(
    board.TOUCH_XL,
    board.TOUCH_XR,
    board.TOUCH_YD,
    board.TOUCH_YU,
    calibration=((5200, 59000), (5800, 57000)),
    size=(display.width, display.height),
)

# Setup the file as the bitmap data source
bitmap = displayio.OnDiskBitmap("/purple.bmp")

# Create a TileGrid to hold the bitmap
tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)

tile_grid.x = 50
tile_grid.y = 50

# Create a Group to hold the TileGrid
group = displayio.Group()

# Add the TileGrid to the Group
group.append(tile_grid)

# Add the Group to the Display
display.show(group)

# Loop forever so you can enjoy your image
while True:
    p = ts.touch_point
    if p:
        print(p)
        if tile_grid.contains(p):
            print("Touching Flowers")
        else:
            print("Outside")

tannewt
tannewt previously approved these changes Jun 3, 2022
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thank you!

@FoamyGuy
Copy link
Collaborator Author

FoamyGuy commented Jun 3, 2022

One more commit to fix an off by 1 error. Turns out the right and bottom edges were returning True for one pixel too large.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

@tannewt tannewt merged commit b90563d into adafruit:main Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants