Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: GR-PEACH_TFTLCD_8bit
Fork of TFTLCD_8bit by
Diff: lcd_base.cpp
- Revision:
- 21:e5c1e8ffada1
- Parent:
- 20:4bdca8d8dadc
- Child:
- 22:4c169297f374
diff -r 4bdca8d8dadc -r e5c1e8ffada1 lcd_base.cpp
--- a/lcd_base.cpp Fri Dec 21 06:05:15 2012 +0000
+++ b/lcd_base.cpp Sat Jan 26 02:55:46 2013 +0000
@@ -27,7 +27,7 @@
{
SetForeground();
SetBackground();
- _font.font = 0;
+ _font = &TerminusFont;
}
inline
@@ -42,13 +42,9 @@
_background = color;
}
-void LCD::SetFont( const char *font )
+void LCD::SetFont( const font_t *font )
{
- _font.font = font;
- _font.width = font[ 0 ];
- _font.height = font[ 1 ];
- _font.offset = font[ 2 ];
- _font.numchars = font[ 3 ];
+ _font = font;
}
inline
@@ -65,6 +61,20 @@
return _disp_height;
}
+inline
+uint8_t LCD::GetFontWidth( void )
+{
+ if ( _font != 0 ) return _font->Width;
+ return 0;
+}
+
+inline
+uint8_t LCD::GetFontHeight( void )
+{
+ if ( _font != 0 ) return _font->Height;
+ return 0;
+}
+
void LCD::FillScreen( int color )
{
unsigned int rgb = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
@@ -314,13 +324,13 @@
stl = strlen( str );
if ( x == RIGHT )
- x = GetWidth() - ( stl * _font.width );
+ x = GetWidth() - ( stl * _font->Width );
if ( x == CENTER )
- x = ( GetWidth() - ( stl * _font.width ) ) / 2;
+ x = ( GetWidth() - ( stl * _font->Width ) ) / 2;
for ( i = 0; i < stl; i++ )
if ( deg == 0 )
- PrintChar( *str++, x + ( i * ( _font.width ) ), y, fgColor, bgColor );
+ PrintChar( *str++, x + ( i * ( _font->Width ) ), y, fgColor, bgColor );
else
RotateChar( *str++, x, y, i, fgColor, bgColor, deg );
}
@@ -482,26 +492,26 @@
{
uint8_t i, ch;
uint16_t j;
- uint16_t temp;
unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor;
unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor;
-
+
+ uint16_t totalCharBytes = ( _font->Width * _font->Height ) / 8;
+ int16_t position = _font->Position[ c - _font->Offset ];
+ if ( position == -1 ) position = 0; // will print space character
+
Activate();
- SetXY( x, y, x + _font.width - 1, y + _font.height - 1 );
-
- temp = ( ( c - _font.offset ) * ( ( _font.width / 8 ) * _font.height ) ) + 4;
- for ( j = 0; j < ( ( _font.width / 8 ) * _font.height ); j++ )
+ SetXY( x, y, x + _font->Width - 1, y + _font->Height - 1 );
+
+ for ( j = 0; j < totalCharBytes; j++ )
{
- ch = _font.font[ temp ];
+ ch = _font->Data[ position ];
for ( i = 0; i < 8; i++ )
{
- if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 )
- SetPixelColor( usedColorFG );
- else
- SetPixelColor( usedColorBG );
+ if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG );
+ else SetPixelColor( usedColorBG );
}
- temp++;
+ position++;
}
Deactivate();
}
@@ -509,7 +519,6 @@
void LCD::RotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor, int bgColor, unsigned short deg )
{
uint8_t i, j, ch;
- uint16_t temp;
int newx, newy;
double radian;
radian = deg * 0.0175;
@@ -517,28 +526,29 @@
unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor;
unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor;
+ int16_t position = _font->Position[ c - _font->Offset ];
+ if ( position == -1 ) position = 0; // will print space character
+
Activate();
-
- temp = ( ( c - _font.offset ) * ( ( _font.width / 8 ) * _font.height ) ) + 4;
- for ( j = 0; j < _font.height; j++ )
+
+ for ( j = 0; j < _font->Height; j++ )
{
- for ( int zz = 0; zz < ( _font.width / 8 ); zz++ )
+ for ( uint16_t zz = 0; zz < ( ( double ) _font->Width / 8 ); zz++ )
{
- ch = _font.font[ temp + zz ];
+ ch = _font->Data[ position + zz ];
for ( i = 0; i < 8; i++ )
{
- newx = x + ( ( ( i + ( zz * 8 ) + ( pos * _font.width ) ) * cos( radian ) ) - ( ( j ) * sin( radian ) ) );
- newy = y + ( ( ( j ) * cos( radian ) ) + ( ( i + ( zz * 8 ) + ( pos * _font.width ) ) * sin( radian ) ) );
+ newx = x + ( ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * cos( radian ) ) - ( ( j ) * sin( radian ) ) );
+ newy = y + ( ( ( j ) * cos( radian ) ) + ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * sin( radian ) ) );
SetXY( newx, newy, newx + 1, newy + 1 );
- if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 )
- SetPixelColor( usedColorFG );
- else
- SetPixelColor( usedColorBG );
+ if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG );
+ else SetPixelColor( usedColorBG );
}
}
- temp += ( _font.width / 8 );
+ position += ( _font->Width / 8 );
}
+
Deactivate();
}
