mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
modtrezorui: add yoffset parameter to display.loader
This commit is contained in:
parent
fffe930d8c
commit
3067bfa003
@ -348,14 +348,18 @@ static void inflate_callback_loader(uint8_t byte, uint32_t pos, void *userdata)
|
||||
out[pos] = byte;
|
||||
}
|
||||
|
||||
void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor)
|
||||
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor)
|
||||
{
|
||||
uint16_t colortable[16], iconcolortable[16];
|
||||
set_color_table(colortable, fgcolor, bgcolor);
|
||||
if (icon) {
|
||||
set_color_table(iconcolortable, iconfgcolor, bgcolor);
|
||||
}
|
||||
display_set_window(DISPLAY_RESX / 2 - img_loader_size, DISPLAY_RESY / 2 - img_loader_size, DISPLAY_RESX / 2 + img_loader_size - 1, DISPLAY_RESY / 2 + img_loader_size - 1);
|
||||
if ((DISPLAY_RESY / 2 - img_loader_size + yoffset < 0) ||
|
||||
(DISPLAY_RESY / 2 + img_loader_size - 1 + yoffset >= DISPLAY_RESY)) {
|
||||
return;
|
||||
}
|
||||
display_set_window(DISPLAY_RESX / 2 - img_loader_size, DISPLAY_RESY / 2 - img_loader_size + yoffset, DISPLAY_RESX / 2 + img_loader_size - 1, DISPLAY_RESY / 2 + img_loader_size - 1 + yoffset);
|
||||
if (icon && memcmp(icon, "TOIg", 4) == 0 && LOADER_ICON_SIZE == *(uint16_t *)(icon + 4) && LOADER_ICON_SIZE == *(uint16_t *)(icon + 6) && iconlen == 12 + *(uint32_t *)(icon + 8)) {
|
||||
uint8_t icondata[LOADER_ICON_SIZE * LOADER_ICON_SIZE / 2];
|
||||
sinf_inflate(icon + 12, iconlen - 12, inflate_callback_loader, icondata);
|
||||
|
@ -34,7 +34,7 @@ void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint
|
||||
void display_image(int x, int y, int w, int h, const void *data, int datalen);
|
||||
void display_icon(int x, int y, int w, int h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale);
|
||||
void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
|
||||
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
|
||||
void display_text(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_text_center(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_text_right(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
|
@ -223,7 +223,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_qrcode(size_t n_args, const mp_obj_t *args)
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_qrcode_obj, 5, 5, mod_TrezorUi_Display_qrcode);
|
||||
|
||||
/// def trezor.ui.display.loader(progress: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None:
|
||||
/// def trezor.ui.display.loader(progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None:
|
||||
/// '''
|
||||
/// Renders a rotating loader graphic.
|
||||
/// Progress determines its position (0-1000), fgcolor is used as foreground color, bgcolor as background.
|
||||
@ -232,11 +232,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_qrcode_obj, 5, 5
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t progress = mp_obj_get_int(args[1]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[2]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[3]);
|
||||
if (n_args > 4) { // icon provided
|
||||
mp_int_t yoffset = mp_obj_get_int(args[2]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[3]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[4]);
|
||||
if (n_args > 5) { // icon provided
|
||||
mp_buffer_info_t icon;
|
||||
mp_get_buffer_raise(args[4], &icon, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(args[5], &icon, MP_BUFFER_READ);
|
||||
const uint8_t *data = icon.buf;
|
||||
if (icon.len < 8 || memcmp(data, "TOIg", 4) != 0) {
|
||||
mp_raise_ValueError("Invalid image format");
|
||||
@ -251,18 +252,18 @@ STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args)
|
||||
mp_raise_ValueError("Invalid size of data");
|
||||
}
|
||||
uint16_t iconfgcolor;
|
||||
if (n_args > 5) { // icon color provided
|
||||
iconfgcolor = mp_obj_get_int(args[5]);
|
||||
if (n_args > 6) { // icon color provided
|
||||
iconfgcolor = mp_obj_get_int(args[6]);
|
||||
} else {
|
||||
iconfgcolor = ~bgcolor; // invert
|
||||
}
|
||||
display_loader(progress, fgcolor, bgcolor, icon.buf, icon.len, iconfgcolor);
|
||||
display_loader(progress, yoffset, fgcolor, bgcolor, icon.buf, icon.len, iconfgcolor);
|
||||
} else {
|
||||
display_loader(progress, fgcolor, bgcolor, NULL, 0, 0);
|
||||
display_loader(progress, yoffset, fgcolor, bgcolor, NULL, 0, 0);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_loader_obj, 4, 6, mod_TrezorUi_Display_loader);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_loader_obj, 5, 7, mod_TrezorUi_Display_loader);
|
||||
|
||||
/// def trezor.ui.display.orientation(degrees: int=None) -> int:
|
||||
/// '''
|
||||
|
@ -73,7 +73,7 @@ def qrcode(x: int, y: int, data: bytes, scale: int) -> None:
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def loader(progress: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None:
|
||||
def loader(progress: int, yoffset: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None:
|
||||
'''
|
||||
Renders a rotating loader graphic.
|
||||
Progress determines its position (0-1000), fgcolor is used as foreground color, bgcolor as background.
|
||||
|
@ -47,12 +47,12 @@ class Loader():
|
||||
style = self.normal_style
|
||||
|
||||
if style['icon'] is None:
|
||||
ui.display.loader(progress, style['fg-color'], style['bg-color'])
|
||||
ui.display.loader(progress, -8, style['fg-color'], style['bg-color'])
|
||||
elif style['icon-fg-color'] is None:
|
||||
ui.display.loader(
|
||||
progress, style['fg-color'], style['bg-color'], style['icon'])
|
||||
progress, -8, style['fg-color'], style['bg-color'], style['icon'])
|
||||
else:
|
||||
ui.display.loader(
|
||||
progress, style['fg-color'], style['bg-color'], style['icon'], style['icon-fg-color'])
|
||||
progress, -8, style['fg-color'], style['bg-color'], style['icon'], style['icon-fg-color'])
|
||||
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user