aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/keymapper/remap-dialog.cpp41
-rw-r--r--backends/keymapper/remap-dialog.h2
2 files changed, 39 insertions, 4 deletions
diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp
index b67eecc165..94b0cbf66b 100644
--- a/backends/keymapper/remap-dialog.cpp
+++ b/backends/keymapper/remap-dialog.cpp
@@ -35,6 +35,7 @@ namespace Common {
enum {
kRemapCmd = 'REMP',
+ kClearCmd = 'CLER',
kCloseCmd = 'CLOS'
};
@@ -140,8 +141,10 @@ void RemapDialog::reflowLayout() {
uint16 areaW, areaH;
int spacing = g_gui.xmlEval()->getVar("Globals.KeyMapper.Spacing");
int labelWidth = g_gui.xmlEval()->getVar("Globals.KeyMapper.LabelWidth");
- int buttonWidth = g_gui.xmlEval()->getVar("Globals.KeyMapper.ButtonWidth");
- int colWidth = labelWidth + buttonWidth + spacing;
+ int keyButtonWidth = g_gui.xmlEval()->getVar("Globals.KeyMapper.ButtonWidth");
+ int clearButtonWidth = g_gui.xmlEval()->getVar("Globals.Line.Height");
+ int clearButtonHeight = g_gui.xmlEval()->getVar("Globals.Line.Height");
+ int colWidth = labelWidth + keyButtonWidth + clearButtonWidth + spacing;
g_gui.xmlEval()->getWidgetData((const String&)String("KeyMapper.KeymapArea"), areaX, areaY, areaW, areaH);
@@ -156,6 +159,7 @@ void RemapDialog::reflowLayout() {
_scrollBar->recalc();
uint textYOff = (buttonHeight - kLineHeight) / 2;
+ uint clearButtonYOff = (buttonHeight - clearButtonHeight) / 2;
uint oldSize = _keymapWidgets.size();
uint newSize = _rowCount * _colCount;
@@ -169,6 +173,9 @@ void RemapDialog::reflowLayout() {
new GUI::StaticTextWidget(this, 0, 0, 0, 0, "", Graphics::kTextAlignRight);
widg.keyButton =
new GUI::ButtonWidget(this, 0, 0, 0, 0, "", 0, kRemapCmd + i);
+ widg.clearButton =
+ new GUI::ButtonWidget(this, 0, 0, 0, 0, "C", 0, kClearCmd + i);
+
_keymapWidgets.push_back(widg);
} else {
widg = _keymapWidgets[i];
@@ -178,7 +185,8 @@ void RemapDialog::reflowLayout() {
uint y = areaY + (i / _colCount) * (buttonHeight + spacing);
widg.actionText->resize(x, y + textYOff, labelWidth, kLineHeight);
- widg.keyButton->resize(x + labelWidth, y, buttonWidth, buttonHeight);
+ widg.keyButton->resize(x + labelWidth, y, keyButtonWidth, buttonHeight);
+ widg.clearButton->resize(x + labelWidth + keyButtonWidth + spacing, y + clearButtonYOff, clearButtonWidth, clearButtonHeight);
}
while (oldSize > newSize) {
ActionWidgets widg = _keymapWidgets.remove_at(--oldSize);
@@ -188,14 +196,19 @@ void RemapDialog::reflowLayout() {
removeWidget(widg.keyButton);
delete widg.keyButton;
+
+ removeWidget(widg.clearButton);
+ delete widg.clearButton;
}
}
void RemapDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
- debug(3, "RemapDialog::handleCommand");
+ debug(3, "RemapDialog::handleCommand %u %u", cmd, data);
if (cmd >= kRemapCmd && cmd < kRemapCmd + _keymapWidgets.size()) {
startRemapping(cmd - kRemapCmd);
+ } else if (cmd >= kClearCmd && cmd < kClearCmd + _keymapWidgets.size()) {
+ clearMapping(cmd - kClearCmd);
} else if (cmd == GUI::kPopUpItemSelectedCmd) {
loadKeymap();
} else if (cmd == GUI::kSetPositionCmd) {
@@ -207,6 +220,23 @@ void RemapDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 d
}
}
+void RemapDialog::clearMapping(uint i) {
+ if (_topAction + i >= _currentActions.size())
+ return;
+
+ debug(3, "clear the mapping %u", i);
+ _activeRemapAction = _currentActions[_topAction + i].action;
+ _activeRemapAction->mapKey(0);
+ _activeRemapAction->getParent()->saveMappings();
+ _changes = true;
+
+ // force refresh
+ _topAction = -1;
+ refreshKeymap();
+
+ _activeRemapAction = 0;
+}
+
void RemapDialog::startRemapping(uint i) {
if (_topAction + i >= _currentActions.size())
return;
@@ -354,6 +384,7 @@ void RemapDialog::refreshKeymap() {
ActionWidgets& widg = _keymapWidgets[widgetI];
if (actionI < _currentActions.size()) {
+ debug(8, "RemapDialog::refreshKeymap actionI=%u", actionI);
ActionInfo& info = _currentActions[actionI];
widg.actionText->setLabel(info.description + ": ");
@@ -368,11 +399,13 @@ void RemapDialog::refreshKeymap() {
widg.actionText->setVisible(true);
widg.keyButton->setVisible(true);
+ widg.clearButton->setVisible(true);
actionI++;
} else {
widg.actionText->setVisible(false);
widg.keyButton->setVisible(false);
+ widg.clearButton->setVisible(false);
}
//widg.actionText->draw();
//widg.keyButton->draw();
diff --git a/backends/keymapper/remap-dialog.h b/backends/keymapper/remap-dialog.h
index f587ae515d..25e336c4fe 100644
--- a/backends/keymapper/remap-dialog.h
+++ b/backends/keymapper/remap-dialog.h
@@ -55,6 +55,7 @@ protected:
struct ActionWidgets {
GUI::StaticTextWidget *actionText;
GUI::ButtonWidget *keyButton;
+ GUI::ButtonWidget *clearButton;
};
struct ActionInfo {
Action *action;
@@ -64,6 +65,7 @@ protected:
void loadKeymap();
void refreshKeymap();
+ void clearMapping(uint i);
void startRemapping(uint i);
void stopRemapping();