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
|
/* 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 "illusions/illusions.h"
#include "illusions/screentext.h"
#include "illusions/dictionary.h"
#include "illusions/resources/fontresource.h"
#include "illusions/screen.h"
#include "illusions/textdrawer.h"
#include "engines/util.h"
#include "graphics/palette.h"
namespace Illusions {
ScreenText::ScreenText(IllusionsEngine *vm)
: _vm(vm), _surface(0) {
}
ScreenText::~ScreenText() {
}
void ScreenText::getTextInfoDimensions(WidthHeight &textInfoDimensions) {
textInfoDimensions = _dimensions;
}
void ScreenText::setTextInfoPosition(Common::Point position) {
_position = position;
clipTextInfoPosition(_position);
}
void ScreenText::updateTextInfoPosition(Common::Point position) {
WidthHeight dimensions;
getTextInfoDimensions(dimensions);
position.x = position.x - dimensions._width / 2;
position.y = position.y - dimensions._height / 2;
setTextInfoPosition(position);
}
void ScreenText::clipTextInfoPosition(Common::Point &position) {
// TODO Set min/max for BBDOU
if (position.x < 2)
position.x = 2;
else if (position.x + _dimensions._width > 318)
position.x = 318 - _dimensions._width;
if (position.y < 2)
position.y = 2;
else if (position.y + _dimensions._height > 198)
position.y = 198 - _dimensions._height;
}
bool ScreenText::refreshScreenText(FontResource *font, WidthHeight dimensions, Common::Point offsPt,
uint16 *text, uint textFlags, uint16 color2, uint16 color1, uint16 *&outTextPtr) {
TextDrawer textDrawer;
bool done = textDrawer.wrapText(font, text, &dimensions, offsPt, textFlags, outTextPtr);
_surface = _vm->_screen->allocSurface(dimensions._width, dimensions._height);
_dimensions = dimensions;
textDrawer.drawText(_vm->_screen, _surface, color2, color1);
return done;
}
bool ScreenText::insertText(uint16 *text, uint32 fontId, WidthHeight dimensions, Common::Point offsPt, uint flags,
uint16 color2, uint16 color1, byte colorR, byte colorG, byte colorB, uint16 *&outTextPtr) {
if (!_screenTexts.empty()) {
ScreenTextEntry *screenText = _screenTexts.back();
screenText->_info._position = _position;
freeTextSurface();
}
ScreenTextEntry *screenText = new ScreenTextEntry();
screenText->_info._fontId = fontId;
screenText->_info._dimensions = dimensions;
screenText->_info._offsPt = offsPt;
screenText->_info._flags = 0;
if (flags & 8)
screenText->_info._flags |= 8;
if (flags & 0x10)
screenText->_info._flags |= 0x10;
if (flags & 1)
screenText->_info._flags |= 1;
else
screenText->_info._flags |= 2;
screenText->_info._color2 = color2;
screenText->_info._color1 = color1;
screenText->_info._colorR = colorR;
screenText->_info._colorG = colorG;
screenText->_info._colorB = colorB;
_screenTexts.push_back(screenText);
FontResource *font = _vm->_dict->findFont(screenText->_info._fontId);
bool done = refreshScreenText(font, screenText->_info._dimensions, screenText->_info._offsPt,
text, screenText->_info._flags, screenText->_info._color2, screenText->_info._color1,
outTextPtr);
debug("font->getColorIndex(): %d", font->getColorIndex());
_vm->_screen->setPaletteEntry(font->getColorIndex(), screenText->_info._colorR, screenText->_info._colorG, screenText->_info._colorB);
uint16 *textPart = screenText->_text;
while (text != outTextPtr)
*textPart++ = *text++;
*textPart = 0;
updateTextInfoPosition(Common::Point(160, 100));
return done;
}
void ScreenText::removeText() {
freeTextSurface();
if (!_screenTexts.empty()) {
ScreenTextEntry *screenText = _screenTexts.back();
delete screenText;
_screenTexts.pop_back();
}
if (!_screenTexts.empty()) {
ScreenTextEntry *screenText = _screenTexts.back();
if (screenText->_info._fontId) {
uint16 *outTextPtr;
FontResource *font = _vm->_dict->findFont(screenText->_info._fontId);
refreshScreenText(font, screenText->_info._dimensions, screenText->_info._offsPt,
screenText->_text, screenText->_info._flags, screenText->_info._color2, screenText->_info._color1,
outTextPtr);
_vm->_screen->setPaletteEntry(font->getColorIndex(), screenText->_info._colorR, screenText->_info._colorG, screenText->_info._colorB);
setTextInfoPosition(screenText->_info._position);
}
}
}
void ScreenText::clearText() {
if (!_screenTexts.empty()) {
ScreenTextEntry *screenText = _screenTexts.back();
screenText->_info._position = _position;
freeTextSurface();
}
ScreenTextEntry *screenText = new ScreenTextEntry();
screenText->_info._fontId = 0;
_screenTexts.push_back(screenText);
}
void ScreenText::freeTextSurface() {
if (_surface) {
_surface->free();
delete _surface;
_surface = 0;
}
}
} // End of namespace Illusions
|