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

Committer:
RichardE
Date:
Wed Nov 21 22:17:26 2012 +0000
Revision:
0:c7d5d58ef13a
Child:
1:b5d8f8deafa5
Not finished. Only draws top left character for each cell in grid.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichardE 0:c7d5d58ef13a 1 /*
RichardE 0:c7d5d58ef13a 2 * SOURCE FILE : CharacterNet.cpp
RichardE 0:c7d5d58ef13a 3 *
RichardE 0:c7d5d58ef13a 4 */
RichardE 0:c7d5d58ef13a 5
RichardE 0:c7d5d58ef13a 6 #include "CharacterNet.h"
RichardE 0:c7d5d58ef13a 7
RichardE 0:c7d5d58ef13a 8 // An instance of this class.
RichardE 0:c7d5d58ef13a 9 CharacterNet CharacterNet::instance;
RichardE 0:c7d5d58ef13a 10
RichardE 0:c7d5d58ef13a 11 // Default character codes to use.
RichardE 0:c7d5d58ef13a 12 const UInt8 CharacterNet::defaultCodes[ CodePosCount ] = {
RichardE 0:c7d5d58ef13a 13 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
RichardE 0:c7d5d58ef13a 14 };
RichardE 0:c7d5d58ef13a 15
RichardE 0:c7d5d58ef13a 16 /** Constructor.
RichardE 0:c7d5d58ef13a 17 */
RichardE 0:c7d5d58ef13a 18 CharacterNet::CharacterNet() :
RichardE 0:c7d5d58ef13a 19 characterCodes( defaultCodes )
RichardE 0:c7d5d58ef13a 20 {
RichardE 0:c7d5d58ef13a 21 }
RichardE 0:c7d5d58ef13a 22
RichardE 0:c7d5d58ef13a 23 /** Draw a net of characters.
RichardE 0:c7d5d58ef13a 24 * @param gd The Gameduino to draw on.
RichardE 0:c7d5d58ef13a 25 * @param xco X coordinate for top left.
RichardE 0:c7d5d58ef13a 26 * @param yco Y coordinate for top left.
RichardE 0:c7d5d58ef13a 27 * @param columnCount The number of columns to draw.
RichardE 0:c7d5d58ef13a 28 * @param rowCount The number of rows to draw.
RichardE 0:c7d5d58ef13a 29 * @param cellWidth The width of each cell in characters.
RichardE 0:c7d5d58ef13a 30 * @param cellHeight The height of each cell in characters.
RichardE 0:c7d5d58ef13a 31 */
RichardE 0:c7d5d58ef13a 32 void CharacterNet::Draw( Gameduino *gd, UInt8 xco, UInt8 yco, UInt8 columnCount, UInt8 rowCount, UInt8 cellWidth, UInt8 cellHeight ) {
RichardE 0:c7d5d58ef13a 33 UInt8 x = xco;
RichardE 0:c7d5d58ef13a 34 for( UInt8 column = 0; column < columnCount; ++column ) {
RichardE 0:c7d5d58ef13a 35 UInt8 y = yco;
RichardE 0:c7d5d58ef13a 36 for( UInt8 row = 0; row < rowCount; ++row ) {
RichardE 0:c7d5d58ef13a 37 DrawCell( gd, x, y, cellWidth, cellHeight, ( row == 0 ), ( column == 0 ) );
RichardE 0:c7d5d58ef13a 38 y += cellHeight;
RichardE 0:c7d5d58ef13a 39 }
RichardE 0:c7d5d58ef13a 40 x += cellWidth;
RichardE 0:c7d5d58ef13a 41 }
RichardE 0:c7d5d58ef13a 42 }
RichardE 0:c7d5d58ef13a 43
RichardE 0:c7d5d58ef13a 44 /** Draw a single cell.
RichardE 0:c7d5d58ef13a 45 * Note that only the upper and left hand edges are drawn.
RichardE 0:c7d5d58ef13a 46 * @param gd Gameduino to draw on.
RichardE 0:c7d5d58ef13a 47 * @param xco X coordinate for top left.
RichardE 0:c7d5d58ef13a 48 * @param yco Y coordinate for top left.
RichardE 0:c7d5d58ef13a 49 * @param cellWidth Width of cell in characters.
RichardE 0:c7d5d58ef13a 50 * @param cellHeight Height of cell in characters.
RichardE 0:c7d5d58ef13a 51 * @param topRow Set to true if this is a cell in the top row of the net.
RichardE 0:c7d5d58ef13a 52 * @param leftColumn Set to true if this is a cell in the leftmost column of the net.
RichardE 0:c7d5d58ef13a 53 */
RichardE 0:c7d5d58ef13a 54 void CharacterNet::DrawCell( Gameduino *gd, UInt8 xco, UInt8 yco, UInt8 cellWidth, UInt8 cellHeight, bool topRow, bool leftColumn ) {
RichardE 0:c7d5d58ef13a 55 // Draw character at top left corner of cell.
RichardE 0:c7d5d58ef13a 56 char text[] = "X";
RichardE 0:c7d5d58ef13a 57 if( topRow ) {
RichardE 0:c7d5d58ef13a 58 if( leftColumn ) {
RichardE 0:c7d5d58ef13a 59 text[ 0 ] = characterCodes[ TopLeftCorner ];
RichardE 0:c7d5d58ef13a 60 }
RichardE 0:c7d5d58ef13a 61 else {
RichardE 0:c7d5d58ef13a 62 text[ 0 ] = characterCodes[ TDown ];
RichardE 0:c7d5d58ef13a 63 }
RichardE 0:c7d5d58ef13a 64 }
RichardE 0:c7d5d58ef13a 65 else if( leftColumn ) {
RichardE 0:c7d5d58ef13a 66 text[ 0 ] = characterCodes[ TRight ];
RichardE 0:c7d5d58ef13a 67 }
RichardE 0:c7d5d58ef13a 68 else {
RichardE 0:c7d5d58ef13a 69 text[ 0 ] = characterCodes[ Cross ];
RichardE 0:c7d5d58ef13a 70 }
RichardE 0:c7d5d58ef13a 71 gd->putstr( xco, yco, text );
RichardE 0:c7d5d58ef13a 72 }
RichardE 0:c7d5d58ef13a 73