From 831edca24eed0b1aae871bc537d3841f5622d916 Mon Sep 17 00:00:00 2001 From: stephena Date: Sun, 31 Mar 2013 20:54:14 +0000 Subject: [PATCH] Finalized tab handling for dialogs containing multiple tabs (for now, only the debugger, but might as well deal with the problem in a general way once and for all). The Shift-Left/Right keys now work as they did before, and switch between tabs in a tabset. For dialogs with multiple tabs, it now selects among those tabs where the focused object is. Clicking on another tabset then changes the focus, and allows the same keys to switch among *that* tabset. Now I can finally start the cart-specific bankswitch UI items. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2679 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/emucore/CartDPCPlus.hxx | 2 +- src/gui/Dialog.cxx | 77 +++++++++++++------------------------ src/gui/Dialog.hxx | 1 + src/gui/GameInfoDialog.cxx | 1 - src/gui/InputDialog.cxx | 2 - src/gui/RomAuditDialog.cxx | 1 - src/gui/TabWidget.cxx | 13 ++----- src/gui/TabWidget.hxx | 21 +++++----- src/gui/UIDialog.cxx | 1 - src/gui/VideoDialog.cxx | 1 - 10 files changed, 43 insertions(+), 77 deletions(-) diff --git a/src/emucore/CartDPCPlus.hxx b/src/emucore/CartDPCPlus.hxx index d8fb41ca1..b2d2a6db0 100644 --- a/src/emucore/CartDPCPlus.hxx +++ b/src/emucore/CartDPCPlus.hxx @@ -129,7 +129,7 @@ class CartridgeDPCPlus : public Cartridge @return The name of the object */ - string name() const { return "CartridgeDPCPlus"; } + string name() const { return "CartridgeDPC+"; } public: /** diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index c89f9d6a5..2366edb70 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -212,7 +212,8 @@ void Dialog::setFocus(Widget* w) // Redraw widgets for new focus _focusedWidget = Widget::setFocusForChain(this, getFocusList(), w, 0); -cerr << "set focus for " << _focusedWidget << endl; + // Update current tab based on new focused widget + getTabIdForWidget(_focusedWidget); } } @@ -228,7 +229,6 @@ void Dialog::buildCurrentFocusList(int tabID) Widget* tabFocusWidget = 0; if(tabID >= 0 && tabID < (int)_myTabList.size()) { -cerr << "save tab, move to next\n"; // Save focus in previously selected tab column, // and get focus for new tab column TabFocus& tabfocus = _myTabList[tabID]; @@ -238,24 +238,12 @@ cerr << "save tab, move to next\n"; _tabID = tabID; } - // Special case for dialogs containing only one tab widget, with all items - // arranged in separate tabs - bool containsSingleTab = _myFocus.list.size() == 1 && _myTabList.size() == 1; - - // A dialog containing only one tabwidget should be added first - if(containsSingleTab) - { - _focusList.push_back(_myFocus.list); - _focusedWidget = _focusList[0]; - } - - // Now add appropriate items from tablist (if present) + // Add appropriate items from tablist (if present) for(uInt32 id = 0; id < _myTabList.size(); ++id) _myTabList[id].appendFocusList(_focusList); // Add remaining items from main focus list - if(!containsSingleTab) - _focusList.push_back(_myFocus.list); + _focusList.push_back(_myFocus.list); // Add button group at end of current focus list // We do it this way for TabWidget, so that buttons are scanned @@ -266,9 +254,7 @@ cerr << "save tab, move to next\n"; // Finally, the moment we've all been waiting for :) // Set the actual focus widget if(tabFocusWidget) -{cerr << "tab focus changed\n"; _focusedWidget = tabFocusWidget; -} else if(!_focusedWidget && _focusList.size() > 0) _focusedWidget = _focusList[0]; } @@ -549,6 +535,9 @@ bool Dialog::handleNavEvent(Event::Type e) { _focusedWidget = Widget::setFocusForChain(this, getFocusList(), _focusedWidget, -1); + // Update current tab based on new focused widget + getTabIdForWidget(_focusedWidget); + return true; } break; @@ -558,6 +547,9 @@ bool Dialog::handleNavEvent(Event::Type e) { _focusedWidget = Widget::setFocusForChain(this, getFocusList(), _focusedWidget, +1); + // Update current tab based on new focused widget + getTabIdForWidget(_focusedWidget); + return true; } break; @@ -587,30 +579,31 @@ bool Dialog::handleNavEvent(Event::Type e) return false; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Dialog::getTabIdForWidget(Widget* w) +{ + if(_myTabList.size() == 0) + return; + + for(uInt32 id = 0; id < _myTabList.size(); ++id) + { + if(w->_boss == _myTabList[id].widget) + { + _tabID = id; + return; + } + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Dialog::cycleTab(int direction) { -cerr << "cycle " << (direction < 0 ? "left" : "right") << ", tabID = " << _tabID << endl; - if(_tabID >= 0 && _tabID < (int)_myTabList.size()) { _myTabList[_tabID].widget->cycleTab(direction); return true; } return false; - -#if 0 - if(key == KBDK_LEFT && _ourTab) // left arrow - { - _ourTab->cycleTab(-1); - return; - } - else if(key == KBDK_RIGHT && _ourTab) // right arrow - { - _ourTab->cycleTab(+1); - return; - } -#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -711,28 +704,10 @@ void Dialog::TabFocus::appendFocusList(WidgetArray& list) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::TabFocus::saveCurrentFocus(Widget* w) { -#if 1 - if(currentTab >= 0 && currentTab < focus.size()) - { - cerr << "chain len = " << focus[currentTab].list.size() << endl; - - if(Widget::isWidgetInChain(focus[currentTab].list, w)) - { - cerr << "saving widget\n"; - focus[currentTab].widget = w; - } - else - cerr << "not in chain\n"; -} - -#else if(currentTab >= 0 && currentTab < focus.size() && Widget::isWidgetInChain(focus[currentTab].list, w)) -{cerr << "saving widget\n"; focus[currentTab].widget = w; } -#endif -} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Widget* Dialog::TabFocus::getNewFocus() diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index 9540ab4c8..3c42b0391 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -100,6 +100,7 @@ class Dialog : public GuiObject private: void buildCurrentFocusList(int tabID = -1); bool handleNavEvent(Event::Type e); + void getTabIdForWidget(Widget* w); bool cycleTab(int direction); protected: diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index ac4822882..cba5c4bb2 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -70,7 +70,6 @@ GameInfoDialog::GameInfoDialog( myTab = new TabWidget(this, font, xpos, ypos, _w - 2*xpos, _h - buttonHeight - fontHeight - ifont.getLineHeight() - 20); addTabWidget(myTab); - addFocusWidget(myTab); // 1) Cartridge properties wid.clear(); diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index ea219f2f5..41c167597 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -56,8 +56,6 @@ InputDialog::InputDialog(OSystem* osystem, DialogContainer* parent, xpos = 2; ypos = vBorder; myTab = new TabWidget(this, font, xpos, ypos, _w - 2*xpos, _h - buttonHeight - 20); addTabWidget(myTab); - wid.push_back(myTab); - addToFocusList(wid); // 1) Event mapper for emulation actions tabID = myTab->addTab("Emul. Events"); diff --git a/src/gui/RomAuditDialog.cxx b/src/gui/RomAuditDialog.cxx index 18cd2632f..118606804 100644 --- a/src/gui/RomAuditDialog.cxx +++ b/src/gui/RomAuditDialog.cxx @@ -92,7 +92,6 @@ RomAuditDialog::RomAuditDialog(OSystem* osystem, DialogContainer* parent, kTextAlignLeft); // Add OK and Cancel buttons - wid.clear(); addOKCancelBGroup(wid, font, "Audit", "Done"); addBGroupToFocusList(wid); diff --git a/src/gui/TabWidget.cxx b/src/gui/TabWidget.cxx index 12e5c1699..c41f144ad 100644 --- a/src/gui/TabWidget.cxx +++ b/src/gui/TabWidget.cxx @@ -73,14 +73,7 @@ int TabWidget::getChildY() const int TabWidget::addTab(const string& title) { // Add a new tab page - Tab newTab; - newTab.title = title; - newTab.firstWidget = NULL; - newTab.parentWidget = NULL; - newTab.enabled = true; - - _tabs.push_back(newTab); - + _tabs.push_back(Tab(title)); int numTabs = _tabs.size(); // Determine the new tab width @@ -145,7 +138,7 @@ void TabWidget::updateActiveTab() void TabWidget::activateTabs() { for(unsigned int i = 0; i <_tabs.size(); ++i) - sendCommand(kTabChangedCmd, i-1, -1); + sendCommand(kTabChangedCmd, i-1, _id); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -315,7 +308,7 @@ void TabWidget::drawWidget(bool hilite) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Widget *TabWidget::findWidget(int x, int y) +Widget* TabWidget::findWidget(int x, int y) { if (y < _tabHeight) { diff --git a/src/gui/TabWidget.hxx b/src/gui/TabWidget.hxx index 0036703a2..0764b0430 100644 --- a/src/gui/TabWidget.hxx +++ b/src/gui/TabWidget.hxx @@ -31,14 +31,6 @@ class TabWidget : public Widget, public CommandSender { - struct Tab { - string title; - Widget* firstWidget; - Widget* parentWidget; - bool enabled; - }; - typedef Common::Array TabList; - public: TabWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h); ~TabWidget(); @@ -77,7 +69,18 @@ class TabWidget : public Widget, public CommandSender virtual void drawWidget(bool hilite); virtual Widget* findWidget(int x, int y); - protected: + private: + struct Tab { + string title; + Widget* firstWidget; + Widget* parentWidget; + bool enabled; + + Tab(const string& t = "", Widget* first = 0, Widget* parent = 0, bool e = true) + : title(t), firstWidget(first), parentWidget(parent), enabled(e) { } + }; + typedef Common::Array TabList; + TabList _tabs; int _tabWidth; int _tabHeight; diff --git a/src/gui/UIDialog.cxx b/src/gui/UIDialog.cxx index 7ebc99cf4..927559030 100644 --- a/src/gui/UIDialog.cxx +++ b/src/gui/UIDialog.cxx @@ -61,7 +61,6 @@ UIDialog::UIDialog(OSystem* osystem, DialogContainer* parent, xpos = ypos = vBorder; myTab = new TabWidget(this, font, xpos, ypos, _w - 2*xpos, _h - buttonHeight - 20); addTabWidget(myTab); - addFocusWidget(myTab); ////////////////////////////////////////////////////////// // 1) Launcher options diff --git a/src/gui/VideoDialog.cxx b/src/gui/VideoDialog.cxx index 141a2c3be..49d06f2e8 100644 --- a/src/gui/VideoDialog.cxx +++ b/src/gui/VideoDialog.cxx @@ -66,7 +66,6 @@ VideoDialog::VideoDialog(OSystem* osystem, DialogContainer* parent, xpos = ypos = 5; myTab = new TabWidget(this, font, xpos, ypos, _w - 2*xpos, _h - buttonHeight - 20); addTabWidget(myTab); - addFocusWidget(myTab); ////////////////////////////////////////////////////////// // 1) General options