From 6fde4e89f85b8091b40569ac5d8e4a34b6007ace Mon Sep 17 00:00:00 2001 From: Thanasis Antoniou Date: Fri, 8 Nov 2019 16:58:16 +0200 Subject: GUI: Fix crash on low resolutions Related to about cls() and easter egg. Crashed on Android port on small screen devices --- gui/about.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/gui/about.cpp b/gui/about.cpp index 825aab4053..d6571c7671 100644 --- a/gui/about.cpp +++ b/gui/about.cpp @@ -451,11 +451,11 @@ bool EEHandler::handleKeyDown(Common::KeyState &state) { } EE::EE() { - _windowX = (g_system->getOverlayWidth() - 320) / 2; - _windowY = (g_system->getOverlayHeight() - 200) / 2; + _windowX = (g_system->getOverlayWidth() > 320) ? (g_system->getOverlayWidth() - 320) / 2 : 0; + _windowY = (g_system->getOverlayHeight() > 200) ? (g_system->getOverlayHeight() - 200) / 2 : 0; _format = g_system->getOverlayFormat(); - _back.create(320, 200, _format); + _back.create(MIN(g_system->getOverlayWidth(), 320), MIN(g_system->getOverlayHeight(), 200), _format); _colorBlue = _format.RGBToColor(5 * 16, 7 * 16, 8 * 16); _colorOrange = _format.RGBToColor(15 * 16, 7 * 16, 8 * 16); @@ -467,10 +467,10 @@ EE::~EE() { } void EE::cls(bool update) { - _back.fillRect(Common::Rect(0, 0, 320, 200), 0); + _back.fillRect(Common::Rect(0, 0, MIN(g_system->getOverlayWidth(), 320), MIN(g_system->getOverlayHeight(), 200)), 0); if (update) - g_system->copyRectToOverlay(_back.getPixels(), _back.pitch, _windowX, _windowY, 320, 200); + g_system->copyRectToOverlay(_back.getPixels(), _back.pitch, _windowX, _windowY, MIN(g_system->getOverlayWidth(), 320), MIN(g_system->getOverlayHeight(), 200)); } void EE::run() { @@ -1107,7 +1107,12 @@ void EE::drawStatus(Common::String str, int x, uint32 color, int y, int color2, void EE::draw(int sn, int x, int y) { _back.transBlitFrom(_sp[sn], Common::Point(x, y), 0); - g_system->copyRectToOverlay(_back.getBasePtr(x, y), _back.pitch, _windowX + x, _windowY + y, _sp[sn].w, _sp[sn].h); + g_system->copyRectToOverlay(_back.getBasePtr(x, y), + _back.pitch, + MIN(_windowX + x, g_system->getOverlayWidth()), + MIN(_windowY + y, g_system->getOverlayHeight()), + MIN(_sp[sn].w, g_system->getOverlayWidth() - MIN(_windowX + x, g_system->getOverlayWidth())), + MIN(_sp[sn].h, g_system->getOverlayHeight() - MIN(_windowY + y, g_system->getOverlayHeight()) )); } const char *codes = @@ -1120,9 +1125,24 @@ void EE::putshapes() { cls(false); if (_oCoords) { - g_system->copyRectToOverlay(_back.getBasePtr(_obx, _oby), _back.pitch, _windowX + _obx, _windowY + _oby, _sp[kSpB1].w, _sp[kSpB1].h); - g_system->copyRectToOverlay(_back.getBasePtr(_olx, _oly), _back.pitch, _windowX + _olx, _windowY + _oly, _sp[kSpL1].w, _sp[kSpL1].h); - g_system->copyRectToOverlay(_back.getBasePtr(_orx, _ory), _back.pitch, _windowX + _orx, _windowY + _ory, _sp[kSpR1].w, _sp[kSpR1].h); + g_system->copyRectToOverlay(_back.getBasePtr(_obx, _oby), + _back.pitch, + MIN(_windowX + _obx, g_system->getOverlayWidth()), + MIN(_windowY + _oby, g_system->getOverlayHeight()), + MIN(_sp[kSpB1].w, g_system->getOverlayWidth() - MIN(_windowX + _obx, g_system->getOverlayWidth())), + MIN(_sp[kSpB1].h, g_system->getOverlayHeight() - MIN(_windowY + _oby, g_system->getOverlayHeight()) )); + g_system->copyRectToOverlay(_back.getBasePtr(_olx, _oly), + _back.pitch, + MIN(_windowX + _olx, g_system->getOverlayWidth()), + MIN(_windowY + _oly, g_system->getOverlayHeight()), + MIN(_sp[kSpL1].w, g_system->getOverlayWidth() - MIN(_windowX + _olx, g_system->getOverlayWidth())), + MIN(_sp[kSpL1].h, g_system->getOverlayHeight() - MIN(_windowY + _oly, g_system->getOverlayHeight()) )); + g_system->copyRectToOverlay(_back.getBasePtr(_orx, _ory), + _back.pitch, + MIN(_windowX + _orx, g_system->getOverlayWidth()), + MIN(_windowY + _ory, g_system->getOverlayHeight()), + MIN(_sp[kSpR1].w, g_system->getOverlayWidth() - MIN(_windowX + _orx, g_system->getOverlayWidth())), + MIN(_sp[kSpR1].h, g_system->getOverlayHeight() - MIN(_windowY + _ory, g_system->getOverlayHeight()) )); } sprite = kSpB1 + (_tbx / 16) % 4; @@ -1172,7 +1192,12 @@ void EE::putshapes() { for (int i = 0; i < 6; i++, ptr += 4) { Common::Rect r(ptr[0], ptr[1], ptr[2], ptr[3]); _back.fillRect(r, (i < 5 ? color1 : color2)); - g_system->copyRectToOverlay(_back.getBasePtr(ptr[0], ptr[1]), _back.pitch, _windowX + ptr[0], _windowY + ptr[1], r.width(), r.height()); + g_system->copyRectToOverlay(_back.getBasePtr(ptr[0], ptr[1]), + _back.pitch, + MIN(_windowX + ptr[0], g_system->getOverlayWidth()), + MIN(_windowY + ptr[1], g_system->getOverlayHeight()), + MIN(r.width(), g_system->getOverlayWidth() - MIN(_windowX + ptr[0], g_system->getOverlayWidth())), + MIN(r.height(), g_system->getOverlayHeight() - MIN(_windowY + ptr[1], g_system->getOverlayHeight()) )); } int startx = 32; @@ -1210,10 +1235,21 @@ void EE::putshapes() { break; } - g_system->copyRectToOverlay(_back.getPixels(), _back.pitch, _windowX, _windowY, 320, 10); + g_system->copyRectToOverlay(_back.getPixels(), + _back.pitch, + MIN(_windowX, g_system->getOverlayWidth()), + MIN(_windowY, g_system->getOverlayHeight()), + MIN(320, g_system->getOverlayWidth() - MIN(_windowX, g_system->getOverlayWidth())), + MIN(10, g_system->getOverlayHeight() - MIN(_windowY, g_system->getOverlayHeight()) )); - if (_mode == kModeMenu) - g_system->copyRectToOverlay(_back.getBasePtr(92, 30), _back.pitch, _windowX + 92, _windowY + 30, 135, 5 * 10); + if (_mode == kModeMenu) { + g_system->copyRectToOverlay(_back.getBasePtr(92, 30), + _back.pitch, + MIN(_windowX + 92, g_system->getOverlayWidth()), + MIN(_windowY + 30, g_system->getOverlayHeight()), + MIN(135, g_system->getOverlayWidth() - MIN(_windowX + 92, g_system->getOverlayWidth())), + MIN(5 * 10, g_system->getOverlayHeight() - MIN(_windowY + 30, g_system->getOverlayHeight()) )); + } } void EE::doMenu(Common::Event &e) { -- cgit v1.2.3