From 6b9264d9da41d8be08ea46076026901374d3d106 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 8 Dec 2015 08:42:08 +0100 Subject: LAB: Refactoring the vgaUnscale code and the way it's used --- engines/lab/tilepuzzle.cpp | 54 +++++++++++++++++++++------------------------- engines/lab/utils.cpp | 29 +++++++++++-------------- engines/lab/utils.h | 3 +-- 3 files changed, 38 insertions(+), 48 deletions(-) (limited to 'engines/lab') diff --git a/engines/lab/tilepuzzle.cpp b/engines/lab/tilepuzzle.cpp index cdc6735de3..2739473d47 100644 --- a/engines/lab/tilepuzzle.cpp +++ b/engines/lab/tilepuzzle.cpp @@ -66,17 +66,16 @@ void LabEngine::initTilePuzzle() { /* Processes mouse clicks and changes the combination. */ /*****************************************************************************/ void LabEngine::mouseTile(Common::Point pos) { - int x = _utils->vgaUnscaleX(pos.x); - int y = _utils->vgaUnscaleY(pos.y); + Common::Point realPos = _utils->vgaUnscale(pos); - if ((x < 101) || (y < 26)) + if ((realPos.x < 101) || (realPos.y < 26)) return; - x = (x - 101) / 30; - y = (y - 26) / 25; + int tileX = (realPos.x - 101) / 30; + int tileY = (realPos.y - 26) / 25; - if ((x < 4) && (y < 4)) - changeTile(x, y); + if ((tileX < 4) && (tileY < 4)) + changeTile(tileX, tileY); } /*****************************************************************************/ @@ -152,29 +151,26 @@ void LabEngine::changeTile(uint16 col, uint16 row) { /* Processes mouse clicks and changes the combination. */ /*****************************************************************************/ void LabEngine::mouseCombination(Common::Point pos) { - uint16 number; - - int x = _utils->vgaUnscaleX(pos.x); - int y = _utils->vgaUnscaleY(pos.y); - - if ((y >= 63) && (y <= 99)) { - if ((x >= 44) && (x < 83)) - number = 0; - else if (x < 127) - number = 1; - else if (x < 165) - number = 2; - else if (x < 210) - number = 3; - else if (x < 245) - number = 4; - else if (x < 286) - number = 5; - else - return; + Common::Point realPos = _utils->vgaUnscale(pos); - changeCombination(number); - } + if (!Common::Rect(44, 63, 285, 99).contains(realPos)) + return; + + uint16 number = 0; + if (realPos.x < 83) + number = 0; + else if (realPos.x < 127) + number = 1; + else if (realPos.x < 165) + number = 2; + else if (realPos.x < 210) + number = 3; + else if (realPos.x < 245) + number = 4; + else if (realPos.x < 286) + number = 5; + + changeCombination(number); } /*****************************************************************************/ diff --git a/engines/lab/utils.cpp b/engines/lab/utils.cpp index 6d4784d0ac..041a970eff 100644 --- a/engines/lab/utils.cpp +++ b/engines/lab/utils.cpp @@ -59,7 +59,7 @@ uint16 Utils::scaleY(uint16 y) { } /*****************************************************************************/ -/* Scales the VGA cords to SVGA if necessary; otherwise, returns VGA cords. */ +/* Scales the VGA coords to SVGA if necessary; otherwise, returns VGA coords.*/ /*****************************************************************************/ int16 Utils::vgaScaleX(int16 x) { if (_vm->_isHiRes) @@ -69,7 +69,7 @@ int16 Utils::vgaScaleX(int16 x) { } /*****************************************************************************/ -/* Scales the VGA cords to SVGA if necessary; otherwise, returns VGA cords. */ +/* Scales the VGA coords to SVGA if necessary; otherwise, returns VGA coords.*/ /*****************************************************************************/ int16 Utils::vgaScaleY(int16 y) { if (_vm->_isHiRes) @@ -86,23 +86,18 @@ uint16 Utils::svgaCord(uint16 cord) { } /*****************************************************************************/ -/* Converts SVGA cords to VGA if necessary, otherwise returns VGA cords. */ +/* Converts SVGA coords to VGA if necessary, otherwise returns VGA coords. */ /*****************************************************************************/ -int Utils::vgaUnscaleX(int x) { - if (_vm->_isHiRes) - return (x / 2); - else - return x; -} +Common::Point Utils::vgaUnscale(Common::Point pos) { + Common::Point result; + if (_vm->_isHiRes) { + result.x = pos.x / 2; + result.y = (pos.y * 5) / 12; + } else { + result = pos; + } -/*****************************************************************************/ -/* Converts SVGA cords to VGA if necessary, otherwise returns VGA cords. */ -/*****************************************************************************/ -int Utils::vgaUnscaleY(int y) { - if (_vm->_isHiRes) - return ((y * 5) / 12); - else - return y; + return result; } /*****************************************************************************/ diff --git a/engines/lab/utils.h b/engines/lab/utils.h index 4fa168dd54..441473672c 100644 --- a/engines/lab/utils.h +++ b/engines/lab/utils.h @@ -52,8 +52,7 @@ public: int16 vgaScaleX(int16 x); int16 vgaScaleY(int16 y); uint16 svgaCord(uint16 cord); - int vgaUnscaleX(int x); - int vgaUnscaleY(int y); + Common::Point vgaUnscale(Common::Point pos); void unDiff(byte *newBuf, byte *oldBuf, byte *diffData, uint16 bytesperrow, bool isV); void runLengthDecode(byte *dest, byte *source); void VRunLengthDecode(byte *dest, byte *source, uint16 bytesPerRow); -- cgit v1.2.3