aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/lab/engine.cpp4
-rw-r--r--engines/lab/interface.cpp16
-rw-r--r--engines/lab/lab.cpp6
-rw-r--r--engines/lab/lab.h17
-rw-r--r--engines/lab/mouse.cpp157
-rw-r--r--engines/lab/mouse.h11
-rw-r--r--engines/lab/music.cpp3
-rw-r--r--engines/lab/vga.cpp112
8 files changed, 162 insertions, 164 deletions
diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp
index b8845412aa..70ab45dc3e 100644
--- a/engines/lab/engine.cpp
+++ b/engines/lab/engine.cpp
@@ -640,7 +640,7 @@ void LabEngine::mainGameLoop() {
/* Set up initial picture. */
while (1) {
- processInput(true);
+ _event->processInput(true);
if (GotMessage) {
if (QuitLab || g_engine->shouldQuit()) {
@@ -729,7 +729,7 @@ void LabEngine::mainGameLoop() {
GotMessage = true;
mayShowCrumbIndicator();
screenUpdate();
- if (!from_crumbs(GADGETUP, code, 0, getMousePos(), curInv, curMsg, forceDraw, code, actionMode))
+ if (!from_crumbs(GADGETUP, code, 0, _event->updateAndGetMousePos(), curInv, curMsg, forceDraw, code, actionMode))
break;
}
}
diff --git a/engines/lab/interface.cpp b/engines/lab/interface.cpp
index 21b5764cc2..dff74be5e0 100644
--- a/engines/lab/interface.cpp
+++ b/engines/lab/interface.cpp
@@ -149,20 +149,6 @@ Gadget *LabEngine::checkNumGadgetHit(Gadget *gadlist, uint16 key) {
return NULL;
}
-
-
-/*****************************************************************************/
-/* Checks whether or not a key has been pressed. */
-/*****************************************************************************/
-static bool keyPress(uint16 *KeyCode) {
- if (g_lab->haveNextChar()) {
- *KeyCode = g_lab->getNextChar();
- return true;
- }
-
- return false;
-}
-
IntuiMessage IMessage;
IntuiMessage *LabEngine::getMsg() {
@@ -188,7 +174,7 @@ IntuiMessage *LabEngine::getMsg() {
IMessage.qualifier = IEQUALIFIER_RBUTTON | Qualifiers;
IMessage.msgClass = MOUSEBUTTONS;
return &IMessage;
- } else if (keyPress(&IMessage.code)) { /* Keyboard key */
+ } else if (_event->keyPress(&IMessage.code)) { /* Keyboard key */
curgad = checkNumGadgetHit(_event->_screenGadgetList, IMessage.code);
if (curgad) {
diff --git a/engines/lab/lab.cpp b/engines/lab/lab.cpp
index a6fe4cf32c..22ab50392d 100644
--- a/engines/lab/lab.cpp
+++ b/engines/lab/lab.cpp
@@ -66,12 +66,6 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
_lastWaitTOFTicks = 0;
- _mousePos = Common::Point(0, 0);
- _mouseAtEdge = false;
-
- _nextKeyIn = 0;
- _nextKeyOut = 0;
-
_isHiRes = false;
_roomNum = -1;
for (int i = 0; i < MAX_CRUMBS; i++) {
diff --git a/engines/lab/lab.h b/engines/lab/lab.h
index b7cf6e1771..348ce11eca 100644
--- a/engines/lab/lab.h
+++ b/engines/lab/lab.h
@@ -102,7 +102,6 @@ public:
int _roomNum;
byte *_currentDisplayBuffer;
- Common::Point _mousePos;
CrumbData _breadCrumbs[MAX_CRUMBS];
uint16 _numCrumbs;
@@ -114,17 +113,10 @@ public:
bool _isCrumbWaiting;
byte *_tempScrollData;
bool _isHiRes;
-
-private:
byte *_displayBuffer;
+private:
int _lastWaitTOFTicks;
-
- uint16 _nextKeyIn;
- uint16 _keyBuf[64];
- uint16 _nextKeyOut;
- bool _mouseAtEdge;
-
bool _lastMessageLong;
bool _lastTooLong;
@@ -146,9 +138,6 @@ public:
void setPalette(void *cmap, uint16 numcolors);
void drawHLine(uint16 x, uint16 y1, uint16 y2);
void drawVLine(uint16 x1, uint16 y, uint16 x2);
- bool haveNextChar();
- uint16 getNextChar();
- void processInput(bool can_delay = false);
void writeColorReg(byte *buf, uint16 regnum);
void writeColorRegsSmooth(byte *buf, uint16 first, uint16 numreg);
@@ -180,13 +169,13 @@ public:
void drawDirection(CloseDataPtr LCPtr);
int followCrumbs();
+ void changeVolume(int delta);
+
private:
void quickWaitTOF();
/*---------- Drawing Routines ----------*/
- Common::Point getMousePos();
- void changeVolume(int delta);
void applyPalette(byte *buf, uint16 first, uint16 numreg, uint16 slow);
// engine.cpp
diff --git a/engines/lab/mouse.cpp b/engines/lab/mouse.cpp
index 879bd08b68..38b893511d 100644
--- a/engines/lab/mouse.cpp
+++ b/engines/lab/mouse.cpp
@@ -54,8 +54,6 @@ static byte MouseData[] = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
#define MOUSE_WIDTH 10
#define MOUSE_HEIGHT 15
-static Gadget *hitgad = NULL;
-
/*****************************************************************************/
/* Checks whether or not the cords fall within one of the gadgets in a list */
/* of gadgets. */
@@ -67,7 +65,7 @@ Gadget *EventManager::checkGadgetHit(Gadget *gadgetList, Common::Point pos) {
(pos.y <= (gadgetList->y + gadgetList->Im->Height)) &&
!(GADGETOFF & gadgetList->GadgetFlags)) {
if (_vm->_isHiRes) {
- hitgad = gadgetList;
+ _hitGadget = gadgetList;
} else {
mouseHide();
gadgetList->ImAlt->drawImage(gadgetList->x, gadgetList->y);
@@ -107,6 +105,15 @@ EventManager::EventManager(LabEngine *vm) : _vm(vm) {
_numHidden = 1;
_lastGadgetHit = nullptr;
_screenGadgetList = nullptr;
+ _hitGadget = nullptr;
+ _nextKeyIn = 0;
+ _nextKeyOut = 0;
+ _mousePos = Common::Point(0, 0);
+ _mouseAtEdge = false;
+
+ for (int i = 0; i < 64; i++)
+ _keyBuf[i] = 0;
+
}
void EventManager::mouseHandler(int flag, Common::Point pos) {
@@ -134,19 +141,19 @@ void EventManager::updateMouse() {
if (!_mouseHidden)
doUpdateDisplay = true;
- if (hitgad) {
+ if (_hitGadget) {
mouseHide();
- hitgad->ImAlt->drawImage(hitgad->x, hitgad->y);
+ _hitGadget->ImAlt->drawImage(_hitGadget->x, _hitGadget->y);
mouseShow();
for (uint16 i = 0; i < 3; i++)
_vm->waitTOF();
mouseHide();
- hitgad->Im->drawImage(hitgad->x, hitgad->y);
+ _hitGadget->Im->drawImage(_hitGadget->x, _hitGadget->y);
mouseShow();
doUpdateDisplay = true;
- hitgad = NULL;
+ _hitGadget = nullptr;
}
if (doUpdateDisplay)
@@ -173,7 +180,7 @@ void EventManager::mouseShow() {
_numHidden--;
if ((_numHidden == 0) && _mouseHidden) {
- _vm->processInput();
+ processInput();
_mouseHidden = false;
}
@@ -199,9 +206,9 @@ void EventManager::mouseHide() {
/*****************************************************************************/
Common::Point EventManager::getMousePos() {
if (_vm->_isHiRes)
- return _vm->_mousePos;
+ return _mousePos;
else
- return Common::Point(_vm->_mousePos.x / 2, _vm->_mousePos.y);
+ return Common::Point(_mousePos.x / 2, _mousePos.y);
}
@@ -215,7 +222,7 @@ void EventManager::setMousePos(Common::Point pos) {
g_system->warpMouse(pos.x * 2, pos.y);
if (!_mouseHidden)
- _vm->processInput();
+ processInput();
}
@@ -227,15 +234,15 @@ void EventManager::setMousePos(Common::Point pos) {
bool EventManager::mouseButton(uint16 *x, uint16 *y, bool leftbutton) {
if (leftbutton) {
if (_leftClick) {
- *x = (!_vm->_isHiRes) ? (uint16)_vm->_mousePos.x / 2 : (uint16)_vm->_mousePos.x;
- *y = (uint16)_vm->_mousePos.y;
+ *x = (!_vm->_isHiRes) ? (uint16)_mousePos.x / 2 : (uint16)_mousePos.x;
+ *y = (uint16)_mousePos.y;
_leftClick = false;
return true;
}
} else {
if (_rightClick) {
- *x = (!_vm->_isHiRes) ? (uint16)_vm->_mousePos.x / 2 : (uint16)_vm->_mousePos.x;
- *y = (uint16)_vm->_mousePos.y;
+ *x = (!_vm->_isHiRes) ? (uint16)_mousePos.x / 2 : (uint16)_mousePos.x;
+ *y = (uint16)_mousePos.y;
_rightClick = false;
return true;
}
@@ -251,4 +258,124 @@ Gadget *EventManager::mouseGadget() {
return temp;
}
+/*****************************************************************************/
+/* Checks whether or not a key has been pressed. */
+/*****************************************************************************/
+bool EventManager::keyPress(uint16 *keyCode) {
+ if (haveNextChar()) {
+ *keyCode = getNextChar();
+ return true;
+ }
+
+ return false;
+}
+
+bool EventManager::haveNextChar() {
+ processInput();
+ return _nextKeyIn != _nextKeyOut;
+}
+
+void EventManager::processInput(bool can_delay) {
+ Common::Event event;
+
+ if (1 /*!g_IgnoreProcessInput*/) {
+ int flags = 0;
+ while (g_system->getEventManager()->pollEvent(event)) {
+ switch (event.type) {
+ case Common::EVENT_RBUTTONDOWN:
+ flags |= 8;
+ mouseHandler(flags, _mousePos);
+ break;
+
+ case Common::EVENT_LBUTTONDOWN:
+ flags |= 2;
+ mouseHandler(flags, _mousePos);
+ break;
+
+ case Common::EVENT_MOUSEMOVE: {
+ int lastMouseAtEdge = _mouseAtEdge;
+ _mouseAtEdge = false;
+ _mousePos.x = event.mouse.x;
+ if (event.mouse.x <= 0) {
+ _mousePos.x = 0;
+ _mouseAtEdge = true;
+ }
+ if (_mousePos.x > _vm->_screenWidth - 1) {
+ _mousePos.x = _vm->_screenWidth;
+ _mouseAtEdge = true;
+ }
+
+ _mousePos.y = event.mouse.y;
+ if (event.mouse.y <= 0) {
+ _mousePos.y = 0;
+ _mouseAtEdge = true;
+ }
+ if (_mousePos.y > _vm->_screenHeight - 1) {
+ _mousePos.y = _vm->_screenHeight;
+ _mouseAtEdge = true;
+ }
+
+ if (!lastMouseAtEdge || !_mouseAtEdge)
+ mouseHandler(1, _mousePos);
+ }
+ break;
+
+ case Common::EVENT_KEYDOWN:
+ switch (event.kbd.keycode) {
+ case Common::KEYCODE_LEFTBRACKET:
+ _vm->changeVolume(-1);
+ break;
+
+ case Common::KEYCODE_RIGHTBRACKET:
+ _vm->changeVolume(1);
+ break;
+
+ case Common::KEYCODE_z:
+ //saveSettings();
+ break;
+
+ default: {
+ int n = ((((unsigned int)((_nextKeyIn + 1) >> 31) >> 26) + (byte)_nextKeyIn + 1) & 0x3F)
+ - ((unsigned int)((_nextKeyIn + 1) >> 31) >> 26);
+ if (n != _nextKeyOut) {
+ _keyBuf[_nextKeyIn] = event.kbd.keycode;
+ _nextKeyIn = n;
+ }
+ }
+ }
+ break;
+
+ case Common::EVENT_QUIT:
+ case Common::EVENT_RTL:
+ default:
+ break;
+ }
+
+ g_system->copyRectToScreen(_vm->_displayBuffer, _vm->_screenWidth, 0, 0, _vm->_screenWidth, _vm->_screenHeight);
+ g_system->updateScreen();
+ }
+ }
+
+ if (can_delay)
+ g_system->delayMillis(10);
+}
+
+uint16 EventManager::getNextChar() {
+ uint16 c = 0;
+
+ processInput();
+ if (_nextKeyIn != _nextKeyOut) {
+ c = _keyBuf[_nextKeyOut];
+ _nextKeyOut = ((((unsigned int)((_nextKeyOut + 1) >> 31) >> 26) + (byte)_nextKeyOut + 1) & 0x3F)
+ - ((unsigned int)((_nextKeyOut + 1) >> 31) >> 26);
+ }
+
+ return c;
+}
+
+Common::Point EventManager::updateAndGetMousePos() {
+ processInput();
+
+ return _mousePos;
+}
} // End of namespace Lab
diff --git a/engines/lab/mouse.h b/engines/lab/mouse.h
index 0ff7d605f0..b3b3e30da3 100644
--- a/engines/lab/mouse.h
+++ b/engines/lab/mouse.h
@@ -48,11 +48,17 @@ private:
bool _mouseHidden;
int32 _numHidden;
Gadget *_lastGadgetHit;
+ uint16 _nextKeyIn;
+ uint16 _nextKeyOut;
+ Common::Point _mousePos;
+ bool _mouseAtEdge;
+ uint16 _keyBuf[64];
public:
EventManager (LabEngine *vm);
Gadget *_screenGadgetList;
+ Gadget *_hitGadget;
Gadget *checkGadgetHit(Gadget *gadgetList, Common::Point pos);
void initMouse();
@@ -65,6 +71,11 @@ public:
Gadget *mouseGadget();
void attachGadgetList(Gadget *gadgetList);
void mouseHandler(int flag, Common::Point pos);
+ bool keyPress(uint16 *keyCode);
+ bool haveNextChar();
+ void processInput(bool can_delay = false);
+ uint16 getNextChar();
+ Common::Point updateAndGetMousePos();
};
} // End of namespace Lab
diff --git a/engines/lab/music.cpp b/engines/lab/music.cpp
index 8d51320057..7f8df15c35 100644
--- a/engines/lab/music.cpp
+++ b/engines/lab/music.cpp
@@ -68,8 +68,7 @@ Music::Music(LabEngine *vm) : _vm(vm) {
/* it from the Audio device. */
/*****************************************************************************/
void Music::updateMusic() {
- _vm->processInput();
-
+ _vm->_event->processInput();
_vm->_event->updateMouse();
if (_musicOn && getPlayingBufferCount() < MAXBUFFERS) {
diff --git a/engines/lab/vga.cpp b/engines/lab/vga.cpp
index 4c8169eb6d..3525e779b2 100644
--- a/engines/lab/vga.cpp
+++ b/engines/lab/vga.cpp
@@ -62,120 +62,12 @@ void LabEngine::changeVolume(int delta) {
warning("STUB: changeVolume()");
}
-uint16 LabEngine::getNextChar() {
- uint16 c = 0;
-
- processInput();
- if (_nextKeyIn != _nextKeyOut) {
- c = _keyBuf[_nextKeyOut];
- _nextKeyOut = ((((unsigned int)((_nextKeyOut + 1) >> 31) >> 26) + (byte)_nextKeyOut + 1) & 0x3F)
- - ((unsigned int)((_nextKeyOut + 1) >> 31) >> 26);
- }
-
- return c;
-}
-
-bool LabEngine::haveNextChar() {
- processInput();
- return _nextKeyIn != _nextKeyOut;
-}
-
-void LabEngine::processInput(bool can_delay) {
- Common::Event event;
-
- if (1 /*!g_IgnoreProcessInput*/) {
- int flags = 0;
- while (g_system->getEventManager()->pollEvent(event)) {
- switch (event.type) {
- case Common::EVENT_RBUTTONDOWN:
- flags |= 8;
- _event->mouseHandler(flags, _mousePos);
- break;
-
- case Common::EVENT_LBUTTONDOWN:
- flags |= 2;
- _event->mouseHandler(flags, _mousePos);
- break;
-
- case Common::EVENT_MOUSEMOVE: {
- int lastMouseAtEdge = _mouseAtEdge;
- _mouseAtEdge = false;
- _mousePos.x = event.mouse.x;
- if (event.mouse.x <= 0) {
- _mousePos.x = 0;
- _mouseAtEdge = true;
- }
- if (_mousePos.x > _screenWidth - 1) {
- _mousePos.x = _screenWidth;
- _mouseAtEdge = true;
- }
-
- _mousePos.y = event.mouse.y;
- if (event.mouse.y <= 0) {
- _mousePos.y = 0;
- _mouseAtEdge = true;
- }
- if (_mousePos.y > _screenHeight - 1) {
- _mousePos.y = _screenHeight;
- _mouseAtEdge = true;
- }
-
- if (!lastMouseAtEdge || !_mouseAtEdge)
- _event->mouseHandler(1, _mousePos);
- }
- break;
-
- case Common::EVENT_KEYDOWN:
- switch (event.kbd.keycode) {
- case Common::KEYCODE_LEFTBRACKET:
- changeVolume(-1);
- break;
-
- case Common::KEYCODE_RIGHTBRACKET:
- changeVolume(1);
- break;
-
- case Common::KEYCODE_z:
- //saveSettings();
- break;
-
- default: {
- int n = ((((unsigned int)((_nextKeyIn + 1) >> 31) >> 26) + (byte)_nextKeyIn + 1) & 0x3F)
- - ((unsigned int)((_nextKeyIn + 1) >> 31) >> 26);
- if (n != _nextKeyOut) {
- _keyBuf[_nextKeyIn] = event.kbd.keycode;
- _nextKeyIn = n;
- }
- }
- }
- break;
-
- case Common::EVENT_QUIT:
- case Common::EVENT_RTL:
- default:
- break;
- }
-
- g_system->copyRectToScreen(_displayBuffer, _screenWidth, 0, 0, _screenWidth, _screenHeight);
- g_system->updateScreen();
- }
- }
-
- if (can_delay)
- g_system->delayMillis(10);
-}
-
-Common::Point LabEngine::getMousePos() {
- processInput();
-
- return _mousePos;
-}
void LabEngine::waitTOF() {
g_system->copyRectToScreen(_displayBuffer, _screenWidth, 0, 0, _screenWidth, _screenHeight);
g_system->updateScreen();
- processInput();
+ _event->processInput();
uint32 now;
@@ -237,7 +129,7 @@ void LabEngine::screenUpdate() {
g_system->copyRectToScreen(_displayBuffer, _screenWidth, 0, 0, _screenWidth, _screenHeight);
g_system->updateScreen();
- processInput();
+ _event->processInput();
}
/*****************************************************************************/