-
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
Changes from all commits
2975057
22e5c46
b4910bf
f3725a5
99ff4ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" | |
| LONGINT_IMPL = MPZ | ||
|
|
||
| CIRCUITPY_JPEGIO = 0 | ||
| CIRCUITPY_RAINBOWIO = 0 | ||
| 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,12 @@ bool displayio_tilegrid_get_rendered_hidden(displayio_tilegrid_t *self) { | |||||||||||||||||
| return self->rendered_hidden; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| void displayio_tilegird_clear_inverts(displayio_tilegrid_t *self) { | ||||||||||||||||||
| for (uint32_t i = 0; i < self->width_in_tiles * self->height_in_tiles; i++) { | ||||||||||||||||||
| self->inverts[i] = false; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t *self, bool hidden) { | ||||||||||||||||||
| self->hidden = hidden; | ||||||||||||||||||
| self->rendered_hidden = false; | ||||||||||||||||||
|
|
@@ -355,6 +363,17 @@ 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; | ||||||||||||||||||
| common_hal_displayio_tilegrid_set_tile(self, x, y, common_hal_displayio_tilegrid_get_tile(self, x, y)); | ||||||||||||||||||
|
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. I'd rather you factor out the code to mark a tile area dirty so you can use it here. That way we can optimize set_tile to skip a dirty area when the tile index is set to the current value. |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| 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; | ||||||||||||||||||
|
|
@@ -488,6 +507,11 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, | |||||||||||||||||
| if (self->pixel_shader == mp_const_none) { | ||||||||||||||||||
| output_pixel.pixel = input_pixel.pixel; | ||||||||||||||||||
| } else if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { | ||||||||||||||||||
| if (common_hal_displayio_palette_get_len(self->pixel_shader) == 2) { | ||||||||||||||||||
| if (self->inverts[tile_location]) { | ||||||||||||||||||
| input_pixel.pixel = (input_pixel.pixel + 1) % 2; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+510
to
+514
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. What do you think about this? It'd do something for all palette sizes.
Suggested change
|
||||||||||||||||||
| displayio_palette_get_color(self->pixel_shader, colorspace, &input_pixel, &output_pixel); | ||||||||||||||||||
| } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { | ||||||||||||||||||
| displayio_colorconverter_convert(self->pixel_shader, colorspace, &input_pixel, &output_pixel); | ||||||||||||||||||
|
|
||||||||||||||||||
| 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, | ||||||
|
|
||||||
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.