summaryrefslogtreecommitdiff
path: root/src/guichan
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-23 02:46:01 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-23 02:48:43 +0300
commita69a87c5a81ddbf25a25c5549259da550d207bda (patch)
tree59f1a919b327912395ab84bab1684118bf0379be /src/guichan
parente646f2fae3f323b7faa26aa9540524d1765211ee (diff)
downloadmv-a69a87c5a81ddbf25a25c5549259da550d207bda.tar.gz
mv-a69a87c5a81ddbf25a25c5549259da550d207bda.tar.bz2
mv-a69a87c5a81ddbf25a25c5549259da550d207bda.tar.xz
mv-a69a87c5a81ddbf25a25c5549259da550d207bda.zip
Improve a bit iterators again.
Diffstat (limited to 'src/guichan')
-rw-r--r--src/guichan/basiccontainer.cpp39
-rw-r--r--src/guichan/defaultfont.cpp4
-rw-r--r--src/guichan/focushandler.cpp8
-rw-r--r--src/guichan/font.cpp9
-rw-r--r--src/guichan/gui.cpp9
-rw-r--r--src/guichan/widget.cpp30
-rw-r--r--src/guichan/widgets/dropdown.cpp4
-rw-r--r--src/guichan/widgets/listbox.cpp4
-rw-r--r--src/guichan/widgets/radiobutton.cpp12
-rw-r--r--src/guichan/widgets/scrollarea.cpp28
-rw-r--r--src/guichan/widgets/tabbedarea.cpp3
-rw-r--r--src/guichan/widgets/textbox.cpp7
-rw-r--r--src/guichan/widgets/window.cpp5
13 files changed, 62 insertions, 100 deletions
diff --git a/src/guichan/basiccontainer.cpp b/src/guichan/basiccontainer.cpp
index 76b671cfb..c74748622 100644
--- a/src/guichan/basiccontainer.cpp
+++ b/src/guichan/basiccontainer.cpp
@@ -66,8 +66,8 @@ namespace gcn
void BasicContainer::moveToTop(Widget* widget)
{
- WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
{
if (*iter == widget)
{
@@ -179,8 +179,8 @@ namespace gcn
x -= r.x;
y -= r.y;
- WidgetListCReverseIterator it;
- for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
+ for (WidgetListCReverseIterator it = mWidgets.rbegin();
+ it != mWidgets.rend(); ++ it)
{
if ((*it)->isVisible() && (*it)->getDimension()
.isPointInRect(x, y))
@@ -204,8 +204,8 @@ namespace gcn
if (mInternalFocusHandler)
return;
- WidgetListConstIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
{
(*iter)->_setFocusHandler(focusHandler);
}
@@ -226,8 +226,8 @@ namespace gcn
void BasicContainer::remove(Widget* widget)
{
- WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
{
if (*iter == widget)
{
@@ -244,9 +244,8 @@ namespace gcn
void BasicContainer::clear()
{
- WidgetListConstIterator iter;
-
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
{
(*iter)->_setFocusHandler(nullptr);
(*iter)->_setParent(nullptr);
@@ -260,8 +259,8 @@ namespace gcn
{
graphics->pushClipArea(getChildrenArea());
- WidgetListConstIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
{
if ((*iter)->isVisible())
{
@@ -290,9 +289,11 @@ namespace gcn
void BasicContainer::logicChildren()
{
- WidgetListConstIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
(*iter)->logic();
+ }
}
void BasicContainer::showWidgetPart(Widget* widget, Rectangle area)
@@ -325,8 +326,8 @@ namespace gcn
{
Widget::setInternalFocusHandler(focusHandler);
- WidgetListConstIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
{
if (!mInternalFocusHandler)
(*iter)->_setFocusHandler(_getFocusHandler());
@@ -337,8 +338,8 @@ namespace gcn
Widget* BasicContainer::findWidgetById(const std::string& id)
{
- WidgetListConstIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
{
if ((*iter)->getId() == id)
return (*iter);
diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp
index 70901bc8e..feeb91001 100644
--- a/src/guichan/defaultfont.cpp
+++ b/src/guichan/defaultfont.cpp
@@ -78,9 +78,7 @@ namespace gcn
void DefaultFont::drawString(Graphics* graphics, const std::string& text,
int x, int y)
{
- unsigned int i;
-
- for (i = 0; i< text.size(); ++i)
+ for (unsigned int i = 0; i< text.size(); ++i)
{
drawGlyph(graphics, text.at(i), x, y);
x += getWidth(text);
diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp
index e3610fb1e..839c35cc1 100644
--- a/src/guichan/focushandler.cpp
+++ b/src/guichan/focushandler.cpp
@@ -73,9 +73,8 @@ namespace gcn
if (!widget || widget == mFocusedWidget)
return;
- unsigned int i = 0;
int toBeFocusedIndex = -1;
- for (i = 0; i < mWidgets.size(); ++i)
+ for (unsigned int i = 0; i < mWidgets.size(); ++i)
{
if (mWidgets[i] == widget)
{
@@ -272,9 +271,8 @@ namespace gcn
if (isFocused(widget))
mFocusedWidget = nullptr;
- WidgetIterator iter;
-
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter)
+ for (WidgetIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++iter)
{
if ((*iter) == widget)
{
diff --git a/src/guichan/font.cpp b/src/guichan/font.cpp
index e2485eb0d..598b1610b 100644
--- a/src/guichan/font.cpp
+++ b/src/guichan/font.cpp
@@ -56,14 +56,9 @@ namespace gcn
{
int Font::getStringIndexAt(const std::string& text, int x) const
{
- unsigned int i;
- int size = 0;
-
- for (i = 0; i < text.size(); ++i)
+ for (unsigned int i = 0; i < text.size(); ++i)
{
- size = getWidth(text.substr(0, i));
-
- if (size > x)
+ if (getWidth(text.substr(0, i)) > x)
return i;
}
diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp
index 0a24d8b17..68cb83190 100644
--- a/src/guichan/gui.cpp
+++ b/src/guichan/gui.cpp
@@ -263,8 +263,8 @@ namespace gcn
while (!widgetWithMouseQueueCheckDone)
{
unsigned int iterations = 0;
- std::deque<Widget*>::iterator iter;
- for (iter = mWidgetWithMouseQueue.begin();
+ for (std::deque<Widget*>::iterator
+ iter = mWidgetWithMouseQueue.begin();
iter != mWidgetWithMouseQueue.end();
++ iter)
{
@@ -755,9 +755,8 @@ namespace gcn
void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent)
{
- KeyListenerListIterator it;
-
- for (it = mKeyListeners.begin(); it != mKeyListeners.end(); ++ it)
+ for (KeyListenerListIterator it = mKeyListeners.begin();
+ it != mKeyListeners.end(); ++ it)
{
switch (keyEvent.getType())
{
diff --git a/src/guichan/widget.cpp b/src/guichan/widget.cpp
index da221b8d5..8bae81141 100644
--- a/src/guichan/widget.cpp
+++ b/src/guichan/widget.cpp
@@ -94,9 +94,7 @@ namespace gcn
Widget::~Widget()
{
- DeathListenerIterator iter;
-
- for (iter = mDeathListeners.begin();
+ for (DeathListenerIterator iter = mDeathListeners.begin();
iter != mDeathListeners.end();
++iter)
{
@@ -122,8 +120,7 @@ namespace gcn
shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
- unsigned int i;
- for (i = 0; i < getFrameSize(); ++i)
+ for (unsigned int i = 0; i < getFrameSize(); ++i)
{
graphics->setColor(shadowColor);
graphics->drawLine(i, i, width - i, i);
@@ -471,8 +468,8 @@ namespace gcn
{
mGlobalFont = font;
- std::list<Widget*>::const_iterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter)
+ for (std::list<Widget*>::const_iterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++iter)
{
if (!(*iter)->mCurrentFont)
(*iter)->fontChanged();
@@ -649,9 +646,7 @@ namespace gcn
void Widget::distributeResizedEvent()
{
- WidgetListenerIterator iter;
-
- for (iter = mWidgetListeners.begin();
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
iter != mWidgetListeners.end();
++ iter)
{
@@ -662,9 +657,7 @@ namespace gcn
void Widget::distributeMovedEvent()
{
- WidgetListenerIterator iter;
-
- for (iter = mWidgetListeners.begin();
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
iter != mWidgetListeners.end();
++ iter)
{
@@ -675,9 +668,7 @@ namespace gcn
void Widget::distributeHiddenEvent()
{
- WidgetListenerIterator iter;
-
- for (iter = mWidgetListeners.begin();
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
iter != mWidgetListeners.end();
++ iter)
{
@@ -688,8 +679,7 @@ namespace gcn
void Widget::distributeActionEvent()
{
- ActionListenerIterator iter;
- for (iter = mActionListeners.begin();
+ for (ActionListenerIterator iter = mActionListeners.begin();
iter != mActionListeners.end();
++iter)
{
@@ -700,9 +690,7 @@ namespace gcn
void Widget::distributeShownEvent()
{
- WidgetListenerIterator iter;
-
- for (iter = mWidgetListeners.begin();
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
iter != mWidgetListeners.end();
++iter)
{
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();