diff options
Diffstat (limited to 'engines/access')
-rw-r--r-- | engines/access/data.cpp | 41 | ||||
-rw-r--r-- | engines/access/data.h | 11 | ||||
-rw-r--r-- | engines/access/room.cpp | 73 | ||||
-rw-r--r-- | engines/access/room.h | 10 |
4 files changed, 117 insertions, 18 deletions
diff --git a/engines/access/data.cpp b/engines/access/data.cpp index 1f8b33ef43..65702db9f1 100644 --- a/engines/access/data.cpp +++ b/engines/access/data.cpp @@ -60,7 +60,7 @@ void Font::load(const int *index, const byte *data) { } int Font::charWidth(char c) { - error("TODO"); + return *_chars[c - ' ']; } int Font::stringWidth(const Common::String &msg) { @@ -72,6 +72,45 @@ int Font::stringWidth(const Common::String &msg) { return 0; } +bool Font::getLine(Common::String &s, int maxWidth, Common::String &line, int &width) { + width = 0; + const char *src = s.c_str(); + char c; + + while ((c = *src) != '\0') { + if (c == '\r') { + // End of line, so return calculated line + line = Common::String(s.c_str(), src - 1); + s = Common::String(src + 1); + return false; + } + + ++src; + width += charWidth(c); + if (width < maxWidth) + continue; + + // Reached maximum allowed. Work backwards to find space at the + // start of the current word as a point to split the line on + while (*src != ' ' && src >= s.c_str()) { + width -= charWidth(*src); + --src; + } + if (src < s.c_str()) + error("Could not fit line"); + + // Split the line around the space + line = Common::String(s.c_str(), src - 1); + s = Common::String(src + 1); + return false; + } + + // Return entire string + line = s; + s = Common::String(); + return true; +} + /*------------------------------------------------------------------------*/ FontManager::FontManager() { diff --git a/engines/access/data.h b/engines/access/data.h index 6d783b15dc..910e2523d1 100644 --- a/engines/access/data.h +++ b/engines/access/data.h @@ -107,6 +107,17 @@ public: * Get the width of a given string */ int stringWidth(const Common::String &msg); + + /** + * Get a partial string that will fit in a given width + * @param s Source string. Modified to remove line + * @param maxWidth Maximum width allowed + * @param line Output line + * @param width Calculated width of returned line + * @returns True if last line + */ + bool getLine(Common::String &s, int maxWidth, Common::String &line, int &width); + }; class FontManager { diff --git a/engines/access/room.cpp b/engines/access/room.cpp index 74a30d8f2a..b46363b32d 100644 --- a/engines/access/room.cpp +++ b/engines/access/room.cpp @@ -558,7 +558,7 @@ int Room::checkBoxes2(const Common::Point &pt, int start, int count) { } void Room::checkBoxes3() { - for (int start = 0; start < _plotter._blocks.size(); ++start) { + for (uint start = 0; start < _plotter._blocks.size(); ++start) { if (_plotter._blocks[start].contains(_vm->_events->_mousePos)) { _plotter._blockIn = start; if (!(validateBox(start) & 0x80)) { @@ -571,7 +571,7 @@ void Room::checkBoxes3() { _vm->_scripts->executeScript(); } - _vm->_boxSelect = -1; + _vm->_boxSelect = true; return; } } @@ -605,19 +605,57 @@ void Room::placeBubble1() { } void Room::calcBubble() { + // Save points Common::Point printOrg = _vm->_fonts._printOrg; Common::Point printStart = _vm->_fonts._printStart; - Common::Rect bounds(printOrg.x - 2, printOrg.y, printOrg.x - 2, printOrg.y); - - if (_bubbleBox._field0 == 4) { + // Figure out maximum width allowed + if (_bubbleBox._type == 4) { _vm->_fonts._printMaxX = 110; } else { - + _vm->_fonts._printMaxX = _vm->_fonts._font2.stringWidth(_bubbleBox._bubblePtr); } + // Start of with a rect with the given starting x and y + Common::Rect bounds(printOrg.x - 2, printOrg.y, printOrg.x - 2, printOrg.y); + + // Loop through getting lines + Common::String msg(_bubbleBox._bubblePtr); + Common::String line; + int width = 0; + bool lastLine; + do { + lastLine = _vm->_fonts._font2.getLine(msg, _vm->_fonts._printMaxX, line, width); + width = MIN(width, _vm->_fonts._printMaxX); + + _vm->_fonts._printOrg.y += 6; + _vm->_fonts._printOrg.x = _vm->_fonts._printStart.x; + } while (!lastLine); + + if (_bubbleBox._type == 4) + ++_vm->_fonts._printOrg.y += 6; + // Determine the width for the area + width = (((_vm->_fonts._printMaxX >> 4) + 1) << 4) + 5; + if (width >= 24) + width += 20 - ((width - 24) % 20); + bounds.setWidth(width); + // Determine the height for area + int y = _vm->_fonts._printOrg.y + 6; + if (_bubbleBox._type == 4) + y += 6; + int height = y - bounds.top; + bounds.setHeight(height); + + height -= (_bubbleBox._type == 4) ? 30 : 24; + if (height >= 0) + bounds.setHeight(bounds.height() + 13 - (height % 13)); + + // Add the new bounds to the bubbles list + _bubbleBox._bubbles.push_back(bounds); + + // Restore points _vm->_fonts._printOrg = printOrg; _vm->_fonts._printStart = printStart; } @@ -627,6 +665,15 @@ void Room::printBubble() { error("TODO: printBubble"); } +void Room::drawBubble(int index) { + _bubbleBox._bounds = _bubbleBox._bubbles[index]; + doBox(); +} + +void Room::doBox() { + error("TODO: doBox"); +} + /*------------------------------------------------------------------------*/ RoomInfo::RoomInfo(const byte *data) { @@ -688,22 +735,20 @@ RoomInfo::RoomInfo(const byte *data) { /*------------------------------------------------------------------------*/ BubbleBox::BubbleBox() { - _field0 = 2; + _type = 2; _bounds = Common::Rect(64, 32, 130, 122); - _bubblePtr = -1; + _bubblePtr = nullptr; _maxChars = 0; } void BubbleBox::load(Common::SeekableReadStream *stream) { - _bubbleTit.clear(); + _bubbleTitle.clear(); byte v; - do { - v = stream->readByte(); - _bubbleTit.push_back(v); - } while (v != 0); + while ((v = stream->readByte()) != 0) + _bubbleTitle += (char)v; - _bubblePtr = 0; + _bubblePtr = _bubbleTitle.c_str(); } void BubbleBox::clearBubbles() { diff --git a/engines/access/room.h b/engines/access/room.h index 9b26ed24e8..3035561892 100644 --- a/engines/access/room.h +++ b/engines/access/room.h @@ -60,10 +60,10 @@ public: class BubbleBox { public: - int _field0; + int _type; Common::Rect _bounds; - Common::Array<int> _bubbleTit; - int _bubblePtr; + Common::String _bubbleTitle; + const char *_bubblePtr; int _maxChars; Common::Array<Common::Rect> _bubbles; public: @@ -165,6 +165,10 @@ public: void calcBubble(); void printBubble(); + + void drawBubble(int index); + + void doBox(); }; |