From 5eab8a8d77a070b752d5f4e02bad73c5e85dd4a6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:42:45 -0500 Subject: ZVISION: Reimplement PushToggleControl --- engines/zvision/control.cpp | 49 ++++++++++++++++++++++++++++++++++++--------- engines/zvision/control.h | 12 +++++++++++ 2 files changed, 51 insertions(+), 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index b55452c876..acc970e167 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -103,12 +103,15 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre renderTable->generateRenderTable(); } -void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream) { - engine->getScriptManager()->setStateValue(key, 0); - Common::Rect hotspot; - Common::String cursorName; - +////////////////////////////////////////////////////////////////////////////// +// PushToggleControl +////////////////////////////////////////////////////////////////////////////// + +PushToggleControl::PushToggleControl(uint32 key, Common::SeekableReadStream &stream) + : Control() { + _event._key = _key = key; + // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -121,23 +124,49 @@ void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::Seekab uint height; sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); - - hotspot = Common::Rect(x, y, x + width, y + height); + + _event._hotspot = Common::Rect(x, y, x + width, y + height); } else if (line.matchString("cursor*", true)) { char nameBuffer[25]; sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); - cursorName = Common::String(nameBuffer); + _event._hoverCursor = Common::String(nameBuffer); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } - if (!hotspot.isEmpty() && !cursorName.empty()) { - engine->registerMouseEvent(MouseEvent(key, hotspot, cursorName)); + if (_event._hotspot.isEmpty() || _event._hoverCursor.empty()) { + warning("Push_toggle cursor %u was parsed incorrectly", &key); + } +} + +bool PushToggleControl::enable(ZVision *engine) { + if (!_enabled) { + engine->registerMouseEvent(_event); + _enabled = true; + return true; + } + + debug("Control %u is already enabled", _key); + return false; +} + +bool PushToggleControl::disable(ZVision *engine) { + if (_enabled) { + engine->removeMouseEvent(_key); + _enabled = false; + return true; } + + debug("Control %u is already disabled", _key); + return false; +} + +void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream) { + } } // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index b374383a45..f17ee7750d 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -25,6 +25,8 @@ #include "common/types.h" +#include "zvision/mouse_event.h" + namespace Common { class SeekableReadStream; } @@ -54,6 +56,16 @@ public: static void parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream); }; +class PushToggleControl : public Control { +public: + PushToggleControl(uint32 key, Common::SeekableReadStream &stream); + bool enable(ZVision *engine); + bool disable(ZVision *engine); + +private: + MouseEvent _event; +}; + } // End of namespace ZVision #endif -- cgit v1.2.3