Draws grids using frames of characters on a Gameduino display. Requires Gameduino library.

Revision:
1:b5d8f8deafa5
Parent:
0:c7d5d58ef13a
--- a/CharacterNet.cpp	Wed Nov 21 22:17:26 2012 +0000
+++ b/CharacterNet.cpp	Sat Nov 24 12:55:27 2012 +0000
@@ -34,7 +34,7 @@
     for( UInt8 column = 0; column < columnCount; ++column ) {
         UInt8 y = yco;
         for( UInt8 row = 0; row < rowCount; ++row ) {
-            DrawCell( gd, x, y, cellWidth, cellHeight, ( row == 0 ), ( column == 0 ) );
+            DrawCell( gd, x, y, cellWidth, cellHeight, ( row == 0 ), ( column == 0 ), ( row == rowCount - 1 ), ( column == columnCount - 1 ) );
             y += cellHeight;
         }
         x += cellWidth;
@@ -50,24 +50,61 @@
  * @param cellHeight Height of cell in characters.
  * @param topRow Set to true if this is a cell in the top row of the net.
  * @param leftColumn Set to true if this is a cell in the leftmost column of the net.
+ * @param bottomRow Set to true if this is a cell in the bottom row of the net.
+ * @param rightColumn Set to true if this is a cell in the rightmost column of the net.
  */
-void CharacterNet::DrawCell( Gameduino *gd, UInt8 xco, UInt8 yco, UInt8 cellWidth, UInt8 cellHeight, bool topRow, bool leftColumn ) {
+void CharacterNet::DrawCell( Gameduino *gd, UInt8 xco, UInt8 yco, UInt8 cellWidth, UInt8 cellHeight, bool topRow, bool leftColumn, bool bottomRow, bool rightColumn ) {
     // Draw character at top left corner of cell.
-    char text[] = "X";
+    char c;
     if( topRow ) {
         if( leftColumn ) {
-            text[ 0 ] = characterCodes[ TopLeftCorner ];
+            c = characterCodes[ TopLeftCorner ];
         }
         else {
-            text[ 0 ] = characterCodes[ TDown ];
+            c = characterCodes[ TDown ];
         }
     }
     else if( leftColumn ) {
-        text[ 0 ] = characterCodes[ TRight ];
+        c = characterCodes[ TRight ];
     }
     else {
-        text[ 0 ] = characterCodes[ Cross ];
+        c = characterCodes[ Cross ];
+    }
+    gd->putchar( xco, yco, c );
+    // If in the rightmost column then draw character at top right of cell.
+    if( rightColumn ) {
+        c = ( topRow ? characterCodes[ TopRightCorner ] : characterCodes[ TLeft ] );
+        gd->putchar( xco + cellWidth, yco, c );
+    }
+    // If in the bottom row then draw character at bottom left of cell.
+    if( bottomRow ) {
+        c = ( leftColumn ? characterCodes[ BottomLeftCorner ] : characterCodes[ TUp ] );
+        gd->putchar( xco, yco + cellHeight, c );
+    }
+    // If in the rightmost column and the bottom row then draw character at bottom right of cell.
+    if( rightColumn && bottomRow ) {
+        gd->putchar( xco + cellWidth, yco + cellHeight, characterCodes[ BottomRightCorner ] );
     }
-    gd->putstr( xco, yco, text );
+    // Draw top edge.
+    c = characterCodes[ Horizontal ];
+    for( UInt8 x = xco + 1; x < xco + cellWidth; ++x ) {
+        gd->putchar( x, yco, c );
+    }
+    // If in bottom row then draw bottom edge.
+    if( bottomRow ) {
+        for( UInt8 x = xco + 1; x < xco + cellWidth; ++x ) {
+            gd->putchar( x, yco + cellHeight, c );
+        }
+    }
+    // Draw left edge.
+    c = characterCodes[ Vertical ];
+    for( UInt8 y = yco + 1; y < yco + cellHeight; ++y ) {
+        gd->putchar( xco, y, c );
+    }
+    // If in rightmost column then draw right edge.
+    if( rightColumn ) {
+        for( UInt8 y = yco + 1; y < yco + cellHeight; ++y ) {
+            gd->putchar( xco + cellWidth, y, c );
+        }
+    }
 }
-      
\ No newline at end of file