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

Skip to content

Integrate TilePaletteMapper and TileGrid further #10318

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 8 commits into from
May 9, 2025

Conversation

FoamyGuy
Copy link
Collaborator

@FoamyGuy FoamyGuy commented May 7, 2025

This makes the following functional changes:

  • TilePaletteMapper now has tilegrid as an argument instead of width, and height
  • TileGrid now allows pixel_shader argument to be None or omitted. But _add_layer() now validates that it it isn't None before it can be added to a Group to be shown on the display.
  • TileGrid is refactored to have a displayio_tilegrid_mark_tile_dirty() function that gets called by set_tile
  • TilePaletteMapper makes use of the new displayio_tilegrid_mark_tile_dirty() to mark individual tiles as dirty when the mapping for that tile is updated, rather than causing the whole TileGrid to be refreshed
  • TilePaletteMapper no longer has needs_refresh or finish_refresh concepts

I have tested the updated TPM functionality with the Matrix CircuitPython code (updated to use the new API), and with the text editor that I am working on for Fruit Jam OS, it uses TPM to highlight the bottom bar with hotkeys in it. All functionality appears to work as expected.

I have not specifically tested / validated the smaller dirty area refresh by ensuring that it speeds up refresh rate when single mappings are updated. That will confirm that it isn't updating the full TileGrid any longer, I will do that once I get the cursor changed to use TPM in the text editor.

I noticed that this change is showing some edits to the .pot file that I did not knowingly make. I ran pre-commit locally and it seems to have made some of those changes even though they appear unrelated to TileGrid or TilePaletteMapper. I'm not sure if that is a git or update / merge issue or something else. Let me know if I need to do anything further in that file though.

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.

I understand there is a circularity to this that needs to be broken. I'd do it the other way so TG always has a pixel_shader. Allow TPM to be constructed without allocating the mapping memory and "bind" the two when the TG is created. This can also check that multiple TG aren't given the TPM. (Or it could track multiple TG to mark dirty.)

@tannewt
Copy link
Member

tannewt commented May 8, 2025

I noticed that this change is showing some edits to the .pot file that I did not knowingly make. I ran pre-commit locally and it seems to have made some of those changes even though they appear unrelated to TileGrid or TilePaletteMapper. I'm not sure if that is a git or update / merge issue or something else. Let me know if I need to do anything further in that file though.

It looks fine to me. I'm not sure why Weblate didn't do it but it seems to be active. Updating these here is fine.

…or width/height, internal bind function is used to bind a TileGrid to a TilePaletteMapper when the TileGrid is init with or has pixel_shader set to a TPM
@FoamyGuy
Copy link
Collaborator Author

FoamyGuy commented May 8, 2025

The latest commit swaps this over to how you describe. pixel_shader is required for TileGrid as it was originally. TPM no longer accepts width, height, or tilegrid. The new internal bind function links a TPM to a TileGrid and is called when the TileGrid is created with a TPM pixel_shader, or has its pixel_shader set to a TPM.

Tested successfully on fruitjam with the circuitpython matrix code, and the latest version of text editor updated to use the new API.

…d to None before it is bound, disallow TPM from being bound multiple times.
@FoamyGuy
Copy link
Collaborator Author

FoamyGuy commented May 9, 2025

A few more changes in the latest commit:

  • fix the pixel_shader property name which was previously palette. I'm guessing that was something I originally intended to change when ColorConverter support was added, but didn't do at the time.
  • Add tilegrid property to the locals table
  • Set tilegrid to None when the TPM is constructed
  • disallow TPM to be bound if its TileGrid isn't None still i.e. TPM can only be bound to a single tilegrid one time, a new one would have to get created to use with a different TileGrid or even to re-bind to the same TileGrid with the pixel_shader setter.

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 to me! One comment you may want to do in a follow up.

@@ -67,7 +55,7 @@ void common_hal_tilepalettemapper_tilepalettemapper_set_mapping(tilepalettemappe
mp_arg_validate_int_range(mapping_val, 0, palette_max, MP_QSTR_mapping_value);
self->tile_mappings[y * self->width_in_tiles + x][i] = mapping_val;
}
self->needs_refresh = true;
displayio_tilegrid_mark_tile_dirty(self->tilegrid, x, y);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a chance that someone will set the existing mapping again? Maybe we want to detect when nothing is actually changed and not mark the tile dirty then.

@tannewt tannewt merged commit a3506a7 into adafruit:main May 9, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants