Skip to content

Commit

Permalink
Use our own font for text labels of buttons (0b01 needs C23 for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenhael-le-moine committed Sep 9, 2024
1 parent dc74c49 commit eb2a8bc
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ EXTRA_WARNING_FLAGS := -Wunused-function \
$(call cc-option,-Wunused-variable)
endif

override CFLAGS := -std=c11 \
override CFLAGS := -std=c23 \
-Wall -Wextra -Wpedantic \
-Wformat=2 -Wshadow \
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \
Expand Down
147 changes: 147 additions & 0 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,137 @@ letter_t small_font[ 128 ] = {
{0, 0, 0 }
};

letter_t big_font[ 128 ] = {
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 }, /* # 16 */
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 }, /* # 32 */
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{big_font_dot_width, big_font_dot_height, big_font_dot_bitmap}, /* # 46 */
{0, 0, 0 },
{big_font_0_width, big_font_0_height, big_font_0_bitmap }, /* # 48 */
{big_font_1_width, big_font_1_height, big_font_1_bitmap },
{big_font_2_width, big_font_2_height, big_font_2_bitmap },
{big_font_3_width, big_font_3_height, big_font_3_bitmap },
{big_font_4_width, big_font_4_height, big_font_4_bitmap },
{big_font_5_width, big_font_5_height, big_font_5_bitmap },
{big_font_6_width, big_font_6_height, big_font_6_bitmap },
{big_font_7_width, big_font_7_height, big_font_7_bitmap },
{big_font_8_width, big_font_8_height, big_font_8_bitmap },
{big_font_9_width, big_font_9_height, big_font_9_bitmap },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 }, /* # 64 */
{big_font_A_width, big_font_A_height, big_font_A_bitmap },
{0, 0, 0 },
{big_font_C_width, big_font_C_height, big_font_C_bitmap },
{big_font_D_width, big_font_D_height, big_font_D_bitmap },
{big_font_E_width, big_font_E_height, big_font_E_bitmap },
{0, 0, 0 },
{big_font_G_width, big_font_G_height, big_font_G_bitmap },
{big_font_H_width, big_font_H_height, big_font_H_bitmap },
{big_font_I_width, big_font_I_height, big_font_I_bitmap },
{0, 0, 0 },
{0, 0, 0 },
{big_font_L_width, big_font_L_height, big_font_L_bitmap },
{big_font_M_width, big_font_M_height, big_font_M_bitmap },
{big_font_N_width, big_font_N_height, big_font_N_bitmap },
{big_font_O_width, big_font_O_height, big_font_O_bitmap },
{big_font_P_width, big_font_P_height, big_font_P_bitmap }, /* # 80 */
{0, 0, 0 },
{big_font_R_width, big_font_R_height, big_font_R_bitmap },
{big_font_S_width, big_font_S_height, big_font_S_bitmap },
{big_font_T_width, big_font_T_height, big_font_T_bitmap },
{0, 0, 0 },
{big_font_V_width, big_font_V_height, big_font_V_bitmap },
{0, 0, 0 },
{big_font_X_width, big_font_X_height, big_font_X_bitmap },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 }, /* # 96 */
{0, 0, 0 }, /* a == left arrow */
{0, 0, 0 }, /* b == differential */
{0, 0, 0 }, /* c == integral */
{0, 0, 0 }, /* d == sigma */
{0, 0, 0 }, /* e == sqr */
{0, 0, 0 }, /* f == root */
{0, 0, 0 }, /* g == pow10 */
{0, 0, 0 }, /* h == exp */
{0, 0, 0 }, /* i == << >> */
{0, 0, 0 }, /* j == " " */
{0, 0, 0 }, /* k == New Line */
{0, 0, 0 }, /* l == pi */
{0, 0, 0 }, /* m == angle */
{0, 0, 0 }, /* n == sqr gx */
{0, 0, 0 }, /* o == root gx */
{0, 0, 0 }, /* p == pow10 gx */
{0, 0, 0 }, /* q == exp gx */
{0, 0, 0 }, /* r == ( ) gx */
{0, 0, 0 }, /* s == # gx */
{0, 0, 0 }, /* t == [] gx */
{0, 0, 0 }, /* u == _ gx */
{0, 0, 0 }, /* v == << >> gx */
{0, 0, 0 }, /* w == " " gx */
{0, 0, 0 }, /* x == {} gx */
{0, 0, 0 }, /* y == :: gx */
{0, 0, 0 }, /* z == angle gx */
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 },
{0, 0, 0 }
};

color_t colors_sx[ NB_COLORS ] = {
{
/* #ffffff */
Expand Down Expand Up @@ -2172,6 +2303,22 @@ int SmallTextWidth( const char* string, unsigned int length )
return w;
}

int BigTextWidth( const char* string, unsigned int length )
{
int w = 0;
for ( unsigned int i = 0; i < length; i++ ) {
if ( big_font[ ( int )string[ i ] ].h != 0 )
w += big_font[ ( int )string[ i ] ].w;
else {
if ( config.verbose )
fprintf( stderr, "Unknown small letter 0x00%x\n", ( int )string[ i ] );
w += 7;
}
}

return w;
}

void start_UI( int argc, char** argv )
{
ui_init_LCD();
Expand Down
184 changes: 184 additions & 0 deletions src/ui_inner.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef struct ann_struct_t {
/* variables */
/*************/
extern letter_t small_font[ 128 ];
extern letter_t big_font[ 128 ];

extern color_t colors_sx[ NB_COLORS ];
extern color_t colors_gx[ NB_COLORS ];
Expand Down Expand Up @@ -625,10 +626,193 @@ static unsigned char arrow_gx_bitmap[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0
#define equal_gx_height 12
static unsigned char equal_gx_bitmap[] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00 };

/************/
/* Big font */
/************/
#define big_font_dot_width 8
#define big_font_dot_height 13
static unsigned char big_font_dot_bitmap[] = {
0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00011000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
};

#define big_font_0_width 8
#define big_font_0_height 13
static unsigned char big_font_0_bitmap[] = {
0b00011000, 0b00111100, 0b01100110, 0b01100110, 0b11000011, 0b11000011, 0b11000011,
0b11000011, 0b11000011, 0b01100110, 0b01100110, 0b00111100, 0b00011000,
};

#define big_font_1_width 8
#define big_font_1_height 13
static unsigned char big_font_1_bitmap[] = {
0b00011000, 0b00011100, 0b00011110, 0b00011011, 0b00011000, 0b00011000, 0b00011000,
0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b11111111,
};

#define big_font_2_width 8
#define big_font_2_height 13
static unsigned char big_font_2_bitmap[] = {
0b00111100, 0b01100110, 0b11000011, 0b11000011, 0b11000000, 0b11000000, 0b01100000,
0b00111000, 0b00001100, 0b00000110, 0b00000011, 0b00000011, 0b11111111,
};

#define big_font_3_width 8
#define big_font_3_height 13
static unsigned char big_font_3_bitmap[] = {
0b00111100, 0b01100110, 0b11000011, 0b11000011, 0b11000000, 0b01100000, 0b00111000,
0b01100000, 0b11000000, 0b11000011, 0b11000011, 0b01100110, 0b00111100,
};

#define big_font_4_width 8
#define big_font_4_height 13
static unsigned char big_font_4_bitmap[] = {
0b01100000, 0b01110000, 0b01111000, 0b01101100, 0b01100110, 0b01100011, 0b01100011,
0b11111111, 0b01100000, 0b01100000, 0b01100000, 0b01100000, 0b01100000,
};

#define big_font_5_width 8
#define big_font_5_height 13
static unsigned char big_font_5_bitmap[] = {
0b11111111, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00111011, 0b01100111,
0b11000000, 0b11000000, 0b11000000, 0b11000011, 0b01100110, 0b00111100,
};

#define big_font_6_width 8
#define big_font_6_height 13
static unsigned char big_font_6_bitmap[] = {
0b00111100, 0b01100110, 0b01000011, 0b00000011, 0b00000011, 0b00111011, 0b01100111,
0b11000011, 0b11000011, 0b11000011, 0b11000011, 0b01100110, 0b00111100,
};

#define big_font_7_width 8
#define big_font_7_height 13
static unsigned char big_font_7_bitmap[] = {
0b11111111, 0b11000000, 0b11000000, 0b01100000, 0b01100000, 0b00110000, 0b00110000,
0b00011000, 0b00011000, 0b00001100, 0b00001100, 0b00000110, 0b00000110,
};

#define big_font_8_width 8
#define big_font_8_height 13
static unsigned char big_font_8_bitmap[] = {
0b00111100, 0b01100110, 0b11000011, 0b11000011, 0b11000011, 0b01100110, 0b00111100,
0b01100110, 0b11000011, 0b11000011, 0b11000011, 0b01100110, 0b00111100,
};

#define big_font_9_width 8
#define big_font_9_height 13
static unsigned char big_font_9_bitmap[] = {
0b00111110, 0b11000011, 0b11000011, 0b11000011, 0b11000011, 0b11000011, 0b11100110,
0b11011100, 0b11000000, 0b11000000, 0b11000010, 0b01100110, 0b00111100,
};

#define big_font_A_width 8
#define big_font_A_height 10
static unsigned char big_font_A_bitmap[] = {
0b00011110, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00111111, 0b00110011, 0b00110011, 0b00110011,
};

#define big_font_C_width 8
#define big_font_C_height 10
static unsigned char big_font_C_bitmap[] = {
0b00011110, 0b00110011, 0b00110011, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00110011, 0b00110011, 0b00011110,
};

#define big_font_D_width 8
#define big_font_D_height 10
static unsigned char big_font_D_bitmap[] = {
0b00001111, 0b00011011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00011011, 0b00001111,
};

#define big_font_E_width 8
#define big_font_E_height 10
static unsigned char big_font_E_bitmap[] = {
0b00111111, 0b00000011, 0b00000011, 0b00000011, 0b00011111, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00111111,
};

#define big_font_G_width 8
#define big_font_G_height 10
static unsigned char big_font_G_bitmap[] = {
0b00011110, 0b00110011, 0b00110011, 0b00000011, 0b00000011, 0b00111011, 0b00110011, 0b00110011, 0b00110011, 0b00011110,
};

#define big_font_H_width 8
#define big_font_H_height 10
static unsigned char big_font_H_bitmap[] = {
0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00111111, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011,
};

#define big_font_I_width 8
#define big_font_I_height 10
static unsigned char big_font_I_bitmap[] = {
0b00111111, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00111111,
};

#define big_font_L_width 8
#define big_font_L_height 10
static unsigned char big_font_L_bitmap[] = {
0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00000011, 0b00111111,
};

#define big_font_M_width 8
#define big_font_M_height 10
static unsigned char big_font_M_bitmap[] = {
0b00100001, 0b00110011, 0b00110011, 0b00111111, 0b00111111, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011,
};

#define big_font_N_width 8
#define big_font_N_height 10
static unsigned char big_font_N_bitmap[] = {
0b00110011, 0b00110011, 0b00110111, 0b00110111, 0b00110111, 0b00111011, 0b00111011, 0b00111011, 0b00110011, 0b00110011,
};

#define big_font_O_width 8
#define big_font_O_height 10
static unsigned char big_font_O_bitmap[] = {
0b00011110, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00011110,
};

#define big_font_P_width 8
#define big_font_P_height 10
static unsigned char big_font_P_bitmap[] = {
0b00011111, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00011111, 0b00000011, 0b00000011, 0b00000011, 0b00000011,
};

#define big_font_R_width 8
#define big_font_R_height 10
static unsigned char big_font_R_bitmap[] = {
0b00011111, 0b00110011, 0b00110011, 0b00110011, 0b00011111, 0b00011011, 0b00110011, 0b00110011, 0b00110011, 0b00110011,
};

#define big_font_S_width 8
#define big_font_S_height 10
static unsigned char big_font_S_bitmap[] = {
0b00011110, 0b00110011, 0b00110011, 0b00000110, 0b00001100, 0b00001100, 0b00011000, 0b00110011, 0b00110011, 0b00011110,
};

#define big_font_T_width 8
#define big_font_T_height 10
static unsigned char big_font_T_bitmap[] = {
0b00111111, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100, 0b00001100,
};

#define big_font_V_width 8
#define big_font_V_height 10
static unsigned char big_font_V_bitmap[] = {
0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00110011, 0b00011110, 0b00011110, 0b00001100,
};

#define big_font_X_width 8
#define big_font_X_height 10
static unsigned char big_font_X_bitmap[] = {
0b00110011, 0b00110011, 0b00011110, 0b00011110, 0b00001100, 0b00001100, 0b00011110, 0b00011110, 0b00110011, 0b00110011,
};

/*************/
/* functions */
/*************/
extern int SmallTextWidth( const char* string, unsigned int length );
extern int BigTextWidth( const char* string, unsigned int length );
extern void ui_init_LCD( void );

#endif /* _UI_INNER_H */
Loading

0 comments on commit eb2a8bc

Please sign in to comment.