From ad6c274e073d6431eae673658976b3ad7e5c3d79 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 10 Oct 2016 14:38:11 +0200 Subject: [PATCH] modtrezorui: loader icon is now 64x64; reorganize icons --- extmod/modtrezorui/display.c | 9 +++++---- extmod/modtrezorui/display.h | 2 ++ extmod/modtrezorui/modtrezorui-display.h | 4 ++-- src/trezor/res/{ => header_icons}/recovery.toig | Bin src/trezor/res/{ => header_icons}/reset.toig | Bin src/trezor/res/{ => header_icons}/wipe.toig | Bin .../res/{close-button.toig => pin_close.toig} | Bin src/trezor/ui/__init__.py | 6 +++--- src/trezor/ui/pin.py | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) rename src/trezor/res/{ => header_icons}/recovery.toig (100%) rename src/trezor/res/{ => header_icons}/reset.toig (100%) rename src/trezor/res/{ => header_icons}/wipe.toig (100%) rename src/trezor/res/{close-button.toig => pin_close.toig} (100%) diff --git a/extmod/modtrezorui/display.c b/extmod/modtrezorui/display.c index 918b9ba16..ed6cb7d18 100644 --- a/extmod/modtrezorui/display.c +++ b/extmod/modtrezorui/display.c @@ -283,8 +283,8 @@ void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const set_color_table(iconcolortable, iconfgcolor, bgcolor); } display_set_window(DISPLAY_RESX / 2 - img_loader_size, DISPLAY_RESY / 2 - img_loader_size, img_loader_size * 2, img_loader_size * 2); - if (icon && memcmp(icon, "TOIg\x60\x00\x60\x00", 8) == 0 && iconlen == 12 + *(uint32_t *)(icon + 8)) { - uint8_t icondata[96 * 96 / 2]; + 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); icon = icondata; } else { @@ -310,8 +310,9 @@ void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const a = 999 - (img_loader[my][mx] >> 8); } // inside of circle - draw glyph - if (icon && mx + my > (48 * 2) && mx >= img_loader_size - 48 && my >= img_loader_size - 48) { - int i = (x - (img_loader_size - 48)) + (y - (img_loader_size - 48)) * 96; + #define LOADER_ICON_CORNER_CUT 2 + if (icon && mx + my > (((LOADER_ICON_SIZE / 2) + LOADER_ICON_CORNER_CUT) * 2) && mx >= img_loader_size - (LOADER_ICON_SIZE / 2) && my >= img_loader_size - (LOADER_ICON_SIZE / 2)) { + int i = (x - (img_loader_size - (LOADER_ICON_SIZE / 2))) + (y - (img_loader_size - (LOADER_ICON_SIZE / 2))) * LOADER_ICON_SIZE; uint8_t c; if (i % 2) { c = icon[i / 2] & 0x0F; diff --git a/extmod/modtrezorui/display.h b/extmod/modtrezorui/display.h index 07d0ca617..e3be54ef8 100644 --- a/extmod/modtrezorui/display.h +++ b/extmod/modtrezorui/display.h @@ -17,6 +17,8 @@ #define FONT_NORMAL 1 #define FONT_BOLD 2 +#define LOADER_ICON_SIZE 64 + void display_init(void); void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h); int display_orientation(int degrees); diff --git a/extmod/modtrezorui/modtrezorui-display.h b/extmod/modtrezorui/modtrezorui-display.h index 428defa1f..b870f13fa 100644 --- a/extmod/modtrezorui/modtrezorui-display.h +++ b/extmod/modtrezorui/modtrezorui-display.h @@ -262,7 +262,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_qrcode_obj, 5, 5 /// Renders a rotating loader graphic. /// Progress determines its position (0-1000), fgcolor is used as foreground color, bgcolor as background. /// When icon and iconfgcolor are provided, an icon is drawn in the middle using the color specified in iconfgcolor. -/// Icon needs to be of exaclty 96x96 pixels size. +/// Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels size. /// ''' 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]); @@ -278,7 +278,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args) mp_int_t w = *(uint16_t *)(data + 4); mp_int_t h = *(uint16_t *)(data + 6); mp_int_t datalen = *(uint32_t *)(data + 8); - if (w != 96 || h != 96) { + if (w != LOADER_ICON_SIZE || h != LOADER_ICON_SIZE) { mp_raise_ValueError("Invalid icon size"); } if (datalen != icon.len - 12) { diff --git a/src/trezor/res/recovery.toig b/src/trezor/res/header_icons/recovery.toig similarity index 100% rename from src/trezor/res/recovery.toig rename to src/trezor/res/header_icons/recovery.toig diff --git a/src/trezor/res/reset.toig b/src/trezor/res/header_icons/reset.toig similarity index 100% rename from src/trezor/res/reset.toig rename to src/trezor/res/header_icons/reset.toig diff --git a/src/trezor/res/wipe.toig b/src/trezor/res/header_icons/wipe.toig similarity index 100% rename from src/trezor/res/wipe.toig rename to src/trezor/res/header_icons/wipe.toig diff --git a/src/trezor/res/close-button.toig b/src/trezor/res/pin_close.toig similarity index 100% rename from src/trezor/res/close-button.toig rename to src/trezor/res/pin_close.toig diff --git a/src/trezor/ui/__init__.py b/src/trezor/ui/__init__.py index 3ee5d0c07..7c75823bd 100644 --- a/src/trezor/ui/__init__.py +++ b/src/trezor/ui/__init__.py @@ -50,9 +50,9 @@ BACKLIGHT_DIM = const(5) BACKLIGHT_MAX = const(255) # icons -ICON_RESET = 'trezor/res/reset.toig' -ICON_WIPE = 'trezor/res/wipe.toig' -ICON_RECOVERY = 'trezor/res/recovery.toig' +ICON_RESET = 'trezor/res/header_icons/reset.toig' +ICON_WIPE = 'trezor/res/header_icons/wipe.toig' +ICON_RECOVERY = 'trezor/res/header_icons/recovery.toig' def in_area(pos: tuple, area: tuple) -> bool: x, y = pos diff --git a/src/trezor/ui/pin.py b/src/trezor/ui/pin.py index 9f412688a..2151de441 100644 --- a/src/trezor/ui/pin.py +++ b/src/trezor/ui/pin.py @@ -25,7 +25,7 @@ class PinMatrix(): self.label = label self.pin = pin self.clear_button = Button((240 - 35, 5, 30, 30), - res.load('trezor/res/close-button.toig'), + res.load('trezor/res/pin_close.toig'), normal_style=CLEAR_BUTTON, active_style=CLEAR_BUTTON_ACTIVE) self.pin_buttons = [Button(digit_area(i), str(d))