diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/widgets/basiccontainer.cpp | 10 | ||||
-rw-r--r-- | src/gui/widgets/basiccontainer.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/tabstrip.cpp | 38 | ||||
-rw-r--r-- | src/gui/widgets/tabstrip.h | 4 | ||||
-rw-r--r-- | src/gui/windows/inventorywindow.cpp | 28 | ||||
-rw-r--r-- | src/gui/windows/inventorywindow.h | 6 |
6 files changed, 89 insertions, 0 deletions
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp index 4803373f2..a66a244a0 100644 --- a/src/gui/widgets/basiccontainer.cpp +++ b/src/gui/widgets/basiccontainer.cpp @@ -372,3 +372,13 @@ void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler) (*iter)->setFocusHandler(mInternalFocusHandler); } } + +Widget *BasicContainer::findFirstWidget(const std::set<Widget*> &list) +{ + FOR_EACHR (WidgetListReverseIterator, iter, mWidgets) + { + if (list.find(*iter) != list.end()) + return *iter; + } + return nullptr; +} diff --git a/src/gui/widgets/basiccontainer.h b/src/gui/widgets/basiccontainer.h index 85067daff..47fa2abc1 100644 --- a/src/gui/widgets/basiccontainer.h +++ b/src/gui/widgets/basiccontainer.h @@ -64,6 +64,7 @@ #ifndef GUI_WIDGETS_BASICCONTAINER_H #define GUI_WIDGETS_BASICCONTAINER_H +#include <set> #include <vector> #include "gui/widgets/widget.h" @@ -134,6 +135,8 @@ class BasicContainer notfinal : public Widget, virtual void death(const Event& event) override; + Widget *findFirstWidget(const std::set<Widget*> &list); + protected: /** * Adds a widget to the basic container. diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp index 7c6627fbf..644fa3d48 100644 --- a/src/gui/widgets/tabstrip.cpp +++ b/src/gui/widgets/tabstrip.cpp @@ -77,3 +77,41 @@ void TabStrip::action(const ActionEvent &event) } } } + +void TabStrip::nextTab() +{ + FOR_EACH (WidgetListConstIterator, iter, mWidgets) + { + Button *button = static_cast<Button*>(*iter); + if (button->isPressed2()) + { + button->setPressed(false); + ++iter; + if (iter == mWidgets.end()) + iter = mWidgets.begin(); + button = static_cast<Button*>(*iter); + action(ActionEvent(button, button->getActionEventId())); + return; + } + } +} + +void TabStrip::prevTab() +{ + FOR_EACH (WidgetListConstIterator, iter, mWidgets) + { + Button *button = static_cast<Button*>(*iter); + if (button->isPressed2()) + { + button->setPressed(false); + if (iter == mWidgets.begin()) + iter = mWidgets.end(); + if (iter == mWidgets.begin()) + return; + --iter; + button = static_cast<Button*>(*iter); + action(ActionEvent(button, button->getActionEventId())); + return; + } + } +} diff --git a/src/gui/widgets/tabstrip.h b/src/gui/widgets/tabstrip.h index a89dd5144..daadad35c 100644 --- a/src/gui/widgets/tabstrip.h +++ b/src/gui/widgets/tabstrip.h @@ -41,6 +41,10 @@ class TabStrip final : public WidgetGroup const override final A_WARN_UNUSED; void action(const ActionEvent &event) override final; + + void nextTab(); + + void prevTab(); }; #endif // GUI_WIDGETS_TABSTRIP_H diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index c1fea4158..ea3cc5ad3 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -54,6 +54,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/tabstrip.h" #include "gui/widgets/textfield.h" +#include "gui/widgets/windowcontainer.h" #include "net/inventoryhandler.h" @@ -746,6 +747,33 @@ bool InventoryWindow::isAnyInputFocused() return false; } +InventoryWindow *InventoryWindow::getFirstVisible() +{ + std::set<Widget*> list; + FOR_EACH (WindowList::const_iterator, it, invInstances) + { + if ((*it) && (*it)->isWindowVisible()) + list.insert(*it); + } + InventoryWindow *const window = dynamic_cast<InventoryWindow*>( + windowContainer->findFirstWidget(list)); + return window; +} + +void InventoryWindow::nextTab() +{ + InventoryWindow *const window = getFirstVisible(); + if (window) + window->mFilter->nextTab(); +} + +void InventoryWindow::prevTab() +{ + InventoryWindow *const window = getFirstVisible(); + if (window) + window->mFilter->prevTab(); +} + void InventoryWindow::widgetResized(const Event &event) { Window::widgetResized(event); diff --git a/src/gui/windows/inventorywindow.h b/src/gui/windows/inventorywindow.h index 98cac78a6..f2952c2f5 100644 --- a/src/gui/windows/inventorywindow.h +++ b/src/gui/windows/inventorywindow.h @@ -156,6 +156,12 @@ class InventoryWindow final : public Window, static bool isAnyInputFocused(); + static InventoryWindow *getFirstVisible(); + + static void nextTab(); + + static void prevTab(); + private: /** * Updates the weight bar. |