ZVISION: Change PushToggleControl to comply with new Control base class

This commit is contained in:
richiesams 2013-08-26 14:07:47 -05:00
parent 4d344cb5a8
commit 7fb024c7fc
3 changed files with 23 additions and 47 deletions

View File

@ -33,8 +33,7 @@
namespace ZVision { namespace ZVision {
PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream)
: MouseEvent(key), : Control(engine, key) {
_engine(engine) {
// Loop until we find the closing brace // Loop until we find the closing brace
Common::String line = stream.readLine(); Common::String line = stream.readLine();
trimCommentsAndWhiteSpace(&line); trimCommentsAndWhiteSpace(&line);
@ -66,39 +65,24 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab
} }
} }
bool PushToggleControl::enable() { PushToggleControl::~PushToggleControl() {
if (!_enabled) { // Clear the state value back to 0
_engine->registerMouseEvent(this); _engine->getScriptManager()->setStateValue(_key, 0);
_enabled = true; }
return true;
}
debug("Control %u is already enabled", _key); void PushToggleControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {
return false; if (_hotspot.contains(backgroundImageSpacePos)) {
}
bool PushToggleControl::disable() {
if (_enabled) {
_engine->removeMouseEvent(_key);
_enabled = false;
return true;
}
debug("Control %u is already disabled", _key);
return false;
}
void PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {
_engine->getScriptManager()->setStateValue(_key, 1); _engine->getScriptManager()->setStateValue(_key, 1);
} }
}
bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {
if (_hotspot.contains(backgroundImageSpacePos)) { if (_hotspot.contains(backgroundImageSpacePos)) {
_engine->getCursorManager()->changeCursor(_hoverCursor); _engine->getCursorManager()->changeCursor(_hoverCursor);
return true; return true;
}
return false;
} }
return false;
}
} // End of namespace ZVision } // End of namespace ZVision

View File

@ -25,32 +25,25 @@
#include "common/types.h" #include "common/types.h"
#include "common/rect.h"
#include "zvision/control.h" #include "zvision/control.h"
#include "zvision/mouse_event.h"
namespace ZVision { namespace ZVision {
class PushToggleControl : public Control, public MouseEvent { class PushToggleControl : public Control {
public: public:
PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
bool enable(); ~PushToggleControl();
bool disable();
/** /**
* Called when LeftMouse is pushed. Calls ScriptManager::setStateValue(_key, 1); * Called when LeftMouse is lifted. Calls ScriptManager::setStateValue(_key, 1);
* *
* @param screenSpacePos The position of the mouse in screen space * @param screenSpacePos The position of the mouse in screen space
* @param backgroundImageSpacePos The position of the mouse in background image space * @param backgroundImageSpacePos The position of the mouse in background image space
*/ */
void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); void onMouseUp(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. * Called on every MouseMove. Tests if the mouse is inside _hotspot, and if so, sets the cursor.
* *
@ -59,10 +52,9 @@ public:
* @param backgroundImageSpacePos The position of the mouse in background image space * @param backgroundImageSpacePos The position of the mouse in background image space
* @return Was the cursor changed? * @return Was the cursor changed?
*/ */
bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
private: private:
ZVision * _engine;
/** /**
* The area that will trigger the event * The area that will trigger the event
* This is in image space coordinates, NOT screen space * This is in image space coordinates, NOT screen space

View File

@ -279,7 +279,7 @@ void ScriptManager::parseControl(Common::String &line, Common::SeekableReadStrea
Common::String controlType(controlTypeBuffer); Common::String controlType(controlTypeBuffer);
if (controlType.equalsIgnoreCase("push_toggle")) { if (controlType.equalsIgnoreCase("push_toggle")) {
_activeControls[key] = new PushToggleControl(_engine, key, stream); _activeControls.push_back(new PushToggleControl(_engine, key, stream));
return; return;
} else if (controlType.equalsIgnoreCase("flat")) { } else if (controlType.equalsIgnoreCase("flat")) {
Control::parseFlatControl(_engine); Control::parseFlatControl(_engine);