1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "gob/draw.h"
24 #include "gob/game.h"
25 #include "gob/global.h"
26 #include "gob/inter.h"
27 #include "gob/resources.h"
28 
29 namespace Gob {
30 
Draw_Fascination(GobEngine * vm)31 Draw_Fascination::Draw_Fascination(GobEngine *vm) : Draw_v2(vm) {
32 }
33 
spriteOperation(int16 operation)34 void Draw_Fascination::spriteOperation(int16 operation) {
35 	int16 len;
36 	int16 x, y;
37 	SurfacePtr sourceSurf, destSurf;
38 	bool deltaVeto;
39 	int16 left;
40 	int16 ratio;
41 	Resource *resource;
42 
43 	deltaVeto = (operation & 0x10) != 0;
44 	operation &= 0x0F;
45 
46 	if (_sourceSurface >= 100)
47 		_sourceSurface -= 80;
48 	if (_destSurface >= 100)
49 		_destSurface -= 80;
50 
51 	if ((_renderFlags & RENDERFLAG_USEDELTAS) && !deltaVeto) {
52 		if ((_sourceSurface == kBackSurface) && (operation != DRAW_LOADSPRITE)) {
53 			_spriteLeft += _backDeltaX;
54 			_spriteTop += _backDeltaY;
55 		}
56 
57 		if (_destSurface == kBackSurface) {
58 			_destSpriteX += _backDeltaX;
59 			_destSpriteY += _backDeltaY;
60 			if ((operation == DRAW_DRAWLINE) ||
61 			   ((operation >= DRAW_DRAWBAR) && (operation <= DRAW_FILLRECTABS))) {
62 				_spriteRight += _backDeltaX;
63 				_spriteBottom += _backDeltaY;
64 			}
65 		}
66 	}
67 
68 	if (_renderFlags & 0x20) {
69 		if (_destSurface == kBackSurface || (operation == 0 && _sourceSurface == kBackSurface)) {
70 			drawWin(operation);
71 			return;
72 		}
73 	}
74 
75 
76 	int16 spriteLeft = _spriteLeft;
77 	int16 spriteTop = _spriteTop;
78 	int16 spriteRight = _spriteRight;
79 	int16 spriteBottom = _spriteBottom;
80 	int16 destSpriteX = _destSpriteX;
81 	int16 destSpriteY = _destSpriteY;
82 	int16 destSurface = _destSurface;
83 	int16 sourceSurface = _sourceSurface;
84 
85 	if (_vm->_video->_splitSurf && ((_destSurface == kFrontSurface) || (_destSurface == kBackSurface))) {
86 		if ((_destSpriteY >= _vm->_video->_splitStart)) {
87 			_destSpriteY -= _vm->_video->_splitStart;
88 			if ((operation == DRAW_DRAWLINE) ||
89 				 ((operation >= DRAW_DRAWBAR) && (operation <= DRAW_FILLRECTABS)))
90 				_spriteBottom -= _vm->_video->_splitStart;
91 
92 			_destSurface += 4;
93 		}
94 
95 		if ((_spriteTop >= _vm->_video->_splitStart) && (operation == DRAW_BLITSURF)) {
96 			_spriteTop -= _vm->_video->_splitStart;
97 			if (_destSurface < 24)
98 				_destSurface += 4;
99 		}
100 
101 	}
102 
103 	adjustCoords(0, &_destSpriteX, &_destSpriteY);
104 	if ((operation != DRAW_LOADSPRITE) && (_needAdjust != 2)) {
105 		adjustCoords(0, &_spriteRight, &_spriteBottom);
106 		adjustCoords(0, &_spriteLeft, &_spriteTop);
107 
108 		if (operation == DRAW_DRAWLINE) {
109 			if ((_spriteRight == _destSpriteX) || (_spriteBottom == _destSpriteY)) {
110 				operation = DRAW_FILLRECTABS;
111 				_backColor = _frontColor;
112 			}
113 		} else if (operation == DRAW_DRAWLETTER)
114 			operation = DRAW_BLITSURF;
115 
116 		if (operation == DRAW_DRAWLINE) {
117 			if (_spriteBottom < _destSpriteY) {
118 				SWAP(_spriteBottom, _destSpriteY);
119 				SWAP(_spriteRight, _destSpriteX);
120 			}
121 		} else if ((operation == DRAW_LOADSPRITE) ||
122 		           (operation > DRAW_PRINTTEXT)) {
123 			if (_spriteBottom < _destSpriteY)
124 				SWAP(_spriteBottom, _destSpriteY);
125 			if (_spriteRight < _destSpriteX)
126 				SWAP(_spriteRight, _destSpriteX);
127 			_spriteRight++;
128 			_spriteBottom++;
129 		}
130 	}
131 
132 	sourceSurf = _spritesArray[_sourceSurface];
133 	destSurf = _spritesArray[_destSurface];
134 
135 	if (!destSurf) {
136 		warning("Can't do operation %d on surface %d: nonexistent", operation, _destSurface);
137 		return;
138 	}
139 
140 	switch (operation) {
141 	case DRAW_DRAWLETTER:
142 	case DRAW_BLITSURF:
143 		if (!sourceSurf || !destSurf)
144 			break;
145 
146 		_spritesArray[_destSurface]->blit(*_spritesArray[_sourceSurface],
147 				_spriteLeft, spriteTop,
148 				_spriteLeft + _spriteRight - 1,
149 				_spriteTop + _spriteBottom - 1,
150 				_destSpriteX, _destSpriteY, (_transparency == 0) ? -1 : 0);
151 
152 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
153 				_destSpriteX + _spriteRight - 1, _destSpriteY + _spriteBottom - 1);
154 		break;
155 
156 	case DRAW_PUTPIXEL:
157 		_spritesArray[_destSurface]->putPixel(_destSpriteX, _destSpriteY, _frontColor);
158 
159 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY, _destSpriteX, _destSpriteY);
160 		break;
161 
162 	case DRAW_FILLRECT:
163 		_spritesArray[_destSurface]->fillRect(destSpriteX,
164 				_destSpriteY, _destSpriteX + _spriteRight - 1,
165 				_destSpriteY + _spriteBottom - 1, _backColor);
166 
167 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
168 				_destSpriteX + _spriteRight - 1, _destSpriteY + _spriteBottom - 1);
169 		break;
170 
171 	case DRAW_DRAWLINE:
172 		_spritesArray[_destSurface]->drawLine(_destSpriteX, _destSpriteY,
173 		    _spriteRight, _spriteBottom, _frontColor);
174 
175 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY, _spriteRight, _spriteBottom);
176 		break;
177 
178 	case DRAW_INVALIDATE:
179 		_spritesArray[_destSurface]->drawCircle(_destSpriteX,
180 				_destSpriteY, _spriteRight, _frontColor);
181 
182 		dirtiedRect(_destSurface, _destSpriteX - _spriteRight, _destSpriteY - _spriteBottom,
183 				_destSpriteX + _spriteRight, _destSpriteY + _spriteBottom);
184 		break;
185 
186 	case DRAW_LOADSPRITE:
187 		resource = _vm->_game->_resources->getResource((uint16) _spriteLeft,
188 			                                             &_spriteRight, &_spriteBottom);
189 
190 		if (!resource)
191 			break;
192 
193 		_vm->_video->drawPackedSprite(resource->getData(),
194 				_spriteRight, _spriteBottom, _destSpriteX, _destSpriteY,
195 				_transparency, *_spritesArray[_destSurface]);
196 
197 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
198 				_destSpriteX + _spriteRight - 1, _destSpriteY + _spriteBottom - 1);
199 
200 		delete resource;
201 		break;
202 
203 	case DRAW_PRINTTEXT:
204 		len = strlen(_textToPrint);
205 		left = _destSpriteX;
206 
207 		if ((_fontIndex >= 4) || (_fontToSprite[_fontIndex].sprite == -1)) {
208 			Font *font = _fonts[_fontIndex];
209 			if (!font) {
210 				warning("Trying to print \"%s\" with undefined font %d", _textToPrint, _fontIndex);
211 				break;
212 			}
213 
214 			if (font->isMonospaced()) {
215 				if (((int8) _textToPrint[0]) == -1) {
216 					_vm->validateLanguage();
217 
218 					byte *dataBuf = _vm->_game->_resources->getTexts() + _textToPrint[1] + 1;
219 					len = *dataBuf++;
220 					for (int i = 0; i < len; i++, dataBuf += 2) {
221 						font->drawLetter(*_spritesArray[_destSurface], READ_LE_UINT16(dataBuf),
222 								_destSpriteX, _destSpriteY, _frontColor, _backColor, _transparency);
223 					}
224 				} else {
225 					font->drawString(_textToPrint, _destSpriteX, _destSpriteY, _frontColor,
226 							_backColor, _transparency, *_spritesArray[_destSurface]);
227 					_destSpriteX += len * font->getCharWidth();
228 				}
229 			} else {
230 				for (int i = 0; i < len; i++) {
231 					font->drawLetter(*_spritesArray[_destSurface], _textToPrint[i],
232 							_destSpriteX, _destSpriteY, _frontColor, _backColor, _transparency);
233 					_destSpriteX += font->getCharWidth(_textToPrint[i]);
234 				}
235 			}
236 
237 		} else {
238 			sourceSurf = _spritesArray[_fontToSprite[_fontIndex].sprite];
239 			ratio = ((sourceSurf == _frontSurface) || (sourceSurf == _backSurface)) ?
240 				320 : sourceSurf->getWidth();
241 			ratio /= _fontToSprite[_fontIndex].width;
242 			for (int i = 0; i < len; i++) {
243 				y = ((_textToPrint[i] - _fontToSprite[_fontIndex].base) / ratio)
244 					* _fontToSprite[_fontIndex].height;
245 				x = ((_textToPrint[i] - _fontToSprite[_fontIndex].base) % ratio)
246 					* _fontToSprite[_fontIndex].width;
247 				_spritesArray[_destSurface]->blit(*_spritesArray[_fontToSprite[_fontIndex].sprite], x, y,
248 						x + _fontToSprite[_fontIndex].width - 1,
249 						y + _fontToSprite[_fontIndex].height - 1,
250 						_destSpriteX, _destSpriteY, (_transparency == 0) ? -1 : 0);
251 				_destSpriteX += _fontToSprite[_fontIndex].width;
252 			}
253 		}
254 
255 		dirtiedRect(_destSurface, left, _destSpriteY,
256 				_destSpriteX - 1, _destSpriteY + _fonts[_fontIndex]->getCharHeight() - 1);
257 		break;
258 
259 	case DRAW_DRAWBAR:
260 		if (_needAdjust != 2) {
261 			_spritesArray[_destSurface]->fillRect(_destSpriteX, _spriteBottom - 1,
262 					_spriteRight, _spriteBottom, _frontColor);
263 
264 			_spritesArray[_destSurface]->fillRect( _destSpriteX, _destSpriteY,
265 					_destSpriteX + 1, _spriteBottom, _frontColor);
266 
267 			_spritesArray[_destSurface]->fillRect( _spriteRight - 1, _destSpriteY,
268 					_spriteRight, _spriteBottom, _frontColor);
269 
270 			_spritesArray[_destSurface]->fillRect( _destSpriteX, _destSpriteY,
271 					_spriteRight, _destSpriteY + 1, _frontColor);
272 		} else {
273 			_spritesArray[_destSurface]->drawLine(_destSpriteX, _spriteBottom,
274 					_spriteRight, _spriteBottom, _frontColor);
275 
276 			_spritesArray[_destSurface]->drawLine(_destSpriteX, _destSpriteY,
277 					_destSpriteX, _spriteBottom, _frontColor);
278 
279 			_spritesArray[_destSurface]->drawLine(_spriteRight, _destSpriteY,
280 					_spriteRight, _spriteBottom, _frontColor);
281 
282 			_spritesArray[_destSurface]->drawLine(_destSpriteX, _destSpriteY,
283 					_spriteRight, _destSpriteY, _frontColor);
284 		}
285 
286 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY, _spriteRight, _spriteBottom);
287 		break;
288 
289 	case DRAW_CLEARRECT:
290 		if ((_backColor != 16) && (_backColor != 144)) {
291 			_spritesArray[_destSurface]->fillRect(_destSpriteX, _destSpriteY, _spriteRight, _spriteBottom, _backColor);
292 		}
293 
294 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY, _spriteRight, _spriteBottom);
295 		break;
296 
297 	case DRAW_FILLRECTABS:
298 		_spritesArray[_destSurface]->fillRect(_destSpriteX, _destSpriteY, _spriteRight, _spriteBottom, _backColor);
299 
300 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY, _spriteRight, _spriteBottom);
301 		break;
302 
303 	default:
304 		break;
305 	}
306 
307 	_spriteLeft = spriteLeft;
308 	_spriteTop = spriteTop;
309 	_spriteRight = spriteRight;
310 	_spriteBottom = spriteBottom;
311 	_destSpriteX = destSpriteX;
312 	_destSpriteY = destSpriteY;
313 	_destSurface = destSurface;
314 	_sourceSurface = sourceSurface;
315 
316 	if (operation == DRAW_PRINTTEXT) {
317 		len = _fonts[_fontIndex]->getCharWidth();
318 		adjustCoords(1, &len, 0);
319 		_destSpriteX += len * strlen(_textToPrint);
320 	}
321 
322 	if ((_renderFlags & RENDERFLAG_USEDELTAS) && !deltaVeto) {
323 		if (_sourceSurface == kBackSurface) {
324 			_spriteLeft -= _backDeltaX;
325 			_spriteTop -= _backDeltaY;
326 		}
327 
328 		if (_destSurface == kBackSurface) {
329 			_destSpriteX -= _backDeltaX;
330 			_destSpriteY -= _backDeltaY;
331 		}
332 	}
333 }
334 
drawWin(int16 fct)335 void Draw_Fascination::drawWin(int16 fct) {
336 	int16 left;
337 	int16 top;
338 	int16 width;
339 	int16 height;
340 
341 	bool found = false;
342 	int len;
343 	Resource *resource;
344 	int table[10];
345 	SurfacePtr tempSrf;
346 
347 	if (_destSurface == kBackSurface) {
348 
349 		if (_vm->_global->_curWinId) {
350 			if (_fascinWin[_vm->_global->_curWinId].id == -1)
351 				return;
352 
353 			else {
354 				_destSpriteX += _fascinWin[_vm->_global->_curWinId].left;
355 				_destSpriteY += _fascinWin[_vm->_global->_curWinId].top;
356 				if (fct == 3 || (fct >= 7 && fct <= 9)) {
357 					_spriteRight  += _fascinWin[_vm->_global->_curWinId].left;
358 					_spriteBottom += _fascinWin[_vm->_global->_curWinId].top;
359 				}
360 			}
361 		}
362 
363 		left = _destSpriteX;
364 		top  = _destSpriteY;
365 
366 	} else {
367 		if (_vm->_global->_curWinId) {
368 			if (_fascinWin[_vm->_global->_curWinId].id == -1)
369 				return;
370 			else {
371 				_spriteLeft += _fascinWin[_vm->_global->_curWinId].left;
372 				_spriteTop  += _fascinWin[_vm->_global->_curWinId].top;
373 			}
374 		}
375 
376 		left = _spriteLeft;
377 		top  = _spriteTop;
378 	}
379 
380 	for (int i = 0; i < 10; i++)
381 		table[i] = 0;
382 
383 	switch (fct) {
384 	case DRAW_BLITSURF:    // 0 - move
385 	case DRAW_FILLRECT:    // 2 - fill rectangle
386 		width  = left + _spriteRight  - 1;
387 		height = top  + _spriteBottom - 1;
388 		break;
389 
390 	case DRAW_PUTPIXEL:    // 1 - put a pixel
391 		width  = _destSpriteX;
392 		height = _destSpriteY;
393 		break;
394 
395 	case DRAW_DRAWLINE:    // 3 - draw line
396 	case DRAW_DRAWBAR:     // 7 - draw border
397 	case DRAW_CLEARRECT:   // 8 - clear rectangle
398 	case DRAW_FILLRECTABS: // 9 - fill rectangle, with other coordinates
399 		width  = _spriteRight;
400 		height = _spriteBottom;
401 		break;
402 
403 	case DRAW_INVALIDATE:  // 4 - Draw a circle
404 		left   = _destSpriteX - _spriteRight;
405 		top    = _destSpriteY - _spriteRight;
406 		width  = _destSpriteX + _spriteRight;
407 		height = _destSpriteY + _spriteBottom;
408 		break;
409 
410 	case DRAW_LOADSPRITE:  // 5 - Uncompress and load a sprite
411 		resource = _vm->_game->_resources->getResource((_spriteLeft & 0x3FFF),
412 				&_spriteRight, &_spriteBottom);
413 
414 		if (!resource) {
415 			width  = 0;
416 			height = 0;
417 			break;
418 		}
419 
420 		_vm->_video->drawPackedSprite(resource->getData(),
421 				_spriteRight, _spriteBottom, _destSpriteX, _destSpriteY,
422 				_transparency, *_spritesArray[_destSurface]);
423 
424 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
425 				_destSpriteX + _spriteRight - 1, _destSpriteY + _spriteBottom - 1);
426 
427 		delete resource;
428 
429 		width  = _destSpriteX + _spriteRight  - 1;
430 		height = _destSpriteY + _spriteBottom - 1;
431 		break;
432 
433 	case DRAW_PRINTTEXT:  // 6 - Display string
434 		width  = _destSpriteX - 1 + strlen(_textToPrint) * _fonts[_fontIndex]->getCharWidth();
435 		height = _destSpriteY - 1 + _fonts[_fontIndex]->getCharHeight();
436 		break;
437 
438 	case DRAW_DRAWLETTER: // 10 - Display a character
439 		if (_fontToSprite[_fontIndex].sprite == -1) {
440 			width  = _destSpriteX - 1 + _fonts[_fontIndex]->getCharWidth();
441 			height = _destSpriteY - 1 + _fonts[_fontIndex]->getCharHeight();
442 		} else {
443 			width  = _destSpriteX + _fontToSprite[_fontIndex].width  - 1;
444 			height = _destSpriteY + _fontToSprite[_fontIndex].height - 1;
445 		}
446 		break;
447 
448 	default:
449 		error("winDraw - Unexpected fct value %d", fct);
450 		break;
451 	}
452 
453 	for (int i = 0; i < 10; i++) {
454 		if ((i != _vm->_global->_curWinId) && (_fascinWin[i].id != -1)) {
455 			if (!_vm->_global->_curWinId || _fascinWin[i].id>_fascinWin[_vm->_global->_curWinId].id) {
456 				if ((_fascinWin[i].left + _fascinWin[i].width  > left) && (width  >= _fascinWin[i].left) &&
457 				    (_fascinWin[i].top  + _fascinWin[i].height > top ) && (height >= _fascinWin[i].top)) {
458 					found = true;
459 					table[_fascinWin[i].id] = i;
460 				}
461 			}
462 		}
463 	}
464 
465 	if ((_sourceSurface == kBackSurface) && (fct == 0)) {
466 		_spritesArray[_destSurface]->blit(*_spritesArray[_sourceSurface],
467 								_spriteLeft, _spriteTop, _spriteLeft + _spriteRight - 1,
468 								_spriteTop + _spriteBottom - 1, _destSpriteX, _destSpriteY, (_transparency == 0) ? -1 : 0);
469 		if (!found)
470 			return;
471 
472 		int j = 0;
473 		if (_vm->_global->_curWinId != 0)
474 			j = _fascinWin[_vm->_global->_curWinId].id + 1;
475 
476 		for (int i = 9; i >= j; i--) {
477 			if (table[i])
478 				_spritesArray[_destSurface]->blit(*_fascinWin[table[i]].savedSurface,
479 										 _fascinWin[table[i]].left & 7, 0,
480 										(_fascinWin[table[i]].left & 7) + _fascinWin[table[i]].width - 1,
481 										 _fascinWin[table[i]].height - 1, _fascinWin[table[i]].left - _spriteLeft + _destSpriteX,
482 										 _fascinWin[table[i]].top - _spriteTop + _destSpriteY);
483 		}
484 		return;
485 	}
486 
487 	if (found) {
488 		tempSrf = _vm->_video->initSurfDesc(width - left + 1, height - top + 1);
489 		tempSrf->blit(*_backSurface, left, top, width, height, 0, 0);
490 
491 		int max = 0;
492 		if (_vm->_global->_curWinId != 0)
493 			max = _fascinWin[_vm->_global->_curWinId].id + 1;
494 
495 		for (int i = 9; i >= max; i--) {
496 			if (table[i])
497 				tempSrf->blit(*_fascinWin[table[i]].savedSurface,
498 										 _fascinWin[table[i]].left & 7, 0,
499 										(_fascinWin[table[i]].left & 7) + _fascinWin[table[i]].width - 1,
500 										 _fascinWin[table[i]].height - 1,
501 										 _fascinWin[table[i]].left  - left,
502 										 _fascinWin[table[i]].top   - top);
503 		}
504 
505 		invalidateRect(left, top, width, height);
506 
507 		switch (fct) {
508 		case DRAW_BLITSURF:    // 0 - move
509 			tempSrf->blit(*_spritesArray[_sourceSurface],
510 									_spriteLeft, _spriteTop, _spriteLeft + _spriteRight - 1,
511 									_spriteTop + _spriteBottom - 1, 0, 0, (_transparency == 0) ? -1 : 0);
512 			break;
513 
514 		case DRAW_PUTPIXEL:    // 1 - put a pixel
515 			tempSrf->putPixel(0, 0, _frontColor);
516 			break;
517 
518 		case DRAW_FILLRECT:    // 2 - fill rectangle
519 			tempSrf->fillRect(0, 0, _spriteRight - 1, _spriteBottom - 1, _backColor);
520 			break;
521 
522 		case DRAW_DRAWLINE:    // 3 - draw line
523 			tempSrf->drawLine(0, 0, _spriteRight - _destSpriteX, _spriteBottom - _destSpriteY, _frontColor);
524 			break;
525 
526 		case DRAW_INVALIDATE:  // 4 - Draw a circle
527 			tempSrf->drawCircle(_spriteRight, _spriteRight, _spriteRight, _frontColor);
528 			break;
529 
530 		case DRAW_LOADSPRITE:  // 5 - Uncompress and load a sprite
531 			decompWin(0, 0, tempSrf);
532 			break;
533 
534 		case DRAW_PRINTTEXT:   // 6 - Display string
535 			len = strlen(_textToPrint);
536 			for (int j = 0; j < len; j++)
537 				_fonts[_fontIndex]->drawLetter(*tempSrf, _textToPrint[j],
538 						j * _fonts[_fontIndex]->getCharWidth(), 0, _frontColor, _backColor, _transparency);
539 			_destSpriteX += len * _fonts[_fontIndex]->getCharWidth();
540 			break;
541 
542 		case DRAW_DRAWBAR:     // 7 - draw border
543 			tempSrf->drawLine(0, _spriteBottom - _destSpriteY, _spriteRight - _destSpriteX, _spriteBottom - _destSpriteY, _frontColor);
544 			tempSrf->drawLine(0, 0, 0, _spriteBottom - _destSpriteY, _frontColor);
545 			tempSrf->drawLine(_spriteRight - _destSpriteX, 0, _spriteRight - _destSpriteX, _spriteBottom - _destSpriteY, _frontColor);
546 			tempSrf->drawLine(0, 0, _spriteRight - _destSpriteX, 0, _frontColor);
547 			break;
548 
549 		case DRAW_CLEARRECT:   // 8 - clear rectangle
550 			if (_backColor < 16)
551 				tempSrf->fillRect(0, 0, _spriteRight - _destSpriteX, _spriteBottom - _destSpriteY, _backColor);
552 			break;
553 
554 		case DRAW_FILLRECTABS: // 9 - fill rectangle, with other coordinates
555 			tempSrf->fillRect(0, 0, _spriteRight - _destSpriteX, _spriteBottom - _destSpriteY, _backColor);
556 			break;
557 
558 		case DRAW_DRAWLETTER:  // 10 - Display a character
559 			if (_fontToSprite[_fontIndex].sprite == -1) {
560 
561 				if (_letterToPrint)
562 					_fonts[_fontIndex]->drawLetter(*tempSrf, _letterToPrint, 0, 0, _frontColor, _backColor, _transparency);
563 			} else {
564 				int xx, yy, nn;
565 				nn = _spritesArray[_fontToSprite[_fontIndex].sprite]->getWidth() / _fontToSprite[_fontIndex].width;
566 				yy = ((_letterToPrint - _fontToSprite[_fontIndex].base) / nn) * _fontToSprite[_fontIndex].height;
567 				xx = ((_letterToPrint - _fontToSprite[_fontIndex].base) % nn) * _fontToSprite[_fontIndex].width;
568 				tempSrf->blit(*_spritesArray[_fontToSprite[_fontIndex].sprite],
569 										 xx, yy, xx + _fontToSprite[_fontIndex].width - 1,
570 										 yy + _fontToSprite[_fontIndex].height - 1, 0, 0, (_transparency == 0) ? -1 : 0);
571 			}
572 			break;
573 
574 		default:
575 			error("winDraw - Unexpected fct value %d", fct);
576 			break;
577 		}
578 
579 		int i = 0;
580 		if (_vm->_global->_curWinId != 0)
581 			i = _fascinWin[_vm->_global->_curWinId].id + 1;
582 
583 		for (; i < 10; i++) {
584 			if (table[i]) {
585 				int k = table[i];
586 				_fascinWin[k].savedSurface->blit(*tempSrf,
587 										0, 0, width - left, height - top,
588 										left - _fascinWin[k].left + (_fascinWin[k].left & 7),
589 										top  - _fascinWin[k].top);
590 				// Shift skipped as always set to zero (?)
591 				tempSrf->blit(*_frontSurface,
592 										MAX(left  , _fascinWin[k].left),
593 										MAX(top   , _fascinWin[k].top),
594 										MIN(width , (int16) (_fascinWin[k].left + _fascinWin[k].width  - 1)),
595 										MIN(height, (int16) (_fascinWin[k].top  + _fascinWin[k].height - 1)),
596 										MAX(left  , _fascinWin[k].left) - left,
597 										MAX(top   , _fascinWin[k].top)  - top);
598 				if (_cursorIndex != -1)
599 					tempSrf->blit(*_cursorSpritesBack,
600 											0, 0, _cursorWidth - 1, _cursorHeight - 1,
601 											_cursorX - left, _cursorY - top);
602 				for (int j = 9; j > i; j--) {
603 					if (table[j] && overlapWin(k, table[j])) {
604 						int l = table[j];
605 						tempSrf->blit(*_fascinWin[l].savedSurface,
606 												MAX(_fascinWin[l].left, _fascinWin[k].left)
607 												  - _fascinWin[l].left + (_fascinWin[l].left & 7),
608 												MAX(_fascinWin[l].top , _fascinWin[k].top ) - _fascinWin[l].top,
609 												MIN(_fascinWin[l].left + _fascinWin[l].width  - 1, _fascinWin[k].left + _fascinWin[k].width - 1)
610 												  - _fascinWin[l].left + (_fascinWin[l].left & 7),
611 												MIN(_fascinWin[l].top  + _fascinWin[l].height - 1, _fascinWin[k].top  + _fascinWin[k].height - 1)
612 												  - _fascinWin[l].top,
613 												MAX(_fascinWin[l].left, _fascinWin[k].left) - left,
614 												MAX(_fascinWin[l].top , _fascinWin[k].top ) - top);
615 					}
616 				}
617 			}
618 		}
619 		_backSurface->blit(*tempSrf, 0, 0, width - left, height - top, left, top);
620 		tempSrf.reset();
621 	} else {
622 		invalidateRect(left, top, width, height);
623 		switch (fct) {
624 		case DRAW_BLITSURF:    // 0 - move
625 			_backSurface->blit(*_spritesArray[_sourceSurface],
626 									 _spriteLeft, _spriteTop,
627 									 _spriteLeft + _spriteRight  - 1,
628 									 _spriteTop  + _spriteBottom - 1,
629 									 _destSpriteX, _destSpriteY, (_transparency == 0) ? -1 : 0);
630 			break;
631 		case DRAW_PUTPIXEL:    // 1 - put a pixel
632 			_backSurface->putPixel(_destSpriteX, _destSpriteY, _frontColor);
633 			break;
634 
635 		case DRAW_FILLRECT:    // 2 - fill rectangle
636 			_backSurface->fillRect(_destSpriteX, _destSpriteY, _destSpriteX + _spriteRight - 1, _destSpriteY + _spriteBottom - 1, _backColor);
637 			break;
638 
639 		case DRAW_DRAWLINE:    // 3 - draw line
640 			_backSurface->drawLine(_destSpriteX, _destSpriteY, _spriteRight, _spriteBottom, _frontColor);
641 			break;
642 
643 		case DRAW_INVALIDATE:  // 4 - Draw a circle
644 			_backSurface->drawCircle(_spriteRight, _spriteRight, _spriteRight, _frontColor);
645 			break;
646 
647 		case DRAW_LOADSPRITE:  // 5 - Uncompress and load a sprite
648 			decompWin(_destSpriteX, _destSpriteY, _backSurface);
649 			break;
650 
651 		case DRAW_PRINTTEXT:   // 6 - Display string
652 			len = strlen(_textToPrint);
653 			for (int j = 0; j < len; j++)
654 				_fonts[_fontIndex]->drawLetter(*_backSurface, _textToPrint[j],
655 						_destSpriteX + j * _fonts[_fontIndex]->getCharWidth(), _destSpriteY,
656 						_frontColor, _backColor, _transparency);
657 			_destSpriteX += len * _fonts[_fontIndex]->getCharWidth();
658 			break;
659 
660 		case DRAW_DRAWBAR:     // 7 - draw border
661 			_backSurface->drawLine(_destSpriteX, _spriteBottom, _spriteRight, _spriteBottom, _frontColor);
662 			_backSurface->drawLine(_destSpriteX, _destSpriteY,  _destSpriteX, _spriteBottom, _frontColor);
663 			_backSurface->drawLine(_spriteRight, _destSpriteY,  _spriteRight, _spriteBottom, _frontColor);
664 			_backSurface->drawLine(_destSpriteX, _destSpriteY,  _spriteRight, _destSpriteY,  _frontColor);
665 			break;
666 
667 		case DRAW_CLEARRECT:   // 8 - clear rectangle
668 		if (_backColor < 16)
669 				_backSurface->fillRect(_destSpriteX, _destSpriteY, _spriteRight, _spriteBottom, _backColor);
670 			break;
671 
672 		case DRAW_FILLRECTABS: // 9 - fill rectangle, with other coordinates
673 			_backSurface->fillRect(_destSpriteX, _destSpriteY, _spriteRight, _spriteBottom, _backColor);
674 			break;
675 
676 		case DRAW_DRAWLETTER:  // 10 - Display a character
677 			if (_fontToSprite[_fontIndex].sprite == -1) {
678 				if (_letterToPrint)
679 					_fonts[_fontIndex]->drawLetter(*_spritesArray[_destSurface], _letterToPrint,
680 							_destSpriteX, _destSpriteY, _frontColor, _backColor, _transparency);
681 			} else {
682 				int xx, yy, nn;
683 				nn = _spritesArray[_fontToSprite[_fontIndex].sprite]->getWidth() / _fontToSprite[_fontIndex].width;
684 				yy = ((_letterToPrint - _fontToSprite[_fontIndex].base) / nn) * _fontToSprite[_fontIndex].height;
685 				xx = ((_letterToPrint - _fontToSprite[_fontIndex].base) % nn) * _fontToSprite[_fontIndex].width;
686 				_spritesArray[_destSurface]->blit(*_spritesArray[_fontToSprite[_fontIndex].sprite],
687 										xx, yy,
688 										xx + _fontToSprite[_fontIndex].width  - 1,
689 										yy + _fontToSprite[_fontIndex].height - 1,
690 										_destSpriteX, _destSpriteY, (_transparency == 0) ? -1 : 0);
691 			}
692 			break;
693 
694 		default:
695 			error("winDraw - Unexpected fct value");
696 			break;
697 		}
698 	}
699 
700 	if (_renderFlags & 16) {
701 		if (_sourceSurface == kBackSurface) {
702 			_spriteLeft -= _backDeltaX;
703 			_spriteTop -= _backDeltaY;
704 		}
705 		if (_destSurface == kBackSurface) {
706 			_destSpriteX -= _backDeltaX;
707 			_destSpriteY -= _backDeltaY;
708 		}
709 	}
710 
711 	if (_vm->_global->_curWinId) {
712 		_destSpriteX -= _fascinWin[_vm->_global->_curWinId].left;
713 		_destSpriteY -= _fascinWin[_vm->_global->_curWinId].top;
714 	}
715 }
716 
decompWin(int16 x,int16 y,SurfacePtr destPtr)717 void Draw_Fascination::decompWin(int16 x, int16 y, SurfacePtr destPtr) {
718 	Resource *resource;
719 	resource = _vm->_game->_resources->getResource((uint16) _spriteLeft,
720 	                                               &_spriteRight, &_spriteBottom);
721 
722 	if (!resource)
723 		return;
724 
725 	_vm->_video->drawPackedSprite(resource->getData(),
726 			_spriteRight, _spriteBottom, x, y, _transparency, *destPtr);
727 
728 	delete resource;
729 	return;
730 }
731 
openWin(int16 id)732 int16 Draw_Fascination::openWin(int16 id) {
733 	if (_fascinWin[id].id != -1)
734 		return 0;
735 
736 	_fascinWin[id].id = _winCount++;
737 	_fascinWin[id].left   = VAR((_winVarArrayLeft   / 4) + id);
738 	_fascinWin[id].top    = VAR((_winVarArrayTop    / 4) + id);
739 	_fascinWin[id].width  = VAR((_winVarArrayWidth  / 4) + id);
740 	_fascinWin[id].height = VAR((_winVarArrayHeight / 4) + id);
741 
742 	_fascinWin[id].savedSurface = _vm->_video->initSurfDesc(_winMaxWidth + 7, _winMaxHeight);
743 
744 	saveWin(id);
745 	WRITE_VAR((_winVarArrayStatus / 4) + id, VAR((_winVarArrayStatus / 4) + id) & 0xFFFFFFFE);
746 
747 	return 1;
748 }
749 
getWinFromCoord(int16 & dx,int16 & dy)750 int16 Draw_Fascination::getWinFromCoord(int16 &dx, int16 &dy) {
751 	int16 bestMatch = -1;
752 
753 	if (!(_renderFlags & RENDERFLAG_HASWINDOWS))
754 		return -1;
755 
756 	for (int i = 0; i < 10; i++) {
757 		if (_fascinWin[i].id != -1) {
758 			if ((_vm->_global->_inter_mouseX >= _fascinWin[i].left) &&
759 			    (_vm->_global->_inter_mouseX <  _fascinWin[i].left + _fascinWin[i].width) &&
760 			    (_vm->_global->_inter_mouseY >= _fascinWin[i].top) &&
761 			    (_vm->_global->_inter_mouseY <  _fascinWin[i].top  + _fascinWin[i].height)) {
762 
763 				if (_fascinWin[i].id == _winCount - 1) {
764 					dx = _fascinWin[i].left;
765 					dy = _fascinWin[i].top;
766 					return(i);
767 				} else {
768 					if (_fascinWin[i].id > bestMatch)
769 						bestMatch = _fascinWin[i].id;
770 				}
771 			}
772 		}
773 	}
774 
775 	if (bestMatch != -1)
776 		return(0);
777 	else
778 		return(-1);
779 }
780 
closeWin(int16 id)781 void Draw_Fascination::closeWin(int16 id) {
782 	if (_fascinWin[id].id == -1)
783 		return;
784 
785 	WRITE_VAR((_winVarArrayStatus / 4) + id, VAR((_winVarArrayStatus / 4) + id) | 1);
786 	restoreWin(id);
787 	_fascinWin[id].id = -1;
788 	_fascinWin[id].savedSurface.reset();
789 	_winCount--;
790 }
791 
handleCurWin()792 int16 Draw_Fascination::handleCurWin() {
793 	int8 matchNum = 0;
794 	int16 bestMatch = -1;
795 
796 	if ((_vm->_game->_mouseButtons != 1) || !(_renderFlags & RENDERFLAG_HASWINDOWS))
797 		return 0;
798 
799 	for (int i = 0; i < 10; i++) {
800 		if (_fascinWin[i].id != -1) {
801 			if ((_vm->_global->_inter_mouseX >= _fascinWin[i].left) &&
802 			    (_vm->_global->_inter_mouseX <  _fascinWin[i].left + _fascinWin[i].width) &&
803 			    (_vm->_global->_inter_mouseY >= _fascinWin[i].top) &&
804 			    (_vm->_global->_inter_mouseY <  _fascinWin[i].top  + _fascinWin[i].height)) {
805 
806 				if (_fascinWin[i].id == _winCount - 1) {
807 					if ((_vm->_global->_inter_mouseX < _fascinWin[i].left + 12) &&
808 					    (_vm->_global->_inter_mouseY < _fascinWin[i].top  + 12) &&
809 					    (VAR(_winVarArrayStatus / 4 + i) & 2)) {
810 
811 						blitCursor();
812 						activeWin(i);
813 						closeWin(i);
814 						_vm->_util->waitMouseRelease(1);
815 						return i;
816 					}
817 
818 					if ((_vm->_global->_inter_mouseX >= _fascinWin[i].left + _fascinWin[i].width - 12) &&
819 					    (_vm->_global->_inter_mouseY <  _fascinWin[i].top  + 12) &&
820 					    (VAR(_winVarArrayStatus / 4 + i) & 4) &&
821 					    (_vm->_global->_mousePresent) &&
822 					    (_vm->_global->_videoMode != 0x07)) {
823 
824 						blitCursor();
825 						handleWinBorder(i);
826 						moveWin(i);
827 						_vm->_global->_inter_mouseX = _fascinWin[i].left + _fascinWin[i].width - 11;
828 						_vm->_util->setMousePos(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY);
829 						return -i;
830 					}
831 					return 0;
832 				} else {
833 					if (_fascinWin[i].id > bestMatch) {
834 						bestMatch = _fascinWin[i].id;
835 						matchNum = i;
836 					}
837 				}
838 			}
839 		}
840 	}
841 
842 	if (bestMatch != -1) {
843 		blitCursor();
844 		activeWin(matchNum);
845 	}
846 
847 	return 0;
848 }
849 
moveWin(int16 id)850 void Draw_Fascination::moveWin(int16 id) {
851 	int oldLeft = _fascinWin[id].left;
852 	int oldTop  = _fascinWin[id].top;
853 
854 	restoreWin(id);
855 
856 	_fascinWin[id].left = _vm->_global->_inter_mouseX;
857 	_fascinWin[id].top  = _vm->_global->_inter_mouseY;
858 
859 	WRITE_VAR((_winVarArrayLeft / 4) + id, _fascinWin[id].left);
860 	WRITE_VAR((_winVarArrayTop  / 4) + id, _fascinWin[id].top);
861 
862 	saveWin(id);
863 
864 	// Shift skipped as always set to zero (?)
865 	_backSurface->blit(*_frontSurface,
866 							oldLeft, oldTop,
867 							oldLeft + _fascinWin[id].width  - 1,
868 							oldTop  + _fascinWin[id].height - 1,
869 							_fascinWin[id].left, _fascinWin[id].top);
870 	invalidateRect(_fascinWin[id].left, _fascinWin[id].top,
871 				   _fascinWin[id].left + _fascinWin[id].width  - 1,
872 				   _fascinWin[id].top  + _fascinWin[id].height - 1);
873 }
874 
overlapWin(int16 idWin1,int16 idWin2)875 bool Draw_Fascination::overlapWin(int16 idWin1, int16 idWin2) {
876 	if ((_fascinWin[idWin1].left + _fascinWin[idWin1].width  <= _fascinWin[idWin2].left) ||
877 		(_fascinWin[idWin2].left + _fascinWin[idWin2].width  <= _fascinWin[idWin1].left) ||
878 		(_fascinWin[idWin1].top  + _fascinWin[idWin1].height <= _fascinWin[idWin2].top ) ||
879 		(_fascinWin[idWin2].top  + _fascinWin[idWin2].height <= _fascinWin[idWin1].top ))
880 		return false;
881 
882 	return true;
883 }
884 
activeWin(int16 id)885 void Draw_Fascination::activeWin(int16 id) {
886 	bool found = false;
887 	int16 t[10], t2[10];
888 	SurfacePtr tempSrf;
889 	SurfacePtr oldSrf[10];
890 
891 	if (_fascinWin[id].id == -1)
892 		return;
893 
894 	blitInvalidated();
895 
896 	for (int i = 0; i < 10; i++) {
897 		t[i]  = -1;
898 		t2[i] = -1;
899 		oldSrf[i].reset();
900 	}
901 
902 	for (int i = 0; i < 10; i++) {
903 		if ((i != id) && (_fascinWin[i].id > _fascinWin[id].id) && (overlapWin(i, id))) {
904 			t[_fascinWin[i].id] = i;
905 			found = true;
906 		}
907 	}
908 
909 	if (found) {
910 		int nextId = -1;
911 		int oldId  = -1;
912 		for (int i = 9; i >= 0; i--) {
913 			if (t[i] != -1) {
914 				if (nextId != -1)
915 					_fascinWin[nextId].savedSurface->blit(*_backSurface,
916 											_fascinWin[t[i]].left, _fascinWin[t[i]].top,
917 											_fascinWin[t[i]].left + _fascinWin[t[i]].width  - 1,
918 											_fascinWin[t[i]].top  + _fascinWin[t[i]].height - 1,
919 											_fascinWin[t[i]].left & 7, 0);
920 				t2[i] = nextId;
921 				restoreWin(t[i]);
922 				nextId = t[i];
923 			}
924 		}
925 
926 		oldId = nextId;
927 		_fascinWin[nextId].savedSurface->blit(*_backSurface,
928 								 _fascinWin[id].left, _fascinWin[id].top,
929 								 _fascinWin[id].left + _fascinWin[id].width  - 1,
930 								 _fascinWin[id].top  + _fascinWin[id].height - 1,
931 								 _fascinWin[id].left & 7, 0);
932 		restoreWin(id);
933 		nextId = id;
934 
935 		for (int i = 0; i < 10; i++) {
936 			if (t[i] != -1) {
937 				_fascinWin[nextId].savedSurface->blit(*_backSurface,
938 										_fascinWin[t[i]].left, _fascinWin[t[i]].top,
939 										_fascinWin[t[i]].left + _fascinWin[t[i]].width  - 1,
940 										_fascinWin[t[i]].top  + _fascinWin[t[i]].height - 1,
941 										_fascinWin[t[i]].left & 7, 0);
942 				oldSrf[t[i]] = _fascinWin[nextId].savedSurface;
943 				if (t2[i] != -1)
944 					_backSurface->blit(*_fascinWin[t2[i]].savedSurface,
945 											 _fascinWin[t[i]].left & 7, 0,
946 											(_fascinWin[t[i]].left & 7) + _fascinWin[t[i]].width - 1,
947 											 _fascinWin[t[i]].height - 1, _fascinWin[t[i]].left,
948 											 _fascinWin[t[i]].top);
949 				else {
950 					// Shift skipped as always set to zero (?)
951 					_backSurface->blit(*_frontSurface,
952 											 _fascinWin[t[i]].left, _fascinWin[t[i]].top,
953 											 _fascinWin[t[i]].left + _fascinWin[t[i]].width  - 1,
954 											 _fascinWin[t[i]].top  + _fascinWin[t[i]].height - 1,
955 											 _fascinWin[t[i]].left, _fascinWin[t[i]].top);
956 				}
957 				invalidateRect(_fascinWin[t[i]].left, _fascinWin[t[i]].top,
958 							_fascinWin[t[i]].left + _fascinWin[t[i]].width  - 1,
959 							_fascinWin[t[i]].top  + _fascinWin[t[i]].height - 1);
960 				nextId = t2[i];
961 			}
962 		}
963 
964 		tempSrf = _vm->_video->initSurfDesc(_winMaxWidth + 7, _winMaxHeight);
965 		tempSrf->blit(*_backSurface,
966 								 _fascinWin[id].left, _fascinWin[id].top,
967 								 _fascinWin[id].left + _fascinWin[id].width  - 1,
968 								 _fascinWin[id].top  + _fascinWin[id].height - 1,
969 								 _fascinWin[id].left & 7, 0);
970 		_backSurface->blit(*_fascinWin[oldId].savedSurface,
971 								 _fascinWin[id].left & 7, 0,
972 								(_fascinWin[id].left & 7) + _fascinWin[id].width - 1,
973 								 _fascinWin[id].height - 1,
974 								 _fascinWin[id].left, _fascinWin[id].top);
975 
976 		_fascinWin[oldId].savedSurface.reset();
977 		_fascinWin[oldId].savedSurface = tempSrf;
978 		oldSrf[id] = _fascinWin[oldId].savedSurface;
979 
980 		invalidateRect(_fascinWin[id].left, _fascinWin[id].top,
981 					_fascinWin[id].left + _fascinWin[id].width  - 1,
982 					_fascinWin[id].top  + _fascinWin[id].height - 1);
983 		nextId = id;
984 
985 		for (int j = 0; j < 10; j++) {
986 			if (oldSrf[j] != 0)
987 				_fascinWin[j].savedSurface = oldSrf[j];
988 		}
989 	}
990 
991 	for (int i = 0; i < 10; i++) {
992 		if ((i != id) && (_fascinWin[i].id > _fascinWin[id].id))
993 			_fascinWin[i].id--;
994 	}
995 
996 	_fascinWin[id].id = _winCount - 1;
997 }
998 
closeAllWin()999 void Draw_Fascination::closeAllWin() {
1000 	for (int i = 0; i < 10; i++) {
1001 		activeWin(i);
1002 		closeWin(i);
1003 	}
1004 }
1005 
saveWin(int16 id)1006 void Draw_Fascination::saveWin(int16 id) {
1007 	_fascinWin[id].savedSurface->blit(*_backSurface,
1008 							_fascinWin[id].left,  _fascinWin[id].top,
1009 							_fascinWin[id].left + _fascinWin[id].width  - 1,
1010 							_fascinWin[id].top  + _fascinWin[id].height - 1,
1011 							_fascinWin[id].left & 7, 0);
1012 }
1013 
restoreWin(int16 id)1014 void Draw_Fascination::restoreWin(int16 id) {
1015 	_backSurface->blit(*_fascinWin[id].savedSurface,
1016 							 _fascinWin[id].left & 7, 0,
1017 							(_fascinWin[id].left & 7) + _fascinWin[id].width - 1, _fascinWin[id].height - 1,
1018 							 _fascinWin[id].left, _fascinWin[id].top);
1019 	invalidateRect(_fascinWin[id].left, _fascinWin[id].top,
1020 				_fascinWin[id].left + _fascinWin[id].width  - 1,
1021 				_fascinWin[id].top  + _fascinWin[id].height - 1);
1022 }
1023 
drawWinTrace(int16 left,int16 top,int16 width,int16 height)1024 void Draw_Fascination::drawWinTrace(int16 left, int16 top, int16 width, int16 height) {
1025 	int16 right, bottom;
1026 
1027 	right  = left + width  - 1;
1028 	bottom = top  + height - 1;
1029 
1030 	Pixel pixelTop = _frontSurface->get(left, top);
1031 	Pixel pixelBottom = _frontSurface->get(left, bottom);
1032 	for (int16 i = 0; i < width; i++, pixelTop++, pixelBottom++) {
1033 		pixelTop.set((pixelTop.get() + 128) & 0xFF);
1034 		pixelBottom.set((pixelBottom.get() + 128) & 0xFF);
1035 	}
1036 
1037 	Pixel pixelLeft = _frontSurface->get(left, top);
1038 	Pixel pixelRight = _frontSurface->get(right, top);
1039 
1040 	for (int16 i = 0; i < height; i++, pixelLeft += _frontSurface->getWidth(), pixelRight += _frontSurface->getWidth()) {
1041 		pixelLeft.set((pixelLeft.get() + 128) & 0xFF);
1042 		pixelRight.set((pixelRight.get() + 128) & 0xFF);
1043 	}
1044 
1045 	_vm->_video->dirtyRectsAll();
1046 	_vm->_video->retrace(true);
1047 }
1048 
handleWinBorder(int16 id)1049 void Draw_Fascination::handleWinBorder(int16 id) {
1050 	int16 minX = 0;
1051 	int16 maxX = 320;
1052 	int16 minY = 0;
1053 	int16 maxY = 200;
1054 
1055 	if (VAR((_winVarArrayStatus / 4) + id) & 8)
1056 		minX = (int16)(VAR((_winVarArrayLimitsX / 4) + id) >> 16L);
1057 	if (VAR((_winVarArrayStatus / 4) + id) & 16)
1058 		maxX = (int16)(VAR((_winVarArrayLimitsX / 4) + id) & 0xFFFFL);
1059 	if (VAR((_winVarArrayStatus / 4) + id) & 32)
1060 		minY = (int16)(VAR((_winVarArrayLimitsY / 4) + id) >> 16L);
1061 	if (VAR((_winVarArrayStatus / 4) + id) & 64)
1062 		maxY = (int16)(VAR((_winVarArrayLimitsY / 4) + id) & 0xFFFFL);
1063 
1064 	_vm->_global->_inter_mouseX = _fascinWin[id].left;
1065 	_vm->_global->_inter_mouseY = _fascinWin[id].top;
1066 
1067 	if (_vm->_global->_mousePresent)
1068 		_vm->_util->setMousePos(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY);
1069 
1070 	drawWinTrace(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY, _fascinWin[id].width, _fascinWin[id].height);
1071 	_cursorX = _vm->_global->_inter_mouseX;
1072 	_cursorY = _vm->_global->_inter_mouseY;
1073 
1074 	do {
1075 		_vm->_game->checkKeys(&_vm->_global->_inter_mouseX, &_vm->_global->_inter_mouseY, &_vm->_game->_mouseButtons, 1);
1076 
1077 		if (_vm->_global->_inter_mouseX != _cursorX || _vm->_global->_inter_mouseY != _cursorY) {
1078 			if (_vm->_global->_inter_mouseX < minX) {
1079 				_vm->_global->_inter_mouseX = minX;
1080 				if (_vm->_global->_mousePresent)
1081 					_vm->_util->setMousePos(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY);
1082 			}
1083 
1084 			if (_vm->_global->_inter_mouseY < minY) {
1085 				_vm->_global->_inter_mouseY = minY;
1086 				if (_vm->_global->_mousePresent)
1087 					_vm->_util->setMousePos(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY);
1088 			}
1089 
1090 			if (_vm->_global->_inter_mouseX + _fascinWin[id].width > maxX) {
1091 				_vm->_global->_inter_mouseX = maxX - _fascinWin[id].width;
1092 				if (_vm->_global->_mousePresent)
1093 					_vm->_util->setMousePos(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY);
1094 			}
1095 
1096 			if (_vm->_global->_inter_mouseY + _fascinWin[id].height > maxY) {
1097 				_vm->_global->_inter_mouseY = maxY - _fascinWin[id].height;
1098 				if (_vm->_global->_mousePresent)
1099 					_vm->_util->setMousePos(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY);
1100 			}
1101 
1102 			drawWinTrace(_cursorX, _cursorY, _fascinWin[id].width, _fascinWin[id].height);
1103 			drawWinTrace(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY, _fascinWin[id].width, _fascinWin[id].height);
1104 			_cursorX = _vm->_global->_inter_mouseX;
1105 			_cursorY = _vm->_global->_inter_mouseY;
1106 		}
1107 	} while (_vm->_game->_mouseButtons);
1108 	drawWinTrace(_cursorX, _cursorY, _fascinWin[id].width, _fascinWin[id].height);
1109 	_cursorX = _vm->_global->_inter_mouseX;
1110 	_cursorY = _vm->_global->_inter_mouseY;
1111 }
1112 
1113 } // End of namespace Gob
1114