Skip to content

Commit

Permalink
LAB: Start to untangle the mess in the event code
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Dec 24, 2015
1 parent 60657f9 commit 9c749c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 61 deletions.
77 changes: 22 additions & 55 deletions engines/lab/eventman.cpp
Expand Up @@ -108,7 +108,6 @@ EventManager::EventManager(LabEngine *vm) : _vm(vm) {
_leftClick = false;
_rightClick = false;

_mouseHidden = true;
_lastButtonHit = nullptr;
_screenButtonList = nullptr;
_hitButton = nullptr;
Expand All @@ -123,28 +122,21 @@ EventManager::EventManager(LabEngine *vm) : _vm(vm) {
}

void EventManager::updateMouse() {
bool doUpdateDisplay = false;
if (!_hitButton)
return;

if (!_mouseHidden)
doUpdateDisplay = true;
mouseHide();
_hitButton->_altImage->drawImage(_hitButton->_x, _hitButton->_y);
mouseShow();

if (_hitButton) {
mouseHide();
_hitButton->_altImage->drawImage(_hitButton->_x, _hitButton->_y);
mouseShow();
for (int i = 0; i < 3; i++)
_vm->waitTOF();

for (int i = 0; i < 3; i++)
_vm->waitTOF();

mouseHide();
_hitButton->_image->drawImage(_hitButton->_x, _hitButton->_y);
mouseShow();
doUpdateDisplay = true;
_hitButton = nullptr;
}

if (doUpdateDisplay)
_vm->_graphics->screenUpdate();
mouseHide();
_hitButton->_image->drawImage(_hitButton->_x, _hitButton->_y);
mouseShow();
_hitButton = nullptr;
_vm->_graphics->screenUpdate();
}

void EventManager::initMouse() {
Expand All @@ -155,20 +147,11 @@ void EventManager::initMouse() {
}

void EventManager::mouseShow() {
if (_mouseHidden) {
processInput();
_mouseHidden = false;
}

_vm->_system->showMouse(true);
}

void EventManager::mouseHide() {
if (!_mouseHidden) {
_mouseHidden = true;

_vm->_system->showMouse(false);
}
_vm->_system->showMouse(false);
}

Common::Point EventManager::getMousePos() {
Expand All @@ -183,23 +166,19 @@ void EventManager::setMousePos(Common::Point pos) {
_vm->_system->warpMouse(pos.x, pos.y);
else
_vm->_system->warpMouse(pos.x * 2, pos.y);

if (!_mouseHidden)
processInput();
}

bool EventManager::keyPress(Common::KeyCode *keyCode) {
if (haveNextChar()) {
*keyCode = getNextChar();
return true;
}

return false;
}
Common::KeyCode EventManager::keyPress() {
Common::KeyCode key = Common::KEYCODE_INVALID;

bool EventManager::haveNextChar() {
processInput();
return _nextKeyIn != _nextKeyOut;

if (_nextKeyIn != _nextKeyOut) {
key = _keyBuf[_nextKeyOut];
_nextKeyOut = (_nextKeyOut + 1) % 64;
}

return key;
}

void EventManager::processInput() {
Expand Down Expand Up @@ -262,18 +241,6 @@ void EventManager::processInput() {
_vm->_system->updateScreen();
}

Common::KeyCode EventManager::getNextChar() {
Common::KeyCode chr = Common::KEYCODE_INVALID;

processInput();
if (_nextKeyIn != _nextKeyOut) {
chr = _keyBuf[_nextKeyOut];
_nextKeyOut = (_nextKeyOut + 1) % 64;
}

return chr;
}

Common::Point EventManager::updateAndGetMousePos() {
processInput();

Expand Down
5 changes: 1 addition & 4 deletions engines/lab/eventman.h
Expand Up @@ -74,7 +74,6 @@ class EventManager {

bool _leftClick;
bool _rightClick;
bool _mouseHidden;

uint16 _nextKeyIn;
uint16 _nextKeyOut;
Expand All @@ -96,9 +95,7 @@ class EventManager {
/**
* Checks whether or not a key has been pressed.
*/
bool keyPress(Common::KeyCode *keyCode);
bool haveNextChar();
Common::KeyCode getNextChar();
Common::KeyCode keyPress();

/**
* Checks whether or not the coords fall within one of the buttons in a list
Expand Down
4 changes: 2 additions & 2 deletions engines/lab/interface.cpp
Expand Up @@ -118,7 +118,7 @@ IntuiMessage *EventManager::getMsg() {

updateMouse();

Common::KeyCode curKey;
Common::KeyCode curKey = keyPress();

if (_lastButtonHit) {
updateMouse();
Expand All @@ -135,7 +135,7 @@ IntuiMessage *EventManager::getMsg() {
message._mouse.x /= 2;
_leftClick = _rightClick = false;
return &message;
} else if (keyPress(&curKey)) {
} else if (curKey != Common::KEYCODE_INVALID) {
message._code = curKey;
Button *curButton = checkNumButtonHit(_screenButtonList, message._code);

Expand Down

0 comments on commit 9c749c7

Please sign in to comment.