2019-01-12 03:44:34 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shared-bindings/displayio/Shape.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "py/binary.h"
|
|
|
|
#include "py/objproperty.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "shared-bindings/util.h"
|
2022-05-27 15:59:54 -04:00
|
|
|
#include "supervisor/shared/translate/translate.h"
|
2019-01-12 03:44:34 -05:00
|
|
|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| class Shape:
|
2020-05-12 20:15:28 -04:00
|
|
|
//| """Represents a shape made by defining boundaries that may be mirrored."""
|
2019-01-12 03:44:34 -05:00
|
|
|
//|
|
2022-09-27 16:21:42 -04:00
|
|
|
//| def __init__(
|
|
|
|
//| self, width: int, height: int, *, mirror_x: bool = False, mirror_y: bool = False
|
|
|
|
//| ) -> None:
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Create a Shape object with the given fixed size. Each pixel is one bit and is stored by the
|
|
|
|
//| column boundaries of the shape on each row. Each row's boundary defaults to the full row.
|
2019-01-12 03:44:34 -05:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| :param int width: The number of pixels wide
|
|
|
|
//| :param int height: The number of pixels high
|
|
|
|
//| :param bool mirror_x: When true the left boundary is mirrored to the right.
|
|
|
|
//| :param bool mirror_y: When true the top boundary is mirrored to the bottom."""
|
|
|
|
//| ...
|
2021-10-15 14:43:12 -04:00
|
|
|
STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
2019-01-12 03:44:34 -05:00
|
|
|
enum { ARG_width, ARG_height, ARG_mirror_x, ARG_mirror_y };
|
|
|
|
static const mp_arg_t allowed_args[] = {
|
2019-01-14 20:26:36 -05:00
|
|
|
{ MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT },
|
|
|
|
{ MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_INT },
|
2019-01-12 03:44:34 -05:00
|
|
|
{ MP_QSTR_mirror_x, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
|
|
|
{ MP_QSTR_mirror_y, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
|
|
|
};
|
|
|
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
2021-10-15 14:43:12 -04:00
|
|
|
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
2019-01-12 03:44:34 -05:00
|
|
|
|
2022-05-13 15:33:43 -04:00
|
|
|
mp_int_t width = mp_arg_validate_int_min(args[ARG_width].u_int, 1, MP_QSTR_width);
|
|
|
|
mp_int_t height = mp_arg_validate_int_min(args[ARG_height].u_int, 1, MP_QSTR_height);
|
2019-02-13 20:34:39 -05:00
|
|
|
|
2019-01-12 03:44:34 -05:00
|
|
|
displayio_shape_t *self = m_new_obj(displayio_shape_t);
|
|
|
|
self->base.type = &displayio_shape_type;
|
|
|
|
common_hal_displayio_shape_construct(self,
|
2019-02-13 20:34:39 -05:00
|
|
|
width,
|
|
|
|
height,
|
2019-01-12 03:44:34 -05:00
|
|
|
args[ARG_mirror_x].u_bool,
|
|
|
|
args[ARG_mirror_y].u_bool);
|
|
|
|
|
|
|
|
return MP_OBJ_FROM_PTR(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-03 10:05:14 -04:00
|
|
|
//| def set_boundary(self, y: int, start_x: int, end_x: int) -> None:
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Loads pre-packed data into the given row."""
|
|
|
|
//| ...
|
2019-01-12 03:44:34 -05:00
|
|
|
STATIC mp_obj_t displayio_shape_obj_set_boundary(size_t n_args, const mp_obj_t *args) {
|
2021-03-15 09:57:36 -04:00
|
|
|
(void)n_args;
|
2019-01-12 03:44:34 -05:00
|
|
|
displayio_shape_t *self = MP_OBJ_TO_PTR(args[0]);
|
2022-06-23 09:36:22 -04:00
|
|
|
mp_int_t y = mp_arg_validate_type_int(args[1], MP_QSTR_y);
|
|
|
|
mp_int_t start_x = mp_arg_validate_type_int(args[1], MP_QSTR_start_x);
|
|
|
|
mp_int_t end_x = mp_arg_validate_type_int(args[1], MP_QSTR_end_x);
|
2019-01-12 03:44:34 -05:00
|
|
|
common_hal_displayio_shape_set_boundary(self, y, start_x, end_x);
|
|
|
|
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(displayio_shape_set_boundary_obj, 4, 4, displayio_shape_obj_set_boundary);
|
|
|
|
|
|
|
|
STATIC const mp_rom_map_elem_t displayio_shape_locals_dict_table[] = {
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_set_boundary), MP_ROM_PTR(&displayio_shape_set_boundary_obj) },
|
|
|
|
};
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(displayio_shape_locals_dict, displayio_shape_locals_dict_table);
|
|
|
|
|
|
|
|
const mp_obj_type_t displayio_shape_type = {
|
|
|
|
{ &mp_type_type },
|
|
|
|
.name = MP_QSTR_Shape,
|
|
|
|
.make_new = displayio_shape_make_new,
|
2021-03-15 09:57:36 -04:00
|
|
|
.locals_dict = (mp_obj_dict_t *)&displayio_shape_locals_dict,
|
2019-01-12 03:44:34 -05:00
|
|
|
};
|