diff options
author | Neeraj Kumar | 2010-07-17 22:32:31 +0000 |
---|---|---|
committer | Neeraj Kumar | 2010-07-17 22:32:31 +0000 |
commit | fd157b47a3ac31cd2d22875b7d0f7bf5c3c0bf49 (patch) | |
tree | 7e9b2ab882866310c3df87cdc8a60c471cd3576f | |
parent | 407d65068a79693f42836c36d6394ef310b5238f (diff) | |
download | scummvm-rg350-fd157b47a3ac31cd2d22875b7d0f7bf5c3c0bf49.tar.gz scummvm-rg350-fd157b47a3ac31cd2d22875b7d0f7bf5c3c0bf49.tar.bz2 scummvm-rg350-fd157b47a3ac31cd2d22875b7d0f7bf5c3c0bf49.zip |
Implemented scrollable checkbox like behaviour using ListWidget
svn-id: r50971
-rw-r--r-- | engines/testbed/config.cpp | 85 | ||||
-rw-r--r-- | engines/testbed/config.h | 54 | ||||
-rw-r--r-- | engines/testbed/testbed.h | 6 |
3 files changed, 93 insertions, 52 deletions
diff --git a/engines/testbed/config.cpp b/engines/testbed/config.cpp index f6687d1803..44f9faffd7 100644 --- a/engines/testbed/config.cpp +++ b/engines/testbed/config.cpp @@ -27,49 +27,71 @@ namespace Testbed { -TestbedOptionsDialog::TestbedOptionsDialog() : GUI::OptionsDialog("Select", 120, 120, 360, 200), _hOffset(15), _vOffset(15), _boxWidth(300), _boxHeight(10) { - new GUI::StaticTextWidget(this, _hOffset, _vOffset, _boxWidth, _boxHeight, "Select testsuites to Execute", Graphics::kTextAlignCenter); - _vOffset += 20; - addCheckbox("FS"); - addCheckbox("GFX"); - addCheckbox("Savegames"); - addCheckbox("Misc"); - addCheckbox("Events"); - new GUI::ButtonWidget(this, 80 , _vOffset + 10, 80, 25, "Continue", GUI::kOKCmd, 'C'); - new GUI::ButtonWidget(this, 200, _vOffset + 10, 80, 25, "Exit", GUI::kCloseCmd, 'X'); -} +TestbedOptionsDialog::TestbedOptionsDialog(Common::Array<Testsuite *> &tsList, TestbedConfigManager *tsConfMan) : GUI::Dialog("Browser") { + + _testbedConfMan = tsConfMan; + + new GUI::StaticTextWidget(this, "Browser.Headline", "Select testsuites to Execute, selected entries are shown in dark"); + _testListDisplay = new TestbedListWidget(this, "Browser.List"); + _testListDisplay->setNumberingMode(GUI::kListNumberingOff); -TestbedOptionsDialog::~TestbedOptionsDialog() {} + // Construct a String Array + Common::Array<Testsuite *>::const_iterator iter; -void TestbedOptionsDialog::addCheckbox(const Common::String &tsName) { - _checkBoxes.push_back(new GUI::CheckboxWidget(this, _hOffset, _vOffset, _boxWidth, _boxHeight, tsName)); - _vOffset += 20; + for (iter = tsList.begin(); iter != tsList.end(); iter++) { + _testSuiteArray.push_back((*iter)->getName()); + _colors.push_back(GUI::ThemeEngine::kFontColorAlternate); + } + + _testListDisplay->setList(_testSuiteArray, &_colors); + + new GUI::ButtonWidget(this, "Browser.Cancel", "Continue", GUI::kCloseCmd, 'C'); + // XXX: Add more commands for this + new GUI::ButtonWidget(this, "Browser.Choose", "Exit", GUI::kCloseCmd, 'X'); } -bool TestbedOptionsDialog::isEnabled(const Common::String &tsName) { - for (uint i = 0; i < _checkBoxes.size(); i++) { - if (_checkBoxes[i]->getLabel().equalsIgnoreCase(tsName)) { - return _checkBoxes[i]->getState(); +TestbedOptionsDialog::~TestbedOptionsDialog() {} + +void TestbedOptionsDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) { + Testsuite *ts; + switch (cmd) { + case kSelectionToggle: + ts = _testbedConfMan->getTestsuiteByName(_testListDisplay->getSelectedString()); + if (ts) { + ts->enable(!ts->isEnabled()); + _testListDisplay->changeColor(); } + default: + GUI::Dialog::handleCommand(sender, cmd, data); } - return false; } +bool TestbedConfigManager::isEnabled(const Common::String &tsName) { + Testsuite *ts = getTestsuiteByName(tsName); + return ts ? ts->isEnabled() : false; +} + + void TestbedConfigManager::enableTestsuite(const Common::String &name, bool enable) { + Testsuite *ts = getTestsuiteByName(name); + if (ts) { + ts->enable(enable); + } else { + warning("No matches found for %s\n", name.c_str()); + } +} + +Testsuite *TestbedConfigManager::getTestsuiteByName(const Common::String &name) { Common::Array<Testsuite *>::const_iterator iter; for (iter = _testsuiteList.begin(); iter != _testsuiteList.end(); iter++) { if (name.equalsIgnoreCase((*iter)->getName())) { - (*iter)->enable(enable); - break; + return *iter; } } - - return; + return 0; } - - void TestbedConfigManager::selectTestsuites() { @@ -96,7 +118,7 @@ void TestbedConfigManager::selectTestsuites() { if (Testsuite::handleInteractiveInput(prompt, "Proceed?", "Customize", kOptionRight)) { // Select testsuites using checkboxes - TestbedOptionsDialog tbd; + TestbedOptionsDialog tbd(_testsuiteList, this); tbd.runModal(); // check if user wanted to exit. @@ -104,15 +126,6 @@ void TestbedConfigManager::selectTestsuites() { return; } - // Enable selected testsuites - Common::String tsName; - for (uint i = 0; i < _testsuiteList.size(); i++) { - tsName = _testsuiteList[i]->getName(); - if (tbd.isEnabled(tsName)) { - enableTestsuite(tsName, true); - } - } - } } diff --git a/engines/testbed/config.h b/engines/testbed/config.h index 953524d618..656f2f8b89 100644 --- a/engines/testbed/config.h +++ b/engines/testbed/config.h @@ -25,36 +25,70 @@ #ifndef TESTBED_CONFIG_H #define TESTBED_CONFIG_H -#include "testbed/testsuite.h" + #include "common/array.h" +#include "common/str-array.h" +#include "common/tokenizer.h" + #include "gui/options.h" +#include "gui/ThemeEngine.h" +#include "gui/ListWidget.h" + +#include "testbed/testsuite.h" namespace Testbed { +enum { + kSelectionToggle = 99 // Some random Number +}; + class TestbedConfigManager { public: TestbedConfigManager(Common::Array<Testsuite *> &tList) : _testsuiteList(tList) {} ~TestbedConfigManager() {} void selectTestsuites(); + Testsuite *getTestsuiteByName(const Common::String &name); + bool isEnabled(const Common::String &tsName); private: Common::Array<Testsuite *> &_testsuiteList; void enableTestsuite(const Common::String &name, bool enable); void parseConfigFile() {} }; -class TestbedOptionsDialog : public GUI::OptionsDialog { +class TestbedListWidget : public GUI::ListWidget { public: - TestbedOptionsDialog(); + TestbedListWidget(GUI::Dialog *boss, const Common::String &name) : GUI::ListWidget(boss, name){} + void handleMouseUp(int x, int y, int button, int clickCount) { + // If the mouse is clicked once, toggle the selection as it happens in checkboxes. + sendCommand(kSelectionToggle, _selectedItem); + } + + void changeColor() { + // Using Font Color Mechanism to highlight selected entries. + // Might not be detectable in some cases + if (_listColors.size() >= 2) { + if (GUI::ThemeEngine::kFontColorNormal == _listColors[_selectedItem]) { + _listColors[_selectedItem] = GUI::ThemeEngine::kFontColorAlternate; + } else if (GUI::ThemeEngine::kFontColorAlternate == _listColors[_selectedItem]) { + _listColors[_selectedItem] = GUI::ThemeEngine::kFontColorNormal; + } + draw(); + } + } + +}; + +class TestbedOptionsDialog : public GUI::Dialog { +public: + TestbedOptionsDialog(Common::Array<Testsuite *> &tsList, TestbedConfigManager *tsConfMan); ~TestbedOptionsDialog(); - void addCheckbox(const Common::String &tsName); - bool isEnabled(const Common::String &tsName); + void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); private: - Common::Array<GUI::CheckboxWidget *> _checkBoxes; - const int _hOffset; // current offset from left - int _vOffset; // current offset from top - const int _boxWidth; - const int _boxHeight; + GUI::ListWidget::ColorList _colors; + Common::StringArray _testSuiteArray; + TestbedListWidget *_testListDisplay; + TestbedConfigManager *_testbedConfMan; }; } // End of namespace Testbed diff --git a/engines/testbed/testbed.h b/engines/testbed/testbed.h index 45aff05320..bee918cc57 100644 --- a/engines/testbed/testbed.h +++ b/engines/testbed/testbed.h @@ -46,12 +46,6 @@ public: virtual Common::Error run(); /** - * All testsuites are disabled by default - * To enable testsuite X, call enableTestsuite("X", true); - */ - void enableTestsuite(const Common::String &name, bool enable); - - /** * Invokes configured testsuites. */ void invokeTestsuites(); |