mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-06-20 06:58:39 +03:00
Added fagci's teeny teeny font
This commit is contained in:
141
ui/helper.c
141
ui/helper.c
@ -32,7 +32,7 @@ void UI_GenerateChannelString(char *pString, const uint8_t Channel, const char s
|
||||
|
||||
if (pString == NULL)
|
||||
return;
|
||||
|
||||
|
||||
if (g_input_box_index == 0)
|
||||
{
|
||||
sprintf(pString, "CH%c%02u", separating_char, Channel + 1);
|
||||
@ -50,7 +50,7 @@ void UI_GenerateChannelStringEx(char *pString, const char *prefix, const uint8_t
|
||||
{
|
||||
if (pString == NULL)
|
||||
return;
|
||||
|
||||
|
||||
if (g_input_box_index > 0)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -60,10 +60,10 @@ void UI_GenerateChannelStringEx(char *pString, const char *prefix, const uint8_t
|
||||
}
|
||||
|
||||
pString[0] = 0;
|
||||
|
||||
|
||||
if (prefix)
|
||||
strcpy(pString, prefix);
|
||||
|
||||
|
||||
if (ChannelNumber == 0xFF)
|
||||
strcpy(pString, "NULL");
|
||||
else
|
||||
@ -90,65 +90,110 @@ void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Lin
|
||||
}
|
||||
}
|
||||
|
||||
void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
|
||||
void UI_print_string(
|
||||
const char *str,
|
||||
unsigned int start,
|
||||
const unsigned int end,
|
||||
const unsigned int line,
|
||||
const uint8_t *font,
|
||||
const unsigned int font_size,
|
||||
const unsigned int char_width)
|
||||
{
|
||||
const size_t Length = strlen(pString);
|
||||
size_t i;
|
||||
|
||||
if (End > Start)
|
||||
Start += (((End - Start) - (Length * 7)) + 1) / 2;
|
||||
|
||||
const unsigned int char_width = ARRAY_SIZE(g_font_small[0]);
|
||||
const unsigned int char_spacing = char_width + 1;
|
||||
uint8_t *pFb = g_frame_buffer[Line] + Start;
|
||||
for (i = 0; i < Length; i++)
|
||||
const size_t length = strlen(str);
|
||||
unsigned int i;
|
||||
uint8_t *f_buf;
|
||||
|
||||
if (end > start)
|
||||
start += (((end - start) - (length * (char_width - 1))) + 1) / 2;
|
||||
|
||||
f_buf = g_frame_buffer[line] + start;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if (pString[i] >= 32)
|
||||
{
|
||||
const unsigned int index = (unsigned int)pString[i] - 32;
|
||||
if (index < ARRAY_SIZE(g_font_small))
|
||||
memmove(pFb + (i * char_spacing) + 1, &g_font_small[index], char_width);
|
||||
}
|
||||
const int c = (int)str[i] - ' ';
|
||||
if (c >= 0 && c < (int)font_size)
|
||||
memmove(f_buf + (char_spacing * i) + 1, font + (char_width * c), char_width);
|
||||
}
|
||||
}
|
||||
|
||||
void UI_PrintStringSmall(const char *str, const unsigned int start, const unsigned int end, const unsigned int line)
|
||||
{
|
||||
UI_print_string(str, start, end, line, (const uint8_t *)g_font_small, ARRAY_SIZE(g_font_small), ARRAY_SIZE(g_font_small[0]));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SMALL_BOLD
|
||||
void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line)
|
||||
void UI_PrintStringSmallBold(const char *str, const unsigned int start, const unsigned int end, const unsigned int line)
|
||||
{
|
||||
const size_t Length = strlen(pString);
|
||||
size_t i;
|
||||
|
||||
if (End > Start)
|
||||
Start += (((End - Start) - (Length * 7)) + 1) / 2;
|
||||
|
||||
const unsigned int char_width = ARRAY_SIZE(g_font_small_bold[0]);
|
||||
const unsigned int char_spacing = char_width + 1;
|
||||
uint8_t *pFb = g_frame_buffer[Line] + Start;
|
||||
for (i = 0; i < Length; i++)
|
||||
{
|
||||
if (pString[i] >= 32)
|
||||
{
|
||||
const unsigned int index = (unsigned int)pString[i] - 32;
|
||||
if (index < ARRAY_SIZE(g_font_small_bold))
|
||||
memmove(pFb + (i * char_spacing) + 1, &g_font_small_bold[index], char_width);
|
||||
}
|
||||
}
|
||||
UI_print_string(str, start, end, line, (const uint8_t *)g_font_small_bold, ARRAY_SIZE(g_font_small_bold), ARRAY_SIZE(g_font_small_bold[0]));
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
void UI_PrintStringSmall4x5(const char *str, const unsigned int start, const unsigned int end, const unsigned int line)
|
||||
{
|
||||
UI_print_string(str, start, end, line, (const uint8_t *)g_font_small_4x5, ARRAY_SIZE(g_font_small_4x5), ARRAY_SIZE(g_font_small_4x5[0]));
|
||||
}
|
||||
*/
|
||||
|
||||
void PutPixel(const unsigned int x, const unsigned int y, const bool fill)
|
||||
{
|
||||
if (fill)
|
||||
g_frame_buffer[y >> 3][x] |= 1u << (y & 7u);
|
||||
else
|
||||
g_frame_buffer[y >> 3][x] &= ~(1u << (y & 7u));
|
||||
}
|
||||
|
||||
void PutPixelStatus(const unsigned int x, const unsigned int y, bool fill)
|
||||
{
|
||||
if (fill)
|
||||
g_status_line[x] |= 1u << y;
|
||||
else
|
||||
g_status_line[x] &= ~(1u << y);
|
||||
}
|
||||
|
||||
void UI_PrintStringSmallest(const void *pString, unsigned int x, const unsigned int y, const bool statusbar, const bool fill)
|
||||
{
|
||||
const unsigned int char_width = ARRAY_SIZE(g_font3x5[0]);
|
||||
const unsigned int char_height = 5;
|
||||
// const uint8_t pixel_mask = (1u << char_height) - 1;
|
||||
const uint8_t *p = (const uint8_t *)pString;
|
||||
int c;
|
||||
|
||||
while ((c = *p++) != 0)
|
||||
{
|
||||
c -= ' ';
|
||||
if (c >= 0 && c < (int)ARRAY_SIZE(g_font3x5))
|
||||
{
|
||||
for (unsigned int xx = 0; xx < char_width; xx++)
|
||||
{
|
||||
uint8_t pixels = g_font3x5[c][xx];
|
||||
if (statusbar)
|
||||
{
|
||||
for (unsigned int yy = 0; yy <= char_height; yy++, pixels >>= 1)
|
||||
if (pixels & 1u)
|
||||
PutPixelStatus(x + xx, y + yy, fill);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int yy = 0; yy <= char_height; yy++, pixels >>= 1)
|
||||
if (pixels & 1u)
|
||||
PutPixel(x + xx, y + yy, fill);
|
||||
}
|
||||
}
|
||||
}
|
||||
x += char_width + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void UI_PrintStringSmallBuffer(const char *pString, uint8_t *buffer)
|
||||
{
|
||||
size_t i;
|
||||
const unsigned int char_width = ARRAY_SIZE(g_font_small[0]);
|
||||
const unsigned int char_spacing = char_width + 1;
|
||||
unsigned int i;
|
||||
for (i = 0; i < strlen(pString); i++)
|
||||
{
|
||||
if (pString[i] >= 32)
|
||||
{
|
||||
const unsigned int index = (unsigned int)pString[i] - 32;
|
||||
if (index < ARRAY_SIZE(g_font_small))
|
||||
memmove(buffer + (i * char_spacing) + 1, &g_font_small[index], char_width);
|
||||
}
|
||||
const int c = (int)pString[i] - ' ';
|
||||
if (c >= 0 && c < (int)ARRAY_SIZE(g_font_small))
|
||||
memmove(buffer + (i * char_spacing) + 1, &g_font_small[c], char_width);
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +204,7 @@ void UI_DisplayFrequency(const char *pDigits, uint8_t X, uint8_t Y, bool bDispla
|
||||
uint8_t *pFb1 = pFb0 + 128;
|
||||
bool bCanDisplay = false;
|
||||
unsigned int i = 0;
|
||||
|
||||
|
||||
// MHz
|
||||
while (i < 3)
|
||||
{
|
||||
@ -184,7 +229,7 @@ void UI_DisplayFrequency(const char *pDigits, uint8_t X, uint8_t Y, bool bDispla
|
||||
*pFb1 = 0x60; pFb0++; pFb1++;
|
||||
*pFb1 = 0x60; pFb0++; pFb1++;
|
||||
*pFb1 = 0x60; pFb0++; pFb1++;
|
||||
|
||||
|
||||
// kHz
|
||||
while (i < 6)
|
||||
{
|
||||
|
Reference in New Issue
Block a user