aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/psp/input.h
diff options
context:
space:
mode:
authorYotam Barnoy2010-10-06 21:26:45 +0000
committerYotam Barnoy2010-10-06 21:26:45 +0000
commite47e474cff9823c789626f4b0b26ff69257b5263 (patch)
treefd271cd9d031888c74a078e1872d3c92147cc42a /backends/platform/psp/input.h
parentb15f51ad7b5e8e85afe970c1740aae566236afe6 (diff)
downloadscummvm-rg350-e47e474cff9823c789626f4b0b26ff69257b5263.tar.gz
scummvm-rg350-e47e474cff9823c789626f4b0b26ff69257b5263.tar.bz2
scummvm-rg350-e47e474cff9823c789626f4b0b26ff69257b5263.zip
PSP: rewrote input code and added an input mode
The old input code was getting too messy. A redesign made it easier to modify and add several modes and combos, including one for 1st person games which benefit from a different control scheme. A combo switches between the modes. I also added directional support while the virtual keyboard is visible, using the nub. This allows moving around in the text in some games, and moving the character while typing for others (e.g. AGI) svn-id: r53042
Diffstat (limited to 'backends/platform/psp/input.h')
-rw-r--r--backends/platform/psp/input.h154
1 files changed, 136 insertions, 18 deletions
diff --git a/backends/platform/psp/input.h b/backends/platform/psp/input.h
index cd686d9e02..6991c50533 100644
--- a/backends/platform/psp/input.h
+++ b/backends/platform/psp/input.h
@@ -28,36 +28,154 @@
#include "common/scummsys.h"
#include "common/events.h"
-#include "backends/platform/psp/display_client.h"
-#include "backends/platform/psp/default_display_client.h"
#include "backends/platform/psp/pspkeyboard.h"
#include "backends/platform/psp/cursor.h"
#include <pspctrl.h>
-class InputHandler {
+enum PspEventType {
+ PSP_EVENT_NONE = 0,
+ PSP_EVENT_SHIFT,
+ PSP_EVENT_SHOW_VIRTUAL_KB,
+ PSP_EVENT_LBUTTON,
+ PSP_EVENT_RBUTTON,
+ PSP_EVENT_MODE_SWITCH,
+ PSP_EVENT_CHANGE_SPEED,
+ PSP_EVENT_LAST
+};
+
+
+struct PspEvent {
+ PspEventType type;
+ uint32 data;
+ PspEvent() { clear(); }
+ void clear() {
+ type = PSP_EVENT_NONE;
+ data = 0;
+ }
+ bool isEmpty() { return type == PSP_EVENT_NONE; }
+};
+
+enum PspPadMode {
+ PAD_MODE_NORMAL,
+ PAD_MODE_LOL,
+ PAD_MODE_LAST
+};
+
+enum ShiftMode {
+ UNSHIFTED = 0,
+ SHIFTED = 1,
+ SHIFTED_MODE_LAST
+};
+
+
+class Button {
+private:
+ Common::KeyCode _key;
+ uint32 _ascii;
+ uint32 _flag;
+ PspEvent _pspEventDown; // event when we press
+ PspEvent _pspEventUp; // event when we release
+public:
+ Button();
+ void clear();
+ bool getEvent(Common::Event &event, PspEvent &pspEvent, bool buttonDown);
+ void setKey(Common::KeyCode key, uint32 ascii = 0, uint32 flag = 0) { _key = key; _ascii = ascii; _flag = flag; }
+ void setPspEvent(PspEventType typeDown, uint32 dataDown, PspEventType typeUp, uint32 dataUp);
+};
+
+class ButtonPad {
public:
- InputHandler() : _cursor(0), _keyboard(0), _prevButtons(0), _lastPadCheckTime(0), _buttonsChanged(0), _dpadX(0), _dpadY(0) {}
+ enum ButtonType { // must match the buttonMap
+ BTN_UP_LEFT,
+ BTN_UP_RIGHT,
+ BTN_DOWN_RIGHT,
+ BTN_DOWN_LEFT,
+ BTN_RIGHT,
+ BTN_DOWN,
+ BTN_LEFT,
+ BTN_UP,
+ BTN_CROSS,
+ BTN_CIRCLE,
+ BTN_TRIANGLE,
+ BTN_SQUARE,
+ BTN_LTRIGGER,
+ BTN_RTRIGGER,
+ BTN_START,
+ BTN_SELECT,
+ BTN_LAST
+ };
- void init();
- bool getAllInputs(Common::Event &event);
- void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; }
- void setCursor(Cursor *cursor) { _cursor = cursor; }
+private:
+ Button _button[BTN_LAST][SHIFTED_MODE_LAST];
+ uint32 _buttonsChanged[SHIFTED_MODE_LAST]; // normal and shifted
+ uint32 _prevButtonState;
+ ShiftMode _shifted;
+ PspPadMode _padMode;
+ bool _comboMode; // are we in the middle of combos
+ static const uint32 _buttonMap[]; // maps the buttons to their values
+ void initButtonsNormalMode();
+ void initButtonsLolMode();
+ void modifyButtonsForCombos(SceCtrlData &pad);
+ void clearButtons();
+
+public:
+ ButtonPad();
+ bool getEvent(Common::Event &event, PspEvent &pspEvent, SceCtrlData &pad);
+ bool getEventFromButtonState(Common::Event &event, PspEvent &pspEvent, uint32 buttonState);
+ void setShifted(ShiftMode shifted) { _shifted = shifted; }
+ void setPadMode(PspPadMode mode) { _padMode = mode; }
+ bool isButtonDown() { return _prevButtonState; }
+ void initButtons();
+};
+
+class Nub {
+private:
+ Cursor *_cursor; // to enable changing/getting cursor position
+
+ ButtonPad _buttonPad; // private buttonpad for dpad mode
+ ShiftMode _shifted;
+ bool _dpadMode;
+
+public:
+ Nub() : _shifted(UNSHIFTED), _dpadMode(false) { _buttonPad.initButtons(); }
+
+ void setCursor(Cursor *cursor) { _cursor = cursor; }
+ void setDpadMode(bool active) { _dpadMode = active; }
+ void setShifted(ShiftMode shifted) { _shifted = shifted; }
+ bool isButtonDown();
+
+ bool getEvent(Common::Event &event, PspEvent &pspEvent, SceCtrlData &pad);
+ int32 modifyNubAxisMotion(int32 input);
+ void translateToDpadState(int dpadX, int dpadY, uint32 &buttonState); // convert nub data to dpad data
+};
+
+class InputHandler {
+public:
+ InputHandler() : _keyboard(0), _cursor(0), _padMode(PAD_MODE_NORMAL), _lastPadCheckTime(0) {}
+ void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; }
+ void setCursor(Cursor *cursor) { _cursor = cursor; _nub.setCursor(cursor); }
+
+ void init();
+ bool getAllInputs(Common::Event &event);
+
private:
- Cursor *_cursor;
PSPKeyboard *_keyboard;
- uint32 _prevButtons;
+ Cursor *_cursor;
+
+ Nub _nub;
+ ButtonPad _buttonPad;
+
+ PspPadMode _padMode; // whice mode we're in
+ PspEvent _pendingPspEvent; // an event that can't be handled yet
uint32 _lastPadCheckTime;
- uint32 _buttonsChanged;
- int32 _dpadX, _dpadY;
- int32 _accelX, _accelY;
+ static const char *_padModeText[];
bool getEvent(Common::Event &event, SceCtrlData &pad);
- bool getDpadEvent(Common::Event &event, SceCtrlData &pad);
- bool getButtonEvent(Common::Event &event, SceCtrlData &pad);
- bool getNubEvent(Common::Event &event, SceCtrlData &pad);
- int32 modifyNubAxisMotion(int32 input);
- Common::KeyCode translateDpad(int x, int y);
+ bool handlePspEvent(Common::Event &event, PspEvent &pspEvent);
+ void handleMouseEvent(Common::Event &event, Common::EventType type, const char *string);
+ void handleShiftEvent(ShiftMode shifted);
+ void handleModeSwitchEvent();
};
#endif /* PSP_INPUT_H */