HDB: Add drawText()

This commit is contained in:
Nipun Garg 2019-06-23 05:52:22 +05:30 committed by Eugene Sandulenko
parent a427871168
commit 6d28554d2a
2 changed files with 64 additions and 0 deletions

View File

@ -442,6 +442,69 @@ bool DrawMan::loadFont(const char *string) {
return true;
}
void DrawMan::drawText(const char *string) {
if (!_systemInit)
return;
if (_cursorX < _eLeft)
_cursorX = _eLeft;
if (_cursorY < _eTop)
_cursorY = _eTop;
// Word Wrapping
int width = _eLeft;
unsigned char c;
char cr[256]; // Carriage Return Array
for (int i = 0; i < (int)strlen(string);i++) {
c = string[i];
width += _charInfoBlocks[c]->width + _fontHeader.kerning + kFontIncrement;
if (c == ' ')
width += kFontSpace;
cr[i] = 0;
if (c == '\n') {
cr[i] = 1;
width = _eLeft;
} else if (width > _eRight) {
i--;
while (string[i] != ' ' && i > 0)
i--;
cr[i] = 1;
width = _eLeft;
}
}
// Draw the characters
for (int j = 0;j < (int)strlen(string);j++) {
c = string[j];
if (c == '\n' || cr[j]) {
_cursorX = _eLeft;
_cursorY += _fontHeader.height + _fontHeader.leading;
if (_cursorY + _fontHeader.height > _eBottom)
_cursorY = _eTop;
continue;
}
width = _charInfoBlocks[c]->width;
if (c == ' ')
width = kFontSpace;
// Blit the character
g_hdb->_drawMan->_globalSurface.transBlitFrom(_fontSurfaces[c], Common::Point(_cursorX, _cursorY));
g_system->copyRectToScreen(g_hdb->_drawMan->_globalSurface.getBasePtr(0, 0), g_hdb->_drawMan->_globalSurface.pitch, 0, 0, width, _fontHeader.height);
// Advance the cursor
_cursorX += width + _fontHeader.kerning * kFontIncrement;
if (_cursorX > kScreenWidth) {
_cursorX = 0;
_cursorY += _fontHeader.height + _fontHeader.leading;
if (_cursorY + _fontHeader.height > kScreenHeight)
_cursorY = 0;
}
}
}
// Calculates pixel width of a string
void DrawMan::getDimensions(const char *string, int *pixelsWide, int *lines) {
if (!string) {

View File

@ -118,6 +118,7 @@ public:
// Font Functions
bool loadFont(const char *string);
void drawText(const char *string);
void getDimensions(const char *string, int *pixelsWide, int *lines);
void setTextEdges(int left, int right, int top, int bottom);
void getTextEdges(int *left, int *right, int *top, int *bottom);