Skip to content

Add .hidden to TileGrid and Group #2113

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 3 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ports/atmel-samd/boards/ugame10/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ CIRCUITPY_ANALOGIO = 1
CIRCUITPY_GAMEPAD = 1
CIRCUITPY_DISPLAYIO = 1

CIRCUITPY_TOUCHIO = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_RTC = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_USB_MIDI = 0

FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/ugame10

Expand Down
27 changes: 27 additions & 0 deletions shared-bindings/displayio/Group.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ displayio_group_t* native_group(mp_obj_t group_obj) {
return MP_OBJ_TO_PTR(native_group);
}

//| .. attribute:: hidden
//|
//| True when the Group and all of it's layers are not visible. When False, the Group's layers
//| are visible if they haven't been hidden.
//|
STATIC mp_obj_t displayio_group_obj_get_hidden(mp_obj_t self_in) {
displayio_group_t *self = native_group(self_in);
return mp_obj_new_bool(common_hal_displayio_group_get_hidden(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_group_get_hidden_obj, displayio_group_obj_get_hidden);

STATIC mp_obj_t displayio_group_obj_set_hidden(mp_obj_t self_in, mp_obj_t hidden_obj) {
displayio_group_t *self = native_group(self_in);

common_hal_displayio_group_set_hidden(self, mp_obj_is_true(hidden_obj));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_set_hidden_obj, displayio_group_obj_set_hidden);

const mp_obj_property_t displayio_group_hidden_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_group_get_hidden_obj,
(mp_obj_t)&displayio_group_set_hidden_obj,
(mp_obj_t)&mp_const_none_obj},
};

//| .. attribute:: scale
//|
//| Scales each pixel within the Group in both directions. For example, when scale=2 each pixel
Expand Down Expand Up @@ -305,6 +331,7 @@ STATIC mp_obj_t group_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t valu
}

STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&displayio_group_hidden_obj) },
{ MP_ROM_QSTR(MP_QSTR_scale), MP_ROM_PTR(&displayio_group_scale_obj) },
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&displayio_group_x_obj) },
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&displayio_group_y_obj) },
Expand Down
2 changes: 2 additions & 0 deletions shared-bindings/displayio/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ displayio_group_t* native_group(mp_obj_t group_obj);
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y);
uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self);
void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale);
bool common_hal_displayio_group_get_hidden(displayio_group_t* self);
void common_hal_displayio_group_set_hidden(displayio_group_t* self, bool hidden);
mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self);
void common_hal_displayio_group_set_x(displayio_group_t* self, mp_int_t x);
mp_int_t common_hal_displayio_group_get_y(displayio_group_t* self);
Expand Down
25 changes: 25 additions & 0 deletions shared-bindings/displayio/TileGrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ static displayio_tilegrid_t* native_tilegrid(mp_obj_t tilegrid_obj) {
mp_obj_assert_native_inited(native_tilegrid);
return MP_OBJ_TO_PTR(native_tilegrid);
}
//| .. attribute:: hidden
//|
//| True when the TileGrid is hidden. This may be False even when a part of a hidden Group.
//|
STATIC mp_obj_t displayio_tilegrid_obj_get_hidden(mp_obj_t self_in) {
displayio_tilegrid_t *self = native_tilegrid(self_in);
return mp_obj_new_bool(common_hal_displayio_tilegrid_get_hidden(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_hidden_obj, displayio_tilegrid_obj_get_hidden);

STATIC mp_obj_t displayio_tilegrid_obj_set_hidden(mp_obj_t self_in, mp_obj_t hidden_obj) {
displayio_tilegrid_t *self = native_tilegrid(self_in);

common_hal_displayio_tilegrid_set_hidden(self, mp_obj_is_true(hidden_obj));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_hidden_obj, displayio_tilegrid_obj_set_hidden);

const mp_obj_property_t displayio_tilegrid_hidden_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_tilegrid_get_hidden_obj,
(mp_obj_t)&displayio_tilegrid_set_hidden_obj,
(mp_obj_t)&mp_const_none_obj},
};

//| .. attribute:: x
//|
Expand Down Expand Up @@ -368,6 +392,7 @@ STATIC mp_obj_t tilegrid_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t v

STATIC const mp_rom_map_elem_t displayio_tilegrid_locals_dict_table[] = {
// Properties
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&displayio_tilegrid_hidden_obj) },
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&displayio_tilegrid_x_obj) },
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&displayio_tilegrid_y_obj) },
{ MP_ROM_QSTR(MP_QSTR_flip_x), MP_ROM_PTR(&displayio_tilegrid_flip_x_obj) },
Expand Down
2 changes: 2 additions & 0 deletions shared-bindings/displayio/TileGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ 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);

bool common_hal_displayio_tilegrid_get_hidden(displayio_tilegrid_t* self);
void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t* self, bool hidden);
mp_int_t common_hal_displayio_tilegrid_get_x(displayio_tilegrid_t *self);
void common_hal_displayio_tilegrid_set_x(displayio_tilegrid_t *self, mp_int_t x);
mp_int_t common_hal_displayio_tilegrid_get_y(displayio_tilegrid_t *self);
Expand Down
1 change: 0 additions & 1 deletion shared-bindings/displayio/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ typedef enum {
DISPLAY_DATA
} display_byte_type_t;


typedef enum {
CHIP_SELECT_UNTOUCHED,
CHIP_SELECT_TOGGLE_EVERY_BYTE
Expand Down
4 changes: 3 additions & 1 deletion shared-module/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin,
uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second) {
// Turn off auto-refresh as we init.
self->auto_refresh = false;
uint16_t ram_width = 0x100;
uint16_t ram_height = 0x100;
if (single_byte_bounds) {
Expand All @@ -64,7 +66,6 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
self->write_ram_command = write_ram_command;
self->brightness_command = brightness_command;
self->auto_brightness = auto_brightness;
self->auto_refresh = auto_refresh;
self->first_manual_refresh = !auto_refresh;
self->data_as_commands = data_as_commands;

Expand Down Expand Up @@ -128,6 +129,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
// Set the group after initialization otherwise we may send pixels while we delay in
// initialization.
common_hal_displayio_display_show(self, &circuitpython_splash);
self->auto_refresh = auto_refresh;
}

bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
Expand Down
41 changes: 41 additions & 0 deletions shared-module/displayio/Group.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,47 @@ void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_
displayio_group_construct(self, children, max_size, scale, x, y);
}

bool common_hal_displayio_group_get_hidden(displayio_group_t* self) {
return self->hidden;
}

void common_hal_displayio_group_set_hidden(displayio_group_t* self, bool hidden) {
if (self->hidden == hidden) {
return;
}
self->hidden = hidden;
if (self->hidden_by_parent) {
return;
}
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_set_hidden_by_parent(layer, hidden);
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {
displayio_group_set_hidden_by_parent(layer, hidden);
}
}
}

void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden) {
if (self->hidden_by_parent == hidden) {
return;
}
self->hidden_by_parent = hidden;
// If we're already hidden, then we're done.
if (self->hidden) {
return;
}
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_set_hidden_by_parent(layer, hidden);
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {
displayio_group_set_hidden_by_parent(layer, hidden);
}
}
}

uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) {
return self->scale;
}
Expand Down
12 changes: 8 additions & 4 deletions shared-module/displayio/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ typedef struct {
typedef struct {
mp_obj_base_t base;
displayio_group_child_t* children;
displayio_buffer_transform_t absolute_transform;
displayio_area_t dirty_area; // Catch all for changed area
int16_t x;
int16_t y;
uint16_t scale;
uint16_t size;
uint16_t max_size;
bool item_removed;
bool in_group;
displayio_buffer_transform_t absolute_transform;
displayio_area_t dirty_area; // Catch all for changed area
bool item_removed :1;
bool in_group :1;
bool hidden :1;
bool hidden_by_parent :1;
uint8_t padding :4;
} displayio_group_t;

void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y);
void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden);
bool displayio_group_get_previous_area(displayio_group_t *group, displayio_area_t* area);
bool displayio_group_fill_area(displayio_group_t *group, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer);
void displayio_group_update_transform(displayio_group_t *group, const displayio_buffer_transform_t* parent_transform);
Expand Down
2 changes: 1 addition & 1 deletion shared-module/displayio/I2CDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool common_hal_displayio_i2cdisplay_bus_free(mp_obj_t obj) {

bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t obj) {
displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
return !common_hal_busio_i2c_try_lock(self->bus);
return common_hal_busio_i2c_try_lock(self->bus);
}

void common_hal_displayio_i2cdisplay_send(mp_obj_t obj, display_byte_type_t data_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
Expand Down
54 changes: 43 additions & 11 deletions shared-module/displayio/TileGrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,30 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_
self->bitmap = bitmap;
self->pixel_shader = pixel_shader;
self->in_group = false;
self->first_draw = true;
self->hidden = false;
self->hidden_by_parent = false;
self->previous_area.x1 = 0xffff;
self->previous_area.x2 = self->previous_area.x1;
self->flip_x = false;
self->flip_y = false;
self->transpose_xy = false;
}


bool common_hal_displayio_tilegrid_get_hidden(displayio_tilegrid_t* self) {
return self->hidden;
}

void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t* self, bool hidden) {
self->hidden = hidden;
}

void displayio_tilegrid_set_hidden_by_parent(displayio_tilegrid_t *self, bool hidden) {
self->hidden_by_parent = hidden;
}

bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t* area) {
if (self->first_draw) {
if (self->previous_area.x1 == self->previous_area.x2) {
return false;
}
displayio_area_copy(&self->previous_area, area);
Expand Down Expand Up @@ -138,12 +154,10 @@ void displayio_tilegrid_update_transform(displayio_tilegrid_t *self,
self->in_group = absolute_transform != NULL;
self->absolute_transform = absolute_transform;
if (absolute_transform != NULL) {
self->moved = !self->first_draw;
self->moved = true;

_update_current_x(self);
_update_current_y(self);
} else {
self->first_draw = true;
}
}

Expand All @@ -155,7 +169,7 @@ void common_hal_displayio_tilegrid_set_x(displayio_tilegrid_t *self, mp_int_t x)
return;
}

self->moved = !self->first_draw;
self->moved = true;

self->x = x;
if (self->absolute_transform != NULL) {
Expand All @@ -170,7 +184,7 @@ void common_hal_displayio_tilegrid_set_y(displayio_tilegrid_t *self, mp_int_t y)
if (self->y == y) {
return;
}
self->moved = !self->first_draw;
self->moved = true;
self->y = y;
if (self->absolute_transform != NULL) {
_update_current_y(self);
Expand Down Expand Up @@ -306,6 +320,11 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
return false;
}

bool hidden = self->hidden || self->hidden_by_parent;
if (hidden) {
return false;
}

displayio_area_t overlap;
if (!displayio_area_compute_overlap(area, &self->current_area, &overlap)) {
return false;
Expand Down Expand Up @@ -455,14 +474,17 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
}

void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) {
if (self->moved || self->first_draw) {
bool first_draw = self->previous_area.x1 == self->previous_area.x2;
bool hidden = self->hidden || self->hidden_by_parent;
if (!first_draw && hidden) {
self->previous_area.x2 = self->previous_area.x1;
} else if (self->moved || first_draw) {
displayio_area_copy(&self->current_area, &self->previous_area);
}

self->moved = false;
self->full_change = false;
self->partial_change = false;
self->first_draw = false;
if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type)) {
displayio_palette_finish_refresh(self->pixel_shader);
} else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type)) {
Expand All @@ -481,7 +503,17 @@ void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) {
}

displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t* tail) {
if (self->moved && !self->first_draw) {
bool first_draw = self->previous_area.x1 == self->previous_area.x2;
bool hidden = self->hidden || self->hidden_by_parent;
// Check hidden first because it trumps all other changes.
if (hidden) {
if (!first_draw) {
self->previous_area.next = tail;
return &self->previous_area;
} else {
return tail;
}
} else if (self->moved && !first_draw) {
displayio_area_union(&self->previous_area, &self->current_area, &self->dirty_area);
if (displayio_area_size(&self->dirty_area) <= 2U * self->pixel_width * self->pixel_height) {
self->dirty_area.next = tail;
Expand Down Expand Up @@ -512,7 +544,7 @@ displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *sel
displayio_palette_needs_refresh(self->pixel_shader)) ||
(MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type) &&
displayio_colorconverter_needs_refresh(self->pixel_shader));
if (self->full_change || self->first_draw) {
if (self->full_change || first_draw) {
self->current_area.next = tail;
return &self->current_area;
}
Expand Down
22 changes: 13 additions & 9 deletions shared-module/displayio/TileGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ typedef struct {
displayio_area_t dirty_area; // Stored as a relative area until the refresh area is fetched.
displayio_area_t previous_area; // Stored as an absolute area.
displayio_area_t current_area; // Stored as an absolute area so it applies across frames.
bool partial_change;
bool full_change;
bool first_draw;
bool moved;
bool inline_tiles;
bool in_group;
bool flip_x;
bool flip_y;
bool transpose_xy;
bool partial_change :1;
bool full_change :1;
bool moved :1;
bool inline_tiles :1;
bool in_group :1;
bool flip_x :1;
bool flip_y :1;
bool transpose_xy :1;
bool hidden :1;
bool hidden_by_parent :1;
uint8_t padding :6;
} displayio_tilegrid_t;

void displayio_tilegrid_set_hidden_by_parent(displayio_tilegrid_t *self, bool hidden);

// Updating the screen is a three stage process.

// The first stage is used to determine i
Expand Down
Loading