diff options
author | Nipun Garg | 2019-06-23 05:48:50 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:16:56 +0200 |
commit | ae872f35691773d412ac7bfff39d9e35f42b65d8 (patch) | |
tree | 0e97598f38c6a25c42e8a8af5dde84d95cd8ca5a | |
parent | 94747f0f76b509a1d3c00f5bc09315486d8840cf (diff) | |
download | scummvm-rg350-ae872f35691773d412ac7bfff39d9e35f42b65d8.tar.gz scummvm-rg350-ae872f35691773d412ac7bfff39d9e35f42b65d8.tar.bz2 scummvm-rg350-ae872f35691773d412ac7bfff39d9e35f42b65d8.zip |
HDB: Add getDimensions() to calculate pixel width
-rw-r--r-- | engines/hdb/draw-manager.cpp | 55 | ||||
-rw-r--r-- | engines/hdb/draw-manager.h | 1 |
2 files changed, 56 insertions, 0 deletions
diff --git a/engines/hdb/draw-manager.cpp b/engines/hdb/draw-manager.cpp index 1f8802876e..113f063076 100644 --- a/engines/hdb/draw-manager.cpp +++ b/engines/hdb/draw-manager.cpp @@ -395,6 +395,61 @@ int DrawMan::animateTile(int tileIndex) { return _tLookupArray[tileIndex].animIndex; } +// Calculates pixel width of a string +void DrawMan::getDimensions(const char *string, int *pixelsWide, int *lines) { + if (!string) { + *pixelsWide = kFontSpace; + *lines = 1; + return; + } + + int width, maxWidth, height; + unsigned char c; + maxWidth = 0; + width = _eLeft; + height = 1; + + for (int i = 0; i < (int)strlen(string); i++) { + c = string[i]; + width += _charInfoBlocks[i]->width + _fontHeader.kerning + kFontIncrement; + if (c == ' ') + width += kFontSpace; + + if (c == '\n') { + height++; + if (width > maxWidth) + maxWidth = width; + width = _eLeft; + } else if (width > _eRight) { + int oldWidth = width; + i--; + while (string[i] != ' ' && i > 0) { + c = string[i]; + width -= _charInfoBlocks[c]->width + _fontHeader.kerning + kFontIncrement; + i--; + } + if (!i) { + maxWidth = oldWidth; + break; + } + height++; + if (width > maxWidth) + maxWidth = width; + width = _eLeft; + } + } + + if (width > maxWidth) + maxWidth = width; + + // If its one line, add 8 pixels + if (height == 1) + maxWidth += 8; + + *pixelsWide = maxWidth - _eLeft; + *lines = height; +} + void DrawMan::setTextEdges(int left, int right, int top, int bottom) { _eLeft = left; _eRight = right; diff --git a/engines/hdb/draw-manager.h b/engines/hdb/draw-manager.h index 9bc2204fa6..db09c172cc 100644 --- a/engines/hdb/draw-manager.h +++ b/engines/hdb/draw-manager.h @@ -117,6 +117,7 @@ public: // Font Functions + 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); void setKernLead(int kern, int lead); |