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 | |
parent | 093e392dd84c920d26bca17d48ac6611393d087c (diff) | |
download | mv-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.gz mv-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.bz2 mv-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.xz mv-c6c4eef4e49bb4de90845408af9f642a1a4e224b.zip |
Improve size calculations.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/charcreatedialog.cpp | 8 | ||||
-rw-r--r-- | src/gui/charselectdialog.cpp | 6 | ||||
-rw-r--r-- | src/gui/didyouknowwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/helpwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/ministatuswindow.cpp | 4 | ||||
-rw-r--r-- | src/gui/outfitwindow.cpp | 18 | ||||
-rw-r--r-- | src/gui/palette.cpp | 2 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 6 | ||||
-rw-r--r-- | src/gui/setup_relations.cpp | 10 | ||||
-rw-r--r-- | src/gui/updaterwindow.cpp | 11 | ||||
-rw-r--r-- | src/gui/whoisonline.cpp | 8 | ||||
-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 |
20 files changed, 64 insertions, 59 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 1ef29c93f..5c27b7440 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -268,7 +268,7 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) mCreateButton->setEnabled(false); std::vector<int> atts; - for (unsigned i = 0; i < mAttributeSlider.size(); i++) + for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++) { atts.push_back(static_cast<int>( mAttributeSlider[i]->getValue())); @@ -362,7 +362,7 @@ std::string CharCreateDialog::getName() const void CharCreateDialog::updateSliders() { - for (unsigned i = 0; i < mAttributeSlider.size(); i++) + for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++) { // Update captions mAttributeValue[i]->setCaption( @@ -404,7 +404,7 @@ int CharCreateDialog::getDistributedPoints() const { int points = 0; - for (unsigned i = 0; i < mAttributeSlider.size(); i++) + for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++) points += static_cast<int>(mAttributeSlider[i]->getValue()); return points; } @@ -434,7 +434,7 @@ void CharCreateDialog::setAttributes(const StringVect &labels, int w = 480; int h = 350; - for (unsigned i = 0; i < labels.size(); i++) + for (unsigned i = 0, sz = labels.size(); i < sz; i++) { mAttributeLabel[i] = new Label(labels[i]); mAttributeLabel[i]->setWidth(70); diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index e0ae9e85f..77c8ea55d 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -211,7 +211,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) // Check if a button of a character was pressed const gcn::Widget *sourceParent = event.getSource()->getParent(); int selected = -1; - for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i) + for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i) { if (mCharacterEntries[i] == sourceParent) { @@ -515,7 +515,7 @@ void CharSelectDialog::setLocked(bool locked) if (mChangeEmailButton) mChangeEmailButton->setEnabled(!locked); - for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i) + for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i) { if (mCharacterEntries[i]) mCharacterEntries[i]->setActive(!mLocked); @@ -528,7 +528,7 @@ bool CharSelectDialog::selectByName(const std::string &name, if (mLocked) return false; - for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i) + for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i) { if (mCharacterEntries[i]) { diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index d7c44ebaa..003395d3b 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -136,7 +136,7 @@ void DidYouKnowWindow::loadFile(int num) TranslationManager::translateFile(helpPath + file + ".txt", translator, lines); - for (unsigned int i = 0; i < lines.size(); ++i) + for (size_t i = 0, sz = lines.size(); i < sz; ++i) mBrowserBox->addRow(lines[i]); } diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 151e8bb63..66e357d31 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -121,7 +121,7 @@ void HelpWindow::loadFile(const std::string &file) TranslationManager::translateFile(helpPath + file + ".txt", translator, lines); - for (unsigned int i = 0; i < lines.size(); ++i) + for (size_t i = 0, sz = lines.size(); i < sz; ++i) mBrowserBox->addRow(lines[i]); } diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp index 72064c335..c32aaa742 100644 --- a/src/gui/ministatuswindow.cpp +++ b/src/gui/ministatuswindow.cpp @@ -212,7 +212,7 @@ void MiniStatusWindow::drawIcons(Graphics *graphics) { // Draw icons int icon_x = mStatusBar->getX() + mStatusBar->getWidth() + 4; - for (unsigned int i = 0; i < mIcons.size(); i++) + for (size_t i = 0, sz = mIcons.size(); i < sz; i ++) { if (mIcons[i]) { @@ -268,7 +268,7 @@ void MiniStatusWindow::logic() { Popup::logic(); - for (unsigned int i = 0; i < mIcons.size(); i++) + for (size_t i = 0, sz = mIcons.size(); i < sz; i++) { if (mIcons[i]) mIcons[i]->update(tick_time * 10); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index fafb69896..2127bc6cf 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -149,13 +149,12 @@ void OutfitWindow::load(bool oldConfig) while (ss >> buf) tokens.push_back(atoi(buf.c_str())); - for (int i = 0; i < static_cast<int>(tokens.size()) - && i < OUTFIT_ITEM_COUNT; i++) + for (size_t i = 0, sz = tokens.size(); + i < sz && i < OUTFIT_ITEM_COUNT; i++) { mItems[o][i] = tokens[i]; } - outfit = cfg->getValue("OutfitColor" + toString(o), "1"); std::stringstream ss2(outfit); @@ -165,8 +164,8 @@ void OutfitWindow::load(bool oldConfig) while (ss2 >> buf) tokens2.push_back(static_cast<unsigned char>(atoi(buf.c_str()))); - for (int i = 0; i < static_cast<int>(tokens2.size()) - && i < OUTFIT_ITEM_COUNT; i++) + for (size_t i = 0, sz = tokens2.size(); + i < sz && i < OUTFIT_ITEM_COUNT; i++) { mItemColors[o][i] = tokens2[i]; } @@ -497,19 +496,20 @@ void OutfitWindow::unequipNotInOutfit(int outfit) for (unsigned i = 0; i < inventory->getSize(); i++) { - if (inventory->getItem(i) && inventory->getItem(i)->isEquipped()) + Item *item = inventory->getItem(i); + if (item && item->isEquipped()) { bool found = false; for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++) { - if (inventory->getItem(i)->getId() == mItems[outfit][f]) + if (item->getId() == mItems[outfit][f]) { found = true; break; } } if (!found) - Net::getInventoryHandler()->unequipItem(inventory->getItem(i)); + Net::getInventoryHandler()->unequipItem(item); } } } @@ -603,7 +603,7 @@ void OutfitWindow::copyFromEquiped(int dst) int outfitCell = 0; - for (unsigned i = 0; i < inventory->getSize(); i++) + for (unsigned i = 0, sz = inventory->getSize(); i < sz; i++) { const Item *item = inventory->getItem(i); if (item && item->isEquipped()) diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index a31346b87..523497044 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -98,7 +98,7 @@ void Palette::advanceGradient() int advance = get_elapsed_time(mRainbowTime) / 5; double startColVal, destColVal; - for (size_t i = 0; i < mGradVector.size(); i++) + for (size_t i = 0, sz = mGradVector.size(); i < sz; i++) { if (!mGradVector[i]) continue; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 80e793cd2..28e0c43e6 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -636,7 +636,7 @@ void ServerDialog::loadServers(bool addNew) MutexLocker tempLock(&mMutex); // Add the server to the local list if it's not already present bool found = false; - for (unsigned int i = 0; i < mServers.size(); i++) + for (unsigned int i = 0, sz = mServers.size(); i < sz; i++) { if (mServers[i] == server) { @@ -713,8 +713,8 @@ void ServerDialog::saveCustomServers(const ServerInfo ¤tServer, int savedServerCount = 0; - for (unsigned i = 0; - i < mServers.size() && savedServerCount < MAX_SERVERLIST; ++i) + for (unsigned i = 0, sz = mServers.size(); + i < sz && savedServerCount < MAX_SERVERLIST; ++ i) { const ServerInfo &server = mServers.at(i); diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index d40995ac2..20ef3b3d4 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -152,7 +152,7 @@ public: mPlayers = player_names; // set up widgets - for (unsigned int r = 0; r < player_names->size(); ++r) + for (unsigned int r = 0, sz = player_names->size(); r < sz; ++r) { std::string name = (*player_names)[r]; gcn::Widget *widget = new Label(name); @@ -316,9 +316,9 @@ void Setup_Relations::reset() // current selection. We could use an index into the table of config // options in player_relations instead of strategies to sidestep this. int selection = 0; - for (unsigned int i = 0; - i < player_relations.getPlayerIgnoreStrategies()->size(); - ++i) + for (size_t i = 0, sz = player_relations.getPlayerIgnoreStrategies() + ->size(); i < sz; ++ i) + { if ((*player_relations.getPlayerIgnoreStrategies())[i] == player_relations.getPlayerIgnoreStrategy()) { @@ -326,7 +326,7 @@ void Setup_Relations::reset() selection = i; break; } - + } mIgnoreActionChoicesBox->setSelected(selection); } diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index eef8ca306..71aec58a0 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -527,7 +527,8 @@ void UpdaterWindow::loadUpdates() } std::string fixPath = mUpdatesDir + "/fix"; - for (mUpdateIndex = 0; mUpdateIndex < mUpdateFiles.size(); mUpdateIndex++) + const unsigned sz = mUpdateFiles.size(); + for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++) { UpdaterWindow::addUpdateFile(resman, mUpdatesDir, fixPath, mUpdateFiles[mUpdateIndex].name, false); @@ -551,8 +552,8 @@ void UpdaterWindow::loadLocalUpdates(std::string dir) } std::string fixPath = dir + "/fix"; - for (unsigned int updateIndex = 0; - updateIndex < updateFiles.size(); updateIndex++) + for (unsigned int updateIndex = 0, sz = updateFiles.size(); + updateIndex < sz; updateIndex ++) { UpdaterWindow::addUpdateFile(resman, dir, fixPath, updateFiles[updateIndex].name, false); @@ -567,8 +568,8 @@ void UpdaterWindow::loadManaPlusUpdates(std::string dir, std::vector<updateFile> updateFiles = loadXMLFile(fixPath + "/" + xmlUpdateFile); - for (unsigned int updateIndex = 0; - updateIndex < updateFiles.size(); updateIndex ++) + for (unsigned int updateIndex = 0, sz = updateFiles.size(); + updateIndex < sz; updateIndex ++) { std::string name = updateFiles[updateIndex].name; if (strStartWith(name, "manaplus_")) diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 8c2bfa6c9..911c26c3e 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -200,7 +200,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends, sort(neutral.begin(), neutral.end(), nameCompare); sort(disregard.begin(), disregard.end(), nameCompare); bool addedFromSection(false); - for (int i = 0; i < static_cast<int>(friends.size()); i++) + for (size_t i = 0, sz = friends.size(); i < sz; i++) { mBrowserBox->addRow(friends.at(i)->getText()); addedFromSection = true; @@ -210,7 +210,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends, mBrowserBox->addRow("---"); addedFromSection = false; } - for (int i = 0; i < static_cast<int>(enemy.size()); i++) + for (size_t i = 0, sz = enemy.size(); i < sz; i++) { mBrowserBox->addRow(enemy.at(i)->getText()); addedFromSection = true; @@ -220,7 +220,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends, mBrowserBox->addRow("---"); addedFromSection = false; } - for (int i = 0; i < static_cast<int>(neutral.size()); i++) + for (size_t i = 0, sz = neutral.size(); i < sz; i++) { mBrowserBox->addRow(neutral.at(i)->getText()); addedFromSection = true; @@ -230,7 +230,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends, mBrowserBox->addRow("---"); // addedFromSection = false; } - for (int i = 0; i < static_cast<int>(disregard.size()); i++) + for (size_t i = 0, sz = disregard.size(); i < sz; i++) mBrowserBox->addRow(disregard.at(i)->getText()); if (mScrollArea->getVerticalMaxScroll() < 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; |