/******************************************************************************* * Ledger Nano S - Secure firmware * (c) 2022 Ledger * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ********************************************************************************/ #ifndef BAGL_H_ #define BAGL_H_ #define BAGL_NOFILL 0 #define BAGL_FILL 1 #define BAGL_OUTLINE 2 #define BAGL_NOICON 3 #define BAGL_FILL_CIRCLE_1_OCTANT 1 #define BAGL_FILL_CIRCLE_2_OCTANT 2 #define BAGL_FILL_CIRCLE_3_OCTANT 4 #define BAGL_FILL_CIRCLE_4_OCTANT 8 #define BAGL_FILL_CIRCLE_5_OCTANT 16 #define BAGL_FILL_CIRCLE_6_OCTANT 32 #define BAGL_FILL_CIRCLE_7_OCTANT 64 #define BAGL_FILL_CIRCLE_8_OCTANT 128 #define BAGL_FILL_CIRCLE 0xFF #define BAGL_FILL_CIRCLE_3PI2_2PI \ (BAGL_FILL_CIRCLE_1_OCTANT | BAGL_FILL_CIRCLE_2_OCTANT) #define BAGL_FILL_CIRCLE_PI_3PI2 \ (BAGL_FILL_CIRCLE_3_OCTANT | BAGL_FILL_CIRCLE_4_OCTANT) #define BAGL_FILL_CIRCLE_0_PI2 \ (BAGL_FILL_CIRCLE_5_OCTANT | BAGL_FILL_CIRCLE_6_OCTANT) #define BAGL_FILL_CIRCLE_PI2_PI \ (BAGL_FILL_CIRCLE_7_OCTANT | BAGL_FILL_CIRCLE_8_OCTANT) // -------------------------------------------------------------------------------------- typedef enum bagl_components_type_e_ { BAGL_NONE = 0, // for fast memset clearing all components BAGL_BUTTON = 1, // BAGL_TEXTBOX, // NOT NECESSARY // BAGL_SENSEZONE, // sense only BAGL_LABEL, BAGL_RECTANGLE, BAGL_LINE, BAGL_ICON, BAGL_CIRCLE, BAGL_LABELINE, // label for which y coordinate is the baseline of the text, // does not support vertical alignment BAGL_FLAG_TOUCHABLE = 0x80, } bagl_components_type_e; #define BAGL_TYPE_FLAGS_MASK 0x80 // -------------------------------------------------------------------------------------- typedef struct { bagl_components_type_e type; unsigned char userid; short x; // allow for out of screen rendering short y; // allow for out of screen rendering unsigned short width; unsigned short height; unsigned char stroke; unsigned char radius; unsigned char fill; unsigned int fgcolor; unsigned int bgcolor; unsigned short font_id; unsigned char icon_id; } bagl_component_t; #define BAGL_FONT_ID_MASK 0x0FFF #define BAGL_FONT_ALIGNMENT_HORIZONTAL_MASK 0xC000 #define BAGL_FONT_ALIGNMENT_LEFT 0x0000 #define BAGL_FONT_ALIGNMENT_RIGHT 0x4000 #define BAGL_FONT_ALIGNMENT_CENTER 0x8000 #define BAGL_FONT_ALIGNMENT_VERTICAL_MASK 0x3000 #define BAGL_FONT_ALIGNMENT_TOP 0x0000 #define BAGL_FONT_ALIGNMENT_BOTTOM 0x1000 #define BAGL_FONT_ALIGNMENT_MIDDLE 0x2000 #define BAGL_STROKE_FLAG_ONESHOT 0x80 // avgcharwidth: the average character width in pixel // stroke: contains the hold time at start and at end (flag oneshot + in x // 100ms) iconid: contains the horizontal scroll speed (in pixel/second) #define BAGL_LONGLABEL_TIME_MS(textlength, avgcharwidth, stroke, iconid) \ (2 * (textlength * avgcharwidth) * 1000 / (iconid) + \ 2 * (stroke & ~(BAGL_STROKE_FLAG_ONESHOT)) * 100) // -------------------------------------------------------------------------------------- /** * helper structure to help handling icons */ typedef struct bagl_icon_details_s { unsigned int width; unsigned int height; // bit per pixel unsigned int bpp; const unsigned int *colors; const unsigned char *bitmap; } bagl_icon_details_t; // -------------------------------------------------------------------------------------- #ifdef HAVE_BAGL_GLYPH_ARRAY typedef struct { unsigned int icon_id; unsigned int width; unsigned int height; unsigned int bits_per_pixel; const unsigned int *default_colors; // color array entry count is (1<