PicoGraphics: Expose line thickness support.

This commit is contained in:
Phil Howard 2023-03-08 12:08:47 +00:00
parent cacb5749ae
commit aed14aca22
2 changed files with 19 additions and 8 deletions

View File

@ -37,7 +37,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(ModPicoGraphics_text_obj, 1, ModPicoGraphics_text);
MP_DEFINE_CONST_FUN_OBJ_KW(ModPicoGraphics_measure_text_obj, 1, ModPicoGraphics_measure_text);
MP_DEFINE_CONST_FUN_OBJ_KW(ModPicoGraphics_polygon_obj, 2, ModPicoGraphics_polygon);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_triangle_obj, 7, 7, ModPicoGraphics_triangle);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_line_obj, 5, 5, ModPicoGraphics_line);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ModPicoGraphics_line_obj, 5, 6, ModPicoGraphics_line);
// Sprites
MP_DEFINE_CONST_FUN_OBJ_2(ModPicoGraphics_set_spritesheet_obj, ModPicoGraphics_set_spritesheet);

View File

@ -1046,16 +1046,27 @@ mp_obj_t ModPicoGraphics_triangle(size_t n_args, const mp_obj_t *args) {
}
mp_obj_t ModPicoGraphics_line(size_t n_args, const mp_obj_t *args) {
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2 };
enum { ARG_self, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_thickness };
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self], ModPicoGraphics_obj_t);
self->graphics->line(
{mp_obj_get_int(args[ARG_x1]),
mp_obj_get_int(args[ARG_y1])},
{mp_obj_get_int(args[ARG_x2]),
mp_obj_get_int(args[ARG_y2])}
);
if(n_args == 5) {
self->graphics->line(
{mp_obj_get_int(args[ARG_x1]),
mp_obj_get_int(args[ARG_y1])},
{mp_obj_get_int(args[ARG_x2]),
mp_obj_get_int(args[ARG_y2])}
);
}
else if(n_args == 6) {
self->graphics->thick_line(
{mp_obj_get_int(args[ARG_x1]),
mp_obj_get_int(args[ARG_y1])},
{mp_obj_get_int(args[ARG_x2]),
mp_obj_get_int(args[ARG_y2])},
mp_obj_get_int(args[ARG_thickness])
);
}
return mp_const_none;
}