| 147 | }; |
| 148 | |
| 149 | bool Bitmap::blitString(const char *pszStr, int x, int y, u8 bSize) |
| 150 | { |
| 151 | // verify valid size index |
| 152 | if ( bSize > 3 || !pszStr ) |
| 153 | return false; |
| 154 | |
| 155 | // localize pointer (TODO: get rid of this offset) |
| 156 | Font *fnt = BWDATA::FontBase[bSize]; |
| 157 | if ( !fnt->isValid() ) |
| 158 | return false; |
| 159 | |
| 160 | // verify if drawing should be done |
| 161 | if ( x + fnt->getTextWidth(pszStr) < 0 || |
| 162 | y + fnt->getTextHeight(pszStr) < 0 || |
| 163 | x >= this->width() || |
| 164 | y >= this->height() ) |
| 165 | return false; |
| 166 | |
| 167 | // Reference an unsigned character array |
| 168 | const u8 *pbChars = (BYTE*)pszStr; |
| 169 | |
| 170 | u8 lastColor = 0, color = 0; |
| 171 | int Xoffset = x, Yoffset = y; |
| 172 | |
| 173 | // Iterate all characters in the message |
| 174 | for ( int c = 0; pbChars[c]; ++c ) |
| 175 | { |
| 176 | // Perform control character and whitespace functions |
| 177 | if ( pbChars[c] <= ' ' ) |
| 178 | { |
| 179 | switch ( pbChars[c] ) |
| 180 | { |
| 181 | case 1: // restore last colour |
| 182 | color = lastColor; |
| 183 | continue; |
| 184 | case '\t': // 9 tab |
| 185 | Xoffset += fnt->getCharWidth( pbChars[c] ); |
| 186 | continue; |
| 187 | case '\n': // 10 newline |
| 188 | Xoffset = x; |
| 189 | Yoffset += fnt->maxHeight(); |
| 190 | continue; |
| 191 | case 11: // invisible |
| 192 | case 20: |
| 193 | color = (BYTE)~0; |
| 194 | continue; |
| 195 | case '\f': // 12 formfeed |
| 196 | break; |
| 197 | case '\r': // 13 carriage return |
| 198 | case 26: |
| 199 | continue; |
| 200 | case 18: // right align |
| 201 | Xoffset += this->width() - fnt->getTextWidth(pszStr) - x; |
| 202 | continue; |
| 203 | case 19: // center align |
| 204 | Xoffset += (this->width() - fnt->getTextWidth(pszStr))/2 - x; |
| 205 | continue; |
| 206 | case ' ': // space |
no test coverage detected