diff options
author | Stephen Kennedy | 2008-08-13 19:24:52 +0000 |
---|---|---|
committer | Stephen Kennedy | 2008-08-13 19:24:52 +0000 |
commit | 70dde2d8bdfeb0e86a76d196193339f9ec9e17ab (patch) | |
tree | f7fb58f22d08e815b06e8dc7bb6058079a4b2cef | |
parent | 6b638f0e58d45096ca77cfafec5e59b14e706d1a (diff) | |
download | scummvm-rg350-70dde2d8bdfeb0e86a76d196193339f9ec9e17ab.tar.gz scummvm-rg350-70dde2d8bdfeb0e86a76d196193339f9ec9e17ab.tar.bz2 scummvm-rg350-70dde2d8bdfeb0e86a76d196193339f9ec9e17ab.zip |
RemapDialog now properly uses reflowLayout() and open(), so that the same instance can be reopened
svn-id: r33843
-rw-r--r-- | backends/events/default/default-events.cpp | 12 | ||||
-rw-r--r-- | backends/events/default/default-events.h | 2 | ||||
-rw-r--r-- | backends/keymapper/keymapper.h | 15 | ||||
-rw-r--r-- | backends/keymapper/remap-dialog.cpp | 161 | ||||
-rw-r--r-- | backends/keymapper/remap-dialog.h | 3 | ||||
-rw-r--r-- | backends/platform/sdl/events.cpp | 4 |
6 files changed, 121 insertions, 76 deletions
diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp index ccea12dad6..af8f9fa231 100644 --- a/backends/events/default/default-events.cpp +++ b/backends/events/default/default-events.cpp @@ -198,6 +198,7 @@ DefaultEventManager::DefaultEventManager(OSystem *boss) : _vk = new Common::VirtualKeyboard(); _keymapper = new Common::Keymapper(this); + _remap = false; } DefaultEventManager::~DefaultEventManager() { @@ -429,8 +430,15 @@ bool DefaultEventManager::pollEvent(Common::Event &event) { result = false; } } else if (event.kbd.keycode == Common::KEYCODE_F7 && event.kbd.flags == 0) { - Common::RemapDialog dialog; - dialog.runModal(); + if (!_remap) { + _remap = true; + Common::RemapDialog _remapDialog; + bool isPaused = (g_engine) ? g_engine->isPaused() : true; + if (!isPaused) g_engine->pauseEngine(true); + _remapDialog.runModal(); + if (!isPaused) g_engine->pauseEngine(false); + _remap = false; + } } break; diff --git a/backends/events/default/default-events.h b/backends/events/default/default-events.h index 8e24120ad0..81387d8d98 100644 --- a/backends/events/default/default-events.h +++ b/backends/events/default/default-events.h @@ -31,6 +31,7 @@ #include "common/savefile.h" namespace Common { + class Keymapper; class VirtualKeyboard; } @@ -51,6 +52,7 @@ class DefaultEventManager : public Common::EventManager { Common::VirtualKeyboard *_vk; Common::Keymapper *_keymapper; + bool _remap; Common::Queue<Common::Event> _artificialEventQueue; int _artificialEventCounter; diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index b5985470fe..7ef2ef96cb 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -36,9 +36,12 @@ namespace Common { class Keymapper { - friend class RemapDialog; - public: + + struct MapRecord { + Keymap* keymap; + bool inherit; + }; Keymapper(EventManager *eventMan); ~Keymapper(); @@ -105,6 +108,9 @@ public: void setEnabled(bool enabled) { _enabled = enabled; } + KeymapManager *getManager() { return _keymapMan; } + Stack<MapRecord>& getActiveStack() { return _activeMaps; } + private: void pushKeymap(Keymap *newMap, bool inherit); @@ -116,11 +122,6 @@ private: bool _enabled; - struct MapRecord { - Keymap* keymap; - bool inherit; - }; - Stack<MapRecord> _activeMaps; }; diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp index 456d7a2f8e..ef9846f34e 100644 --- a/backends/keymapper/remap-dialog.cpp +++ b/backends/keymapper/remap-dialog.cpp @@ -35,39 +35,49 @@ enum { }; RemapDialog::RemapDialog() - : Dialog("remap"), _activeRemapAction(0), _topAction(0), _remapTimeout(0) { + : Dialog("remap"), _keymapTable(0), _activeRemapAction(0), _topAction(0), _remapTimeout(0) { const int screenW = g_system->getOverlayWidth(); const int screenH = g_system->getOverlayHeight(); _keymapper = g_system->getEventManager()->getKeymapper(); assert(_keymapper); - _activeKeymaps = &_keymapper->_activeMaps; + int labelWidth = g_gui.evaluator()->getVar("remap_popup_labelW"); + _kmPopUp = new GUI::PopUpWidget(this, "remap_popup", "Keymap: ", labelWidth); + + _scrollBar = new GUI::ScrollBarWidget(this, 0, 0, 0, 0); +} + +RemapDialog::~RemapDialog() { + if (_keymapTable) free(_keymapTable); +} - KeymapManager::Domain *_globalKeymaps = &_keymapper->_keymapMan->getGlobalDomain(); +void RemapDialog::open() { + _activeKeymaps = &_keymapper->getActiveStack(); + if (_activeKeymaps->size() > 0) { + _kmPopUp->appendEntry(_activeKeymaps->top().keymap->getName() + " (Active)"); + } + + KeymapManager::Domain *_globalKeymaps = &_keymapper->getManager()->getGlobalDomain(); KeymapManager::Domain *_gameKeymaps = 0; + int keymapCount = 0; - if (_globalKeymaps->count() == 0) { + if (_globalKeymaps->count() == 0) _globalKeymaps = 0; - } else { + else keymapCount += _globalKeymaps->count(); - } + if (ConfMan.getActiveDomain() != 0) { - _gameKeymaps = &_keymapper->_keymapMan->getGameDomain(); - if (_gameKeymaps->count() == 0) { + _gameKeymaps = &_keymapper->getManager()->getGameDomain(); + if (_gameKeymaps->count() == 0) _gameKeymaps = 0; - } else { + else keymapCount += _gameKeymaps->count(); - } } + _keymapTable = (Keymap**)malloc(sizeof(Keymap*) * keymapCount); - int labelWidth = g_gui.evaluator()->getVar("remap_popup_labelW"); - _kmPopUp = new GUI::PopUpWidget(this, "remap_popup", "Keymap: ", labelWidth); - if (_activeKeymaps->size() > 0) { - _kmPopUp->appendEntry(_activeKeymaps->top().keymap->getName() + " (Active)"); - } KeymapManager::Domain::iterator it; uint32 idx = 0; if (_globalKeymaps) { @@ -85,20 +95,81 @@ RemapDialog::RemapDialog() } } - setupWidgets(); -} - -RemapDialog::~RemapDialog() { - free(_keymapTable); -} - -void RemapDialog::open() { Dialog::open(); _kmPopUp->setSelected(0); loadKeymap(); } +void RemapDialog::close() { + _kmPopUp->clearEntries(); + if (_keymapTable) { + free(_keymapTable); + _keymapTable = 0; + } + Dialog::close(); +} + +void RemapDialog::reflowLayout() { + int labelWidth = g_gui.evaluator()->getVar("remap_popup_labelW"); + _kmPopUp->changeLabelWidth(labelWidth); + + int scrollbarWidth, buttonHeight; + if (g_gui.getWidgetSize() == GUI::kBigWidgetSize) { + buttonHeight = GUI::kBigButtonHeight; + scrollbarWidth = GUI::kBigScrollBarWidth; + } else { + buttonHeight = GUI::kButtonHeight; + scrollbarWidth = GUI::kNormalScrollBarWidth; + } + int areaX = g_gui.evaluator()->getVar("remap_keymap_area.x"); + int areaY = g_gui.evaluator()->getVar("remap_keymap_area.y"); + int areaW = g_gui.evaluator()->getVar("remap_keymap_area.w"); + int areaH = g_gui.evaluator()->getVar("remap_keymap_area.h"); + int spacing = g_gui.evaluator()->getVar("remap_spacing"); + _colCount = g_gui.evaluator()->getVar("remap_col_count"); + if (_colCount <= 0) + error("remap_col_count must be >= 0"); + _rowCount = (areaH + spacing) / (buttonHeight + spacing); + if (_rowCount <= 0) + error("Remap dialog too small to display any keymaps!"); + int colWidth = (areaW - scrollbarWidth - _colCount * spacing) / _colCount; + + _scrollBar->resize(areaX + areaW - scrollbarWidth, areaY, scrollbarWidth, areaH); + _scrollBar->_entriesPerPage = _rowCount; + _scrollBar->_numEntries = 1; + _scrollBar->recalc(); + + uint textYOff = (buttonHeight - kLineHeight) / 2; + uint oldSize = _keymapWidgets.size(); + uint newSize = _rowCount * _colCount; + _keymapWidgets.reserve(newSize); + for (uint i = 0; i < newSize; i++) { + ActionWidgets widg; + if (i >= _keymapWidgets.size()) { + widg.actionText = + new GUI::StaticTextWidget(this, 0, 0, 0, 0, "", Graphics::kTextAlignRight); + widg.keyButton = + new GUI::ButtonWidget(this, 0, 0, 0, 0, "", kRemapCmd + i); + _keymapWidgets.push_back(widg); + } else { + widg = _keymapWidgets[i]; + } + uint x = areaX + (i % _colCount) * (colWidth + spacing); + uint y = areaY + (i / _colCount) * (buttonHeight + spacing); + widg.actionText->resize(x, y + textYOff, colWidth / 2, kLineHeight); + widg.keyButton->resize(x + colWidth / 2, y, colWidth / 2, buttonHeight); + } + while (oldSize > newSize) { + ActionWidgets widg = _keymapWidgets.remove_at(--oldSize); + removeWidget(widg.actionText); + delete widg.actionText; + removeWidget(widg.keyButton); + delete widg.keyButton; + } + Dialog::reflowLayout(); +} + void RemapDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) { if (cmd >= kRemapCmd && cmd < kRemapCmd + _keymapWidgets.size()) { startRemapping(cmd - kRemapCmd); @@ -155,7 +226,7 @@ void RemapDialog::handleTickle() { void RemapDialog::loadKeymap() { _currentActions.clear(); if (_activeKeymaps->size() > 0 && _kmPopUp->getSelected() == 0) { - List<const HardwareKey*> freeKeys (_keymapper->_keymapMan->getHardwareKeySet()->getHardwareKeys()); + List<const HardwareKey*> freeKeys (_keymapper->getManager()->getHardwareKeySet()->getHardwareKeys()); // add most active keymap's keys Keymapper::MapRecord top = _activeKeymaps->top(); @@ -242,47 +313,5 @@ void RemapDialog::refreshKeymap() { draw(); } -void RemapDialog::setupWidgets() { - - int scrollbarWidth, buttonHeight; - if (g_gui.getWidgetSize() == GUI::kBigWidgetSize) { - buttonHeight = GUI::kBigButtonHeight; - scrollbarWidth = GUI::kBigScrollBarWidth; - } else { - buttonHeight = GUI::kButtonHeight; - scrollbarWidth = GUI::kNormalScrollBarWidth; - } - int areaX = g_gui.evaluator()->getVar("remap_keymap_area.x"); - int areaY = g_gui.evaluator()->getVar("remap_keymap_area.y"); - int areaW = g_gui.evaluator()->getVar("remap_keymap_area.w"); - int areaH = g_gui.evaluator()->getVar("remap_keymap_area.h"); - int spacing = g_gui.evaluator()->getVar("remap_spacing"); - - _colCount = g_gui.evaluator()->getVar("remap_col_count"); - _rowCount = (areaH + spacing) / (buttonHeight + spacing); - int colWidth = (areaW - scrollbarWidth - _colCount * spacing) / _colCount; - - //_container = new GUI::ContainerWidget(this, areaX, areaY, areaW, areaH); - //_container->setHints(GUI::THEME_HINT_USE_SHADOW); - - _scrollBar = new GUI::ScrollBarWidget(this, - areaX + areaW - scrollbarWidth, areaY, scrollbarWidth, areaH); - _scrollBar->_entriesPerPage = _rowCount; - _scrollBar->_numEntries = 1; - _scrollBar->recalc(); - - uint textYOff = (buttonHeight - kLineHeight) / 2; - int n = _rowCount * _colCount; - for (int i = 0; i < n; i++) { - uint x = areaX + (i % _colCount) * (colWidth + spacing); - uint y = areaY + (i / _colCount) * (buttonHeight + spacing); - ActionWidgets widg; - widg.actionText = new GUI::StaticTextWidget(this, x, y + textYOff, - colWidth / 2, kLineHeight, "", Graphics::kTextAlignRight); - widg.keyButton = new GUI::ButtonWidget(this, x + colWidth / 2, - y, colWidth / 2, buttonHeight, "", kRemapCmd + i); - _keymapWidgets.push_back(widg); - } -} } // end of namespace Common diff --git a/backends/keymapper/remap-dialog.h b/backends/keymapper/remap-dialog.h index a9680a0f7a..0bcfee0d29 100644 --- a/backends/keymapper/remap-dialog.h +++ b/backends/keymapper/remap-dialog.h @@ -40,6 +40,8 @@ public: RemapDialog(); virtual ~RemapDialog(); virtual void open(); + virtual void close(); + virtual void reflowLayout(); virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); virtual void handleKeyUp(Common::KeyState state); virtual void handleMouseDown(int x, int y, int button, int clickCount); @@ -58,7 +60,6 @@ protected: void loadKeymap(); void refreshKeymap(); - void setupWidgets(); void startRemapping(uint i); void stopRemapping(); diff --git a/backends/platform/sdl/events.cpp b/backends/platform/sdl/events.cpp index 4731ae59c9..ad62ddb6f5 100644 --- a/backends/platform/sdl/events.cpp +++ b/backends/platform/sdl/events.cpp @@ -566,6 +566,10 @@ void OSystem_SDL::setupKeymapper() { ADD_KEYDOWN_EVENT(KEYCODE_d, 'd', 0); specific->addAction(act); + act = new Action('RUN_', "Run"); + ADD_KEYDOWN_EVENT(KEYCODE_r, 'r', 0); + specific->addAction(act); + #undef ADD_KEYDOWN_EVENT mapper->addGlobalKeymap(global); |