forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Addding support for inverted tiles in TileGrid #10102
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2975057
add support for inverted tiles in TileGrid
FoamyGuy 22e5c46
format code
FoamyGuy b4910bf
refactor for loop and if statements. disable module for feather m0 su…
FoamyGuy f3725a5
force refresh after inverting tile
FoamyGuy 99ff4ff
validate x,y values. change disabled modules to fit
FoamyGuy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_ | |
| mp_obj_t pixel_shader, uint16_t width, uint16_t height, | ||
| uint16_t tile_width, uint16_t tile_height, uint16_t x, uint16_t y, uint8_t default_tile) { | ||
| uint32_t total_tiles = width * height; | ||
| self->inverts = (bool *)m_malloc(total_tiles); | ||
| // Sprites will only have one tile so save a little memory by inlining values in the pointer. | ||
| uint8_t inline_tiles = sizeof(uint8_t *); | ||
| if (total_tiles <= inline_tiles) { | ||
|
|
@@ -54,6 +55,7 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_ | |
| self->flip_y = false; | ||
| self->transpose_xy = false; | ||
| self->absolute_transform = NULL; | ||
| displayio_tilegird_clear_inverts(self); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -65,6 +67,14 @@ bool displayio_tilegrid_get_rendered_hidden(displayio_tilegrid_t *self) { | |
| return self->rendered_hidden; | ||
| } | ||
|
|
||
| void displayio_tilegird_clear_inverts(displayio_tilegrid_t *self) { | ||
| for (uint16_t x = 0; x < self->width_in_tiles; x++) { | ||
| for (uint16_t y = 0; y < self->height_in_tiles; y++) { | ||
| self->inverts[y * self->width_in_tiles + x] = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t *self, bool hidden) { | ||
| self->hidden = hidden; | ||
| self->rendered_hidden = false; | ||
|
|
@@ -355,6 +365,16 @@ bool common_hal_displayio_tilegrid_contains(displayio_tilegrid_t *self, uint16_t | |
| y >= self->y && y < bottom_edge; | ||
| } | ||
|
|
||
| bool common_hal_displayio_tilegrid_get_inverted(displayio_tilegrid_t *self, uint16_t x, uint16_t y) { | ||
| uint16_t tile_location = y * self->width_in_tiles + x; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add: |
||
| return self->inverts[tile_location]; | ||
| } | ||
|
|
||
| void common_hal_displayio_tilegrid_set_inverted(displayio_tilegrid_t *self, uint16_t x, uint16_t y, bool inverted) { | ||
| uint16_t tile_location = y * self->width_in_tiles + x; | ||
| self->inverts[tile_location] = inverted; | ||
| } | ||
|
|
||
| void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y) { | ||
| self->top_left_x = x; | ||
| self->top_left_y = y; | ||
|
|
@@ -484,6 +504,16 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, | |
| input_pixel.pixel = common_hal_displayio_ondiskbitmap_get_pixel(self->bitmap, input_pixel.tile_x, input_pixel.tile_y); | ||
| } | ||
|
|
||
| if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type) && common_hal_displayio_palette_get_len(self->pixel_shader) == 2) { | ||
| if (self->inverts[tile_location]) { | ||
| if (input_pixel.pixel == 0) { | ||
| input_pixel.pixel = 1; | ||
| } else if (input_pixel.pixel == 1) { | ||
| input_pixel.pixel = 0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| output_pixel.opaque = true; | ||
| if (self->pixel_shader == mp_const_none) { | ||
| output_pixel.pixel = input_pixel.pixel; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -225,6 +225,7 @@ def _load_row(self, y, row): | |||||
| .top_left_x = {0}, | ||||||
| .top_left_y = {0}, | ||||||
| .tiles = 0, | ||||||
| .inverts = false, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| .partial_change = false, | ||||||
| .full_change = false, | ||||||
| .hidden = false, | ||||||
|
|
@@ -275,6 +276,7 @@ def _load_row(self, y, row): | |||||
| .tile_width = {1}, | ||||||
| .tile_height = {2}, | ||||||
| .tiles = NULL, | ||||||
| .inverts = NULL, | ||||||
| .partial_change = false, | ||||||
| .full_change = false, | ||||||
| .hidden = false, | ||||||
|
|
@@ -303,6 +305,7 @@ def _load_row(self, y, row): | |||||
| .tile_width = {1}, | ||||||
| .tile_height = {2}, | ||||||
| .tiles = NULL, | ||||||
| .inverts = NULL, | ||||||
| .partial_change = false, | ||||||
| .full_change = false, | ||||||
| .hidden = false, | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will allocate one byte per tile. It may save some code size to do so but it'll leave 7 unused bits.