Minor tweaks based on Dan's feedback

This commit is contained in:
Scott Shawcroft 2019-06-13 00:34:19 -07:00
parent d2ec43113e
commit 6f6dcafd90
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59
4 changed files with 27 additions and 41 deletions

View File

@ -249,8 +249,8 @@ const mp_obj_property_t displayio_tilegrid_flip_y_obj = {
//| .. attribute:: transpose_xy
//|
//| If true, the TileGrid will be rotate 90 degrees. When combined with mirroring any 90 degree
//| rotation can be achieved.
//| If true, the TileGrid's axis will be swapped. When combined with mirroring, any 90 degree
//| rotation can be achieved along with the corresponding mirrored version.
//|
STATIC mp_obj_t displayio_tilegrid_obj_get_transpose_xy(mp_obj_t self_in) {
displayio_tilegrid_t *self = native_tilegrid(self_in);

View File

@ -354,4 +354,4 @@ bool displayio_display_fill_area(displayio_display_obj_t *self, displayio_area_t
bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_area_t* area, displayio_area_t* clipped) {
return displayio_area_compute_overlap(&self->area, area, clipped);
}
}

View File

@ -40,7 +40,7 @@ uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) {
bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t* area) {
bool first = true;
for (int32_t i = 0; i < self->size; i++) {
for (size_t i = 0; i < self->size; i++) {
mp_obj_t layer = self->children[i].native;
displayio_area_t layer_area;
if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) {
@ -74,7 +74,7 @@ static void _update_child_transforms(displayio_group_t* self) {
if (!self->in_group) {
return;
}
for (int32_t i = 0; i < self->size; i++) {
for (size_t i = 0; i < self->size; i++) {
mp_obj_t layer = self->children[i].native;
if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) {
displayio_tilegrid_update_transform(layer, &self->absolute_transform);
@ -128,10 +128,10 @@ void common_hal_displayio_group_set_x(displayio_group_t* self, mp_int_t x) {
return;
}
if (self->absolute_transform.transpose_xy) {
int8_t dy = self->absolute_transform.dy / self->scale;
int16_t dy = self->absolute_transform.dy / self->scale;
self->absolute_transform.y += dy * (x - self->x);
} else {
int8_t dx = self->absolute_transform.dx / self->scale;
int16_t dx = self->absolute_transform.dx / self->scale;
self->absolute_transform.x += dx * (x - self->x);
}

View File

@ -80,13 +80,15 @@ bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_
}
void _update_current_x(displayio_tilegrid_t *self) {
int16_t width;
if (self->transpose_xy) {
width = self->pixel_height;
} else {
width = self->pixel_width;
}
if (self->absolute_transform->transpose_xy) {
self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->x;
if (self->transpose_xy) {
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + self->pixel_height);
} else {
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + self->pixel_width);
}
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + width);
if (self->current_area.y2 < self->current_area.y1) {
int16_t temp = self->current_area.y2;
self->current_area.y2 = self->current_area.y1;
@ -94,11 +96,7 @@ void _update_current_x(displayio_tilegrid_t *self) {
}
} else {
self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->x;
if (self->transpose_xy) {
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->pixel_height);
} else {
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->pixel_width);
}
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + width);
if (self->current_area.x2 < self->current_area.x1) {
int16_t temp = self->current_area.x2;
self->current_area.x2 = self->current_area.x1;
@ -108,13 +106,15 @@ void _update_current_x(displayio_tilegrid_t *self) {
}
void _update_current_y(displayio_tilegrid_t *self) {
int16_t height;
if (self->transpose_xy) {
height = self->pixel_width;
} else {
height = self->pixel_height;
}
if (self->absolute_transform->transpose_xy) {
self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->y;
if (self->transpose_xy) {
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->pixel_width);
} else {
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->pixel_height);
}
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + height);
if (self->current_area.x2 < self->current_area.x1) {
int16_t temp = self->current_area.x2;
self->current_area.x2 = self->current_area.x1;
@ -122,11 +122,7 @@ void _update_current_y(displayio_tilegrid_t *self) {
}
} else {
self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->y;
if (self->transpose_xy) {
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->pixel_width);
} else {
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->pixel_height);
}
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + height);
if (self->current_area.y2 < self->current_area.y1) {
int16_t temp = self->current_area.y2;
self->current_area.y2 = self->current_area.y1;
@ -315,22 +311,12 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_ar
// How many pixels are outside of our area between us and the start of the row.
uint16_t start = 0;
if ((self->absolute_transform->dx < 0) != flip_x) {
// if (self->absolute_transform->transpose_xy) {
// start += (area->y2 - area->y1 - 1) * y_stride;
// y_stride *= -1;
// } else {
start += (area->x2 - area->x1 - 1) * x_stride;
x_stride *= -1;
//}
start += (area->x2 - area->x1 - 1) * x_stride;
x_stride *= -1;
}
if ((self->absolute_transform->dy < 0) != flip_y) {
// if (self->absolute_transform->transpose_xy) {
// start += (area->x2 - area->x1 - 1) * x_stride;
// x_stride *= -1;
// } else {
start += (area->y2 - area->y1 - 1) * y_stride;
y_stride *= -1;
//}
start += (area->y2 - area->y1 - 1) * y_stride;
y_stride *= -1;
}
// Track if this layer finishes filling in the given area. We can ignore any remaining