aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/psp/pspkeyboard.h
blob: a30e7d0f32cda64a3aa7dc48a1a3ccaaa4c4ce4a (plain)
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
/* 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef PSPKEYBOARD_H
#define PSPKEYBOARD_H

#include "common/events.h"
#include "common/stream.h"
#include "backends/platform/psp/display_client.h"
#include <pspctrl.h>

//number of modes
#define MODE_COUNT 4
#define guiStringsSize 8 /* size of guistrings array */

class PSPKeyboard : public DisplayClient {

private:
	enum State {
		kInvisible,
		kDefault,
		kCornersSelected,
		kLTriggerDown,
		kRTriggerDown,
		kMove
	};

public:
	PSPKeyboard();
	~PSPKeyboard();

	bool load();												// Load keyboard into memory
	bool isInit() const { return _init; }								// Check for initialization
	bool isDirty() const { return _dirty; }							// Check if needs redrawing
	void setDirty() { _dirty = true; }
	void setClean() { _dirty = false; }
	bool isVisible() const { return _state != kInvisible; }			// Check if visible
	void setVisible(bool val);
	bool processInput(Common::Event &event, SceCtrlData &pad);	// Process input
	void moveTo(const int newX, const int newY);				// Move keyboard
	void render();												// Draw the keyboard onscreen

private:
	enum CursorDirections {
		kUp = 0,
		kRight,
		kDown,
		kLeft,
		kCenter
	};

	Buffer _buffers[guiStringsSize];
	Palette _palettes[guiStringsSize];
	GuRenderer _renderer;

	int loadPngImage(Common::SeekableReadStream *file, Buffer &buffer, Palette &palette);
	int getPngImageSize(Common::SeekableReadStream *, uint32 *png_width, uint32 *png_height, uint32 *paletteSize);
	uint32 convert_pow2(uint32 size);
	void increaseKeyboardLocationX(int amount);		// Move keyboard onscreen
	void increaseKeyboardLocationY(int amount);
	void convertCursorToXY(CursorDirections cur, int &x, int &y);

	void handleMoveState(SceCtrlData &pad);
	bool handleDefaultState(Common::Event &event, SceCtrlData &pad);
	bool handleCornersSelectedState(Common::Event &event, SceCtrlData &pad);
	bool getInputChoice(Common::Event &event, SceCtrlData &pad);
	void getCursorMovement(SceCtrlData &pad);
	void handleRTriggerDownState(SceCtrlData &pad);
	void handleLTriggerDownState(SceCtrlData &pad);

	static short _modeChar[MODE_COUNT][5][6];
	static const char *_guiStrings[];
	bool _init;
	uint32 _prevButtons;	// A bit pattern.
	uint32 _buttonsChanged;

	bool _dirty;        		// keyboard needs redrawing
	int _mode;          		// charset selected. (0 - letters or 1 - numbers)
	int _movedX;				// location we've moved the KB to onscreen
	int _movedY;
	bool _moved;				// whether the keyboard was moved

	State _state;				// State of keyboard Keyboard state machine
	State _lastState;

	CursorDirections _oldCursor;			// Point to place of last cursor

};

#endif /* PSPKEYBOARD_H */