|
|
|
@ -21,6 +21,9 @@
|
|
|
|
|
|
|
|
|
|
#include "display.h"
|
|
|
|
|
|
|
|
|
|
#define FONT_PY_TO_C(f) (-(f))
|
|
|
|
|
#define FONT_C_TO_PY(f) (-(f))
|
|
|
|
|
|
|
|
|
|
/// class Display:
|
|
|
|
|
/// '''
|
|
|
|
|
/// Provide access to device display.
|
|
|
|
@ -194,17 +197,19 @@ STATIC mp_obj_t mod_trezorui_Display_print(mp_obj_t self, mp_obj_t text) {
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_print_obj, mod_trezorui_Display_print);
|
|
|
|
|
|
|
|
|
|
/// def text(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> None:
|
|
|
|
|
/// def text(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int:
|
|
|
|
|
/// '''
|
|
|
|
|
/// Renders left-aligned text at position (x,y) where x is left position and y is baseline.
|
|
|
|
|
/// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background.
|
|
|
|
|
/// Fills at least minwidth pixels with bgcolor.
|
|
|
|
|
/// Returns width of rendered text in pixels.
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
|
|
|
|
|
mp_int_t x = mp_obj_get_int(args[1]);
|
|
|
|
|
mp_int_t y = mp_obj_get_int(args[2]);
|
|
|
|
|
mp_buffer_info_t text;
|
|
|
|
|
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
|
|
|
|
mp_int_t font = mp_obj_get_int(args[4]);
|
|
|
|
|
mp_int_t font = FONT_PY_TO_C(mp_obj_get_int(args[4]));
|
|
|
|
|
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
|
|
|
|
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
|
|
|
|
mp_int_t minwidth = (n_args > 7) ? mp_obj_get_int(args[7]) : 0;
|
|
|
|
@ -214,21 +219,23 @@ STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
|
|
|
|
|
display_bar(x, y - 18, barwidth, 23, bgcolor);
|
|
|
|
|
// prefill end
|
|
|
|
|
display_text(x, y, text.buf, text.len, font, fgcolor, bgcolor);
|
|
|
|
|
return mp_const_none;
|
|
|
|
|
return mp_obj_new_int(w);
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 8, mod_trezorui_Display_text);
|
|
|
|
|
|
|
|
|
|
/// def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> None:
|
|
|
|
|
/// def text_center(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int:
|
|
|
|
|
/// '''
|
|
|
|
|
/// Renders text centered at position (x,y) where x is text center and y is baseline.
|
|
|
|
|
/// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background.
|
|
|
|
|
/// Fills at least minwidth pixels with bgcolor.
|
|
|
|
|
/// Returns width of rendered text in pixels.
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args, const mp_obj_t *args) {
|
|
|
|
|
mp_int_t x = mp_obj_get_int(args[1]);
|
|
|
|
|
mp_int_t y = mp_obj_get_int(args[2]);
|
|
|
|
|
mp_buffer_info_t text;
|
|
|
|
|
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
|
|
|
|
mp_int_t font = mp_obj_get_int(args[4]);
|
|
|
|
|
mp_int_t font = FONT_PY_TO_C(mp_obj_get_int(args[4]));
|
|
|
|
|
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
|
|
|
|
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
|
|
|
|
mp_int_t minwidth = (n_args > 7) ? mp_obj_get_int(args[7]) : 0;
|
|
|
|
@ -238,21 +245,23 @@ STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args, const mp_obj_t *
|
|
|
|
|
display_bar(x - barwidth / 2, y - 18, barwidth, 23, bgcolor);
|
|
|
|
|
// prefill end
|
|
|
|
|
display_text_center(x, y, text.buf, text.len, font, fgcolor, bgcolor);
|
|
|
|
|
return mp_const_none;
|
|
|
|
|
return mp_obj_new_int(w);
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_center_obj, 7, 8, mod_trezorui_Display_text_center);
|
|
|
|
|
|
|
|
|
|
/// def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> None:
|
|
|
|
|
/// def text_right(self, x: int, y: int, text: str, font: int, fgcolor: int, bgcolor: int, minwidth: int=None) -> int:
|
|
|
|
|
/// '''
|
|
|
|
|
/// Renders right-aligned text at position (x,y) where x is right position and y is baseline.
|
|
|
|
|
/// Font font is used for rendering, fgcolor is used as foreground color, bgcolor as background.
|
|
|
|
|
/// Fills at least minwidth pixels with bgcolor.
|
|
|
|
|
/// Returns width of rendered text in pixels.
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args, const mp_obj_t *args) {
|
|
|
|
|
mp_int_t x = mp_obj_get_int(args[1]);
|
|
|
|
|
mp_int_t y = mp_obj_get_int(args[2]);
|
|
|
|
|
mp_buffer_info_t text;
|
|
|
|
|
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
|
|
|
|
mp_int_t font = mp_obj_get_int(args[4]);
|
|
|
|
|
mp_int_t font = FONT_PY_TO_C(mp_obj_get_int(args[4]));
|
|
|
|
|
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
|
|
|
|
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
|
|
|
|
mp_int_t minwidth = (n_args > 7) ? mp_obj_get_int(args[7]) : 0;
|
|
|
|
@ -262,7 +271,7 @@ STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args, const mp_obj_t *a
|
|
|
|
|
display_bar(x - barwidth, y - 18, barwidth, 23, bgcolor);
|
|
|
|
|
// prefill end
|
|
|
|
|
display_text_right(x, y, text.buf, text.len, font, fgcolor, bgcolor);
|
|
|
|
|
return mp_const_none;
|
|
|
|
|
return mp_obj_new_int(w);
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj, 7, 8, mod_trezorui_Display_text_right);
|
|
|
|
|
|
|
|
|
@ -273,9 +282,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj,
|
|
|
|
|
STATIC mp_obj_t mod_trezorui_Display_text_width(mp_obj_t self, mp_obj_t text, mp_obj_t font) {
|
|
|
|
|
mp_buffer_info_t txt;
|
|
|
|
|
mp_get_buffer_raise(text, &txt, MP_BUFFER_READ);
|
|
|
|
|
mp_int_t f = mp_obj_get_int(font);
|
|
|
|
|
mp_int_t f = FONT_PY_TO_C(mp_obj_get_int(font));
|
|
|
|
|
int w = display_text_width(txt.buf, txt.len, f);
|
|
|
|
|
return MP_OBJ_NEW_SMALL_INT(w);
|
|
|
|
|
return mp_obj_new_int(w);
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorui_Display_text_width_obj, mod_trezorui_Display_text_width);
|
|
|
|
|
|
|
|
|
@ -450,9 +459,9 @@ STATIC const mp_rom_map_elem_t mod_trezorui_Display_locals_dict_table[] = {
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_OBJ_NEW_SMALL_INT(DISPLAY_RESX) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_OBJ_NEW_SMALL_INT(DISPLAY_RESY) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_FONT_SIZE), MP_OBJ_NEW_SMALL_INT(FONT_SIZE) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO), MP_OBJ_NEW_SMALL_INT(FONT_MONO) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_FONT_NORMAL), MP_OBJ_NEW_SMALL_INT(FONT_NORMAL) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_FONT_BOLD), MP_OBJ_NEW_SMALL_INT(FONT_BOLD) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO), MP_OBJ_NEW_SMALL_INT(FONT_C_TO_PY(FONT_MONO)) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_FONT_NORMAL), MP_OBJ_NEW_SMALL_INT(FONT_C_TO_PY(FONT_NORMAL)) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_FONT_BOLD), MP_OBJ_NEW_SMALL_INT(FONT_C_TO_PY(FONT_BOLD)) },
|
|
|
|
|
};
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(mod_trezorui_Display_locals_dict, mod_trezorui_Display_locals_dict_table);
|
|
|
|
|
|
|
|
|
|