Skip to content

Commit

Permalink
Remove unsused radius for circles and discs
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger authored and abonnaudet-ledger committed Jan 30, 2024
1 parent b120659 commit 67f2865
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 108 deletions.
Binary file removed lib_nbgl/glyphs/quarter_circle_16px_1bpp_nocomp.bmp
Binary file not shown.
Binary file removed lib_nbgl/glyphs/quarter_circle_20px_1bpp_nocomp.bmp
Binary file not shown.
Binary file removed lib_nbgl/glyphs/quarter_circle_24px_1bpp_nocomp.bmp
Binary file not shown.
Binary file removed lib_nbgl/glyphs/quarter_circle_8px_1bpp_nocomp.bmp
Binary file not shown.
Binary file removed lib_nbgl/glyphs/quarter_round_16px_1bpp_nocomp.bmp
Binary file not shown.
Binary file removed lib_nbgl/glyphs/quarter_round_20px_1bpp_nocomp.bmp
Binary file not shown.
Binary file removed lib_nbgl/glyphs/quarter_round_24px_1bpp_nocomp.bmp
Binary file not shown.
Binary file removed lib_nbgl/glyphs/quarter_round_8px_1bpp_nocomp.bmp
Binary file not shown.
4 changes: 3 additions & 1 deletion lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ typedef enum {
*
*/
typedef enum {
NO_STYLE, ///< no border
NO_STYLE, ///< no border
#ifdef SCREEN_SIZE_NANO
INVERTED_COLORS ///< Inverted background and rounded corners, only for @ref TEXT_AREA
#endif // SCREEN_SIZE_NANO
} nbgl_style_t;

/**
Expand Down
19 changes: 9 additions & 10 deletions lib_nbgl/include/nbgl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,15 @@ typedef enum nbgl_post_refresh_t {
*
*/
typedef enum {
RADIUS_3_PIXELS = 0, ///< 3 pixels (not on Stax)
RADIUS_4_PIXELS, ///< 4 pixels
RADIUS_8_PIXELS, ///< 8 pixels
RADIUS_16_PIXELS, ///< 16 pixels
RADIUS_20_PIXELS, ///< 20 pixels
RADIUS_24_PIXELS, ///< 24 pixels
RADIUS_32_PIXELS, ///< 32 pixels
RADIUS_40_PIXELS, ///< 40 pixels
RADIUS_48_PIXELS, ///< 48 pixels
RADIUS_1_PIXEL, ///< 1 pixel (not on Stax)
#ifdef SCREEN_SIZE_WALLET
RADIUS_32_PIXELS = 0, ///< 32 pixels
RADIUS_40_PIXELS, ///< 48 pixels
RADIUS_MAX = RADIUS_40_PIXELS,
#else // SCREEN_SIZE_WALLET
RADIUS_1_PIXEL = 0, ///< 1 pixel
RADIUS_3_PIXELS, ///< 3 pixels
RADIUS_MAX = RADIUS_3_PIXELS,
#endif // SCREEN_SIZE_WALLET
RADIUS_0_PIXELS = 0xFF, ///< no radius (square angle)
} nbgl_radius_t;

Expand Down
8 changes: 4 additions & 4 deletions lib_nbgl/serialization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ Deserialize raw bytes into an Nbgl event:
>>> data = bytes.fromhex("00010501f403e800ff003201000301020403015465737420627574746f6e00")
>>> nbgl_event = deserialize_nbgl_bytes(data)
>>> nbgl_event
NbglDrawObjectEvent(obj=NbglButton(area=NbglArea(width=255, height=50, x0=500, y0=1000, background_color=<NbglColor.DARK_GRAY: 1>, bpp=<NbglBpp.BPP_1: 0>), inner_color=<NbglColor.WHITE: 3>, border_color=<NbglColor.DARK_GRAY: 1>, foreground_color=<NbglColor.LIGHT_GRAY: 2>, radius=<NbglRadius.RADIUS_24_PIXELS: 4>, font_id=<NbglFontId.BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px: 3>, localized=True, text='Test button'))
NbglDrawObjectEvent(obj=NbglButton(area=NbglArea(width=255, height=50, x0=500, y0=1000, background_color=<NbglColor.DARK_GRAY: 1>, bpp=<NbglBpp.BPP_1: 0>), inner_color=<NbglColor.WHITE: 3>, border_color=<NbglColor.DARK_GRAY: 1>, foreground_color=<NbglColor.LIGHT_GRAY: 2>, radius=<NbglRadius.RADIUS_40_PIXELS: 4>, font_id=<NbglFontId.BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px: 3>, localized=True, text='Test button'))
```

Serialize a Nbgl event into a json-like dict:
```python
>>> from nbgl_lib import serialize_nbgl_json
>>> serialize_nbgl_json(nbgl_event)
{'event': 'NBGL_DRAW_OBJ', 'obj': {'type': 'BUTTON', 'content': {'area': {'width': 255, 'height': 50, 'x0': 500, 'y0': 1000, 'background_color': 'DARK_GRAY', 'bpp': 'BPP_1'}, 'inner_color': 'WHITE', 'border_color': 'DARK_GRAY', 'foreground_color': 'LIGHT_GRAY', 'radius': 'RADIUS_24_PIXELS', 'font_id': 'BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px', 'localized': True, 'text': 'Test button'}}}
{'event': 'NBGL_DRAW_OBJ', 'obj': {'type': 'BUTTON', 'content': {'area': {'width': 255, 'height': 50, 'x0': 500, 'y0': 1000, 'background_color': 'DARK_GRAY', 'bpp': 'BPP_1'}, 'inner_color': 'WHITE', 'border_color': 'DARK_GRAY', 'foreground_color': 'LIGHT_GRAY', 'radius': 'RADIUS_40_PIXELS', 'font_id': 'BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px', 'localized': True, 'text': 'Test button'}}}
```

Deserialize json-like dict into an Nbgl event:

```python
>>> from nbgl_lib import deserialize_nbgl_json
>>> deserialize_nbgl_json({'event': 'NBGL_DRAW_OBJ', 'obj': {'type': 'BUTTON', 'content': {'area': {'width': 255, 'height': 50, 'x0': 500, 'y0': 1000, 'background_color': 'DARK_GRAY', 'bpp': 'BPP_1'}, 'inner_color': 'WHITE', 'border_color': 'DARK_GRAY', 'foreground_color': 'LIGHT_GRAY', 'radius': 'RADIUS_24_PIXELS', 'font_id': 'BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px', 'localized': True, 'text': 'Test button'}}})
NbglDrawObjectEvent(obj=NbglButton(area=NbglArea(width=255, height=50, x0=500, y0=1000, background_color=<NbglColor.DARK_GRAY: 1>, bpp=<NbglBpp.BPP_1: 0>), inner_color=<NbglColor.WHITE: 3>, border_color=<NbglColor.DARK_GRAY: 1>, foreground_color=<NbglColor.LIGHT_GRAY: 2>, radius=<NbglRadius.RADIUS_24_PIXELS: 4>, font_id=<NbglFontId.BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px: 3>, localized=True, text='Test button'))
>>> deserialize_nbgl_json({'event': 'NBGL_DRAW_OBJ', 'obj': {'type': 'BUTTON', 'content': {'area': {'width': 255, 'height': 50, 'x0': 500, 'y0': 1000, 'background_color': 'DARK_GRAY', 'bpp': 'BPP_1'}, 'inner_color': 'WHITE', 'border_color': 'DARK_GRAY', 'foreground_color': 'LIGHT_GRAY', 'radius': 'RADIUS_40_PIXELS', 'font_id': 'BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px', 'localized': True, 'text': 'Test button'}}})
NbglDrawObjectEvent(obj=NbglButton(area=NbglArea(width=255, height=50, x0=500, y0=1000, background_color=<NbglColor.DARK_GRAY: 1>, bpp=<NbglBpp.BPP_1: 0>), inner_color=<NbglColor.WHITE: 3>, border_color=<NbglColor.DARK_GRAY: 1>, foreground_color=<NbglColor.LIGHT_GRAY: 2>, radius=<NbglRadius.RADIUS_40_PIXELS: 4>, font_id=<NbglFontId.BAGL_FONT_HM_ALPHA_MONO_MEDIUM_32px: 3>, localized=True, text='Test button'))
```
### Tests

Expand Down
2 changes: 1 addition & 1 deletion lib_nbgl/serialization/generate_data_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void test_draw_nbgl_button()
.innerColor = WHITE,
.borderColor = DARK_GRAY,
.foregroundColor = LIGHT_GRAY,
.radius = RADIUS_24_PIXELS,
.radius = RADIUS_40_PIXELS,
.fontId = BAGL_FONT_INTER_MEDIUM_32px,
.localized = true,
.text = "Test button",
Expand Down
14 changes: 5 additions & 9 deletions lib_nbgl/serialization/nbgl_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ class NbglQrCodeVersion(IntEnum):


class NbglRadius(IntEnum):
RADIUS_4_PIXELS = 0,
RADIUS_8_PIXELS = 1,
RADIUS_16_PIXELS = 2,
RADIUS_20_PIXELS = 3,
RADIUS_24_PIXELS = 4,
RADIUS_32_PIXELS = 5,
RADIUS_40_PIXELS = 6,
RADIUS_48_PIXELS = 7,
RADIUS_0_PIXELS = 0xFF,
RADIUS_32_PIXELS = 0
RADIUS_40_PIXELS = 1
RADIUS_1_PIXEL = 0
RADIUS_3_PIXELS = 1
RADIUS_0_PIXELS = 0xFF


class NbglKeyboardMode(IntEnum):
Expand Down
2 changes: 1 addition & 1 deletion lib_nbgl/serialization/test_bytes_deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_draw_nbgl_button(data_test):
inner_color=NbglColor.WHITE,
border_color=NbglColor.DARK_GRAY,
foreground_color=NbglColor.LIGHT_GRAY,
radius=NbglRadius.RADIUS_24_PIXELS,
radius=NbglRadius.RADIUS_40_PIXELS,
font_id=NbglFontId.BAGL_FONT_INTER_MEDIUM_32px,
text="Test button",
localized=True
Expand Down
104 changes: 31 additions & 73 deletions lib_nbgl/src/nbgl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,70 +53,38 @@ typedef struct {
/**********************
* STATIC VARIABLES
**********************/
static const uint8_t quarter_disc_3px_1bpp[] = {0xEC, 0xFF};
#ifndef HAVE_SE_TOUCH
#ifndef SCREEN_SIZE_WALLET
static const uint8_t quarter_disc_3px_1bpp[] = {0xEC, 0xFF};
static const uint8_t quarter_disc_3px_90_1bpp[] = {0x2F, 0xFF};
static const uint8_t quarter_disc_3px_180_1bpp[] = {0x9B, 0xFF};
static const uint8_t quarter_disc_3px_270_1bpp[] = {0xFA, 0x00};
#endif // HAVE_SE_TOUCH

static const uint8_t quarter_circle_3px_1bpp[] = {0x4C, 0x00};
#ifndef HAVE_SE_TOUCH
static const uint8_t quarter_circle_3px_1bpp[] = {0x4C, 0x00};
static const uint8_t quarter_circle_3px_90_1bpp[] = {0x0D, 0x00};
static const uint8_t quarter_circle_3px_180_1bpp[] = {0x19, 0x00};
static const uint8_t quarter_circle_3px_270_1bpp[] = {0x58, 0x00};
#else // HAVE_SE_TOUCH
static const nbgl_icon_details_t C_quarter_disc_3px_1bpp
= {2, 2, NBGL_BPP_1, false, quarter_disc_3px_1bpp};
static const nbgl_icon_details_t C_quarter_circle_3px_1bpp
= {2, 2, NBGL_BPP_1, false, quarter_circle_3px_1bpp};

static const uint8_t quarter_disc_4px_1bpp[] = {0x13, 0xFF};
static const nbgl_icon_details_t C_quarter_disc_4px_1bpp
= {4, 4, NBGL_BPP_1, false, quarter_disc_4px_1bpp};

static const uint8_t quarter_circle_4px_1bpp[] = {0x13, 0xFF};
static const nbgl_icon_details_t C_quarter_circle_4px_1bpp
= {4, 4, NBGL_BPP_1, false, quarter_circle_4px_1bpp};
#endif // HAVE_SE_TOUCH
#endif // SCREEN_SIZE_WALLET

// indexed by nbgl_radius_t (except RADIUS_0_PIXELS)
static const uint8_t radiusValues[] = {3,
#ifdef HAVE_SE_TOUCH
4,
8,
16,
20,
24,
32,
40,
48
#endif // HAVE_SE_TOUCH
static const uint8_t radiusValues[] = {
#ifdef SCREEN_SIZE_WALLET
32,
40
#else // SCREEN_SIZE_WALLET
1,
3
#endif // SCREEN_SIZE_WALLET
};

#ifdef HAVE_SE_TOUCH
#ifdef SCREEN_SIZE_WALLET
// indexed by nbgl_radius_t (except RADIUS_0_PIXELS)
static const nbgl_icon_details_t *quarterDiscs[] = {&C_quarter_disc_3px_1bpp,
&C_quarter_disc_4px_1bpp,
&C_quarter_round_8px_1bpp,
&C_quarter_round_16px_1bpp,
&C_quarter_round_20px_1bpp,
&C_quarter_round_24px_1bpp,
&C_quarter_round_32px_1bpp,
&C_quarter_round_40px_1bpp,
&C_quarter_round_48px_1bpp};
static const nbgl_icon_details_t *quarterDiscs[] = {&C_quarter_round_32px_1bpp,
&C_quarter_round_40px_1bpp};

// indexed by nbgl_radius_t (except RADIUS_0_PIXELS)
static const nbgl_icon_details_t *quarterCircles[] = {&C_quarter_circle_3px_1bpp,
&C_quarter_circle_4px_1bpp,
&C_quarter_circle_8px_1bpp,
&C_quarter_circle_16px_1bpp,
&C_quarter_circle_20px_1bpp,
&C_quarter_circle_24px_1bpp,
&C_quarter_circle_32px_1bpp,
&C_quarter_circle_40px_1bpp,
&C_quarter_circle_48px_1bpp};
#endif // HAVE_SE_TOUCH
static const nbgl_icon_details_t *quarterCircles[] = {&C_quarter_circle_32px_1bpp,
&C_quarter_circle_40px_1bpp};
#endif // SCREEN_SIZE_WALLET

#ifdef NBGL_QRCODE
// ensure that the ramBuffer also used for image file decompression is big enough for QR code
Expand All @@ -142,11 +110,11 @@ static void draw_circle_helper(int x_center,
const uint8_t *quarter_buffer = NULL;
nbgl_area_t area = {.bpp = NBGL_BPP_1, .backgroundColor = backgroundColor};

#ifdef HAVE_SE_TOUCH
// radius is not supported
if (radiusIndex > RADIUS_48_PIXELS) {
if (radiusIndex > RADIUS_MAX) {
return;
}
#ifdef SCREEN_SIZE_WALLET
if (borderColor == innerColor) {
quarter_buffer
= (const uint8_t *) ((const nbgl_icon_details_t *) PIC(quarterDiscs[radiusIndex]))
Expand Down Expand Up @@ -179,11 +147,7 @@ static void draw_circle_helper(int x_center,
area.y0 = y_center - area.width;
nbgl_frontDrawImage(&area, quarter_buffer, NO_TRANSFORMATION, borderColor);
}
#else // HAVE_SE_TOUCH
// radius is not supported
if (radiusIndex > RADIUS_3_PIXELS) {
return;
}
#else // SCREEN_SIZE_WALLET
area.width = area.height = radiusValues[radiusIndex];
area.backgroundColor = backgroundColor;
if (quarter & BAGL_FILL_CIRCLE_3PI2_2PI) { //
Expand Down Expand Up @@ -211,7 +175,7 @@ static void draw_circle_helper(int x_center,
= (borderColor == innerColor) ? quarter_disc_3px_1bpp : quarter_circle_3px_1bpp;
}
nbgl_frontDrawImage(&area, quarter_buffer, NO_TRANSFORMATION, borderColor);
#endif // HAVE_SE_TOUCH
#endif // SCREEN_SIZE_WALLET
}

/**********************
Expand Down Expand Up @@ -239,17 +203,9 @@ void nbgl_drawRoundedRect(const nbgl_area_t *area, nbgl_radius_t radiusIndex, co
area->width,
area->height);

if (radiusIndex <= RADIUS_48_PIXELS) {
#ifndef HAVE_SE_TOUCH
if (radiusIndex > RADIUS_3_PIXELS) {
return;
}
#endif // HAVE_SE_TOUCH
if (radiusIndex <= RADIUS_MAX) {
radius = radiusValues[radiusIndex];
}
else if (radiusIndex == RADIUS_1_PIXEL) {
radius = 1;
}
else if (radiusIndex == RADIUS_0_PIXELS) {
radius = 0;
}
Expand Down Expand Up @@ -283,9 +239,11 @@ void nbgl_drawRoundedRect(const nbgl_area_t *area, nbgl_radius_t radiusIndex, co
rectArea.height = area->height - (2 * radius);
nbgl_frontDrawRect(&rectArea);

#ifdef SCREEN_SIZE_NANO
if (radiusIndex == RADIUS_1_PIXEL) {
return;
}
#endif // SCREEN_SIZE_NANO
// Draw 4 quarters of disc
draw_circle_helper(area->x0 + radius,
area->y0 + radius,
Expand Down Expand Up @@ -343,7 +301,7 @@ void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area,
borderColor,
area->backgroundColor);

if (radiusIndex <= RADIUS_48_PIXELS) {
if (radiusIndex <= RADIUS_MAX) {
radius = radiusValues[radiusIndex];
}
else if (radiusIndex == RADIUS_0_PIXELS) {
Expand Down Expand Up @@ -375,7 +333,7 @@ void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area,
nbgl_frontDrawRect(&rectArea);
}
// special case when radius is null, left and right rectangles are not necessary
if (radiusIndex <= RADIUS_48_PIXELS) {
if (radiusIndex <= RADIUS_MAX) {
if ((2 * radius) < area->height) {
rectArea.x0 = area->x0;
rectArea.y0 = area->y0 + radius;
Expand All @@ -389,7 +347,7 @@ void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area,
}
// border
// 4 rectangles (with last pixel of each corner not set)
#ifdef HAVE_SE_TOUCH
#ifdef SCREEN_SIZE_WALLET
uint8_t maskTop, maskBottom;
if (stroke == 1) {
maskTop = 0x1;
Expand Down Expand Up @@ -419,7 +377,7 @@ void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area,
rectArea.x0 = area->x0 + radius;
rectArea.y0 = area->y0 + area->height - 4;
nbgl_frontDrawHorizontalLine(&rectArea, maskBottom, borderColor); // bottom
#else // HAVE_SE_TOUCH
#else // SCREEN_SIZE_WALLET
rectArea.x0 = area->x0 + radius;
rectArea.y0 = area->y0;
rectArea.width = area->width - 2 * radius;
Expand All @@ -428,7 +386,7 @@ void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area,
nbgl_frontDrawRect(&rectArea); // top
rectArea.y0 = area->y0 + area->height - stroke;
nbgl_frontDrawRect(&rectArea); // bottom
#endif // HAVE_SE_TOUCH
#endif // SCREEN_SIZE_WALLET
if ((2 * radius) < area->height) {
rectArea.x0 = area->x0;
rectArea.y0 = area->y0 + radius;
Expand All @@ -440,7 +398,7 @@ void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area,
nbgl_frontDrawRect(&rectArea); // right
}

if (radiusIndex <= RADIUS_48_PIXELS) {
if (radiusIndex <= RADIUS_MAX) {
// Draw 4 quarters of circles
draw_circle_helper(area->x0 + radius,
area->y0 + radius,
Expand Down
19 changes: 10 additions & 9 deletions lib_nbgl/src/nbgl_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,14 @@ static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool compu
obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;

// draw background to make sure it's clean
#ifdef SCREEN_SIZE_NANO
if (obj->style == INVERTED_COLORS) {
obj->obj.area.backgroundColor = WHITE;
rectArea.backgroundColor = BLACK;
}
else {
else
#endif // SCREEN_SIZE_NANO
{
// inherit background from parent
obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
rectArea.backgroundColor = obj->obj.area.backgroundColor;
Expand All @@ -830,10 +833,13 @@ static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool compu
rectArea.y0 = obj->obj.area.y0;
rectArea.width = obj->obj.area.width;
rectArea.height = obj->obj.area.height;
#ifdef SCREEN_SIZE_NANO
if (obj->style == INVERTED_COLORS) {
nbgl_drawRoundedRect(&rectArea, RADIUS_1_PIXEL, WHITE);
}
else {
else
#endif // SCREEN_SIZE_NANO
{
nbgl_frontDrawRect(&rectArea);
}

Expand Down Expand Up @@ -877,16 +883,11 @@ static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool compu
textHeight = (nbLines - 1) * lineHeight + fontHeight;

midHeight = (obj->obj.area.height - textHeight) / 2;
// Be sure midHeight is modulo 4
#ifdef HAVE_SE_TOUCH
if (midHeight % 4) {
midHeight -= midHeight % 4;
}
#else // HAVE_SE_TOUCH
#ifdef SCREEN_SIZE_NANO
if (obj->style == INVERTED_COLORS) {
midHeight--;
}
#endif // HAVE_SE_TOUCH
#endif // SCREEN_SIZE_NANO

rectArea.backgroundColor = obj->obj.area.backgroundColor;
rectArea.height = fontHeight;
Expand Down
2 changes: 2 additions & 0 deletions target/europa/include/bolos_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
#define ST33K1M5
#endif // ST33K1M5
#define TARGET_ID 0x33300004
#ifndef TARGET_EUROPA
#define TARGET_EUROPA
#endif // TARGET_EUROPA
2 changes: 2 additions & 0 deletions target/stax/include/bolos_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
#define ST33K1M5
#endif // ST33K1M5
#define TARGET_ID 0x33200004
#ifndef TARGET_STAX
#define TARGET_STAX
#endif // TARGET_STAX

0 comments on commit 67f2865

Please sign in to comment.