Skip to content

Commit

Permalink
ZVISION: Refactor of pushtoggle code, now full functional implementat…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
Marisa-Chan committed Feb 7, 2014
1 parent 0033740 commit cb2503a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
51 changes: 47 additions & 4 deletions engines/zvision/push_toggle_control.cpp
Expand Up @@ -35,10 +35,13 @@
namespace ZVision {

PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream)
: Control(engine, key) {
: Control(engine, key),
_countTo(2),
_event(Common::EVENT_LBUTTONUP) {
// Loop until we find the closing brace
Common::String line = stream.readLine();
trimCommentsAndWhiteSpace(&line);
line.toLowercase();

while (!stream.eos() && !line.contains('}')) {
if (line.matchString("*_hotspot*", true)) {
Expand All @@ -56,6 +59,27 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab
sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer);

_hoverCursor = Common::String(nameBuffer);
} else if (line.matchString("animation*", true)) {
// Not used
} else if (line.matchString("sound*", true)) {
// Not used
} else if (line.matchString("count_to*", true)) {
sscanf(line.c_str(), "%*[^(](%u)", &_countTo);
} else if (line.matchString("mouse_event*", true)) {
char nameBuffer[25];

sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer);

Common::String evntStr(nameBuffer);
if (evntStr.equalsIgnoreCase("up")) {
_event = Common::EVENT_LBUTTONUP;
} else if (evntStr.equalsIgnoreCase("down")) {
_event = Common::EVENT_LBUTTONDOWN;
} else if (evntStr.equalsIgnoreCase("double")) {
// Not used
}
} else if (line.matchString("venus_id*", true)) {
// Not used
}

line = stream.readLine();
Expand All @@ -68,16 +92,35 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab
}

PushToggleControl::~PushToggleControl() {
// Clear the state value back to 0
_engine->getScriptManager()->setStateValue(_key, 0);
}

bool PushToggleControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {
if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
return false;

if (_event != Common::EVENT_LBUTTONUP)
return false;

if (_hotspot.contains(backgroundImageSpacePos)) {
int32 val = _engine->getScriptManager()->getStateValue(_key);
val = (val + 1) % _countTo;
_engine->getScriptManager()->setStateValue(_key, val);
return true;
}
return false;
}

bool PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {
if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED)
return false;

if (_event != Common::EVENT_LBUTTONDOWN)
return false;

if (_hotspot.contains(backgroundImageSpacePos)) {
_engine->getScriptManager()->setStateValue(_key, 1);
int32 val = _engine->getScriptManager()->getStateValue(_key);
val = (val + 1) % _countTo;
_engine->getScriptManager()->setStateValue(_key, val);
return true;
}
return false;
Expand Down
12 changes: 12 additions & 0 deletions engines/zvision/push_toggle_control.h
Expand Up @@ -26,6 +26,7 @@
#include "zvision/control.h"

#include "common/rect.h"
#include "common/events.h"


namespace ZVision {
Expand All @@ -35,6 +36,13 @@ class PushToggleControl : public Control {
PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream);
~PushToggleControl();

/**
* Called when LeftMouse is pushed. Default is NOP.
*
* @param screenSpacePos The position of the mouse in screen space
* @param backgroundImageSpacePos The position of the mouse in background image space
*/
bool onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
/**
* Called when LeftMouse is lifted. Calls ScriptManager::setStateValue(_key, 1);
*
Expand All @@ -60,6 +68,10 @@ class PushToggleControl : public Control {
Common::Rect _hotspot;
/** The cursor to use when hovering over _hotspot */
Common::String _hoverCursor;
/** Button maximal values count */
uint _countTo;

Common::EventType _event;
};

} // End of namespace ZVision
Expand Down

0 comments on commit cb2503a

Please sign in to comment.