1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef AGS_EVENTS_H
#define AGS_EVENTS_H
#include "shared/ac/keycode.h"
#include "common/array.h"
#include "common/queue.h"
#include "common/events.h"
namespace AGS {
class EventsManager {
private:
Common::Queue<Common::Event> _pendingEvents;
Common::Queue<Common::Event> _keyEvents;
Common::Array<bool> _keys;
Common::Point _mousePos;
int16 _joystickAxis[32];
bool _joystickButton[32];
byte _keyModifierFlags = 0;
bool isModifierKey(const Common::KeyCode &keycode) const;
bool isExtendedKey(const Common::KeyCode &keycode) const;
void updateKeys(const Common::Event &event, bool isDown);
public:
/**
* Converts ags key to ScummVM scancode
*/
static bool ags_key_to_scancode(AGS3::eAGSKeyCode key, Common::KeyCode(&kc)[3]);
/*
* Converts a ScummVM event to the ags keycode
*/
static AGS3::eAGSKeyCode scummvm_key_to_ags_key(const Common::Event &event, int &ags_mod, bool old_keyhandle);
public:
EventsManager();
~EventsManager();
/**
* Poll any pending events
*/
void pollEvents();
/**
* Returns true if any unprocessed keyboard events are pending
*/
bool keyEventPending() const {
return !_keyEvents.empty();
}
/**
* Returns the next pending unprocessed keyboard event
*/
Common::Event getPendingKeyEvent() {
return _keyEvents.pop();
}
/**
* Returns the bitset of currently pressed modifier keys
*/
uint getModifierFlags() const {
return _keyModifierFlags;
}
/**
* Pushes a keydown event into the keypresses queue,
* without updating the key down flag array
*/
void pushKeyboardEvent(const Common::Event &evt) {
_keyEvents.push(evt);
}
/**
* Returns the next event, if any
*/
Common::Event readEvent();
/**
* Sets the mouse position
*/
void warpMouse(const Common::Point &newPos);
/**
* Returns true if a given key is pressed
*/
bool isKeyPressed(AGS3::eAGSKeyCode key, bool poll = true);
void clearEvents() {
_pendingEvents.clear();
_keyEvents.clear();
}
/**
* Get the current mouse position
*/
Common::Point getMousePos() const {
return _mousePos;
}
/**
* Gets a joystick axis position
*/
int16 getJoystickAxis(byte axis) const {
assert(axis < 32);
return _joystickAxis[axis];
}
/**
* Gets whether a given joystick button is down
*/
bool getJoystickButton(byte button) const {
assert(button < 32);
return _joystickButton[button];
}
/**
* Gets whether a given joystick button is down once
*/
bool getJoystickButtonOnce(byte button) {
assert(button < 32);
bool result = _joystickButton[button];
_joystickButton[button] = false;
return result;
}
};
extern EventsManager *g_events;
} // namespace AGS
#endif
|