mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
display.bar now can set roundness
This commit is contained in:
parent
e6b8dc3cc5
commit
a768d32ff9
@ -78,30 +78,35 @@ static const uint8_t cornertable[CORNER_RADIUS*CORNER_RADIUS] = {
|
||||
};
|
||||
|
||||
|
||||
void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c, uint16_t b)
|
||||
void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c, uint16_t b, uint8_t r)
|
||||
{
|
||||
if (r != 2 && r != 4 && r != 8 && r != 16) {
|
||||
return;
|
||||
} else {
|
||||
r = 16 / r;
|
||||
}
|
||||
uint16_t colortable[16];
|
||||
set_color_table(colortable, c, b);
|
||||
display_set_window(x, y, w, h);
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
if (x < CORNER_RADIUS && y < CORNER_RADIUS) {
|
||||
uint8_t c = cornertable[x + y * CORNER_RADIUS];
|
||||
if (x < CORNER_RADIUS / r && y < CORNER_RADIUS / r) {
|
||||
uint8_t c = cornertable[x * r + y * r * CORNER_RADIUS];
|
||||
DATA(colortable[c] >> 8);
|
||||
DATA(colortable[c] & 0xFF);
|
||||
} else
|
||||
if (x < CORNER_RADIUS && y >= h - CORNER_RADIUS) {
|
||||
uint8_t c = cornertable[x + (h - 1 - y) * CORNER_RADIUS];
|
||||
if (x < CORNER_RADIUS / r && y >= h - CORNER_RADIUS / r) {
|
||||
uint8_t c = cornertable[x * r + (h - 1 - y) * r * CORNER_RADIUS];
|
||||
DATA(colortable[c] >> 8);
|
||||
DATA(colortable[c] & 0xFF);
|
||||
} else
|
||||
if (x >= w - CORNER_RADIUS && y < CORNER_RADIUS) {
|
||||
uint8_t c = cornertable[(w - 1 - x) + y * CORNER_RADIUS];
|
||||
if (x >= w - CORNER_RADIUS / r && y < CORNER_RADIUS / r) {
|
||||
uint8_t c = cornertable[(w - 1 - x) * r + y * r * CORNER_RADIUS];
|
||||
DATA(colortable[c] >> 8);
|
||||
DATA(colortable[c] & 0xFF);
|
||||
} else
|
||||
if (x >= w - CORNER_RADIUS && y >= h - CORNER_RADIUS) {
|
||||
uint8_t c = cornertable[(w - 1 - x) + (h - 1 - y) * CORNER_RADIUS];
|
||||
if (x >= w - CORNER_RADIUS / r && y >= h - CORNER_RADIUS / r) {
|
||||
uint8_t c = cornertable[(w - 1 - x) * r + (h - 1 - y) * r * CORNER_RADIUS];
|
||||
DATA(colortable[c] >> 8);
|
||||
DATA(colortable[c] & 0xFF);
|
||||
} else {
|
||||
|
@ -19,7 +19,7 @@ int display_backlight(int val);
|
||||
|
||||
void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_bar(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c);
|
||||
void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c, uint16_t b);
|
||||
void display_bar_radius(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c, uint16_t b, uint8_t r);
|
||||
void display_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen);
|
||||
void display_image(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen);
|
||||
void display_icon(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor);
|
||||
|
@ -21,7 +21,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_make_new(const mp_obj_type_t *type, size_t
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
/// def trezor.ui.display.bar(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None) -> None
|
||||
/// def trezor.ui.display.bar(x: int, y: int, w: int, h: int, fgcolor: int, bgcolor: int=None, radius: int=None) -> None
|
||||
/// '''
|
||||
/// Renders a bar at position (x,y = upper left corner) with width w and height h of color fgcolor.
|
||||
/// When a bgcolor is set, the bar is drawn with rounded corners and bgcolor is used for background.
|
||||
@ -35,15 +35,16 @@ STATIC mp_obj_t mod_TrezorUi_Display_bar(size_t n_args, const mp_obj_t *args) {
|
||||
if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds"));
|
||||
}
|
||||
if (n_args > 6) {
|
||||
if (n_args > 7) {
|
||||
uint16_t b = mp_obj_get_int(args[6]);
|
||||
display_bar_radius(x, y, w, h, c, b);
|
||||
uint8_t r = mp_obj_get_int(args[7]);
|
||||
display_bar_radius(x, y, w, h, c, b, r);
|
||||
} else {
|
||||
display_bar(x, y, w, h, c);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_bar_obj, 6, 7, mod_TrezorUi_Display_bar);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_bar_obj, 6, 8, mod_TrezorUi_Display_bar);
|
||||
|
||||
/// def trezor.ui.display.blit(x: int, y: int, w: int, h: int, data: bytes) -> None
|
||||
/// '''
|
||||
|
Loading…
Reference in New Issue
Block a user