2014-02-07 22:04:27 +01:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* 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.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2014-02-07 22:04:27 +01:00
|
|
|
* 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.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2014-02-07 22:04:27 +01:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
// winnt.h defines ARRAYSIZE, but we want our own one...
|
|
|
|
#undef ARRAYSIZE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "engines/myst3/gfx.h"
|
|
|
|
|
2014-09-01 09:47:46 +02:00
|
|
|
#include "graphics/surface.h"
|
|
|
|
|
2014-02-07 22:04:27 +01:00
|
|
|
namespace Myst3 {
|
|
|
|
|
|
|
|
BaseRenderer::BaseRenderer(OSystem *system)
|
2014-07-03 20:18:21 +02:00
|
|
|
: _system(system), _font(NULL) { }
|
2014-02-07 22:04:27 +01:00
|
|
|
|
|
|
|
BaseRenderer::~BaseRenderer() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseRenderer::initFont(const Graphics::Surface *surface) {
|
|
|
|
_font = createTexture(surface);
|
|
|
|
}
|
|
|
|
|
2014-09-13 11:44:19 +02:00
|
|
|
void BaseRenderer::freeFont() {
|
|
|
|
if (_font) {
|
|
|
|
freeTexture(_font);
|
|
|
|
_font = nullptr;
|
|
|
|
}
|
2014-02-07 22:04:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect BaseRenderer::getFontCharacterRect(uint8 character) {
|
|
|
|
uint index = 0;
|
|
|
|
|
|
|
|
if (character == ' ')
|
|
|
|
index = 0;
|
|
|
|
else if (character >= '0' && character <= '9')
|
|
|
|
index = 1 + character - '0';
|
|
|
|
else if (character >= 'A' && character <= 'Z')
|
|
|
|
index = 1 + 10 + character - 'A';
|
|
|
|
else if (character == '|')
|
|
|
|
index = 1 + 10 + 26;
|
|
|
|
|
|
|
|
return Common::Rect(16 * index, 0, 16 * (index + 1), 32);
|
|
|
|
}
|
|
|
|
|
2012-12-26 11:43:52 +01:00
|
|
|
Common::Rect BaseRenderer::viewport() const {
|
|
|
|
return _screenViewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect BaseRenderer::frameViewport() const {
|
|
|
|
Common::Rect screen = viewport();
|
|
|
|
|
|
|
|
Common::Rect frame = Common::Rect(screen.width(), screen.height() * kFrameHeight / kOriginalHeight);
|
|
|
|
frame.translate(screen.left, screen.top + screen.height() * kBottomBorderHeight / kOriginalHeight);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseRenderer::computeScreenViewport() {
|
|
|
|
int32 screenWidth = _system->getWidth();
|
|
|
|
int32 screenHeight = _system->getHeight();
|
|
|
|
|
|
|
|
// Aspect ratio correction
|
|
|
|
int32 viewportWidth = MIN<int32>(screenWidth, screenHeight * kOriginalWidth / kOriginalHeight);
|
|
|
|
int32 viewportHeight = MIN<int32>(screenHeight, screenWidth * kOriginalHeight / kOriginalWidth);
|
|
|
|
_screenViewport = Common::Rect(viewportWidth, viewportHeight);
|
|
|
|
|
|
|
|
// Pillarboxing
|
|
|
|
_screenViewport.translate((screenWidth - viewportWidth) / 2,
|
|
|
|
(screenHeight - viewportHeight) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Point BaseRenderer::frameCenter() const {
|
|
|
|
Common::Rect screen = viewport();
|
|
|
|
Common::Rect frame = frameViewport();
|
|
|
|
return Common::Point((frame.left + frame.right) / 2, screen.top + screen.bottom - (frame.top + frame.bottom) / 2);
|
|
|
|
}
|
|
|
|
|
2014-09-01 09:47:46 +02:00
|
|
|
void BaseRenderer::flipVertical(Graphics::Surface *s) {
|
|
|
|
for (int y = 0; y < s->h / 2; ++y) {
|
|
|
|
// Flip the lines
|
|
|
|
byte *line1P = (byte *)s->getBasePtr(0, y);
|
|
|
|
byte *line2P = (byte *)s->getBasePtr(0, s->h - y - 1);
|
|
|
|
|
|
|
|
for (int x = 0; x < s->pitch; ++x)
|
|
|
|
SWAP(line1P[x], line2P[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 20:18:21 +02:00
|
|
|
} // End of namespace Myst3
|