Files
scummvm/engines/scumm/gfx_mac.cpp
T
Torbjörn Andersson aa35d449a6 SCUMM: Eliminate need to expose MacDialogWindow outside of MacGui
The plan is to eventually hide as much of the MacGui implementation as
possible from the rest of the engine, and only provide a minimal
macgui.h for it to use.
2023-12-22 15:09:06 +01:00

189 lines
5.9 KiB
C++

/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/system.h"
#include "graphics/macega.h"
#include "scumm/charset.h"
#include "scumm/macgui/macgui.h"
namespace Scumm {
void ScummEngine::mac_markScreenAsDirty(int x, int y, int w, int h) {
// Mark the virtual screen as dirty. The top and left coordinates are
// rounded down, while the bottom and right ones are rounded up.
VirtScreen *vs = &_virtscr[kMainVirtScreen];
int vsTop = y / 2 - vs->topline;
int vsBottom = (y + h) / 2 - vs->topline;
int vsLeft = x / 2;
int vsRight = (x + w) / 2;
if ((y + h) & 1)
vsBottom++;
if ((x + w) & 1)
vsRight++;
markRectAsDirty(kMainVirtScreen, vsLeft, vsRight, vsTop, vsBottom);
}
void ScummEngine::mac_drawStripToScreen(VirtScreen *vs, int top, int x, int y, int width, int height) {
// The verb screen is completely replaced with a custom GUI. While
// it is active, all other drawing to that area is suspended.
if (_macGui && vs->number == kVerbVirtScreen && _macGui->isVerbGuiActive())
return;
const byte *pixels = vs->getPixels(x, top);
const byte *ts = (byte *)_textSurface.getBasePtr(x * 2, y * 2);
byte *mac = (byte *)_macScreen->getBasePtr(x * 2, y * 2);
int pixelsPitch = vs->pitch;
int tsPitch = _textSurface.pitch;
int macPitch = _macScreen->pitch;
// In b/w Mac rendering mode, the shadow palette is implemented here,
// and not as a palette manipulation. See special cases in o5_roomOps()
// and updatePalette().
//
// This is used at the very least for the lightning flashes at Castle
// Brunwald in Indy 3, as well as the scene where the dragon finds
// Rusty in Loom.
//
// Interestingly, the original Mac interpreter does not seem to do
// this, and instead just renders the scene as if the palette was
// unmodified. At least, that's what Mini vMac did when I tried it.
if (_renderMode == Common::kRenderMacintoshBW) {
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
int color = enhancementEnabled(kEnhVisualChanges) ? _shadowPalette[pixels[w]] : pixels[w];
if (ts[2 * w] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w] = Graphics::macEGADither[color][0];
if (ts[2 * w + 1] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w + 1] = Graphics::macEGADither[color][1];
if (ts[2 * w + tsPitch] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w + macPitch] = Graphics::macEGADither[color][2];
if (ts[2 * w + tsPitch + 1] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w + macPitch + 1] = Graphics::macEGADither[color][3];
}
pixels += pixelsPitch;
ts += tsPitch * 2;
mac += macPitch * 2;
}
} else {
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
if (ts[2 * w] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w] = pixels[w];
if (ts[2 * w + 1] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w + 1] = pixels[w];
if (ts[2 * w + tsPitch] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w + macPitch] = pixels[w];
if (ts[2 * w + tsPitch + 1] == CHARSET_MASK_TRANSPARENCY)
mac[2 * w + macPitch + 1] = pixels[w];
}
pixels += pixelsPitch;
ts += tsPitch * 2;
mac += macPitch * 2;
}
}
_system->copyRectToScreen(_macScreen->getBasePtr(x * 2, y * 2), _macScreen->pitch, x * 2, y * 2, width * 2, height * 2);
}
void ScummEngine::mac_drawIndy3TextBox() {
Graphics::Surface *s = _macGui->textArea();
// The first two rows of the text box are padding for font rendering.
// They are not drawn to the screen.
int x = 96;
int y = 32 + _screenDrawOffset * 2;
int w = s->w;
int h = s->h - 2;
// The text box is drawn to the Mac screen and text surface, as if it
// had been one giant glyph. Note that it will be drawn on the main
// virtual screen, but we still pretend it's on the text one.
byte *ptr = (byte *)s->getBasePtr(0, 2);
int pitch = s->pitch;
_macScreen->copyRectToSurface(ptr, pitch, x, y, w, h);
_textSurface.fillRect(Common::Rect(x, y, x + w, y + h), 0);
mac_markScreenAsDirty(x, y, w, h);
}
void ScummEngine::mac_undrawIndy3TextBox() {
Graphics::Surface *s = _macGui->textArea();
int x = 96;
int y = 32 + _screenDrawOffset * 2;
int w = s->w;
int h = s->h - 2;
_macScreen->fillRect(Common::Rect(x, y, x + w, y + h), 0);
_textSurface.fillRect(Common::Rect(x, y, x + w, y + h), CHARSET_MASK_TRANSPARENCY);
mac_markScreenAsDirty(x, y, w, h);
}
void ScummEngine::mac_undrawIndy3CreditsText() {
// Set _masMask to make the text clear, and _textScreenID to ensure
// that it's the main area that's cleared.
_charset->_hasMask = true;
_charset->_textScreenID = kMainVirtScreen;
restoreCharsetBg();
}
Common::KeyState ScummEngine::mac_showOldStyleBannerAndPause(const char *msg, int32 waitTime) {
char bannerMsg[512];
_messageBannerActive = true;
// Fetch the translated string for the message...
convertMessageToString((const byte *)msg, (byte *)bannerMsg, sizeof(bannerMsg));
Common::KeyState ks = Common::KEYCODE_INVALID;
_macGui->drawBanner(bannerMsg);
if (waitTime) {
bool leftBtnPressed = false, rightBtnPressed = false;
waitForBannerInput(waitTime, ks, leftBtnPressed, rightBtnPressed);
}
_macGui->undrawBanner();
clearClickedStatus();
_messageBannerActive = false;
return ks;
}
} // End of namespace Scumm