diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-02-07 16:18:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-02-07 16:18:13 +0300 |
commit | 9fe21fcd8883b37bdc30224822e6e42afb35b8f0 (patch) | |
tree | 798117abd4dc7e610997d59d530a96ddc1509f53 /src/gui | |
parent | 4429cb14e9e187edef27aba692a4266733f79c17 (diff) | |
download | manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.gz manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.bz2 manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.xz manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.zip |
Replace most static_cast<Type> to shorter versions from defines.
Diffstat (limited to 'src/gui')
108 files changed, 628 insertions, 628 deletions
diff --git a/src/gui/color.cpp b/src/gui/color.cpp index 3e82a1210..6d0e3037e 100644 --- a/src/gui/color.cpp +++ b/src/gui/color.cpp @@ -126,9 +126,9 @@ Color Color::operator-(const Color& color) const Color Color::operator*(const float value) const { - Color result(static_cast<unsigned int>(static_cast<float>(r) * value), - static_cast<unsigned int>(static_cast<float>(g) * value), - static_cast<unsigned int>(static_cast<float>(b) * value), + Color result(CAST_U32(static_cast<float>(r) * value), + CAST_U32(static_cast<float>(g) * value), + CAST_U32(static_cast<float>(b) * value), a); result.r = (result.r > 255U ? 255U : result.r); diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp index 50aeb9738..02588a353 100644 --- a/src/gui/focushandler.cpp +++ b/src/gui/focushandler.cpp @@ -185,7 +185,7 @@ void FocusHandler::tabNext() int i; int focusedWidget = -1; - const int sz = static_cast<int>(mWidgets.size()); + const int sz = CAST_S32(mWidgets.size()); for (i = 0; i < sz; ++ i) { if (mWidgets[i] == mFocusedWidget) @@ -256,7 +256,7 @@ void FocusHandler::tabPrevious() int i; int focusedWidget = -1; - const int sz = static_cast<int>(mWidgets.size()); + const int sz = CAST_S32(mWidgets.size()); for (i = 0; i < sz; ++ i) { if (mWidgets[i] == mFocusedWidget) @@ -360,7 +360,7 @@ void FocusHandler::requestFocus(const Widget *const widget) return; int toBeFocusedIndex = -1; - for (unsigned int i = 0, sz = static_cast<unsigned int>( + for (unsigned int i = 0, sz = CAST_U32( mWidgets.size()); i < sz; ++i) { if (mWidgets[i] == widget) @@ -426,7 +426,7 @@ void FocusHandler::focusNext() { int i; int focusedWidget = -1; - const int sz = static_cast<int>(mWidgets.size()); + const int sz = CAST_S32(mWidgets.size()); for (i = 0; i < sz; ++i) { if (mWidgets[i] == mFocusedWidget) @@ -482,7 +482,7 @@ void FocusHandler::focusPrevious() int i; int focusedWidget = -1; - const int sz = static_cast<int>(mWidgets.size()); + const int sz = CAST_S32(mWidgets.size()); for (i = 0; i < sz; ++ i) { if (mWidgets[i] == mFocusedWidget) diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp index b476de976..0f36e5f0e 100644 --- a/src/gui/fonts/font.cpp +++ b/src/gui/fonts/font.cpp @@ -317,7 +317,7 @@ void Font::doClean() for (unsigned int f = 0; f < CACHES_NUMBER; f ++) { TextChunkList *const cache = &mCache[f]; - const size_t size = static_cast<size_t>(cache->size); + const size_t size = CAST_SIZE(cache->size); #ifdef DEBUG_FONT_COUNTERS logger->log("ptr: %u, size: %ld", f, size); #endif @@ -360,10 +360,10 @@ 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 static_cast<int>(i); + return CAST_S32(i); } - return static_cast<int>(sz); + return CAST_S32(sz); } const TextChunkList *Font::getCache() const noexcept diff --git a/src/gui/fonts/textchunk.cpp b/src/gui/fonts/textchunk.cpp index ca22d3ee5..63c70acdb 100644 --- a/src/gui/fonts/textchunk.cpp +++ b/src/gui/fonts/textchunk.cpp @@ -97,9 +97,9 @@ void TextChunk::generate(TTF_Font *restrict const font, { BLOCK_START("TextChunk::generate") SDL_Color sdlCol; - sdlCol.b = static_cast<uint8_t>(color.b); - sdlCol.r = static_cast<uint8_t>(color.r); - sdlCol.g = static_cast<uint8_t>(color.g); + sdlCol.b = CAST_U8(color.b); + sdlCol.r = CAST_U8(color.r); + sdlCol.g = CAST_U8(color.g); #ifdef USE_SDL2 sdlCol.a = 255; #else @@ -134,9 +134,9 @@ void TextChunk::generate(TTF_Font *restrict const font, BLOCK_END("TextChunk::generate") return; } - sdlCol2.b = static_cast<uint8_t>(color2.b); - sdlCol2.r = static_cast<uint8_t>(color2.r); - sdlCol2.g = static_cast<uint8_t>(color2.g); + sdlCol2.b = CAST_U8(color2.b); + sdlCol2.r = CAST_U8(color2.r); + sdlCol2.g = CAST_U8(color2.g); #ifdef USE_SDL2 sdlCol2.a = 255; #else diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index f10b386af..db03887fb 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -501,7 +501,7 @@ void Gui::draw() } #endif Image *const mouseCursor = mMouseCursors->get( - static_cast<size_t>(mCursorType)); + CAST_SIZE(mCursorType)); if (mouseCursor) { mouseCursor->setAlpha(mMouseCursorAlpha); @@ -648,7 +648,7 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput) } widgetWithMouseQueueCheckDone = - (static_cast<size_t>(iterations) == mWidgetWithMouseQueue.size()); + (CAST_SIZE(iterations) == mWidgetWithMouseQueue.size()); } // Check all widgets below the mouse to see if they are diff --git a/src/gui/models/beingslistmodel.h b/src/gui/models/beingslistmodel.h index 953c78119..ccf0338c7 100644 --- a/src/gui/models/beingslistmodel.h +++ b/src/gui/models/beingslistmodel.h @@ -55,7 +55,7 @@ class BeingsListModel final : public AvatarListModel int getNumberOfElements() override final { - return static_cast<int>(mMembers.size()); + return CAST_S32(mMembers.size()); } std::vector<Avatar*> mMembers; diff --git a/src/gui/models/colormodel.cpp b/src/gui/models/colormodel.cpp index 88dee3c93..046d69a92 100644 --- a/src/gui/models/colormodel.cpp +++ b/src/gui/models/colormodel.cpp @@ -38,22 +38,22 @@ ColorModel::~ColorModel() int ColorModel::getNumberOfElements() { - return static_cast<int>(mNames.size()); + return CAST_S32(mNames.size()); } std::string ColorModel::getElementAt(int i) { if (i >= getNumberOfElements() || i < 0) return "???"; - return mNames[static_cast<size_t>(i)]; + return mNames[CAST_SIZE(i)]; } const ColorPair *ColorModel::getColorAt(const int i) const { - if (i >= static_cast<int>(mColors.size()) || i < 0) + if (i >= CAST_S32(mColors.size()) || i < 0) return &mColors[0]; - return &mColors[static_cast<size_t>(i)]; + return &mColors[CAST_SIZE(i)]; } void ColorModel::add(const std::string &name, const Color *const color1, diff --git a/src/gui/models/extendednamesmodel.cpp b/src/gui/models/extendednamesmodel.cpp index ac65c8b21..28eececc4 100644 --- a/src/gui/models/extendednamesmodel.cpp +++ b/src/gui/models/extendednamesmodel.cpp @@ -35,22 +35,22 @@ ExtendedNamesModel::~ExtendedNamesModel() int ExtendedNamesModel::getNumberOfElements() { - return static_cast<int>(mNames.size()); + return CAST_S32(mNames.size()); } std::string ExtendedNamesModel::getElementAt(int i) { if (i >= getNumberOfElements() || i < 0) return "???"; - return mNames[static_cast<size_t>(i)]; + return mNames[CAST_SIZE(i)]; } const Image *ExtendedNamesModel::getImageAt(int i) { - if (i >= static_cast<int>(mImages.size()) || i < 0) + if (i >= CAST_S32(mImages.size()) || i < 0) return nullptr; - return mImages[static_cast<size_t>(i)]; + return mImages[CAST_SIZE(i)]; } void ExtendedNamesModel::clear() diff --git a/src/gui/models/iconsmodel.h b/src/gui/models/iconsmodel.h index d9cb0be5a..a04703149 100644 --- a/src/gui/models/iconsmodel.h +++ b/src/gui/models/iconsmodel.h @@ -70,7 +70,7 @@ class IconsModel final : public ListModel int getNumberOfElements() override final { - return static_cast<int>(mStrings.size()); + return CAST_S32(mStrings.size()); } std::string getElementAt(int i) override final diff --git a/src/gui/models/ignorechoiceslistmodel.h b/src/gui/models/ignorechoiceslistmodel.h index fc87a7690..8a8a7f053 100644 --- a/src/gui/models/ignorechoiceslistmodel.h +++ b/src/gui/models/ignorechoiceslistmodel.h @@ -39,7 +39,7 @@ class IgnoreChoicesListModel final : public ListModel int getNumberOfElements() override final { - return static_cast<int>(player_relations. + return CAST_S32(player_relations. getPlayerIgnoreStrategies()->size()); } diff --git a/src/gui/models/itemsmodel.h b/src/gui/models/itemsmodel.h index 96fe37b7c..032a090eb 100644 --- a/src/gui/models/itemsmodel.h +++ b/src/gui/models/itemsmodel.h @@ -69,7 +69,7 @@ class ItemsModal final : public ListModel int getNumberOfElements() override final { - return static_cast<int>(mStrings.size()); + return CAST_S32(mStrings.size()); } std::string getElementAt(int i) override final diff --git a/src/gui/models/modelistmodel.h b/src/gui/models/modelistmodel.h index e74dcb69f..9e5339a3d 100644 --- a/src/gui/models/modelistmodel.h +++ b/src/gui/models/modelistmodel.h @@ -43,13 +43,13 @@ class ModeListModel final : public ListModel * Returns the number of elements in container. */ int getNumberOfElements() override final - { return static_cast<int>(mVideoModes.size()); } + { return CAST_S32(mVideoModes.size()); } /** * Returns element from container. */ std::string getElementAt(int i) override final - { return mVideoModes[static_cast<size_t>(i)]; } + { return mVideoModes[CAST_SIZE(i)]; } /** * Returns the index corresponding to the given video mode. diff --git a/src/gui/models/namesmodel.cpp b/src/gui/models/namesmodel.cpp index a66cea6b2..2e7606274 100644 --- a/src/gui/models/namesmodel.cpp +++ b/src/gui/models/namesmodel.cpp @@ -35,14 +35,14 @@ NamesModel::~NamesModel() int NamesModel::getNumberOfElements() { - return static_cast<int>(mNames.size()); + return CAST_S32(mNames.size()); } std::string NamesModel::getElementAt(int i) { if (i >= getNumberOfElements() || i < 0) return "???"; - return mNames[static_cast<size_t>(i)]; + return mNames[CAST_SIZE(i)]; } void NamesModel::fillFromArray(const char *const *const arr, std::size_t sz) diff --git a/src/gui/models/playertablemodel.cpp b/src/gui/models/playertablemodel.cpp index c4a438c4c..80eab3694 100644 --- a/src/gui/models/playertablemodel.cpp +++ b/src/gui/models/playertablemodel.cpp @@ -67,7 +67,7 @@ PlayerTableModel::~PlayerTableModel() int PlayerTableModel::getRows() const { if (mPlayers) - return static_cast<int>(mPlayers->size()); + return CAST_S32(mPlayers->size()); else return 0; } @@ -100,7 +100,7 @@ void PlayerTableModel::playerRelationsUpdated() mPlayers = player_names; // set up widgets - for (unsigned int r = 0, sz = static_cast<unsigned int>( + for (unsigned int r = 0, sz = CAST_U32( player_names->size()); r < sz; ++r) { const std::string name = (*player_names)[r]; @@ -108,7 +108,7 @@ void PlayerTableModel::playerRelationsUpdated() mWidgets.push_back(widget); DropDown *const choicebox = new DropDown(this, mListModel); - choicebox->setSelected(static_cast<int>( + choicebox->setSelected(CAST_S32( player_relations.getRelation(name))); mWidgets.push_back(choicebox); } @@ -140,7 +140,7 @@ void PlayerTableModel::freeWidgets() std::string PlayerTableModel::getPlayerAt(const int index) const { if (!mPlayers || index < 0 - || index >= static_cast<signed>(mPlayers->size())) + || index >= CAST_S32(mPlayers->size())) { return std::string(); } diff --git a/src/gui/models/serverslistmodel.h b/src/gui/models/serverslistmodel.h index d41f54bf9..15d3d7e9a 100644 --- a/src/gui/models/serverslistmodel.h +++ b/src/gui/models/serverslistmodel.h @@ -56,7 +56,7 @@ class ServersListModel final : public ListModel int getNumberOfElements() override final A_WARN_UNUSED { MutexLocker lock = mParent->lock(); - return static_cast<int>(mServers->size()); + return CAST_S32(mServers->size()); } /** @@ -80,7 +80,7 @@ class ServersListModel final : public ListModel void setVersionString(const int index, const std::string &version) { - if (index < 0 || index >= static_cast<int>(mVersionStrings.size())) + if (index < 0 || index >= CAST_S32(mVersionStrings.size())) return; if (version.empty() || !gui) diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp index 52515ea5b..952e5fe19 100644 --- a/src/gui/models/shopitems.cpp +++ b/src/gui/models/shopitems.cpp @@ -42,8 +42,8 @@ ShopItems::~ShopItems() std::string ShopItems::getElementAt(int i) { - if (i < 0 || static_cast<unsigned>(i) - >= static_cast<unsigned int>(mShopItems.size()) || !mShopItems.at(i)) + if (i < 0 || CAST_U32(i) + >= CAST_U32(mShopItems.size()) || !mShopItems.at(i)) { return ""; } @@ -105,7 +105,7 @@ ShopItem *ShopItems::addItem2(const int inventoryIndex, ShopItem *ShopItems::at(unsigned int i) const { - if (i >= static_cast<unsigned int>(mShopItems.size())) + if (i >= CAST_U32(mShopItems.size())) return nullptr; return mShopItems.at(i); @@ -125,7 +125,7 @@ bool ShopItems::findInAllItems(std::vector<ShopItem*>::iterator &it, void ShopItems::erase(const unsigned int i) { - if (i >= static_cast<unsigned int>(mShopItems.size())) + if (i >= CAST_U32(mShopItems.size())) return; const ShopItem *const item = *(mShopItems.begin() + i); @@ -137,7 +137,7 @@ void ShopItems::erase(const unsigned int i) void ShopItems::del(const unsigned int i) { - if (i >= static_cast<unsigned int>(mShopItems.size())) + if (i >= CAST_U32(mShopItems.size())) return; ShopItem *item = *(mShopItems.begin() + i); diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h index 5224566e5..c75fee7e1 100644 --- a/src/gui/models/shopitems.h +++ b/src/gui/models/shopitems.h @@ -92,7 +92,7 @@ class ShopItems final : public ListModel * Returns the number of items in the shop. */ int getNumberOfElements() override final A_WARN_UNUSED - { return static_cast<int>(mShopItems.size()); } + { return CAST_S32(mShopItems.size()); } bool empty() const A_WARN_UNUSED { return mShopItems.empty(); } diff --git a/src/gui/models/skillmodel.cpp b/src/gui/models/skillmodel.cpp index d26283ef0..7e49de9a3 100644 --- a/src/gui/models/skillmodel.cpp +++ b/src/gui/models/skillmodel.cpp @@ -34,7 +34,7 @@ SkillModel::SkillModel() : SkillInfo *SkillModel::getSkillAt(const int i) const { - if (i < 0 || i >= static_cast<int>(mVisibleSkills.size())) + if (i < 0 || i >= CAST_S32(mVisibleSkills.size())) return nullptr; return mVisibleSkills.at(i); } diff --git a/src/gui/models/skillmodel.h b/src/gui/models/skillmodel.h index fd75c4ea7..d7695253d 100644 --- a/src/gui/models/skillmodel.h +++ b/src/gui/models/skillmodel.h @@ -38,7 +38,7 @@ class SkillModel final : public ListModel std::string getElementAt(int i) override final; int getNumberOfElements() override final - { return static_cast<int>(mVisibleSkills.size()); } + { return CAST_S32(mVisibleSkills.size()); } void addSkill(SkillInfo *const info) { mSkills.push_back(info); } diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h index 194812958..67fffc34e 100644 --- a/src/gui/models/updatelistmodel.h +++ b/src/gui/models/updatelistmodel.h @@ -47,7 +47,7 @@ class UpdateListModel final : public ListModel { if (!mLoginData) return 0; - return static_cast<int>(mLoginData->updateHosts.size()); + return CAST_S32(mLoginData->updateHosts.size()); } std::string getElementAt(int i) override final diff --git a/src/gui/models/worldlistmodel.h b/src/gui/models/worldlistmodel.h index 1c78232cc..035824cb4 100644 --- a/src/gui/models/worldlistmodel.h +++ b/src/gui/models/worldlistmodel.h @@ -47,7 +47,7 @@ class WorldListModel final : public ListModel int getNumberOfElements() override final { - return static_cast<int>(mWorlds.size()); + return CAST_S32(mWorlds.size()); } std::string getElementAt(int i) override final diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index a56388120..0e3f9560c 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -120,7 +120,7 @@ void Palette::advanceGradient() if (grad == GradientType::PULSE) { - colVal = static_cast<int>(255.0 * + colVal = CAST_S32(255.0 * sin(M_PI * colIndex / numOfColors)); const Color &col = elem->testColor; @@ -135,12 +135,12 @@ void Palette::advanceGradient() { // falling curve if (delay) { - colVal = static_cast<int>(255.0 * + colVal = CAST_S32(255.0 * (cos(M_PI * pos / delay) + 1) / 2); } else { - colVal = static_cast<int>(255.0 * + colVal = CAST_S32(255.0 * (cos(M_PI * pos) + 1) / 2); } } @@ -148,12 +148,12 @@ void Palette::advanceGradient() { // ascending curve if (delay) { - colVal = static_cast<int>(255.0 * (cos(M_PI * + colVal = CAST_S32(255.0 * (cos(M_PI * (delay - pos) / delay) + 1) / 2); } else { - colVal = static_cast<int>(255.0 * (cos(M_PI * + colVal = CAST_S32(255.0 * (cos(M_PI * (delay - pos)) + 1) / 2); } } @@ -180,13 +180,13 @@ void Palette::advanceGradient() destColVal = 1 - startColVal; - color.r = static_cast<int>(startColVal + color.r = CAST_S32(startColVal * startCol.r + destColVal * destCol.r); - color.g = static_cast<int>(startColVal + color.g = CAST_S32(startColVal * startCol.g + destColVal * destCol.g); - color.b = static_cast<int>(startColVal + color.b = CAST_S32(startColVal * startCol.b + destColVal * destCol.b); } } diff --git a/src/gui/palette.h b/src/gui/palette.h index ca5ab08ab..ebcc2936f 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -73,7 +73,7 @@ class Palette notfinal * @return the color char of the color with the given index */ inline char getColorChar(const int type) const A_WARN_UNUSED - { return mColors[static_cast<size_t>(type)].ch; } + { return mColors[CAST_SIZE(type)].ch; } /** * Updates all colors, that are non-static. diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp index 8f8a07b71..f0ab5d167 100644 --- a/src/gui/popups/itempopup.cpp +++ b/src/gui/popups/itempopup.cpp @@ -138,19 +138,19 @@ void ItemPopup::setItem(const Item *const item, { mItemName->setCaption(strprintf("%s (+%u), %d", ii.getName(item->getColor()).c_str(), - static_cast<unsigned int>(item->getRefine()), + CAST_U32(item->getRefine()), ii.getId())); } else { mItemName->setCaption(strprintf("%s (+%u), %d", ii.getName().c_str(), - static_cast<unsigned int>(item->getRefine()), + CAST_U32(item->getRefine()), ii.getId())); } mItemName->adjustSize(); const unsigned minWidth = mItemName->getWidth() + 8; - if (static_cast<unsigned>(getWidth()) < minWidth) + if (CAST_U32(getWidth()) < minWidth) setWidth(minWidth); } } diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index e319ba7fd..b9fc252b8 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -441,7 +441,7 @@ void PopupMenu::showPopup(const int x, const int y, if (being && !being->getName().empty()) { mBrowserBox->addRow(strprintf("@@player_%u|%s >@@", - static_cast<unsigned>(being->getId()), (being->getName() + CAST_U32(being->getId()), (being->getName() + being->getGenderSignWithSpace()).c_str())); } else if (actor->getType() == ActorType::FloorItem) @@ -449,7 +449,7 @@ void PopupMenu::showPopup(const int x, const int y, const FloorItem *const floorItem = static_cast<const FloorItem*>(actor); mBrowserBox->addRow(strprintf("@@flooritem_%u|%s >@@", - static_cast<unsigned>(actor->getId()), + CAST_U32(actor->getId()), floorItem->getName().c_str())); } } @@ -799,7 +799,7 @@ void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab) mBrowserBox->addRow("disable away", _("Disable away")); } mBrowserBox->addRow("##3---"); - if (tab->getType() == static_cast<int>(ChatTabType::PARTY)) + if (tab->getType() == CAST_S32(ChatTabType::PARTY)) { // TRANSLATORS: popup menu item // TRANSLATORS: enable away messages in chat tab @@ -1041,11 +1041,11 @@ void PopupMenu::handleLink(const std::string &link, if (specialLayer) { const bool isHome = (mMapItem->getType() - == static_cast<int>(MapItemType::HOME)); + == CAST_S32(MapItemType::HOME)); const int x = static_cast<const int>(mMapItem->getX()); const int y = static_cast<const int>(mMapItem->getY()); specialLayer->setTile(x, y, - static_cast<int>(MapItemType::EMPTY)); + CAST_S32(MapItemType::EMPTY)); if (socialWindow) socialWindow->removePortal(x, y); if (isHome && localPlayer) @@ -1493,7 +1493,7 @@ void PopupMenu::handleLink(const std::string &link, replaceAll(cmd, "'FLOORID'", toString(toInt(mFloorItemId, int))); replaceAll(cmd, "'ITEMID'", toString(mItemId)); replaceAll(cmd, "'ITEMCOLOR'", toString(toInt(mItemColor, int))); - replaceAll(cmd, "'BEINGTYPEID'", toString(static_cast<int>(mType))); + replaceAll(cmd, "'BEINGTYPEID'", toString(CAST_S32(mType))); replaceAll(cmd, "'PLAYER'", localPlayer->getName()); if (mItemIndex >= 0) replaceAll(cmd, "'INVINDEX'", toString(mItemIndex)); @@ -2163,7 +2163,7 @@ void PopupMenu::showWindowsPopup() continue; mBrowserBox->addRow(strprintf("show window_%d", - static_cast<int>(btn->key)), + CAST_S32(btn->key)), btn->text.c_str()); } mBrowserBox->addRow("##3---"); diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index c6f29a6e3..4850f3227 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -495,7 +495,7 @@ int SDLInput::convertKeyCharacter(const SDL_Event &event) break; } - if (!(static_cast<unsigned int>(keysym.mod) & KMOD_NUM)) + if (!(CAST_U32(keysym.mod) & KMOD_NUM)) { switch (keysym.sym) { diff --git a/src/gui/shortcut/emoteshortcut.cpp b/src/gui/shortcut/emoteshortcut.cpp index 1079076f6..c49dc2ab8 100644 --- a/src/gui/shortcut/emoteshortcut.cpp +++ b/src/gui/shortcut/emoteshortcut.cpp @@ -46,14 +46,14 @@ EmoteShortcut::~EmoteShortcut() void EmoteShortcut::load() { for (unsigned char i = 0, j = 0, - sz = static_cast<unsigned char>(EmoteDB::getLast()); + sz = CAST_U8(EmoteDB::getLast()); i <= sz && j < SHORTCUT_EMOTES; i++) { const EmoteSprite *const sprite = EmoteDB::getSprite(i, true); if (sprite) { - mEmotes[j] = static_cast<unsigned char>(i + 1); + mEmotes[j] = CAST_U8(i + 1); j ++; } } @@ -64,9 +64,9 @@ void EmoteShortcut::save() const for (int i = 0; i < SHORTCUT_EMOTES; i++) { const unsigned char emoteId = mEmotes[i] ? mEmotes[i] - : static_cast<unsigned char>(0); + : CAST_U8(0); serverConfig.setValue("emoteshortcut" + toString(i), - static_cast<unsigned int>(emoteId)); + CAST_U32(emoteId)); } } diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp index 7166fddf5..4349f1c44 100644 --- a/src/gui/shortcut/itemshortcut.cpp +++ b/src/gui/shortcut/itemshortcut.cpp @@ -226,8 +226,8 @@ void ItemShortcut::setItem(const int index, void ItemShortcut::swap(const int index1, const int index2) { if (index1 < 0 || index2 < 0 - || static_cast<unsigned int>(index1) >= SHORTCUT_ITEMS - || static_cast<unsigned int>(index2) >= SHORTCUT_ITEMS) + || CAST_U32(index1) >= SHORTCUT_ITEMS + || CAST_U32(index2) >= SHORTCUT_ITEMS) { return; } diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index d588ecdb3..20ec774dc 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -70,72 +70,72 @@ static void initDefaultThemePath() } Theme::Theme() : - Palette(static_cast<int>(ThemeColorId::THEME_COLORS_END) * THEME_PALETTES), + Palette(CAST_S32(ThemeColorId::THEME_COLORS_END) * THEME_PALETTES), mSkins(), mMinimumOpacity(-1.0F), - mProgressColors(ProgressColors(static_cast<size_t>( + mProgressColors(ProgressColors(CAST_SIZE( ProgressColorId::THEME_PROG_END))) { initDefaultThemePath(); config.addListener("guialpha", this); - mColors[static_cast<size_t>(ThemeColorId::HIGHLIGHT)].ch = 'H'; - mColors[static_cast<size_t>(ThemeColorId::CHAT)].ch = 'C'; - mColors[static_cast<size_t>(ThemeColorId::GM)].ch = 'G'; - mColors[static_cast<size_t>(ThemeColorId::GLOBAL)].ch = 'g'; - mColors[static_cast<size_t>(ThemeColorId::PLAYER)].ch = 'Y'; - mColors[static_cast<size_t>(ThemeColorId::WHISPER_TAB)].ch = 'W'; - mColors[static_cast<size_t>(ThemeColorId::WHISPER_TAB_OFFLINE)].ch = 'w'; - mColors[static_cast<size_t>(ThemeColorId::IS)].ch = 'I'; - mColors[static_cast<size_t>(ThemeColorId::PARTY_CHAT_TAB)].ch = 'P'; - mColors[static_cast<size_t>(ThemeColorId::GUILD_CHAT_TAB)].ch = 'U'; - mColors[static_cast<size_t>(ThemeColorId::SERVER)].ch = 'S'; - mColors[static_cast<size_t>(ThemeColorId::LOGGER)].ch = 'L'; - mColors[static_cast<size_t>(ThemeColorId::HYPERLINK)].ch = '<'; - mColors[static_cast<size_t>(ThemeColorId::SELFNICK)].ch = 's'; - mColors[static_cast<size_t>(ThemeColorId::OLDCHAT)].ch = 'o'; - mColors[static_cast<size_t>(ThemeColorId::AWAYCHAT)].ch = 'a'; - mCharColors['H'] = static_cast<int>(ThemeColorId::HIGHLIGHT); - mCharColors['C'] = static_cast<int>(ThemeColorId::CHAT); - mCharColors['G'] = static_cast<int>(ThemeColorId::GM); - mCharColors['g'] = static_cast<int>(ThemeColorId::GLOBAL); - mCharColors['Y'] = static_cast<int>(ThemeColorId::PLAYER); - mCharColors['W'] = static_cast<int>(ThemeColorId::WHISPER_TAB); - mCharColors['w'] = static_cast<int>(ThemeColorId::WHISPER_TAB_OFFLINE); - mCharColors['I'] = static_cast<int>(ThemeColorId::IS); - mCharColors['P'] = static_cast<int>(ThemeColorId::PARTY_CHAT_TAB); - mCharColors['U'] = static_cast<int>(ThemeColorId::GUILD_CHAT_TAB); - mCharColors['S'] = static_cast<int>(ThemeColorId::SERVER); - mCharColors['L'] = static_cast<int>(ThemeColorId::LOGGER); - mCharColors['<'] = static_cast<int>(ThemeColorId::HYPERLINK); - mCharColors['s'] = static_cast<int>(ThemeColorId::SELFNICK); - mCharColors['o'] = static_cast<int>(ThemeColorId::OLDCHAT); - mCharColors['a'] = static_cast<int>(ThemeColorId::AWAYCHAT); + mColors[CAST_SIZE(ThemeColorId::HIGHLIGHT)].ch = 'H'; + mColors[CAST_SIZE(ThemeColorId::CHAT)].ch = 'C'; + mColors[CAST_SIZE(ThemeColorId::GM)].ch = 'G'; + mColors[CAST_SIZE(ThemeColorId::GLOBAL)].ch = 'g'; + mColors[CAST_SIZE(ThemeColorId::PLAYER)].ch = 'Y'; + mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB)].ch = 'W'; + mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB_OFFLINE)].ch = 'w'; + mColors[CAST_SIZE(ThemeColorId::IS)].ch = 'I'; + mColors[CAST_SIZE(ThemeColorId::PARTY_CHAT_TAB)].ch = 'P'; + mColors[CAST_SIZE(ThemeColorId::GUILD_CHAT_TAB)].ch = 'U'; + mColors[CAST_SIZE(ThemeColorId::SERVER)].ch = 'S'; + mColors[CAST_SIZE(ThemeColorId::LOGGER)].ch = 'L'; + mColors[CAST_SIZE(ThemeColorId::HYPERLINK)].ch = '<'; + mColors[CAST_SIZE(ThemeColorId::SELFNICK)].ch = 's'; + mColors[CAST_SIZE(ThemeColorId::OLDCHAT)].ch = 'o'; + mColors[CAST_SIZE(ThemeColorId::AWAYCHAT)].ch = 'a'; + mCharColors['H'] = CAST_S32(ThemeColorId::HIGHLIGHT); + mCharColors['C'] = CAST_S32(ThemeColorId::CHAT); + mCharColors['G'] = CAST_S32(ThemeColorId::GM); + mCharColors['g'] = CAST_S32(ThemeColorId::GLOBAL); + mCharColors['Y'] = CAST_S32(ThemeColorId::PLAYER); + mCharColors['W'] = CAST_S32(ThemeColorId::WHISPER_TAB); + mCharColors['w'] = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE); + mCharColors['I'] = CAST_S32(ThemeColorId::IS); + mCharColors['P'] = CAST_S32(ThemeColorId::PARTY_CHAT_TAB); + mCharColors['U'] = CAST_S32(ThemeColorId::GUILD_CHAT_TAB); + mCharColors['S'] = CAST_S32(ThemeColorId::SERVER); + mCharColors['L'] = CAST_S32(ThemeColorId::LOGGER); + mCharColors['<'] = CAST_S32(ThemeColorId::HYPERLINK); + mCharColors['s'] = CAST_S32(ThemeColorId::SELFNICK); + mCharColors['o'] = CAST_S32(ThemeColorId::OLDCHAT); + mCharColors['a'] = CAST_S32(ThemeColorId::AWAYCHAT); // here need use outlined colors mCharColors['H' | 0x80] - = static_cast<int>(ThemeColorId::HIGHLIGHT_OUTLINE); - mCharColors['C' | 0x80] = static_cast<int>(ThemeColorId::CHAT_OUTLINE); - mCharColors['G' | 0x80] = static_cast<int>(ThemeColorId::GM_OUTLINE); - mCharColors['g' | 0x80] = static_cast<int>(ThemeColorId::GLOBAL_OUTLINE); - mCharColors['Y' | 0x80] = static_cast<int>(ThemeColorId::PLAYER_OUTLINE); + = CAST_S32(ThemeColorId::HIGHLIGHT_OUTLINE); + mCharColors['C' | 0x80] = CAST_S32(ThemeColorId::CHAT_OUTLINE); + mCharColors['G' | 0x80] = CAST_S32(ThemeColorId::GM_OUTLINE); + mCharColors['g' | 0x80] = CAST_S32(ThemeColorId::GLOBAL_OUTLINE); + mCharColors['Y' | 0x80] = CAST_S32(ThemeColorId::PLAYER_OUTLINE); mCharColors['W' | 0x80] - = static_cast<int>(ThemeColorId::WHISPER_TAB_OUTLINE); + = CAST_S32(ThemeColorId::WHISPER_TAB_OUTLINE); mCharColors['w' | 0x80] - = static_cast<int>(ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE); - mCharColors['I' | 0x80] = static_cast<int>(ThemeColorId::IS_OUTLINE); + = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE); + mCharColors['I' | 0x80] = CAST_S32(ThemeColorId::IS_OUTLINE); mCharColors['P' | 0x80] - = static_cast<int>(ThemeColorId::PARTY_CHAT_TAB_OUTLINE); + = CAST_S32(ThemeColorId::PARTY_CHAT_TAB_OUTLINE); mCharColors['U' | 0x80] - = static_cast<int>(ThemeColorId::GUILD_CHAT_TAB_OUTLINE); - mCharColors['S' | 0x80] = static_cast<int>(ThemeColorId::SERVER_OUTLINE); - mCharColors['L' | 0x80] = static_cast<int>(ThemeColorId::LOGGER_OUTLINE); + = CAST_S32(ThemeColorId::GUILD_CHAT_TAB_OUTLINE); + mCharColors['S' | 0x80] = CAST_S32(ThemeColorId::SERVER_OUTLINE); + mCharColors['L' | 0x80] = CAST_S32(ThemeColorId::LOGGER_OUTLINE); mCharColors['<' | 0x80] - = static_cast<int>(ThemeColorId::HYPERLINK_OUTLINE); - mCharColors['s' | 0x80] = static_cast<int>(ThemeColorId::SELFNICK_OUTLINE); - mCharColors['o' | 0x80] = static_cast<int>(ThemeColorId::OLDCHAT_OUTLINE); - mCharColors['a' | 0x80] = static_cast<int>(ThemeColorId::AWAYCHAT_OUTLINE); + = CAST_S32(ThemeColorId::HYPERLINK_OUTLINE); + mCharColors['s' | 0x80] = CAST_S32(ThemeColorId::SELFNICK_OUTLINE); + mCharColors['o' | 0x80] = CAST_S32(ThemeColorId::OLDCHAT_OUTLINE); + mCharColors['a' | 0x80] = CAST_S32(ThemeColorId::AWAYCHAT_OUTLINE); } Theme::~Theme() @@ -154,7 +154,7 @@ Color Theme::getProgressColor(const ProgressColorIdT type, if (theme) { const DyePalette *const dye - = theme->mProgressColors[static_cast<size_t>(type)]; + = theme->mProgressColors[CAST_SIZE(type)]; if (dye) { @@ -163,7 +163,7 @@ Color Theme::getProgressColor(const ProgressColorIdT type, else { logger->log("color not found: " - + toString(static_cast<int>(type))); + + toString(CAST_S32(type))); } } @@ -610,7 +610,7 @@ void Theme::prepareThemePath() std::string Theme::resolveThemePath(const std::string &path) { // Need to strip off any dye info for the existence tests - const int pos = static_cast<int>(path.find('|')); + const int pos = CAST_S32(path.find('|')); std::string file; if (pos > 0) file = path.substr(0, pos); @@ -648,7 +648,7 @@ ImageSet *Theme::getImageSetFromTheme(const std::string &path, static int readColorType(const std::string &type) { - static const std::string colors[static_cast<size_t>( + static const std::string colors[CAST_SIZE( ThemeColorId::THEME_COLORS_END)] = { "BROWSERBOX", @@ -878,7 +878,7 @@ static int readColorType(const std::string &type) if (type.empty()) return -1; - for (int i = 0; i < static_cast<int>(ThemeColorId::THEME_COLORS_END); i++) + for (int i = 0; i < CAST_S32(ThemeColorId::THEME_COLORS_END); i++) { if (compareStrI(type, colors[i]) == 0) return i; @@ -952,7 +952,7 @@ static GradientTypeT readColorGradient(const std::string &grad) static int readProgressType(const std::string &type) { - static const std::string colors[static_cast<size_t>( + static const std::string colors[CAST_SIZE( ProgressColorId::THEME_PROG_END)] = { "HP", @@ -972,7 +972,7 @@ static int readProgressType(const std::string &type) if (type.empty()) return -1; - for (int i = 0; i < static_cast<int>(ProgressColorId::THEME_PROG_END); i++) + for (int i = 0; i < CAST_S32(ProgressColorId::THEME_PROG_END); i++) { if (compareStrI(type, colors[i]) == 0) return i; @@ -1036,7 +1036,7 @@ void Theme::loadColors(std::string file) const Color color = readColor(temp); const GradientTypeT grad = readColorGradient( XML::getProperty(node, "effect", "")); - mColors[paletteId * static_cast<size_t>( + mColors[paletteId * CAST_SIZE( ThemeColorId::THEME_COLORS_END) + type].set( type, color, grad, 10); @@ -1046,7 +1046,7 @@ void Theme::loadColors(std::string file) if (type2 < 0) continue; const int idx = paletteId - * static_cast<int>(ThemeColorId::THEME_COLORS_END); + * CAST_S32(ThemeColorId::THEME_COLORS_END); mColors[idx + type2] = mColors[idx + type]; } } diff --git a/src/gui/theme.h b/src/gui/theme.h index 9e9badffa..91d1064be 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -136,14 +136,14 @@ class Theme final : public Palette, const unsigned int alpha = 255U) A_WARN_UNUSED { - if (static_cast<size_t>(type) >= mColors.size()) + if (CAST_SIZE(type) >= mColors.size()) { logger->log("incorrect color request type: %d from %u", - static_cast<int>(type), - static_cast<unsigned int>(mColors.size())); + CAST_S32(type), + CAST_U32(mColors.size())); type = ThemeColorId::BROWSERBOX; } - Color* col = &mColors[static_cast<size_t>(type)].color; + Color* col = &mColors[CAST_SIZE(type)].color; col->a = alpha; return *col; } diff --git a/src/gui/themecolorsidoperators.cpp b/src/gui/themecolorsidoperators.cpp index badd20b69..753512cc0 100644 --- a/src/gui/themecolorsidoperators.cpp +++ b/src/gui/themecolorsidoperators.cpp @@ -24,5 +24,5 @@ ThemeColorIdT operator+(const ThemeColorIdT &id, const int& i) { - return static_cast<ThemeColorIdT>(static_cast<int>(id) + i); + return static_cast<ThemeColorIdT>(CAST_S32(id) + i); } diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index cf0e5da05..a7fba6399 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -31,7 +31,7 @@ UserPalette *userPalette = nullptr; -const std::string ColorTypeNames[static_cast<size_t>( +const std::string ColorTypeNames[CAST_SIZE( UserColorId::USER_COLOR_LAST)] = { "", @@ -107,7 +107,7 @@ std::string UserPalette::getConfigName(const std::string &typeName) } else { - res[pos] = static_cast<signed char>(tolower(typeName[i])); + res[pos] = CAST_S8(tolower(typeName[i])); } pos ++; } @@ -116,14 +116,14 @@ std::string UserPalette::getConfigName(const std::string &typeName) } UserPalette::UserPalette() : - Palette(static_cast<int>(UserColorId::USER_COLOR_LAST)) + Palette(CAST_S32(UserColorId::USER_COLOR_LAST)) { - mColors[static_cast<size_t>(UserColorId::BEING)] = ColorElem(); - mColors[static_cast<size_t>(UserColorId::PC)] = ColorElem(); - mColors[static_cast<size_t>(UserColorId::SELF)] = ColorElem(); - mColors[static_cast<size_t>(UserColorId::GM)] = ColorElem(); - mColors[static_cast<size_t>(UserColorId::NPC)] = ColorElem(); - mColors[static_cast<size_t>(UserColorId::MONSTER)] = ColorElem(); + mColors[CAST_SIZE(UserColorId::BEING)] = ColorElem(); + mColors[CAST_SIZE(UserColorId::PC)] = ColorElem(); + mColors[CAST_SIZE(UserColorId::SELF)] = ColorElem(); + mColors[CAST_SIZE(UserColorId::GM)] = ColorElem(); + mColors[CAST_SIZE(UserColorId::NPC)] = ColorElem(); + mColors[CAST_SIZE(UserColorId::MONSTER)] = ColorElem(); addLabel(UserColorId::LABEL_BEING, // TRANSLATORS: palette label @@ -415,7 +415,7 @@ UserPalette::~UserPalette() continue; const std::string &configName = ColorTypeNames[col->type]; config.setValue(configName + "Gradient", - static_cast<int>(col->committedGrad)); + CAST_S32(col->committedGrad)); config.setValue(configName + "Delay", col->delay); if (col->grad == GradientType::STATIC || @@ -434,7 +434,7 @@ void UserPalette::setColor(const UserColorIdT type, const int g, const int b) { - Color &color = mColors[static_cast<size_t>(type)].color; + Color &color = mColors[CAST_SIZE(type)].color; color.r = r; color.g = g; color.b = b; @@ -443,7 +443,7 @@ void UserPalette::setColor(const UserColorIdT type, void UserPalette::setGradient(const UserColorIdT type, const GradientTypeT grad) { - ColorElem *const elem = &mColors[static_cast<size_t>(type)]; + ColorElem *const elem = &mColors[CAST_SIZE(type)]; if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC) { @@ -530,10 +530,10 @@ void UserPalette::addColor(const UserColorIdT type, const unsigned maxType = sizeof(ColorTypeNames) / sizeof(ColorTypeNames[0]); - if (static_cast<unsigned>(type) >= maxType) + if (CAST_U32(type) >= maxType) return; - const std::string &configName = ColorTypeNames[static_cast<size_t>(type)]; + const std::string &configName = ColorTypeNames[CAST_SIZE(type)]; char buffer[20]; snprintf(buffer, sizeof(buffer), "0x%06x", rgb); buffer[19] = 0; @@ -548,14 +548,14 @@ void UserPalette::addColor(const UserColorIdT type, const Color &trueCol = Color(rgbValue); grad = static_cast<GradientTypeT>(config.getValue( configName + "Gradient", - static_cast<int>(grad))); + CAST_S32(grad))); delay = config.getValueInt(configName + "Delay", delay); - mColors[static_cast<size_t>(type)].set(static_cast<int>(type), + mColors[CAST_SIZE(type)].set(CAST_S32(type), trueCol, grad, delay); - mColors[static_cast<size_t>(type)].text = text; + mColors[CAST_SIZE(type)].text = text; if (grad != GradientType::STATIC) - mGradVector.push_back(&mColors[static_cast<size_t>(type)]); + mGradVector.push_back(&mColors[CAST_SIZE(type)]); } void UserPalette::addLabel(const UserColorIdT type, @@ -564,15 +564,15 @@ void UserPalette::addLabel(const UserColorIdT type, const unsigned maxType = sizeof(ColorTypeNames) / sizeof(ColorTypeNames[0]); - if (static_cast<unsigned>(type) >= maxType) + if (CAST_U32(type) >= maxType) return; - mColors[static_cast<size_t>(type)] = ColorElem(); + mColors[CAST_SIZE(type)] = ColorElem(); const std::string str(" \342\200\225\342\200\225\342\200\225" "\342\200\225\342\200\225 "); - mColors[static_cast<size_t>(type)].grad = GradientType::LABEL; - mColors[static_cast<size_t>(type)].text = + mColors[CAST_SIZE(type)].grad = GradientType::LABEL; + mColors[CAST_SIZE(type)].text = std::string(str).append(text).append(str); } diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h index 49c9fce31..9f0566198 100644 --- a/src/gui/userpalette.h +++ b/src/gui/userpalette.h @@ -60,7 +60,7 @@ class UserPalette final : public Palette, public ListModel inline const Color &getCommittedColor(const UserColorIdT type) const A_WARN_UNUSED { - return mColors[static_cast<size_t>(type)].committedColor; + return mColors[CAST_SIZE(type)].committedColor; } /** @@ -72,7 +72,7 @@ class UserPalette final : public Palette, public ListModel */ inline const Color &getTestColor(const UserColorIdT type) const A_WARN_UNUSED - { return mColors[static_cast<size_t>(type)].testColor; } + { return mColors[CAST_SIZE(type)].testColor; } /** * Sets the test color associated with the specified type. @@ -82,7 +82,7 @@ class UserPalette final : public Palette, public ListModel */ inline void setTestColor(const UserColorIdT type, const Color &color) - { mColors[static_cast<size_t>(type)].testColor = color; } + { mColors[CAST_SIZE(type)].testColor = color; } /** * Sets the color for the specified type. @@ -112,7 +112,7 @@ class UserPalette final : public Palette, public ListModel */ void setGradientDelay(const UserColorIdT type, const int delay) - { mColors[static_cast<size_t>(type)].delay = delay; } + { mColors[CAST_SIZE(type)].delay = delay; } /** * Returns the number of colors known. @@ -120,7 +120,7 @@ class UserPalette final : public Palette, public ListModel * @return the number of colors known */ inline int getNumberOfElements() override final A_WARN_UNUSED - { return static_cast<int>(mColors.size()); } + { return CAST_S32(mColors.size()); } /** * Returns the name of the ith color. @@ -165,14 +165,14 @@ class UserPalette final : public Palette, public ListModel const unsigned int alpha = 255U) A_WARN_UNUSED { - if (static_cast<size_t>(type) >= mColors.size()) + if (CAST_SIZE(type) >= mColors.size()) { logger->log("incorrect color request type: %d from %u", - static_cast<int>(type), - static_cast<unsigned int>(mColors.size())); + CAST_S32(type), + CAST_U32(mColors.size())); type = UserColorId::BEING; } - Color* col = &mColors[static_cast<size_t>(type)].color; + Color* col = &mColors[CAST_SIZE(type)].color; col->a = alpha; return *col; } @@ -188,7 +188,7 @@ class UserPalette final : public Palette, public ListModel */ inline GradientTypeT getGradientType(const UserColorIdT type) const A_WARN_UNUSED - { return mColors[static_cast<size_t>(type)].grad; } + { return mColors[CAST_SIZE(type)].grad; } /** * Gets the gradient delay for the specified type. @@ -199,14 +199,14 @@ class UserPalette final : public Palette, public ListModel */ inline int getGradientDelay(const UserColorIdT type) const A_WARN_UNUSED - { return mColors[static_cast<size_t>(type)].delay; } + { return mColors[CAST_SIZE(type)].delay; } inline const Color &getColorWithAlpha(const UserColorIdT type) A_WARN_UNUSED { - Color *const col = &mColors[static_cast<size_t>(type)].color; - col->a = static_cast<unsigned int>( - mColors[static_cast<size_t>(type)].delay); + Color *const col = &mColors[CAST_SIZE(type)].color; + col->a = CAST_U32( + mColors[CAST_SIZE(type)].delay); return *col; } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 8f2940824..c7483b8a2 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -138,9 +138,9 @@ void Viewport::draw(Graphics *graphics) const int midTileY = (graphics->mHeight + mScrollCenterOffsetY) / 2; const Vector &playerPos = localPlayer->getPosition(); - const int player_x = static_cast<int>(playerPos.x) + const int player_x = CAST_S32(playerPos.x) - midTileX + mCameraRelativeX; - const int player_y = static_cast<int>(playerPos.y) + const int player_y = CAST_S32(playerPos.y) - midTileY + mCameraRelativeY; if (mScrollLaziness < 1) @@ -155,28 +155,28 @@ void Viewport::draw(Graphics *graphics) { if (player_x > mPixelViewX + mScrollRadius) { - mPixelViewX += static_cast<int>( + mPixelViewX += CAST_S32( static_cast<float>(player_x - mPixelViewX - mScrollRadius) / static_cast<float>(mScrollLaziness)); } if (player_x < mPixelViewX - mScrollRadius) { - mPixelViewX += static_cast<int>( + mPixelViewX += CAST_S32( static_cast<float>(player_x - mPixelViewX + mScrollRadius) / static_cast<float>(mScrollLaziness)); } if (player_y > mPixelViewY + mScrollRadius) { - mPixelViewY += static_cast<int>( + mPixelViewY += CAST_S32( static_cast<float>(player_y - mPixelViewY - mScrollRadius) / static_cast<float>(mScrollLaziness)); } if (player_y < mPixelViewY - mScrollRadius) { - mPixelViewY += static_cast<int>( + mPixelViewY += CAST_S32( static_cast<float>(player_y - mPixelViewY + mScrollRadius) / static_cast<float>(mScrollLaziness)); @@ -321,8 +321,8 @@ void Viewport::drawDebugPath(Graphics *const graphics) const Vector &playerPos = localPlayer->getPosition(); debugPath = mMap->findPath( - static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize, - static_cast<int>(playerPos.y - mapTileSize) / mapTileSize, + CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize, + CAST_S32(playerPos.y - mapTileSize) / mapTileSize, mousePosX / mapTileSize, mousePosY / mapTileSize, localPlayer->getBlockWalkMask(), 500); @@ -584,7 +584,7 @@ void Viewport::getMouseTile(const int x, int y, { const int tw = mMap->getTileWidth(); const int th = mMap->getTileHeight(); - destX = static_cast<int>(x + mPixelViewX) + destX = CAST_S32(x + mPixelViewX) / static_cast<float>(tw); if (mMap->isHeightsPresent()) @@ -614,7 +614,7 @@ void Viewport::getMouseTile(const int x, int y, } else { - destY = static_cast<int>((y + mPixelViewY) / static_cast<float>(th)); + destY = CAST_S32((y + mPixelViewY) / static_cast<float>(th)); } } @@ -924,7 +924,7 @@ void Viewport::mouseMoved(MouseEvent &event) void Viewport::toggleMapDrawType() { settings.mapDrawType = static_cast<MapTypeT>( - static_cast<int>(settings.mapDrawType) + 1); + CAST_S32(settings.mapDrawType) + 1); if (settings.mapDrawType > MapType::BLACKWHITE) settings.mapDrawType = MapType::NORMAL; if (mMap) @@ -978,8 +978,8 @@ void Viewport::moveCameraToActor(const BeingId actorId, const Vector &actorPos = actor->getPosition(); const Vector &playerPos = localPlayer->getPosition(); settings.cameraMode = 1; - mCameraRelativeX = static_cast<int>(actorPos.x - playerPos.x) + x; - mCameraRelativeY = static_cast<int>(actorPos.y - playerPos.y) + y; + mCameraRelativeX = CAST_S32(actorPos.x - playerPos.x) + x; + mCameraRelativeY = CAST_S32(actorPos.y - playerPos.y) + y; } void Viewport::moveCameraToPosition(const int x, const int y) @@ -990,8 +990,8 @@ void Viewport::moveCameraToPosition(const int x, const int y) const Vector &playerPos = localPlayer->getPosition(); settings.cameraMode = 1; - mCameraRelativeX = x - static_cast<int>(playerPos.x); - mCameraRelativeY = y - static_cast<int>(playerPos.y); + mCameraRelativeX = x - CAST_S32(playerPos.x); + mCameraRelativeY = y - CAST_S32(playerPos.y); } void Viewport::moveCameraRelative(const int x, const int y) diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp index f867518a7..15042b971 100644 --- a/src/gui/widgets/basiccontainer.cpp +++ b/src/gui/widgets/basiccontainer.cpp @@ -312,7 +312,7 @@ void BasicContainer::drawChildren(Graphics *restrict graphics) restrict2 if (widget->mFrameSize > 0) { Rect rec = widget->mDimension; - const int frame = static_cast<int>(widget->mFrameSize); + const int frame = CAST_S32(widget->mFrameSize); const int frame2 = frame * 2; rec.x -= frame; rec.y -= frame; @@ -352,7 +352,7 @@ void BasicContainer::safeDrawChildren(Graphics *restrict graphics) restrict2 if (widget->mFrameSize > 0) { Rect rec = widget->mDimension; - const int frame = static_cast<int>(widget->mFrameSize); + const int frame = CAST_S32(widget->mFrameSize); const int frame2 = frame * 2; rec.x -= frame; rec.y -= frame; diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 2a85748b2..eec2547ee 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -132,7 +132,7 @@ BrowserBox::BrowserBox(const Widget2 *const widget, if (mSkin) { mPadding = mSkin->getPadding(); - mNewLinePadding = static_cast<unsigned int>( + mNewLinePadding = CAST_U32( mSkin->getOption("newLinePadding", 15)); mItemPadding = mSkin->getOption("itemPadding"); if (mSkin->getOption("highlightBackground")) @@ -235,7 +235,7 @@ void BrowserBox::addRow(const std::string &row, const 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>(sz) * font->getHeight(); + bLink.y1 = CAST_S32(sz) * font->getHeight(); bLink.y2 = bLink.y1 + font->getHeight(); if (bLink.caption.empty()) { @@ -311,7 +311,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) if (idx2 == std::string::npos) break; - const unsigned int newSize = static_cast<unsigned int>( + const unsigned int newSize = CAST_U32( atoi(newRow.substr( idx1 + 2, idx2 - idx1 - 2).c_str())); std::string str = newRow.substr(0, idx1); @@ -337,7 +337,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) // discard older rows when a row limit has been set if (mMaxRows > 0 && !mTextRows.empty()) { - while (mTextRows.size() > static_cast<size_t>(mMaxRows)) + while (mTextRows.size() > CAST_SIZE(mMaxRows)) { mTextRows.pop_front(); int cnt = mTextRowLinksCount.front(); @@ -374,7 +374,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) unsigned int y = 0; unsigned int nextChar; const char *const hyphen = "~"; - const unsigned int hyphenWidth = static_cast<unsigned int>( + const unsigned int hyphenWidth = CAST_U32( font->getWidth(hyphen)); unsigned int x = 0; @@ -384,24 +384,24 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) for (unsigned int j = 0, sz = tempRow.size(); j < sz; j++) { const std::string character = tempRow.substr(j, 1); - x += static_cast<unsigned int>(font->getWidth(character)); + x += CAST_U32(font->getWidth(character)); nextChar = j + 1; // Wraping between words (at blank spaces) if (nextChar < sz && tempRow.at(nextChar) == ' ') { - unsigned int nextSpacePos = static_cast<unsigned int>( + unsigned int nextSpacePos = CAST_U32( tempRow.find(" ", (nextChar + 1))); if (nextSpacePos <= 0) - nextSpacePos = static_cast<unsigned int>(sz) - 1U; + nextSpacePos = CAST_U32(sz) - 1U; const unsigned int nextWordWidth = - static_cast<unsigned int>(font->getWidth( + CAST_U32(font->getWidth( tempRow.substr(nextChar, (nextSpacePos - nextChar)))); if ((x + nextWordWidth + 10) - > static_cast<unsigned>(getWidth())) + > CAST_U32(getWidth())) { x = mNewLinePadding; // Ident in new line y += 1; @@ -410,7 +410,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) } // Wrapping looong lines (brutal force) else if ((x + 2 * hyphenWidth) - > static_cast<unsigned>(getWidth())) + > CAST_U32(getWidth())) { x = mNewLinePadding; // Ident in new line y += 1; @@ -418,12 +418,12 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) } } - setHeight(fontHeight * (static_cast<int>( - static_cast<unsigned int>(mTextRows.size()) + y))); + setHeight(fontHeight * (CAST_S32( + CAST_U32(mTextRows.size()) + y))); } else { - setHeight(fontHeight * static_cast<int>(mTextRows.size())); + setHeight(fontHeight * CAST_S32(mTextRows.size())); } mUpdateTime = 0; updateHeight(); @@ -478,7 +478,7 @@ void BrowserBox::mouseMoved(MouseEvent &event) MouseOverLink(event.getX(), event.getY())); mSelectedLink = (i != mLinks.end()) - ? static_cast<int>(i - mLinks.begin()) : -1; + ? CAST_S32(i - mLinks.begin()) : -1; } void BrowserBox::mouseExited(MouseEvent &event A_UNUSED) @@ -506,11 +506,11 @@ void BrowserBox::draw(Graphics *graphics) } if (mSelectedLink >= 0 && mSelectedLink - < static_cast<signed>(mLinks.size())) + < CAST_S32(mLinks.size())) { if ((mHighMode & BACKGROUND)) { - BrowserLink &link = mLinks[static_cast<size_t>(mSelectedLink)]; + BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)]; graphics->setColor(mHighlightColor); graphics->fillRectangle(Rect( link.x1, @@ -521,7 +521,7 @@ void BrowserBox::draw(Graphics *graphics) if ((mHighMode & UNDERLINE)) { - BrowserLink &link = mLinks[static_cast<size_t>(mSelectedLink)]; + BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)]; graphics->setColor(mHyperLinkColor); graphics->drawLine( link.x1, @@ -575,13 +575,13 @@ void BrowserBox::safeDraw(Graphics *graphics) int BrowserBox::calcHeight() { - unsigned int y = static_cast<unsigned int>(mPadding); + unsigned int y = CAST_U32(mPadding); int wrappedLines = 0; int moreHeight = 0; int maxWidth = mDimension.width - mPadding; int link = 0; bool bold = false; - unsigned int wWidth = static_cast<unsigned int>(maxWidth); + unsigned int wWidth = CAST_U32(maxWidth); if (maxWidth < 0) return 1; @@ -598,7 +598,7 @@ int BrowserBox::calcHeight() FOR_EACH (TextRowCIter, i, mTextRows) { - unsigned int x = static_cast<unsigned int>(mPadding); + unsigned int x = CAST_U32(mPadding); const std::string row = *(i); bool wrapped = false; int objects = 0; @@ -607,16 +607,16 @@ int BrowserBox::calcHeight() if (row.find("---", 0) == 0) { const int dashWidth = fontWidthMinus; - for (x = static_cast<unsigned int>(mPadding); x < wWidth; x ++) + for (x = CAST_U32(mPadding); x < wWidth; x ++) { - mLineParts.push_back(LinePart(static_cast<int>(x), - static_cast<int>(y) + mItemPadding, + mLineParts.push_back(LinePart(CAST_S32(x), + CAST_S32(y) + mItemPadding, selColor[0], selColor[1], "-", false)); - x += static_cast<unsigned int>(static_cast<int>( + x += CAST_U32(CAST_S32( dashWidth) - 2); } - y += static_cast<unsigned int>(fontHeight); + y += CAST_U32(fontHeight); continue; } else if (mEnableImages && row.find("~~~", 0) == 0) @@ -629,10 +629,10 @@ int BrowserBox::calcHeight() if (img) { img->incRef(); - mLineParts.push_back(LinePart(static_cast<int>(x), - static_cast<int>(y) + mItemPadding, + mLineParts.push_back(LinePart(CAST_S32(x), + CAST_S32(y) + mItemPadding, selColor[0], selColor[1], img)); - y += static_cast<unsigned int>(img->getHeight() + 2); + y += CAST_U32(img->getHeight() + 2); moreHeight += img->getHeight(); if (img->getWidth() > maxWidth) maxWidth = img->getWidth() + 2; @@ -645,7 +645,7 @@ int BrowserBox::calcHeight() prevColor[1] = selColor[1]; bold = false; - const int xPadding = static_cast<int>(mNewLinePadding) + mPadding; + const int xPadding = CAST_S32(mNewLinePadding) + mPadding; for (size_t start = 0, end = std::string::npos; start != std::string::npos; @@ -656,8 +656,8 @@ int BrowserBox::calcHeight() // Wrapped line continuation shall be indented if (wrapped) { - y += static_cast<unsigned int>(fontHeight); - x = static_cast<unsigned int>(xPadding); + y += CAST_U32(fontHeight); + x = CAST_U32(xPadding); wrapped = false; } @@ -683,7 +683,7 @@ int BrowserBox::calcHeight() const Color col[2] = { getThemeCharColor(c, valid), - getThemeCharColor(static_cast<signed char>( + getThemeCharColor(CAST_S8( c | 0x80), valid) }; @@ -763,17 +763,17 @@ int BrowserBox::calcHeight() } } - if (c == '<' && link < static_cast<signed>(mLinks.size())) + if (c == '<' && link < CAST_S32(mLinks.size())) { const int size = font->getWidth( - mLinks[static_cast<size_t>(link)].caption) + 1; + mLinks[CAST_SIZE(link)].caption) + 1; - BrowserLink &linkRef = mLinks[static_cast<size_t>( + BrowserLink &linkRef = mLinks[CAST_SIZE( link)]; - linkRef.x1 = static_cast<int>(x); - linkRef.y1 = static_cast<int>(y); + linkRef.x1 = CAST_S32(x); + linkRef.y1 = CAST_S32(y); linkRef.x2 = linkRef.x1 + size; - linkRef.y2 = static_cast<int>(y) + fontHeight - 1; + linkRef.y2 = CAST_S32(y) + fontHeight - 1; link++; } @@ -802,15 +802,15 @@ int BrowserBox::calcHeight() if (mEmotes) { const size_t sz = mEmotes->size(); - if (static_cast<size_t>(cid) < sz) + if (CAST_SIZE(cid) < sz) { Image *const img = mEmotes->get( - static_cast<size_t>(cid)); + CAST_SIZE(cid)); if (img) { mLineParts.push_back(LinePart( - static_cast<int>(x), - static_cast<int>(y) + mItemPadding, + CAST_S32(x), + CAST_S32(y) + mItemPadding, selColor[0], selColor[1], img)); x += 18; } @@ -844,7 +844,7 @@ int BrowserBox::calcHeight() // Auto wrap mode if (mMode == AUTO_WRAP && wWidth > 0 && width > 0 - && (x + static_cast<unsigned int>(width) + 10) > wWidth) + && (x + CAST_U32(width) + 10) > wWidth) { bool forced = false; @@ -862,7 +862,7 @@ int BrowserBox::calcHeight() { forced = true; end = row.size(); - x += static_cast<unsigned int>(hyphenWidth); + x += CAST_U32(hyphenWidth); continue; } @@ -879,14 +879,14 @@ int BrowserBox::calcHeight() } while (end > start && width > 0 && - (x + static_cast<unsigned int>(width) + 10) > wWidth); + (x + CAST_U32(width) + 10) > wWidth); if (forced) { - x -= static_cast<unsigned int>(hyphenWidth); + x -= CAST_U32(hyphenWidth); mLineParts.push_back(LinePart( - static_cast<int>(wWidth) - hyphenWidth, - static_cast<int>(y) + mItemPadding, + CAST_S32(wWidth) - hyphenWidth, + CAST_S32(y) + mItemPadding, selColor[0], selColor[1], hyphen, bold)); end++; // Skip to the next character } @@ -899,8 +899,8 @@ int BrowserBox::calcHeight() wrappedLines++; } - mLineParts.push_back(LinePart(static_cast<int>(x), - static_cast<int>(y) + mItemPadding, + mLineParts.push_back(LinePart(CAST_S32(x), + CAST_S32(y) + mItemPadding, selColor[0], selColor[1], part.c_str(), bold)); if (bold) @@ -911,16 +911,16 @@ int BrowserBox::calcHeight() if (mMode == AUTO_WRAP && (width == 0 && !processed)) break; - x += static_cast<unsigned int>(width); + x += CAST_U32(width); if (x > mDataWidth) mDataWidth = x; } - y += static_cast<unsigned int>(fontHeight); + y += CAST_U32(fontHeight); } - if (static_cast<signed>(wWidth) != maxWidth) + if (CAST_S32(wWidth) != maxWidth) setWidth(maxWidth); - return (static_cast<int>(mTextRows.size()) + wrappedLines) + return (CAST_S32(mTextRows.size()) + wrappedLines) * fontHeight + moreHeight + 2 * mPadding; } @@ -981,7 +981,7 @@ void BrowserBox::setForegroundColorAll(const Color &color1, void BrowserBox::moveSelectionUp() { if (mSelectedLink <= 0) - mSelectedLink = static_cast<signed>(mLinks.size()) - 1; + mSelectedLink = CAST_S32(mLinks.size()) - 1; else mSelectedLink --; } @@ -1002,6 +1002,6 @@ void BrowserBox::selectSelection() return; } - mLinkHandler->handleLink(mLinks[static_cast<size_t>(mSelectedLink)].link, + mLinkHandler->handleLink(mLinks[CAST_SIZE(mSelectedLink)].link, nullptr); } diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp index b74ec842f..7aed3469c 100644 --- a/src/gui/widgets/characterdisplay.cpp +++ b/src/gui/widgets/characterdisplay.cpp @@ -134,7 +134,7 @@ void CharacterDisplay::mouseMoved(MouseEvent &event A_UNUSED) name, // TRANSLATORS: character level strprintf(_("Level: %u"), - static_cast<uint32_t>( + CAST_U32( mCharacter->data.mAttributes[Attributes::LEVEL])), // TRANSLATORS: character money strprintf(_("Money: %s"), Units::formatCurrency( diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp index 10469adac..8d374fc4c 100644 --- a/src/gui/widgets/characterviewnormal.cpp +++ b/src/gui/widgets/characterviewnormal.cpp @@ -44,7 +44,7 @@ CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget, character->setVisible(Visible_true); } const size_t sz = mCharacterEntries->size(); - if (mSelected >= 0 && mSelected < static_cast<signed>(sz)) + if (mSelected >= 0 && mSelected < CAST_S32(sz)) { CharacterDisplay *const display = (*mCharacterEntries)[mSelected]; if (display) @@ -72,7 +72,7 @@ CharacterViewNormal::~CharacterViewNormal() void CharacterViewNormal::show(const int i) { - const int sz = static_cast<signed>(mCharacterEntries->size()); + const int sz = CAST_S32(mCharacterEntries->size()); if (i >= 0 && i < sz) { if (mSelected >= 0) @@ -84,7 +84,7 @@ void CharacterViewNormal::show(const int i) void CharacterViewNormal::resize() { - const int sz = static_cast<signed>(mCharacterEntries->size()); + const int sz = CAST_S32(mCharacterEntries->size()); if (sz <= 0) return; const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; diff --git a/src/gui/widgets/characterviewsmall.cpp b/src/gui/widgets/characterviewsmall.cpp index 3ae0229c9..24961f3ce 100644 --- a/src/gui/widgets/characterviewsmall.cpp +++ b/src/gui/widgets/characterviewsmall.cpp @@ -47,7 +47,7 @@ CharacterViewSmall::CharacterViewSmall(CharSelectDialog *const widget, { add(*it); } - const int sz = static_cast<signed>(mCharacterEntries->size()); + const int sz = CAST_S32(mCharacterEntries->size()); if (sz > 0) { mSelected = 0; @@ -78,7 +78,7 @@ CharacterViewSmall::~CharacterViewSmall() void CharacterViewSmall::show(const int i) { - const int sz = static_cast<signed>(mCharacterEntries->size()); + const int sz = CAST_S32(mCharacterEntries->size()); if (sz <= 0) return; if (mSelectedEntry) @@ -97,7 +97,7 @@ void CharacterViewSmall::show(const int i) void CharacterViewSmall::resize() { - const int sz = static_cast<signed>(mCharacterEntries->size()); + const int sz = CAST_S32(mCharacterEntries->size()); if (sz <= 0) return; const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp index 078f5bb48..a668f2d6f 100644 --- a/src/gui/widgets/colorpage.cpp +++ b/src/gui/widgets/colorpage.cpp @@ -36,11 +36,11 @@ ColorPage::ColorPage(const Widget2 *const widget, mItemPadding = mSkin ? mSkin->getOption("itemPadding") : 1; mRowHeight = 13; const Font *const font = getFont(); - mRowHeight = static_cast<unsigned int>(font->getHeight() + + mRowHeight = CAST_U32(font->getHeight() + 2 * mItemPadding); if (mListModel) { - setHeight(static_cast<int>(getRowHeight()) * + setHeight(CAST_S32(getRowHeight()) * mListModel->getNumberOfElements() + 2 * mPadding + 20); } @@ -57,11 +57,11 @@ void ColorPage::draw(Graphics *graphics) const ColorModel *const model = static_cast<ColorModel* const>( mListModel); - mHighlightColor.a = static_cast<unsigned int>(mAlpha * 255.0F); + mHighlightColor.a = CAST_U32(mAlpha * 255.0F); updateAlpha(); Font *const font = getFont(); - const int rowHeight = static_cast<int>(getRowHeight()); + const int rowHeight = CAST_S32(getRowHeight()); const int width = mDimension.width; if (mSelected >= 0) @@ -115,7 +115,7 @@ void ColorPage::adjustSize() BLOCK_START("ColorPage::adjustSize") if (mListModel) { - setHeight(static_cast<int>(getRowHeight()) * + setHeight(CAST_S32(getRowHeight()) * mListModel->getNumberOfElements() + 2 * mPadding + 20); } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 629bda46b..506503e01 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -150,7 +150,7 @@ DropDown::DropDown(const Widget2 *const widget, if (mSkin) { mSpacing = mSkin->getOption("spacing"); - mFrameSize = static_cast<unsigned int>(mSkin->getOption("frameSize")); + mFrameSize = CAST_U32(mSkin->getOption("frameSize")); mPadding = mSkin->getPadding(); mImagePadding = mSkin->getOption("imagePadding"); } @@ -219,7 +219,7 @@ void DropDown::draw(Graphics* graphics) updateAlpha(); - const unsigned int alpha = static_cast<unsigned int>(mAlpha * 255.0F); + const unsigned int alpha = CAST_U32(mAlpha * 255.0F); const int pad = 2 * mPadding; mHighlightColor.a = alpha; mShadowColor.a = alpha; @@ -294,7 +294,7 @@ void DropDown::safeDraw(Graphics* graphics) void DropDown::drawFrame(Graphics *graphics) { BLOCK_START("DropDown::drawFrame") - const int bs2 = static_cast<int>(getFrameSize()); + const int bs2 = CAST_S32(getFrameSize()); const Rect &rect = mDimension; graphics->drawImageRect(0, 0, rect.width + bs2, rect.height + bs2, @@ -305,7 +305,7 @@ void DropDown::drawFrame(Graphics *graphics) void DropDown::safeDrawFrame(Graphics *graphics) { BLOCK_START("DropDown::drawFrame") - const int bs2 = static_cast<int>(getFrameSize()); + const int bs2 = CAST_S32(getFrameSize()); const Rect &rect = mDimension; graphics->drawImageRect(0, 0, rect.width + bs2, rect.height + bs2, @@ -476,7 +476,7 @@ void DropDown::dropDown() int x = 0; int y = 0; getAbsolutePosition(x, y); - const int frame = static_cast<int>(mParent->getFrameSize()); + const int frame = CAST_S32(mParent->getFrameSize()); const int pad = mPopup->getPadding(); const int pad2 = pad * 2; diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp index 92c10f8a9..6e3732413 100644 --- a/src/gui/widgets/emotepage.cpp +++ b/src/gui/widgets/emotepage.cpp @@ -142,7 +142,7 @@ int EmotePage::getIndexFromGrid(const int x, const int y) const return -1; const int cols = width / emoteWidth; const int index = (y / emoteHeight) * cols + (x / emoteWidth); - if (index >= static_cast<int>(mEmotes->size())) + if (index >= CAST_S32(mEmotes->size())) return -1; return index; } diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 1a7f73b95..6df0cd398 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -97,7 +97,7 @@ void EmoteShortcutContainer::draw(Graphics *restrict graphics) restrict2 Font *const font = getFont(); drawBackground(graphics); - unsigned sz = static_cast<unsigned>(mEmoteImg.size()); + unsigned sz = CAST_U32(mEmoteImg.size()); if (sz > mMaxItems) sz = mMaxItems; for (unsigned i = 0; i < sz; i++) @@ -149,7 +149,7 @@ void EmoteShortcutContainer::safeDraw(Graphics *restrict graphics) restrict2 Font *const font = getFont(); safeDrawBackground(graphics); - unsigned sz = static_cast<unsigned>(mEmoteImg.size()); + unsigned sz = CAST_U32(mEmoteImg.size()); if (sz > mMaxItems) sz = mMaxItems; for (unsigned i = 0; i < sz; i++) @@ -258,7 +258,7 @@ void EmoteShortcutContainer::mouseMoved(MouseEvent &restrict event) restrict2 textPopup->setVisible(Visible_false); - if (static_cast<size_t>(index) < mEmoteImg.size() && mEmoteImg[index]) + if (CAST_SIZE(index) < mEmoteImg.size() && mEmoteImg[index]) { const EmoteSprite *restrict const sprite = mEmoteImg[index]; textPopup->show(viewport->mMouseX, viewport->mMouseY, diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp index 23daafb8e..fd9b4c660 100644 --- a/src/gui/widgets/extendedlistbox.cpp +++ b/src/gui/widgets/extendedlistbox.cpp @@ -59,7 +59,7 @@ void ExtendedListBox::draw(Graphics *graphics) updateAlpha(); Font *const font = getFont(); - const int height = static_cast<int>(mRowHeight); + const int height = CAST_S32(mRowHeight); const int pad2 = 2 + mPadding; const int width = mDimension.width; int textPos = (height - font->getHeight()) / 2 + mPadding; @@ -89,7 +89,7 @@ void ExtendedListBox::draw(Graphics *graphics) { const size_t strSize = str.size(); size_t divPos = strSize / 2; - if (divPos > 0 && static_cast<unsigned char>( + if (divPos > 0 && CAST_U8( str[divPos - 1]) >= 0xc0) { divPos --; @@ -130,7 +130,7 @@ void ExtendedListBox::draw(Graphics *graphics) if (minY != -1) { - mHighlightColor.a = static_cast<unsigned int>(mAlpha * 255.0F); + mHighlightColor.a = CAST_U32(mAlpha * 255.0F); graphics->setColor(mHighlightColor); graphics->fillRectangle(Rect(mPadding, minY + mPadding, width - pad2, maxY - minY + height)); @@ -233,7 +233,7 @@ int ExtendedListBox::getSelectionByMouse(const int y) const if (mListItems.empty() && mSelectedItems.empty()) return ListBox::getSelectionByMouse(y); - const int height = static_cast<int>(mRowHeight); + const int height = CAST_S32(mRowHeight); const size_t itemsSz = mListItems.size(); for (size_t f = 0; f < itemsSz; f ++) { diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp index 7984ef0f7..d6f10248e 100644 --- a/src/gui/widgets/flowcontainer.cpp +++ b/src/gui/widgets/flowcontainer.cpp @@ -48,7 +48,7 @@ void FlowContainer::widgetResized(const Event &event A_UNUSED) return; } - const int itemCount = static_cast<int>(mWidgets.size()); + const int itemCount = CAST_S32(mWidgets.size()); if (!mBoxWidth) mGridWidth = getWidth(); diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index 00f925aff..c41d4886c 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -235,7 +235,7 @@ void GuiTable::draw(Graphics* graphics) const int y = rect.y; if (mOpaque) { - mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255.0F); + mBackgroundColor.a = CAST_U32(mAlpha * 255.0F); graphics->setColor(mBackgroundColor); graphics->fillRectangle(Rect(0, 0, width, height)); } @@ -250,7 +250,7 @@ void GuiTable::draw(Graphics* graphics) if (first_row < 0) first_row = 0; - unsigned int rows_nr = static_cast<unsigned int>(1 + + unsigned int rows_nr = CAST_U32(1 + height / rHeight); // May overestimate by one. unsigned int max_rows_nr; if (mModel->getRows() < first_row) @@ -259,7 +259,7 @@ void GuiTable::draw(Graphics* graphics) } else { - max_rows_nr = static_cast<unsigned int>( + max_rows_nr = CAST_U32( mModel->getRows() - first_row); // clip if neccessary: } if (max_rows_nr < rows_nr) @@ -268,23 +268,23 @@ void GuiTable::draw(Graphics* graphics) // Now determine the first and last column // Take the easy way out; these are usually bounded and all visible. const unsigned first_column = 0; - const unsigned last_column1 = static_cast<unsigned int>( + const unsigned last_column1 = CAST_U32( mModel->getColumns()); int y_offset = first_row * rHeight; - for (unsigned int r = static_cast<unsigned int>(first_row); - r < static_cast<unsigned int>(first_row) + rows_nr; + for (unsigned int r = CAST_U32(first_row); + r < CAST_U32(first_row) + rows_nr; ++r) { int x_offset = 0; for (unsigned c = first_column; c + 1 <= last_column1; ++c) { - Widget *const widget = mModel->getElementAt(static_cast<int>(r), - static_cast<int>(c)); - const int cWidth = static_cast<int>(getColumnWidth( - static_cast<int>(c))); + Widget *const widget = mModel->getElementAt(CAST_S32(r), + CAST_S32(c)); + const int cWidth = CAST_S32(getColumnWidth( + CAST_S32(c))); if (widget) { Rect bounds(x_offset, y_offset, cWidth, rHeight); @@ -299,19 +299,19 @@ void GuiTable::draw(Graphics* graphics) if (mSelectedRow > -1) { - mHighlightColor.a = static_cast<unsigned int>( + mHighlightColor.a = CAST_U32( mAlpha * 255.0F); graphics->setColor(mHighlightColor); - if (mLinewiseMode && r == static_cast<unsigned>( + if (mLinewiseMode && r == CAST_U32( mSelectedRow) && c == 0) { graphics->fillRectangle(Rect(0, y_offset, width, rHeight)); } else if (!mLinewiseMode && mSelectedColumn > 0 - && c == static_cast<unsigned>(mSelectedColumn) - && r == static_cast<unsigned>(mSelectedRow)) + && c == CAST_U32(mSelectedColumn) + && r == CAST_U32(mSelectedRow)) { graphics->fillRectangle(Rect( x_offset, y_offset, cWidth, rHeight)); @@ -353,7 +353,7 @@ void GuiTable::safeDraw(Graphics* graphics) const int y = rect.y; if (mOpaque) { - mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255.0F); + mBackgroundColor.a = CAST_U32(mAlpha * 255.0F); graphics->setColor(mBackgroundColor); graphics->fillRectangle(Rect(0, 0, width, height)); } @@ -368,7 +368,7 @@ void GuiTable::safeDraw(Graphics* graphics) if (first_row < 0) first_row = 0; - unsigned int rows_nr = static_cast<unsigned int>( + unsigned int rows_nr = CAST_U32( 1 + height / rHeight); // May overestimate by one. unsigned int max_rows_nr; if (mModel->getRows() < first_row) @@ -377,7 +377,7 @@ void GuiTable::safeDraw(Graphics* graphics) } else { - max_rows_nr = static_cast<unsigned int>( + max_rows_nr = CAST_U32( mModel->getRows() - first_row); // clip if neccessary: } if (max_rows_nr < rows_nr) @@ -386,23 +386,23 @@ void GuiTable::safeDraw(Graphics* graphics) // Now determine the first and last column // Take the easy way out; these are usually bounded and all visible. const unsigned int first_column = 0; - const unsigned int last_column1 = static_cast<unsigned int>( + const unsigned int last_column1 = CAST_U32( mModel->getColumns()); int y_offset = first_row * rHeight; - for (unsigned int r = static_cast<unsigned int>(first_row); - r < static_cast<unsigned int>(first_row + static_cast<int>(rows_nr)); + for (unsigned int r = CAST_U32(first_row); + r < CAST_U32(first_row + CAST_S32(rows_nr)); ++r) { int x_offset = 0; for (unsigned c = first_column; c + 1 <= last_column1; ++c) { - Widget *const widget = mModel->getElementAt(static_cast<int>(r), - static_cast<int>(c)); - const int cWidth = static_cast<int>(getColumnWidth( - static_cast<int>(c))); + Widget *const widget = mModel->getElementAt(CAST_S32(r), + CAST_S32(c)); + const int cWidth = CAST_S32(getColumnWidth( + CAST_S32(c))); if (widget) { Rect bounds(x_offset, y_offset, cWidth, rHeight); @@ -417,19 +417,19 @@ void GuiTable::safeDraw(Graphics* graphics) if (mSelectedRow > -1) { - mHighlightColor.a = static_cast<unsigned int>( + mHighlightColor.a = CAST_U32( mAlpha * 255.0F); graphics->setColor(mHighlightColor); - if (mLinewiseMode && r == static_cast<unsigned>( + if (mLinewiseMode && r == CAST_U32( mSelectedRow) && c == 0) { graphics->fillRectangle(Rect(0, y_offset, width, rHeight)); } else if (!mLinewiseMode && mSelectedColumn > 0 - && c == static_cast<unsigned>(mSelectedColumn) - && r == static_cast<unsigned>(mSelectedRow)) + && c == CAST_U32(mSelectedColumn) + && r == CAST_U32(mSelectedRow)) { graphics->fillRectangle(Rect( x_offset, y_offset, cWidth, rHeight)); diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp index 925ff34b4..cb01c12a3 100644 --- a/src/gui/widgets/inttextfield.cpp +++ b/src/gui/widgets/inttextfield.cpp @@ -130,7 +130,7 @@ void IntTextField::setValue(const int i) const std::string valStr = toString(mValue); setText(valStr); - setCaretPosition(static_cast<unsigned>(valStr.length()) + 1); + setCaretPosition(CAST_U32(valStr.length()) + 1); } void IntTextField::setDefaultValue(const int value) diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 4c183d87d..9bb1f0da3 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -638,7 +638,7 @@ void ItemContainer::mousePressed(MouseEvent &event) if (itemShortcutWindow) { const int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS)) + if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)) { if (itemShortcut[num]) itemShortcut[num]->setItemSelected(item); @@ -1047,7 +1047,7 @@ void ItemContainer::updateMatrix() mRedraw = true; delete []mShowMatrix; - mShowMatrix = new int[static_cast<size_t>(mGridRows * mGridColumns)]; + mShowMatrix = new int[CAST_SIZE(mGridRows * mGridColumns)]; std::vector<ItemIdPair*> sortedItems; int i = 0; diff --git a/src/gui/widgets/layoutarray.cpp b/src/gui/widgets/layoutarray.cpp index 74bbebd87..5b726b9cc 100644 --- a/src/gui/widgets/layoutarray.cpp +++ b/src/gui/widgets/layoutarray.cpp @@ -59,7 +59,7 @@ LayoutCell &LayoutArray::at(const int x, const int y, const int w, const int h) { resizeGrid(x + w, y + h); - LayoutCell *&cell = mCells[static_cast<size_t>(y)][static_cast<size_t>(x)]; + LayoutCell *&cell = mCells[CAST_SIZE(y)][static_cast<size_t>(x)]; if (!cell) cell = new LayoutCell; return *cell; @@ -67,22 +67,22 @@ LayoutCell &LayoutArray::at(const int x, const int y, void LayoutArray::resizeGrid(int w, const int h) { - const bool extW = w && w > static_cast<int>(mSizes[0].size()); - const bool extH = h && h > static_cast<int>(mSizes[1].size()); + const bool extW = w && w > CAST_S32(mSizes[0].size()); + const bool extH = h && h > CAST_S32(mSizes[1].size()); if (!extW && !extH) return; if (extH) { - mSizes[1].resize(static_cast<size_t>(h), LayoutType::DEF); - mCells.resize(static_cast<size_t>(h)); + mSizes[1].resize(CAST_SIZE(h), LayoutType::DEF); + mCells.resize(CAST_SIZE(h)); if (!extW) - w = static_cast<int>(mSizes[0].size()); + w = CAST_S32(mSizes[0].size()); } if (extW) - mSizes[0].resize(static_cast<size_t>(w), LayoutType::DEF); + mSizes[0].resize(CAST_SIZE(w), LayoutType::DEF); std::vector <std::vector <LayoutCell *> >::iterator i = mCells.begin(); @@ -90,7 +90,7 @@ void LayoutArray::resizeGrid(int w, const int h) i_end = mCells.end(); while (i != i_end) { - i->resize(static_cast<size_t>(w), nullptr); + i->resize(CAST_SIZE(w), nullptr); ++i; } } @@ -98,23 +98,23 @@ void LayoutArray::resizeGrid(int w, const int h) void LayoutArray::setColWidth(const int n, const int w) { resizeGrid(n + 1, 0); - mSizes[0U][static_cast<size_t>(n)] = w; + mSizes[0U][CAST_SIZE(n)] = w; } void LayoutArray::setRowHeight(const int n, const int h) { resizeGrid(0, n + 1); - mSizes[1][static_cast<size_t>(n)] = h; + mSizes[1][CAST_SIZE(n)] = h; } void LayoutArray::matchColWidth(const int n1, const int n2) { resizeGrid(std::max(n1, n2) + 1, 0); const std::vector<int> widths = getSizes(0, LayoutType::DEF); - const int s = std::max(widths[static_cast<size_t>(n1)], - widths[static_cast<size_t>(n2)]); - mSizes[0][static_cast<size_t>(n1)] = s; - mSizes[0][static_cast<size_t>(n2)] = s; + const int s = std::max(widths[CAST_SIZE(n1)], + widths[CAST_SIZE(n2)]); + mSizes[0][CAST_SIZE(n1)] = s; + mSizes[0][CAST_SIZE(n2)] = s; } void LayoutArray::extend(const int x, const int y, const int w, const int h) @@ -147,8 +147,8 @@ LayoutCell &LayoutArray::place(Widget *const widget, const int x, cell.mVPadding = 0; cell.mAlign[0] = LayoutCell::FILL; cell.mAlign[1] = LayoutCell::FILL; - int &cs = mSizes[0][static_cast<size_t>(x)]; - int &rs = mSizes[1][static_cast<size_t>(y)]; + int &cs = mSizes[0][CAST_SIZE(x)]; + int &rs = mSizes[1][CAST_SIZE(y)]; if (cs == LayoutType::DEF && w == 1) cs = 0; if (rs == LayoutType::DEF && h == 1) @@ -196,8 +196,8 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const if (dim < 0 || dim >= 2) return mSizes[1]; - const int gridW = static_cast<int>(mSizes[0].size()); - const int gridH = static_cast<int>(mSizes[1].size()); + const int gridW = CAST_S32(mSizes[0].size()); + const int gridH = CAST_S32(mSizes[1].size()); std::vector<int> sizes = mSizes[dim]; // Compute minimum sizes. @@ -205,8 +205,8 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const { for (int gridX = 0; gridX < gridW; ++gridX) { - const LayoutCell *const cell = mCells[static_cast<size_t>(gridY)] - [static_cast<size_t>(gridX)]; + const LayoutCell *const cell = mCells[CAST_SIZE(gridY)] + [CAST_SIZE(gridX)]; if (!cell || cell->mType == LayoutCell::NONE) continue; @@ -214,8 +214,8 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const { const int n = (dim == 0 ? gridX : gridY); const int s = cell->mSize[dim] + cell->mVPadding * 2; - if (s > sizes[static_cast<size_t>(n)]) - sizes[static_cast<size_t>(n)] = s; + if (s > sizes[CAST_SIZE(n)]) + sizes[CAST_SIZE(n)] = s; } } } @@ -224,22 +224,22 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const return sizes; // Compute the FILL sizes. - const int nb = static_cast<int>(sizes.size()); + const int nb = CAST_S32(sizes.size()); int nbFill = 0; for (int i = 0; i < nb; ++i) { - if (mSizes[static_cast<size_t>(dim)][static_cast<size_t>(i)] + if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] <= LayoutType::DEF) { ++nbFill; - if (mSizes[static_cast<size_t>(dim)][static_cast<size_t>(i)] == + if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] == LayoutType::SET || - sizes[static_cast<size_t>(i)] <= LayoutType::DEF) + sizes[CAST_SIZE(i)] <= LayoutType::DEF) { - sizes[static_cast<size_t>(i)] = 0; + sizes[CAST_SIZE(i)] = 0; } } - upp -= sizes[static_cast<size_t>(i)] + mSpacing; + upp -= sizes[CAST_SIZE(i)] + mSpacing; } upp = upp + mSpacing; @@ -248,14 +248,14 @@ std::vector<int> LayoutArray::getSizes(const int dim, int upp) const for (int i = 0; i < nb; ++i) { - if (mSizes[static_cast<size_t>(dim)][static_cast<size_t>(i)] > + if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] > LayoutType::DEF) { continue; } const int s = upp / nbFill; - sizes[static_cast<size_t>(i)] += s; + sizes[CAST_SIZE(i)] += s; upp -= s; --nbFill; } @@ -267,11 +267,11 @@ int LayoutArray::getSize(const int dim) const { std::vector<int> sizes = getSizes(dim, LayoutType::DEF); int size = 0; - const int nb = static_cast<int>(sizes.size()); + const int nb = CAST_S32(sizes.size()); for (int i = 0; i < nb; ++i) { - if (sizes[static_cast<size_t>(i)] > LayoutType::DEF) - size += sizes[static_cast<size_t>(i)]; + if (sizes[CAST_SIZE(i)] > LayoutType::DEF) + size += sizes[CAST_SIZE(i)]; size += mSpacing; } return size - mSpacing; @@ -280,33 +280,33 @@ int LayoutArray::getSize(const int dim) const void LayoutArray::reflow(const int nx, const int ny, const int nw, const int nh) { - const int gridW = static_cast<int>(mSizes[0].size()); - const int gridH = static_cast<int>(mSizes[1].size()); + const int gridW = CAST_S32(mSizes[0].size()); + const int gridH = CAST_S32(mSizes[1].size()); 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()); + const int szW = CAST_S32(widths.size()); + const int szH = CAST_S32(heights.size()); int y = ny; for (int gridY = 0; gridY < gridH; ++gridY) { int x = nx; for (int gridX = 0; gridX < gridW; ++gridX) { - LayoutCell *const cell = mCells[static_cast<size_t>(gridY)] - [static_cast<size_t>(gridX)]; + LayoutCell *const cell = mCells[CAST_SIZE(gridY)] + [CAST_SIZE(gridX)]; if (cell && cell->mType != LayoutCell::NONE) { int dx = x, dy = y, dw = 0, dh = 0; align(dx, dw, 0, *cell, - &widths[static_cast<size_t>(gridX)], szW - gridX); + &widths[CAST_SIZE(gridX)], szW - gridX); align(dy, dh, 1, *cell, - &heights[static_cast<size_t>(gridY)], szH - gridY); + &heights[CAST_SIZE(gridY)], szH - gridY); cell->reflow(dx, dy, dw, dh); } - x += widths[static_cast<size_t>(gridX)] + mSpacing; + x += widths[CAST_SIZE(gridX)] + mSpacing; } - y += heights[static_cast<size_t>(gridY)] + mSpacing; + y += heights[CAST_SIZE(gridY)] + mSpacing; } } diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index c827911eb..ced9dcb99 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -122,7 +122,7 @@ ListBox::ListBox(const Widget2 *const widget, } const Font *const font = getFont(); - mRowHeight = static_cast<unsigned int>( + mRowHeight = CAST_U32( font->getHeight() + 2 * mItemPadding); } @@ -157,10 +157,10 @@ void ListBox::draw(Graphics *graphics) BLOCK_START("ListBox::draw") updateAlpha(); - mHighlightColor.a = static_cast<unsigned int>(mAlpha * 255.0F); + mHighlightColor.a = CAST_U32(mAlpha * 255.0F); graphics->setColor(mHighlightColor); Font *const font = getFont(); - const int rowHeight = static_cast<int>(getRowHeight()); + const int rowHeight = CAST_S32(getRowHeight()); const int width = mDimension.width; if (mCenterText) @@ -359,7 +359,7 @@ void ListBox::adjustSize() BLOCK_START("ListBox::adjustSize") if (mListModel) { - setHeight(static_cast<int>(getRowHeight()) * + setHeight(CAST_S32(getRowHeight()) * mListModel->getNumberOfElements() + 2 * mPadding); } BLOCK_END("ListBox::adjustSize") @@ -376,7 +376,7 @@ int ListBox::getSelectionByMouse(const int y) const { if (y < mPadding) return -1; - return (y - mPadding) / static_cast<int>(getRowHeight()); + return (y - mPadding) / CAST_S32(getRowHeight()); } void ListBox::setSelected(const int selected) @@ -400,9 +400,9 @@ void ListBox::setSelected(const int selected) if (mSelected < 0) scroll.y = 0; else - scroll.y = static_cast<int>(getRowHeight()) * mSelected; + scroll.y = CAST_S32(getRowHeight()) * mSelected; - scroll.height = static_cast<int>(getRowHeight()); + scroll.height = CAST_S32(getRowHeight()); showPart(scroll); distributeValueChangedEvent(); diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp index a385e8387..ae47d4500 100644 --- a/src/gui/widgets/passwordfield.cpp +++ b/src/gui/widgets/passwordfield.cpp @@ -29,9 +29,9 @@ PasswordField::PasswordField(const Widget2 *const widget, const std::string &text) : TextField(widget, text), - mPasswordChar(mSkin ? static_cast<char>( + mPasswordChar(mSkin ? CAST_8( mSkin->getOption("passwordChar", 42)) - : static_cast<char>(42)) + : CAST_8(42)) { } diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 03db3f97e..455ccc31c 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -161,7 +161,7 @@ void ProgressBar::draw(Graphics *graphics) } updateAlpha(); - mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255); + mBackgroundColor.a = CAST_U32(mAlpha * 255); if (mRedraw || graphics->getRedraw()) { @@ -173,7 +173,7 @@ void ProgressBar::draw(Graphics *graphics) { const unsigned int pad = 2 * mFillPadding; const int maxWidth = mDimension.width - pad; - int width = static_cast<int>(mProgress + int width = CAST_S32(mProgress * static_cast<float>(maxWidth)); if (width > 0) { @@ -194,7 +194,7 @@ void ProgressBar::draw(Graphics *graphics) graphics->setColor(mBackgroundColor); const unsigned int pad = 2 * mFillPadding; const int maxWidth = mDimension.width - pad; - int width = static_cast<int>(mProgress * static_cast<float>(maxWidth)); + int width = CAST_S32(mProgress * static_cast<float>(maxWidth)); if (width > 0) { if (width > maxWidth) @@ -240,7 +240,7 @@ void ProgressBar::safeDraw(Graphics *graphics) } updateAlpha(); - mBackgroundColor.a = static_cast<unsigned int>(mAlpha * 255); + mBackgroundColor.a = CAST_U32(mAlpha * 255); graphics->drawImageRect(0, 0, mDimension.width, mDimension.height, mSkin->getBorder()); @@ -248,7 +248,7 @@ void ProgressBar::safeDraw(Graphics *graphics) { const unsigned int pad = 2 * mFillPadding; const int maxWidth = mDimension.width - pad; - int width = static_cast<int>(mProgress + int width = CAST_S32(mProgress * static_cast<float>(maxWidth)); if (width > 0) { @@ -265,7 +265,7 @@ void ProgressBar::safeDraw(Graphics *graphics) graphics->setColor(mBackgroundColor); const unsigned int pad = 2 * mFillPadding; const int maxWidth = mDimension.width - pad; - int width = static_cast<int>(mProgress * static_cast<float>(maxWidth)); + int width = CAST_S32(mProgress * static_cast<float>(maxWidth)); if (width > 0) { if (width > maxWidth) diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 4edd5b1a0..5bf67bfda 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -496,10 +496,10 @@ Image *ScrollArea::getImageByState(Rect &dim, const BUTTON_DIR dir) case BUTTONS_DIR: default: logger->log("ScrollArea::drawButton unknown dir: " - + toString(static_cast<unsigned>(dir))); + + toString(CAST_U32(dir))); return nullptr; } - return buttons[static_cast<size_t>(dir)][state]; + return buttons[CAST_SIZE(dir)][state]; } void ScrollArea::drawButton(Graphics *const graphics, @@ -790,12 +790,12 @@ void ScrollArea::mousePressed(MouseEvent& event) if (y < getVerticalMarkerDimension().y) { setVerticalScrollAmount(mVScroll - - static_cast<int>(getChildrenArea().height * 0.95)); + - CAST_S32(getChildrenArea().height * 0.95)); } else { setVerticalScrollAmount(mVScroll - + static_cast<int>(getChildrenArea().height * 0.95)); + + CAST_S32(getChildrenArea().height * 0.95)); } event.consume(); } @@ -811,12 +811,12 @@ void ScrollArea::mousePressed(MouseEvent& event) if (x < getHorizontalMarkerDimension().x) { setHorizontalScrollAmount(mHScroll - - static_cast<int>(getChildrenArea().width * 0.95)); + - CAST_S32(getChildrenArea().width * 0.95)); } else { setHorizontalScrollAmount(mHScroll - + static_cast<int>(getChildrenArea().width * 0.95)); + + CAST_S32(getChildrenArea().width * 0.95)); } event.consume(); } diff --git a/src/gui/widgets/selldialog.cpp b/src/gui/widgets/selldialog.cpp index 7716c9a9c..189babc89 100644 --- a/src/gui/widgets/selldialog.cpp +++ b/src/gui/widgets/selldialog.cpp @@ -256,7 +256,7 @@ void SellDialog::action(const ActionEvent &event) if (eventId == "slider") { - mAmountItems = static_cast<int>(mSlider->getValue()); + mAmountItems = CAST_S32(mSlider->getValue()); updateButtonsAndLabels(); } else if (eventId == "inc" && mSlider && mAmountItems < mMaxItems) diff --git a/src/gui/widgets/serverslistbox.h b/src/gui/widgets/serverslistbox.h index 15295f0a8..444e70c9b 100644 --- a/src/gui/widgets/serverslistbox.h +++ b/src/gui/widgets/serverslistbox.h @@ -53,11 +53,11 @@ class ServersListBox final : public ListBox updateAlpha(); - mHighlightColor.a = static_cast<int>(mAlpha * 255.0F); + mHighlightColor.a = CAST_S32(mAlpha * 255.0F); graphics->setColor(mHighlightColor); const int height = getRowHeight(); - mNotSupportedColor.a = static_cast<int>(mAlpha * 255.0F); + mNotSupportedColor.a = CAST_S32(mAlpha * 255.0F); // Draw filled rectangle around the selected list element if (mSelected >= 0) diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 87ea1c908..be9f2000f 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -993,14 +993,14 @@ void SetupItemSlider2::action(const ActionEvent &event A_UNUSED) void SetupItemSlider2::updateLabel() { - int val = static_cast<int>(mSlider->getValue()) - mMin; + int val = CAST_S32(mSlider->getValue()) - mMin; if (val < 0) { val = 0; } else { - const int sz = static_cast<signed>(mValues->size()); + const int sz = CAST_S32(mValues->size()); if (val >= sz) val = sz - 1; } diff --git a/src/gui/widgets/setuptouchitem.cpp b/src/gui/widgets/setuptouchitem.cpp index 8c14d9f19..fb6cca184 100644 --- a/src/gui/widgets/setuptouchitem.cpp +++ b/src/gui/widgets/setuptouchitem.cpp @@ -118,7 +118,7 @@ void SetupActionDropDown::fromWidget() if (!mDropDown || !mModel) return; - mValue = toString(static_cast<int>(mModel->getActionFromSelection( + mValue = toString(CAST_S32(mModel->getActionFromSelection( mDropDown->getSelected()))); } diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 1477f94e7..ce5f5f8e9 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -91,7 +91,7 @@ void ShopListBox::draw(Graphics *graphics) if (settings.guiAlpha != mAlpha) mAlpha = settings.guiAlpha; - const unsigned int alpha = static_cast<unsigned int>(mAlpha * 255.0F); + const unsigned int alpha = CAST_U32(mAlpha * 255.0F); Font *const font = getFont(); const int sz = mListModel->getNumberOfElements(); diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp index dbbbaceba..8470d0b57 100644 --- a/src/gui/widgets/shortcutcontainer.cpp +++ b/src/gui/widgets/shortcutcontainer.cpp @@ -92,7 +92,7 @@ void ShortcutContainer::widgetResized(const Event &event A_UNUSED) if (mGridWidth < 1) mGridWidth = 1; - mGridHeight = mMaxItems / static_cast<unsigned int>(mGridWidth); + mGridHeight = mMaxItems / CAST_U32(mGridWidth); if (mMaxItems % mGridWidth != 0 || mGridHeight < 1) ++mGridHeight; @@ -110,7 +110,7 @@ int ShortcutContainer::getIndexFromGrid(const int pointX, int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth; if (!tRect.isPointInRect(pointX, pointY) || - index >= static_cast<int>(mMaxItems) || index < 0) + index >= CAST_S32(mMaxItems) || index < 0) { index = -1; } diff --git a/src/gui/widgets/skillinfo.cpp b/src/gui/widgets/skillinfo.cpp index dd8863206..4174146e2 100644 --- a/src/gui/widgets/skillinfo.cpp +++ b/src/gui/widgets/skillinfo.cpp @@ -152,7 +152,7 @@ void SkillInfo::update() default: // TRANSLATORS: Skill type skillEffect = strprintf(typeStr, _("Unknown:")); - skillEffect.append(" ").append(toString(static_cast<int>(type))); + skillEffect.append(" ").append(toString(CAST_S32(type))); break; } diff --git a/src/gui/widgets/skilllistbox.h b/src/gui/widgets/skilllistbox.h index 74aff1636..e0d1b2d91 100644 --- a/src/gui/widgets/skilllistbox.h +++ b/src/gui/widgets/skilllistbox.h @@ -93,7 +93,7 @@ class SkillListBox final : public ListBox SkillModel *const model = static_cast<SkillModel*>(mListModel); updateAlpha(); - mHighlightColor.a = static_cast<int>(mAlpha * 255.0F); + mHighlightColor.a = CAST_S32(mAlpha * 255.0F); graphics->setColor(mHighlightColor); const int width1 = getWidth(); diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 0ec6d64dc..d642354bc 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -468,7 +468,7 @@ void Slider::setValue(const double value) mValue = mScaleStart; else mValue = value; - mValue = static_cast<int>((mValue - mScaleStart) / mStepLength) + mValue = CAST_S32((mValue - mScaleStart) / mStepLength) * mStepLength + mScaleStart; } @@ -492,7 +492,7 @@ int Slider::valueToMarkerPosition(const double value) const else v = mDimension.height; - const int w = static_cast<int>((v - mMarkerLength) + const int w = CAST_S32((v - mMarkerLength) * (value - mScaleStart) / (mScaleEnd - mScaleStart)); diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index f01a5ba7a..4b67977dd 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -290,7 +290,7 @@ void SpellShortcutContainer::mouseReleased(MouseEvent &event) if (spell && !spell->isEmpty()) { const int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS) + if (num >= 0 && num < CAST_S32(SHORTCUT_TABS) && itemShortcut[num]) { itemShortcut[num]->setItemSelected( @@ -302,7 +302,7 @@ void SpellShortcutContainer::mouseReleased(MouseEvent &event) else { const int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS) + if (num >= 0 && num < CAST_S32(SHORTCUT_TABS) && itemShortcut[num]) { itemShortcut[num]->setItemSelected(-1); diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index e50f6aefa..aea5bf252 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -158,7 +158,7 @@ void TabbedArea::enableScrollButtons(const bool enable) int TabbedArea::getNumberOfTabs() const { - return static_cast<int>(mTabs.size()); + return CAST_S32(mTabs.size()); } Tab *TabbedArea::getTab(const std::string &name) const @@ -318,7 +318,7 @@ void TabbedArea::removeTab(Tab *const tab) { const int index = getSelectedTabIndex(); const size_t sz = mTabs.size(); - if (index == static_cast<int>(sz) - 1 && sz == 1) + if (index == CAST_S32(sz) - 1 && sz == 1) tabIndexToBeSelected = -1; else tabIndexToBeSelected = index - 1; @@ -346,7 +346,7 @@ void TabbedArea::removeTab(Tab *const tab) } } - const int tabsSize = static_cast<int>(mTabs.size()); + const int tabsSize = CAST_S32(mTabs.size()); if (tabIndexToBeSelected >= tabsSize) tabIndexToBeSelected = tabsSize - 1; if (tabIndexToBeSelected < -1) @@ -421,7 +421,7 @@ void TabbedArea::setSelectedTab(Tab *const tab) int TabbedArea::getSelectedTabIndex() const { - for (unsigned int i = 0, sz = static_cast<unsigned int>(mTabs.size()); + for (unsigned int i = 0, sz = CAST_U32(mTabs.size()); i < sz; i++) { if (mTabs[i].first == mSelectedTab) @@ -527,7 +527,7 @@ void TabbedArea::updateVisibleTabsWidth() for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i) { if (mTabs[i].first) - mVisibleTabsWidth += static_cast<int>(mTabs[i].first->getWidth()); + mVisibleTabsWidth += CAST_S32(mTabs[i].first->getWidth()); } } @@ -625,7 +625,7 @@ void TabbedArea::action(const ActionEvent& actionEvent) } else if (eventId == "shift_right") { - if (static_cast<size_t>(mTabScrollIndex) < mTabs.size() - 1) + if (CAST_SIZE(mTabScrollIndex) < mTabs.size() - 1) ++mTabScrollIndex; } adjustTabPositions(); @@ -675,14 +675,14 @@ void TabbedArea::updateArrowEnableState() Tab *TabbedArea::getTabByIndex(const int index) const { - if (index < 0 || index >= static_cast<int>(mTabs.size())) + if (index < 0 || index >= CAST_S32(mTabs.size())) return nullptr; return static_cast<Tab*>(mTabs[index].first); } Widget *TabbedArea::getWidgetByIndex(const int index) const { - if (index < 0 || index >= static_cast<int>(mTabs.size())) + if (index < 0 || index >= CAST_S32(mTabs.size())) return nullptr; return mTabs[index].second; } @@ -691,7 +691,7 @@ void TabbedArea::removeAll(const bool del) { if (getSelectedTabIndex() != -1) { - setSelectedTabByIndex(static_cast<unsigned int>(0)); + setSelectedTabByIndex(CAST_U32(0)); } while (getNumberOfTabs() > 0) { @@ -755,7 +755,7 @@ void TabbedArea::keyPressed(KeyEvent& event) int index = getSelectedTabIndex(); index++; - if (index >= static_cast<int>(mTabs.size())) + if (index >= CAST_S32(mTabs.size())) return; else setSelectedTab(mTabs[index].first); @@ -778,7 +778,7 @@ void TabbedArea::selectNextTab() { int tab = getSelectedTabIndex(); tab++; - if (tab == static_cast<int>(mTabs.size())) + if (tab == CAST_S32(mTabs.size())) tab = 0; setSelectedTab(mTabs[tab].first); } @@ -788,7 +788,7 @@ void TabbedArea::selectPrevTab() int tab = getSelectedTabIndex(); if (tab == 0) - tab = static_cast<int>(mTabs.size()); + tab = CAST_S32(mTabs.size()); if (tab < 0) return; tab--; diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp index e3af82d2a..942ade320 100644 --- a/src/gui/widgets/tabs/chat/chattab.cpp +++ b/src/gui/widgets/tabs/chat/chattab.cpp @@ -264,9 +264,9 @@ void ChatTab::chatLog(std::string line, // Format the time string properly std::stringstream timeStr; timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast<int>(((t / 60) / 60) % 24) + << CAST_S32(((t / 60) / 60) % 24) << ":" << (((t / 60) % 60 < 10) ? "0" : "") - << static_cast<int>((t / 60) % 60) + << CAST_S32((t / 60) % 60) << "] "; line = std::string(lineColor).append(timeStr.str()).append( tmp.nick).append(tmp.text); diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp index 22a07f23d..00ab33bcc 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -377,7 +377,7 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED) setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); - mGradTypeSlider->setValue(static_cast<int>(grad)); + mGradTypeSlider->setValue(CAST_S32(grad)); updateGradType(); mGradTypeSlider->setEnabled(true); } @@ -406,7 +406,7 @@ void Setup_Colors::cancel() const UserColorIdT type = static_cast<UserColorIdT>( userPalette->getColorTypeAt(mSelected)); const Color *const col = &userPalette->getColor(type); - mGradTypeSlider->setValue(static_cast<int>( + mGradTypeSlider->setValue(CAST_S32( userPalette->getGradientType(type))); const int delay = userPalette->getGradientDelay(type); setEntry(mGradDelaySlider, mGradDelayText, delay); @@ -456,23 +456,23 @@ void Setup_Colors::updateColor() const UserColorIdT type = static_cast<UserColorIdT>( userPalette->getColorTypeAt(mSelected)); const GradientTypeT grad = static_cast<GradientTypeT>( - static_cast<int>(mGradTypeSlider->getValue())); - const int delay = static_cast<int>(mGradDelaySlider->getValue()); + CAST_S32(mGradTypeSlider->getValue())); + const int delay = CAST_S32(mGradDelaySlider->getValue()); userPalette->setGradient(type, grad); userPalette->setGradientDelay(type, delay); if (grad == GradientType::STATIC) { userPalette->setColor(type, - static_cast<int>(mRedSlider->getValue()), - static_cast<int>(mGreenSlider->getValue()), - static_cast<int>(mBlueSlider->getValue())); + CAST_S32(mRedSlider->getValue()), + CAST_S32(mGreenSlider->getValue()), + CAST_S32(mBlueSlider->getValue())); } else if (grad == GradientType::PULSE) { userPalette->setTestColor(type, Color( - static_cast<int>(mRedSlider->getValue()), - static_cast<int>(mGreenSlider->getValue()), - static_cast<int>(mBlueSlider->getValue()))); + CAST_S32(mRedSlider->getValue()), + CAST_S32(mGreenSlider->getValue()), + CAST_S32(mBlueSlider->getValue()))); } } diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp index 861a2d3ee..64282ac1e 100644 --- a/src/gui/widgets/tabs/setup_joystick.cpp +++ b/src/gui/widgets/tabs/setup_joystick.cpp @@ -80,7 +80,7 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) : else { unsigned int sel = config.getIntValue("selectedJoystick"); - if (sel >= static_cast<unsigned int>(mNamesModel->size())) + if (sel >= CAST_U32(mNamesModel->size())) sel = 0; mNamesDropDown->setSelected(sel); } diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp index 87a491116..844532278 100644 --- a/src/gui/widgets/tabs/setup_relations.cpp +++ b/src/gui/widgets/tabs/setup_relations.cpp @@ -160,7 +160,7 @@ void Setup_Relations::reset() if ((*player_relations.getPlayerIgnoreStrategies())[i] == player_relations.getPlayerIgnoreStrategy()) { - selection = static_cast<int>(i); + selection = CAST_S32(i); break; } } diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp index 55f68548d..dced19225 100644 --- a/src/gui/widgets/tabs/setup_theme.cpp +++ b/src/gui/widgets/tabs/setup_theme.cpp @@ -393,9 +393,9 @@ void Setup_Theme::apply() || config.getValue("chinaFont", "fonts/wqy-microhei.ttf") != mChinaFont || config.getIntValue("fontSize") - != static_cast<int>(mFontSizeDropDown->getSelected()) + 9 + != CAST_S32(mFontSizeDropDown->getSelected()) + 9 || config.getIntValue("npcfontSize") - != static_cast<int>(mNpcFontSizeDropDown->getSelected()) + 9) + != CAST_S32(mNpcFontSizeDropDown->getSelected()) + 9) { config.setValue("font", "fonts/" + getFileName(mFont)); config.setValue("boldFont", "fonts/" + getFileName(mBoldFont)); diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp index fad7f3ba2..591093bc8 100644 --- a/src/gui/widgets/tabs/setup_video.cpp +++ b/src/gui/widgets/tabs/setup_video.cpp @@ -263,13 +263,13 @@ void Setup_Video::apply() const int sel = mOpenGLDropDown->getSelected(); RenderType mode = RENDER_SOFTWARE; - if (sel >= 0 && static_cast<unsigned int>(sel) < sizeof(indexToRender)) + if (sel >= 0 && CAST_U32(sel) < sizeof(indexToRender)) mode = indexToRender[mOpenGLDropDown->getSelected()]; // OpenGL change if (mode != mOpenGLEnabled) { - config.setValue("opengl", static_cast<int>(mode)); + config.setValue("opengl", CAST_S32(mode)); // OpenGL can currently only be changed by restarting, notify user. CREATEWIDGET(OkDialog, @@ -287,9 +287,9 @@ void Setup_Video::apply() } mFps = mFpsCheckBox->isSelected() ? - static_cast<int>(mFpsSlider->getValue()) : 0; + CAST_S32(mFpsSlider->getValue()) : 0; - mAltFps = static_cast<int>(mAltFpsSlider->getValue()); + mAltFps = CAST_S32(mAltFpsSlider->getValue()); mFpsSlider->setEnabled(mFps > 0); @@ -336,7 +336,7 @@ void Setup_Video::cancel() config.setValue("screenheight", mainGraphics->mActualHeight); config.setValue("customcursor", mCustomCursorEnabled); - config.setValue("opengl", static_cast<int>(mOpenGLEnabled)); + config.setValue("opengl", CAST_S32(mOpenGLEnabled)); config.setValue("enableresize", mEnableResize); config.setValue("noframe", mNoFrame); } @@ -443,7 +443,7 @@ void Setup_Video::action(const ActionEvent &event) } else if (id == "fpslimitcheckbox" || id == "fpslimitslider") { - int tempFps = static_cast<int>(mFpsSlider->getValue()); + int tempFps = CAST_S32(mFpsSlider->getValue()); if (id == "fpslimitcheckbox" && !mFpsSlider->isEnabled()) tempFps = 60; else @@ -458,8 +458,8 @@ void Setup_Video::action(const ActionEvent &event) } else if (id == "altfpslimitslider") { - int tempFps = static_cast<int>(mAltFpsSlider->getValue()); - tempFps = tempFps > 0 ? tempFps : static_cast<int>( + int tempFps = CAST_S32(mAltFpsSlider->getValue()); + tempFps = tempFps > 0 ? tempFps : CAST_S32( mAltFpsSlider->getScaleStart()); mAltFps = tempFps; // TRANSLATORS: video settings label @@ -486,7 +486,7 @@ void Setup_Video::action(const ActionEvent &event) { Configuration &conf = test->getConfig(); const int val = conf.getValueInt("opengl", -1); - if (val >= 0 && static_cast<unsigned int>(val) + if (val >= 0 && CAST_U32(val) < sizeof(renderToIndex) / sizeof(int)) { mOpenGLDropDown->setSelected(renderToIndex[val]); diff --git a/src/gui/widgets/tabs/socialfriendstab.h b/src/gui/widgets/tabs/socialfriendstab.h index d4543a46b..b53138e10 100644 --- a/src/gui/widgets/tabs/socialfriendstab.h +++ b/src/gui/widgets/tabs/socialfriendstab.h @@ -112,8 +112,8 @@ class SocialFriendsTab final : public SocialTab // TRANSLATORS: social window label mCounterString = strprintf(_("Friends: %u/%u"), - static_cast<uint32_t>(online), - static_cast<uint32_t>(total)); + CAST_U32(online), + CAST_U32(total)); updateCounter(); } diff --git a/src/gui/widgets/tabs/socialguildtab.h b/src/gui/widgets/tabs/socialguildtab.h index a76b3d58b..942ce9d59 100644 --- a/src/gui/widgets/tabs/socialguildtab.h +++ b/src/gui/widgets/tabs/socialguildtab.h @@ -140,8 +140,8 @@ class SocialGuildTab final : public SocialTab, { // TRANSLATORS: social window label mCounterString = strprintf(_("Members: %u/%u"), - static_cast<uint32_t>(online0), - static_cast<uint32_t>(total0)); + CAST_U32(online0), + CAST_U32(total0)); } else { @@ -164,8 +164,8 @@ class SocialGuildTab final : public SocialTab, // TRANSLATORS: social window label mCounterString = strprintf(_("Players: %u/%u"), - static_cast<uint32_t>(online), - static_cast<uint32_t>(total)); + CAST_U32(online), + CAST_U32(total)); } updateCounter(); } diff --git a/src/gui/widgets/tabs/socialguildtab2.h b/src/gui/widgets/tabs/socialguildtab2.h index 67aa2ee08..c216c6d36 100644 --- a/src/gui/widgets/tabs/socialguildtab2.h +++ b/src/gui/widgets/tabs/socialguildtab2.h @@ -95,8 +95,8 @@ class SocialGuildTab2 final : public SocialTab, // TRANSLATORS: social window label mCounterString = strprintf(_("Players: %u/%u"), - static_cast<uint32_t>(online), - static_cast<uint32_t>(total)); + CAST_U32(online), + CAST_U32(total)); updateCounter(); } }; diff --git a/src/gui/widgets/tabs/socialnavigationtab.h b/src/gui/widgets/tabs/socialnavigationtab.h index 6d9a5e9f0..e673c689b 100644 --- a/src/gui/widgets/tabs/socialnavigationtab.h +++ b/src/gui/widgets/tabs/socialnavigationtab.h @@ -159,8 +159,8 @@ class SocialNavigationTab final : public SocialTab // TRANSLATORS: social window label mCounterString = strprintf(_("Portals: %u/%u"), - static_cast<uint32_t>(online), - static_cast<uint32_t>(total)); + CAST_U32(online), + CAST_U32(total)); updateCounter(); } @@ -170,7 +170,7 @@ class SocialNavigationTab final : public SocialTab return; std::vector<Avatar*> *const avatars = mBeings->getMembers(); - if (avatars->size() <= static_cast<size_t>(num)) + if (avatars->size() <= CAST_SIZE(num)) return; const Avatar *const ava = avatars->at(num); diff --git a/src/gui/widgets/tabs/socialpartytab.h b/src/gui/widgets/tabs/socialpartytab.h index 6202e537a..153c1b3ec 100644 --- a/src/gui/widgets/tabs/socialpartytab.h +++ b/src/gui/widgets/tabs/socialpartytab.h @@ -157,8 +157,8 @@ class SocialPartyTab final : public SocialTab, // TRANSLATORS: social window label mCounterString = strprintf(_("Players: %u/%u"), - static_cast<uint32_t>(online), - static_cast<uint32_t>(total)); + CAST_U32(online), + CAST_U32(total)); updateCounter(); } diff --git a/src/gui/widgets/tabs/socialplayerstab.h b/src/gui/widgets/tabs/socialplayerstab.h index b3a234301..50d86e33c 100644 --- a/src/gui/widgets/tabs/socialplayerstab.h +++ b/src/gui/widgets/tabs/socialplayerstab.h @@ -186,7 +186,7 @@ class SocialPlayersTab final : public SocialTab } // TRANSLATORS: social window label mCounterString = strprintf(_("Visible players: %d"), - static_cast<int>(avatars->size())); + CAST_S32(avatars->size())); updateCounter(); } diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp index 035acbb70..26a4feac0 100644 --- a/src/gui/widgets/tabstrip.cpp +++ b/src/gui/widgets/tabstrip.cpp @@ -52,7 +52,7 @@ Widget *TabStrip::createWidget(const std::string &text, widget->adjustSize(); if ((!mCount && mPressFirst) || pressed) widget->setPressed(true); - widget->setTag(static_cast<int>(mWidgets.size())); + widget->setTag(CAST_S32(mWidgets.size())); return widget; } diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index b49562673..8478e767e 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -241,9 +241,9 @@ void TextBox::setText(const std::string& text) pos = text.find("\n", lastPos); if (pos != std::string::npos) - length = static_cast<int>(pos - lastPos); + length = CAST_S32(pos - lastPos); else - length = static_cast<int>(text.size() - lastPos); + length = CAST_S32(text.size() - lastPos); std::string sub = text.substr(lastPos, length); mTextRows.push_back(sub); lastPos = pos + 1; @@ -273,7 +273,7 @@ void TextBox::keyPressed(KeyEvent& event) } else { - mCaretColumn = static_cast<int>( + mCaretColumn = CAST_S32( mTextRows[mCaretRow].size()); } } @@ -283,18 +283,18 @@ void TextBox::keyPressed(KeyEvent& event) case InputAction::GUI_RIGHT: { ++mCaretColumn; - if (mCaretColumn > static_cast<int>(mTextRows[mCaretRow].size())) + if (mCaretColumn > CAST_S32(mTextRows[mCaretRow].size())) { ++ mCaretRow; - const int sz = static_cast<int>(mTextRows.size()); + const int sz = CAST_S32(mTextRows.size()); if (mCaretRow >= sz) { mCaretRow = sz - 1; if (mCaretRow < 0) mCaretRow = 0; - mCaretColumn = static_cast<int>( + mCaretColumn = CAST_S32( mTextRows[mCaretRow].size()); } else @@ -322,7 +322,7 @@ void TextBox::keyPressed(KeyEvent& event) } case InputAction::GUI_END: { - mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size()); + mCaretColumn = CAST_S32(mTextRows[mCaretRow].size()); break; } @@ -349,7 +349,7 @@ void TextBox::keyPressed(KeyEvent& event) } else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable) { - mCaretColumn = static_cast<int>( + mCaretColumn = CAST_S32( mTextRows[mCaretRow - 1].size()); mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; mTextRows.erase(mTextRows.begin() + mCaretRow); @@ -360,14 +360,14 @@ void TextBox::keyPressed(KeyEvent& event) case InputAction::GUI_DELETE: { - if (mCaretColumn < static_cast<int>( + if (mCaretColumn < CAST_S32( mTextRows[mCaretRow].size()) && mEditable) { mTextRows[mCaretRow].erase(mCaretColumn, 1); } - else if (mCaretColumn == static_cast<int>( + else if (mCaretColumn == CAST_S32( mTextRows[mCaretRow].size()) && - mCaretRow < (static_cast<int>(mTextRows.size()) - 1) && + mCaretRow < (CAST_S32(mTextRows.size()) - 1) && mEditable) { mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; @@ -402,7 +402,7 @@ void TextBox::keyPressed(KeyEvent& event) / getFont()->getHeight(); mCaretRow += rowsPerPage; - const int sz = static_cast<int>(mTextRows.size()); + const int sz = CAST_S32(mTextRows.size()); if (mCaretRow >= sz) mCaretRow = sz - 1; } @@ -424,7 +424,7 @@ void TextBox::keyPressed(KeyEvent& event) if (key.isCharacter() && mEditable) { mTextRows[mCaretRow].insert(mCaretColumn, - std::string(1, static_cast<signed char>(key.getValue()))); + std::string(1, CAST_S8(key.getValue()))); ++ mCaretColumn; } break; @@ -463,7 +463,7 @@ void TextBox::draw(Graphics* graphics) mForegroundColor, mForegroundColor2, mTextRows[i], 1, - static_cast<int>(i * static_cast<size_t>(fontHeight))); + CAST_S32(i * CAST_SIZE(fontHeight))); } BLOCK_END("TextBox::draw") } @@ -494,7 +494,7 @@ std::string TextBox::getText() const int i; std::string text; - const int sz = static_cast<int>(mTextRows.size()); + const int sz = CAST_S32(mTextRows.size()); for (i = 0; i < sz - 1; ++ i) text.append(mTextRows[i]).append("\n"); text.append(mTextRows[i]); @@ -514,7 +514,7 @@ void TextBox::setTextRow(const int row, const std::string& text) void TextBox::setCaretPosition(unsigned int position) { - for (int row = 0, sz = static_cast<int>(mTextRows.size()); + for (int row = 0, sz = CAST_S32(mTextRows.size()); row < sz; row ++) { if (position <= mTextRows[row].size()) @@ -530,15 +530,15 @@ void TextBox::setCaretPosition(unsigned int position) } // position beyond end of text - mCaretRow = static_cast<int>(mTextRows.size() - 1); - mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size()); + mCaretRow = CAST_S32(mTextRows.size() - 1); + mCaretColumn = CAST_S32(mTextRows[mCaretRow].size()); } void TextBox::setCaretRow(const int row) { mCaretRow = row; - const int sz = static_cast<int>(mTextRows.size()); + const int sz = CAST_S32(mTextRows.size()); if (mCaretRow >= sz) mCaretRow = sz - 1; @@ -553,7 +553,7 @@ unsigned int TextBox::getCaretPosition() const int pos = 0, row; for (row = 0; row < mCaretRow; row++) - pos += static_cast<int>(mTextRows[row].size()); + pos += CAST_S32(mTextRows[row].size()); return pos + mCaretColumn; } @@ -562,7 +562,7 @@ void TextBox::setCaretColumn(const int column) { mCaretColumn = column; - const int sz = static_cast<int>(mTextRows[mCaretRow].size()); + const int sz = CAST_S32(mTextRows[mCaretRow].size()); if (mCaretColumn > sz) mCaretColumn = sz; @@ -605,7 +605,7 @@ void TextBox::mousePressed(MouseEvent& event) event.consume(); mCaretRow = event.getY() / height; - const int sz = static_cast<int>(mTextRows.size()); + const int sz = CAST_S32(mTextRows.size()); if (mCaretRow >= sz) mCaretRow = sz - 1; @@ -637,5 +637,5 @@ void TextBox::adjustSize() } setWidth(width + 1); - setHeight(font->getHeight() * static_cast<int>(mTextRows.size())); + setHeight(font->getHeight() * CAST_S32(mTextRows.size())); } diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h index 5bfec42a1..bdeca3c5d 100644 --- a/src/gui/widgets/textbox.h +++ b/src/gui/widgets/textbox.h @@ -157,7 +157,7 @@ class TextBox final : public Widget, * @return The number of rows in the text. */ unsigned int getNumberOfRows() const - { return static_cast<int>(mTextRows.size()); } + { return CAST_S32(mTextRows.size()); } /** * Gets the caret position in the text. diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index b9f90c949..291a5fa22 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -298,7 +298,7 @@ void TextField::keyPressed(KeyEvent &event) std::string str = event.getText(); mText.insert(mCaretPosition, str); mTextChanged = true; - mCaretPosition += static_cast<unsigned int>(str.size()); + mCaretPosition += CAST_U32(str.size()); event.consume(); fixScroll(); if (mSendAlwaysEvents) @@ -314,7 +314,7 @@ void TextField::keyPressed(KeyEvent &event) if ((val >= '0' && val <= '9') || (val == '-' && !mCaretPosition)) { char buf[2]; - buf[0] = static_cast<char>(val); + buf[0] = CAST_8(val); buf[1] = 0; mText.insert(mCaretPosition, std::string(buf)); mTextChanged = true; @@ -327,7 +327,7 @@ void TextField::keyPressed(KeyEvent &event) } } else if (!mMaximum || - static_cast<int>(mText.size()) < mMaximum) + CAST_S32(mText.size()) < mMaximum) { int len; if (val < 128) @@ -342,13 +342,13 @@ void TextField::keyPressed(KeyEvent &event) char buf[4]; for (int i = 0; i < len; ++ i) { - buf[i] = static_cast<char>(val >> (6 * (len - i - 1))); + buf[i] = CAST_8(val >> (6 * (len - i - 1))); if (i > 0) - buf[i] = static_cast<char>((buf[i] & 63) | 128); + buf[i] = CAST_8((buf[i] & 63) | 128); } if (len > 1) - buf[0] |= static_cast<char>(255U << (8 - len)); + buf[0] |= CAST_8(255U << (8 - len)); mText.insert(mCaretPosition, std::string(buf, buf + len)); mCaretPosition += len; @@ -413,7 +413,7 @@ bool TextField::handleNormalKeys(const InputActionT action, bool &consumed) case InputAction::GUI_RIGHT: { consumed = true; - const unsigned sz = static_cast<unsigned>(mText.size()); + const unsigned sz = CAST_U32(mText.size()); while (mCaretPosition < sz) { ++mCaretPosition; @@ -429,7 +429,7 @@ bool TextField::handleNormalKeys(const InputActionT action, bool &consumed) case InputAction::GUI_DELETE: { consumed = true; - unsigned sz = static_cast<unsigned>(mText.size()); + unsigned sz = CAST_U32(mText.size()); while (mCaretPosition < sz) { --sz; @@ -462,7 +462,7 @@ bool TextField::handleNormalKeys(const InputActionT action, bool &consumed) break; case InputAction::GUI_END: - mCaretPosition = static_cast<unsigned>(mText.size()); + mCaretPosition = CAST_U32(mText.size()); consumed = true; break; @@ -517,7 +517,7 @@ void TextField::handleCtrlKeys(const InputActionT action, bool &consumed) } case InputAction::GUI_E: { - mCaretPosition = static_cast<int>(mText.size()); + mCaretPosition = CAST_S32(mText.size()); consumed = true; break; } @@ -584,7 +584,7 @@ void TextField::moveCaretBack() void TextField::moveCaretForward() { - const unsigned sz = static_cast<unsigned>(mText.size()); + const unsigned sz = CAST_U32(mText.size()); while (mCaretPosition < sz) { ++mCaretPosition; @@ -595,7 +595,7 @@ void TextField::moveCaretForward() void TextField::caretDelete() { - unsigned sz = static_cast<unsigned>(mText.size()); + unsigned sz = CAST_U32(mText.size()); while (mCaretPosition < sz) { --sz; @@ -609,12 +609,12 @@ void TextField::caretDelete() void TextField::handlePaste() { std::string text = getText(); - size_t caretPos = static_cast<size_t>(getCaretPosition()); + size_t caretPos = CAST_SIZE(getCaretPosition()); if (retrieveBuffer(text, caretPos)) { setText(text); - setCaretPosition(static_cast<unsigned int>(caretPos)); + setCaretPosition(CAST_U32(caretPos)); } } @@ -649,7 +649,7 @@ void TextField::moveCaretWordBack() void TextField::moveCaretWordForward() { - const unsigned sz = static_cast<unsigned>(mText.size()); + const unsigned sz = CAST_U32(mText.size()); const unsigned int oldCaret = mCaretPosition; while (mCaretPosition < sz) { @@ -731,9 +731,9 @@ void TextField::fixScroll() void TextField::setCaretPosition(unsigned int position) { - const unsigned int sz = static_cast<unsigned int>(mText.size()); + const unsigned int sz = CAST_U32(mText.size()); if (position > sz) - mCaretPosition = static_cast<int>(sz); + mCaretPosition = CAST_S32(sz); else mCaretPosition = position; @@ -781,7 +781,7 @@ void TextField::focusLost(const Event &event A_UNUSED) void TextField::setText(const std::string& text) { - const unsigned int sz = static_cast<unsigned int>(text.size()); + const unsigned int sz = CAST_U32(text.size()); if (sz < mCaretPosition) mCaretPosition = sz; mText = text; diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index a0b504065..6e61a16a5 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -88,15 +88,15 @@ void TextPreview::draw(Graphics* graphics) if (settings.guiAlpha != mAlpha) mAlpha = settings.guiAlpha; - const int intAlpha = static_cast<int>(mAlpha * 255.0F); + const int intAlpha = CAST_S32(mAlpha * 255.0F); const int alpha = mTextAlpha ? intAlpha : 255; if (mOpaque) { - graphics->setColor(Color(static_cast<int>(mBGColor->r), - static_cast<int>(mBGColor->g), - static_cast<int>(mBGColor->b), - static_cast<int>(mAlpha * 255.0F))); + graphics->setColor(Color(CAST_S32(mBGColor->r), + CAST_S32(mBGColor->g), + CAST_S32(mBGColor->b), + CAST_S32(mAlpha * 255.0F))); graphics->fillRectangle(Rect(0, 0, mDimension.width, mDimension.height)); } @@ -107,9 +107,9 @@ void TextPreview::draw(Graphics* graphics) + 2 * ((mOutline || mShadow) ? 1 :0); const int y = mFont->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); - graphics->setColor(Color(static_cast<int>(mTextBGColor->r), - static_cast<int>(mTextBGColor->g), - static_cast<int>(mTextBGColor->b), + graphics->setColor(Color(CAST_S32(mTextBGColor->r), + CAST_S32(mTextBGColor->g), + CAST_S32(mTextBGColor->b), intAlpha)); graphics->fillRectangle(Rect(mPadding, mPadding, x, y)); } diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h index 8e56a2477..bbf9beff6 100644 --- a/src/gui/widgets/widget2.h +++ b/src/gui/widgets/widget2.h @@ -62,7 +62,7 @@ class Widget2 notfinal void setPalette(int palette) { - mPaletteOffset = palette * static_cast<int>( + mPaletteOffset = palette * CAST_S32( ThemeColorId::THEME_COLORS_END); checkPalette(); setWidget2(this); @@ -71,7 +71,7 @@ class Widget2 notfinal void checkPalette() { if (mPaletteOffset < 0 || - mPaletteOffset >= THEME_PALETTES * static_cast<int>( + mPaletteOffset >= THEME_PALETTES * CAST_S32( ThemeColorId::THEME_COLORS_END)) { mPaletteOffset = 0; diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 02a13a249..450c2e025 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -202,7 +202,7 @@ Window::Window(const std::string &caption, { mCaptionAlign = Graphics::LEFT; } - setTitleBarHeight(static_cast<unsigned int>( + setTitleBarHeight(CAST_U32( getOption("titlebarHeight"))); if (!mTitleBarHeight) mTitleBarHeight = mCaptionFont->getHeight() + mPadding; @@ -821,7 +821,7 @@ void Window::mousePressed(MouseEvent &event) mDragOffsetX = event.getX(); mDragOffsetY = event.getY(); - mMoved = event.getY() <= static_cast<int>(mTitleBarHeight); + mMoved = event.getY() <= CAST_S32(mTitleBarHeight); } const MouseButtonT button = event.getButton(); @@ -1290,8 +1290,8 @@ int Window::getResizeHandles(const MouseEvent &event) { if (mGrip && (y > mTitleBarHeight || - (static_cast<int>(y) < mPadding && - static_cast<int>(mTitleBarHeight) > mPadding))) + (CAST_S32(y) < mPadding && + CAST_S32(mTitleBarHeight) > mPadding))) { if (!getWindowArea().isPointInRect(x, y) && event.getSource() == this) @@ -1301,8 +1301,8 @@ int Window::getResizeHandles(const MouseEvent &event) resizeHandles |= (y > mDimension.height - resizeBorderWidth) ? BOTTOM : (y < resizeBorderWidth) ? TOP : 0; } - if (x >= static_cast<unsigned>(mGripRect.x) - && y >= static_cast<unsigned>(mGripRect.y)) + if (x >= CAST_U32(mGripRect.x) + && y >= CAST_U32(mGripRect.y)) { mDragOffsetX = x; mDragOffsetY = y; @@ -1319,7 +1319,7 @@ bool Window::isResizeAllowed(const MouseEvent &event) const const int y = event.getY(); if (mGrip && - (y > static_cast<int>(mTitleBarHeight) || + (y > CAST_S32(mTitleBarHeight) || y < mPadding)) { const int x = event.getX(); diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 9d9f9a213..6633fcb90 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -256,7 +256,7 @@ void WindowMenu::addButton(const char *const text, Button *const btn = new Button(this, gettext(text), text, this); btn->setPosition(x, mPadding); btn->setDescription(description); - btn->setTag(static_cast<int>(key)); + btn->setTag(CAST_S32(key)); add(btn); btn->setFocusable(false); x += btn->getWidth() + mSpacing; diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index 644e8c5ce..82f49421b 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -482,7 +482,7 @@ void BuyDialog::action(const ActionEvent &event) if (eventId == "slider") { - mAmountItems = static_cast<int>(mSlider->getValue()); + mAmountItems = CAST_S32(mSlider->getValue()); mAmountField->setValue(mAmountItems); updateButtonsAndLabels(); } diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp index 6e8120373..0f693aa45 100644 --- a/src/gui/windows/charcreatedialog.cpp +++ b/src/gui/windows/charcreatedialog.cpp @@ -163,7 +163,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent, if (maxHairStyle) { - mHairStyle = (static_cast<unsigned int>(rand()) + mHairStyle = (CAST_U32(rand()) % maxHairStyle) + minHairStyle; } else @@ -172,7 +172,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent, } if (maxHairColor) { - mHairColor = (static_cast<unsigned int>(rand()) + mHairColor = (CAST_U32(rand()) % maxHairColor) + minHairColor; } else @@ -440,7 +440,7 @@ void CharCreateDialog::action(const ActionEvent &event) std::vector<int> atts; for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++) { - atts.push_back(static_cast<int>( + atts.push_back(CAST_S32( mAttributeSlider[i]->getValue())); } @@ -451,8 +451,8 @@ void CharCreateDialog::action(const ActionEvent &event) mGender, mHairStyle, mHairColor, - static_cast<unsigned char>(mRace), - static_cast<unsigned char>(mLook), + CAST_U8(mRace), + CAST_U8(mLook), atts); } else @@ -568,7 +568,7 @@ void CharCreateDialog::updateSliders() { // Update captions mAttributeValue[i]->setCaption( - toString(static_cast<int>(mAttributeSlider[i]->getValue()))); + toString(CAST_S32(mAttributeSlider[i]->getValue()))); mAttributeValue[i]->adjustSize(); } @@ -610,7 +610,7 @@ int CharCreateDialog::getDistributedPoints() const int points = 0; for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++) - points += static_cast<int>(mAttributeSlider[i]->getValue()); + points += CAST_S32(mAttributeSlider[i]->getValue()); return points; } @@ -642,7 +642,7 @@ void CharCreateDialog::setAttributes(const StringVect &labels, if (serverFeatures->haveRaceSelection() && mMinRace < mMaxRace) y += 29; - for (unsigned i = 0, sz = static_cast<unsigned>(labels.size()); + for (unsigned i = 0, sz = CAST_U32(labels.size()); i < sz; i++) { mAttributeLabel[i] = new Label(this, labels[i]); @@ -704,8 +704,8 @@ void CharCreateDialog::updateHair() mHairStyle = Being::getNumOfHairstyles() - 1; else mHairStyle %= Being::getNumOfHairstyles(); - if (mHairStyle < static_cast<signed>(minHairStyle) - || mHairStyle > static_cast<signed>(maxHairStyle)) + if (mHairStyle < CAST_S32(minHairStyle) + || mHairStyle > CAST_S32(maxHairStyle)) { mHairStyle = minHairStyle; } @@ -722,8 +722,8 @@ void CharCreateDialog::updateHair() mHairColor = 0; if (mHairColor < 0) mHairColor += ColorDB::getHairSize(); - if (mHairColor < static_cast<signed>(minHairColor) - || mHairColor > static_cast<signed>(maxHairColor)) + if (mHairColor < CAST_S32(minHairColor) + || mHairColor > CAST_S32(maxHairColor)) { mHairColor = minHairColor; } @@ -767,7 +767,7 @@ void CharCreateDialog::updateLook() mLook = 0; } mPlayer->setSubtype(fromInt(mRace, BeingTypeId), - static_cast<uint8_t>(mLook)); + CAST_U8(mLook)); if (mRaceNameLabel) { mRaceNameLabel->setCaption(item.getName()); diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp index ac5f3b291..57cc7ceb5 100644 --- a/src/gui/windows/charselectdialog.cpp +++ b/src/gui/windows/charselectdialog.cpp @@ -113,7 +113,7 @@ CharSelectDialog::CharSelectDialog(LoginData &data) : placer(n, 0, mInfoButton); n ++; - for (int i = 0; i < static_cast<int>(mLoginData->characterSlots); i++) + for (int i = 0; i < CAST_S32(mLoginData->characterSlots); i++) { CharacterDisplay *const character = new CharacterDisplay(this, this); character->setVisible(Visible_false); @@ -183,7 +183,7 @@ void CharSelectDialog::action(const ActionEvent &event) // Check if a button of a character was pressed const Widget *const sourceParent = event.getSource()->getParent(); int selected = -1; - for (unsigned int i = 0, sz = static_cast<unsigned int>( + for (unsigned int i = 0, sz = CAST_U32( mCharacterEntries.size()); i < sz; ++i) { if (mCharacterEntries[i] == sourceParent) @@ -241,17 +241,17 @@ 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"), - static_cast<uint32_t>( + CAST_U32( character->data.mAttributes[Attributes::HP]), - static_cast<uint32_t>( + CAST_U32( character->data.mAttributes[Attributes::MAX_HP]), - static_cast<uint32_t>( + CAST_U32( character->data.mAttributes[Attributes::MP]), - static_cast<uint32_t>( + CAST_U32( character->data.mAttributes[Attributes::MAX_MP]), - static_cast<uint32_t>( + CAST_U32( character->data.mAttributes[Attributes::LEVEL]), - static_cast<uint32_t>( + CAST_U32( character->data.mAttributes[Attributes::EXP]), Units::formatCurrency( character->data.mAttributes[Attributes::MONEY]).c_str()); @@ -506,7 +506,7 @@ void CharSelectDialog::setCharacter(Net::Character *const character) if (!character) return; const int characterSlot = character->slot; - if (characterSlot >= static_cast<int>(mCharacterEntries.size())) + if (characterSlot >= CAST_S32(mCharacterEntries.size())) { logger->log("Warning: slot out of range: %d", character->slot); return; @@ -562,10 +562,10 @@ bool CharSelectDialog::selectByName(const std::string &name, { if (character->dummy && character->dummy->getName() == name) { - mCharacterView->show(static_cast<int>(i)); + mCharacterView->show(CAST_S32(i)); updateState(); if (selAction == Choose) - attemptCharacterSelect(static_cast<int>(i)); + attemptCharacterSelect(CAST_S32(i)); return true; } } @@ -616,7 +616,7 @@ void CharSelectDialog::updateState() void CharSelectDialog::setName(const BeingId id, const std::string &newName) { - for (unsigned int i = 0, sz = static_cast<unsigned int>( + for (unsigned int i = 0, sz = CAST_U32( mCharacterEntries.size()); i < sz; ++i) { if (!mCharacterEntries[i]) diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 8f74a6877..e15f68f35 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -403,7 +403,7 @@ void ChatWindow::closeTab() const void ChatWindow::defaultTab() { if (mChatTabs) - mChatTabs->setSelectedTabByIndex(static_cast<unsigned>(0)); + mChatTabs->setSelectedTabByIndex(CAST_U32(0)); } void ChatWindow::action(const ActionEvent &event) @@ -773,7 +773,7 @@ void ChatWindow::keyPressed(KeyEvent &event) if (mCurHist != mHistory.end()) { mChatInput->setText(*mCurHist); - mChatInput->setCaretPosition(static_cast<unsigned>( + mChatInput->setCaretPosition(CAST_U32( mChatInput->getText().length())); } else @@ -797,7 +797,7 @@ void ChatWindow::keyPressed(KeyEvent &event) --mCurHist; addCurrentToHistory(); mChatInput->setText(*mCurHist); - mChatInput->setCaretPosition(static_cast<unsigned>( + mChatInput->setCaretPosition(CAST_U32( mChatInput->getText().length())); } else if (actionId == InputAction::GUI_INSERT && @@ -828,7 +828,7 @@ void ChatWindow::keyPressed(KeyEvent &event) { if (!mChatHistoryIndex) { - mChatHistoryIndex = static_cast<unsigned>( + mChatHistoryIndex = CAST_U32( tab->getRows().size()); mChatInput->setText(""); @@ -848,7 +848,7 @@ void ChatWindow::keyPressed(KeyEvent &event) if (f == mChatHistoryIndex) mChatInput->setText(*it); } - mChatInput->setCaretPosition(static_cast<unsigned>( + mChatInput->setCaretPosition(CAST_U32( mChatInput->getText().length())); } } @@ -860,11 +860,11 @@ void ChatWindow::keyPressed(KeyEvent &event) { const std::list<std::string> &rows = tab->getRows(); const size_t &tabSize = rows.size(); - if (static_cast<size_t>(mChatHistoryIndex) + 1 < tabSize) + if (CAST_SIZE(mChatHistoryIndex) + 1 < tabSize) { mChatHistoryIndex ++; } - else if (static_cast<size_t>(mChatHistoryIndex) < tabSize) + else if (CAST_SIZE(mChatHistoryIndex) < tabSize) { mChatHistoryIndex ++; mChatInput->setText(""); @@ -884,7 +884,7 @@ void ChatWindow::keyPressed(KeyEvent &event) if (f == mChatHistoryIndex) mChatInput->setText(*it); } - mChatInput->setCaretPosition(static_cast<unsigned>( + mChatInput->setCaretPosition(CAST_U32( mChatInput->getText().length())); } } @@ -1014,8 +1014,8 @@ void ChatWindow::addInputText(const std::string &text, const bool space) ss << inputText.substr(caretPos); mChatInput->setText(ss.str()); - mChatInput->setCaretPosition(caretPos + static_cast<int>( - text.length()) + static_cast<int>(space)); + mChatInput->setCaretPosition(caretPos + CAST_S32( + text.length()) + CAST_S32(space)); requestChatFocus(); } @@ -1298,7 +1298,7 @@ void ChatWindow::postConnection() skip --; \ continue; \ } \ - const unsigned char ch = static_cast<unsigned char>(msg.at(f)); \ + const unsigned char ch = CAST_U8(msg.at(f)); \ if (f + 2 < sz && msg.substr(f, 2) == "%%") \ { \ newMsg += msg.at(f); \ @@ -1419,8 +1419,8 @@ void ChatWindow::autoComplete() .append(inputText.substr(caretPos, inputText.length() - caretPos))); - const int len = caretPos - static_cast<int>(name.length()) - + static_cast<int>(newName.length()); + const int len = caretPos - CAST_S32(name.length()) + + CAST_S32(newName.length()); if (startName > 0) mChatInput->setCaretPosition(len + 1); @@ -1592,7 +1592,7 @@ bool ChatWindow::resortChatLog(std::string line, { const std::string nick = line.substr(0, idx2 - 1); line = line.substr(idx2 + 6); - localPetEmote(nick, static_cast<uint8_t>( + localPetEmote(nick, CAST_U8( atoi(line.c_str()))); } else if (line.find(": \302\202\302m") != std::string::npos) @@ -1608,7 +1608,7 @@ bool ChatWindow::resortChatLog(std::string line, { const std::string nick = line.substr(0, idx2 - 1); line = line.substr(idx2 + 6); - localPetDirection(nick, static_cast<uint8_t>( + localPetDirection(nick, CAST_U8( atoi(line.c_str()))); } else if (line.find(": \302\202\302a") != std::string::npos) @@ -1946,9 +1946,9 @@ bool ChatWindow::saveTab(const int num, ChatTab *const tab) const tab->getChannelName()); serverConfig.setValue("chatWhisperFlags" + toString(num), - static_cast<int>(tab->getAllowHighlight()) - + (2 * static_cast<int>(tab->getRemoveNames())) - + (4 * static_cast<int>(tab->getNoAway()))); + CAST_S32(tab->getAllowHighlight()) + + (2 * CAST_S32(tab->getRemoveNames())) + + (4 * CAST_S32(tab->getNoAway()))); return true; } diff --git a/src/gui/windows/editserverdialog.cpp b/src/gui/windows/editserverdialog.cpp index e456533cb..d45d46be3 100644 --- a/src/gui/windows/editserverdialog.cpp +++ b/src/gui/windows/editserverdialog.cpp @@ -230,7 +230,7 @@ void EditServerDialog::action(const ActionEvent &event) mServer.description = mDescriptionField->getText(); mServer.onlineListUrl = mOnlineListUrlField->getText(); mServer.hostname = mServerAddressField->getText(); - mServer.port = static_cast<int16_t>(atoi( + mServer.port = CAST_S16(atoi( mPortField->getText().c_str())); mServer.persistentIp = mPersistentIp->isSelected(); diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp index fe2ab432b..7acbad13d 100644 --- a/src/gui/windows/emotewindow.cpp +++ b/src/gui/windows/emotewindow.cpp @@ -158,7 +158,7 @@ std::string EmoteWindow::getSelectedEmote() const return std::string(); char chr[2]; - chr[0] = static_cast<char>('0' + index); + chr[0] = CAST_8('0' + index); chr[1] = 0; return std::string("%%").append(&chr[0]); } @@ -178,7 +178,7 @@ std::string EmoteWindow::getSelectedColor() const return std::string(); char chr[2]; - chr[0] = static_cast<char>('0' + index); + chr[0] = CAST_8('0' + index); chr[1] = 0; return std::string("##").append(&chr[0]); } diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index a32f80c3e..ddde610eb 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -713,7 +713,7 @@ void EquipmentWindow::loadSlot(const XmlNodePtr slotNode, const int imageIndex = XML::getProperty(slotNode, "image", -1); Image *image = nullptr; - if (imageIndex >= 0 && imageIndex < static_cast<signed>(imageset->size())) + if (imageIndex >= 0 && imageIndex < CAST_S32(imageset->size())) image = imageset->get(imageIndex); std::vector<EquipmentBox*> &boxes = mPages[page]->boxes; @@ -786,7 +786,7 @@ void EquipmentWindow::addBox(const int idx, int x, int y, const int imageIndex) Image *image = nullptr; if (mImageSet && imageIndex >= 0 && imageIndex - < static_cast<signed>(mImageSet->size())) + < CAST_S32(mImageSet->size())) { image = mImageSet->get(imageIndex); } @@ -826,5 +826,5 @@ int EquipmentWindow::addPage(const std::string &name) boxes.push_back(nullptr); mTabs->addButton(name, name, false); - return static_cast<int>(mPages.size()) - 1; + return CAST_S32(mPages.size()) - 1; } diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp index cefeaca7b..8ad79ecab 100644 --- a/src/gui/windows/itemamountwindow.cpp +++ b/src/gui/windows/itemamountwindow.cpp @@ -413,7 +413,7 @@ void ItemAmountWindow::action(const ActionEvent &event) else if (eventId == "all") amount = mMax; else if (eventId == "slide") - amount = static_cast<int>(mItemAmountSlide->getValue()); + amount = CAST_S32(mItemAmountSlide->getValue()); mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); @@ -429,22 +429,22 @@ void ItemAmountWindow::action(const ActionEvent &event) if (eventId == "incPrice") { mPrice++; - price = static_cast<int>(pow(10.0, mPrice)); + price = CAST_S32(pow(10.0, mPrice)); mItemPriceTextField->setValue(price); mItemPriceSlide->setValue(price); } else if (eventId == "decPrice") { mPrice--; - price = static_cast<int>(pow(10.0, mPrice)); + price = CAST_S32(pow(10.0, mPrice)); mItemPriceTextField->setValue(price); mItemPriceSlide->setValue(price); } else if (eventId == "slidePrice") { - price = static_cast<int>(mItemPriceSlide->getValue()); + price = CAST_S32(mItemPriceSlide->getValue()); if (price) - mPrice = static_cast<int>(log(static_cast<float>(price))); + mPrice = CAST_S32(log(static_cast<float>(price))); else mPrice = 0; mItemPriceTextField->setValue(price); diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp index 3a0fd56ef..c39486dda 100644 --- a/src/gui/windows/logindialog.cpp +++ b/src/gui/windows/logindialog.cpp @@ -130,7 +130,7 @@ LoginDialog::LoginDialog(LoginData &data, mUpdateTypeDropDown->setActionEventId("updatetype"); mUpdateTypeDropDown->setSelected((mLoginData->updateType - | UpdateType::Custom) ^ static_cast<int>(UpdateType::Custom)); + | UpdateType::Custom) ^ CAST_S32(UpdateType::Custom)); if (!mCustomUpdateHost->isSelected()) mUpdateHostText->setVisible(Visible_false); @@ -339,7 +339,7 @@ void LoginDialog::prepareUpdate() } mLoginData->updateType = updateType; - serverConfig.setValue("updateType", static_cast<int>(updateType)); + serverConfig.setValue("updateType", CAST_S32(updateType)); mRegisterButton->setEnabled(false); mServerButton->setEnabled(false); diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp index 2d52a2e99..071a1ecee 100644 --- a/src/gui/windows/mailwindow.cpp +++ b/src/gui/windows/mailwindow.cpp @@ -252,7 +252,7 @@ void MailWindow::viewPrev(const int id) if (it == mMessages.begin()) { it = mMessages.end(); - mListBox->setSelected(static_cast<int>(mMessages.size()) - 1); + mListBox->setSelected(CAST_S32(mMessages.size()) - 1); } else { diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index ae93c9190..797427c50 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -375,9 +375,9 @@ void Minimap::draw2(Graphics *const graphics) if (userPalette) graphics->setColor(userPalette->getColor(type)); - const int offsetHeight = static_cast<int>(static_cast<float>( + const int offsetHeight = CAST_S32(static_cast<float>( dotSize - 1) * mHeightProportion); - const int offsetWidth = static_cast<int>(static_cast<float>( + const int offsetWidth = CAST_S32(static_cast<float>( dotSize - 1) * mWidthProportion); const Vector &pos = being->getPosition(); @@ -414,15 +414,15 @@ void Minimap::draw2(Graphics *const graphics) UserColorId::PARTY)); } - const int offsetHeight = static_cast<int>( + const int offsetHeight = CAST_S32( mHeightProportion); - const int offsetWidth = static_cast<int>( + const int offsetWidth = CAST_S32( mWidthProportion); graphics->fillRectangle(Rect( - static_cast<int>(member->getX() + CAST_S32(member->getX() * mWidthProportion) + mMapOriginX - offsetWidth, - static_cast<int>(member->getY() + CAST_S32(member->getY() * mHeightProportion) + mMapOriginY - offsetHeight, 2, 2)); } @@ -443,9 +443,9 @@ void Minimap::draw2(Graphics *const graphics) + viewport->getCameraRelativeY()) * mHeightProportion) / 32 + mMapOriginY; - const int w = static_cast<int>(static_cast<float>( + const int w = CAST_S32(static_cast<float>( gw) * mWidthProportion / 32); - const int h = static_cast<int>(static_cast<float>( + const int h = CAST_S32(static_cast<float>( gh) * mHeightProportion / 32); if (w <= a.width) diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index 3ca9b8e35..1e43ce3b5 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -226,7 +226,7 @@ void MiniStatusWindow::updateBars() void MiniStatusWindow::setIcon(const int index, AnimatedSprite *const sprite) { - if (index >= static_cast<int>(mIcons.size())) + if (index >= CAST_S32(mIcons.size())) mIcons.resize(index + 1, nullptr); delete mIcons[index]; @@ -235,7 +235,7 @@ void MiniStatusWindow::setIcon(const int index, AnimatedSprite *const sprite) void MiniStatusWindow::eraseIcon(const int index) { - if (index < static_cast<int>(mIcons.size())) + if (index < CAST_S32(mIcons.size())) { delete mIcons[index]; mIcons.erase(mIcons.begin() + index); diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index dc991097b..27386af5b 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -348,14 +348,14 @@ void NpcDialog::action(const ActionEvent &event) gui->resetClickCount(); const int selectedIndex = mItemList->getSelected(); - if (selectedIndex >= static_cast<int>(mItems.size()) + if (selectedIndex >= CAST_S32(mItems.size()) || selectedIndex < 0 || !PacketLimiter::limitPackets( PacketType::PACKET_NPC_INPUT)) { return; } - unsigned char choice = static_cast<unsigned char>( + unsigned char choice = CAST_U8( selectedIndex + 1); printText = mItems[selectedIndex]; @@ -678,7 +678,7 @@ void NpcDialog::closeDialog() int NpcDialog::getNumberOfElements() { - return static_cast<int>(mItems.size()); + return CAST_S32(mItems.size()); } std::string NpcDialog::getElementAt(int i) @@ -1118,7 +1118,7 @@ void NpcDialog::saveCamera() if (!viewport || mCameraMode >= 0) return; - mCameraMode = static_cast<int>(settings.cameraMode); + mCameraMode = CAST_S32(settings.cameraMode); mCameraX = viewport->getCameraRelativeX(); mCameraY = viewport->getCameraRelativeY(); } @@ -1128,7 +1128,7 @@ void NpcDialog::restoreCamera() if (!viewport || mCameraMode == -1) return; - if (static_cast<int>(settings.cameraMode) != mCameraMode) + if (CAST_S32(settings.cameraMode) != mCameraMode) viewport->toggleCameraMode(); if (mCameraMode) { @@ -1206,7 +1206,7 @@ void NpcDialog::logic() if (mShowAvatar && mAvatarBeing) { mAvatarBeing->logic(); - if (mPlayerBox->getWidth() < static_cast<signed>(3 * getPadding())) + if (mPlayerBox->getWidth() < CAST_S32(3 * getPadding())) { const Sprite *const sprite = mAvatarBeing->getSprite(0); if (sprite) diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index 73cc5101d..83874f4c3 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -169,7 +169,7 @@ void OutfitWindow::load(const bool oldConfig) std::vector<unsigned char> tokens2; while (ss2 >> buf) - tokens2.push_back(static_cast<unsigned char>(atoi(buf.c_str()))); + tokens2.push_back(CAST_U8(atoi(buf.c_str()))); for (size_t i = 0, sz = tokens2.size(); i < sz && i < OUTFIT_ITEM_COUNT; i++) @@ -181,8 +181,8 @@ void OutfitWindow::load(const bool oldConfig) true); } mAwayOutfit = cfg->getValue("OutfitAwayIndex", OUTFITS_COUNT - 1); - if (mAwayOutfit >= static_cast<int>(OUTFITS_COUNT)) - mAwayOutfit = static_cast<int>(OUTFITS_COUNT) - 1; + if (mAwayOutfit >= CAST_S32(OUTFITS_COUNT)) + mAwayOutfit = CAST_S32(OUTFITS_COUNT) - 1; if (mAwayOutfitCheck) mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit); @@ -204,7 +204,7 @@ void OutfitWindow::save() const outfitStr.append(toString(res)); if (i < OUTFIT_ITEM_COUNT - 1) outfitStr.append(" "); - outfitColorsStr.append(toString(static_cast<int>( + outfitColorsStr.append(toString(CAST_S32( toInt(mItemColors[o][i], int)))); if (i < OUTFIT_ITEM_COUNT - 1) outfitColorsStr.append(" "); @@ -249,7 +249,7 @@ void OutfitWindow::action(const ActionEvent &event) } else if (eventId == "unequip") { - if (mCurrentOutfit >= 0 && mCurrentOutfit < static_cast<int>( + if (mCurrentOutfit >= 0 && mCurrentOutfit < CAST_S32( OUTFITS_COUNT)) { mItemsUnequip[mCurrentOutfit] = mUnequipCheck->isSelected(); @@ -274,7 +274,7 @@ void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty, { bool isEmpty = true; - if (outfit < 0 || outfit > static_cast<int>(OUTFITS_COUNT)) + if (outfit < 0 || outfit > CAST_S32(OUTFITS_COUNT)) return; for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++) @@ -294,7 +294,7 @@ void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty, } } - if ((!isEmpty || unwearEmpty) && outfit < static_cast<int>(OUTFITS_COUNT) + if ((!isEmpty || unwearEmpty) && outfit < CAST_S32(OUTFITS_COUNT) && mItemsUnequip[outfit]) { unequipNotInOutfit(outfit); @@ -313,8 +313,8 @@ void OutfitWindow::copyOutfit(const int outfit) void OutfitWindow::copyOutfit(const int src, const int dst) { - if (src < 0 || src > static_cast<int>(OUTFITS_COUNT) - || dst < 0 || dst > static_cast<int>(OUTFITS_COUNT)) + if (src < 0 || src > CAST_S32(OUTFITS_COUNT) + || dst < 0 || dst > CAST_S32(OUTFITS_COUNT)) { return; } @@ -339,7 +339,7 @@ void OutfitWindow::draw(Graphics *graphics) { const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth); const int itemY = mPadding + mTitleBarHeight - + ((i / static_cast<unsigned int>(mGridWidth)) * mBoxHeight); + + ((i / CAST_U32(mGridWidth)) * mBoxHeight); graphics->setColor(mBorderColor); graphics->drawRectangle(Rect(itemX, itemY, 32, 32)); @@ -395,7 +395,7 @@ void OutfitWindow::safeDraw(Graphics *graphics) { const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth); const int itemY = mPadding + mTitleBarHeight - + ((i / static_cast<unsigned int>(mGridWidth)) * mBoxHeight); + + ((i / CAST_U32(mGridWidth)) * mBoxHeight); graphics->setColor(mBorderColor); graphics->drawRectangle(Rect(itemX, itemY, 32, 32)); @@ -558,7 +558,7 @@ int OutfitWindow::getIndexFromGrid(const int pointX, const int pointY) const return -1; const int index = (((pointY - mTitleBarHeight) / mBoxHeight) * mGridWidth) + (pointX - mPadding) / mBoxWidth; - if (index >= static_cast<int>(OUTFIT_ITEM_COUNT) || index < 0) + if (index >= CAST_S32(OUTFIT_ITEM_COUNT) || index < 0) return -1; return index; } @@ -601,7 +601,7 @@ std::string OutfitWindow::keyName(const int number) void OutfitWindow::next() { - if (mCurrentOutfit < (static_cast<int>(OUTFITS_COUNT) - 1)) + if (mCurrentOutfit < (CAST_S32(OUTFITS_COUNT) - 1)) mCurrentOutfit++; else mCurrentOutfit = 0; @@ -621,7 +621,7 @@ void OutfitWindow::showCurrentOutfit() { // TRANSLATORS: outfits window label mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1)); - if (mCurrentOutfit < static_cast<int>(OUTFITS_COUNT)) + if (mCurrentOutfit < CAST_S32(OUTFITS_COUNT)) mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]); else mUnequipCheck->setSelected(false); @@ -635,7 +635,7 @@ void OutfitWindow::wearNextOutfit(const bool all) { next(); if (!all && mCurrentOutfit >= 0 && mCurrentOutfit - < static_cast<int>(OUTFITS_COUNT)) + < CAST_S32(OUTFITS_COUNT)) { bool fromStart = false; while (!mItemsUnequip[mCurrentOutfit]) @@ -657,7 +657,7 @@ void OutfitWindow::wearPreviousOutfit(const bool all) { previous(); if (!all && mCurrentOutfit >= 0 && mCurrentOutfit - < static_cast<int>(OUTFITS_COUNT)) + < CAST_S32(OUTFITS_COUNT)) { bool fromStart = false; while (!mItemsUnequip[mCurrentOutfit]) @@ -694,7 +694,7 @@ void OutfitWindow::copyFromEquiped(const int dst) { mItems[dst][outfitCell] = item->getId(); mItemColors[dst][outfitCell++] = item->getColor(); - if (outfitCell >= static_cast<int>(OUTFIT_ITEM_COUNT)) + if (outfitCell >= CAST_S32(OUTFIT_ITEM_COUNT)) break; } } diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp index 3bea8577f..9e46c1793 100644 --- a/src/gui/windows/questswindow.cpp +++ b/src/gui/windows/questswindow.cpp @@ -369,10 +369,10 @@ void QuestsWindow::rebuild(const bool playSound) FOR_EACH (std::vector<QuestItem*>::const_iterator, it, hidden) (*it)->completeFlag = -1; - if (updatedQuest == -1 || updatedQuest >= static_cast<int>( + if (updatedQuest == -1 || updatedQuest >= CAST_S32( mQuestLinks.size())) { - updatedQuest = static_cast<int>(mQuestLinks.size() - 1); + updatedQuest = CAST_S32(mQuestLinks.size() - 1); } if (updatedQuest >= 0) { diff --git a/src/gui/windows/quitdialog.cpp b/src/gui/windows/quitdialog.cpp index 1ef878aae..ff12795d4 100644 --- a/src/gui/windows/quitdialog.cpp +++ b/src/gui/windows/quitdialog.cpp @@ -141,7 +141,7 @@ QuitDialog::~QuitDialog() void QuitDialog::placeOption(ContainerPlacer &placer, RadioButton *const option) { - placer(0, static_cast<int>(mOptions.size()), option, 3); + placer(0, CAST_S32(mOptions.size()), option, 3); mOptions.push_back(option); } diff --git a/src/gui/windows/registerdialog.cpp b/src/gui/windows/registerdialog.cpp index 601f16aa8..3c4fe5ed2 100644 --- a/src/gui/windows/registerdialog.cpp +++ b/src/gui/windows/registerdialog.cpp @@ -149,7 +149,7 @@ void RegisterDialog::postInit() Window::postInit(); setVisible(Visible_true); mUserField->requestFocus(); - mUserField->setCaretPosition(static_cast<unsigned>( + mUserField->setCaretPosition(CAST_U32( mUserField->getText().length())); mRegisterButton->setEnabled(canSubmit()); diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp index 1049085b4..f4cd045c3 100644 --- a/src/gui/windows/serverdialog.cpp +++ b/src/gui/windows/serverdialog.cpp @@ -521,7 +521,7 @@ void ServerDialog::loadServers(const bool addNew) server.hostname = XML::getProperty(subNode, "hostname", ""); server.althostname = XML::getProperty( subNode, "althostname", ""); - server.port = static_cast<uint16_t>( + server.port = CAST_U16( XML::getProperty(subNode, "port", 0)); if (server.port == 0) @@ -570,7 +570,7 @@ void ServerDialog::loadServers(const 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, sz = static_cast<unsigned int>( + for (unsigned int i = 0, sz = CAST_U32( mServers.size()); i < sz; i++) { if (mServers[i] == server) @@ -622,7 +622,7 @@ void ServerDialog::loadCustomServers() persistentIpKey, 0) ? true : false; const int defaultPort = defaultPortForServerType(server.type); - server.port = static_cast<uint16_t>( + server.port = CAST_U16( config.getValue(portKey, defaultPort)); // skip invalid server @@ -640,7 +640,7 @@ void ServerDialog::saveCustomServers(const ServerInfo ¤tServer, // Make sure the current server is mentioned first if (currentServer.isValid()) { - if (index >= 0 && static_cast<size_t>(index) < mServers.size()) + if (index >= 0 && CAST_SIZE(index) < mServers.size()) { mServers[index] = currentServer; } @@ -660,7 +660,7 @@ void ServerDialog::saveCustomServers(const ServerInfo ¤tServer, int savedServerCount = 0; - for (unsigned i = 0, sz = static_cast<unsigned>(mServers.size()); + for (unsigned i = 0, sz = CAST_U32(mServers.size()); i < sz && savedServerCount < MAX_SERVERLIST; ++ i) { const ServerInfo &server = mServers.at(i); @@ -712,7 +712,7 @@ int ServerDialog::downloadUpdate(void *ptr, { finished = true; } - else if (static_cast<int>(status) < 0) + else if (CAST_S32(status) < 0) { logger->log("Error retreiving server list: %s\n", sd->mDownload->getError()); diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index b80f6d5fe..d8ae3ef2d 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -135,7 +135,7 @@ void SkillDialog::action(const ActionEvent &event) if (tab) { if (const SkillInfo *const info = tab->getSelectedInfo()) - playerHandler->increaseSkill(static_cast<uint16_t>(info->id)); + playerHandler->increaseSkill(CAST_U16(info->id)); } } else if (eventId == "sel") @@ -150,7 +150,7 @@ void SkillDialog::action(const ActionEvent &event) mUseButton->setCaption(info->useButton); mIncreaseButton->setEnabled(info->id < SKILL_VAR_MIN_ID); const int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS) + if (num >= 0 && num < CAST_S32(SHORTCUT_TABS) && itemShortcut[num]) { itemShortcut[num]->setItemSelected( @@ -329,7 +329,7 @@ void SkillDialog::loadXmlFile(const std::string &fileName) if (!skill) { skill = new SkillInfo; - skill->id = static_cast<unsigned int>(id); + skill->id = CAST_U32(id); skill->modifiable = Modifiable_false; skill->model = model; skill->update(); @@ -482,7 +482,7 @@ void SkillDialog::addSkill(const SkillOwner::Type owner, if (mDefaultModel) { SkillInfo *const skill = new SkillInfo; - skill->id = static_cast<unsigned int>(id); + skill->id = CAST_U32(id); skill->type = type; skill->owner = owner; SkillData *const data = skill->data; diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp index 799456fe0..c2a5d66c9 100644 --- a/src/gui/windows/textcommandeditor.cpp +++ b/src/gui/windows/textcommandeditor.cpp @@ -151,11 +151,11 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : mSymbolTextField->setText(command->getSymbol()); mCommandTextField->setText(command->getCommand()); mCommentTextField->setText(command->getComment()); - mTypeDropDown->setSelected(static_cast<int>(command->getTargetType())); + mTypeDropDown->setSelected(CAST_S32(command->getTargetType())); #ifdef TMWA_SUPPORT mManaField->setValue(command->getMana()); mMagicLvlField->setValue(command->getBaseLvl()); - mSchoolDropDown->setSelected(static_cast<int>(command->getSchool()) + mSchoolDropDown->setSelected(CAST_S32(command->getSchool()) - MAGIC_START_ID); mSchoolLvlField->setValue(command->getSchoolLvl()); #endif diff --git a/src/gui/windows/textdialog.cpp b/src/gui/windows/textdialog.cpp index e777cf6a8..442cd5c67 100644 --- a/src/gui/windows/textdialog.cpp +++ b/src/gui/windows/textdialog.cpp @@ -71,7 +71,7 @@ TextDialog::TextDialog(const std::string &restrict title, int width = getFont()->getWidth(title); if (width < textLabel->getWidth()) width = textLabel->getWidth(); - reflowLayout(static_cast<int>(width + 20)); + reflowLayout(CAST_S32(width + 20)); } void TextDialog::postInit() diff --git a/src/gui/windows/textselectdialog.cpp b/src/gui/windows/textselectdialog.cpp index bac3ac0e4..dbc34bfaf 100644 --- a/src/gui/windows/textselectdialog.cpp +++ b/src/gui/windows/textselectdialog.cpp @@ -136,7 +136,7 @@ void TextSelectDialog::action(const ActionEvent &event) else if (eventId == "select") { const int index = mItemList->getSelected(); - if (index < 0 || index >= static_cast<int>(mModel->size())) + if (index < 0 || index >= CAST_S32(mModel->size())) return; mText = mModel->getElementAt(index); distributeActionEvent(); diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index bf4814a03..e6e97553a 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -531,7 +531,7 @@ int UpdaterWindow::updateProgress(void *ptr, progress = 1.0F; uw->setLabel(std::string(uw->mCurrentFile).append(" (") - .append(toString(static_cast<int>(progress * 100))).append("%)")); + .append(toString(CAST_S32(progress * 100))).append("%)")); uw->setProgress(progress); @@ -554,11 +554,11 @@ size_t UpdaterWindow::memoryWrite(void *ptr, size_t size, if (!uw) return 0; uw->mMemoryBuffer = static_cast<char*>(realloc(uw->mMemoryBuffer, - static_cast<size_t>(uw->mDownloadedBytes) + totalMem)); + CAST_SIZE(uw->mDownloadedBytes) + totalMem)); if (uw->mMemoryBuffer) { memcpy(&(uw->mMemoryBuffer[uw->mDownloadedBytes]), ptr, totalMem); - uw->mDownloadedBytes += static_cast<int>(totalMem); + uw->mDownloadedBytes += CAST_S32(totalMem); } return totalMem; @@ -655,7 +655,7 @@ void UpdaterWindow::loadUpdates() } std::string fixPath = mUpdatesDir + "/fix"; - const unsigned sz = static_cast<unsigned>(mUpdateFiles.size()); + const unsigned sz = CAST_U32(mUpdateFiles.size()); for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++) { const UpdateFile &file = mUpdateFiles[mUpdateIndex]; @@ -685,7 +685,7 @@ void UpdaterWindow::loadLocalUpdates(const std::string &dir) } const std::string fixPath = dir + "/fix"; - for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + for (unsigned int updateIndex = 0, sz = CAST_U32( updateFiles.size()); updateIndex < sz; updateIndex ++) { const UpdateFile &file = updateFiles[updateIndex]; @@ -712,7 +712,7 @@ void UpdaterWindow::unloadUpdates(const std::string &dir) } const std::string fixPath = dir + "/fix"; - for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + for (unsigned int updateIndex = 0, sz = CAST_U32( updateFiles.size()); updateIndex < sz; updateIndex ++) { UpdaterWindow::removeUpdateFile(dir, @@ -728,7 +728,7 @@ void UpdaterWindow::loadManaPlusUpdates(const std::string &dir) std::vector<UpdateFile> updateFiles = loadXMLFile( std::string(fixPath).append("/").append(xmlUpdateFile), false); - for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + for (unsigned int updateIndex = 0, sz = CAST_U32( updateFiles.size()); updateIndex < sz; updateIndex ++) { const UpdateFile &file = updateFiles[updateIndex]; @@ -752,7 +752,7 @@ void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir) const std::vector<UpdateFile> updateFiles = loadXMLFile( std::string(fixPath).append("/").append(xmlUpdateFile), true); - for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + for (unsigned int updateIndex = 0, sz = CAST_U32( updateFiles.size()); updateIndex < sz; updateIndex ++) { std::string name = updateFiles[updateIndex].name; @@ -815,11 +815,11 @@ void UpdaterWindow::logic() mProgressBar->setProgress(mDownloadProgress); if (mUpdateFiles.size() - && static_cast<size_t>(mUpdateIndex) <= mUpdateFiles.size()) + && CAST_SIZE(mUpdateIndex) <= mUpdateFiles.size()) { mProgressBar->setText(strprintf("%u/%u", mUpdateIndex - + mUpdateIndexOffset + 1, static_cast<unsigned>( - mUpdateFiles.size()) + static_cast<int>( + + mUpdateIndexOffset + 1, CAST_U32( + mUpdateFiles.size()) + CAST_S32( mTempUpdateFiles.size()) + 1)); } else @@ -911,7 +911,7 @@ void UpdaterWindow::logic() case UPDATE_RESOURCES: if (mDownloadComplete) { - if (static_cast<size_t>(mUpdateIndex) < mUpdateFiles.size()) + if (CAST_SIZE(mUpdateIndex) < mUpdateFiles.size()) { UpdateFile thisFile = mUpdateFiles[mUpdateIndex]; if (thisFile.type == "music" @@ -983,7 +983,7 @@ void UpdaterWindow::logic() if (mDownloadComplete) { mValidateXml = false; - if (static_cast<size_t>(mUpdateIndex) + if (CAST_SIZE(mUpdateIndex) < mTempUpdateFiles.size()) { const UpdateFile thisFile = mTempUpdateFiles[mUpdateIndex]; @@ -1027,7 +1027,7 @@ void UpdaterWindow::logic() break; default: logger->log("UpdaterWindow::logic unknown status: " - + toString(static_cast<unsigned>(mDownloadStatus))); + + toString(CAST_U32(mDownloadStatus))); break; } BLOCK_END("UpdaterWindow::logic") @@ -1085,7 +1085,7 @@ void UpdaterWindow::loadMods(const std::string &dir, splitToStringSet(modsList, modsString, '|'); const std::string fixPath = dir + "/fix"; - for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + for (unsigned int updateIndex = 0, sz = CAST_U32( updateFiles.size()); updateIndex < sz; updateIndex ++) { const UpdateFile &file = updateFiles[updateIndex]; @@ -1105,7 +1105,7 @@ void UpdaterWindow::loadMods(const std::string &dir, std::vector<UpdateFile> updateFiles2 = loadXMLFile( std::string(fixPath).append("/").append(xmlUpdateFile), true); - for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + for (unsigned int updateIndex = 0, sz = CAST_U32( updateFiles2.size()); updateIndex < sz; updateIndex ++) { const UpdateFile &file = updateFiles2[updateIndex]; diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp index d51af6b05..e5a803a29 100644 --- a/src/gui/windows/whoisonline.cpp +++ b/src/gui/windows/whoisonline.cpp @@ -459,7 +459,7 @@ void WhoIsOnline::loadWebList() level = 0; OnlinePlayer *const player = new OnlinePlayer(nick, - static_cast<unsigned char>(255), level, + CAST_U8(255), level, Gender::UNSPECIFIED, -1); mOnlinePlayers.insert(player); mOnlineNicks.insert(nick); @@ -502,11 +502,11 @@ size_t WhoIsOnline::memoryWrite(void *restrict ptr, reinterpret_cast<WhoIsOnline *restrict>(stream); const size_t totalMem = size * nmemb; wio->mMemoryBuffer = static_cast<char*>(realloc(wio->mMemoryBuffer, - static_cast<size_t>(wio->mDownloadedBytes) + totalMem)); + CAST_SIZE(wio->mDownloadedBytes) + totalMem)); if (wio->mMemoryBuffer) { memcpy(&(wio->mMemoryBuffer[wio->mDownloadedBytes]), ptr, totalMem); - wio->mDownloadedBytes += static_cast<int>(totalMem); + wio->mDownloadedBytes += CAST_S32(totalMem); } return totalMem; @@ -570,7 +570,7 @@ int WhoIsOnline::downloadThread(void *ptr) case CURLE_COULDNT_CONNECT: default: std::cerr << "curl error " - << static_cast<unsigned>(res) << ": " + << CAST_U32(res) << ": " << wio->mCurlError << " host: " << url.c_str() << std::endl; break; |