- Main Page
- Classes
- Files

- File List
- File Members

# C:/Users/Public/AGS Final Folder/BFLETCHER D4010283/Source/Game/Source/TextSprite.cpp

Go to the documentation of this file.

    00001 #include "TextSprite.h"
    00002
    00003 #include "SDL.h"
    00004 #include "Visualisation.h"
    00005 #include "AlphabetData.h"
    00006 #include "GameConfig.h"
    00007
    00008 #include "GameException.h"
    00009
    00010 TextSprite::TextSprite(const SpriteID &id, const std::string &message, const ColourRGB &colour)
    00011 : Sprite(id)
    00012 {
    00013         m_width = message.size() * CHARACTER_WIDTH;
    00014         m_height = CHARACTER_HEIGHT;
    00015
    00016         m_numFrames = 1; //Only one frame for procedural boxes so far, animation could be added later.
    00017         SDL_Surface* pScreen = Visualisation::getSingleton()->GetScreen();
    00018         m_pFrames = SDL_CreateRGBSurface(SDL_HWSURFACE, m_width, m_height, pScreen->format->BitsPerPixel, pScreen->format->Rmask, pScreen->format->Gmask, pScreen->format->Bmask, pScreen->format->Amask);
    00019
    00020         if(!m_pFrames)
    00021         {
    00022                 throw GameException(eMajorError, "TextSprite: Constructor failed due to failed SDL_CreateRGBSurface() call.");
    00023                 return;
    00024         }
    00025
    00026         ColourRGB transColour = Visualisation::getSingleton()->GetTransparencyKey();
    00027         Uint32 key = SDL_MapRGB(m_pFrames->format, transColour.r, transColour.g, transColour.b);
    00028         SDL_SetColorKey(m_pFrames, SDL_SRCCOLORKEY, key);
    00029
    00030         int xOffset = 0;
    00031         for(size_t i = 0; i < message.size(); i++)
    00032         {
    00033                 for(size_t x = 0; x < CHARACTER_WIDTH; x++)
    00034                 {
    00035                         for(size_t y = 0; y < CHARACTER_HEIGHT; y++)
    00036                         {
    00037                                 int charDataIndex = (y * CHARACTER_WIDTH) + x;
    00038                                 int pixelDataIndex = (y * m_width) + (x + xOffset);
    00039
    00040                                 const bool* pCharData = GetCharacterArray(message[i]);
    00041                                 if(!pCharData)
    00042                                 {
    00043                                         throw GameException(eMinorError, "TextSprite: GetCharacterArray() failed on character: %c", message[i]);
    00044                                         return;
    00045                                 }
    00046
    00047                                 if(pCharData[charDataIndex])
    00048                                         WritePixel(m_pFrames, x + xOffset, y, colour);
    00049                                 else
    00050                                         WritePixel(m_pFrames, x + xOffset, y, transColour);
    00051                         }
    00052                 }
    00053
    00054                 xOffset += CHARACTER_WIDTH;
    00055         }
    00056 }
    00057
    00058 const bool* TextSprite::GetCharacterArray(char letter)
    00059 {
    00060         const bool* pCharacter = 0;
    00061         switch(letter)
    00062         {
    00063                 case ' ':
    00064                         pCharacter = gCharacterSpace;
    00065                         break;
    00066                 case 'A':
    00067                 case 'a':
    00068                         pCharacter = gCharacterA;
    00069                         break;
    00070                 case 'B':
    00071                 case 'b':
    00072                         pCharacter = gCharacterB;
    00073                         break;
    00074                 case 'C':
    00075                 case 'c':
    00076                         pCharacter = gCharacterC;
    00077                         break;
    00078                 case 'D':
    00079                 case 'd':
    00080                         pCharacter = gCharacterD;
    00081                         break;
    00082                 case 'E':
    00083                 case 'e':
    00084                         pCharacter = gCharacterE;
    00085                         break;
    00086                 case 'F':
    00087                 case 'f':
    00088                         pCharacter = gCharacterF;
    00089                         break;
    00090                 case 'G':
    00091                 case 'g':
    00092                         pCharacter = gCharacterG;
    00093                         break;
    00094                 case 'H':
    00095                 case 'h':
    00096                         pCharacter = gCharacterH;
    00097                         break;
    00098                 case 'I':
    00099                 case 'i':
    00100                         pCharacter = gCharacterI;
    00101                         break;
    00102                 case 'J':
    00103                 case 'j':
    00104                         pCharacter = gCharacterJ;
    00105                         break;
    00106                 case 'K':
    00107                 case 'k':
    00108                         pCharacter = gCharacterK;
    00109                         break;
    00110                 case 'L':
    00111                 case 'l':
    00112                         pCharacter = gCharacterL;
    00113                         break;
    00114                 case 'M':
    00115                 case 'm':
    00116                         pCharacter = gCharacterM;
    00117                         break;
    00118                 case 'N':
    00119                 case 'n':
    00120                         pCharacter = gCharacterN;
    00121                         break;
    00122                 case 'O':
    00123                 case 'o':
    00124                         pCharacter = gCharacterO;
    00125                         break;
    00126                 case 'P':
    00127                 case 'p':
    00128                         pCharacter = gCharacterP;
    00129                         break;
    00130                 case 'Q':
    00131                 case 'q':
    00132                         pCharacter = gCharacterQ;
    00133                         break;
    00134                 case 'R':
    00135                 case 'r':
    00136                         pCharacter = gCharacterR;
    00137                         break;
    00138                 case 'S':
    00139                 case 's':
    00140                         pCharacter = gCharacterS;
    00141                         break;
    00142                 case 'T':
    00143                 case 't':
    00144                         pCharacter = gCharacterT;
    00145                         break;
    00146                 case 'U':
    00147                 case 'u':
    00148                         pCharacter = gCharacterU;
    00149                         break;
    00150                 case 'V':
    00151                 case 'v':
    00152                         pCharacter = gCharacterV;
    00153                         break;
    00154                 case 'W':
    00155                 case 'w':
    00156                         pCharacter = gCharacterW;
    00157                         break;
    00158                 case 'X':
    00159                 case 'x':
    00160                         pCharacter = gCharacterX;
    00161                         break;
    00162                 case 'Y':
    00163                 case 'y':
    00164                         pCharacter = gCharacterY;
    00165                         break;
    00166                 case 'Z':
    00167                 case 'z':
    00168                         pCharacter = gCharacterZ;
    00169                         break;
    00170                 case '0':
    00171                         pCharacter = gCharacter0;
    00172                         break;
    00173                 case '1':
    00174                         pCharacter = gCharacter1;
    00175                         break;
    00176                 case '2':
    00177                         pCharacter = gCharacter2;
    00178                         break;
    00179                 case '3':
    00180                         pCharacter = gCharacter3;
    00181                         break;
    00182                 case '4':
    00183                         pCharacter = gCharacter4;
    00184                         break;
    00185                 case '5':
    00186                         pCharacter = gCharacter5;
    00187                         break;
    00188                 case '6':
    00189                         pCharacter = gCharacter6;
    00190                         break;
    00191                 case '7':
    00192                         pCharacter = gCharacter7;
    00193                         break;
    00194                 case '8':
    00195                         pCharacter = gCharacter8;
    00196                         break;
    00197                 case '9':
    00198                         pCharacter = gCharacter9;
    00199                         break;
    00200                 case '!':
    00201                         pCharacter = gCharacterExclamationMark;
    00202                         break;
    00203                 case '?':
    00204                         pCharacter = gCharacterQuestionMark;
    00205                         break;
    00206                 case '.':
    00207                         pCharacter = gCharacterFullstop;
    00208                         break;
    00209                 case ',':
    00210                         pCharacter = gCharacterComma;
    00211                         break;
    00212                 case ':':
    00213                         pCharacter = gCharacterColon;
    00214                         break;
    00215         }
    00216
    00217         return pCharacter;
    00218 }