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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef PSPKEYBOARD_H
24 #define PSPKEYBOARD_H
25 
26 #include "common/events.h"
27 #include "common/stream.h"
28 #include "backends/platform/psp/display_client.h"
29 //#include "backends/platform/psp/input.h"
30 #include <pspctrl.h>
31 
32 //number of modes
33 #define MODE_COUNT 4
34 #define guiStringsSize 8 /* size of guistrings array */
35 
36 class PspEvent;
37 
38 class PSPKeyboard : public DisplayClient {
39 
40 private:
41 	enum State {
42 		kInvisible,
43 		kDefault,
44 		kCornersSelected,
45 		kLTriggerDown,
46 		kRTriggerDown,
47 		kMove
48 	};
49 
50 public:
51 	PSPKeyboard();
52 	~PSPKeyboard();
53 
54 	bool load();												// Load keyboard into memory
isInit()55 	bool isInit() const { return _init; }								// Check for initialization
isDirty()56 	bool isDirty() const { return _dirty; }							// Check if needs redrawing
setDirty()57 	void setDirty() { _dirty = true; }
setClean()58 	void setClean() { _dirty = false; }
isVisible()59 	bool isVisible() const { return _state != kInvisible; }			// Check if visible
60 	void setVisible(bool val);
61 	bool processInput(Common::Event &event, PspEvent &pspEvent, SceCtrlData &pad);	// Process input
62 	void moveTo(const int newX, const int newY);				// Move keyboard
63 	void render();												// Draw the keyboard onscreen
64 private:
65 	enum CursorDirections {
66 		kUp = 0,
67 		kRight,
68 		kDown,
69 		kLeft,
70 		kCenter
71 	};
72 
73 	Buffer _buffers[guiStringsSize];
74 	Palette _palettes[guiStringsSize];
75 	GuRenderer _renderer;
76 
77 	void increaseKeyboardLocationX(int amount);		// Move keyboard onscreen
78 	void increaseKeyboardLocationY(int amount);
79 	void convertCursorToXY(CursorDirections cur, int &x, int &y);
80 
81 	bool handleMoveState(SceCtrlData &pad);
82 	bool handleDefaultState(Common::Event &event, SceCtrlData &pad);
83 	bool handleCornersSelectedState(Common::Event &event, SceCtrlData &pad);
84 	bool getInputChoice(Common::Event &event, SceCtrlData &pad);
85 	void getCursorMovement(SceCtrlData &pad);
86 	void handleRTriggerDownState(SceCtrlData &pad);
87 	void handleLTriggerDownState(SceCtrlData &pad);
88 
89 	static short _modeChar[MODE_COUNT][5][6];
90 	static const char *_guiStrings[];
91 	bool _init;
92 	uint32 _prevButtons;	// A bit pattern.
93 	uint32 _buttonsChanged;
94 
95 	bool _dirty;        		// keyboard needs redrawing
96 	int _mode;          		// charset selected. (0 - letters or 1 - numbers)
97 	int _movedX;				// location we've moved the KB to onscreen
98 	int _movedY;
99 	bool _moved;				// whether the keyboard was moved
100 
101 	State _state;				// State of keyboard Keyboard state machine
102 	State _lastState;
103 
104 	CursorDirections _oldCursor;			// Point to place of last cursor
105 
106 };
107 
108 #endif /* PSPKEYBOARD_H */
109