Skip to content

Commit

Permalink
[python/kandinsky] Allow selecting italic font for draw_string using …
Browse files Browse the repository at this point in the history
…7th argument
  • Loading branch information
Yaya-Cout committed Jun 27, 2023
1 parent 4630052 commit 6976e52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion python/port/mod/kandinsky/modkandinsky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ mp_obj_t modkandinsky_draw_string(size_t n_args, const mp_obj_t * args) {
KDPoint point(mp_obj_get_int(args[1]), mp_obj_get_int(args[2]));
KDColor textColor = (n_args >= 4) ? MicroPython::Color::Parse(args[3]) : Palette::PrimaryText;
KDColor backgroundColor = (n_args >= 5) ? MicroPython::Color::Parse(args[4]) : Palette::HomeBackground;
const KDFont * font = (n_args >= 6) ? ((mp_obj_is_true(args[5])) ? KDFont::SmallFont : KDFont::LargeFont) : KDFont::LargeFont;
bool bigFont = (n_args >= 6) ? mp_obj_is_true(args[5]) : false;
bool isItalic = (n_args >= 7) ? mp_obj_is_true(args[6]) : false;
const KDFont * font = KDFont::LargeFont;
if (bigFont && !isItalic) {
font = KDFont::LargeFont;
} else if (!bigFont && !isItalic) {
font = KDFont::SmallFont;
} else if (bigFont && isItalic) {
font = KDFont::ItalicLargeFont;
} else if (!bigFont && isItalic) {
font = KDFont::ItalicSmallFont;
}
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
KDIonContext::sharedContext()->drawString(text, point, font, textColor, backgroundColor);
return mp_const_none;
Expand Down
2 changes: 1 addition & 1 deletion python/port/mod/kandinsky/modkandinsky_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_color_obj, 1, 3, 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_VAR_BETWEEN(modkandinsky_draw_string_obj, 3, 6, modkandinsky_draw_string);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_string_obj, 3, 7, modkandinsky_draw_string);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_line_obj, 5, 5, modkandinsky_draw_line);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_circle_obj, 4, 4, modkandinsky_draw_circle);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_rect_obj, 5, 5, modkandinsky_fill_rect);
Expand Down

0 comments on commit 6976e52

Please sign in to comment.