LAB: More cleanup of the keyboard handling code

This commit is contained in:
Filippos Karapetis 2015-12-24 18:25:16 +02:00
parent 9c749c7d2e
commit b2fad340b5
3 changed files with 19 additions and 47 deletions

View file

@ -59,6 +59,17 @@ static const byte mouseData[] = {
#define MOUSE_WIDTH 10 #define MOUSE_WIDTH 10
#define MOUSE_HEIGHT 15 #define MOUSE_HEIGHT 15
EventManager::EventManager(LabEngine *vm) : _vm(vm) {
_leftClick = false;
_rightClick = false;
_lastButtonHit = nullptr;
_screenButtonList = nullptr;
_hitButton = nullptr;
_mousePos = Common::Point(0, 0);
_keyPressed = Common::KEYCODE_INVALID;
}
Button *EventManager::checkButtonHit(ButtonList *buttonList, Common::Point pos) { Button *EventManager::checkButtonHit(ButtonList *buttonList, Common::Point pos) {
for (ButtonList::iterator buttonItr = buttonList->begin(); buttonItr != buttonList->end(); ++buttonItr) { for (ButtonList::iterator buttonItr = buttonList->begin(); buttonItr != buttonList->end(); ++buttonItr) {
Button *button = *buttonItr; Button *button = *buttonItr;
@ -104,23 +115,6 @@ Button *EventManager::getButton(uint16 id) {
return nullptr; return nullptr;
} }
EventManager::EventManager(LabEngine *vm) : _vm(vm) {
_leftClick = false;
_rightClick = false;
_lastButtonHit = nullptr;
_screenButtonList = nullptr;
_hitButton = nullptr;
_mousePos = Common::Point(0, 0);
_nextKeyIn = 0;
_nextKeyOut = 0;
for (int i = 0; i < 64; i++)
_keyBuf[i] = Common::KEYCODE_INVALID;
}
void EventManager::updateMouse() { void EventManager::updateMouse() {
if (!_hitButton) if (!_hitButton)
return; return;
@ -168,19 +162,6 @@ void EventManager::setMousePos(Common::Point pos) {
_vm->_system->warpMouse(pos.x * 2, pos.y); _vm->_system->warpMouse(pos.x * 2, pos.y);
} }
Common::KeyCode EventManager::keyPress() {
Common::KeyCode key = Common::KEYCODE_INVALID;
processInput();
if (_nextKeyIn != _nextKeyOut) {
key = _keyBuf[_nextKeyOut];
_nextKeyOut = (_nextKeyOut + 1) % 64;
}
return key;
}
void EventManager::processInput() { void EventManager::processInput() {
Common::Event event; Common::Event event;
Button *curButton = nullptr; Button *curButton = nullptr;
@ -220,13 +201,9 @@ void EventManager::processInput() {
continue; continue;
} }
// Intentional fall through // Intentional fall through
default: { default:
int n = (_nextKeyIn + 1) % 64; _keyPressed = event.kbd;
if (n != _nextKeyOut) { break;
_keyBuf[_nextKeyIn] = event.kbd.keycode;
_nextKeyIn = n;
}
}
} }
break; break;
case Common::EVENT_QUIT: case Common::EVENT_QUIT:

View file

@ -77,7 +77,6 @@ private:
uint16 _nextKeyIn; uint16 _nextKeyIn;
uint16 _nextKeyOut; uint16 _nextKeyOut;
Common::KeyCode _keyBuf[64];
Button *_hitButton; Button *_hitButton;
Button *_lastButtonHit; Button *_lastButtonHit;
@ -92,11 +91,6 @@ private:
*/ */
Button *checkButtonHit(ButtonList *buttonList, Common::Point pos); Button *checkButtonHit(ButtonList *buttonList, Common::Point pos);
/**
* Checks whether or not a key has been pressed.
*/
Common::KeyCode keyPress();
/** /**
* Checks whether or not the coords fall within one of the buttons in a list * Checks whether or not the coords fall within one of the buttons in a list
* of buttons. * of buttons.

View file

@ -117,8 +117,7 @@ IntuiMessage *EventManager::getMsg() {
static IntuiMessage message; static IntuiMessage message;
updateMouse(); updateMouse();
processInput();
Common::KeyCode curKey = keyPress();
if (_lastButtonHit) { if (_lastButtonHit) {
updateMouse(); updateMouse();
@ -135,8 +134,10 @@ IntuiMessage *EventManager::getMsg() {
message._mouse.x /= 2; message._mouse.x /= 2;
_leftClick = _rightClick = false; _leftClick = _rightClick = false;
return &message; return &message;
} else if (curKey != Common::KEYCODE_INVALID) { } else if (_keyPressed.keycode != Common::KEYCODE_INVALID) {
message._code = curKey; message._code = _keyPressed.keycode;
_keyPressed.keycode = Common::KEYCODE_INVALID;
Button *curButton = checkNumButtonHit(_screenButtonList, message._code); Button *curButton = checkNumButtonHit(_screenButtonList, message._code);
if (curButton) { if (curButton) {