aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/graphics/gui32.cpp
blob: 132ae67a85f7c3976eb8ad71e5b2e751d52db60e (plain)
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
/* 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/timer.h"
#include "common/util.h"

#include "sci/sci.h"
#include "sci/debug.h"	// for g_debug_sleeptime_factor
#include "sci/event.h"
#include "sci/engine/state.h"
#include "sci/engine/selector.h"
#include "sci/graphics/gui32.h"
#include "sci/graphics/screen.h"
#include "sci/graphics/palette.h"
#include "sci/graphics/cursor.h"
#include "sci/graphics/cache.h"
#include "sci/graphics/compare.h"
#include "sci/graphics/frameout.h"
#include "sci/graphics/paint32.h"
#include "sci/graphics/picture.h"
#include "sci/graphics/robot.h"
#include "sci/graphics/view.h"

namespace Sci {

SciGui32::SciGui32(EngineState *state, GfxScreen *screen, GfxPalette *palette, GfxCache *cache, Cursor *cursor)
	: _s(state), _screen(screen), _palette(palette), _cache(cache), _cursor(cursor) {

	_compare = new GfxCompare(_s->_segMan, _s->_kernel, _cache, _screen);
	_paint32 = new GfxPaint32(_s->resMan, _s->_segMan, _s->_kernel, _cache, _screen, _palette);
	_s->_gfxPaint = _paint32;
	_frameout = new GfxFrameout(_s->_segMan, _s->resMan, _cache, _screen, _palette, _paint32);
}

SciGui32::~SciGui32() {
	delete _frameout;
	delete _paint32;
	delete _compare;
}

void SciGui32::resetEngineState(EngineState *s) {
	_s = s;
}

void SciGui32::init() {
}

void SciGui32::globalToLocal(int16 *x, int16 *y, reg_t planeObj) {
	//int16 resY = GET_SEL32V(_s->_segMan, planeObj, resY);
	//int16 resX = GET_SEL32V(_s->_segMan, planeObj, resX);
	//*x = ( *x * _screen->getWidth()) / resX;
	//*y = ( *y * _screen->getHeight()) / resY;
	*x -= GET_SEL32V(_s->_segMan, planeObj, left);
	*y -= GET_SEL32V(_s->_segMan, planeObj, top);
}

void SciGui32::localToGlobal(int16 *x, int16 *y, reg_t planeObj) {
	//int16 resY = GET_SEL32V(_s->_segMan, planeObj, resY);
	//int16 resX = GET_SEL32V(_s->_segMan, planeObj, resX);
	*x += GET_SEL32V(_s->_segMan, planeObj, left);
	*y += GET_SEL32V(_s->_segMan, planeObj, top);
	//*x = ( *x * resX) / _screen->getWidth();
	//*y = ( *y * resY) / _screen->getHeight();
}

void SciGui32::textSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight) {
	*textWidth = 0;
	*textHeight = 0;
}

void SciGui32::shakeScreen(uint16 shakeCount, uint16 directions) {
	while (shakeCount--) {
		if (directions & SCI_SHAKE_DIRECTION_VERTICAL)
			_screen->setVerticalShakePos(10);
		// TODO: horizontal shakes
		g_system->updateScreen();
		g_system->delayMillis(50);
		if (directions & SCI_SHAKE_DIRECTION_VERTICAL)
			_screen->setVerticalShakePos(0);
		g_system->updateScreen();
		g_system->delayMillis(50);
	}
}

uint16 SciGui32::onControl(byte screenMask, Common::Rect rect) {
	Common::Rect adjustedRect = rect;
	uint16 result;

	adjustedRect.translate(0, 10);

	result = _compare->onControl(screenMask, rect);
	return result;
}

void SciGui32::setNowSeen(reg_t objectReference) {
	_compare->SetNowSeen(objectReference);
}

bool SciGui32::canBeHere(reg_t curObject, reg_t listReference) {
	Common::Rect checkRect;
	uint16 signal, controlMask;
	bool result;

	checkRect.left = GET_SEL32V(_s->_segMan, curObject, brLeft);
	checkRect.top = GET_SEL32V(_s->_segMan, curObject, brTop);
	checkRect.right = GET_SEL32V(_s->_segMan, curObject, brRight);
	checkRect.bottom = GET_SEL32V(_s->_segMan, curObject, brBottom);
	signal = GET_SEL32V(_s->_segMan, curObject, signal);
	controlMask = GET_SEL32V(_s->_segMan, curObject, illegalBits);
	result = (_compare->onControl(SCI_SCREEN_MASK_CONTROL, checkRect) & controlMask) ? false : true;
	if ((result)) { // gui16 && (signal & (kSignalIgnoreActor | kSignalRemoveView)) == 0) {
		List *list = _s->_segMan->lookupList(listReference);
		if (!list)
			error("kCanBeHere called with non-list as parameter");

		result = _compare->CanBeHereCheckRectList(curObject, checkRect, list);
	}
	return result;
}

bool SciGui32::isItSkip(GuiResourceId viewId, int16 loopNo, int16 celNo, Common::Point position) {
	View *tmpView = _cache->getView(viewId);
	CelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
	position.x = CLIP<int>(position.x, 0, celInfo->width - 1);
	position.y = CLIP<int>(position.y, 0, celInfo->height - 1);
	byte *celData = tmpView->getBitmap(loopNo, celNo);
	bool result = (celData[position.y * celInfo->width + position.x] == celInfo->clearKey);
	return result;
}

void SciGui32::baseSetter(reg_t object) {
	if (lookup_selector(_s->_segMan, object, _s->_kernel->_selectorCache.brLeft, NULL, NULL) == kSelectorVariable) {
		int16 x = GET_SEL32V(_s->_segMan, object, x);
		int16 y = GET_SEL32V(_s->_segMan, object, y);
		int16 z = (_s->_kernel->_selectorCache.z > -1) ? GET_SEL32V(_s->_segMan, object, z) : 0;
		int16 yStep = GET_SEL32V(_s->_segMan, object, yStep);
		GuiResourceId viewId = GET_SEL32V(_s->_segMan, object, view);
		int16 loopNo = GET_SEL32V(_s->_segMan, object, loop);
		int16 celNo = GET_SEL32V(_s->_segMan, object, cel);

		if (viewId != SIGNAL_OFFSET) {
			View *tmpView = _cache->getView(viewId);
			Common::Rect celRect;

			tmpView->getCelRect(loopNo, celNo, x, y, z, &celRect);
			celRect.bottom = y + 1;
			celRect.top = celRect.bottom - yStep;

			PUT_SEL32V(_s->_segMan, object, brLeft, celRect.left);
			PUT_SEL32V(_s->_segMan, object, brRight, celRect.right);
			PUT_SEL32V(_s->_segMan, object, brTop, celRect.top);
			PUT_SEL32V(_s->_segMan, object, brBottom, celRect.bottom);
		}
	}
}

void SciGui32::hideCursor() {
	_cursor->hide();
}

void SciGui32::showCursor() {
	_cursor->show();
}

bool SciGui32::isCursorVisible() {
	return _cursor->isVisible();
}

void SciGui32::setCursorShape(GuiResourceId cursorId) {
	_cursor->setShape(cursorId);
}

void SciGui32::setCursorView(GuiResourceId viewNum, int loopNum, int cellNum, Common::Point *hotspot) {
	_cursor->setView(viewNum, loopNum, cellNum, hotspot);
}

void SciGui32::setCursorPos(Common::Point pos) {
	//pos.y += _gfx->GetPort()->top;
	//pos.x += _gfx->GetPort()->left;
	moveCursor(pos);
}

Common::Point SciGui32::getCursorPos() {
	return _cursor->getPosition();
}

void SciGui32::moveCursor(Common::Point pos) {
	// pos.y += _windowMgr->_picWind->rect.top;
	// pos.x += _windowMgr->_picWind->rect.left;

	// pos.y = CLIP<int16>(pos.y, _windowMgr->_picWind->rect.top, _windowMgr->_picWind->rect.bottom - 1);
	// pos.x = CLIP<int16>(pos.x, _windowMgr->_picWind->rect.left, _windowMgr->_picWind->rect.right - 1);

	if (pos.x > _screen->getWidth() || pos.y > _screen->getHeight()) {
		warning("attempt to place cursor at invalid coordinates (%d, %d)", pos.y, pos.x);
		return;
	}

	_cursor->setPosition(pos);

	// Trigger event reading to make sure the mouse coordinates will
	// actually have changed the next time we read them.
	_s->_event->get(SCI_EVENT_PEEK);
}

void SciGui32::setCursorZone(Common::Rect zone) {
	_cursor->setMoveZone(zone);
}
void SciGui32::addScreenItem(reg_t object) {
	_frameout->kernelAddScreenItem(object);
}

void SciGui32::deleteScreenItem(reg_t object) {
	_frameout->kernelDeleteScreenItem(object);
}

void SciGui32::addPlane(reg_t object) {
	_frameout->kernelAddPlane(object);
}

void SciGui32::updatePlane(reg_t object) {
	_frameout->kernelUpdatePlane(object);
}

void SciGui32::deletePlane(reg_t object) {
	_frameout->kernelDeletePlane(object);
}

int16 SciGui32::getHighPlanePri() {
	return _frameout->kernelGetHighPlanePri();
}

void SciGui32::frameOut() {
	_frameout->kernelFrameout();
	_screen->copyToScreen();
}

void SciGui32::drawRobot(GuiResourceId robotId) {
	Robot *test = new Robot(_s->resMan, _screen, robotId);
	test->draw();
	delete test;
}

bool SciGui32::debugShowMap(int mapNo) {
	_screen->debugShowMap(mapNo);
	return false;
}

} // End of namespace Sci