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
|
/* 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.
*
*/
#include "gui/KeysDialog.h"
#include "gui/Actions.h"
#include "common/translation.h"
#include <SDL_keyboard.h>
#ifdef _WIN32_WCE
#include "CEDevice.h"
#endif
namespace GUI {
enum {
kMapCmd = 'map '
};
KeysDialog::KeysDialog(const Common::String &title)
: GUI::Dialog("KeysDialog") {
new ButtonWidget(this, "KeysDialog.Map", _("Map"), 0, kMapCmd);
new ButtonWidget(this, "KeysDialog.Ok", _("OK"), 0, kOKCmd);
new ButtonWidget(this, "KeysDialog.Cancel", _("Cancel"), 0, kCloseCmd);
_actionsList = new ListWidget(this, "KeysDialog.List");
_actionsList->setNumberingMode(kListNumberingZero);
_actionTitle = new StaticTextWidget(this, "KeysDialog.Action", title);
_keyMapping = new StaticTextWidget(this, "KeysDialog.Mapping", _("Select an action and click 'Map'"));
_actionTitle->setFlags(WIDGET_CLEARBG);
_keyMapping->setFlags(WIDGET_CLEARBG);
// Get actions names
ListWidget::StringArray l;
for (int i = 0; i < Actions::Instance()->size(); i++)
l.push_back(Actions::Instance()->actionName((ActionType)i));
_actionsList->setList(l);
_actionSelected = -1;
Actions::Instance()->beginMapping(false);
}
void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kListSelectionChangedCmd:
if (_actionsList->getSelected() >= 0) {
Common::String selection;
uint16 key = Actions::Instance()->getMapping(_actionsList->getSelected());
#ifdef __SYMBIAN32__
// ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
key = key - Common::ASCII_F1 + SDLK_F1;
#endif
if (key != 0)
selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey)key));
else
selection = Common::String::format(_("Associated key : none"));
_keyMapping->setLabel(selection);
_keyMapping->markAsDirty();
}
break;
case kMapCmd:
if (_actionsList->getSelected() < 0) {
_actionTitle->setLabel(_("Please select an action"));
} else {
Common::String selection;
_actionSelected = _actionsList->getSelected();
uint16 key = Actions::Instance()->getMapping(_actionSelected);
#ifdef __SYMBIAN32__
// ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
key = key - Common::ASCII_F1 + SDLK_F1;
#endif
if (key != 0)
selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey)key));
else
selection = Common::String::format(_("Associated key : none"));
_actionTitle->setLabel(_("Press the key to associate"));
_keyMapping->setLabel(selection);
_keyMapping->markAsDirty();
Actions::Instance()->beginMapping(true);
_actionsList->setEnabled(false);
}
_actionTitle->markAsDirty();
break;
case kOKCmd:
Actions::Instance()->saveMapping();
close();
break;
case kCloseCmd:
Actions::Instance()->loadMapping();
close();
break;
}
}
void KeysDialog::handleKeyDown(Common::KeyState state){
if (!Actions::Instance()->mappingActive())
Dialog::handleKeyDown(state);
}
void KeysDialog::handleKeyUp(Common::KeyState state) {
#ifdef __SYMBIAN32__
if (Actions::Instance()->mappingActive()) {
#else
if (state.flags == 0xff && Actions::Instance()->mappingActive()) { // GAPI key was selected
#endif
Common::String selection;
Actions::Instance()->setMapping((ActionType)_actionSelected, state.ascii);
if (state.ascii != 0)
selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey) state.keycode));
else
selection = Common::String::format(_("Associated key : none"));
_actionTitle->setLabel(_("Choose an action to map"));
_keyMapping->setLabel(selection);
_keyMapping->markAsDirty();
_actionTitle->markAsDirty();
_actionSelected = -1;
_actionsList->setEnabled(true);
Actions::Instance()->beginMapping(false);
} else
Dialog::handleKeyUp(state);
}
} // namespace GUI
|