LAB: More cleanup of the keyboard handling code
This commit is contained in:
parent
9c749c7d2e
commit
b2fad340b5
3 changed files with 19 additions and 47 deletions
|
@ -59,6 +59,17 @@ static const byte mouseData[] = {
|
|||
#define MOUSE_WIDTH 10
|
||||
#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) {
|
||||
for (ButtonList::iterator buttonItr = buttonList->begin(); buttonItr != buttonList->end(); ++buttonItr) {
|
||||
Button *button = *buttonItr;
|
||||
|
@ -104,23 +115,6 @@ Button *EventManager::getButton(uint16 id) {
|
|||
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() {
|
||||
if (!_hitButton)
|
||||
return;
|
||||
|
@ -168,19 +162,6 @@ void EventManager::setMousePos(Common::Point pos) {
|
|||
_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() {
|
||||
Common::Event event;
|
||||
Button *curButton = nullptr;
|
||||
|
@ -220,13 +201,9 @@ void EventManager::processInput() {
|
|||
continue;
|
||||
}
|
||||
// Intentional fall through
|
||||
default: {
|
||||
int n = (_nextKeyIn + 1) % 64;
|
||||
if (n != _nextKeyOut) {
|
||||
_keyBuf[_nextKeyIn] = event.kbd.keycode;
|
||||
_nextKeyIn = n;
|
||||
}
|
||||
}
|
||||
default:
|
||||
_keyPressed = event.kbd;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Common::EVENT_QUIT:
|
||||
|
|
|
@ -77,7 +77,6 @@ private:
|
|||
|
||||
uint16 _nextKeyIn;
|
||||
uint16 _nextKeyOut;
|
||||
Common::KeyCode _keyBuf[64];
|
||||
|
||||
Button *_hitButton;
|
||||
Button *_lastButtonHit;
|
||||
|
@ -92,11 +91,6 @@ private:
|
|||
*/
|
||||
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
|
||||
* of buttons.
|
||||
|
|
|
@ -117,8 +117,7 @@ IntuiMessage *EventManager::getMsg() {
|
|||
static IntuiMessage message;
|
||||
|
||||
updateMouse();
|
||||
|
||||
Common::KeyCode curKey = keyPress();
|
||||
processInput();
|
||||
|
||||
if (_lastButtonHit) {
|
||||
updateMouse();
|
||||
|
@ -135,8 +134,10 @@ IntuiMessage *EventManager::getMsg() {
|
|||
message._mouse.x /= 2;
|
||||
_leftClick = _rightClick = false;
|
||||
return &message;
|
||||
} else if (curKey != Common::KEYCODE_INVALID) {
|
||||
message._code = curKey;
|
||||
} else if (_keyPressed.keycode != Common::KEYCODE_INVALID) {
|
||||
message._code = _keyPressed.keycode;
|
||||
_keyPressed.keycode = Common::KEYCODE_INVALID;
|
||||
|
||||
Button *curButton = checkNumButtonHit(_screenButtonList, message._code);
|
||||
|
||||
if (curButton) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue