aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBorja Lorente2016-06-25 20:45:53 +0200
committerBorja Lorente2016-08-14 18:39:27 +0200
commit4837b7750a5494f7002f8f7c5d47ba44621dd425 (patch)
tree6bede815159a671a94d9a71dea9e30c78152e3dd
parent25f086e63b2b007ba03a47dcdab2426369edf01f (diff)
downloadscummvm-rg350-4837b7750a5494f7002f8f7c5d47ba44621dd425.tar.gz
scummvm-rg350-4837b7750a5494f7002f8f7c5d47ba44621dd425.tar.bz2
scummvm-rg350-4837b7750a5494f7002f8f7c5d47ba44621dd425.zip
MACVENTURE: Add rect collission for main game window
-rw-r--r--engines/macventure/container.h31
-rw-r--r--engines/macventure/gui.cpp39
-rw-r--r--engines/macventure/image.cpp12
-rw-r--r--engines/macventure/image.h1
4 files changed, 55 insertions, 28 deletions
diff --git a/engines/macventure/container.h b/engines/macventure/container.h
index 4dc5172fd7..440c0cb977 100644
--- a/engines/macventure/container.h
+++ b/engines/macventure/container.h
@@ -42,6 +42,8 @@ class Container {
public:
Container(const char *filename) {
+ _filename = Common::String(filename);
+
if (!_file.open(filename))
error("Could not open %s", filename);
@@ -172,9 +174,11 @@ public:
* getItemByteSize should be called before this one
*/
Common::SeekableReadStream *getItem(uint32 id) {
+ _res->seek(0);
+ Common::SeekableReadStream *res = _res->readStream(_res->size());
if (_simplified) {
- _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET);
- return _res;
+ res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET);
+ return res;
} else {
uint32 groupID = (id >> 6);
uint32 objectIndex = id & 0x3f; // Index within the group
@@ -184,9 +188,9 @@ public:
offset += _groups[groupID].lengths[i];
}
- _res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET);
+ res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET);
- return _res;
+ return res;
}
}
@@ -202,27 +206,14 @@ protected:
uint16 _huff[15]; // huffman masks
uint8 _lens[16]; // huffman lengths
Common::Array<ItemGroup> _groups;
-
+
+ Common::String _filename;
Common::File _file;
Common::SeekableReadStream *_res;
-
- // To be moved
- //byte _remainderOffset;
+
};
-/*
-template <typedef T>
-class PersistentContainer : public Container {
-public:
- PersistentContainer(Common::String filename) :
- Container(filename) {
- // Load
- }
-
-private:
-
-};*/
} // End of namespace MacVenture
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp
index e0fcc5d691..529d0444de 100644
--- a/engines/macventure/gui.cpp
+++ b/engines/macventure/gui.cpp
@@ -26,11 +26,19 @@
#include "macventure/macventure.h"
#include "macventure/gui.h"
+// TBDeleted
+#include "common/system.h"
+
namespace MacVenture {
enum MenuAction;
enum {
+ kCursorWidth = 4, // HACK Arbitrary width to test
+ kCursorHeight = 4
+};
+
+enum {
kMenuHighLevel = -1,
kMenuAbout = 0,
kMenuFile = 1,
@@ -250,7 +258,7 @@ void Gui::initWindows() {
_mainGameWindow->setActive(false);
_mainGameWindow->setCallback(mainGameWindowCallback, this);
//loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false);
- //loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true);
+ loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true);
// In-game Output Console
_outConsoleWindow = _wm.addWindow(false, true, true);
@@ -558,6 +566,17 @@ void Gui::drawMainGameWindow() {
kBlitDirect);
drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface());
+
+ // To be deleted
+ /*
+ g_system->copyRectToScreen(
+ _mainGameWindow->getSurface()->getPixels(),
+ _mainGameWindow->getSurface()->pitch,
+ 0, 0,
+ _mainGameWindow->getSurface()->w,
+ _mainGameWindow->getSurface()->h);
+ */
+ g_system->updateScreen();
}
void Gui::drawSelfWindow() {
@@ -914,15 +933,19 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e
WindowData &data = findWindowData(kMainGameWindow);
ObjID child;
Common::Point pos;
+ // Click rect to local coordinates. We assume the click is inside the window ^
+ int left = event.mouse.x - _mainGameWindow->getDimensions().left;
+ int top = event.mouse.y - _mainGameWindow->getDimensions().top;
+ Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight);
for (Common::Array<DrawableObject>::const_iterator it = data.children.begin(); it != data.children.end(); it++) {
child = (*it).obj;
- pos = _engine->getObjPosition(child);
- pos.x += _mainGameWindow->getDimensions().left;
- pos.y += _mainGameWindow->getDimensions().top;
- pos = event.mouse - pos;
- if (_assets.contains(child) && _assets[child]->isPointInside(pos)) {
- // select the first object clicked
- _engine->handleObjectSelect(child, kMainGameWindow, event);
+ Common::Rect intersection = clickRect.findIntersectingRect(_engine->getObjBounds(child));
+ intersection = Common::Rect(0, 0, intersection.width(), intersection.height());
+ if (_assets.contains(child) && _engine->isObjClickable(child)) {
+ if (_assets[child]->isRectInside(intersection)) {
+ // select the first object clicked
+ _engine->handleObjectSelect(child, kMainGameWindow, event);
+ }
}
}
}
diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp
index 323b8a1089..1a50a4ffbc 100644
--- a/engines/macventure/image.cpp
+++ b/engines/macventure/image.cpp
@@ -350,6 +350,18 @@ bool ImageAsset::isPointInside(Common::Point point) {
return pix != 0;
}
+bool ImageAsset::isRectInside(Common::Rect rect) {
+ for (uint y = rect.top; y < rect.top + rect.height(); y++) {
+ uint bmpofs = y * _rowBytes;
+ byte pix;
+ for (uint x = rect.left; x < rect.left + rect.width(); x++) {
+ pix = _maskData[bmpofs + (x >> 3)] & (1 << (7 - (x & 7)));
+ if (pix) return true;
+ }
+ }
+ return false;
+}
+
uint ImageAsset::getWidth() {
return _bitWidth;
}
diff --git a/engines/macventure/image.h b/engines/macventure/image.h
index 9538d0cbb6..5cbe146055 100644
--- a/engines/macventure/image.h
+++ b/engines/macventure/image.h
@@ -61,6 +61,7 @@ public:
void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode);
bool isPointInside(Common::Point point);
+ bool isRectInside(Common::Rect rect);
uint getWidth();
uint getHeight();