MACVENTURE: Fix cursor warning

This commit is contained in:
Borja Lorente 2016-08-15 20:49:02 +02:00
parent 9c0777efbf
commit 234a3b95a2
4 changed files with 154 additions and 121 deletions

View File

@ -0,0 +1,128 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "macventure/gui.h"
namespace MacVenture {
static void cursorTimerHandler(void *refCon);
static const ClickState _transitionTable[kCursorStateCount][kCursorInputCount] = {
/* 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 }
};
Cursor::Cursor(Gui *gui) {
_gui = gui;
_state = kCursorIdle;
}
Cursor::~Cursor() {}
void Cursor::tick() {
changeState(kTickCol);
}
bool Cursor::processEvent(const Common::Event &event) {
if (event.type == Common::EVENT_MOUSEMOVE) {
_pos = event.mouse;
return true;
}
if (event.type == Common::EVENT_LBUTTONDOWN) {
changeState(kButtonDownCol);
return true;
}
if (event.type == Common::EVENT_LBUTTONUP) {
changeState(kButtonUpCol);
return true;
}
return false;
}
Common::Point Cursor::getPos() {
return _pos;
}
bool Cursor::canSelectDraggable() {
return _state == kCursorSCDrag;
}
void Cursor::changeState(CursorInput input) {
debugC(3, kMVDebugGUI, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]);
if (_state != _transitionTable[_state][input]) {
executeStateOut();
_state = _transitionTable[_state][input];
executeStateIn();
}
}
void Cursor::executeStateIn() {
switch (_state) {
case kCursorSCStart:
g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor");
_gui->selectForDrag(_pos);
break;
case kCursorDCStart:
g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor");
break;
case kCursorSCSink:
_gui->handleSingleClick();
changeState(kTickCol);
break;
default:
break;
}
}
void Cursor::executeStateOut() {
switch (_state) {
case kCursorIdle:
break;
case kCursorSCStart:
g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
break;
case kCursorSCDrag:
_gui->handleSingleClick();
break;
case kCursorDCStart:
g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
break;
case kCursorDCDo:
_gui->handleDoubleClick();
break;
default:
break;
}
}
static void cursorTimerHandler(void *refCon) {
Cursor *cursor = (Cursor *)refCon;
cursor->tick();
}
} // End of namespace MacVenture

View File

@ -83,15 +83,6 @@ struct DraggedObj {
bool hasMoved;
};
enum CursorState {
// HACK, I should define a proper FSM for this
kCursorIdle,
kCursorSingleClick, // Triggered when mouse goes up
kCursorSingleClickAwait, // Triggered when we are in single click and mouse goes down
kCursorSingleClickTrap, // Trap state, for when we are in await, and the timer goes off
kCursorDoubleClick
};
class Gui {
public:
@ -251,9 +242,6 @@ private: // Methods
};
static void cursorTimerHandler(void *refCon);
class Cursor {
enum ClickState {
kCursorIdle = 0,
kCursorSCStart = 1,
@ -271,103 +259,22 @@ enum CursorInput { // Columns for the FSM transition table
kCursorInputCount
};
ClickState _transitionTable[kCursorStateCount][kCursorInputCount] = {
/* 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 },
};
class Cursor {
public:
Cursor(Gui *gui) {
_gui = gui;
_state = kCursorIdle;
}
Cursor(Gui *gui);
~Cursor();
~Cursor() {}
void tick() {
changeState(kTickCol);
}
bool processEvent(const Common::Event &event) {
if (event.type == Common::EVENT_MOUSEMOVE) {
_pos = event.mouse;
return true;
}
if (event.type == Common::EVENT_LBUTTONDOWN) {
changeState(kButtonDownCol);
return true;
}
if (event.type == Common::EVENT_LBUTTONUP) {
changeState(kButtonUpCol);
return true;
}
return false;
}
Common::Point getPos() {
return _pos;
}
bool canSelectDraggable() {
return _state == kCursorSCDrag;
}
void tick();
bool processEvent(const Common::Event &event);
Common::Point getPos();
bool canSelectDraggable();
private:
void changeState(CursorInput input) {
debugC(3, kMVDebugGUI, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]);
if (_state != _transitionTable[_state][input]) {
executeStateOut();
_state = _transitionTable[_state][input];
executeStateIn();
}
}
void executeStateIn() {
switch (_state) {
case kCursorSCStart:
g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor");
_gui->selectForDrag(_pos);
break;
case kCursorDCStart:
g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor");
break;
case kCursorSCSink:
_gui->handleSingleClick();
changeState(kTickCol);
break;
default:
break;
}
}
void executeStateOut() {
switch (_state) {
case kCursorIdle:
break;
case kCursorSCStart:
g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
break;
case kCursorSCDrag:
_gui->handleSingleClick();
break;
case kCursorDCStart:
g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
break;
case kCursorDCDo:
_gui->handleDoubleClick();
break;
default:
break;
}
}
void changeState(CursorInput input);
void executeStateIn();
void executeStateOut();
private:
@ -377,10 +284,6 @@ private:
ClickState _state;
};
static void cursorTimerHandler(void *refCon) {
Cursor *cursor = (Cursor *)refCon;
cursor->tick();
}
enum {

View File

@ -24,7 +24,7 @@
namespace MacVenture {
PPICHuff PPIC1Huff = {
static const PPICHuff PPIC1Huff = {
// Masks
{ 0x0000,0x2000,0x4000,0x5000,0x6000,0x7000,0x8000,0x9000,0xa000,
0xb000,0xc000,0xd000,0xd800,0xe000,0xe800,0xf000,0xf800 },
@ -35,7 +35,7 @@ PPICHuff PPIC1Huff = {
0x02,0x04,0x0b,0x0d,0xe }
};
PPICHuff PPIC2Huff = {
static const PPICHuff PPIC2Huff = {
// Masks
{ 0x0000,0x4000,0x8000,0xc000,0xc800,0xd000,0xd800,0xe000,0xe800,
0xf000,0xf400,0xf600,0xf800,0xfa00,0xfc00,0xfe00,0xff00 },
@ -47,18 +47,19 @@ PPICHuff PPIC2Huff = {
};
// Used to load the huffman table in PPIC3 decoding
byte loadBits[] = {
0x08, 0x0f, 0x02, 0xff, 0x00,
0x04, 0xff, 0x01,
0x07, 0x09, 0x08, 0xff, 0x03,
0x04, 0xff, 0x04,
0x0a, 0x07, 0x0a, 0x0b, 0x06, 0xff, 0x05,
0x06, 0x06, 0x0b, 0xff, 0x07,
0x03, 0xff, 0x09,
0x04, 0x03, 0x0e, 0xff, 0x0c,
0x02, 0xff, 0x0d,
0x01, 0xff, 0x0f,
0xff };
static const byte loadBits[] = {
0x08, 0x0f, 0x02, 0xff, 0x00,
0x04, 0xff, 0x01,
0x07, 0x09, 0x08, 0xff, 0x03,
0x04, 0xff, 0x04,
0x0a, 0x07, 0x0a, 0x0b, 0x06, 0xff, 0x05,
0x06, 0x06, 0x0b, 0xff, 0x07,
0x03, 0xff, 0x09,
0x04, 0x03, 0x0e, 0xff, 0x0c,
0x02, 0xff, 0x0d,
0x01, 0xff, 0x0f,
0xff
};
ImageAsset::ImageAsset(ObjID original, Container * container) {
_id = (original * 2);

View File

@ -2,6 +2,7 @@ MODULE := engines/macventure
MODULE_OBJS := \
controls.o \
cursor.o \
datafiles.o \
detection.o \
dialog.o \