Kentaro Sekimoto / TFTLCD_8bit

Dependents:   GR-PEACH_TFTLCD_8bit

Fork of TFTLCD_8bit by Thiha Electronics

Revision:
30:5f23a4cbebd7
Parent:
29:ad9d18445005
Child:
31:9ca104de2f74
diff -r ad9d18445005 -r 5f23a4cbebd7 lcd_base.cpp
--- a/lcd_base.cpp	Mon Apr 07 16:53:44 2014 +0000
+++ b/lcd_base.cpp	Wed Apr 16 14:48:51 2014 +0000
@@ -90,6 +90,14 @@
     _font = font;
 }
 
+//inline
+unsigned short LCD::GetHeight( void )
+{
+    if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_width;
+    return _disp_height;
+}
+
+
 inline
 unsigned short LCD::GetWidth( void )
 {
@@ -97,12 +105,6 @@
     return _disp_width;
 }
 
-inline
-unsigned short LCD::GetHeight( void )
-{
-    if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_width;
-    return _disp_height;
-}
 
 inline
 uint8_t LCD::GetFontWidth( void )
@@ -244,6 +246,67 @@
         Deactivate();
     }
 }
+void LCD::DrawTriangle( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned short x3, unsigned short y3,  int color )
+{
+//    if ( x1 > x2 ) swap( ushort, x1, x2 )
+//    if ( y1 > y2 ) swap( ushort, y1, y2 )
+
+    DrawLine( x1, y1, x2, y2, color );
+    DrawLine( x2, y2, x3, y3, color );
+    DrawLine( x3, y3, x1, y1, color );
+}
+
+void LCD::FillTriangle( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned short x3, unsigned short y3,  int color )
+{
+    int dx1, dx2, dx3;
+    int sx1, sx2, sy;
+    
+
+    if ( y1 > y2 ) { swap( ushort, y1, y2 ); swap( ushort, x1, x2 ); }
+    if ( y2 > y3 ) { swap( ushort, y3, y2 ); swap( ushort, x3, x2 ); }
+    if ( y1 > y2 ) { swap( ushort, y1, y2 ); swap( ushort, x1, x2 ); }
+
+    sx2= x1 * 1000; // Use fixed point math for x axis values
+    sx1 = sx2;
+    sy=y1;
+
+  // Calculate interpolation deltas
+    if (y2-y1 > 0) dx1=((x2-x1)*1000)/(y2-y1);
+      else dx1=0;
+    if (y3-y1 > 0) dx2=((x3-x1)*1000)/(y3-y1);
+      else dx2=0;
+    if (y3-y2 > 0) dx3=((x3-x2)*1000)/(y3-y2);
+      else dx3=0;
+
+  // Render scanlines (horizontal lines are the fastest rendering method)
+  if (dx1 > dx2)
+  {
+    for(; sy<=y2; sy++, sx1+=dx2, sx2+=dx1)
+    {
+      DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
+    }
+    sx2 = x2*1000;
+    sy = y2;
+    for(; sy<=y3; sy++, sx1+=dx2, sx2+=dx3)
+    {
+      DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
+    }
+  }
+  else
+  {
+    for(; sy<=y2; sy++, sx1+=dx1, sx2+=dx2)
+    {
+      DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
+    }
+    sx1 = x2*1000;
+    sy = y2;
+    for(; sy<=y3; sy++, sx1+=dx3, sx2+=dx2)
+    {
+      DrawHLine(sx1/1000, sy, (sx2-sx1)/1000, color);
+    }
+  }
+
+}
 
 void LCD::DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color )
 {