ScummVM API documentation
input.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef PSP_INPUT_H
23 #define PSP_INPUT_H
24 
25 #include "common/scummsys.h"
26 #include "common/events.h"
27 #include "backends/platform/psp/pspkeyboard.h"
28 #include "backends/platform/psp/cursor.h"
29 #include "backends/platform/psp/image_viewer.h"
30 #include <pspctrl.h>
31 
32 enum PspEventType {
33  PSP_EVENT_NONE = 0,
34  PSP_EVENT_SHIFT,
35  PSP_EVENT_SHOW_VIRTUAL_KB,
36  PSP_EVENT_LBUTTON,
37  PSP_EVENT_RBUTTON,
38  PSP_EVENT_MODE_SWITCH,
39  PSP_EVENT_CHANGE_SPEED,
40  PSP_EVENT_IMAGE_VIEWER,
41  PSP_EVENT_IMAGE_VIEWER_SET_BUTTONS,
42  PSP_EVENT_LAST
43 };
44 
45 struct PspEvent {
46  PspEventType type;
47  uint32 data;
48  PspEvent() { clear(); }
49  void clear() {
50  type = PSP_EVENT_NONE;
51  data = 0;
52  }
53  bool isEmpty() { return type == PSP_EVENT_NONE; }
54 };
55 
56 enum PspPadMode {
57  PAD_MODE_NORMAL,
58  PAD_MODE_LOL,
59  PAD_MODE_LAST
60 };
61 
62 enum ShiftMode {
63  UNSHIFTED = 0,
64  SHIFTED = 1,
65  SHIFTED_MODE_LAST
66 };
67 
68 
69 class Button {
70 private:
71  Common::KeyCode _key;
72  uint32 _ascii;
73  uint32 _flag;
74  PspEvent _pspEventDown; // event when we press
75  PspEvent _pspEventUp; // event when we release
76 public:
77  Button();
78  void clear();
79  bool getEvent(Common::Event &event, PspEvent &pspEvent, bool buttonDown);
80  void setKey(Common::KeyCode key, uint32 ascii = 0, uint32 flag = 0) { _key = key; _ascii = ascii; _flag = flag; }
81  void setPspEvent(PspEventType typeDown, uint32 dataDown, PspEventType typeUp, uint32 dataUp);
82 };
83 
84 class ButtonPad {
85 public:
86  enum ButtonType { // must match the buttonMap
87  BTN_UP_LEFT,
88  BTN_UP_RIGHT,
89  BTN_DOWN_RIGHT,
90  BTN_DOWN_LEFT,
91  BTN_RIGHT,
92  BTN_DOWN,
93  BTN_LEFT,
94  BTN_UP,
95  BTN_CROSS,
96  BTN_CIRCLE,
97  BTN_TRIANGLE,
98  BTN_SQUARE,
99  BTN_LTRIGGER,
100  BTN_RTRIGGER,
101  BTN_START,
102  BTN_SELECT,
103  BTN_LAST
104  };
105 
106 private:
107  Button _button[BTN_LAST][SHIFTED_MODE_LAST];
108  uint32 _buttonsChanged[SHIFTED_MODE_LAST]; // normal and shifted
109  uint32 _prevButtonState;
110  ShiftMode _shifted;
111  PspPadMode _padMode;
112  bool _comboMode; // are we in the middle of combos
113  bool _combosEnabled; // can we do combos
114  static const uint32 _buttonMap[]; // maps the buttons to their values
115 
116  void initButtonsNormalMode();
117  void initButtonsLolMode();
118  void modifyButtonsForCombos(SceCtrlData &pad);
119 
120 public:
121  ButtonPad();
122  void initButtons(); // set the buttons to the mode that's selected
123  void clearButtons(); // empty the buttons of all events
124 
125  bool getEvent(Common::Event &event, PspEvent &pspEvent, SceCtrlData &pad);
126  bool getEventFromButtonState(Common::Event &event, PspEvent &pspEvent, uint32 buttonState);
127 
128  void setShifted(ShiftMode shifted) { _shifted = shifted; }
129  void setPadMode(PspPadMode mode) { _padMode = mode; }
130  bool isButtonDown() { return _prevButtonState; }
131 
132  void enableCombos(bool value) { _combosEnabled = value; }
133  Button &getButton(ButtonType type, ShiftMode mode) { return _button[type][mode]; }
134 };
135 
136 class Nub {
137 private:
138  Cursor *_cursor; // to enable changing/getting cursor position
139 
140  ShiftMode _shifted;
141  int32 _hiresX; // to accumulate analog X over many frames
142  int32 _hiresY; // to accumulate analog Y over many frames
143  bool _dpadMode;
144 
145  ButtonPad _buttonPad; // private buttonpad for dpad mode
146 
147  int32 modifyNubAxisMotion(int32 input);
148  void translateToDpadState(int dpadX, int dpadY, uint32 &buttonState); // convert nub data to dpad data
149 public:
150  Nub() : _shifted(UNSHIFTED), _dpadMode(false), _hiresX(0), _hiresY(0) { }
151  void init() { _buttonPad.initButtons(); }
152 
153  void setCursor(Cursor *cursor) { _cursor = cursor; }
154 
155  // setters
156  void setDpadMode(bool active) { _dpadMode = active; }
157  void setShifted(ShiftMode shifted) { _shifted = shifted; }
158 
159  // getters
160  bool isButtonDown();
161  bool getEvent(Common::Event &event, PspEvent &pspEvent, SceCtrlData &pad);
162  ButtonPad &getPad() { return _buttonPad; }
163 };
164 
166 public:
167  InputHandler() : _keyboard(0), _cursor(0), _imageViewer(0), _padMode(PAD_MODE_NORMAL),
168  _lastPadCheckTime(0) {}
169  // pointer setters
170  void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; }
171  void setCursor(Cursor *cursor) { _cursor = cursor; _nub.setCursor(cursor); }
172  void setImageViewer(ImageViewer *imageViewer) { _imageViewer = imageViewer; }
173 
174  void init();
175  bool getAllInputs(Common::Event &event);
176  void setImageViewerMode(bool active);
177 
178 private:
179  Nub _nub;
180  ButtonPad _buttonPad;
181 
182  // Pointers to relevant other classes
183  PSPKeyboard *_keyboard;
184  Cursor *_cursor;
185  ImageViewer *_imageViewer;
186 
187  PspPadMode _padMode; // whice mode we're in
188  PspEvent _pendingPspEvent; // an event that can't be handled yet
189  uint32 _lastPadCheckTime;
190  static const char *_padModeText[];
191 
192  bool getEvent(Common::Event &event, SceCtrlData &pad);
193  bool handlePspEvent(Common::Event &event, PspEvent &pspEvent);
194  void handleMouseEvent(Common::Event &event, Common::EventType type, const char *string);
195  void handleShiftEvent(ShiftMode shifted);
196  void handleModeSwitchEvent();
197  void setButtonsForImageViewer();
198 };
199 
200 #endif /* PSP_INPUT_H */
Definition: input.h:165
EventType
Definition: events.h:49
Definition: input.h:45
Definition: atari-cursor.h:38
Definition: input.h:136
Definition: events.h:199
Definition: image_viewer.h:29
Definition: pspkeyboard.h:37
Definition: input.h:84
Definition: input.h:69