ZVISION: Reimplement PushToggleControl

This commit is contained in:
richiesams
2013-08-18 19:53:05 -05:00
parent d26c814d1e
commit 5eab8a8d77
2 changed files with 51 additions and 10 deletions
+39 -10
View File
@@ -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
+12
View File
@@ -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