Skip to content

Commit

Permalink
[python/kandinsky] Expose the fill_rect method
Browse files Browse the repository at this point in the history
Which allows for *much* faster graphics
  • Loading branch information
Ecco authored and EmilieNumworks committed Apr 26, 2019
1 parent bb89ae9 commit 926b96c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/port/genhdr/qstrdefs.in.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ QCFG(BYTES_IN_HASH, (2))
Q(kandinsky)
Q(color)
Q(draw_string)
Q(fill_rect)
Q(get_pixel)
Q(set_pixel)

Expand Down
13 changes: 13 additions & 0 deletions python/port/mod/kandinsky/modkandinsky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,16 @@ mp_obj_t modkandinsky_draw_string(mp_obj_t text, mp_obj_t x, mp_obj_t y) {
return mp_const_none;
}

mp_obj_t modkandinsky_fill_rect(size_t n_args, const mp_obj_t * args) {
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
KDIonContext::sharedContext()->fillRect(
KDRect(
mp_obj_get_int(args[0]),
mp_obj_get_int(args[1]),
mp_obj_get_int(args[2]),
mp_obj_get_int(args[3])
),
ColorForTuple(args[4])
);
return mp_const_none;
}
1 change: 1 addition & 0 deletions python/port/mod/kandinsky/modkandinsky.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mp_obj_t modkandinsky_color(mp_obj_t red, mp_obj_t green, mp_obj_t blue);
mp_obj_t modkandinsky_get_pixel(mp_obj_t x, mp_obj_t y);
mp_obj_t modkandinsky_set_pixel(mp_obj_t x, mp_obj_t y, mp_obj_t color);
mp_obj_t modkandinsky_draw_string(mp_obj_t text, mp_obj_t x, mp_obj_t y);
mp_obj_t modkandinsky_fill_rect(size_t n_args, const mp_obj_t *args);
2 changes: 2 additions & 0 deletions python/port/mod/kandinsky/modkandinsky_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(modkandinsky_color_obj, modkandinsky_color);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(modkandinsky_get_pixel_obj, modkandinsky_get_pixel);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(modkandinsky_set_pixel_obj, modkandinsky_set_pixel);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(modkandinsky_draw_string_obj, modkandinsky_draw_string);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_rect_obj, 5, 5, modkandinsky_fill_rect);

STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_kandinsky) },
{ MP_ROM_QSTR(MP_QSTR_color), (mp_obj_t)&modkandinsky_color_obj },
{ MP_ROM_QSTR(MP_QSTR_get_pixel), (mp_obj_t)&modkandinsky_get_pixel_obj },
{ MP_ROM_QSTR(MP_QSTR_set_pixel), (mp_obj_t)&modkandinsky_set_pixel_obj },
{ MP_ROM_QSTR(MP_QSTR_draw_string), (mp_obj_t)&modkandinsky_draw_string_obj },
{ MP_ROM_QSTR(MP_QSTR_fill_rect), (mp_obj_t)&modkandinsky_fill_rect_obj },
};

STATIC MP_DEFINE_CONST_DICT(modkandinsky_module_globals, modkandinsky_module_globals_table);
Expand Down

0 comments on commit 926b96c

Please sign in to comment.