📄 ui.c
字号:
{ FONT_CHAR_ARM, 6, 208, UI_FLAG_ARM_LOGO },
{ FONT_CHAR_UP, 10, 208, UI_FLAG_SHIFT },
{ ' ', 14, 208, 0 },
{ FONT_CHAR_BACKSPACE, 30, 208, 0 },
{ FONT_CHAR_RUN, 36, 208, 0 },
//
// The next three are used for calibration of the touch screen.
//
//{ 'X', (48 - 16) / 8, 36 - 16, 0 },
//{ 'X', (160 - 16) / 8, 204 - 16, 0 },
//{ 'X', (272 - 16) / 8, 120 - 16, 0 },
};
//*****************************************************************************
//
//! The buttons to be displayed in diagnostic mode.
//
//*****************************************************************************
static const tButton g_sDiagButtons[] =
{
{ 'L', 0, 62, 0x81 },
{ '-', 8, 62, CMD_X_MINUS },
{ '+', 28, 62, CMD_X_PLUS },
{ 'L', 36, 62, 0x82 },
{ 'L', 0, 104, 0x84 },
{ '-', 8, 104, CMD_Y_MINUS },
{ '+', 28, 104, CMD_Y_PLUS },
{ 'L', 36, 104, 0x88 },
{ 'L', 0, 146, 0x90 },
{ '-', 8, 146, CMD_Z_MINUS },
{ '+', 28, 146, CMD_Z_PLUS },
{ 'L', 36, 146, 0xa0 },
{ 'P', 0, 208, 0xc0 },
{ 'S', 18, 208, CMD_SHIP },
{ FONT_CHAR_BACKSPACE, 36, 208, 0x80 }
};
//*****************************************************************************
//
//! Decompresses a single glyph from the compressed raster font.
//!
//! \param ulIdx is the index of the character to be decompressed.
//!
//! This function will decompress a single glyph from the compressed raster
//! font in flash, storing it into a temporary buffer in SRAM (in #g_pucChar).
//! Each time this function is called, the previously decompressed glyph is
//! overwritten with the data for the new glyph.
//!
//! \return None.
//
//*****************************************************************************
static void
UIDecompress(unsigned long ulIdx)
{
unsigned long ulLoop, ulByte, ulI, ulData, ulCount;
const unsigned char *pucData;
//
// Get a pointer to the glyph to be decompressed.
//
pucData = g_ppucFont24x32[ulIdx];
//
// Write the decompressed glyph starting from the beginning of the buffer.
//
ulByte = 0;
//
// Initially, there is no data in the local buffer.
//
ulData = 0;
ulCount = 0;
//
// Loop over the byes in the compressed glyph.
//
for(ulLoop = 0; ulLoop < pucData[0]; )
{
//
// See if this is a literal or encoded value.
//
if(pucData[ulLoop + 1] == 0x00)
{
//
// This is a literal value, so see if it is a literal sequence or
// a repeated value.
//
if((pucData[ulLoop + 2] & 0x80) == 0x00)
{
//
// This is a literal sequence, so copy the specified number of
// bytes from the compressed glyph to the decompressed glyph.
//
for(ulI = 0; ulI < (pucData[ulLoop + 2] & 0x7f); ulI++)
{
g_pucChar[ulByte++] = pucData[ulLoop + ulI + 3];
}
//
// Skip past the literal sequence.
//
ulLoop += 2 + pucData[ulLoop + 2];
}
else
{
//
// This is a repeated value, so copy the specified number of
// instances of the repeated byte to the decompressed glyph.
//
for(ulI = 0; ulI < (pucData[ulLoop + 2] & 0x7f); ulI++)
{
g_pucChar[ulByte++] = pucData[ulLoop + 3];
}
//
// Skip past the repeated sequence.
//
ulLoop += 3;
}
}
else
{
//
// The first part of the encoded value is the number of zero bits
// to insert. Place them into the local data buffer.
//
ulCount += pucData[ulLoop + 1] >> 4;
//
// Write any full bytes from the local data buffer to the
// decompressed glyph buffer.
//
while(ulCount >= 8)
{
//
// Write the next byte to the decompressed glyph buffer.
//
g_pucChar[ulByte++] = ulData >> 24;
//
// Remove the byte from the local data buffer.
//
ulData <<= 8;
//
// Decrement the count of bits in the local data buffer.
//
ulCount -= 8;
}
//
// Get the couunt of one bits to insert.
//
ulI = pucData[ulLoop + 1] & 15;
//
// Place the one bits into the local data buffer.
//
ulData |= ((1 << ulI) - 1) << (32 - ulCount - ulI);
//
// Increment the count of bits in the local data buffer.
//
ulCount += ulI;
//
// Write any full bytes from the local data buffer to the
// decompressed glyph buffer.
//
while(ulCount >= 8)
{
//
// Write the next byte to the decompressed glyph buffer.
//
g_pucChar[ulByte++] = ulData >> 24;
//
// Remove the byte from the local data buffer.
//
ulData <<= 8;
//
// Decrement the count of bits in the local data buffer.
//
ulCount -= 8;
}
//
// Skip past this encoded value.
//
ulLoop++;
}
}
}
//*****************************************************************************
//
//! Determines the width of a string in pixels.
//!
//! \param pucString is the string whose width is desired.
//!
//! This will determine the number of horizontal pixles required to render a
//! given string (taking into consideration the proportionally spaced nature of
//! the font). This can be used to determine when a string is too long to
//! display, or to not display characters from the beginning as a simplistic
//! scrolling mechanism.
//!
//! \return The number of horizontal pixels required to display the given
//! string.
//
//*****************************************************************************
static unsigned long
UIStringWidthGet(const unsigned char *pucString)
{
unsigned long ulWidth;
//
// The initial accumulated width is zero pixels.
//
ulWidth = 0;
//
// Loop over all the characters in this string.
//
while(*pucString)
{
//
// Add the width of this character.
//
ulWidth += g_pucFont24x32Width[*pucString++ - ' '] + 3;
}
//
// Return accumulated width, minus the three spacing columns at the end
// (which aren't needed since there are no characters following).
//
return(ulWidth - 3);
}
//*****************************************************************************
//
//! Draws a string on the LCD.
//!
//! \param pucString is the string to be displayed.
//! \param ulX is the horizontal location to display the string, specified in
//! bytes (groups of eight columns) to the right of the left column.
//! \param ulY is the vertical location to display the string, specified in
//! scan lines down from the top scan line.
//! \param ulWidth is the maximum width of the displayed string, specified in
//! bytes (groups of eight columns).
//! \param bBackLayer is a boolean that is true of the image should be
//! displayed on the second frame buffer (i.e. the back layer) and false if it
//! should be displayed on the first frame buffer.
//!
//! This routine will display a string on the LCD with a proportionally spaced
//! font. The string will consume thirty two scan lines, and a width
//! determined by the minimum of the width of the string itself or the maximum
//! allowed width as provided by the \e ulWidth parameter. Because of the
//! proportional nature of the font, the LCDStringWidthGet() function can be
//! used to determine the actual width of the LCD required for a string.
//!
//! The portion of the LCD used to render the string is completely overwritten,
//! losing any content that was previous on the LCD.
//!
//! \return None.
//
//*****************************************************************************
static void
UIStringDraw(const unsigned char *pucString, unsigned long ulX,
unsigned long ulY, unsigned long ulWidth, tBoolean bBackLayer)
{
unsigned long ulPos, ulFirst, ulData, ulIdx;
const unsigned char *pucFont;
unsigned char ucChar;
//
// Convert the width into the maximum column allowed.
//
ulWidth += ulX;
//
// Clear the first byte column of the temporary buffer and set the number
// of pixel columns of actual data to zero.
//
for(ulIdx = 0; ulIdx < 32; ulIdx++)
{
g_pucTemp[ulIdx] = 0;
}
ulPos = 0;
//
// Loop while there are still characters in the string.
//
while(*pucString)
{
//
// Get the next character from the string, and convert it into an
// offset into the front.
//
ucChar = *pucString++ - ' ';
//
// Decompress the glyph for this character and get a pointer to it.
//
UIDecompress(ucChar);
pucFont = g_pucChar;
//
// Get the first pixel column of this glyph.
//
ulFirst = g_pucFont24x32First[ucChar];
//
// Loop over the scan lines of this glyph.
//
for(ulIdx = 0; ulIdx < 32; ulIdx++)
{
//
// Read the next scan line from the glyph.
//
ulData = ((pucFont[0] << 24) | (pucFont[1] << 16) |
(pucFont[2] << 8));
pucFont += 3;
//
// Shift the scan line data so that the first pixel column of the
// glyph is in the MSB of ulData.
//
ulData <<= ulFirst;
//
// Copy this character's glpyh into the temporary buffer.
//
g_pucTemp[ulIdx] |= ulData >> (ulPos + 24);
g_pucTemp[ulIdx + 32] = (ulData >> (ulPos + 16)) & 0xff;
g_pucTemp[ulIdx + 64] = (ulData >> (ulPos + 8)) & 0xff;
g_pucTemp[ulIdx + 96] = (ulData >> ulPos) & 0xff;
}
//
// Add this glyph's width, plus three spacing columns, to the number of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -