aboutsummaryrefslogtreecommitdiff
path: root/backends/wince/gapi_keys.cpp
blob: ff1622fd9b4bdc2ae7e0de9064b946e9141feda8 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001/2002 The ScummVM project
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#ifdef _WIN32_WCE

// Handle mapping of actions to hardware keys

#include "stdafx.h"
#include <assert.h>

#if _WIN32_WCE < 300

#include <Wingdi.h>
#include <Winbase.h>
#include <Wtypes.h>

#endif

#include <Winuser.h>
#include <sipapi.h>
//#include <Aygshell.h>
#include <gx.h>
#include "dynamic_imports.h"

#include "gapi_keys.h"

#include "screen.h"

struct oneAction _actions[TOTAL_ACTIONS];
struct GXKeyList _portrait_keys;
struct GXKeyList _landscape_keys;
pAction *_action_functions;

void handleSelectGameUp(void);
void handleSelectGameDown(void);
void handleSelectGameButton(void);

const char* ActionsText[] = {
	"None",
	"Pause",
	"Save",
	"Quit",
	"Skip",
	"Hide",
	"Keyboard",
	"Sound",
	"Right click",
	"Cursor on/off",
	"Subtitles on/off",
	"Boss",
	"Free look"
};

bool _typeExists(unsigned int x) {
	int i;

	for (i=0; i<TOTAL_ACTIONS; i++)
		if (_actions[i].action_type == x)
			return true;

	return false;
}


const char* getActionName(int action) {
	return ActionsText[action];
}

void GAPIKeysInit() {
	dynamicGXOpenInput();
	GAPIKeysGetReference();
}

void GAPIKeysInitActions(pAction *functions) {
	int i;

	for (i=0; i<TOTAL_ACTIONS; i++) {
		_actions[i].action_key = 0;
	}

	/* Default actions */

	/*
	_actions[0].action_type = ACTION_PAUSE;
	_actions[1].action_type = ACTION_SAVE;
	_actions[2].action_type = ACTION_QUIT;
	_actions[3].action_type = ACTION_SKIP;
	_actions[4].action_type = ACTION_HIDE;
	*/

	_action_functions = functions;
	
}

void GAPIKeysGetReference() {
	/*
	if(GetScreenMode()) {
		_keys = GXGetDefaultKeys(GX_LANDSCAPEKEYS);
	} else {
		_keys = GXGetDefaultKeys(GX_NORMALKEYS);
	}
	*/

	_portrait_keys = dynamicGXGetDefaultKeys(GX_NORMALKEYS);
	_landscape_keys = dynamicGXGetDefaultKeys(GX_LANDSCAPEKEYS);
}

void GAPIKeysHandleSelect(int key) {
	if (key == _portrait_keys.vkUp)
		handleSelectGameUp();
	if (key == _portrait_keys.vkDown)
		handleSelectGameDown();
	if (key == _portrait_keys.vkA ||
		key == _portrait_keys.vkB ||
		key == _portrait_keys.vkC ||
		key == _portrait_keys.vkStart)
		handleSelectGameButton();
}

unsigned int GAPIKeysTranslate(unsigned int key) {
/*
	if (key == _landscape_keys.vkUp)
		return _portrait_keys.vkUp;
	if (key == _landscape_keys.vkDown)
		return _portrait_keys.vkDown;
	if (key == _landscape_keys.vkLeft)
		return _portrait_keys.vkLeft;
	if (key == _landscape_keys.vkRight)
		return _portrait_keys.vkRight;
	if (key == _landscape_keys.vkA)
		return _portrait_keys.vkA;
	if (key == _landscape_keys.vkB)
		return _portrait_keys.vkB;
	if (key == _landscape_keys.vkC)
		return _portrait_keys.vkC;
	if (key == _landscape_keys.vkStart)
		return _portrait_keys.vkStart;
*/
	return key;
}

/*
const unsigned char getGAPIKeyMapping(short key) {
	// first the standard GAPI controls
	if (key == _keys.vkA)
		return GAPI_KEY_VKA;
	
	if (key == _keys.vkB)
			return GAPI_KEY_VKB;
	
	if (key == _keys.vkC)
			return GAPI_KEY_VKC;
	
	if (key == _keys.vkStart)
			return GAPI_KEY_VKSTART;

	if (key == _keys.vkUp) 
			return GAPI_KEY_VKUP;

	if (key == _keys.vkDown)
			return GAPI_KEY_VKDOWN;

	if (key == _keys.vkLeft)
			return GAPI_KEY_VKLEFT;

	if (key == _keys.vkRight)
			return GAPI_KEY_VKRIGHT;

	switch (key) {
		// then the "unsupported" keys 
		case INTERNAL_KEY_CALENDAR:
			return GAPI_KEY_CALENDAR;
		case INTERNAL_KEY_CONTACTS:
			return GAPI_KEY_CONTACTS;
		case INTERNAL_KEY_INBOX:
			return GAPI_KEY_INBOX;
		case INTERNAL_KEY_ITASK:
			return GAPI_KEY_ITASK;
		default:
			return 0;
	}
}
*/

const char* getGAPIKeyName(unsigned int key) {
	static char key_name[50];

	if (!key)
		return "Not mapped";
	if (key == (unsigned int)_portrait_keys.vkA)
		return "Button A";
	if (key == (unsigned int)_portrait_keys.vkB)
		return "Button B";
	if (key == (unsigned int)_portrait_keys.vkC)
		return "Button C";
	if (key == (unsigned int)_portrait_keys.vkStart)
		return "Button Start";
	if (key == (unsigned int)_portrait_keys.vkUp)
		return "Pad Up";
	if (key == (unsigned int)_portrait_keys.vkDown)
		return "Pad Down";
	if (key == (unsigned int)_portrait_keys.vkLeft)
		return "Pad Left";
	if (key == (unsigned int)_portrait_keys.vkRight)
		return "Pad Right";
	if (key == INTERNAL_KEY_CALENDAR)
		return "Button Calendar";
	if (key == INTERNAL_KEY_CONTACTS)
		return "Button Contacts";
	if (key == INTERNAL_KEY_INBOX)
		return "Button Inbox";
	if (key == INTERNAL_KEY_ITASK)
		return "Button ITask";
	sprintf(key_name, "Key %.4x", key);
		return key_name;

/*
	switch(key) {
		case 0:
			return "Not mapped";
		case GAPI_KEY_VKA:
			return "Button A";
		case GAPI_KEY_VKB:
			return "Button B";
		case GAPI_KEY_VKC:
			return "Button C";
		case GAPI_KEY_VKSTART:
			return "Button Start";
		case GAPI_KEY_CALENDAR:
			return "Button Calendar";
		case GAPI_KEY_CONTACTS:
			return "Button Contacts";
		case GAPI_KEY_INBOX:
			return "Button Inbox";
		case GAPI_KEY_ITASK:
			return "Button ITask";
		case GAPI_KEY_VKUP:
			return "Pad Up";
		case GAPI_KEY_VKDOWN:
			return "Pad Down";
		case GAPI_KEY_VKLEFT:
			return "Pad Left";
		case GAPI_KEY_VKRIGHT:
			return "Pad Right";
		default:
			sprintf(key_name, "Unknown key %.4x", key);
			return key_name;
	}
*/
}

struct oneAction* getAction(int action) {
	return &_actions[action];
}

bool processAction (unsigned int key) {
	int i;
	/*
	unsigned char GAPI_key;

	GAPI_key = getGAPIKeyMapping(key);
	if (!GAPI_key)
		return;
	*/

	for (i=0; i<TOTAL_ACTIONS; i++) {
		//if (_actions[i].action_key == GAPI_key &&
		/*
		if (_actions[i].action_key == key &&
			_actions[i].action_type != ACTION_NONE &&
			_action_functions[_actions[i].action_type - 1]) {
					_action_functions[_actions[i].action_type - 1]();
					return true;
		}
		*/
		
		if (_actions[i].action_key && _actions[i].action_key == key) {
			_action_functions[i]();
			return true;
		}
	}


	return false;
}

void clearActionKey (unsigned char key) {
	int i;

	for (i=0; i<TOTAL_ACTIONS; i++)
		if (_actions[i].action_key == key) {
			_actions[i].action_key = 0;
		}
}

const unsigned int* getActionKeys() {
	int i;
	static unsigned int actionKeys[TOTAL_ACTIONS];

	for (i=0; i<TOTAL_ACTIONS; i++)
		actionKeys[i] = _actions[i].action_key;

	return actionKeys;
}

const unsigned char* getActionTypes() {
	int i;
	static unsigned char actionTypes[TOTAL_ACTIONS];

	for (i=0; i<TOTAL_ACTIONS; i++)
		actionTypes[i] = _actions[i].action_type;

	return actionTypes;

}


void setNextType(int action) {
	int start = _actions[action].action_type;
	int current = start;
	for (;;) {
		current++;
		if (current == start)
			return;
		if (current > TOTAL_ACTIONS)
			current = 1;
		if (!_typeExists(current)) {
				_actions[action].action_type = current;
				return;
		}
	}
}

void setPreviousType(int action) {
	int start = _actions[action].action_type;
	int current = start;
	for (;;) {
		current--;
		if (current == start)
			return;
		if (current <= 0)
			current = TOTAL_ACTIONS;
		if (!_typeExists(current)) {
				_actions[action].action_type = current;
				return;
		}
	}
}



void setActionKeys(unsigned int *actionKeys) {
	int i;

	for (i=0; i<TOTAL_ACTIONS; i++)
		_actions[i].action_key = actionKeys[i];
}

void setActionTypes(unsigned char *actionTypes) {
	int i;

	for (i=0; i<TOTAL_ACTIONS; i++)
		_actions[i].action_type = (ActionType)actionTypes[i];
}

bool isRightClickSet() {
	return (_actions[ACTION_RIGHTCLICK].action_key);
}

#endif