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
|
/* 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 "sherlock/tattoo/widget_credits.h"
#include "sherlock/tattoo/tattoo.h"
namespace Sherlock {
namespace Tattoo {
WidgetCredits::WidgetCredits(SherlockEngine *vm) : _vm(vm) {
_creditSpeed = 4;
_creditsActive = false;
}
void WidgetCredits::initCredits() {
Resources &res = *_vm->_res;
Screen &screen = *_vm->_screen;
Common::SeekableReadStream *stream = res.load("credits.txt");
int spacing = screen.fontHeight() * 2;
int yp = screen.h();
_creditsActive = true;
_creditLines.clear();
while (stream->pos() < stream->size()) {
Common::String line = stream->readLine();
if (line.hasPrefix("Scroll Speed")) {
const char *p = line.c_str() + 12;
while ((*p < '0') || (*p > '9'))
p++;
_creditSpeed = atoi(p);
} else if (line.hasPrefix("Y Spacing")) {
const char *p = line.c_str() + 12;
while ((*p < '0') || (*p > '9'))
p++;
spacing = atoi(p) + screen.fontHeight() + 1;
} else {
int width = screen.stringWidth(line) + 2;
_creditLines.push_back(CreditLine(line, Common::Point((screen.w() - width) / 2 + 1, yp), width));
yp += spacing;
}
}
// Post-processing for finding split lines
for (int l = 0; l < (int)_creditLines.size(); ++l) {
CreditLine &cl = _creditLines[l];
const char *p = strchr(cl._line.c_str(), '-');
if (p != nullptr && p[1] == '>') {
cl._line2 = Common::String(p + 3);
cl._line = Common::String(cl._line.c_str(), p);
int width = cl._width;
int width1 = screen.stringWidth(cl._line);
int width2 = screen.stringWidth(cl._line2);
int c = 1;
for (int l1 = l + 1; l1 < (int)_creditLines.size(); ++l1) {
if ((p = strchr(_creditLines[l1]._line.c_str(), '-')) != nullptr) {
if (p[1] == '>') {
Common::String line1 = Common::String(_creditLines[l1]._line.c_str(), p);
Common::String line2 = Common::String(p + 3);
width1 = MAX(width1, screen.stringWidth(line1));
if (screen.stringWidth(line2) > width2)
width2 = screen.stringWidth(line2);
++c;
} else {
break;
}
} else {
break;
}
}
width = width1 + width2 + screen.widestChar();
width1 += screen.widestChar();
for (int l1 = l; l1 < l + c; ++l1) {
_creditLines[l1]._width = width;
_creditLines[l1]._xOffset = width1;
}
l += c - 1;
}
}
delete stream;
}
void WidgetCredits::close() {
_creditsActive = false;
_creditLines.clear();
}
void WidgetCredits::drawCredits() {
Screen &screen = *_vm->_screen;
Common::Rect screenRect(0, 0, screen.w(), screen.h());
Surface &bb1 = screen._backBuffer1;
for (uint idx = 0; idx < _creditLines.size() && _creditLines[idx]._position.y < screen.h(); ++idx) {
if (screenRect.contains(_creditLines[idx]._position)) {
if (!_creditLines[idx]._line2.empty()) {
int x1 = _creditLines[idx]._position.x;
int x2 = x1 + _creditLines[idx]._xOffset;
const Common::String &line1 = _creditLines[idx]._line;
const Common::String &line2 = _creditLines[idx]._line2;
bb1.writeString(line1, Common::Point(x1 - 1, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(line1, Common::Point(x1, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(line1, Common::Point(x1 + 1, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(line1, Common::Point(x1 - 1, _creditLines[idx]._position.y), 0);
bb1.writeString(line1, Common::Point(x1 + 1, _creditLines[idx]._position.y), 0);
bb1.writeString(line1, Common::Point(x1 - 1, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(line1, Common::Point(x1, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(line1, Common::Point(x1 + 1, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(line1, Common::Point(x1, _creditLines[idx]._position.y), INFO_TOP);
bb1.writeString(line2, Common::Point(x2 - 1, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(line2, Common::Point(x2, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(line2, Common::Point(x2 + 1, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(line2, Common::Point(x2 - 1, _creditLines[idx]._position.y), 0);
bb1.writeString(line2, Common::Point(x2 + 1, _creditLines[idx]._position.y), 0);
bb1.writeString(line2, Common::Point(x2 - 1, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(line2, Common::Point(x2, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(line2, Common::Point(x2 + 1, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(line2, Common::Point(x2, _creditLines[idx]._position.y), INFO_TOP);
} else {
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x - 1, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x + 1, _creditLines[idx]._position.y - 1), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x - 1, _creditLines[idx]._position.y), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x + 1, _creditLines[idx]._position.y), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x - 1, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x + 1, _creditLines[idx]._position.y + 1), 0);
bb1.writeString(_creditLines[idx]._line, Common::Point(_creditLines[idx]._position.x, _creditLines[idx]._position.y), INFO_TOP);
}
}
}
}
void WidgetCredits::blitCredits() {
Screen &screen = *_vm->_screen;
Common::Rect screenRect(0, -_creditSpeed, screen.w(), screen.h() + _creditSpeed);
for (uint idx = 0; idx < _creditLines.size(); ++idx) {
if (screenRect.contains(_creditLines[idx]._position)) {
Common::Rect r(_creditLines[idx]._width, screen.fontHeight() + 2);
r.moveTo(_creditLines[idx]._position.x, _creditLines[idx]._position.y - 1);
screen.slamRect(r);
}
_creditLines[idx]._position.y -= _creditSpeed;
}
}
void WidgetCredits::eraseCredits() {
Screen &screen = *_vm->_screen;
Common::Rect screenRect(0, -_creditSpeed, screen.w(), screen.h() + _creditSpeed);
for (uint idx = 0; idx < _creditLines.size(); ++idx) {
if (screenRect.contains(_creditLines[idx]._position)) {
Common::Rect r(_creditLines[idx]._width, screen.fontHeight() + 3);
r.moveTo(_creditLines[idx]._position.x, _creditLines[idx]._position.y - 1 + _creditSpeed);
screen.restoreBackground(r);
}
}
if (_creditLines[_creditLines.size() - 1]._position.y < -_creditSpeed) {
// Completely finished credits display. Note that the credits will still remain flagged as active,
// so that the user interface knows not to allow and standard scene interaction
_creditLines.clear();
}
}
} // End of namespace Tattoo
} // End of namespace Sherlock
|