diff options
author | Eugene Sandulenko | 2017-08-03 09:27:29 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-08-04 21:54:20 +0200 |
commit | 08293015e7c18202a4783d39d4083077f562cbca (patch) | |
tree | 3fd487c54ba9356365be3f6f472131e5c99f03f2 | |
parent | c25a26d11cad273865a1ccf51f2ca8819f3e18ee (diff) | |
download | scummvm-rg350-08293015e7c18202a4783d39d4083077f562cbca.tar.gz scummvm-rg350-08293015e7c18202a4783d39d4083077f562cbca.tar.bz2 scummvm-rg350-08293015e7c18202a4783d39d4083077f562cbca.zip |
GRAPHICS: MACGUI: Implement MacText::getRowCol() method
-rw-r--r-- | graphics/macgui/mactext.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index 6ebbe181c6..7316e5a680 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -362,7 +362,7 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int } g->blitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y), - MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), + MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), Common::Point(xoff, yoff)); } @@ -446,7 +446,43 @@ void MacText::removeLastLine() { } void MacText::getRowCol(int x, int y, int *col, int *row) { - warning("getRowCol(%d, %d, ...)", x, y); + CLIP(y, 0, _textMaxHeight); + + // FIXME: We should use bsearch() here + *row = 0; + + while (*row < _textLines.size() - 1 && _textLines[*row].y < y) + (*row)++; + + *col = 0; + + int width = 0, pwidth = 0; + int mcol = 0, pmcol = 0; + uint chunk; + for (chunk = 0; chunk < _textLines[*row].chunks.size() - 1; chunk++) { + pwidth = width; + pmcol = mcol; + if (!_textLines[*row].chunks[chunk].text.empty()) { + width += _textLines[*row].chunks[chunk].getFont()->getStringWidth(_textLines[*row].chunks[chunk].text); + mcol += _textLines[*row].chunks[chunk].text.size(); + } + + if (width > x) + break; + } + + Common::String str = _textLines[*row].chunks[chunk].text; + + *col = mcol; + + for (int i = str.size(); i >= 0; i--) { + if (_textLines[*row].chunks[chunk].getFont()->getStringWidth(str) + pwidth < x) { + *col = mcol + i; + break; + } + + str.deleteLastChar(); + } } } // End of namespace Graphics |