diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-04-30 19:52:16 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-04-30 19:52:16 +0300 |
commit | 88c6a0aa757df0ec38bc67f2cf314f8be3efd0ce (patch) | |
tree | b35a28cd317e2895c063749180b98edfe223c032 /src/gui | |
parent | c24fefa91a1416a4dad7fd97d67cefa51f9eb97c (diff) | |
download | plus-88c6a0aa757df0ec38bc67f2cf314f8be3efd0ce.tar.gz plus-88c6a0aa757df0ec38bc67f2cf314f8be3efd0ce.tar.bz2 plus-88c6a0aa757df0ec38bc67f2cf314f8be3efd0ce.tar.xz plus-88c6a0aa757df0ec38bc67f2cf314f8be3efd0ce.zip |
Fix code style in gui.
Diffstat (limited to 'src/gui')
25 files changed, 108 insertions, 62 deletions
diff --git a/src/gui/font.cpp b/src/gui/font.cpp index acc27d4ab..b5bb46eb0 100644 --- a/src/gui/font.cpp +++ b/src/gui/font.cpp @@ -645,7 +645,7 @@ int Font::getStringIndexAt(const std::string& text, const int x) const for (size_t i = 0; i < sz; ++i) { if (getWidth(text.substr(0, i)) > x) - return i; + return static_cast<int>(i); } return static_cast<int>(sz); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 4ad1138eb..7be573995 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -487,7 +487,7 @@ void Gui::draw() int mouseX; int mouseY; - const uint8_t button = getMouseState(&mouseX, &mouseY); + const MouseStateType button = getMouseState(&mouseX, &mouseY); if ((client->getMouseFocused() || button & SDL_BUTTON(1)) && mMouseCursors && mCustomCursor && mMouseCursorAlpha > 0.0F) @@ -1111,9 +1111,9 @@ void Gui::removeDragged(Widget *widget) mFocusHandler->setDraggedWidget(nullptr); } -uint32_t Gui::getMouseState(int *const x, int *const y) +MouseStateType Gui::getMouseState(int *const x, int *const y) { - const uint32_t res = SDL_GetMouseState(x, y); + const MouseStateType res = SDL_GetMouseState(x, y); const int scale = mainGraphics->getScale(); (*x) /= scale; (*y) /= scale; diff --git a/src/gui/gui.h b/src/gui/gui.h index 723c653ca..b4f9991f0 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -88,6 +88,12 @@ class SDLInput; class Widget; class Window; +#ifdef USE_SDL2 +#define MouseStateType uint32_t +#else +#define MouseStateType uint8_t +#endif + /** * \defgroup GUI Core GUI related classes (widgets) */ @@ -215,7 +221,7 @@ class Gui final int getLastMouseY() const { return mLastMouseY; } - static uint32_t getMouseState(int *const x, int *const y); + static MouseStateType getMouseState(int *const x, int *const y); /** * Sets the top widget. The top widget is the root widget diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 0bc23a849..e863f0b2a 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -163,7 +163,7 @@ void SDLInput::pushInput(const SDL_Event &event) #ifdef ANDROID mouseInput.setReal(0, 0); #endif - mouseInput.setButton(-1); + mouseInput.setButton(static_cast<uint32_t>(-1)); if (y > 0) mouseInput.setType(MouseInput::WHEEL_MOVED_UP); else diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h index d146a334f..b27aa5483 100644 --- a/src/gui/setupactiondata.h +++ b/src/gui/setupactiondata.h @@ -33,6 +33,16 @@ struct SetupActionData final { + SetupActionData(const std::string name0, + const int actionId0, + const std::string text0) : + name(name0), + actionId(actionId0), + text(text0) + { } + + A_DELETE_COPY(SetupActionData) + std::string name; const int actionId; std::string text; diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 1b1955647..ea902e2b5 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -1235,8 +1235,8 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name, xmlNodeGetContent(infoNode))) #define readFloatValue(name) \ - info->name = atof(reinterpret_cast<const char*>(\ - xmlNodeGetContent(infoNode))) + info->name = static_cast<float>(atof(reinterpret_cast<const char*>(\ + xmlNodeGetContent(infoNode)))) ThemeInfo *Theme::loadInfo(const std::string &themeName) { diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 061b07adc..af2125cb5 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -280,7 +280,7 @@ void Viewport::followMouse() { if (!gui) return; - const uint8_t button = Gui::getMouseState(&mMouseX, &mMouseY); + const MouseStateType button = Gui::getMouseState(&mMouseX, &mMouseY); // If the left button is dragged if (mPlayerFollowMouse && (button & SDL_BUTTON(1))) { diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 4d4a51ca4..2696bcdbc 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -629,7 +629,8 @@ int BrowserBox::calcHeight() const Color col[2] = { getThemeCharColor(c, valid), - getThemeCharColor(c | 0x80, valid) + getThemeCharColor(static_cast<signed char>( + c | 0x80), valid) }; if (c == '>') diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp index a5cf2379e..941249560 100644 --- a/src/gui/widgets/characterdisplay.cpp +++ b/src/gui/widgets/characterdisplay.cpp @@ -132,7 +132,8 @@ void CharacterDisplay::mouseMoved(MouseEvent &event A_UNUSED) if (!name.empty()) { mPopup->show(mouseX, mouseY, name, strprintf(_("Level: %u"), - mCharacter->data.mAttributes[PlayerInfo::LEVEL]), + static_cast<uint32_t>( + mCharacter->data.mAttributes[PlayerInfo::LEVEL])), strprintf(_("Money: %s"), Units::formatCurrency( mCharacter->data.mAttributes[PlayerInfo::MONEY]).c_str())); } diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp index 7245ddd19..89bcc7485 100644 --- a/src/gui/widgets/extendedlistbox.cpp +++ b/src/gui/widgets/extendedlistbox.cpp @@ -89,14 +89,14 @@ void ExtendedListBox::draw(Graphics *graphics) if (insideWidth < strWidth) { - const int strSize = str.size(); - int divPos = strSize / 2; + const size_t strSize = str.size(); + size_t divPos = strSize / 2; if (divPos > 0 && static_cast<unsigned char>( str[divPos - 1]) >= 0xc0) { divPos --; } - for (int d = divPos; d > 10; d --) + for (size_t d = divPos; d > 10; d --) { if (str[d] == 32) { @@ -116,11 +116,11 @@ void ExtendedListBox::draw(Graphics *graphics) } mHeight = y + height; - const int itemsSz = mListItems.size(); - const int selSz = mSelectedItems.size(); + const size_t itemsSz = mListItems.size(); + const size_t selSz = mSelectedItems.size(); int minY = -1; int maxY = -1; - for (int f = 0; f < selSz; f ++) + for (size_t f = 0; f < selSz; f ++) { const ExtendedListBoxItem &item = mSelectedItems[f]; const int y1 = item.y; @@ -138,7 +138,7 @@ void ExtendedListBox::draw(Graphics *graphics) width - pad2, maxY - minY + height)); } - for (int f = 0; f < itemsSz; ++f) + for (size_t f = 0; f < itemsSz; ++f) { const ExtendedListBoxItem &item = mListItems[f]; const int row1 = item.row; @@ -156,7 +156,7 @@ void ExtendedListBox::draw(Graphics *graphics) graphics->setColorAll(mForegroundColor, mForegroundColor2); - for (int f = 0; f < itemsSz; ++f) + for (size_t f = 0; f < itemsSz; ++f) { const ExtendedListBoxItem &item = mListItems[f]; const int row1 = item.row; @@ -173,7 +173,7 @@ void ExtendedListBox::draw(Graphics *graphics) } } - for (int f = 0; f < selSz; ++f) + for (size_t f = 0; f < selSz; ++f) { const ExtendedListBoxItem &item = mSelectedItems[f]; const int row1 = item.row; @@ -191,7 +191,7 @@ void ExtendedListBox::draw(Graphics *graphics) graphics->setColorAll(mForegroundSelectedColor, mForegroundSelectedColor2); - for (int f = 0; f < selSz; ++f) + for (size_t f = 0; f < selSz; ++f) { const ExtendedListBoxItem &item = mSelectedItems[f]; const int row1 = item.row; @@ -225,8 +225,8 @@ int ExtendedListBox::getSelectionByMouse(const int y) const return ListBox::getSelectionByMouse(y); const int height = mRowHeight; - const int itemsSz = mListItems.size(); - for (int f = 0; f < itemsSz; f ++) + const size_t itemsSz = mListItems.size(); + for (size_t f = 0; f < itemsSz; f ++) { const ExtendedListBoxItem &item = mListItems[f]; const int y2 = item.y; @@ -234,8 +234,8 @@ int ExtendedListBox::getSelectionByMouse(const int y) const return item.row; } - const int selSz = mSelectedItems.size(); - for (int f = 0; f < selSz; f ++) + const size_t selSz = mSelectedItems.size(); + for (size_t f = 0; f < selSz; f ++) { const ExtendedListBoxItem &item = mSelectedItems[f]; const int y2 = item.y; diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h index 1a9067378..398ebb7b9 100644 --- a/src/gui/widgets/playerbox.h +++ b/src/gui/widgets/playerbox.h @@ -45,10 +45,10 @@ class PlayerBox final : public Widget, * Constructor. Takes the initial player character that this box should * display, which defaults to <code>NULL</code>. */ - explicit PlayerBox(Widget2 *const widget, - Being *const being, - const std::string &skin = "", - const std::string &selectedSkin = ""); + PlayerBox(Widget2 *const widget, + Being *const being, + const std::string &skin = "", + const std::string &selectedSkin = ""); explicit PlayerBox(Widget2 *const widget, const std::string &skin = "", diff --git a/src/gui/widgets/spellshortcutcontainer.h b/src/gui/widgets/spellshortcutcontainer.h index afff6dcf9..ba192d4bc 100644 --- a/src/gui/widgets/spellshortcutcontainer.h +++ b/src/gui/widgets/spellshortcutcontainer.h @@ -38,8 +38,8 @@ class SpellShortcutContainer final : public ShortcutContainer /** * Constructor. Initializes the graphic. */ - explicit SpellShortcutContainer(Widget2 *const widget, - const unsigned number); + SpellShortcutContainer(Widget2 *const widget, + const unsigned number); A_DELETE_COPY(SpellShortcutContainer) diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index b1849e801..d616ecd0d 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -456,7 +456,8 @@ void TextBox::draw(Graphics* graphics) 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. - font->drawString(graphics, mTextRows[i], 1, i * fontHeight); + font->drawString(graphics, mTextRows[i], 1, + static_cast<int>(i * fontHeight)); } BLOCK_END("TextBox::draw") } diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index f89d2ead2..342e97ee8 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -253,7 +253,7 @@ void TextField::keyPressed(KeyEvent &event) { std::string str = event.getText(); mText.insert(mCaretPosition, str); - mCaretPosition += str.size(); + mCaretPosition += static_cast<unsigned int>(str.size()); event.consume(); fixScroll(); if (mSendAlwaysEvents) @@ -679,7 +679,7 @@ void TextField::fixScroll() void TextField::setCaretPosition(unsigned int position) { - const unsigned int sz = mText.size(); + const unsigned int sz = static_cast<unsigned int>(mText.size()); if (position > sz) mCaretPosition = static_cast<int>(sz); else @@ -746,7 +746,7 @@ void TextField::setText(const std::string& text) { const size_t sz = text.size(); if (sz < mCaretPosition) - mCaretPosition = sz; + mCaretPosition = static_cast<unsigned int>(sz); mText = text; } diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 1795f2843..a14f960cd 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -104,8 +104,10 @@ class Window : public BasicContainer2, * a window will never go below its parent window. * @param skin The location where the window's skin XML can be found. */ - Window(const std::string &caption = "Window", const bool modal = false, - Window *const parent = nullptr, std::string skin = ""); + explicit Window(const std::string &caption = "Window", + const bool modal = false, + Window *const parent = nullptr, + std::string skin = ""); A_DELETE_COPY(Window) diff --git a/src/gui/windows/botcheckerwindow.cpp b/src/gui/windows/botcheckerwindow.cpp index 32a0227d7..e8dd03f63 100644 --- a/src/gui/windows/botcheckerwindow.cpp +++ b/src/gui/windows/botcheckerwindow.cpp @@ -116,9 +116,9 @@ public: } const unsigned int curTime = cur_time; - const unsigned int sz = mPlayers.size(); + const size_t sz = mPlayers.size(); // set up widgets - for (unsigned int r = 0; r < sz; ++r) + for (size_t r = 0; r < sz; ++r) { if (!mPlayers.at(r)) continue; diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp index 0fe412e5c..182ce5f03 100644 --- a/src/gui/windows/charcreatedialog.cpp +++ b/src/gui/windows/charcreatedialog.cpp @@ -340,7 +340,8 @@ void CharCreateDialog::action(const ActionEvent &event) Net::getCharServerHandler()->newCharacter(getName(), characterSlot, mFemale->isSelected(), mHairStyle, mHairColor, - static_cast<unsigned char>(mRace), mLook, atts); + static_cast<unsigned char>(mRace), + static_cast<unsigned char>(mLook), atts); } else { @@ -620,7 +621,8 @@ void CharCreateDialog::updateLook() { mLook = 0; } - mPlayer->setSubtype(static_cast<uint16_t>(mRace), mLook); + mPlayer->setSubtype(static_cast<uint16_t>(mRace), + static_cast<uint8_t>(mLook)); if (mRaceNameLabel) { mRaceNameLabel->setCaption(item.getName()); diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp index 887937232..4754d01e5 100644 --- a/src/gui/windows/charselectdialog.cpp +++ b/src/gui/windows/charselectdialog.cpp @@ -256,12 +256,18 @@ void CharSelectDialog::action(const ActionEvent &event) // TRANSLATORS: char select dialog. player info message. _("Hp: %u/%u\nMp: %u/%u\nLevel: %u\n" "Experience: %u\nMoney: %s"), - character->data.mAttributes[PlayerInfo::HP], - character->data.mAttributes[PlayerInfo::MAX_HP], - character->data.mAttributes[PlayerInfo::MP], - character->data.mAttributes[PlayerInfo::MAX_MP], - character->data.mAttributes[PlayerInfo::LEVEL], - character->data.mAttributes[PlayerInfo::EXP], + static_cast<uint32_t>( + character->data.mAttributes[PlayerInfo::HP]), + static_cast<uint32_t>( + character->data.mAttributes[PlayerInfo::MAX_HP]), + static_cast<uint32_t>( + character->data.mAttributes[PlayerInfo::MP]), + static_cast<uint32_t>( + character->data.mAttributes[PlayerInfo::MAX_MP]), + static_cast<uint32_t>( + character->data.mAttributes[PlayerInfo::LEVEL]), + static_cast<uint32_t>( + character->data.mAttributes[PlayerInfo::EXP]), Units::formatCurrency( character->data.mAttributes[PlayerInfo::MONEY]).c_str()); new OkDialog(data->getName(), msg, DIALOG_SILENCE); diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 5b1eba199..1b1973f63 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -1452,7 +1452,8 @@ bool ChatWindow::resortChatLog(std::string line, Own own, { const std::string nick = line.substr(0, idx2 - 1); line = line.substr(idx2 + 6); - localPetEmote(nick, atoi(line.c_str())); + localPetEmote(nick, static_cast<uint8_t>( + atoi(line.c_str()))); } // ignore other special message formats. return false; diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp index 0f286b145..713a6e567 100644 --- a/src/gui/windows/emotewindow.cpp +++ b/src/gui/windows/emotewindow.cpp @@ -153,7 +153,7 @@ std::string EmoteWindow::getSelectedEmote() const return std::string(); char chr[2]; - chr[0] = '0' + index; + chr[0] = static_cast<char>('0' + index); chr[1] = 0; return std::string("%%").append(&chr[0]); } @@ -173,7 +173,7 @@ std::string EmoteWindow::getSelectedColor() const return std::string(); char chr[2]; - chr[0] = '0' + index; + chr[0] = static_cast<char>('0' + index); chr[1] = 0; return std::string("##").append(&chr[0]); } diff --git a/src/gui/windows/shortcutwindow.h b/src/gui/windows/shortcutwindow.h index 5e36e68d7..9a447d05c 100644 --- a/src/gui/windows/shortcutwindow.h +++ b/src/gui/windows/shortcutwindow.h @@ -45,9 +45,9 @@ class ShortcutWindow final : public Window const std::string &restrict skinFile = "", int width = 0, int height = 0); - ShortcutWindow(const std::string &restrict title, - const std::string &restrict skinFile = "", - const int width = 0, const int height = 0); + explicit ShortcutWindow(const std::string &restrict title, + const std::string &restrict skinFile = "", + const int width = 0, const int height = 0); A_DELETE_COPY(ShortcutWindow) diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index f077341bf..0051dd1e7 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -332,7 +332,10 @@ void SkillDialog::action(const ActionEvent &event) if (tab) { if (const SkillInfo *const info = tab->getSelectedInfo()) - Net::getPlayerHandler()->increaseSkill(info->id); + { + Net::getPlayerHandler()->increaseSkill( + static_cast<uint16_t>(info->id)); + } } } else if (eventId == "sel") diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp index 3f6fe663d..6a17514d6 100644 --- a/src/gui/windows/socialwindow.cpp +++ b/src/gui/windows/socialwindow.cpp @@ -277,7 +277,9 @@ public: if (online0 || total0) { // TRANSLATORS: social window label - mCounterString = strprintf(_("Members: %u/%u"), online0, total0); + mCounterString = strprintf(_("Members: %u/%u"), + static_cast<uint32_t>(online0), + static_cast<uint32_t>(total0)); } else { @@ -299,7 +301,9 @@ public: } // TRANSLATORS: social window label - mCounterString = strprintf(_("Players: %u/%u"), online, total); + mCounterString = strprintf(_("Players: %u/%u"), + static_cast<uint32_t>(online), + static_cast<uint32_t>(total)); } updateCounter(); } @@ -369,7 +373,9 @@ public: } // TRANSLATORS: social window label - mCounterString = strprintf(_("Players: %u/%u"), online, total); + mCounterString = strprintf(_("Players: %u/%u"), + static_cast<uint32_t>(online), + static_cast<uint32_t>(total)); updateCounter(); } }; @@ -492,7 +498,9 @@ public: } // TRANSLATORS: social window label - mCounterString = strprintf(_("Players: %u/%u"), online, total); + mCounterString = strprintf(_("Players: %u/%u"), + static_cast<uint32_t>(online), + static_cast<uint32_t>(total)); updateCounter(); } @@ -781,7 +789,9 @@ public: socialWindow->setProcessedPortals(true); // TRANSLATORS: social window label - mCounterString = strprintf(_("Portals: %u/%u"), online, total); + mCounterString = strprintf(_("Portals: %u/%u"), + static_cast<uint32_t>(online), + static_cast<uint32_t>(total)); updateCounter(); } @@ -1157,7 +1167,9 @@ public: delete players; // TRANSLATORS: social window label - mCounterString = strprintf(_("Friends: %u/%u"), online, total); + mCounterString = strprintf(_("Friends: %u/%u"), + static_cast<uint32_t>(online), + static_cast<uint32_t>(total)); updateCounter(); } diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index 53abb7fdf..f2473241c 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -114,7 +114,8 @@ class DerDisplay final : public AttrDisplay { return DERIVED; } }; -class ChangeDisplay final : public AttrDisplay, ActionListener +class ChangeDisplay final : public AttrDisplay, + public ActionListener { public: ChangeDisplay(const Widget2 *const widget, diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp index b7616eb72..34ae7aa49 100644 --- a/src/gui/windows/whoisonline.cpp +++ b/src/gui/windows/whoisonline.cpp @@ -434,7 +434,7 @@ void WhoIsOnline::loadWebList() level = 0; OnlinePlayer *const player = new OnlinePlayer(nick, - static_cast<signed char>(255), level, + static_cast<unsigned char>(255), level, GENDER_UNSPECIFIED, -1); mOnlinePlayers.insert(player); mOnlineNicks.insert(nick); |