aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBorja Lorente2016-08-04 13:54:21 +0200
committerBorja Lorente2016-08-14 19:01:00 +0200
commit0aef29a8c5f364e53f6bef57fee890005bcda129 (patch)
tree8dcee982ddfa108598e16c24629ddc242509e7ee
parent5b63e29d5e2ff4710cf4d417474b607d84317dee (diff)
downloadscummvm-rg350-0aef29a8c5f364e53f6bef57fee890005bcda129.tar.gz
scummvm-rg350-0aef29a8c5f364e53f6bef57fee890005bcda129.tar.bz2
scummvm-rg350-0aef29a8c5f364e53f6bef57fee890005bcda129.zip
MACVENTURE: Revamp double click detection
-rw-r--r--engines/macventure/gui.cpp20
-rw-r--r--engines/macventure/gui.h88
2 files changed, 68 insertions, 40 deletions
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp
index 4f11478c21..327a2e8b7f 100644
--- a/engines/macventure/gui.cpp
+++ b/engines/macventure/gui.cpp
@@ -20,9 +20,7 @@
*
*/
-
#include "common/file.h"
-#include "common/timer.h"
#include "common/system.h"
#include "image/bmp.h"
@@ -92,11 +90,6 @@ static const Graphics::MenuData menuSubItems[] = {
};
-static void cursorTimerHandler(void *refCon) {
- Gui *gui = (Gui *)refCon;
- gui->processCursorTick();
-}
-
bool commandsWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui);
bool mainGameWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui);
bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui);
@@ -117,7 +110,6 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) {
_dialog = nullptr;
_cursor = new Cursor(this);
- g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 500000, this, "macVentureCursor");
_consoleText = new ConsoleText(this);
@@ -886,8 +878,7 @@ WindowReference Gui::findWindowAtPoint(Common::Point point) {
win = findWindow(it->refcon);
if (win && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered
if (win->getDimensions().contains(point)) {
- if (win->isActive())
- return it->refcon;
+ return it->refcon;
}
}
}
@@ -979,7 +970,10 @@ void Gui::checkSelect(const WindowData &data, const Common::Event &event, const
child = (*it).obj;
}
}
- if (child != 0) selectDraggable(child, ref, event.mouse, data.scrollPos);
+ if (child != 0) {
+ selectDraggable(child, ref, event.mouse, data.scrollPos);
+ bringToFront(ref);
+ }
}
bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) {
@@ -1375,10 +1369,6 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) {
return true;
}
-void Gui::processCursorTick() {
- _cursor->tick();
-}
-
void Gui::handleSingleClick(Common::Point pos) {
debug("Single Click");
// HACK THERE HAS TO BE A MORE ELEGANT WAY
diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h
index a44e394eaf..bc9ca14643 100644
--- a/engines/macventure/gui.h
+++ b/engines/macventure/gui.h
@@ -29,6 +29,8 @@
#include "graphics/font.h"
+#include "common/timer.h"
+
#include "macventure/macventure.h"
#include "macventure/container.h"
#include "macventure/image.h"
@@ -123,8 +125,6 @@ public:
bool processDiplomaEvents(WindowClick click, Common::Event &event);
bool processInventoryEvents(WindowClick click, Common::Event &event);
- void processCursorTick();
-
const WindowData& getWindowData(WindowReference reference);
const Graphics::Font& getCurrentFont();
@@ -244,32 +244,35 @@ private: // Methods
};
+static void cursorTimerHandler(void *refCon);
+
class Cursor {
enum ClickState {
kCursorIdle = 0,
- kCursorSC = 1,
- kCursorNoTick = 2,
- kCursorSCTrans = 3,
- kCursorExecSC = 4,
- kCursorExecDC = 5,
+ kCursorSCStart = 1,
+ kCursorSCDrag = 2,
+ kCursorDCStart = 3,
+ kCursorDCDo = 4,
+ kCursorSCSink = 5,
kCursorStateCount
};
enum CursorInput { // Columns for the FSM transition table
- kTickCol = 0,
- kButtonDownCol = 1,
- kButtonUpCol = 2,
+ kButtonDownCol = 0,
+ kButtonUpCol = 1,
+ kTickCol = 2,
kCursorInputCount
};
ClickState _transitionTable[kCursorStateCount][kCursorInputCount] = {
- /* kCursorIdle */ {kCursorIdle, kCursorIdle, kCursorSC },
- /* kCursorSC */ {kCursorExecSC, kCursorSCTrans, kCursorExecDC },
- /* IgnoreTick */ {kCursorNoTick, kCursorNoTick, kCursorExecSC },
- /* SC Transition */ {kCursorNoTick, kCursorNoTick, kCursorExecDC },
- /* Exec SC */ {kCursorIdle, kCursorExecSC, kCursorExecSC }, // Trap state
- /* Exec DC */ {kCursorIdle, kCursorExecDC, kCursorExecDC } // Trap state
+ /* Button down, Button Up, Tick */
+ /* Idle */ {kCursorSCStart, kCursorIdle, kCursorIdle },
+ /* SC Start */ {kCursorSCStart, kCursorDCStart, kCursorSCDrag},
+ /* SC Do */ {kCursorSCDrag, kCursorIdle, kCursorSCDrag},
+ /* DC Start */ {kCursorDCDo, kCursorDCStart, kCursorSCSink},
+ /* DC Do */ {kCursorDCDo, kCursorIdle, kCursorDCDo },
+ /* SC Sink */ {kCursorIdle, kCursorIdle, kCursorIdle },
};
public:
@@ -281,12 +284,10 @@ public:
~Cursor() {}
void tick() {
- executeState();
changeState(kTickCol);
}
bool processEvent(const Common::Event &event) {
-
if (event.type == Common::EVENT_MOUSEMOVE) {
_pos = event.mouse;
return true;
@@ -310,17 +311,49 @@ public:
private:
void changeState(CursorInput input) {
- debug(4, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]);
- _state = _transitionTable[_state][input];
+ debug(1, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]);
+ if (_state != _transitionTable[_state][input]) {
+ executeStateOut();
+ _state = _transitionTable[_state][input];
+ executeStateIn();
+ }
}
- void executeState() {
- if (_state == kCursorExecSC) {
+ void executeStateIn() {
+ switch (_state) {
+ case kCursorSCStart:
+ g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor");
+ break;
+ case kCursorDCStart:
+ g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor");
+ break;
+ case kCursorSCSink:
_gui->handleSingleClick(_pos);
changeState(kTickCol);
- } else if (_state == kCursorExecDC) {
+ break;
+ default:
+ break;
+ }
+ }
+
+ void executeStateOut() {
+ switch (_state) {
+ case kCursorIdle:
+ break;
+ case kCursorSCStart:
+ g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
+ break;
+ case kCursorSCDrag:
+ _gui->handleSingleClick(_pos);
+ break;
+ case kCursorDCStart:
+ g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
+ break;
+ case kCursorDCDo:
_gui->handleDoubleClick(_pos);
- changeState(kTickCol);
+ break;
+ default:
+ break;
}
}
@@ -330,9 +363,14 @@ private:
Common::Point _pos;
ClickState _state;
-
};
+static void cursorTimerHandler(void *refCon) {
+ Cursor *cursor = (Cursor *)refCon;
+ cursor->tick();
+}
+
+
class ConsoleText {
public: