diff options
Diffstat (limited to 'src/gui/widgets')
49 files changed, 306 insertions, 306 deletions
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(); |