From a69a87c5a81ddbf25a25c5549259da550d207bda Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 23 Jun 2012 02:46:01 +0300 Subject: Improve a bit iterators again. --- src/guichan/widgets/dropdown.cpp | 4 +--- src/guichan/widgets/listbox.cpp | 4 +--- src/guichan/widgets/radiobutton.cpp | 12 ++++-------- src/guichan/widgets/scrollarea.cpp | 28 ++++++++++++---------------- src/guichan/widgets/tabbedarea.cpp | 3 +-- src/guichan/widgets/textbox.cpp | 7 ++----- src/guichan/widgets/window.cpp | 5 ++--- 7 files changed, 23 insertions(+), 40 deletions(-) (limited to 'src/guichan/widgets') diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp index ead4e7815..9f2180a72 100644 --- a/src/guichan/widgets/dropdown.cpp +++ b/src/guichan/widgets/dropdown.cpp @@ -411,9 +411,7 @@ namespace gcn void DropDown::distributeValueChangedEvent() { - SelectionListenerIterator iter; - - for (iter = mSelectionListeners.begin(); + for (SelectionListenerIterator iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter) { diff --git a/src/guichan/widgets/listbox.cpp b/src/guichan/widgets/listbox.cpp index 3152890bc..ac71852e1 100644 --- a/src/guichan/widgets/listbox.cpp +++ b/src/guichan/widgets/listbox.cpp @@ -268,9 +268,7 @@ namespace gcn void ListBox::distributeValueChangedEvent() { - SelectionListenerIterator iter; - - for (iter = mSelectionListeners.begin(); + for (SelectionListenerIterator iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++ iter) { diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp index c5c0b1ebd..26bd7e44c 100644 --- a/src/guichan/widgets/radiobutton.cpp +++ b/src/guichan/widgets/radiobutton.cpp @@ -103,10 +103,8 @@ namespace gcn { if (selected && mGroup != "") { - GroupIterator iter, iterEnd; - iterEnd = mGroupMap.upper_bound(mGroup); - - for (iter = mGroupMap.lower_bound(mGroup); + for (GroupIterator iter = mGroupMap.lower_bound(mGroup), + iterEnd = mGroupMap.upper_bound(mGroup); iter != iterEnd; ++ iter) { @@ -150,10 +148,8 @@ namespace gcn { if (mGroup != "") { - GroupIterator iter, iterEnd; - iterEnd = mGroupMap.upper_bound(mGroup); - - for (iter = mGroupMap.lower_bound(mGroup); + for (GroupIterator iter = mGroupMap.lower_bound(mGroup), + iterEnd = mGroupMap.upper_bound(mGroup); iter != iterEnd; ++ iter) { diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp index a9d84dd98..c0734a926 100644 --- a/src/guichan/widgets/scrollarea.cpp +++ b/src/guichan/widgets/scrollarea.cpp @@ -536,10 +536,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.height / 2; - int h = w / 2 + 2; - for (i = 0; i < w / 2; ++i) + const int w = dim.height / 2; + const int h = w / 2 + 2; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(w - i + offset, i + h + offset, w + i + offset, i + h + offset); @@ -595,10 +594,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.height / 2; - int h = w + 1; - for (i = 0; i < w / 2; ++i) + const int w = dim.height / 2; + const int h = w + 1; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(w - i + offset, -i + h + offset, w + i + offset, -i + h + offset); @@ -654,10 +652,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.width / 2; - int h = w - 2; - for (i = 0; i < w / 2; ++i) + const int w = dim.width / 2; + const int h = w - 2; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(i + h + offset, w - i + offset, i + h + offset, w + i + offset); @@ -713,10 +710,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.width / 2; - int h = w + 1; - for (i = 0; i < w / 2; ++i) + const int w = dim.width / 2; + const int h = w + 1; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(-i + h + offset, w - i + offset, -i + h + offset, w + i + offset); diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp index fb6619bed..a4179db5e 100644 --- a/src/guichan/widgets/tabbedarea.cpp +++ b/src/guichan/widgets/tabbedarea.cpp @@ -160,8 +160,7 @@ namespace gcn int TabbedArea::getSelectedTabIndex() const { - unsigned int i; - for (i = 0; i < mTabs.size(); i++) + for (unsigned int i = 0; i < mTabs.size(); i++) { if (mTabs[i].first == mSelectedTab) return i; diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp index 2c6066976..0103cdb99 100644 --- a/src/guichan/widgets/textbox.cpp +++ b/src/guichan/widgets/textbox.cpp @@ -114,8 +114,6 @@ namespace gcn void TextBox::draw(Graphics* graphics) { - unsigned int i; - if (mOpaque) { graphics->setColor(getBackgroundColor()); @@ -132,7 +130,7 @@ namespace gcn graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); - for (i = 0; i < mTextRows.size(); i++) + for (size_t i = 0; i < mTextRows.size(); i++) { // Move the text one pixel so we can have a caret before a letter. graphics->drawText(mTextRows[i], 1, i * getFont()->getHeight()); @@ -170,9 +168,8 @@ namespace gcn void TextBox::adjustSize() { - unsigned int i; int width = 0; - for (i = 0; i < mTextRows.size(); ++i) + for (size_t i = 0; i < mTextRows.size(); ++i) { int w = getFont()->getWidth(mTextRows[i]); if (width < w) diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp index c7ed8a69e..1a2279811 100644 --- a/src/guichan/widgets/window.cpp +++ b/src/guichan/widgets/window.cpp @@ -189,10 +189,9 @@ namespace gcn void Window::resizeToContent() { - WidgetListConstIterator it; - int w = 0, h = 0; - for (it = mWidgets.begin(); it != mWidgets.end(); ++ it) + for (WidgetListConstIterator it = mWidgets.begin(); + it != mWidgets.end(); ++ it) { if ((*it)->getX() + (*it)->getWidth() > w) w = (*it)->getX() + (*it)->getWidth(); -- cgit v1.2.3-60-g2f50