diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-08-17 16:34:36 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-08-17 16:34:36 +0300 |
commit | c6c4eef4e49bb4de90845408af9f642a1a4e224b (patch) | |
tree | 81d192e85b3c075cb2e52671bea4c3c0499dc3f2 /src/gui/widgets | |
parent | 093e392dd84c920d26bca17d48ac6611393d087c (diff) | |
download | manaverse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.gz manaverse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.bz2 manaverse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.xz manaverse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.zip |
Improve size calculations.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 9 | ||||
-rw-r--r-- | src/gui/widgets/emoteshortcutcontainer.cpp | 7 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/layout.cpp | 8 | ||||
-rw-r--r-- | src/gui/widgets/progressindicator.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 7 | ||||
-rw-r--r-- | src/gui/widgets/tablemodel.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/textbox.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 4 |
9 files changed, 25 insertions, 21 deletions
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 534bd1d19..cf2a9ea88 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -120,6 +120,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop) // Check for links in format "@@link|Caption@@" idx1 = tmp.find("@@"); + const int sz = static_cast<int>(mTextRows.size()); while (idx1 != std::string::npos) { size_t idx2 = tmp.find("|", idx1); @@ -129,7 +130,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop) break; bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2)); bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1)); - bLink.y1 = static_cast<int>(mTextRows.size()) * font->getHeight(); + bLink.y1 = sz * font->getHeight(); bLink.y2 = bLink.y1 + font->getHeight(); newRow += tmp.substr(0, idx1); @@ -224,19 +225,19 @@ void BrowserBox::addRow(const std::string &row, bool atTop) i != i_end; ++ i) { std::string tempRow = *i; - for (unsigned int j = 0; j < tempRow.size(); j++) + for (unsigned int j = 0, sz = tempRow.size(); j < sz; j++) { std::string character = tempRow.substr(j, 1); x += font->getWidth(character); nextChar = j + 1; // Wraping between words (at blank spaces) - if (nextChar < tempRow.size() && tempRow.at(nextChar) == ' ') + if (nextChar < sz && tempRow.at(nextChar) == ' ') { int nextSpacePos = static_cast<int>( tempRow.find(" ", (nextChar + 1))); if (nextSpacePos <= 0) - nextSpacePos = static_cast<int>(tempRow.size()) - 1; + nextSpacePos = static_cast<int>(sz) - 1; unsigned nextWordWidth = font->getWidth( tempRow.substr(nextChar, diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 17d825909..2347edd0c 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -131,17 +131,18 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) graphics->setColor(getForegroundColor()); g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); } + unsigned sz = mEmoteImg.size(); for (unsigned i = 0; i < mMaxItems; i++) { - if (i < mEmoteImg.size() && mEmoteImg[i] && mEmoteImg[i]->sprite) + if (i < sz && mEmoteImg[i] && mEmoteImg[i]->sprite) { mEmoteImg[i]->sprite->draw(g, (i % mGridWidth) * mBoxWidth + 2, (i / mGridWidth) * mBoxHeight + 10); } } - if (mEmoteMoved && mEmoteMoved < static_cast<unsigned>( - mEmoteImg.size()) + 1 && mEmoteMoved > 0) + if (mEmoteMoved && mEmoteMoved < static_cast<unsigned>(sz) + 1 + && mEmoteMoved > 0) { // Draw the emote image being dragged by the cursor. const EmoteSprite* sprite = mEmoteImg[mEmoteMoved - 1]; diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index e315a336c..f16852673 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -551,7 +551,7 @@ void ItemContainer::updateMatrix() mShowMatrix[idx] = -1; } - for (unsigned idx = 0; idx < sortedItems.size(); idx ++) + for (size_t idx = 0, sz = sortedItems.size(); idx < sz; idx ++) delete sortedItems[idx]; } diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 990937e06..b7856da81 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -338,6 +338,8 @@ void LayoutArray::reflow(int nx, int ny, int nw, int nh) std::vector<int> widths = getSizes(0, nw); std::vector<int> heights = getSizes(1, nh); + const int szW = static_cast<int>(widths.size()); + const int szH = static_cast<int>(heights.size()); int y = ny; for (int gridY = 0; gridY < gridH; ++gridY) { @@ -348,10 +350,8 @@ void LayoutArray::reflow(int nx, int ny, int nw, int nh) if (cell && cell->mType != LayoutCell::NONE) { int dx = x, dy = y, dw = 0, dh = 0; - align(dx, dw, 0, *cell, &widths[gridX], - static_cast<int>(widths.size() - gridX)); - align(dy, dh, 1, *cell, &heights[gridY], - static_cast<int>(heights.size() - gridY)); + align(dx, dw, 0, *cell, &widths[gridX], szW - gridX); + align(dy, dh, 1, *cell, &heights[gridY], szH - gridY); cell->reflow(dx, dy, dw, dh); } x += widths[gridX] + mSpacing; diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp index 6adb5a2fa..681da7ae4 100644 --- a/src/gui/widgets/progressindicator.cpp +++ b/src/gui/widgets/progressindicator.cpp @@ -42,7 +42,7 @@ ProgressIndicator::ProgressIndicator() Animation *anim = new Animation; if (images) { - for (ImageSet::size_type i = 0; i < images->size(); ++i) + for (ImageSet::size_type i = 0, sz = images->size(); i < sz; ++i) anim->addFrame(images->get(i), 100, 0, 0, 100); mIndicator = new SimpleAnimation(anim); diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 96e81b534..43e829a4e 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -342,7 +342,7 @@ void TabbedArea::updateTabsWidth() void TabbedArea::updateVisibleTabsWidth() { mVisibleTabsWidth = 0; - for (unsigned int i = mTabScrollIndex; i < mTabs.size(); ++i) + for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i) { if (mTabs[i].first) mVisibleTabsWidth += mTabs[i].first->getWidth(); @@ -352,14 +352,15 @@ void TabbedArea::updateVisibleTabsWidth() void TabbedArea::adjustTabPositions() { int maxTabHeight = 0; - for (unsigned i = 0; i < mTabs.size(); ++i) + size_t sz = mTabs.size(); + for (size_t i = 0; i < sz; ++i) { if (mTabs[i].first && mTabs[i].first->getHeight() > maxTabHeight) maxTabHeight = mTabs[i].first->getHeight(); } int x = mArrowButton[0]->isVisible() ? mArrowButton[0]->getWidth() : 0; - for (unsigned i = mTabScrollIndex; i < mTabs.size(); ++i) + for (size_t i = mTabScrollIndex; i < sz; ++i) { gcn::Tab* tab = mTabs[i].first; if (!tab) diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp index bc5d2ead6..04f81fdd6 100644 --- a/src/gui/widgets/tablemodel.cpp +++ b/src/gui/widgets/tablemodel.cpp @@ -163,7 +163,7 @@ int StaticTableModel::getWidth() const { int width = 0; - for (unsigned int i = 0; i < mWidths.size(); i++) + for (size_t i = 0, sz = mWidths.size(); i < sz; i++) width += mWidths[i]; return width; diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index cd5b4bf99..048051bb9 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -191,9 +191,10 @@ void TextBox::keyPressed(gcn::KeyEvent& keyEvent) { ++ mCaretRow; - if (mCaretRow >= static_cast<int>(mTextRows.size())) + const int sz = static_cast<int>(mTextRows.size()); + if (mCaretRow >= sz) { - mCaretRow = static_cast<int>(mTextRows.size()) - 1; + mCaretRow = sz - 1; if (mCaretRow < 0) mCaretRow = 0; diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index d5fb58cb9..79c48beac 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -241,7 +241,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) case 6: // Ctrl+f { - unsigned sz = static_cast<unsigned>(mText.size()); + const unsigned sz = static_cast<unsigned>(mText.size()); while (mCaretPosition < sz) { ++mCaretPosition; @@ -356,7 +356,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) case Input::KEY_GUI_RIGHT: { consumed = true; - unsigned sz = static_cast<unsigned>(mText.size()); + const unsigned sz = static_cast<unsigned>(mText.size()); while (mCaretPosition < sz) { ++mCaretPosition; |