[Scummvm-git-logs] scummvm master -> e2221d6585383915344dcdfd3e1ce19b65e73e7f
bluegr
noreply at scummvm.org
Tue Mar 22 20:15:55 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e2221d6585 CHEWY: Refactor the hotspot matching code
Commit: e2221d6585383915344dcdfd3e1ce19b65e73e7f
https://github.com/scummvm/scummvm/commit/e2221d6585383915344dcdfd3e1ce19b65e73e7f
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-03-22T22:15:44+02:00
Commit Message:
CHEWY: Refactor the hotspot matching code
Changed paths:
engines/chewy/dialogs/cinema.cpp
engines/chewy/dialogs/files.cpp
engines/chewy/dialogs/inventory.cpp
engines/chewy/dialogs/options.cpp
engines/chewy/mouse.cpp
engines/chewy/mouse.h
engines/chewy/rooms/room04.cpp
diff --git a/engines/chewy/dialogs/cinema.cpp b/engines/chewy/dialogs/cinema.cpp
index 942d12bd37f..aa795f1ffdc 100644
--- a/engines/chewy/dialogs/cinema.cpp
+++ b/engines/chewy/dialogs/cinema.cpp
@@ -30,6 +30,13 @@ namespace Dialogs {
static constexpr int CINEMA_LINES = 12;
+static const Common::Rect cinematicsHotspots[] = {
+ { 10, 80, 32, 105 },
+ { 10, 150, 32, 175 },
+ { 36, 64, 310, 188 },
+ { -1, -1, -1, -1 }
+};
+
static const int16 CINEMA_TBL[4 * 3] = {
10, 80, 32, 105,
10, 150, 32, 175,
@@ -87,7 +94,7 @@ void Cinema::execute() {
if (_G(minfo)._button == 1 && !flag) {
flag = true;
- switch (_G(in)->mouseVector(g_events->_mousePos.x, g_events->_mousePos.y, CINEMA_TBL, 3)) {
+ switch (_G(in)->findHotspot(cinematicsHotspots)) {
case 0:
g_events->_kbInfo._scanCode = Common::KEYCODE_UP;
if (!endLoop)
diff --git a/engines/chewy/dialogs/files.cpp b/engines/chewy/dialogs/files.cpp
index 0ac7abb40c2..a15603e0314 100644
--- a/engines/chewy/dialogs/files.cpp
+++ b/engines/chewy/dialogs/files.cpp
@@ -36,15 +36,16 @@ enum Widget {
GAME = 4, QUIT = 5, OPTIONS = 6, W7 = 7, W8 = 8
};
-static const int16 FILE_ICONS[8 * 4] = {
- 14, 73, 32, 94,
- 14, 96, 32, 118,
- 36, 64, 310, 128,
- 16, 143, 76, 193,
- 78, 143, 130, 193,
- 132, 143, 178, 193,
- 180, 143, 228, 193,
- 232, 143, 310, 193
+static const Common::Rect fileHotspots[] = {
+ { 14, 73, 32, 94 },
+ { 14, 96, 32, 118 },
+ { 36, 64, 310, 128 },
+ { 16, 143, 76, 193 },
+ { 78, 143, 130, 193 },
+ { 132, 143, 178, 193 },
+ { 180, 143, 228, 193 },
+ { 232, 143, 310, 193 },
+ { -1, -1, -1, -1 }
};
@@ -160,7 +161,7 @@ int16 Files::execute(bool isInGame) {
}
if (!flag && _G(minfo)._button == 1) {
- int16 rect = _G(in)->mouseVector(g_events->_mousePos.x, g_events->_mousePos.y, FILE_ICONS, 8);
+ int16 rect = _G(in)->findHotspot(fileHotspots);
flag = true;
key = 0;
diff --git a/engines/chewy/dialogs/inventory.cpp b/engines/chewy/dialogs/inventory.cpp
index 6b80c0e2f44..4421936468e 100644
--- a/engines/chewy/dialogs/inventory.cpp
+++ b/engines/chewy/dialogs/inventory.cpp
@@ -30,15 +30,16 @@
namespace Chewy {
namespace Dialogs {
-static const int16 INVENTORY_HOTSPOTS[INVENTORY_HOTSPOTS_COUNT][4] = {
- { WIN_INF_X + 6, WIN_INF_Y + 10, WIN_INF_X + 6 + 30, WIN_INF_Y + 10 + 14 },
- { WIN_INF_X + 6 + 32, WIN_INF_Y + 10, WIN_INF_X + 6 + 62, WIN_INF_Y + 10 + 14 },
- { -1, -1, -1, -1 },
- { WIN_INF_X + 198, WIN_INF_Y + 10, WIN_INF_X + 198 + 30, WIN_INF_Y + 10 + 14 },
- { WIN_INF_X + 198 + 40, WIN_INF_Y + 10, WIN_INF_X + 198 + 70, WIN_INF_Y + 10 + 14 },
- { WIN_INF_X + 6, WIN_INF_Y + 4 + 26, WIN_INF_X + 268, WIN_INF_Y + 4 + 26 + 90 },
- { WIN_INF_X + 242, WIN_INF_Y + 136, WIN_INF_X + 292, WIN_INF_Y + 136 + 14 },
- { WIN_INF_X + 242, WIN_INF_Y + 156, WIN_INF_X + 292, WIN_INF_Y + 156 + 14 }
+static const Common::Rect inventoryHotspots[] = {
+ { 21, 25, 51, 39 },
+ { 53, 25, 83, 39 },
+ { -2, -2, -2, -2 },
+ { 213, 25, 243, 39 },
+ { 253, 25, 283, 39 },
+ { 21, 45, 283, 135 },
+ { 257, 151, 307, 165 },
+ { 257, 171, 307, 185 },
+ { -1, -1, -1, -1 }
};
static const int16 ANI_INVENT_END[3] = { 7, 16, 24 };
@@ -60,11 +61,11 @@ void Inventory::plot_menu() {
}
int16 y;
- int16 k = _G(in)->mouseVector(g_events->_mousePos.x, g_events->_mousePos.y, &INVENTORY_HOTSPOTS[0][0], INVENTORY_HOTSPOTS_COUNT);
+ int16 k = _G(in)->findHotspot(inventoryHotspots);
if (k != -1) {
if (k < 5)
- _G(out)->boxFill(INVENTORY_HOTSPOTS[k][0], INVENTORY_HOTSPOTS[k][1],
- INVENTORY_HOTSPOTS[k][2] + 1, INVENTORY_HOTSPOTS[k][3] + 5, 41);
+ _G(out)->boxFill(inventoryHotspots[k].left, inventoryHotspots[k].top,
+ inventoryHotspots[k].bottom + 1, inventoryHotspots[k].right + 5, 41);
else {
int16 x = (g_events->_mousePos.x - (WIN_INF_X)) / 54;
y = (g_events->_mousePos.y - (WIN_INF_Y + 4 + 30)) / 30;
@@ -167,7 +168,7 @@ void Inventory::menu() {
mouseFl = true;
g_events->_kbInfo._keyCode = '\0';
- int16 k = _G(in)->mouseVector(g_events->_mousePos.x, g_events->_mousePos.y, &INVENTORY_HOTSPOTS[0][0], INVENTORY_HOTSPOTS_COUNT);
+ int16 k = _G(in)->findHotspot(inventoryHotspots);
if (keyVal == Common::KEYCODE_F1)
k = 0;
else if (keyVal == Common::KEYCODE_F2)
@@ -424,7 +425,7 @@ int16 Inventory::look(int16 invent_nr, int16 mode, int16 ats_nr) {
}
while (!endLoop) {
- int16 rect = _G(in)->mouseVector(g_events->_mousePos.x, g_events->_mousePos.y, (const int16 *)INVENTORY_HOTSPOTS, INVENTORY_HOTSPOTS_COUNT);
+ int16 rect = _G(in)->findHotspot(inventoryHotspots);
if (_G(minfo)._button) {
if (_G(minfo)._button == 2) {
diff --git a/engines/chewy/dialogs/options.cpp b/engines/chewy/dialogs/options.cpp
index a418674f7f3..6b92b4c8419 100644
--- a/engines/chewy/dialogs/options.cpp
+++ b/engines/chewy/dialogs/options.cpp
@@ -43,16 +43,17 @@ namespace Dialogs {
#define MUSIC_ON2 26
#define EXIT 27
-static const int16 OPTION_ICONS[9 * 4] = {
- 18, 61, 40, 76,
- 112, 61, 130, 76,
- 82, 104, 144, 139,
- 164, 93, 194, 115,
- 198, 80, 206, 115,
- 210, 55, 302, 138,
- 126, 146, 210, 198,
- 22, 92, 44, 136,
- 50, 92, 72, 136
+static const Common::Rect optionHotspots[] = {
+ { 18, 61, 40, 76 },
+ { 112, 61, 130, 76 },
+ { 82, 104, 144, 139 },
+ { 164, 93, 194, 115 },
+ { 198, 80, 206, 115 },
+ { 210, 55, 302, 138 },
+ { 126, 146, 210, 198 },
+ { 22, 92, 44, 136 },
+ { 50, 92, 72, 136 },
+ { -1, -1, -1, -1 }
};
void Options::execute(TafInfo *ti) {
@@ -149,7 +150,7 @@ void Options::execute(TafInfo *ti) {
if ((_G(minfo)._button == 1) || (key == Common::KEYCODE_RETURN)) {
WAIT_TASTE_LOS
- int16 rect = _G(in)->mouseVector(g_events->_mousePos.x, g_events->_mousePos.y, OPTION_ICONS, 9);
+ int16 rect = _G(in)->findHotspot(optionHotspots);
switch (rect) {
case 0:
if (_G(gameState).FramesPerSecond > 6)
diff --git a/engines/chewy/mouse.cpp b/engines/chewy/mouse.cpp
index d71782e2490..795f94f6d7d 100644
--- a/engines/chewy/mouse.cpp
+++ b/engines/chewy/mouse.cpp
@@ -35,14 +35,16 @@ InputMgr::InputMgr() {
InputMgr::~InputMgr() {
}
-int16 InputMgr::mouseVector(int16 x, int16 y, const int16 *tbl, int16 nr) {
- int16 i = -1;
- for (int16 j = 0; (j < nr * 4) && (i == -1); j += 4) {
- if ((x >= tbl[j]) && (x <= tbl[j + 2]) && (y >= tbl[j + 1]) && (y <= tbl[j + 3]))
- i = j / 4;
- }
-
- return i;
+int16 InputMgr::findHotspot(const Common::Rect *hotspots) {
+ int16 i = 0;
+
+ do {
+ if (hotspots[i].contains(g_events->_mousePos))
+ return i;
+ i++;
+ } while (hotspots[i].left != -1);
+
+ return -1;
}
int16 InputMgr::getSwitchCode() {
diff --git a/engines/chewy/mouse.h b/engines/chewy/mouse.h
index 528eb228dd6..d233289e77c 100644
--- a/engines/chewy/mouse.h
+++ b/engines/chewy/mouse.h
@@ -23,6 +23,7 @@
#define CHEWY_MOUSE_H
#include "common/keyboard.h"
+#include "common/rect.h"
namespace Chewy {
@@ -33,7 +34,7 @@ public:
InputMgr();
~InputMgr();
- int16 mouseVector(int16 x, int16 y, const int16 *tbl, int16 nr);
+ int16 findHotspot(const Common::Rect *hotspots);
int16 getSwitchCode();
diff --git a/engines/chewy/rooms/room04.cpp b/engines/chewy/rooms/room04.cpp
index efed1e07f8c..1581dafba48 100644
--- a/engines/chewy/rooms/room04.cpp
+++ b/engines/chewy/rooms/room04.cpp
@@ -40,10 +40,11 @@ int16 Room4::comp_probe() {
{ 136, 103 },
{ 188, 101 }
};
- static const int16 CONSOLE[3][4] = {
- { 82, 158, 143, 199 },
- { 150, 159, 194, 193 },
- { 201, 154, 262, 193 }
+
+ static const Common::Rect consoleHotspots[] = {
+ { 99, 165, 160, 206 },
+ { 167, 166, 211, 200 },
+ { 218, 161, 279, 200 }
};
cur_2_inventory();
@@ -61,7 +62,7 @@ int16 Room4::comp_probe() {
while (!endLoop) {
mouseAction();
if (_G(mouseLeftClick)) {
- switch (_G(in)->mouseVector(g_events->_mousePos.x + 17, g_events->_mousePos.y + 7, &CONSOLE[0][0], 3)) {
+ switch (_G(in)->findHotspot(consoleHotspots)) {
case 0:
if (curX > 0)
--curX;
More information about the Scummvm-git-logs
mailing list