From 513d0be10628574c98bb2588a7ef4567590228e2 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 19 Oct 2011 20:27:43 +0300 Subject: SCI: Merged all the code to get/set the NS rect --- engines/sci/graphics/animate.cpp | 16 ++++------------ engines/sci/graphics/compare.cpp | 35 +++++++++++++++++++++++++++-------- engines/sci/graphics/compare.h | 2 ++ engines/sci/graphics/controls.cpp | 5 +++-- engines/sci/graphics/frameout.cpp | 6 ++---- engines/sci/graphics/text32.cpp | 17 ++++------------- engines/sci/graphics/text32.h | 1 - 7 files changed, 42 insertions(+), 40 deletions(-) (limited to 'engines/sci/graphics') diff --git a/engines/sci/graphics/animate.cpp b/engines/sci/graphics/animate.cpp index 18f8511953..983e697481 100644 --- a/engines/sci/graphics/animate.cpp +++ b/engines/sci/graphics/animate.cpp @@ -32,6 +32,7 @@ #include "sci/engine/selector.h" #include "sci/engine/vm.h" #include "sci/graphics/cache.h" +#include "sci/graphics/compare.h" #include "sci/graphics/cursor.h" #include "sci/graphics/ports.h" #include "sci/graphics/paint16.h" @@ -307,10 +308,7 @@ void GfxAnimate::setNsRect(GfxView *view, AnimateList::iterator it) { // This special handling is not included in the other SCI1.1 interpreters and MUST NOT be // checked in those cases, otherwise we will break games (e.g. EcoQuest 2, room 200) if ((g_sci->getGameId() == GID_HOYLE4) && (it->scaleSignal & kScaleSignalHoyle4SpecialHandling)) { - it->celRect.left = readSelectorValue(_s->_segMan, it->object, SELECTOR(nsLeft)); - it->celRect.top = readSelectorValue(_s->_segMan, it->object, SELECTOR(nsTop)); - it->celRect.right = readSelectorValue(_s->_segMan, it->object, SELECTOR(nsRight)); - it->celRect.bottom = readSelectorValue(_s->_segMan, it->object, SELECTOR(nsBottom)); + it->celRect = g_sci->_gfxCompare->getNSRect(it->object); view->getCelSpecialHoyle4Rect(it->loopNo, it->celNo, it->x, it->y, it->z, it->celRect); shouldSetNsRect = false; } else { @@ -319,10 +317,7 @@ void GfxAnimate::setNsRect(GfxView *view, AnimateList::iterator it) { } if (shouldSetNsRect) { - writeSelectorValue(_s->_segMan, it->object, SELECTOR(nsLeft), it->celRect.left); - writeSelectorValue(_s->_segMan, it->object, SELECTOR(nsTop), it->celRect.top); - writeSelectorValue(_s->_segMan, it->object, SELECTOR(nsRight), it->celRect.right); - writeSelectorValue(_s->_segMan, it->object, SELECTOR(nsBottom), it->celRect.bottom); + g_sci->_gfxCompare->setNSRect(it->object, it->celRect); } } @@ -544,10 +539,7 @@ void GfxAnimate::addToPicDrawCels() { applyGlobalScaling(it, view); } view->getCelScaledRect(it->loopNo, it->celNo, it->x, it->y, it->z, it->scaleX, it->scaleY, it->celRect); - writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsLeft), it->celRect.left); - writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsTop), it->celRect.top); - writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsRight), it->celRect.right); - writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsBottom), it->celRect.bottom); + g_sci->_gfxCompare->setNSRect(curObject, it->celRect); } else { view->getCelRect(it->loopNo, it->celNo, it->x, it->y, it->z, it->celRect); } diff --git a/engines/sci/graphics/compare.cpp b/engines/sci/graphics/compare.cpp index 3183ffa2b9..70dff15a86 100644 --- a/engines/sci/graphics/compare.cpp +++ b/engines/sci/graphics/compare.cpp @@ -147,10 +147,7 @@ void GfxCompare::kernelSetNowSeen(reg_t objectReference) { #endif if (lookupSelector(_segMan, objectReference, SELECTOR(nsTop), NULL, NULL) == kSelectorVariable) { - writeSelectorValue(_segMan, objectReference, SELECTOR(nsLeft), celRect.left); - writeSelectorValue(_segMan, objectReference, SELECTOR(nsRight), celRect.right); - writeSelectorValue(_segMan, objectReference, SELECTOR(nsTop), celRect.top); - writeSelectorValue(_segMan, objectReference, SELECTOR(nsBottom), celRect.bottom); + setNSRect(objectReference, celRect); } } @@ -221,10 +218,7 @@ void GfxCompare::kernelBaseSetter(reg_t object) { scaleSignal = 0; if (scaleSignal & kScaleSignalDoScaling) { - celRect.left = readSelectorValue(_segMan, object, SELECTOR(nsLeft)); - celRect.right = readSelectorValue(_segMan, object, SELECTOR(nsRight)); - celRect.top = readSelectorValue(_segMan, object, SELECTOR(nsTop)); - celRect.bottom = readSelectorValue(_segMan, object, SELECTOR(nsBottom)); + celRect = getNSRect(object); } else { if (tmpView->isSci2Hires()) tmpView->adjustToUpscaledCoordinates(y, x); @@ -247,4 +241,29 @@ void GfxCompare::kernelBaseSetter(reg_t object) { } } +Common::Rect GfxCompare::getNSRect(reg_t object, bool fixRect) { + Common::Rect nsRect; + nsRect.top = readSelectorValue(_segMan, object, SELECTOR(nsTop)); + nsRect.left = readSelectorValue(_segMan, object, SELECTOR(nsLeft)); + nsRect.bottom = readSelectorValue(_segMan, object, SELECTOR(nsBottom)); + nsRect.right = readSelectorValue(_segMan, object, SELECTOR(nsRight)); + + if (fixRect) { + // nsRect top/left may be negative, adjust accordingly + if (nsRect.top < 0) + nsRect.top = 0; + if (nsRect.left < 0) + nsRect.left = 0; + } + + return nsRect; +} + +void GfxCompare::setNSRect(reg_t object, Common::Rect nsRect) { + writeSelectorValue(_segMan, object, SELECTOR(nsLeft), nsRect.left); + writeSelectorValue(_segMan, object, SELECTOR(nsTop), nsRect.top); + writeSelectorValue(_segMan, object, SELECTOR(nsRight), nsRect.right); + writeSelectorValue(_segMan, object, SELECTOR(nsBottom), nsRect.bottom); +} + } // End of namespace Sci diff --git a/engines/sci/graphics/compare.h b/engines/sci/graphics/compare.h index bacb6e71e2..91e3b90fdb 100644 --- a/engines/sci/graphics/compare.h +++ b/engines/sci/graphics/compare.h @@ -42,6 +42,8 @@ public: reg_t kernelCanBeHere(reg_t curObject, reg_t listReference); bool kernelIsItSkip(GuiResourceId viewId, int16 loopNo, int16 celNo, Common::Point position); void kernelBaseSetter(reg_t object); + Common::Rect getNSRect(reg_t object, bool fixRect = false); + void setNSRect(reg_t object, Common::Rect nsRect); private: SegManager *_segMan; diff --git a/engines/sci/graphics/controls.cpp b/engines/sci/graphics/controls.cpp index 8d4712a969..a0750c7d3e 100644 --- a/engines/sci/graphics/controls.cpp +++ b/engines/sci/graphics/controls.cpp @@ -30,6 +30,7 @@ #include "sci/engine/kernel.h" #include "sci/engine/state.h" #include "sci/engine/selector.h" +#include "sci/graphics/compare.h" #include "sci/graphics/ports.h" #include "sci/graphics/paint16.h" #include "sci/graphics/font.h" @@ -230,8 +231,8 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) { if (textChanged) { GuiResourceId oldFontId = _text16->GetFontId(); GuiResourceId fontId = readSelectorValue(_segMan, controlObject, SELECTOR(font)); - rect = Common::Rect(readSelectorValue(_segMan, controlObject, SELECTOR(nsLeft)), readSelectorValue(_segMan, controlObject, SELECTOR(nsTop)), - readSelectorValue(_segMan, controlObject, SELECTOR(nsRight)), readSelectorValue(_segMan, controlObject, SELECTOR(nsBottom))); + rect = g_sci->_gfxCompare->getNSRect(controlObject); + _text16->SetFont(fontId); if (textAddChar) { diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp index c771b5c7a4..a41efd6a9f 100644 --- a/engines/sci/graphics/frameout.cpp +++ b/engines/sci/graphics/frameout.cpp @@ -37,6 +37,7 @@ #include "sci/engine/vm.h" #include "sci/graphics/cache.h" #include "sci/graphics/coordadjuster.h" +#include "sci/graphics/compare.h" #include "sci/graphics/font.h" #include "sci/graphics/view.h" #include "sci/graphics/screen.h" @@ -546,10 +547,7 @@ void GfxFrameout::kernelFrameout() { continue; } - writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsLeft), nsRect.left); - writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsTop), nsRect.top); - writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsRight), nsRect.right); - writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsBottom), nsRect.bottom); + g_sci->_gfxCompare->setNSRect(itemEntry->object, nsRect); } int16 screenHeight = _screen->getHeight(); diff --git a/engines/sci/graphics/text32.cpp b/engines/sci/graphics/text32.cpp index 49e6fe01b8..c7c9332313 100644 --- a/engines/sci/graphics/text32.cpp +++ b/engines/sci/graphics/text32.cpp @@ -32,6 +32,7 @@ #include "sci/engine/selector.h" #include "sci/engine/state.h" #include "sci/graphics/cache.h" +#include "sci/graphics/compare.h" #include "sci/graphics/font.h" #include "sci/graphics/screen.h" #include "sci/graphics/text32.h" @@ -123,14 +124,14 @@ void GfxText32::drawTextBitmap(reg_t textObject) { byte *surface = memoryPtr + BITMAP_HEADER_SIZE; int curByte = 0; - Common::Rect nsRect = getNSRect(textObject); + Common::Rect nsRect = g_sci->_gfxCompare->getNSRect(textObject); Common::Rect planeRect = getPlaneRect(textObject); uint16 x = readSelectorValue(_segMan, textObject, SELECTOR(x)); uint16 y = readSelectorValue(_segMan, textObject, SELECTOR(y)); uint16 textX = planeRect.left + x; uint16 textY = planeRect.top + y; - uint16 width = nsRect.width(); - uint16 height = nsRect.height(); + uint16 width = nsRect.width() + 1; + uint16 height = nsRect.height() + 1; // Upscale the coordinates/width if the fonts are already upscaled if (_screen->fontIsUpscaled()) { @@ -163,16 +164,6 @@ Common::Rect GfxText32::getPlaneRect(reg_t textObject) { return planeRect; } -Common::Rect GfxText32::getNSRect(reg_t textObject) { - Common::Rect nsRect; - nsRect.top = readSelectorValue(_segMan, textObject, SELECTOR(nsTop)); - nsRect.left = readSelectorValue(_segMan, textObject, SELECTOR(nsLeft)); - nsRect.bottom = readSelectorValue(_segMan, textObject, SELECTOR(nsBottom)) + 1; - nsRect.right = readSelectorValue(_segMan, textObject, SELECTOR(nsRight)) + 1; - - return nsRect; -} - int16 GfxText32::GetLongest(const char *text, int16 maxWidth, GfxFont *font) { uint16 curChar = 0; int16 maxChars = 0, curCharCount = 0; diff --git a/engines/sci/graphics/text32.h b/engines/sci/graphics/text32.h index 5a069958d9..dfcbf63ccf 100644 --- a/engines/sci/graphics/text32.h +++ b/engines/sci/graphics/text32.h @@ -47,7 +47,6 @@ private: void Width(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight, bool restoreFont); void StringWidth(const char *str, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight); Common::Rect getPlaneRect(reg_t textObject); - Common::Rect getNSRect(reg_t textObject); SegManager *_segMan; GfxCache *_cache; -- cgit v1.2.3