embed/extmod/modtrezorui: remove FONT_PY_TO_C/FONT_C_TO_PY, use (signed) int globally for font id

pull/25/head
Pavol Rusnak 6 years ago
parent 3a2c1eecdb
commit 6801b61514
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -283,7 +283,7 @@ void display_icon(int x, int y, int w, int h, const void *data, int datalen, uin
sinf_inflate(data, datalen, inflate_callback_icon, userdata);
}
static const uint8_t *get_glyph(uint8_t font, uint8_t c)
static const uint8_t *get_glyph(int font, uint8_t c)
{
if (c >= ' ' && c <= '~') {
// do nothing - valid ASCII
@ -416,7 +416,7 @@ void display_printf(const char *fmt, ...)
#endif // TREZOR_PRINT_DISABLE
static void display_text_render(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
static void display_text_render(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor)
{
// determine text length if not provided
if (textlen < 0) {
@ -461,14 +461,14 @@ static void display_text_render(int x, int y, const char *text, int textlen, uin
}
}
void display_text(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor)
void display_text(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
display_text_render(x, y, text, textlen, font, fgcolor, 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_center(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
@ -476,7 +476,7 @@ void display_text_center(int x, int y, const char *text, int textlen, uint8_t fo
display_text_render(x - w / 2, y, text, textlen, font, fgcolor, bgcolor);
}
void display_text_right(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, int font, uint16_t fgcolor, uint16_t bgcolor)
{
x += DISPLAY_OFFSET.x;
y += DISPLAY_OFFSET.y;
@ -485,7 +485,7 @@ void display_text_right(int x, int y, const char *text, int textlen, uint8_t fon
}
// compute the width of the text (in pixels)
int display_text_width(const char *text, int textlen, uint8_t font)
int display_text_width(const char *text, int textlen, int font)
{
int width = 0;
// determine text length if not provided

@ -33,16 +33,16 @@
#define FONT_SIZE 20
#ifdef TREZOR_FONT_NORMAL_ENABLE
#define FONT_NORMAL 1
#define FONT_NORMAL (-1)
#endif
#ifdef TREZOR_FONT_BOLD_ENABLE
#define FONT_BOLD 2
#define FONT_BOLD (-2)
#endif
#ifdef TREZOR_FONT_MONO_ENABLE
#define FONT_MONO 3
#define FONT_MONO (-3)
#endif
#ifdef TREZOR_FONT_MONO_BOLD_ENABLE
#define FONT_MONO_BOLD 4
#define FONT_MONO_BOLD (-4)
#endif
#define AVATAR_IMAGE_SIZE 144
@ -76,10 +76,10 @@ void display_print(const char *text, int textlen);
void display_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
#endif
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);
int display_text_width(const char *text, int textlen, uint8_t font);
void display_text(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor);
void display_text_center(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor);
void display_text_right(int x, int y, const char *text, int textlen, int font, uint16_t fgcolor, uint16_t bgcolor);
int display_text_width(const char *text, int textlen, int font);
void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale);
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);

@ -21,9 +21,6 @@
#include "display.h"
#define FONT_PY_TO_C(f) (-(f))
#define FONT_C_TO_PY(f) (-(f))
/// class Display:
/// '''
/// Provide access to device display.
@ -205,7 +202,7 @@ STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
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 = FONT_PY_TO_C(mp_obj_get_int(args[4]));
mp_int_t font = 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;
@ -231,7 +228,7 @@ STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args, const mp_obj_t *
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 = FONT_PY_TO_C(mp_obj_get_int(args[4]));
mp_int_t font = 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;
@ -257,7 +254,7 @@ STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args, const mp_obj_t *a
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 = FONT_PY_TO_C(mp_obj_get_int(args[4]));
mp_int_t font = 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;
@ -278,7 +275,7 @@ 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 = FONT_PY_TO_C(mp_obj_get_int(font));
mp_int_t f = mp_obj_get_int(font);
int w = display_text_width(txt.buf, txt.len, f);
return mp_obj_new_int(w);
}
@ -455,10 +452,10 @@ 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_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)) },
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO), MP_OBJ_NEW_SMALL_INT(FONT_C_TO_PY(FONT_MONO)) },
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO_BOLD), MP_OBJ_NEW_SMALL_INT(FONT_C_TO_PY(FONT_MONO_BOLD)) },
{ 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_MONO) },
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO_BOLD), MP_OBJ_NEW_SMALL_INT(FONT_MONO_BOLD) },
};
STATIC MP_DEFINE_CONST_DICT(mod_trezorui_Display_locals_dict, mod_trezorui_Display_locals_dict_table);

Loading…
Cancel
Save