summaryrefslogtreecommitdiff
path: root/src/guichan
diff options
context:
space:
mode:
Diffstat (limited to 'src/guichan')
-rw-r--r--src/guichan/defaultfont.cpp2
-rw-r--r--src/guichan/focushandler.cpp30
-rw-r--r--src/guichan/font.cpp2
-rw-r--r--src/guichan/widgets/tabbedarea.cpp11
-rw-r--r--src/guichan/widgets/textbox.cpp10
5 files changed, 31 insertions, 24 deletions
diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp
index 8d0b23623..e6da87fcd 100644
--- a/src/guichan/defaultfont.cpp
+++ b/src/guichan/defaultfont.cpp
@@ -78,7 +78,7 @@ namespace gcn
void DefaultFont::drawString(Graphics* graphics, const std::string& text,
int x, int y)
{
- for (unsigned int i = 0; i< text.size(); ++i)
+ for (size_t i = 0, sz = text.size(); i < sz; ++i)
{
drawGlyph(graphics, text.at(i), x, y);
x += getWidth(text);
diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp
index 494a2a899..3a5424851 100644
--- a/src/guichan/focushandler.cpp
+++ b/src/guichan/focushandler.cpp
@@ -74,7 +74,7 @@ namespace gcn
return;
int toBeFocusedIndex = -1;
- for (unsigned int i = 0; i < mWidgets.size(); ++i)
+ for (unsigned int i = 0, sz = mWidgets.size(); i < sz; ++i)
{
if (mWidgets[i] == widget)
{
@@ -157,7 +157,8 @@ namespace gcn
{
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -166,7 +167,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
++ focusedWidget;
@@ -179,7 +180,7 @@ namespace gcn
-- i;
- if (focusedWidget >= static_cast<int>(mWidgets.size()))
+ if (focusedWidget >= sz)
focusedWidget = 0;
if (focusedWidget == focused)
@@ -212,7 +213,8 @@ namespace gcn
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++ i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -221,7 +223,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
-- focusedWidget;
@@ -235,7 +237,7 @@ namespace gcn
-- i;
if (focusedWidget <= 0)
- focusedWidget = static_cast<int>(mWidgets.size() - 1);
+ focusedWidget = sz - 1;
if (focusedWidget == focused)
return;
@@ -340,7 +342,8 @@ namespace gcn
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++ i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -350,7 +353,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
++ focusedWidget;
@@ -363,7 +366,7 @@ namespace gcn
-- i;
- if (focusedWidget >= static_cast<int>(mWidgets.size()))
+ if (focusedWidget >= sz)
focusedWidget = 0;
if (focusedWidget == focused)
@@ -408,7 +411,8 @@ namespace gcn
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++ i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -418,7 +422,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
-- focusedWidget;
@@ -432,7 +436,7 @@ namespace gcn
-- i;
if (focusedWidget <= 0)
- focusedWidget = static_cast<int>(mWidgets.size() - 1);
+ focusedWidget = sz - 1;
if (focusedWidget == focused)
return;
diff --git a/src/guichan/font.cpp b/src/guichan/font.cpp
index 6fec94121..ea4652814 100644
--- a/src/guichan/font.cpp
+++ b/src/guichan/font.cpp
@@ -56,7 +56,7 @@ namespace gcn
{
int Font::getStringIndexAt(const std::string& text, int x) const
{
- for (unsigned int i = 0; i < text.size(); ++i)
+ for (unsigned int i = 0, sz = text.size(); i < sz; ++i)
{
if (getWidth(text.substr(0, i)) > x)
return i;
diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp
index a4179db5e..487549b6a 100644
--- a/src/guichan/widgets/tabbedarea.cpp
+++ b/src/guichan/widgets/tabbedarea.cpp
@@ -88,7 +88,7 @@ namespace gcn
delete mWidgetContainer;
mWidgetContainer = nullptr;
- for (unsigned int i = 0; i < mTabsToDelete.size(); i++)
+ for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
{
delete mTabsToDelete[i];
mTabsToDelete[i] = nullptr;
@@ -160,7 +160,7 @@ namespace gcn
int TabbedArea::getSelectedTabIndex() const
{
- for (unsigned int i = 0; i < mTabs.size(); i++)
+ for (unsigned int i = 0, sz = mTabs.size(); i < sz; i++)
{
if (mTabs[i].first == mSelectedTab)
return i;
@@ -241,7 +241,7 @@ namespace gcn
{
int maxTabHeight = 0;
- for (unsigned int i = 0; i < mTabs.size(); i++)
+ for (size_t i = 0, sz = mTabs.size(); i < sz; i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
maxTabHeight = mTabs[i].first->getHeight();
@@ -258,14 +258,15 @@ namespace gcn
{
int maxTabHeight = 0;
unsigned int i;
- for (i = 0; i < mTabs.size(); i++)
+ const unsigned int sz = mTabs.size();
+ for (i = 0; i < sz; i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
maxTabHeight = mTabs[i].first->getHeight();
}
int x = 0;
- for (i = 0; i < mTabs.size(); i++)
+ for (i = 0; i < sz; i++)
{
Tab* tab = mTabs[i].first;
tab->setPosition(x, maxTabHeight - tab->getHeight());
diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp
index 6b03a1cb5..97256eb44 100644
--- a/src/guichan/widgets/textbox.cpp
+++ b/src/guichan/widgets/textbox.cpp
@@ -130,7 +130,7 @@ namespace gcn
graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
- for (size_t i = 0; i < mTextRows.size(); i++)
+ for (size_t i = 0, sz = mTextRows.size(); i < sz; i++)
{
// Move the text one pixel so we can have a caret before a letter.
graphics->drawText(mTextRows[i], 1,
@@ -170,7 +170,7 @@ namespace gcn
void TextBox::adjustSize()
{
int width = 0;
- for (size_t i = 0; i < mTextRows.size(); ++i)
+ for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i)
{
int w = getFont()->getWidth(mTextRows[i]);
if (width < w)
@@ -183,7 +183,8 @@ namespace gcn
void TextBox::setCaretPosition(unsigned int position)
{
- for (int row = 0; row < static_cast<int>(mTextRows.size()); row ++)
+ for (int row = 0, sz = static_cast<int>(mTextRows.size());
+ row < sz; row ++)
{
if (position <= mTextRows[row].size())
{
@@ -280,7 +281,8 @@ namespace gcn
int i;
std::string text;
- for (i = 0; i < static_cast<int>(mTextRows.size()) - 1; ++ i)
+ const int sz = static_cast<int>(mTextRows.size());
+ for (i = 0; i < sz - 1; ++ i)
text = text + mTextRows[i] + "\n";
text = text + mTextRows[i];