1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/algorithm.h"
#include "access/bubble_box.h"
#include "access/access.h"
namespace Access {
BubbleBox::BubbleBox(AccessEngine *vm) : Manager(vm) {
_type = TYPE_2;
_bounds = Common::Rect(64, 32, 64 + 130, 32 + 122);
_bubblePtr = nullptr;
_fieldD = 0;
_fieldE = 0;
_fieldF = 0;
_field10 = 0;
_maxChars = 0;
}
void BubbleBox::load(Common::SeekableReadStream *stream) {
_bubbleTitle.clear();
byte v;
while ((v = stream->readByte()) != 0)
_bubbleTitle += (char)v;
_bubblePtr = _bubbleTitle.c_str();
}
void BubbleBox::clearBubbles() {
_bubbles.clear();
}
void BubbleBox::placeBubble(const Common::String &msg) {
BubbleBox::_maxChars = 27;
placeBubble1(msg);
}
void BubbleBox::placeBubble1(const Common::String &msg) {
BubbleBox::clearBubbles();
_vm->_fonts._charSet._lo = 1;
_vm->_fonts._charSet._hi = 8;
_vm->_fonts._charFor._lo = 29;
_vm->_fonts._charFor._hi = 32;
calcBubble(msg);
Common::Rect r = _bubbles[0];
r.translate(-2, 0);
_vm->_screen->saveBlock(r);
printBubble(msg);
}
void BubbleBox::calcBubble(const Common::String &msg) {
// Save points
Common::Point printOrg = _vm->_screen->_printOrg;
Common::Point printStart = _vm->_screen->_printStart;
// Figure out maximum width allowed
if (_type == TYPE_4) {
_vm->_fonts._printMaxX = 110;
} else {
_vm->_fonts._printMaxX = _vm->_fonts._font2.stringWidth(_bubblePtr);
}
// Start of with a rect with the given starting x and y
Common::Rect bounds(printOrg.x - 2, printOrg.y - 10, printOrg.x - 2, printOrg.y - 10);
// Loop through getting lines
Common::String s = msg;
Common::String line;
int width = 0;
bool lastLine;
do {
lastLine = _vm->_fonts._font2.getLine(s, _maxChars * 6, line, width);
_vm->_fonts._printMaxX = MAX(width, _vm->_fonts._printMaxX);
_vm->_screen->_printOrg.y += 6;
_vm->_screen->_printOrg.x = _vm->_screen->_printStart.x;
} while (!lastLine);
if (_type == TYPE_4)
++_vm->_screen->_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->_screen->_printOrg.y + 6;
if (_type == TYPE_4)
y += 6;
int height = y - bounds.top;
bounds.setHeight(height);
height -= (_type == TYPE_4) ? 30 : 24;
if (height >= 0)
bounds.setHeight(bounds.height() + 13 - (height % 13));
// Add the new bounds to the bubbles list
_bubbles.push_back(bounds);
// Restore points
_vm->_screen->_printOrg = printOrg;
_vm->_screen->_printStart = printStart;
}
void BubbleBox::printBubble(const Common::String &msg) {
drawBubble(_bubbles.size() - 1);
// Loop through drawing the lines
Common::String s = msg;
Common::String line;
int width = 0;
bool lastLine;
do {
// Get next line
Font &font2 = _vm->_fonts._font2;
lastLine = font2.getLine(s, _maxChars * 6, line, width);
// Set font colors
font2._fontColors[0] = 0;
font2._fontColors[1] = 27;
font2._fontColors[2] = 28;
font2._fontColors[3] = 29;
int xp = _vm->_screen->_printOrg.x;
if (_type == TYPE_4)
xp = (_bounds.width() - width) / 2 + _bounds.left - 4;
// Draw the text
font2.drawString(_vm->_screen, line, Common::Point(xp, _vm->_screen->_printOrg.y));
// Move print position
_vm->_screen->_printOrg.y += 6;
_vm->_screen->_printOrg.x = _vm->_screen->_printStart.x;
} while (!lastLine);
}
void BubbleBox::drawBubble(int index) {
_bounds = _bubbles[index];
doBox(0, 0);
}
void BubbleBox::doBox(int item, int box) {
FontManager &fonts = _vm->_fonts;
ASurface &screen = *_vm->_screen;
_startItem = item;
_startBox = box;
// Save state information
FontVal charSet = fonts._charSet;
FontVal charFor = fonts._charFor;
Common::Point printOrg = screen._printOrg;
Common::Point printStart = screen._printStart;
int charCol = _charCol;
int rowOff = _rowOff;
_vm->_screen->saveScreen();
_vm->_screen->setDisplayScan();
fonts._charFor._hi = 0xff;
fonts._charSet._lo = 1;
fonts._charSet._hi = 0;
if (_type == TYPE_4) {
fonts._charFor._lo = 0xFF;
error("TODO: filename listing");
return;
}
// Get icons data
byte *iconData = _vm->_files->loadFile("ICONS.LZ");
SpriteResource *icons = new SpriteResource(_vm, iconData, _vm->_files->_filesize);
delete[] iconData;
// Set the up boundaries and color to use for the box background
_vm->_screen->_orgX1 = _bounds.left - 2;
_vm->_screen->_orgY1 = _bounds.top;
_vm->_screen->_orgX2 = _bounds.right - 2;
_vm->_screen->_orgY2 = _bounds.bottom;
_vm->_screen->_lColor = 1;
int h = _bounds.height() - (_type == TYPE_4 ? 30 : 24);
int ySize = (h < 0) ? 0 : (h + 12) / 13;
int w = _bounds.width() - 24;
int xSize = (w < 0) ? 0 : (w + 19) / 20;
// Draw a background for the entire area
screen.drawRect();
// Draw images to form the top border
int xp, yp;
screen.plotImage(icons, 20, Common::Point(screen._orgX1, screen._orgY1));
xp = screen._orgX1 + 12;
for (int x = 0; x < xSize; ++x, xp += 20)
screen.plotImage(icons, 24 + x, Common::Point(xp, screen._orgY1));
screen.plotImage(icons, 21, Common::Point(xp, screen._orgY1));
// Draw images to form the bottom border
yp = screen._orgY2 - (_type == TYPE_4 ? 18 : 12);
screen.plotImage(icons, (_type == TYPE_4) ? 72 : 22,
Common::Point(screen._orgX1, yp));
xp = screen._orgX1 + 12;
yp += (_type == TYPE_4) ? 4 : 8;
for (int x = 0; x < xSize; ++x, xp += 20) {
screen.plotImage(icons, (_type == TYPE_4 ? 62 : 34) + x,
Common::Point(xp, yp));
}
yp = screen._orgY2 - (_type == TYPE_4 ? 18 : 12);
screen.plotImage(icons, (_type == TYPE_4) ? 73 : 23, Common::Point(xp, yp));
if (_type == TYPE_4) {
// Further stuff for filename dialog
error("TODO: Box type 4");
}
// Draw images to form the sides
yp = screen._orgY1 + 12;
for (int y = 0; y < ySize; ++y, yp += 13) {
screen.plotImage(icons, 44 + y, Common::Point(screen._orgX1, yp));
screen.plotImage(icons, 53 + y, Common::Point(screen._orgX2 - 4, yp));
}
// Handle drawing title
int titleWidth = _vm->_fonts._font2.stringWidth(_bubblePtr);
Font &font2 = _vm->_fonts._font2;
font2._fontColors[0] = 0;
font2._fontColors[1] = 3;
font2._fontColors[2] = 2;
font2._fontColors[3] = 1;
font2.drawString(_vm->_screen, _bubblePtr, Common::Point(
_bounds.left + (_bounds.width() / 2) - (titleWidth / 2), _bounds.top + 1));
// Restore positional state
fonts._charSet = charSet;
fonts._charFor = charFor;
screen._printOrg = printOrg;
screen._printStart = printStart;
_charCol = charCol;
_rowOff = rowOff;
_vm->_screen->restoreScreen();
// Free icons data
delete icons;
}
} // End of namespace Access
|