aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorrichiesams2013-08-24 00:06:20 -0500
committerrichiesams2013-08-24 00:23:41 -0500
commit3054489a8bcc9604028ac16a0b074e13bff258eb (patch)
tree779934efe18ca390fa075e8509d0ea79f6d662ed /engines
parent7095e613d59630ec03dbf8a17e18ae9b4aabf289 (diff)
downloadscummvm-rg350-3054489a8bcc9604028ac16a0b074e13bff258eb.tar.gz
scummvm-rg350-3054489a8bcc9604028ac16a0b074e13bff258eb.tar.bz2
scummvm-rg350-3054489a8bcc9604028ac16a0b074e13bff258eb.zip
ZVISION: Have PushToggleControl inherit from MouseEvent and handle the methods internally.
Rather than creating an instance of MouseEvent and passing argument around.
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/control.cpp33
-rw-r--r--engines/zvision/control.h47
-rw-r--r--engines/zvision/scr_file_handling.cpp2
3 files changed, 65 insertions, 17 deletions
diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp
index 94e0c477ab..ff767863f4 100644
--- a/engines/zvision/control.cpp
+++ b/engines/zvision/control.cpp
@@ -108,10 +108,9 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre
// PushToggleControl
//////////////////////////////////////////////////////////////////////////////
-PushToggleControl::PushToggleControl(uint32 key, Common::SeekableReadStream &stream)
- : Control() {
- _event._key = _key = key;
-
+PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream)
+ : MouseEvent(key),
+ _engine(engine) {
// Loop until we find the closing brace
Common::String line = stream.readLine();
trimCommentsAndWhiteSpace(&line);
@@ -125,27 +124,27 @@ PushToggleControl::PushToggleControl(uint32 key, Common::SeekableReadStream &str
sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height);
- _event._hotspot = Common::Rect(x, y, x + width, y + height);
+ _hotspot = Common::Rect(x, y, x + width, y + height);
} else if (line.matchString("cursor*", true)) {
char nameBuffer[25];
sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer);
- _event._hoverCursor = Common::String(nameBuffer);
+ _hoverCursor = Common::String(nameBuffer);
}
line = stream.readLine();
trimCommentsAndWhiteSpace(&line);
}
- if (_event._hotspot.isEmpty() || _event._hoverCursor.empty()) {
+ if (_hotspot.isEmpty() || _hoverCursor.empty()) {
warning("Push_toggle cursor %u was parsed incorrectly", key);
}
}
-bool PushToggleControl::enable(ZVision *engine) {
+bool PushToggleControl::enable() {
if (!_enabled) {
- engine->registerMouseEvent(_event);
+ _engine->registerMouseEvent(this);
_enabled = true;
return true;
}
@@ -154,9 +153,9 @@ bool PushToggleControl::enable(ZVision *engine) {
return false;
}
-bool PushToggleControl::disable(ZVision *engine) {
+bool PushToggleControl::disable() {
if (_enabled) {
- engine->removeMouseEvent(_key);
+ _engine->removeMouseEvent(_key);
_enabled = false;
return true;
}
@@ -165,4 +164,16 @@ bool PushToggleControl::disable(ZVision *engine) {
return false;
}
+void PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {
+ _engine->getScriptManager()->setStateValue(_key, 1);
+}
+
+bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {
+ if (_hotspot.contains(backgroundImageSpacePos)) {
+ _engine->getCursorManager()->changeCursor(_hoverCursor);
+ return true;
+ }
+
+ return false;
+}
} // End of namespace ZVision
diff --git a/engines/zvision/control.h b/engines/zvision/control.h
index 17408c79f1..28079d52e7 100644
--- a/engines/zvision/control.h
+++ b/engines/zvision/control.h
@@ -52,14 +52,51 @@ public:
static void parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream);
};
-class PushToggleControl : public Control {
+
+class PushToggleControl : public Control, public MouseEvent {
+public:
+ PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
+ bool enable();
+ bool disable();
+
+ /**
+ * Called when LeftMouse is pushed. Calls ScriptManager::setStateValue(_key, 1);
+ *
+ * @param screenSpacePos The position of the mouse in screen space
+ * @param backgroundImageSpacePos The position of the mouse in background image space
+ */
+ void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos);
+ /**
+ * Called when LeftMouse is lifted. Does nothing
+ *
+ * @param screenSpacePos The position of the mouse in screen space
+ * @param backgroundImageSpacePos The position of the mouse in background image space
+ */
+ void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {}
+ /**
+ * Called on every MouseMove. Tests if the mouse is inside _hotspot, and if so, sets the cursor.
+ *
+ * @param engine The base engine
+ * @param screenSpacePos The position of the mouse in screen space
+ * @param backgroundImageSpacePos The position of the mouse in background image space
+ * @return Was the cursor changed?
+ */
+ bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos);
+
+private:
+ ZVision * _engine;
+ /**
+ * The area that will trigger the event
+ * This is in image space coordinates, NOT screen space
+ */
+ Common::Rect _hotspot;
+ /** The cursor to use when hovering over _hotspot */
+ Common::String _hoverCursor;
+};
+
public:
- PushToggleControl(uint32 key, Common::SeekableReadStream &stream);
- bool enable(ZVision *engine);
- bool disable(ZVision *engine);
private:
- MouseEvent _event;
};
// TODO: Implement InputControl
diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp
index 7ccd939e54..921c1d5b44 100644
--- a/engines/zvision/scr_file_handling.cpp
+++ b/engines/zvision/scr_file_handling.cpp
@@ -278,7 +278,7 @@ void ScriptManager::parseControl(Common::String &line, Common::SeekableReadStrea
Common::String controlType(controlTypeBuffer);
if (controlType.equalsIgnoreCase("push_toggle")) {
- _activeControls[key] = new PushToggleControl(key, stream);
+ _activeControls[key] = new PushToggleControl(_engine, key, stream);
return;
} else if (controlType.equalsIgnoreCase("flat")) {
Control::parseFlatControl(_engine);