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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
/* 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.
*
* $URL$
* $Id$
*
*/
#include "common/util.h"
#include "sci/sci.h"
#include "sci/engine/state.h"
#include "sci/tools.h"
#include "sci/gui/gui_screen.h"
#include "sci/gui/gui_gfx.h"
#include "sci/gui/gui_windowmgr.h"
#include "sci/gui/gui_memmgr.h"
#include "sci/gui/gui_view.h"
#include "sci/gfx/operations.h"
namespace Sci {
SciGUI::SciGUI(OSystem *system, EngineState *state)
: _system(system), _s(state) {
_screen = new SciGUIscreen(_system, _s);
_gfx = new SciGUIgfx(_system, _s, _screen);
_windowMgr = new SciGUIwindowMgr(_s, _gfx);
}
SciGUI::SciGUI() {
}
SciGUI::~SciGUI() {
}
void SciGUI::init(bool oldGfxFunctions) {
_usesOldGfxFunctions = oldGfxFunctions;
/* Set default SCI0 palette */
}
int16 SciGUI::getTimeTicks() {
return _gfx->_sysTicks;
}
void SciGUI::wait(int16 ticks) {
uint32 waitto = _gfx->_sysTicks + ticks;
do {
//eventMgr->pollEvents();
_system->delayMillis(_gfx->_sysSpeed >> 11);
} while (_gfx->_sysTicks < waitto);
}
void SciGUI::setPort(uint16 portPtr) {
switch (portPtr) {
case 0: _gfx->SetPort(_windowMgr->_wmgrPort); break;
case 0xFFFF: _gfx->SetPort(_gfx->_menuPort); break;
default:
_gfx->SetPort((sciPort *)heap2Ptr(portPtr));
};
}
void SciGUI::setPortPic(Common::Rect rect, int16 picTop, int16 picLeft) {
_windowMgr->_picWind->rect = rect;
_windowMgr->_picWind->top = picTop;
_windowMgr->_picWind->left = picLeft;
//if (argc >= 7)
//InitPri(42,190);
}
reg_t SciGUI::getPort() {
return make_reg(0, ptr2heap((byte *)_gfx->GetPort()));
}
void SciGUI::globalToLocal(int16 *x, int16 *y) {
sciPort *curPort = _gfx->GetPort();
*x = *x - curPort->left;
*y = *y - curPort->top;
}
void SciGUI::localToGlobal(int16 *x, int16 *y) {
sciPort *curPort = _gfx->GetPort();
*x = *x + curPort->left;
*y = *y + curPort->top;
}
reg_t SciGUI::newWindow(Common::Rect rect1, Common::Rect rect2, uint16 style, int16 priority, int16 colorPen, int16 colorBack, const char *title) {
sciWnd *wnd = NULL;
if (rect2.top != 0 && rect2.left != 0 && rect2.height() != 0 && rect2.width() != 0)
wnd = _windowMgr->NewWindow(&rect1, &rect2, title, style, priority, 0);
else
wnd = _windowMgr->NewWindow(&rect1, NULL, title, style, priority, 0);
wnd->penClr = colorPen;
wnd->backClr = colorBack;
_windowMgr->DrawWindow(wnd);
return make_reg(0, ptr2heap((byte *)wnd));
}
void SciGUI::disposeWindow(uint16 windowPtr, int16 arg2) {
sciWnd *wnd = (sciWnd *)heap2Ptr(windowPtr);
_windowMgr->DisposeWindow(wnd, arg2);
}
void SciGUI::display(const char *text, int argc, reg_t *argv) {
int displayArg;
sciPort oldPort;
int16 align = 0;
int16 bgcolor = -1, width = -1, bRedraw = 1;
byte bSaveUnder = false;
Common::Rect rect, *orect = &((sciWnd *)_gfx->GetPort())->rect0;
memcpy(&oldPort, _gfx->GetPort(), sizeof(sciPort));
// setting defaults
_gfx->PenMode(0);
_gfx->PenColor(0);
_gfx->TextFace(0);
// processing codes in argv
while (argc > 0) {
displayArg = argv[0].toUint16();
argc--; argv++;
switch (displayArg - 100) {
case 0:
_gfx->MoveTo(argv[0].toUint16(), argv[1].toUint16());
argc -= 2; argv += 2;
break;// move pen
case 1:
align = argv[0].toUint16();
argc--; argv++;
break;// set alignment
case 2:
_gfx->PenColor(argv[0].toUint16());
argc--; argv++;
break;// set pen color
case 3:
bgcolor = argv[0].toUint16();
argc--; argv++;
break;
case 4:
_gfx->TextFace(argv[0].toUint16());
argc--; argv++;
break;// set text grayout flag
case 5:
_gfx->SetFont(argv[0].toUint16());
argc--; argv++;
break;// set font
case 6:
width = argv[0].toUint16();
argc--; argv++;
break;
case 7:
bSaveUnder = 1;
break;
case 8: // restore under
// if (hunk2Ptr(*pArgs)) {
// memcpy(&rect, hunk2Ptr(*pArgs), sizeof(Common::Rect));
// // rect is now absolute. Have to move it to be port-relative
// rect.translate(-_gfx->RGetPort()->left, -_gfx->RGetPort()->top);
// _gfx->RestoreBits(*pArgs);
// ReAnimate(&rect);
// }
// finishing loop
argc = 0;
break;
case 0x15:
bRedraw = 0;
break;
default:
warning("Unknown kDisplay argument %X", displayArg);
break;
}
}
// now drawing the text
_gfx->TextSize(rect, text, -1, width);
_gfx->Move((orect->left <= 320 ? 0 : 320 - orect->left), (orect->top <= 200 ? 0 : 200 - orect->top)); // move port to (0,0)
rect.moveTo(_gfx->GetPort()->curLeft, _gfx->GetPort()->curTop);
// if (bSaveUnder)
// _acc = _gfx->SaveBits(rect, 1);
if (bgcolor != -1)
_gfx->FillRect(rect, 1, bgcolor, 0, 0);
_gfx->TextBox(text, 0, rect, align, -1);
// if (_picNotValid == 0 && bRedraw)
// _gfx->ShowBits(rect, 1);
// restoring port and cursor pos
sciPort *currport = _gfx->GetPort();
uint16 tTop = currport->curTop;
uint16 tLeft = currport->curLeft;
memcpy(currport, &oldPort, sizeof(sciPort));
currport->curTop = tTop;
currport->curLeft = tLeft;
_screen->UpdateWhole();
}
void SciGUI::textSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight) {
Common::Rect rect(0, 0, *textWidth, *textHeight);
_gfx->TextSize(rect, text, font, maxWidth);
*textWidth = rect.width(); *textHeight = rect.height();
}
// Used SCI1+ for text codes
void SciGUI::textFonts(int argc, reg_t *argv) {
_gfx->SetTextFonts(argc, argv);
}
// Used SCI1+ for text codes
void SciGUI::textColors(int argc, reg_t *argv) {
_gfx->SetTextColors(argc, argv);
}
void SciGUI::drawPicture(sciResourceId pictureId, uint16 style, uint16 flags, int16 EGApaletteNo) {
bool addToFlag = flags ? true : false;
sciPort *oldPort = _gfx->SetPort((sciPort *)_windowMgr->_picWind);
if (_windowMgr->isFrontWindow(_windowMgr->_picWind)) {
_gfx->drawPicture(pictureId, style, addToFlag, EGApaletteNo);
} else {
_windowMgr->BeginUpdate(_windowMgr->_picWind);
_gfx->drawPicture(pictureId, style, addToFlag, EGApaletteNo);
_windowMgr->EndUpdate(_windowMgr->_picWind);
}
_screen->UpdateWhole();
_gfx->SetPort(oldPort);
_s->pic_not_valid = 1;
}
void SciGUI::drawCell(sciResourceId viewId, uint16 loopNo, uint16 cellNo, uint16 leftPos, uint16 topPos, int16 priority, uint16 paletteNo) {
_gfx->drawCell(viewId, loopNo, cellNo, leftPos, topPos, priority, paletteNo);
_gfx->SetCLUT(&_gfx->_sysPalette);
_screen->UpdateWhole();
}
void SciGUI::drawControlButton(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 style, bool inverse) {
rect.grow(1);
_gfx->EraseRect(rect);
_gfx->FrameRect(rect);
rect.grow(-2);
_gfx->TextFace(style & 1 ? 0 : 1);
_gfx->TextBox(text, 0, rect, 1, fontId);
_gfx->TextFace(0);
if (style & 8) { // selected
rect.grow(1);
_gfx->FrameRect(rect);
}
_screen->UpdateWhole();
}
void SciGUI::drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, bool inverse) {
rect.grow(1);
_gfx->EraseRect(rect);
rect.grow(-1);
_gfx->TextBox(text, 0, rect, mode, fontId);
if (style & 8) { // selected
_gfx->FrameRect(rect);
}
_screen->UpdateWhole();
}
void SciGUI::graphFillBoxForeground(Common::Rect rect) {
_gfx->PaintRect(rect);
_screen->UpdateWhole();
}
void SciGUI::graphFillBoxBackground(Common::Rect rect) {
_gfx->EraseRect(rect);
_screen->UpdateWhole();
}
void SciGUI::graphFillBox(Common::Rect rect, uint16 colorMask, int16 color, int16 priority, int16 control) {
_gfx->FillRect(rect, colorMask, color, priority, control);
_screen->UpdateWhole();
}
void SciGUI::graphDrawLine(Common::Rect rect, int16 color, int16 priority, int16 control) {
_gfx->Draw_Line(rect.left, rect.top, rect.right, rect.bottom, color, priority, control);
_screen->UpdateWhole();
}
reg_t SciGUI::graphSaveBox(Common::Rect rect, uint16 flags) {
return _gfx->SaveBits(rect, flags);
}
void SciGUI::graphRestoreBox(reg_t handle) {
_gfx->RestoreBits(handle);
_screen->UpdateWhole();
}
void SciGUI::paletteSet(int resourceNo, int flags) {
_gfx->SetResPalette(resourceNo, flags);
}
int16 SciGUI::paletteFind(int r, int g, int b) {
return _gfx->MatchColor(&_gfx->_sysPalette, r, g, b) & 0xFF;
}
void SciGUI::paletteAnimate(int fromColor, int toColor, int speed) {
_gfx->animatePalette(fromColor, toColor, speed);
}
int16 SciGUI::onControl(byte screenMask, Common::Rect rect) {
sciPort *oldPort = _gfx->SetPort((sciPort *)_windowMgr->_picWind);
int16 result;
result = _gfx->onControl(screenMask, rect);
_gfx->SetPort(oldPort);
return result;
}
void SciGUI::moveCursor(int16 x, int16 y) {
Common::Point newPos;
sciPort *curPort = _gfx->GetPort();
x += _windowMgr->_picWind->rect.left;
y += _windowMgr->_picWind->rect.top;
newPos.x = CLIP<int16> (x, _windowMgr->_picWind->rect.left, _windowMgr->_picWind->rect.right - 1);
newPos.y = CLIP<int16> (y, _windowMgr->_picWind->rect.top, _windowMgr->_picWind->rect.bottom - 1);
gfxop_set_pointer_position(_s->gfx_state, newPos);
}
} // End of namespace Sci
|