diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 13:24:16 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 21:23:10 +0100 |
commit | 306ad2effe4d0897453e61ad787e01dc47c33076 (patch) | |
tree | 75b8b291af55e80d01d9eb85afd7d465233a1a57 /src/gui/widgets | |
parent | 66599a9896e0cf69b58c0a73152aba4750d87af2 (diff) | |
download | mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.gz mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.bz2 mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.xz mana-306ad2effe4d0897453e61ad787e01dc47c33076.zip |
General code cleanups
* Use default member initializers
* Use range-based for loops
* Avoid needless pointer references for ShopItem::mDuplicates
* Removed type aliases that are only used once or twice
* Removed more unused includes
* Removed some unused functions
* Removed superfluous .c_str()
* Rely on default copy and assignment operators for Vector class
* Use std::unique_ptr in some places
* Removed duplicated mPlayerMoney updating in SellDialog
* Removed duplicated Game::handleInput call
* Removed unused SDLInput::mMouseInWindow
* Removed remnant of manual widget positioning in HelpWindow
* Removed superfluous initialization of static pointers
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/button.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/icon.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/icon.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/layout.cpp | 21 | ||||
-rw-r--r-- | src/gui/widgets/linkhandler.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/shopitems.cpp | 12 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 28 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 7 |
9 files changed, 37 insertions, 45 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index d40a54fb..28d16b72 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -61,8 +61,7 @@ static ButtonData const data[BUTTON_COUNT] = { { "button_disabled.png", 25, 23 } }; -Button::Button(): - mButtonIcon(nullptr) +Button::Button() { init(); adjustSize(); diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp index eaf5be1c..5becadd1 100644 --- a/src/gui/widgets/icon.cpp +++ b/src/gui/widgets/icon.cpp @@ -31,10 +31,8 @@ Icon::Icon(const std::string &file) {} Icon::Icon(Image *image) - : mImage(image) { - if (mImage) - setSize(mImage->getWidth(), mImage->getHeight()); + setImage(image); } void Icon::setImage(Image *image) diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h index 896b26c1..508d2095 100644 --- a/src/gui/widgets/icon.h +++ b/src/gui/widgets/icon.h @@ -62,7 +62,7 @@ class Icon : public gcn::Widget void draw(gcn::Graphics *g) override; private: - Image *mImage; + Image *mImage = nullptr; }; #endif // ICON_H diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index f7941889..c40a3b2c 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -37,13 +37,15 @@ LayoutCell &ContainerPlacer::operator() LayoutCell::~LayoutCell() { - if (mType == ARRAY) delete mArray; + if (mType == ARRAY) + delete mArray; } LayoutArray &LayoutCell::getArray() { assert(mType != WIDGET); - if (mType == ARRAY) return *mArray; + if (mType == ARRAY) + return *mArray; mArray = new LayoutArray; mType = ARRAY; mExtent[0] = 1; @@ -114,7 +116,8 @@ void LayoutArray::resizeGrid(int w, int h) { bool extW = w && w > (int)mSizes[0].size(), extH = h && h > (int)mSizes[1].size(); - if (!extW && !extH) return; + if (!extW && !extH) + return; if (extH) { @@ -177,8 +180,10 @@ LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) cell.mAlign[1] = LayoutCell::FILL; short &cs = mSizes[0][x]; short &rs = mSizes[1][y]; - if (cs == Layout::AUTO_DEF && w == 1) cs = 0; - if (rs == Layout::AUTO_DEF && h == 1) rs = 0; + if (cs == Layout::AUTO_DEF && w == 1) + cs = 0; + if (rs == Layout::AUTO_DEF && h == 1) + rs = 0; return cell; } @@ -218,7 +223,8 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const for (int gridX = 0; gridX < gridW; ++gridX) { LayoutCell const *cell = mCells[gridY][gridX]; - if (!cell || cell->mType == LayoutCell::NONE) continue; + if (!cell || cell->mType == LayoutCell::NONE) + continue; if (cell->mExtent[dim] == 1) { @@ -249,7 +255,8 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const } upp = upp + mSpacing; - if (nbFill == 0) return sizes; + if (nbFill == 0) + return sizes; for (int i = 0; i < nb; ++i) { diff --git a/src/gui/widgets/linkhandler.h b/src/gui/widgets/linkhandler.h index dab42a24..33263a25 100644 --- a/src/gui/widgets/linkhandler.h +++ b/src/gui/widgets/linkhandler.h @@ -31,7 +31,7 @@ class LinkHandler { public: - virtual ~LinkHandler() { } + virtual ~LinkHandler() = default; virtual void handleLink(const std::string &link) = 0; }; diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/widgets/shopitems.cpp index 91829131..031416e0 100644 --- a/src/gui/widgets/shopitems.cpp +++ b/src/gui/widgets/shopitems.cpp @@ -60,7 +60,7 @@ void ShopItems::addItem(int inventoryIndex, int id, int quantity, int price) if (item) { - item->addDuplicate (inventoryIndex, quantity); + item->addDuplicate(inventoryIndex, quantity); } else { @@ -87,15 +87,11 @@ void ShopItems::clear() ShopItem *ShopItems::findItem(int id) { - ShopItem *item; - - std::vector<ShopItem*>::iterator it; - for (it = mShopItems.begin(); it != mShopItems.end(); it++) + for (auto shopItem : mShopItems) { - item = *(it); - if (item->getId() == id) + if (shopItem->getId() == id) { - return item; + return shopItem; } } diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 644adf07..772a8e22 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -48,10 +48,10 @@ int TabbedArea::getNumberOfTabs() const Tab *TabbedArea::getTab(const std::string &name) const { - for (auto itr = mTabs.begin(); itr != mTabs.end(); ++itr) + for (const auto &[tab, _] : mTabs) { - if ((*itr).first->getCaption() == name) - return static_cast<Tab*>((*itr).first); + if (tab->getCaption() == name) + return static_cast<Tab*>(tab); } return nullptr; } @@ -113,8 +113,7 @@ void TabbedArea::removeTab(Tab *tab) mSelectedTab = nullptr; } - TabContainer::iterator iter; - for (iter = mTabs.begin(); iter != mTabs.end(); iter++) + for (auto iter = mTabs.begin(); iter != mTabs.end(); iter++) { if (iter->first == tab) { @@ -124,12 +123,11 @@ void TabbedArea::removeTab(Tab *tab) } } - std::vector<gcn::Tab*>::iterator iter2; - for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++) + for (auto iter = mTabsToDelete.begin(); iter != mTabsToDelete.end(); iter++) { - if (*iter2 == tab) + if (*iter == tab) { - mTabsToDelete.erase(iter2); + mTabsToDelete.erase(iter); delete tab; break; } @@ -154,9 +152,8 @@ void TabbedArea::mousePressed(gcn::MouseEvent &mouseEvent) { gcn::Widget *widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); - auto *tab = dynamic_cast<gcn::Tab*>(widget); - if (tab) + if (auto *tab = dynamic_cast<gcn::Tab*>(widget)) { setSelectedTab(tab); requestFocus(); @@ -205,9 +202,9 @@ void TabbedArea::widgetResized(const gcn::Event &event) void TabbedArea::updateTabsWidth() { mTabsWidth = 0; - for (const auto &tab : mTabs) + for (const auto &[tab, _] : mTabs) { - mTabsWidth += tab.first->getWidth(); + mTabsWidth += tab->getWidth(); } updateVisibleTabsWidth(); } @@ -255,10 +252,9 @@ void TabbedArea::adjustTabPositions() void TabbedArea::action(const gcn::ActionEvent& actionEvent) { - Widget* source = actionEvent.getSource(); - Tab* tab = dynamic_cast<Tab*>(source); + Widget *source = actionEvent.getSource(); - if (tab) + if (Tab *tab = dynamic_cast<Tab*>(source)) { setSelectedTab(tab); } diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 18e923bf..8e6dcb5f 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -112,9 +112,8 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener // Inherited from MouseListener void mousePressed(gcn::MouseEvent &mouseEvent) override; - private: - using TabContainer = std::vector<std::pair<gcn::Tab *, gcn::Widget *>>; + private: /** The tab arrows */ Button *mArrowButton[2]; diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 3b997ba8..9235f4b8 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -30,13 +30,10 @@ class TextInput; class ImageRect; class TextField; -using TextHistoryList = std::list<std::string>; -using TextHistoryIterator = TextHistoryList::iterator; - struct TextHistory { - TextHistoryList history; /**< Command history. */ - TextHistoryIterator current; /**< History iterator. */ + std::list<std::string> history; /**< Command history. */ + std::list<std::string>::iterator current; /**< History iterator. */ TextHistory() { current = history.end(); } |