25 #ifndef PEGASUS_INPUT_H 26 #define PEGASUS_INPUT_H 28 #include "common/events.h" 29 #include "common/rect.h" 30 #include "common/singleton.h" 32 #include "pegasus/constants.h" 33 #include "pegasus/types.h" 46 kPegasusActionInteract,
47 kPegasusActionShowInventory,
48 kPegasusActionShowBiochip,
49 kPegasusActionToggleCenterDisplay,
50 kPegasusActionShowInfoScreen,
51 kPegasusActionShowPauseMenu,
52 kPegasusActionSaveGameState,
53 kPegasusActionLoadGameState,
54 kPegasusActionEnableEasterEgg,
55 kPegasusActionToggleChattyAI,
67 void getInput(
Input &,
const InputBits);
69 void waitInput(
const InputBits);
77 bool _keysDown[kPegasusActionCount];
78 InputBits _lastRawBits;
87 kButtonDownMask = 1 << kButtonDownBit,
88 kAutoButtonMask = 1 << kAutoButtonBit,
90 kButtonStateBits = kButtonDownMask | kAutoButtonMask,
93 kRawButtonDown = kButtonDownMask | kAutoButtonMask,
96 kButtonDown = kButtonDownMask,
97 kButtonAutoUp = kAutoButtonMask,
98 kButtonAutoDown = kButtonDownMask | kAutoButtonMask
106 kLeftFireButtonNum = 4,
107 kRightFireButtonNum = 5,
118 kUpButtonShift = kUpButtonNum * kBitsPerButton,
119 kLeftButtonShift = kLeftButtonNum * kBitsPerButton,
120 kDownButtonShift = kDownButtonNum * kBitsPerButton,
121 kRightButtonShift = kRightButtonNum * kBitsPerButton,
122 kLeftFireButtonShift = kLeftFireButtonNum * kBitsPerButton,
123 kRightFireButtonShift = kRightFireButtonNum * kBitsPerButton,
124 kOneButtonShift = kOneButtonNum * kBitsPerButton,
125 kTwoButtonShift = kTwoButtonNum * kBitsPerButton,
126 kThreeButtonShift = kThreeButtonNum * kBitsPerButton,
127 kFourButtonShift = kFourButtonNum * kBitsPerButton,
128 kMod1ButtonShift = kMod1ButtonNum * kBitsPerButton,
129 kMod2ButtonShift = kMod2ButtonNum * kBitsPerButton,
130 kMod3ButtonShift = kMod3ButtonNum * kBitsPerButton
134 kAllUpBits = (kButtonUp << kUpButtonShift) |
135 (kButtonUp << kLeftButtonShift) |
136 (kButtonUp << kDownButtonShift) |
137 (kButtonUp << kRightButtonShift) |
138 (kButtonUp << kLeftFireButtonShift) |
139 (kButtonUp << kRightFireButtonShift) |
140 (kButtonUp << kOneButtonShift) |
141 (kButtonUp << kTwoButtonShift) |
142 (kButtonUp << kThreeButtonShift) |
143 (kButtonUp << kFourButtonShift) |
144 (kButtonUp << kMod1ButtonShift) |
145 (kButtonUp << kMod2ButtonShift) |
146 (kButtonUp << kMod3ButtonShift),
147 kDirectionBits = (kButtonDownMask << kUpButtonShift) |
148 (kButtonDownMask << kLeftButtonShift) |
149 (kButtonDownMask << kDownButtonShift) |
150 (kButtonDownMask << kRightButtonShift),
151 kButtonBits = (kButtonDownMask << kLeftFireButtonShift) |
152 (kButtonDownMask << kRightFireButtonShift) |
153 (kButtonDownMask << kOneButtonShift) |
154 (kButtonDownMask << kTwoButtonShift) |
155 (kButtonDownMask << kThreeButtonShift) |
156 (kButtonDownMask << kFourButtonShift) |
157 (kButtonDownMask << kMod1ButtonShift) |
158 (kButtonDownMask << kMod2ButtonShift) |
159 (kButtonDownMask << kMod3ButtonShift),
160 kAllButtonDownBits = kDirectionBits | kButtonBits,
161 kAllAutoBits = (kAutoButtonMask << kUpButtonShift) |
162 (kAutoButtonMask << kLeftButtonShift) |
163 (kAutoButtonMask << kDownButtonShift) |
164 (kAutoButtonMask << kRightButtonShift) |
165 (kAutoButtonMask << kLeftFireButtonShift) |
166 (kAutoButtonMask << kRightFireButtonShift) |
167 (kAutoButtonMask << kOneButtonShift) |
168 (kAutoButtonMask << kTwoButtonShift) |
169 (kAutoButtonMask << kThreeButtonShift) |
170 (kAutoButtonMask << kFourButtonShift) |
171 (kAutoButtonMask << kMod1ButtonShift) |
172 (kAutoButtonMask << kMod2ButtonShift) |
173 (kAutoButtonMask << kMod3ButtonShift),
175 kFilterUpButton = kButtonDownMask << kUpButtonShift,
176 kFilterUpAuto = kAutoButtonMask << kUpButtonShift,
177 kFilterUpButtonAny = kFilterUpButton | kFilterUpAuto,
178 kFilterLeftButton = kButtonDownMask << kLeftButtonShift,
179 kFilterLeftAuto = kAutoButtonMask << kLeftButtonShift,
180 kFilterLeftButtonAny = kFilterLeftButton | kFilterLeftAuto,
181 kFilterDownButton = kButtonDownMask << kDownButtonShift,
182 kFilterDownAuto = kAutoButtonMask << kDownButtonShift,
183 kFilterDownButtonAny = kFilterDownButton | kFilterDownAuto,
184 kFilterRightButton = kButtonDownMask << kRightButtonShift,
185 kFilterRightAuto = kAutoButtonMask << kRightButtonShift,
186 kFilterRightButtonAny = kFilterRightButton | kFilterRightAuto,
187 kFilterLeftFireButton = kButtonDownMask << kLeftFireButtonShift,
188 kFilterLeftFireAuto = kAutoButtonMask << kLeftFireButtonShift,
189 kFilterLeftFireButtonAny = kFilterLeftFireButton | kFilterLeftFireAuto,
190 kFilterRightFireButton = kButtonDownMask << kRightFireButtonShift,
191 kFilterRightFireAuto = kAutoButtonMask << kRightFireButtonShift,
192 kFilterRightFireButtonAny = kFilterRightFireButton | kFilterRightFireAuto,
193 kFilterOneButton = kButtonDownMask << kOneButtonShift,
194 kFilterOneAuto = kAutoButtonMask << kOneButtonShift,
195 kFilterOneButtonAny = kFilterOneButton | kFilterOneAuto,
196 kFilterTwoButton = kButtonDownMask << kTwoButtonShift,
197 kFilterTwoAuto = kAutoButtonMask << kTwoButtonShift,
198 kFilterTwoButtonAny = kFilterTwoButton | kFilterTwoAuto,
199 kFilterThreeButton = kButtonDownMask << kThreeButtonShift,
200 kFilterThreeAuto = kAutoButtonMask << kThreeButtonShift,
201 kFilterThreeButtonAny = kFilterThreeButton | kFilterThreeAuto,
202 kFilterFourButton = kButtonDownMask << kFourButtonShift,
203 kFilterFourAuto = kAutoButtonMask << kFourButtonShift,
204 kFilterFourButtonAny = kFilterFourButton | kFilterFourAuto,
205 kFilterMod1Button = kButtonDownMask << kMod1ButtonShift,
206 kFilterMod1Auto = kAutoButtonMask << kMod1ButtonShift,
207 kFilterMod1ButtonAny = kFilterMod1Button | kFilterMod1Auto,
208 kFilterMod2Button = kButtonDownMask << kMod2ButtonShift,
209 kFilterMod2Auto = kAutoButtonMask << kMod2ButtonShift,
210 kFilterMod2ButtonAny = kFilterMod2Button | kFilterMod2Auto,
211 kFilterMod3Button = kButtonDownMask << kMod3ButtonShift,
212 kFilterMod3Auto = kAutoButtonMask << kMod3ButtonShift,
213 kFilterMod3ButtonAny = kFilterMod3Button | kFilterMod3Auto,
216 kFilterAllInput = kFilterUpButton |
224 kFilterLeftFireButton |
225 kFilterLeftFireAuto |
226 kFilterRightFireButton |
227 kFilterRightFireAuto |
243 kFilterAllDirections = kFilterUpButton |
252 kFilterButtons = kFilterOneButton |
261 kFilterFireButtons = kFilterLeftFireButton |
262 kFilterLeftFireAuto |
263 kFilterRightFireButton |
264 kFilterRightFireAuto,
266 kFilterAllButtons = kFilterLeftFireButton |
267 kFilterLeftFireAuto |
268 kFilterRightFireButton |
269 kFilterRightFireAuto |
285 kFilterAllInputNoAuto = kFilterUpButton |
289 kFilterLeftFireButton |
290 kFilterRightFireButton |
300 static const InputBits kHintInterruption = kFilterAllInputNoAuto;
301 static const InputBits kWarningInterruption = kFilterAllInputNoAuto;
302 static const InputBits kOpticalInterruption = kFilterAllInputNoAuto;
323 friend int operator==(
const Input &,
const Input &);
324 friend int operator!=(
const Input &,
const Input &);
328 Input() { clearInput(); }
330 bool upButtonDown()
const {
return (_inputState & (kButtonStateBits << kUpButtonShift)) == (kButtonDown << kUpButtonShift); }
331 bool upButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kUpButtonShift)) == (kButtonAutoDown << kUpButtonShift); }
332 bool upButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kUpButtonShift)) != 0; }
334 bool leftButtonDown()
const {
return (_inputState & (kButtonStateBits << kLeftButtonShift)) == (kButtonDown << kLeftButtonShift); }
335 bool leftButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kLeftButtonShift)) == (kButtonAutoDown << kLeftButtonShift); }
336 bool leftButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kLeftButtonShift)) != 0; }
338 bool downButtonDown()
const {
return (_inputState & (kButtonStateBits << kDownButtonShift)) == (kButtonDown << kDownButtonShift); }
339 bool downButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kDownButtonShift)) == (kButtonAutoDown << kDownButtonShift); }
340 bool downButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kDownButtonShift)) != 0; }
342 bool rightButtonDown()
const {
return (_inputState & (kButtonStateBits << kRightButtonShift)) == (kButtonDown << kRightButtonShift); }
343 bool rightButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kRightButtonShift)) == (kButtonAutoDown << kRightButtonShift); }
344 bool rightButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kRightButtonShift)) != 0; }
346 bool leftFireButtonDown()
const {
return (_inputState & (kButtonStateBits << kLeftFireButtonShift)) == (kButtonDown << kLeftFireButtonShift); }
347 bool leftFireButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kLeftFireButtonShift)) == (kButtonAutoDown << kLeftFireButtonShift); }
348 bool leftFireButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kLeftFireButtonShift)) != 0; }
350 bool rightFireButtonDown()
const {
return (_inputState & (kButtonStateBits << kRightFireButtonShift)) == (kButtonDown << kRightFireButtonShift); }
351 bool rightFireButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kRightFireButtonShift)) == (kButtonAutoDown << kRightFireButtonShift); }
352 bool rightFireButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kRightFireButtonShift)) != 0; }
354 bool oneButtonDown()
const {
return (_inputState & (kButtonStateBits << kOneButtonShift)) == (kButtonDown << kOneButtonShift); }
355 bool oneButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kOneButtonShift)) == (kButtonAutoDown << kOneButtonShift); }
356 bool oneButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kOneButtonShift)) != 0; }
358 bool twoButtonDown()
const {
return (_inputState & (kButtonStateBits << kTwoButtonShift)) == (kButtonDown << kTwoButtonShift); }
359 bool twoButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kTwoButtonShift)) == (kButtonAutoDown << kTwoButtonShift); }
360 bool twoButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kTwoButtonShift)) != 0; }
362 bool threeButtonDown()
const {
return (_inputState & (kButtonStateBits << kThreeButtonShift)) == (kButtonDown << kThreeButtonShift); }
363 bool threeButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kThreeButtonShift)) == (kButtonAutoDown << kThreeButtonShift); }
364 bool threeButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kThreeButtonShift)) != 0; }
366 bool fourButtonDown()
const {
return (_inputState & (kButtonStateBits << kFourButtonShift)) == (kButtonDown << kFourButtonShift); }
367 bool fourButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kFourButtonShift)) == (kButtonAutoDown << kFourButtonShift); }
368 bool fourButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kFourButtonShift)) != 0; }
370 bool mod1ButtonDown()
const {
return (_inputState & (kButtonStateBits << kMod1ButtonShift)) == (kButtonDown << kMod1ButtonShift); }
371 bool mod1ButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kMod1ButtonShift)) == (kButtonAutoDown << kMod1ButtonShift); }
372 bool mod1ButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kMod1ButtonShift)) != 0; }
374 bool mod2ButtonDown()
const {
return (_inputState & (kButtonStateBits << kMod2ButtonShift)) == (kButtonDown << kMod2ButtonShift); }
375 bool mod2ButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kMod2ButtonShift)) == (kButtonAutoDown << kMod2ButtonShift); }
376 bool mod2ButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kMod2ButtonShift)) != 0; }
378 bool mod3ButtonDown()
const {
return (_inputState & (kButtonStateBits << kMod3ButtonShift)) == (kButtonDown << kMod3ButtonShift); }
379 bool mod3ButtonAutoDown()
const {
return (_inputState & (kButtonStateBits << kMod3ButtonShift)) == (kButtonAutoDown << kMod3ButtonShift); }
380 bool mod3ButtonAnyDown()
const {
return (_inputState & (kButtonAutoDown << kMod3ButtonShift)) != 0; }
382 bool allAutoInput()
const {
return (_inputState & kAllAutoBits) != 0; }
383 bool anyDirectionInput()
const {
return (_inputState & kDirectionBits) != 0; }
384 bool anyButtonInput()
const {
return (_inputState & kButtonBits) != 0; }
385 bool anyInput()
const {
return _inputState != 0; }
387 void getInputLocation(
Common::Point &where)
const { where = _inputLocation; }
389 bool anyInputBitSet(
const InputBits bits)
const {
return (_inputState & bits) != 0; }
391 bool isAltDown()
const {
return _altDown; }
394 _inputState = kAllUpBits;
395 _inputLocation.x = 0;
396 _inputLocation.y = 0;
401 void setInputBits(
const InputBits state) { _inputState = state; }
402 void setInputLocation(
const Common::Point &where) { _inputLocation = where; }
403 void setAltDown(
bool altDown) { _altDown = altDown; }
405 InputBits _inputState;
413 static InputHandler *getCurrentHandler() {
return _inputHandler; }
414 static void pollForInput();
416 static void readInputDevice(
Input&);
417 static void invalHotspots() { _invalHotspots =
true; }
418 static InputBits getCurrentFilter() {
return _lastFilter; }
423 virtual void setNextHandler(
InputHandler *nextHandler) { _nextHandler = nextHandler; }
424 virtual InputHandler *getNextHandler() {
return _nextHandler; }
426 virtual void handleInput(
const Input &,
const Hotspot *);
427 virtual void clickInHotspot(
const Input &,
const Hotspot *);
429 virtual void activateHotspots();
431 virtual bool isClickInput(
const Input &,
const Hotspot *);
432 virtual bool wantsCursor();
434 virtual bool releaseInputFocus() {
return true; }
435 virtual void grabInputFocus() {}
438 virtual InputBits getInputFilter();
441 virtual InputBits getClickFilter();
443 virtual void allowInput(
const bool allow) { _allowInput = allow; }
447 static bool _invalHotspots;
448 static InputBits _lastFilter;
471 void handleInput(
const Input &,
const Hotspot *)
override;
472 virtual bool stopTrackingInput(
const Input &) {
return false; }
474 virtual void startTracking(
const Input &);
475 virtual void stopTracking(
const Input &);
476 virtual void continueTracking(
const Input &) {}
478 bool isTracking() {
return this == _currentTracker; }
479 bool isClickInput(
const Input &,
const Hotspot *)
override;
481 bool releaseInputFocus()
override {
return !isTracking(); }
484 static Tracker *_currentTracker;
491 static bool isMenuButtonPressInput(
const Input &input) {
return input.twoButtonDown(); }
493 static InputBits getClickInputFilter() {
return kFilterTwoButton; }
494 static bool isClickInput(
const Input &input) {
return input.twoButtonDown(); }
495 static bool isDraggingInput(
const Input &input) {
return input.twoButtonAnyDown(); }
496 static bool isPressingInput(
const Input &input) {
return input.twoButtonAnyDown(); }
498 static bool isRaiseInventoryInput(
const Input &input) {
return input.leftFireButtonDown(); }
499 static bool isRaiseBiochipsInput(
const Input &input) {
return input.rightFireButtonDown(); }
500 static InputBits getItemPanelsInputFilter() {
return kFilterFourButton | kFilterLeftFireButton | kFilterRightFireButton; }
502 static bool isToggleAIMiddleInput(
const Input &input) {
return input.threeButtonDown(); }
504 static bool isToggleInfoInput(
const Input &input) {
return input.fourButtonDown(); }
507 static bool isEasterEggModifierInput(
const Input &input) {
return input.isAltDown(); }
509 static bool isTogglePauseInput(
const Input &input) {
return input.mod3ButtonDown(); }
514 #define InputDevice (::Pegasus::InputDeviceManager::instance())
Definition: ai_action.h:33
Definition: singleton.h:42