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

View File

@ -25,32 +25,25 @@
#include "common/types.h"
#include "common/rect.h"
#include "zvision/control.h"
#include "zvision/mouse_event.h"
namespace ZVision {
class PushToggleControl : public Control, public MouseEvent {
class PushToggleControl : public Control {
public:
PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
bool enable();
bool disable();
~PushToggleControl();
/**
* 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 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) {}
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.
*
@ -59,10 +52,9 @@ public:
* @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);
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

View File

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