2020-10-14 13:16:30 +00:00
|
|
|
/* 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 "twine/interface.h"
|
2020-11-16 17:01:16 +00:00
|
|
|
#include "graphics/managed_surface.h"
|
2020-10-14 13:16:30 +00:00
|
|
|
#include "twine/twine.h"
|
|
|
|
|
|
|
|
namespace TwinE {
|
|
|
|
|
|
|
|
Interface::Interface(TwinEEngine *engine) : _engine(engine) {}
|
|
|
|
|
2020-10-14 12:20:38 +00:00
|
|
|
const int32 INSIDE = 0; // 0000
|
|
|
|
const int32 LEFT = 1; // 0001
|
|
|
|
const int32 RIGHT = 2; // 0010
|
2020-10-14 13:16:30 +00:00
|
|
|
const int32 TOP = 4; // 0100
|
|
|
|
const int32 BOTTOM = 8; // 1000
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-14 13:16:30 +00:00
|
|
|
int32 Interface::checkClipping(int32 x, int32 y) {
|
2020-10-14 12:20:38 +00:00
|
|
|
int32 code = INSIDE;
|
2020-11-25 17:20:38 +00:00
|
|
|
if (x < textWindow.left) {
|
2020-10-14 13:16:30 +00:00
|
|
|
code |= LEFT;
|
2020-11-25 17:20:38 +00:00
|
|
|
} else if (x > textWindow.right) {
|
2020-10-14 13:16:30 +00:00
|
|
|
code |= RIGHT;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
2020-11-25 17:20:38 +00:00
|
|
|
if (y < textWindow.top) {
|
2020-10-14 13:16:30 +00:00
|
|
|
code |= TOP;
|
2020-11-25 17:20:38 +00:00
|
|
|
} else if (y > textWindow.bottom) {
|
2020-10-14 13:16:30 +00:00
|
|
|
code |= BOTTOM;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
2020-10-14 12:20:38 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:16:30 +00:00
|
|
|
// TODO: check if Graphics::drawLine() works here
|
2020-11-27 22:11:15 +00:00
|
|
|
void Interface::drawLine(int32 startWidth, int32 startHeight, int32 endWidth, int32 endHeight, uint8 lineColor) {
|
|
|
|
uint8 currentLineColor = lineColor;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
|
|
|
// draw line from left to right
|
|
|
|
if (startWidth > endWidth) {
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 temp = endWidth;
|
2020-10-14 12:20:38 +00:00
|
|
|
endWidth = startWidth;
|
|
|
|
startWidth = temp;
|
|
|
|
|
|
|
|
temp = endHeight;
|
|
|
|
endHeight = startHeight;
|
|
|
|
startHeight = temp;
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:16:30 +00:00
|
|
|
// Perform proper clipping (CohenSutherland algorithm)
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 outcode0 = checkClipping(startWidth, startHeight);
|
|
|
|
int32 outcode1 = checkClipping(endWidth, endHeight);
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-11-16 18:35:33 +00:00
|
|
|
while ((outcode0 | outcode1) != INSIDE) {
|
|
|
|
if ((outcode0 & outcode1) != INSIDE && outcode0 != INSIDE) {
|
2020-10-14 13:16:30 +00:00
|
|
|
return; // Reject lines which are behind one clipping plane
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
2020-10-14 12:20:38 +00:00
|
|
|
|
|
|
|
// At least one endpoint is outside the clip rectangle; pick it.
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 outcodeOut = outcode0 ? outcode0 : outcode1;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 x = 0;
|
|
|
|
int32 y = 0;
|
2020-10-14 13:16:30 +00:00
|
|
|
if (outcodeOut & TOP) { // point is above the clip rectangle
|
2020-11-25 17:20:38 +00:00
|
|
|
x = startWidth + (int)((endWidth - startWidth) * (float)(textWindow.top - startHeight) / (float)(endHeight - startHeight));
|
|
|
|
y = textWindow.top;
|
2020-10-14 12:20:38 +00:00
|
|
|
} else if (outcodeOut & BOTTOM) { // point is below the clip rectangle
|
2020-11-25 17:20:38 +00:00
|
|
|
x = startWidth + (int)((endWidth - startWidth) * (float)(textWindow.bottom - startHeight) / (float)(endHeight - startHeight));
|
|
|
|
y = textWindow.bottom;
|
2020-10-14 13:16:30 +00:00
|
|
|
} else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle
|
2020-11-25 17:20:38 +00:00
|
|
|
y = startHeight + (int)((endHeight - startHeight) * (float)(textWindow.right - startWidth) / (float)(endWidth - startWidth));
|
|
|
|
x = textWindow.right;
|
2020-10-14 13:16:30 +00:00
|
|
|
} else if (outcodeOut & LEFT) { // point is to the left of clip rectangle
|
2020-11-25 17:20:38 +00:00
|
|
|
y = startHeight + (int)((endHeight - startHeight) * (float)(textWindow.left - startWidth) / (float)(endWidth - startWidth));
|
|
|
|
x = textWindow.left;
|
2020-10-14 12:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clip the point
|
|
|
|
if (outcodeOut == outcode0) {
|
|
|
|
startWidth = x;
|
|
|
|
startHeight = y;
|
|
|
|
outcode0 = checkClipping(startWidth, startHeight);
|
|
|
|
} else {
|
|
|
|
endWidth = x;
|
|
|
|
endHeight = y;
|
|
|
|
outcode1 = checkClipping(endWidth, endHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 20:31:58 +00:00
|
|
|
int32 flag2 = SCREEN_WIDTH;
|
2020-10-14 12:20:38 +00:00
|
|
|
endWidth -= startWidth;
|
|
|
|
endHeight -= startHeight;
|
|
|
|
if (endHeight < 0) {
|
|
|
|
flag2 = -flag2;
|
|
|
|
endHeight = -endHeight;
|
|
|
|
}
|
|
|
|
|
2020-11-16 18:35:33 +00:00
|
|
|
uint8 *out = (uint8*)_engine->frontVideoBuffer.getBasePtr(startWidth, startHeight);
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-11-27 22:11:15 +00:00
|
|
|
uint8 color = currentLineColor;
|
2020-10-14 13:16:30 +00:00
|
|
|
if (endWidth < endHeight) { // significant slope
|
2020-10-22 14:32:52 +00:00
|
|
|
int16 xchg = endWidth;
|
2020-10-14 12:20:38 +00:00
|
|
|
endWidth = endHeight;
|
|
|
|
endHeight = xchg;
|
2020-10-22 14:32:52 +00:00
|
|
|
int16 var2 = endWidth;
|
2020-10-14 12:20:38 +00:00
|
|
|
var2 <<= 1;
|
|
|
|
startHeight = endWidth;
|
|
|
|
endHeight <<= 1;
|
|
|
|
endWidth++;
|
|
|
|
do {
|
2020-11-27 22:11:15 +00:00
|
|
|
*out = color;
|
2020-10-14 12:20:38 +00:00
|
|
|
startHeight -= endHeight;
|
|
|
|
if (startHeight > 0) {
|
|
|
|
out += flag2;
|
|
|
|
} else {
|
|
|
|
startHeight += var2;
|
|
|
|
out += flag2 + 1;
|
|
|
|
}
|
|
|
|
} while (--endWidth);
|
2020-10-14 13:16:30 +00:00
|
|
|
} else { // reduced slope
|
2020-10-22 14:32:52 +00:00
|
|
|
int16 var2 = endWidth;
|
2020-10-14 12:20:38 +00:00
|
|
|
var2 <<= 1;
|
|
|
|
startHeight = endWidth;
|
|
|
|
endHeight <<= 1;
|
|
|
|
endWidth++;
|
|
|
|
do {
|
2020-11-27 22:11:15 +00:00
|
|
|
*out = color;
|
2020-10-14 12:20:38 +00:00
|
|
|
out++;
|
|
|
|
startHeight -= endHeight;
|
|
|
|
if (startHeight < 0) {
|
|
|
|
startHeight += var2;
|
|
|
|
out += flag2;
|
|
|
|
}
|
|
|
|
} while (--endWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:36:18 +00:00
|
|
|
void Interface::blitBox(const Common::Rect &rect, const Graphics::ManagedSurface &source, Graphics::ManagedSurface &dest) {
|
2020-11-25 17:20:38 +00:00
|
|
|
int32 left = rect.left;
|
|
|
|
const int32 top = rect.top;
|
|
|
|
const int32 right = rect.right;
|
|
|
|
const int32 bottom = rect.bottom;
|
2020-11-25 15:59:54 +00:00
|
|
|
|
2020-11-16 17:01:16 +00:00
|
|
|
const int8 *s = (const int8 *)source.getBasePtr(left, top);
|
|
|
|
int8 *d = (int8 *)dest.getBasePtr(left, top);
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 width = right - left + 1;
|
|
|
|
int32 height = bottom - top + 1;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 insideLine = SCREEN_WIDTH - width;
|
|
|
|
int32 temp3 = left;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
|
|
|
left >>= 2;
|
|
|
|
temp3 &= 3;
|
|
|
|
|
2020-10-22 14:32:52 +00:00
|
|
|
for (int32 j = 0; j < height; j++) {
|
|
|
|
for (int32 i = 0; i < width; i++) {
|
2020-10-14 12:20:38 +00:00
|
|
|
*(d++) = *(s++);
|
|
|
|
}
|
|
|
|
|
|
|
|
d += insideLine;
|
|
|
|
s += insideLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 15:59:54 +00:00
|
|
|
void Interface::drawTransparentBox(const Common::Rect &rect, int32 colorAdj) {
|
2020-11-25 17:20:38 +00:00
|
|
|
int32 left = rect.left;
|
|
|
|
int32 top = rect.top;
|
|
|
|
int32 right = rect.right;
|
|
|
|
int32 bottom = rect.bottom;
|
2020-11-25 15:59:54 +00:00
|
|
|
|
2020-11-05 19:02:19 +00:00
|
|
|
if (left > SCREEN_TEXTLIMIT_RIGHT) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (right < SCREEN_TEXTLIMIT_LEFT) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (top > SCREEN_TEXTLIMIT_BOTTOM) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (bottom < SCREEN_TEXTLIMIT_TOP) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-11-05 19:02:19 +00:00
|
|
|
if (left < SCREEN_TEXTLIMIT_LEFT) {
|
2020-10-14 12:20:38 +00:00
|
|
|
left = SCREEN_TEXTLIMIT_LEFT;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (right > SCREEN_TEXTLIMIT_RIGHT) {
|
2020-10-14 12:20:38 +00:00
|
|
|
right = SCREEN_TEXTLIMIT_RIGHT;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (top < SCREEN_TEXTLIMIT_TOP) {
|
2020-10-14 12:20:38 +00:00
|
|
|
top = SCREEN_TEXTLIMIT_TOP;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (bottom > SCREEN_TEXTLIMIT_BOTTOM) {
|
2020-10-14 12:20:38 +00:00
|
|
|
bottom = SCREEN_TEXTLIMIT_BOTTOM;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-11-16 17:01:16 +00:00
|
|
|
uint8 *pos = (uint8*)_engine->frontVideoBuffer.getBasePtr(left, top);
|
2020-11-05 19:02:19 +00:00
|
|
|
const int32 height = bottom - top;
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 height2 = height + 1;
|
2020-11-05 19:02:19 +00:00
|
|
|
const int32 width = right - left + 1;
|
2020-11-12 20:31:58 +00:00
|
|
|
const int32 pitch = SCREEN_WIDTH - width;
|
2020-11-05 19:02:19 +00:00
|
|
|
const int32 localMode = colorAdj;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
|
|
|
do {
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 var1 = width;
|
2020-10-14 12:20:38 +00:00
|
|
|
do {
|
2020-10-22 14:32:52 +00:00
|
|
|
int8 color = *pos & 0x0F;
|
|
|
|
const int8 color2 = *pos & 0xF0;
|
2020-10-14 12:20:38 +00:00
|
|
|
color -= localMode;
|
2020-10-22 14:32:52 +00:00
|
|
|
if (color < 0) {
|
2020-10-14 12:20:38 +00:00
|
|
|
color = color2;
|
2020-10-22 14:32:52 +00:00
|
|
|
} else {
|
2020-10-14 12:20:38 +00:00
|
|
|
color += color2;
|
2020-10-22 14:32:52 +00:00
|
|
|
}
|
2020-10-14 12:20:38 +00:00
|
|
|
*pos++ = color;
|
|
|
|
var1--;
|
|
|
|
} while (var1 > 0);
|
2020-10-22 14:32:52 +00:00
|
|
|
pos += pitch;
|
2020-10-14 12:20:38 +00:00
|
|
|
height2--;
|
|
|
|
} while (height2 > 0);
|
|
|
|
}
|
|
|
|
|
2020-11-24 17:17:12 +00:00
|
|
|
void Interface::drawSplittedBox(const Common::Rect &rect, uint8 colorIndex) {
|
2020-11-25 17:20:38 +00:00
|
|
|
const int32 left = rect.left;
|
|
|
|
const int32 top = rect.top;
|
|
|
|
const int32 right = rect.right;
|
|
|
|
const int32 bottom = rect.bottom;
|
2020-11-24 17:17:12 +00:00
|
|
|
|
2020-11-05 19:02:19 +00:00
|
|
|
if (left > SCREEN_TEXTLIMIT_RIGHT) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (right < SCREEN_TEXTLIMIT_LEFT) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (top > SCREEN_TEXTLIMIT_BOTTOM) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
|
|
|
if (bottom < SCREEN_TEXTLIMIT_TOP) {
|
2020-10-14 12:20:38 +00:00
|
|
|
return;
|
2020-11-05 19:02:19 +00:00
|
|
|
}
|
2020-10-14 12:20:38 +00:00
|
|
|
|
|
|
|
// cropping
|
2020-10-22 14:32:52 +00:00
|
|
|
int32 offset = -((right - left) - SCREEN_WIDTH);
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-11-16 17:01:16 +00:00
|
|
|
uint8 *ptr = (uint8*)_engine->frontVideoBuffer.getBasePtr(left, top);
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-22 14:32:52 +00:00
|
|
|
for (int32 x = top; x < bottom; x++) {
|
|
|
|
for (int32 y = left; y < right; y++) {
|
2020-12-13 14:38:39 +00:00
|
|
|
*ptr++ = colorIndex;
|
2020-10-14 12:20:38 +00:00
|
|
|
}
|
|
|
|
ptr += offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 15:59:54 +00:00
|
|
|
void Interface::setClip(const Common::Rect &rect) {
|
2020-11-25 17:20:38 +00:00
|
|
|
int32 left = rect.left;
|
|
|
|
int32 top = rect.top;
|
|
|
|
int32 right = rect.right;
|
|
|
|
int32 bottom = rect.bottom;
|
2020-11-25 15:59:54 +00:00
|
|
|
|
2020-10-30 19:29:10 +00:00
|
|
|
if (left < 0) {
|
2020-10-14 12:20:38 +00:00
|
|
|
left = 0;
|
2020-10-30 19:29:10 +00:00
|
|
|
}
|
2020-11-25 17:20:38 +00:00
|
|
|
textWindow.left = left;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-30 19:29:10 +00:00
|
|
|
if (top < 0) {
|
2020-10-14 12:20:38 +00:00
|
|
|
top = 0;
|
2020-10-30 19:29:10 +00:00
|
|
|
}
|
2020-11-25 17:20:38 +00:00
|
|
|
textWindow.top = top;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-30 19:29:10 +00:00
|
|
|
if (right >= SCREEN_WIDTH) {
|
2020-10-14 12:20:38 +00:00
|
|
|
right = SCREEN_TEXTLIMIT_RIGHT;
|
2020-10-30 19:29:10 +00:00
|
|
|
}
|
2020-11-25 17:20:38 +00:00
|
|
|
textWindow.right = right;
|
2020-10-14 12:20:38 +00:00
|
|
|
|
2020-10-30 19:29:10 +00:00
|
|
|
if (bottom >= SCREEN_HEIGHT) {
|
2020-10-14 12:20:38 +00:00
|
|
|
bottom = SCREEN_TEXTLIMIT_BOTTOM;
|
2020-10-30 19:29:10 +00:00
|
|
|
}
|
2020-11-25 17:20:38 +00:00
|
|
|
textWindow.bottom = bottom;
|
2020-10-14 12:20:38 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 13:16:30 +00:00
|
|
|
void Interface::saveClip() { // saveTextWindow
|
2020-11-25 17:20:38 +00:00
|
|
|
textWindowLeftSave = textWindow.left;
|
|
|
|
textWindowTopSave = textWindow.top;
|
|
|
|
textWindowRightSave = textWindow.right;
|
|
|
|
textWindowBottomSave = textWindow.bottom;
|
2020-10-14 12:20:38 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 13:16:30 +00:00
|
|
|
void Interface::loadClip() { // loadSavedTextWindow
|
2020-11-25 17:20:38 +00:00
|
|
|
textWindow.left = textWindowLeftSave;
|
|
|
|
textWindow.top = textWindowTopSave;
|
|
|
|
textWindow.right = textWindowRightSave;
|
|
|
|
textWindow.bottom = textWindowBottomSave;
|
2020-10-14 12:20:38 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 13:16:30 +00:00
|
|
|
void Interface::resetClip() {
|
2020-11-25 17:20:38 +00:00
|
|
|
textWindow.top = textWindow.left = SCREEN_TEXTLIMIT_TOP;
|
|
|
|
textWindow.right = SCREEN_TEXTLIMIT_RIGHT;
|
|
|
|
textWindow.bottom = SCREEN_TEXTLIMIT_BOTTOM;
|
2020-10-14 12:20:38 +00:00
|
|
|
}
|
2020-10-14 13:16:30 +00:00
|
|
|
|
|
|
|
} // namespace TwinE
|