Forked from TFTLCD_8bit by Thiha Electronics

Dependents:   GR-PEACH_TFTLCD_8bit

Fork of TFTLCD_8bit by Thiha Electronics

Committer:
ThihaElectronics
Date:
Wed Dec 03 16:35:25 2014 +0000
Revision:
32:155abe4126e3
Parent:
31:9ca104de2f74
sorry if i broken any of your code by recent check in. please enlighten me how to unlink library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ttodorov 0:881ff0b71102 1 /*
ttodorov 0:881ff0b71102 2 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
ttodorov 0:881ff0b71102 3 * Copyright (C)2012 Todor Todorov.
ttodorov 0:881ff0b71102 4 *
ttodorov 0:881ff0b71102 5 * This library is free software; you can redistribute it and/or
ttodorov 0:881ff0b71102 6 * modify it under the terms of the GNU Lesser General Public
ttodorov 0:881ff0b71102 7 * License as published by the Free Software Foundation; either
ttodorov 0:881ff0b71102 8 * version 2.1 of the License, or (at your option) any later version.
ttodorov 0:881ff0b71102 9 *
ttodorov 0:881ff0b71102 10 * This library is distributed in the hope that it will be useful,
ttodorov 0:881ff0b71102 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ttodorov 0:881ff0b71102 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ttodorov 0:881ff0b71102 13 * Lesser General Public License for more details.
ttodorov 0:881ff0b71102 14 *
ttodorov 0:881ff0b71102 15 * You should have received a copy of the GNU Lesser General Public
ttodorov 0:881ff0b71102 16 * License along with this library; if not, write to:
ttodorov 0:881ff0b71102 17 *
ttodorov 0:881ff0b71102 18 * Free Software Foundation, Inc.
ttodorov 0:881ff0b71102 19 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
ttodorov 0:881ff0b71102 20 *
ttodorov 0:881ff0b71102 21 *********************************************************************/
ttodorov 0:881ff0b71102 22 #include "lcd_base.h"
ttodorov 3:64a5b67d5b51 23 #include "helpers.h"
ttodorov 0:881ff0b71102 24
ttodorov 22:4c169297f374 25 LCD::LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET, PinName BL, backlight_t blType, float defaultBacklight )
ttodorov 22:4c169297f374 26 : _disp_width( width ), _disp_height( height ), _lcd_pin_cs( CS ), _lcd_pin_rs( RS ), _lcd_pin_reset( RESET ), _bl_type( blType )
ttodorov 4:3ac4239f6c9c 27 {
ttodorov 4:3ac4239f6c9c 28 SetForeground();
ttodorov 4:3ac4239f6c9c 29 SetBackground();
ThihaElectronics 29:ad9d18445005 30 // _font = &TerminusFont;
ThihaElectronics 29:ad9d18445005 31 _font = &TerminusBigFont;
ttodorov 22:4c169297f374 32 if ( defaultBacklight < 0 ) _bl_pwm_default = 0;
ttodorov 22:4c169297f374 33 else if ( defaultBacklight > 1.0 ) _bl_pwm_default = 1.0;
ttodorov 22:4c169297f374 34 else _bl_pwm_default = defaultBacklight;
ttodorov 22:4c169297f374 35 if ( BL != NC )
ttodorov 22:4c169297f374 36 {
ttodorov 22:4c169297f374 37 if ( blType == Constant )
ttodorov 22:4c169297f374 38 {
ttodorov 22:4c169297f374 39 _bl_pwm = 0;
ttodorov 22:4c169297f374 40 _lcd_pin_bl = new DigitalOut( BL );
ttodorov 22:4c169297f374 41 }
ttodorov 22:4c169297f374 42 else
ttodorov 22:4c169297f374 43 {
ttodorov 22:4c169297f374 44 _lcd_pin_bl = 0;
ttodorov 22:4c169297f374 45 _bl_pwm = new PwmOut( BL );
ttodorov 22:4c169297f374 46 _bl_pwm->period_ms( 8.33 ); // 120 Hz
ttodorov 22:4c169297f374 47 _bl_pwm_current = _bl_pwm_default;
ttodorov 22:4c169297f374 48 // initially off
ttodorov 22:4c169297f374 49 *_bl_pwm = 0;
ttodorov 22:4c169297f374 50 }
ttodorov 22:4c169297f374 51
ttodorov 22:4c169297f374 52 }
ttodorov 22:4c169297f374 53 else
ttodorov 22:4c169297f374 54 {
ttodorov 22:4c169297f374 55 _lcd_pin_bl = 0;
ttodorov 22:4c169297f374 56 _bl_pwm = 0;
ttodorov 22:4c169297f374 57 }
ttodorov 22:4c169297f374 58 }
ttodorov 22:4c169297f374 59
ttodorov 22:4c169297f374 60 void LCD::Sleep( void )
ttodorov 22:4c169297f374 61 {
ttodorov 22:4c169297f374 62 if ( _lcd_pin_bl != 0 )
ttodorov 22:4c169297f374 63 *_lcd_pin_bl = LOW;
ttodorov 22:4c169297f374 64 else if ( _bl_pwm != 0 )
ttodorov 22:4c169297f374 65 *_bl_pwm = 0;
ttodorov 22:4c169297f374 66 }
ttodorov 22:4c169297f374 67
ttodorov 22:4c169297f374 68 void LCD::WakeUp( void )
ttodorov 22:4c169297f374 69 {
ttodorov 22:4c169297f374 70 if ( _lcd_pin_bl != 0 )
ttodorov 22:4c169297f374 71 *_lcd_pin_bl = HIGH;
ttodorov 22:4c169297f374 72 else if ( _bl_pwm != 0 )
ttodorov 22:4c169297f374 73 *_bl_pwm = _bl_pwm_current;
ttodorov 4:3ac4239f6c9c 74 }
ttodorov 0:881ff0b71102 75
ttodorov 0:881ff0b71102 76 inline
ttodorov 12:d0978272a340 77 void LCD::SetForeground( unsigned int color )
ttodorov 0:881ff0b71102 78 {
ttodorov 0:881ff0b71102 79 _foreground = color;
ttodorov 0:881ff0b71102 80 }
ttodorov 0:881ff0b71102 81
ttodorov 0:881ff0b71102 82 inline
ttodorov 12:d0978272a340 83 void LCD::SetBackground( unsigned int color )
ttodorov 0:881ff0b71102 84 {
ttodorov 0:881ff0b71102 85 _background = color;
ttodorov 0:881ff0b71102 86 }
ttodorov 0:881ff0b71102 87
ttodorov 21:e5c1e8ffada1 88 void LCD::SetFont( const font_t *font )
ttodorov 0:881ff0b71102 89 {
ttodorov 21:e5c1e8ffada1 90 _font = font;
ttodorov 0:881ff0b71102 91 }
ttodorov 0:881ff0b71102 92
ThihaElectronics 30:5f23a4cbebd7 93 //inline
ThihaElectronics 30:5f23a4cbebd7 94 unsigned short LCD::GetHeight( void )
ThihaElectronics 30:5f23a4cbebd7 95 {
ThihaElectronics 30:5f23a4cbebd7 96 if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_width;
ThihaElectronics 30:5f23a4cbebd7 97 return _disp_height;
ThihaElectronics 30:5f23a4cbebd7 98 }
ThihaElectronics 30:5f23a4cbebd7 99
ThihaElectronics 30:5f23a4cbebd7 100
ttodorov 0:881ff0b71102 101 inline
ttodorov 0:881ff0b71102 102 unsigned short LCD::GetWidth( void )
ttodorov 0:881ff0b71102 103 {
ttodorov 12:d0978272a340 104 if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_height;
ttodorov 0:881ff0b71102 105 return _disp_width;
ttodorov 0:881ff0b71102 106 }
ttodorov 0:881ff0b71102 107
ttodorov 0:881ff0b71102 108
ThihaElectronics 31:9ca104de2f74 109 //inline
ttodorov 21:e5c1e8ffada1 110 uint8_t LCD::GetFontWidth( void )
ttodorov 21:e5c1e8ffada1 111 {
ttodorov 21:e5c1e8ffada1 112 if ( _font != 0 ) return _font->Width;
ttodorov 21:e5c1e8ffada1 113 return 0;
ttodorov 21:e5c1e8ffada1 114 }
ttodorov 21:e5c1e8ffada1 115
ttodorov 21:e5c1e8ffada1 116 inline
ttodorov 21:e5c1e8ffada1 117 uint8_t LCD::GetFontHeight( void )
ttodorov 21:e5c1e8ffada1 118 {
ttodorov 21:e5c1e8ffada1 119 if ( _font != 0 ) return _font->Height;
ttodorov 21:e5c1e8ffada1 120 return 0;
ttodorov 21:e5c1e8ffada1 121 }
ttodorov 21:e5c1e8ffada1 122
ttodorov 22:4c169297f374 123 void LCD::SetBacklightLevel( float level )
ttodorov 22:4c169297f374 124 {
ttodorov 22:4c169297f374 125 switch ( _bl_type )
ttodorov 22:4c169297f374 126 {
ttodorov 22:4c169297f374 127 case Direct:
ttodorov 22:4c169297f374 128 if ( _bl_pwm != 0 )
ttodorov 22:4c169297f374 129 {
ttodorov 22:4c169297f374 130 *_bl_pwm = level;
ttodorov 22:4c169297f374 131 _bl_pwm_current = level;
ttodorov 22:4c169297f374 132 }
ttodorov 22:4c169297f374 133 break;
ttodorov 22:4c169297f374 134
ttodorov 22:4c169297f374 135 case Indirect:
ttodorov 22:4c169297f374 136 break;
ttodorov 22:4c169297f374 137 case Constant:
ttodorov 22:4c169297f374 138 default:
ttodorov 22:4c169297f374 139 break;
ttodorov 22:4c169297f374 140 }
ttodorov 22:4c169297f374 141 }
ttodorov 22:4c169297f374 142
ttodorov 0:881ff0b71102 143 void LCD::FillScreen( int color )
ttodorov 0:881ff0b71102 144 {
ttodorov 12:d0978272a340 145 unsigned int rgb = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 4:3ac4239f6c9c 146 Activate();
ttodorov 2:81ed304b7e9b 147 ClearXY();
ttodorov 1:14bef43daf6f 148 for ( int i = 0; i < ( ( _disp_width ) * ( _disp_height ) ); i++ )
ttodorov 10:69571adcfad5 149 SetPixelColor( rgb );
ttodorov 4:3ac4239f6c9c 150 Deactivate();
ttodorov 0:881ff0b71102 151 }
ttodorov 0:881ff0b71102 152
ttodorov 0:881ff0b71102 153 inline
ttodorov 0:881ff0b71102 154 void LCD::ClearScreen( void )
ttodorov 0:881ff0b71102 155 {
ttodorov 0:881ff0b71102 156 FillScreen( -1 );
ttodorov 0:881ff0b71102 157 }
ttodorov 0:881ff0b71102 158
ttodorov 0:881ff0b71102 159 void LCD::DrawPixel( unsigned short x, unsigned short y, int color )
ttodorov 0:881ff0b71102 160 {
ttodorov 4:3ac4239f6c9c 161 Activate();
ttodorov 2:81ed304b7e9b 162 SetXY( x, y, x, y );
ttodorov 10:69571adcfad5 163 SetPixelColor( color == -1 ? _background :
ttodorov 0:881ff0b71102 164 color == -2 ? _foreground : color );
ttodorov 4:3ac4239f6c9c 165 Deactivate();
ttodorov 0:881ff0b71102 166 }
ttodorov 0:881ff0b71102 167
ttodorov 0:881ff0b71102 168 void LCD::DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 169 {
ttodorov 0:881ff0b71102 170
ttodorov 0:881ff0b71102 171 double delta, tx, ty;
ttodorov 0:881ff0b71102 172
ttodorov 0:881ff0b71102 173 if ( ( ( x2 - x1 ) < 0 ) )
ttodorov 0:881ff0b71102 174 {
ttodorov 0:881ff0b71102 175 swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 176 swap( ushort, y1, y2 )
ttodorov 0:881ff0b71102 177 }
ttodorov 0:881ff0b71102 178 if ( ( ( y2 - y1 ) < 0 ) )
ttodorov 0:881ff0b71102 179 {
ttodorov 0:881ff0b71102 180 swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 181 swap( ushort, y1, y2 )
ttodorov 0:881ff0b71102 182 }
ttodorov 0:881ff0b71102 183
ttodorov 0:881ff0b71102 184 if ( y1 == y2 )
ttodorov 0:881ff0b71102 185 {
ttodorov 0:881ff0b71102 186 if ( x1 > x2 )
ttodorov 0:881ff0b71102 187 swap( ushort, x1, x2 )
ttodorov 2:81ed304b7e9b 188 DrawHLine( x1, y1, x2 - x1, color );
ttodorov 0:881ff0b71102 189 }
ttodorov 0:881ff0b71102 190 else if ( x1 == x2 )
ttodorov 0:881ff0b71102 191 {
ttodorov 0:881ff0b71102 192 if ( y1 > y2 )
ttodorov 0:881ff0b71102 193 swap( ushort, y1, y2 )
ttodorov 2:81ed304b7e9b 194 DrawVLine( x1, y1, y2 - y1, color );
ttodorov 0:881ff0b71102 195 }
ttodorov 4:3ac4239f6c9c 196 else
ttodorov 0:881ff0b71102 197 {
ttodorov 12:d0978272a340 198 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 4:3ac4239f6c9c 199 Activate();
ttodorov 4:3ac4239f6c9c 200 if ( abs( x2 - x1 ) > abs( y2 - y1 ) )
ttodorov 0:881ff0b71102 201 {
ttodorov 4:3ac4239f6c9c 202 delta = ( double( y2 - y1 ) / double( x2 - x1 ) );
ttodorov 4:3ac4239f6c9c 203 ty = double( y1 );
ttodorov 4:3ac4239f6c9c 204 if ( x1 > x2 )
ttodorov 0:881ff0b71102 205 {
ttodorov 4:3ac4239f6c9c 206 for ( int i = x1; i >= x2; i-- )
ttodorov 4:3ac4239f6c9c 207 {
ttodorov 4:3ac4239f6c9c 208 SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) );
ttodorov 10:69571adcfad5 209 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 210 ty = ty - delta;
ttodorov 4:3ac4239f6c9c 211 }
ttodorov 4:3ac4239f6c9c 212 }
ttodorov 4:3ac4239f6c9c 213 else
ttodorov 4:3ac4239f6c9c 214 {
ttodorov 4:3ac4239f6c9c 215 for ( int i = x1; i <= x2; i++ )
ttodorov 4:3ac4239f6c9c 216 {
ttodorov 4:3ac4239f6c9c 217 SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) );
ttodorov 10:69571adcfad5 218 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 219 ty = ty + delta;
ttodorov 4:3ac4239f6c9c 220 }
ttodorov 0:881ff0b71102 221 }
ttodorov 0:881ff0b71102 222 }
ttodorov 0:881ff0b71102 223 else
ttodorov 0:881ff0b71102 224 {
ttodorov 4:3ac4239f6c9c 225 delta = ( float( x2 - x1 ) / float( y2 - y1 ) );
ttodorov 4:3ac4239f6c9c 226 tx = float( x1 );
ttodorov 4:3ac4239f6c9c 227 if ( y1 > y2 )
ttodorov 0:881ff0b71102 228 {
ttodorov 4:3ac4239f6c9c 229 for ( int i = y2 + 1; i > y1; i-- )
ttodorov 4:3ac4239f6c9c 230 {
ttodorov 4:3ac4239f6c9c 231 SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i );
ttodorov 10:69571adcfad5 232 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 233 tx = tx + delta;
ttodorov 4:3ac4239f6c9c 234 }
ttodorov 4:3ac4239f6c9c 235 }
ttodorov 4:3ac4239f6c9c 236 else
ttodorov 4:3ac4239f6c9c 237 {
ttodorov 4:3ac4239f6c9c 238 for ( int i = y1; i < y2 + 1; i++ )
ttodorov 4:3ac4239f6c9c 239 {
ttodorov 4:3ac4239f6c9c 240 SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i );
ttodorov 10:69571adcfad5 241 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 242 tx = tx + delta;
ttodorov 4:3ac4239f6c9c 243 }
ttodorov 0:881ff0b71102 244 }
ttodorov 0:881ff0b71102 245 }
ttodorov 4:3ac4239f6c9c 246 Deactivate();
ttodorov 0:881ff0b71102 247 }
ttodorov 0:881ff0b71102 248 }
ThihaElectronics 30:5f23a4cbebd7 249 void LCD::DrawTriangle( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned short x3, unsigned short y3, int color )
ThihaElectronics 30:5f23a4cbebd7 250 {
ThihaElectronics 30:5f23a4cbebd7 251 // if ( x1 > x2 ) swap( ushort, x1, x2 )
ThihaElectronics 30:5f23a4cbebd7 252 // if ( y1 > y2 ) swap( ushort, y1, y2 )
ThihaElectronics 30:5f23a4cbebd7 253
ThihaElectronics 30:5f23a4cbebd7 254 DrawLine( x1, y1, x2, y2, color );
ThihaElectronics 30:5f23a4cbebd7 255 DrawLine( x2, y2, x3, y3, color );
ThihaElectronics 30:5f23a4cbebd7 256 DrawLine( x3, y3, x1, y1, color );
ThihaElectronics 30:5f23a4cbebd7 257 }
ThihaElectronics 30:5f23a4cbebd7 258
ThihaElectronics 30:5f23a4cbebd7 259 void LCD::FillTriangle( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned short x3, unsigned short y3, int color )
ThihaElectronics 30:5f23a4cbebd7 260 {
ThihaElectronics 30:5f23a4cbebd7 261 int dx1, dx2, dx3;
ThihaElectronics 30:5f23a4cbebd7 262 int sx1, sx2, sy;
ThihaElectronics 30:5f23a4cbebd7 263
ThihaElectronics 30:5f23a4cbebd7 264
ThihaElectronics 30:5f23a4cbebd7 265 if ( y1 > y2 ) { swap( ushort, y1, y2 ); swap( ushort, x1, x2 ); }
ThihaElectronics 30:5f23a4cbebd7 266 if ( y2 > y3 ) { swap( ushort, y3, y2 ); swap( ushort, x3, x2 ); }
ThihaElectronics 30:5f23a4cbebd7 267 if ( y1 > y2 ) { swap( ushort, y1, y2 ); swap( ushort, x1, x2 ); }
ThihaElectronics 30:5f23a4cbebd7 268
ThihaElectronics 30:5f23a4cbebd7 269 sx2= x1 * 1000; // Use fixed point math for x axis values
ThihaElectronics 30:5f23a4cbebd7 270 sx1 = sx2;
ThihaElectronics 30:5f23a4cbebd7 271 sy=y1;
ThihaElectronics 30:5f23a4cbebd7 272
ThihaElectronics 30:5f23a4cbebd7 273 // Calculate interpolation deltas
ThihaElectronics 30:5f23a4cbebd7 274 if (y2-y1 > 0) dx1=((x2-x1)*1000)/(y2-y1);
ThihaElectronics 30:5f23a4cbebd7 275 else dx1=0;
ThihaElectronics 30:5f23a4cbebd7 276 if (y3-y1 > 0) dx2=((x3-x1)*1000)/(y3-y1);
ThihaElectronics 30:5f23a4cbebd7 277 else dx2=0;
ThihaElectronics 30:5f23a4cbebd7 278 if (y3-y2 > 0) dx3=((x3-x2)*1000)/(y3-y2);
ThihaElectronics 30:5f23a4cbebd7 279 else dx3=0;
ThihaElectronics 30:5f23a4cbebd7 280
ThihaElectronics 30:5f23a4cbebd7 281 // Render scanlines (horizontal lines are the fastest rendering method)
ThihaElectronics 30:5f23a4cbebd7 282 if (dx1 > dx2)
ThihaElectronics 30:5f23a4cbebd7 283 {
ThihaElectronics 30:5f23a4cbebd7 284 for(; sy<=y2; sy++, sx1+=dx2, sx2+=dx1)
ThihaElectronics 30:5f23a4cbebd7 285 {
ThihaElectronics 30:5f23a4cbebd7 286 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
ThihaElectronics 30:5f23a4cbebd7 287 }
ThihaElectronics 30:5f23a4cbebd7 288 sx2 = x2*1000;
ThihaElectronics 30:5f23a4cbebd7 289 sy = y2;
ThihaElectronics 30:5f23a4cbebd7 290 for(; sy<=y3; sy++, sx1+=dx2, sx2+=dx3)
ThihaElectronics 30:5f23a4cbebd7 291 {
ThihaElectronics 30:5f23a4cbebd7 292 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
ThihaElectronics 30:5f23a4cbebd7 293 }
ThihaElectronics 30:5f23a4cbebd7 294 }
ThihaElectronics 30:5f23a4cbebd7 295 else
ThihaElectronics 30:5f23a4cbebd7 296 {
ThihaElectronics 30:5f23a4cbebd7 297 for(; sy<=y2; sy++, sx1+=dx1, sx2+=dx2)
ThihaElectronics 30:5f23a4cbebd7 298 {
ThihaElectronics 30:5f23a4cbebd7 299 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
ThihaElectronics 30:5f23a4cbebd7 300 }
ThihaElectronics 30:5f23a4cbebd7 301 sx1 = x2*1000;
ThihaElectronics 30:5f23a4cbebd7 302 sy = y2;
ThihaElectronics 30:5f23a4cbebd7 303 for(; sy<=y3; sy++, sx1+=dx3, sx2+=dx2)
ThihaElectronics 30:5f23a4cbebd7 304 {
ThihaElectronics 30:5f23a4cbebd7 305 DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
ThihaElectronics 30:5f23a4cbebd7 306 }
ThihaElectronics 30:5f23a4cbebd7 307 }
ThihaElectronics 30:5f23a4cbebd7 308
ThihaElectronics 30:5f23a4cbebd7 309 }
ttodorov 0:881ff0b71102 310
ttodorov 0:881ff0b71102 311 void LCD::DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 312 {
ttodorov 0:881ff0b71102 313 if ( x1 > x2 ) swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 314 if ( y1 > y2 ) swap( ushort, y1, y2 )
ttodorov 0:881ff0b71102 315
ttodorov 2:81ed304b7e9b 316 DrawHLine( x1, y1, x2 - x1, color );
ttodorov 2:81ed304b7e9b 317 DrawHLine( x1, y2, x2 - x1, color );
ttodorov 2:81ed304b7e9b 318 DrawVLine( x1, y1, y2 - y1, color );
ttodorov 2:81ed304b7e9b 319 DrawVLine( x2, y1, y2 - y1, color );
ttodorov 0:881ff0b71102 320 }
ttodorov 0:881ff0b71102 321
ttodorov 0:881ff0b71102 322 void LCD::DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 323 {
ttodorov 0:881ff0b71102 324 if ( x1 > x2 ) swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 325 if ( y1 > y2 ) swap( ushort, y1, y2 )
ttodorov 0:881ff0b71102 326
ttodorov 0:881ff0b71102 327 if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 )
ttodorov 0:881ff0b71102 328 {
ttodorov 0:881ff0b71102 329 DrawPixel( x1 + 1, y1 + 1, color );
ttodorov 0:881ff0b71102 330 DrawPixel( x2 - 1, y1 + 1, color );
ttodorov 0:881ff0b71102 331 DrawPixel( x1 + 1, y2 - 1, color );
ttodorov 0:881ff0b71102 332 DrawPixel( x2 - 1, y2 - 1, color );
ttodorov 2:81ed304b7e9b 333 DrawHLine( x1 + 2, y1, x2 - x1 - 4, color );
ttodorov 2:81ed304b7e9b 334 DrawHLine( x1 + 2, y2, x2 - x1 - 4, color );
ttodorov 2:81ed304b7e9b 335 DrawVLine( x1, y1 + 2, y2 - y1 - 4, color );
ttodorov 2:81ed304b7e9b 336 DrawVLine( x2, y1 + 2, y2 - y1 - 4, color );
ttodorov 0:881ff0b71102 337 }
ttodorov 0:881ff0b71102 338 }
ttodorov 0:881ff0b71102 339
ttodorov 0:881ff0b71102 340 void LCD::FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 341 {
ttodorov 0:881ff0b71102 342 if ( x1 > x2 ) swap( ushort, x1, x2 );
ttodorov 0:881ff0b71102 343 if ( y1 > y2 ) swap( ushort, y1, y2 );
ttodorov 0:881ff0b71102 344
ttodorov 12:d0978272a340 345 for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ )
ttodorov 0:881ff0b71102 346 {
ttodorov 12:d0978272a340 347 DrawHLine( x1, y1 + i, x2 - x1, color );
ttodorov 12:d0978272a340 348 DrawHLine( x1, y2 - i, x2 - x1, color );
ttodorov 0:881ff0b71102 349 }
ttodorov 0:881ff0b71102 350 }
ttodorov 0:881ff0b71102 351
ttodorov 0:881ff0b71102 352 void LCD::FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
ttodorov 0:881ff0b71102 353 {
ttodorov 0:881ff0b71102 354 if ( x1 > x2 ) swap( ushort, x1, x2 )
ttodorov 0:881ff0b71102 355 if ( y1 > y2 ) swap( ushort, y1, y2 )
ttodorov 0:881ff0b71102 356
ttodorov 0:881ff0b71102 357 if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 )
ttodorov 0:881ff0b71102 358 {
ttodorov 0:881ff0b71102 359 for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ )
ttodorov 0:881ff0b71102 360 {
ttodorov 0:881ff0b71102 361 switch ( i )
ttodorov 0:881ff0b71102 362 {
ttodorov 0:881ff0b71102 363 case 0:
ttodorov 2:81ed304b7e9b 364 DrawHLine( x1 + 2, y1 + i, x2 - x1 - 4, color );
ttodorov 2:81ed304b7e9b 365 DrawHLine( x1 + 2, y2 - i, x2 - x1 - 4, color );
ttodorov 0:881ff0b71102 366 break;
ttodorov 0:881ff0b71102 367
ttodorov 0:881ff0b71102 368 case 1:
ttodorov 2:81ed304b7e9b 369 DrawHLine( x1 + 1, y1 + i, x2 - x1 - 2, color );
ttodorov 2:81ed304b7e9b 370 DrawHLine( x1 + 1, y2 - i, x2 - x1 - 2, color );
ttodorov 0:881ff0b71102 371 break;
ttodorov 0:881ff0b71102 372
ttodorov 0:881ff0b71102 373 default:
ttodorov 2:81ed304b7e9b 374 DrawHLine( x1, y1 + i, x2 - x1, color );
ttodorov 2:81ed304b7e9b 375 DrawHLine( x1, y2 - i, x2 - x1, color );
ttodorov 0:881ff0b71102 376 break;
ttodorov 0:881ff0b71102 377 }
ttodorov 0:881ff0b71102 378 }
ttodorov 0:881ff0b71102 379 }
ttodorov 0:881ff0b71102 380 }
ttodorov 0:881ff0b71102 381
ttodorov 0:881ff0b71102 382 void LCD::DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color )
ttodorov 0:881ff0b71102 383 {
ttodorov 0:881ff0b71102 384 int f = 1 - radius;
ttodorov 0:881ff0b71102 385 int ddF_x = 1;
ttodorov 0:881ff0b71102 386 int ddF_y = -2 * radius;
ttodorov 0:881ff0b71102 387 int x1 = 0;
ttodorov 0:881ff0b71102 388 int y1 = radius;
ttodorov 12:d0978272a340 389 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 0:881ff0b71102 390
ttodorov 4:3ac4239f6c9c 391 Activate();
ttodorov 2:81ed304b7e9b 392 SetXY( x, y + radius, x, y + radius );
ttodorov 10:69571adcfad5 393 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 394 SetXY( x, y - radius, x, y - radius );
ttodorov 10:69571adcfad5 395 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 396 SetXY( x + radius, y, x + radius, y );
ttodorov 10:69571adcfad5 397 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 398 SetXY( x - radius, y, x - radius, y );
ttodorov 10:69571adcfad5 399 SetPixelColor( usedColor );
ttodorov 0:881ff0b71102 400
ttodorov 0:881ff0b71102 401 while ( x1 < y1 )
ttodorov 0:881ff0b71102 402 {
ttodorov 0:881ff0b71102 403 if ( f >= 0 )
ttodorov 0:881ff0b71102 404 {
ttodorov 0:881ff0b71102 405 y1--;
ttodorov 0:881ff0b71102 406 ddF_y += 2;
ttodorov 0:881ff0b71102 407 f += ddF_y;
ttodorov 0:881ff0b71102 408 }
ttodorov 0:881ff0b71102 409 x1++;
ttodorov 0:881ff0b71102 410 ddF_x += 2;
ttodorov 0:881ff0b71102 411 f += ddF_x;
ttodorov 2:81ed304b7e9b 412 SetXY( x + x1, y + y1, x + x1, y + y1 );
ttodorov 10:69571adcfad5 413 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 414 SetXY( x - x1, y + y1, x - x1, y + y1 );
ttodorov 10:69571adcfad5 415 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 416 SetXY( x + x1, y - y1, x + x1, y - y1 );
ttodorov 10:69571adcfad5 417 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 418 SetXY( x - x1, y - y1, x - x1, y - y1 );
ttodorov 10:69571adcfad5 419 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 420 SetXY( x + y1, y + x1, x + y1, y + x1 );
ttodorov 10:69571adcfad5 421 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 422 SetXY( x - y1, y + x1, x - y1, y + x1 );
ttodorov 10:69571adcfad5 423 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 424 SetXY( x + y1, y - x1, x + y1, y - x1 );
ttodorov 10:69571adcfad5 425 SetPixelColor( usedColor );
ttodorov 2:81ed304b7e9b 426 SetXY( x - y1, y - x1, x - y1, y - x1 );
ttodorov 10:69571adcfad5 427 SetPixelColor( usedColor );
ttodorov 0:881ff0b71102 428 }
ttodorov 4:3ac4239f6c9c 429 Deactivate();
ttodorov 0:881ff0b71102 430 }
ttodorov 0:881ff0b71102 431
ttodorov 0:881ff0b71102 432 void LCD::FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color )
ttodorov 0:881ff0b71102 433 {
ttodorov 12:d0978272a340 434 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 4:3ac4239f6c9c 435 Activate();
ttodorov 0:881ff0b71102 436 for ( int y1 = -radius; y1 <= radius; y1++ )
ttodorov 0:881ff0b71102 437 for ( int x1 = -radius; x1 <= radius; x1++ )
ttodorov 0:881ff0b71102 438 if ( x1 * x1 + y1 * y1 <= radius * radius )
ttodorov 0:881ff0b71102 439 {
ttodorov 2:81ed304b7e9b 440 SetXY( x + x1, y + y1, x + x1, y + y1 );
ttodorov 10:69571adcfad5 441 SetPixelColor( usedColor );
ttodorov 0:881ff0b71102 442 }
ttodorov 4:3ac4239f6c9c 443 Deactivate();
ttodorov 0:881ff0b71102 444 }
ttodorov 0:881ff0b71102 445
ttodorov 0:881ff0b71102 446 void LCD::Print( const char *str, unsigned short x, unsigned short y, int fgColor, int bgColor, unsigned short deg )
ttodorov 0:881ff0b71102 447 {
ttodorov 0:881ff0b71102 448 int stl, i;
ttodorov 0:881ff0b71102 449
ttodorov 0:881ff0b71102 450 stl = strlen( str );
ttodorov 0:881ff0b71102 451
ttodorov 12:d0978272a340 452 if ( x == RIGHT )
ttodorov 21:e5c1e8ffada1 453 x = GetWidth() - ( stl * _font->Width );
ttodorov 12:d0978272a340 454 if ( x == CENTER )
ttodorov 21:e5c1e8ffada1 455 x = ( GetWidth() - ( stl * _font->Width ) ) / 2;
ttodorov 0:881ff0b71102 456
ttodorov 0:881ff0b71102 457 for ( i = 0; i < stl; i++ )
ttodorov 0:881ff0b71102 458 if ( deg == 0 )
ttodorov 21:e5c1e8ffada1 459 PrintChar( *str++, x + ( i * ( _font->Width ) ), y, fgColor, bgColor );
ttodorov 0:881ff0b71102 460 else
ttodorov 2:81ed304b7e9b 461 RotateChar( *str++, x, y, i, fgColor, bgColor, deg );
ttodorov 0:881ff0b71102 462 }
ttodorov 0:881ff0b71102 463
ttodorov 12:d0978272a340 464 void LCD::DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned char scale )
ttodorov 0:881ff0b71102 465 {
ttodorov 0:881ff0b71102 466 int tx, ty, tc, tsx, tsy;
ttodorov 0:881ff0b71102 467
ttodorov 4:3ac4239f6c9c 468 Activate();
ttodorov 0:881ff0b71102 469 if ( scale == 1 )
ttodorov 0:881ff0b71102 470 {
ttodorov 12:d0978272a340 471 SetXY( x, y, x + img->Width - 1, y + img->Height - 1 );
ttodorov 20:4bdca8d8dadc 472
ttodorov 13:5ceeba86bbe4 473 if ( img->Format == RGB16 )
ttodorov 0:881ff0b71102 474 {
ttodorov 13:5ceeba86bbe4 475 const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
ttodorov 20:4bdca8d8dadc 476 for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
ttodorov 20:4bdca8d8dadc 477 SetPixelColor( *pixel++, img->Format );
ttodorov 13:5ceeba86bbe4 478 }
ttodorov 13:5ceeba86bbe4 479 else if ( img->Format == RGB18 )
ttodorov 13:5ceeba86bbe4 480 {
ttodorov 13:5ceeba86bbe4 481 const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
ttodorov 20:4bdca8d8dadc 482 for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
ttodorov 20:4bdca8d8dadc 483 SetPixelColor( *pixel++, img->Format );
ttodorov 0:881ff0b71102 484 }
ttodorov 0:881ff0b71102 485 }
ttodorov 0:881ff0b71102 486 else
ttodorov 0:881ff0b71102 487 {
ttodorov 13:5ceeba86bbe4 488 if ( img->Format == RGB16 )
ttodorov 0:881ff0b71102 489 {
ttodorov 13:5ceeba86bbe4 490 const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
ttodorov 13:5ceeba86bbe4 491
ttodorov 13:5ceeba86bbe4 492 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 13:5ceeba86bbe4 493 {
ttodorov 13:5ceeba86bbe4 494 SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
ttodorov 13:5ceeba86bbe4 495 for ( tsy = 0; tsy < scale; tsy++ )
ttodorov 13:5ceeba86bbe4 496 {
ttodorov 13:5ceeba86bbe4 497 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 13:5ceeba86bbe4 498 {
ttodorov 13:5ceeba86bbe4 499 for ( tsx = 0; tsx < scale; tsx++ )
ttodorov 20:4bdca8d8dadc 500 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 20:4bdca8d8dadc 501 }
ttodorov 20:4bdca8d8dadc 502 }
ttodorov 20:4bdca8d8dadc 503 }
ttodorov 20:4bdca8d8dadc 504 }
ttodorov 20:4bdca8d8dadc 505 else if ( img->Format == RGB18 )
ttodorov 20:4bdca8d8dadc 506 {
ttodorov 20:4bdca8d8dadc 507 const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
ttodorov 20:4bdca8d8dadc 508
ttodorov 20:4bdca8d8dadc 509 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 20:4bdca8d8dadc 510 {
ttodorov 20:4bdca8d8dadc 511 SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
ttodorov 20:4bdca8d8dadc 512 for ( tsy = 0; tsy < scale; tsy++ )
ttodorov 20:4bdca8d8dadc 513 {
ttodorov 20:4bdca8d8dadc 514 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 20:4bdca8d8dadc 515 {
ttodorov 20:4bdca8d8dadc 516 for ( tsx = 0; tsx < scale; tsx++ )
ttodorov 20:4bdca8d8dadc 517 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 13:5ceeba86bbe4 518 }
ttodorov 13:5ceeba86bbe4 519 }
ttodorov 13:5ceeba86bbe4 520 }
ttodorov 13:5ceeba86bbe4 521 }
ttodorov 0:881ff0b71102 522 }
ttodorov 4:3ac4239f6c9c 523 Deactivate();
ttodorov 0:881ff0b71102 524 }
ttodorov 0:881ff0b71102 525
ttodorov 12:d0978272a340 526 void LCD::DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned short deg, unsigned short rox, unsigned short roy )
ttodorov 0:881ff0b71102 527 {
ttodorov 0:881ff0b71102 528 int tx, ty, newx, newy;
ttodorov 0:881ff0b71102 529 double radian;
ttodorov 0:881ff0b71102 530 radian = deg * 0.0175;
ttodorov 0:881ff0b71102 531
ttodorov 0:881ff0b71102 532 if ( deg == 0 )
ttodorov 12:d0978272a340 533 DrawBitmap( x, y, img );
ttodorov 0:881ff0b71102 534 else
ttodorov 0:881ff0b71102 535 {
ttodorov 4:3ac4239f6c9c 536 Activate();
ttodorov 13:5ceeba86bbe4 537
ttodorov 13:5ceeba86bbe4 538 if ( img->Format == RGB16 )
ttodorov 13:5ceeba86bbe4 539 {
ttodorov 13:5ceeba86bbe4 540 const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
ttodorov 13:5ceeba86bbe4 541
ttodorov 13:5ceeba86bbe4 542 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 13:5ceeba86bbe4 543 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 13:5ceeba86bbe4 544 {
ttodorov 13:5ceeba86bbe4 545 newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 546 newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 547
ttodorov 13:5ceeba86bbe4 548 SetXY( newx, newy, newx, newy );
ttodorov 20:4bdca8d8dadc 549 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 13:5ceeba86bbe4 550 }
ttodorov 13:5ceeba86bbe4 551 }
ttodorov 13:5ceeba86bbe4 552 else if ( img->Format == RGB18 )
ttodorov 13:5ceeba86bbe4 553 {
ttodorov 13:5ceeba86bbe4 554 const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
ttodorov 13:5ceeba86bbe4 555
ttodorov 13:5ceeba86bbe4 556 for ( ty = 0; ty < img->Height; ty++ )
ttodorov 13:5ceeba86bbe4 557 for ( tx = 0; tx < img->Width; tx++ )
ttodorov 13:5ceeba86bbe4 558 {
ttodorov 13:5ceeba86bbe4 559 newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 560 newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
ttodorov 13:5ceeba86bbe4 561
ttodorov 13:5ceeba86bbe4 562 SetXY( newx, newy, newx, newy );
ttodorov 20:4bdca8d8dadc 563 SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format );
ttodorov 13:5ceeba86bbe4 564 }
ttodorov 13:5ceeba86bbe4 565 }
ttodorov 4:3ac4239f6c9c 566 Deactivate();
ttodorov 0:881ff0b71102 567 }
ttodorov 4:3ac4239f6c9c 568 }
ttodorov 4:3ac4239f6c9c 569
ttodorov 4:3ac4239f6c9c 570 inline
ttodorov 4:3ac4239f6c9c 571 void LCD::Activate( void )
ttodorov 4:3ac4239f6c9c 572 {
ttodorov 4:3ac4239f6c9c 573 _lcd_pin_cs = LOW;
ttodorov 4:3ac4239f6c9c 574 }
ttodorov 4:3ac4239f6c9c 575
ttodorov 4:3ac4239f6c9c 576 inline
ttodorov 4:3ac4239f6c9c 577 void LCD::Deactivate( void )
ttodorov 4:3ac4239f6c9c 578 {
ttodorov 4:3ac4239f6c9c 579 _lcd_pin_cs = HIGH;
ttodorov 0:881ff0b71102 580 }
ttodorov 0:881ff0b71102 581
ttodorov 0:881ff0b71102 582 inline
ttodorov 2:81ed304b7e9b 583 void LCD::WriteCmdData( unsigned short cmd, unsigned short data )
ttodorov 0:881ff0b71102 584 {
ttodorov 2:81ed304b7e9b 585 WriteCmd( cmd );
ttodorov 2:81ed304b7e9b 586 WriteData( data );
ttodorov 0:881ff0b71102 587 }
ttodorov 0:881ff0b71102 588
ttodorov 12:d0978272a340 589 inline
ttodorov 12:d0978272a340 590 void LCD::ClearXY( void )
ttodorov 0:881ff0b71102 591 {
ttodorov 12:d0978272a340 592 SetXY( 0, 0, GetWidth() - 1, GetHeight() - 1 );
ttodorov 0:881ff0b71102 593 }
ttodorov 0:881ff0b71102 594
ttodorov 2:81ed304b7e9b 595 void LCD::DrawHLine( unsigned short x, unsigned short y, unsigned short len, int color )
ttodorov 0:881ff0b71102 596 {
ttodorov 12:d0978272a340 597 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 0:881ff0b71102 598
ttodorov 4:3ac4239f6c9c 599 Activate();
ttodorov 2:81ed304b7e9b 600 SetXY( x, y, x + len, y );
ttodorov 0:881ff0b71102 601 for ( int i = 0; i < len + 1; i++ )
ttodorov 10:69571adcfad5 602 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 603 Deactivate();
ttodorov 0:881ff0b71102 604 }
ttodorov 0:881ff0b71102 605
ttodorov 2:81ed304b7e9b 606 void LCD::DrawVLine( unsigned short x, unsigned short y, unsigned short len, int color )
ttodorov 0:881ff0b71102 607 {
ttodorov 12:d0978272a340 608 unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color;
ttodorov 0:881ff0b71102 609
ttodorov 4:3ac4239f6c9c 610 Activate();
ttodorov 2:81ed304b7e9b 611 SetXY( x, y, x, y + len );
ttodorov 0:881ff0b71102 612 for ( int i = 0; i < len; i++ )
ttodorov 10:69571adcfad5 613 SetPixelColor( usedColor );
ttodorov 4:3ac4239f6c9c 614 Deactivate();
ttodorov 0:881ff0b71102 615 }
ttodorov 0:881ff0b71102 616
ttodorov 2:81ed304b7e9b 617 void LCD::PrintChar( char c, unsigned short x, unsigned short y, int fgColor, int bgColor )
ttodorov 0:881ff0b71102 618 {
ttodorov 0:881ff0b71102 619 uint8_t i, ch;
ttodorov 0:881ff0b71102 620 uint16_t j;
ttodorov 12:d0978272a340 621 unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor;
ttodorov 12:d0978272a340 622 unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor;
ttodorov 21:e5c1e8ffada1 623
ttodorov 21:e5c1e8ffada1 624 uint16_t totalCharBytes = ( _font->Width * _font->Height ) / 8;
ttodorov 21:e5c1e8ffada1 625 int16_t position = _font->Position[ c - _font->Offset ];
ttodorov 21:e5c1e8ffada1 626 if ( position == -1 ) position = 0; // will print space character
ttodorov 21:e5c1e8ffada1 627
ttodorov 4:3ac4239f6c9c 628 Activate();
ttodorov 0:881ff0b71102 629
ttodorov 21:e5c1e8ffada1 630 SetXY( x, y, x + _font->Width - 1, y + _font->Height - 1 );
ttodorov 21:e5c1e8ffada1 631
ttodorov 21:e5c1e8ffada1 632 for ( j = 0; j < totalCharBytes; j++ )
ttodorov 0:881ff0b71102 633 {
ttodorov 21:e5c1e8ffada1 634 ch = _font->Data[ position ];
ttodorov 12:d0978272a340 635 for ( i = 0; i < 8; i++ )
ttodorov 0:881ff0b71102 636 {
ttodorov 21:e5c1e8ffada1 637 if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG );
ttodorov 21:e5c1e8ffada1 638 else SetPixelColor( usedColorBG );
ttodorov 0:881ff0b71102 639 }
ttodorov 21:e5c1e8ffada1 640 position++;
ttodorov 0:881ff0b71102 641 }
ttodorov 4:3ac4239f6c9c 642 Deactivate();
ttodorov 0:881ff0b71102 643 }
ttodorov 0:881ff0b71102 644
ttodorov 2:81ed304b7e9b 645 void LCD::RotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor, int bgColor, unsigned short deg )
ttodorov 0:881ff0b71102 646 {
ttodorov 0:881ff0b71102 647 uint8_t i, j, ch;
ttodorov 0:881ff0b71102 648 int newx, newy;
ttodorov 0:881ff0b71102 649 double radian;
ttodorov 0:881ff0b71102 650 radian = deg * 0.0175;
ttodorov 0:881ff0b71102 651
ttodorov 12:d0978272a340 652 unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor;
ttodorov 12:d0978272a340 653 unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor;
ttodorov 0:881ff0b71102 654
ttodorov 21:e5c1e8ffada1 655 int16_t position = _font->Position[ c - _font->Offset ];
ttodorov 21:e5c1e8ffada1 656 if ( position == -1 ) position = 0; // will print space character
ttodorov 21:e5c1e8ffada1 657
ttodorov 4:3ac4239f6c9c 658 Activate();
ttodorov 21:e5c1e8ffada1 659
ttodorov 21:e5c1e8ffada1 660 for ( j = 0; j < _font->Height; j++ )
ttodorov 0:881ff0b71102 661 {
ttodorov 21:e5c1e8ffada1 662 for ( uint16_t zz = 0; zz < ( ( double ) _font->Width / 8 ); zz++ )
ttodorov 0:881ff0b71102 663 {
ttodorov 21:e5c1e8ffada1 664 ch = _font->Data[ position + zz ];
ttodorov 0:881ff0b71102 665 for ( i = 0; i < 8; i++ )
ttodorov 0:881ff0b71102 666 {
ttodorov 21:e5c1e8ffada1 667 newx = x + ( ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * cos( radian ) ) - ( ( j ) * sin( radian ) ) );
ttodorov 21:e5c1e8ffada1 668 newy = y + ( ( ( j ) * cos( radian ) ) + ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * sin( radian ) ) );
ttodorov 0:881ff0b71102 669
ttodorov 2:81ed304b7e9b 670 SetXY( newx, newy, newx + 1, newy + 1 );
ttodorov 0:881ff0b71102 671
ttodorov 21:e5c1e8ffada1 672 if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG );
ttodorov 21:e5c1e8ffada1 673 else SetPixelColor( usedColorBG );
ttodorov 0:881ff0b71102 674 }
ttodorov 0:881ff0b71102 675 }
ttodorov 21:e5c1e8ffada1 676 position += ( _font->Width / 8 );
ttodorov 0:881ff0b71102 677 }
ttodorov 21:e5c1e8ffada1 678
ttodorov 4:3ac4239f6c9c 679 Deactivate();
ttodorov 0:881ff0b71102 680 }