Skip to content

Commit

Permalink
PEGASUS: Add the Tracker class
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Sep 18, 2011
1 parent 1390db1 commit 8f6e603
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
27 changes: 27 additions & 0 deletions engines/pegasus/input.cpp
Expand Up @@ -267,4 +267,31 @@ bool InputHandler::wantsCursor() {
return false;
}

Tracker *Tracker::_currentTracker = 0;

void Tracker::handleInput(const Input &input, const Hotspot *) {
if (stopTrackingInput(input))
stopTracking(input);
else if (isTracking())
continueTracking(input);
}

void Tracker::startTracking(const Input &) {
if (!isTracking()) {
_savedHandler = InputHandler::setInputHandler(this);
_currentTracker = this;
}
}

void Tracker::stopTracking(const Input &) {
if (isTracking()) {
_currentTracker = NULL;
InputHandler::setInputHandler(_savedHandler);
}
}

bool Tracker::isClickInput(const Input &input, const Hotspot *hotspot) {
return !isTracking() && InputHandler::isClickInput(input, hotspot);
}

} // End of namespace Pegasus
35 changes: 35 additions & 0 deletions engines/pegasus/input.h
Expand Up @@ -414,6 +414,41 @@ class InputHandler {
bool _allowInput;
};


/*
Tracker implements "dragging". A Tracker can receive a startTracking message,
which causes it to be the current tracker, as well as setting it up as the current
input handler. In addition, only one tracker can be tracking at a time, and no
other handler can be set up as the current handler until the track finishes. By
default, there is no next input handler for a Tracker, but this behavior can be
overridden if desired.
*/

class Tracker : public InputHandler {
public:
Tracker() : InputHandler(0) {}
virtual ~Tracker();

virtual void handleInput(const Input &, const Hotspot *);
virtual bool stopTrackingInput(const Input &) { return false; }

virtual void startTracking(const Input &);
virtual void stopTracking(const Input &);
virtual void continueTracking(const Input &) {}

bool isTracking() { return this == _currentTracker; }
bool isClickInput(const Input &, const Hotspot *);

bool releaseInputFocus() { return !isTracking(); }

protected:
static Tracker *_currentTracker;

InputHandler *_savedHandler;
};

} // End of namespace Pegasus

#endif

0 comments on commit 8f6e603

Please sign in to comment.