Accept x and y kwargs into Group for initial position.

This commit is contained in:
Scott Shawcroft 2019-03-12 14:39:46 -07:00
parent 2169a62409
commit ea45877ca5
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59
4 changed files with 14 additions and 10 deletions

View File

@ -41,19 +41,23 @@
//|
//| Manage a group of sprites and groups and how they are inter-related.
//|
//| .. class:: Group(*, max_size=4, scale=1)
//| .. class:: Group(*, max_size=4, scale=1, x=0, y=0)
//|
//| Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2
//| leads to a layer's pixel being 2x2 pixels when in the group.
//|
//| :param int max_size: The maximum group size.
//| :param int scale: Scale of layer pixels in one dimension.
//| :param int x: Initial x position within the parent.
//| :param int y: Initial y position within the parent.
//|
STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_max_size, ARG_scale };
enum { ARG_max_size, ARG_scale, ARG_x, ARG_y };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_max_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 4} },
{ MP_QSTR_scale, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
{ MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -70,7 +74,7 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg
displayio_group_t *self = m_new_obj(displayio_group_t);
self->base.type = &displayio_group_type;
common_hal_displayio_group_construct(self, max_size, scale);
common_hal_displayio_group_construct(self, max_size, scale, args[ARG_x].u_int, args[ARG_y].u_int);
return MP_OBJ_FROM_PTR(self);
}

View File

@ -32,7 +32,7 @@
extern const mp_obj_type_t displayio_group_type;
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale);
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);
mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self);

View File

@ -29,9 +29,9 @@
#include "py/runtime.h"
#include "shared-bindings/displayio/TileGrid.h"
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale) {
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) {
displayio_group_child_t* children = m_new(displayio_group_child_t, max_size);
displayio_group_construct(self, children, max_size, scale);
displayio_group_construct(self, children, max_size, scale, x, y);
}
uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) {
@ -116,9 +116,9 @@ void common_hal_displayio_group_set(displayio_group_t* self, size_t index, mp_ob
self->needs_refresh = true;
}
void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale) {
self->x = 0;
self->y = 0;
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) {
self->x = x;
self->y = y;
self->children = child_array;
self->max_size = max_size;
self->needs_refresh = false;

View File

@ -48,7 +48,7 @@ typedef struct {
bool needs_refresh;
} displayio_group_t;
void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale);
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);
bool displayio_group_get_pixel(displayio_group_t *group, int16_t x, int16_t y, uint16_t *pixel);
bool displayio_group_needs_refresh(displayio_group_t *self);
void displayio_group_finish_refresh(displayio_group_t *self);