aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner/regions.cpp
diff options
context:
space:
mode:
authorPeter Kohaut2016-09-10 18:16:17 +0200
committerEugene Sandulenko2016-09-29 22:33:40 +0200
commitb67bca20b5db7f3d6473341efd7fabfa6532f465 (patch)
tree6fbbd28dc707dac1c3cacde2e8622cceea6d1b0f /engines/bladerunner/regions.cpp
parent2888d0b3460cdca2dd52f8d6aa94b429d46345ad (diff)
downloadscummvm-rg350-b67bca20b5db7f3d6473341efd7fabfa6532f465.tar.gz
scummvm-rg350-b67bca20b5db7f3d6473341efd7fabfa6532f465.tar.bz2
scummvm-rg350-b67bca20b5db7f3d6473341efd7fabfa6532f465.zip
BLADERUNNER: Pull in changes from madmoose
Diffstat (limited to 'engines/bladerunner/regions.cpp')
-rw-r--r--engines/bladerunner/regions.cpp103
1 files changed, 70 insertions, 33 deletions
diff --git a/engines/bladerunner/regions.cpp b/engines/bladerunner/regions.cpp
index fe817e074b..f75be0ff1b 100644
--- a/engines/bladerunner/regions.cpp
+++ b/engines/bladerunner/regions.cpp
@@ -1,47 +1,84 @@
#include "bladerunner/regions.h"
namespace BladeRunner {
- Regions::Regions() {
- _enabled = true;
- _regions = new Region[10];
- }
- Regions::~Regions() {
- delete[] _regions;
- }
+Regions::Regions() {
+ _enabled = true;
+ _regions = new Region[10];
+ clear();
+}
- bool Regions::add(int index, Common::Rect rect, int type) {
- if (index <= 0 || index >= 10)
- return false;
+Regions::~Regions() {
+ delete[] _regions;
+}
- if (_regions[index]._present)
- return false;
+void BladeRunner::Regions::clear() {
+ for (int i = 0; i < 10; ++i)
+ remove(i);
+}
- _regions[index]._rectangle = rect;
- _regions[index]._type = type;
- _regions[index]._present = 1;
+bool Regions::add(int index, Common::Rect rect, int type) {
+ if (index < 0 || index >= 10)
+ return false;
- return true;
- }
+ if (_regions[index]._present)
+ return false;
- bool Regions::remove(int index) {
- if (index <= 0 || index >= 10)
- return false;
+ _regions[index]._rectangle = rect;
+ _regions[index]._type = type;
+ _regions[index]._present = 1;
- _regions[index]._rectangle = Common::Rect(-1, -1, -1, -1);
- _regions[index]._type = -1;
- _regions[index]._present = 0;
+ return true;
+}
- return true;
- }
+bool Regions::remove(int index) {
+ if (index < 0 || index >= 10)
+ return false;
- void BladeRunner::Regions::clear() {
- int i;
- for (i = 0; i < 10; i++)
- remove(i);
- }
+ _regions[index]._rectangle = Common::Rect(-1, -1, -1, -1);
+ _regions[index]._type = -1;
+ _regions[index]._present = 0;
+
+ return true;
+}
+
+int Regions::getTypeAtXY(int x, int y) {
+ int index = getRegionAtXY(x, y);
+
+ if (index == -1)
+ return -1;
- void Regions::setEnabled(bool enabled) {
- _enabled = enabled;
+ return _regions[index]._type;
+}
+
+int Regions::getRegionAtXY(int x, int y) {
+ if (!_enabled)
+ return -1;
+
+ for (int i = 0; i != 10; ++i) {
+ if (!_regions[i]._present)
+ continue;
+
+ // Common::Rect::contains is exclusive of right and bottom but
+ // Blade Runner wants inclusive, so we adjust the edges.
+ // TODO: Roll our own rect class?
+ Common::Rect r = _regions[i]._rectangle;
+ r.right++;
+ r.bottom++;
+
+ if (r.contains(x, y))
+ return i;
}
-} \ No newline at end of file
+
+ return -1;
+}
+
+void Regions::setEnabled(bool enabled) {
+ _enabled = enabled;
+}
+
+void Regions::enable() {
+ _enabled = true;
+}
+
+} // End of namespace BladeRunner