diff --git a/src/common/Rect.hxx b/src/common/Rect.hxx index 90b77fda7..4e64a122e 100644 --- a/src/common/Rect.hxx +++ b/src/common/Rect.hxx @@ -36,7 +36,7 @@ struct Point Int32 y{0}; //!< The vertical part of the point Point() = default; - explicit Point(Int32 x1, Int32 y1) : x(x1), y(y1) { } + explicit constexpr Point(Int32 x1, Int32 y1) : x{x1}, y{y1} { } explicit Point(const string& p) { char c = '\0'; istringstream buf(p); @@ -59,7 +59,7 @@ struct Size uInt32 h{0}; //!< The height part of the size Size() = default; - explicit Size(uInt32 w1, uInt32 h1) : w(w1), h(h1) { } + explicit constexpr Size(uInt32 w1, uInt32 h1) : w{w1}, h{h1} { } explicit Size(const string& s) { char c = '\0'; istringstream buf(s); @@ -106,84 +106,84 @@ struct Size */ struct Rect { - private: - //!< The point at the top left of the rectangle (part of the rect). - uInt32 top{0}, left{0}; - //!< The point at the bottom right of the rectangle (not part of the rect). - uInt32 bottom{0}, right{0}; +private: + //!< The point at the top left of the rectangle (part of the rect). + uInt32 top{0}, left{0}; + //!< The point at the bottom right of the rectangle (not part of the rect). + uInt32 bottom{0}, right{0}; - public: - Rect() {} - explicit Rect(const Size& s) : bottom(s.h), right(s.w) { assert(valid()); } - Rect(uInt32 w, uInt32 h) : bottom(h), right(w) { assert(valid()); } - Rect(const Point& p, uInt32 w, uInt32 h) - : top(p.y), left(p.x), bottom(p.y + h), right(p.x + w) { assert(valid()); } - Rect(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top(y1), left(x1), bottom(y2), right(x2) { assert(valid()); } +public: + Rect() {} + constexpr explicit Rect(const Size& s) : bottom{ s.h }, right{ s.w } { assert(valid()); } + constexpr Rect(uInt32 w, uInt32 h) : bottom{ h }, right{ w } { assert(valid()); } + constexpr Rect(const Point& p, uInt32 w, uInt32 h) + : top(p.y), left(p.x), bottom(p.y + h), right( p.x + w) { assert(valid()); } + constexpr Rect(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top{y1}, left{x1}, bottom{y2}, right{x2} { assert(valid()); } - uInt32 x() const { return left; } - uInt32 y() const { return top; } - Point point() const { return Point(x(), y()); } + uInt32 x() const { return left; } + uInt32 y() const { return top; } + Point point() const { return Point(x(), y()); } - uInt32 w() const { return right - left; } - uInt32 h() const { return bottom - top; } - Size size() const { return Size(w(), h()); } + uInt32 w() const { return right - left; } + uInt32 h() const { return bottom - top; } + Size size() const { return Size(w(), h()); } - void setWidth(uInt32 aWidth) { right = left + aWidth; } - void setHeight(uInt32 aHeight) { bottom = top + aHeight; } - void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); } + void setWidth(uInt32 aWidth) { right = left + aWidth; } + void setHeight(uInt32 aHeight) { bottom = top + aHeight; } + void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); } - void setBounds(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) { - top = y1; - left = x1; - bottom = y2; - right = x2; - assert(valid()); - } + void setBounds(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) { + top = y1; + left = x1; + bottom = y2; + right = x2; + assert(valid()); + } - bool valid() const { - return (left <= right && top <= bottom); - } + bool valid() const { + return (left <= right && top <= bottom); + } - bool empty() const { - return top == 0 && left == 0 && bottom == 0 && right == 0; - } + bool empty() const { + return top == 0 && left == 0 && bottom == 0 && right == 0; + } - void moveTo(uInt32 x, uInt32 y) { - bottom += y - top; - right += x - left; - top = y; - left = x; - } + void moveTo(uInt32 x, uInt32 y) { + bottom += y - top; + right += x - left; + top = y; + left = x; + } - void moveTo(const Point& p) { - moveTo(p.x, p.y); - } + void moveTo(const Point& p) { + moveTo(p.x, p.y); + } - bool contains(uInt32 x, uInt32 y) const { - return x >= left && y >= top && x < right && y < bottom; - } + bool contains(uInt32 x, uInt32 y) const { + return x >= left && y >= top && x < right && y < bottom; + } - // Tests whether 'r' is completely contained within this rectangle. - // If it isn't, then set 'x' and 'y' such that moving 'r' to this - // position will make it be contained. - bool contains(uInt32& x, uInt32& y, const Rect& r) const { - if(r.left < left) x = left; - else if(r.right > right) x = r.left - (r.right - right); - if(r.top < top) y = top; - else if(r.bottom > bottom) y = r.top - (r.bottom - bottom); + // Tests whether 'r' is completely contained within this rectangle. + // If it isn't, then set 'x' and 'y' such that moving 'r' to this + // position will make it be contained. + bool contains(uInt32& x, uInt32& y, const Rect& r) const { + if(r.left < left) x = left; + else if(r.right > right) x = r.left - (r.right - right); + if(r.top < top) y = top; + else if(r.bottom > bottom) y = r.top - (r.bottom - bottom); - return r.left != x || r.top != y; - } + return r.left != x || r.top != y; + } - bool operator==(const Rect& r) const { - return top == r.top && left == r.left && bottom == r.bottom && right == r.right; - } - bool operator!=(const Rect& r) const { return !(*this == r); } + bool operator==(const Rect& r) const { + return top == r.top && left == r.left && bottom == r.bottom && right == r.right; + } + bool operator!=(const Rect& r) const { return !(*this == r); } - friend ostream& operator<<(ostream& os, const Rect& r) { - os << r.point() << "," << r.size(); - return os; - } + friend ostream& operator<<(ostream& os, const Rect& r) { + os << r.point() << "," << r.size(); + return os; + } }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/AboutDialog.cxx b/src/gui/AboutDialog.cxx index a13198518..a330b3720 100644 --- a/src/gui/AboutDialog.cxx +++ b/src/gui/AboutDialog.cxx @@ -38,7 +38,6 @@ AboutDialog::AboutDialog(OSystem& osystem, DialogContainer& parent, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; WidgetArray wid; // Set real dimensions @@ -46,7 +45,7 @@ AboutDialog::AboutDialog(OSystem& osystem, DialogContainer& parent, _h = _th + 14 * lineHeight + VGAP * 3 + buttonHeight + VBORDER * 2; // Add Previous, Next and Close buttons - xpos = HBORDER; ypos = _h - buttonHeight - VBORDER; + int xpos = HBORDER, ypos = _h - buttonHeight - VBORDER; myPrevButton = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, "Previous", GuiObject::kPrevCmd); @@ -112,8 +111,8 @@ AboutDialog::~AboutDialog() void AboutDialog::updateStrings(int page, int lines, string& title) { int i = 0; - auto ADD_ATEXT = [&](const string& d) { myDescStr[i] = d; i++; }; - auto ADD_ALINE = [&]() { ADD_ATEXT(""); }; + const auto ADD_ATEXT = [&](const string& d) { myDescStr[i] = d; i++; }; + const auto ADD_ALINE = [&]() { ADD_ATEXT(""); }; switch(page) { @@ -323,7 +322,7 @@ const string AboutDialog::getUrl(const string& str) const for(size_t i = 0; i < str.size(); ++i) { string remainder = str.substr(i); - char ch = str[i]; + const char ch = str[i]; if(!isUrl && (BSPF::startsWithIgnoreCase(remainder, "http://") diff --git a/src/gui/BrowserDialog.cxx b/src/gui/BrowserDialog.cxx index 05eab474f..016d06bf9 100644 --- a/src/gui/BrowserDialog.cxx +++ b/src/gui/BrowserDialog.cxx @@ -44,10 +44,8 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font, HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); const int selectHeight = lineHeight + VGAP * 3; - int xpos, ypos; - ButtonWidget* b; - - xpos = HBORDER; ypos = VBORDER + _th; + int xpos = HBORDER, ypos = VBORDER + _th; + ButtonWidget* b = nullptr; // Current path _navigationBar = new NavigationWidget(this, font, xpos, ypos, _w - HBORDER * 2, buttonHeight); @@ -122,7 +120,7 @@ void BrowserDialog::show(GuiObject* parent, const GUI::Font& font, uInt32 w = 0, h = 0; static_cast(parent)->getDynamicBounds(w, h); - if(w > uInt32(font.getMaxCharWidth() * 80)) + if(w > static_cast(font.getMaxCharWidth() * 80)) w = font.getMaxCharWidth() * 80; if(ourBrowser == nullptr || &ourBrowser->parent() != &parent->parent()) @@ -277,7 +275,7 @@ void BrowserDialog::handleCommand(CommandSender* sender, int cmd, // Send a signal to the calling class that a selection has been made if(_mode != Mode::Directories) { - bool savePath = _savePathBox->getState(); + const bool savePath = _savePathBox->getState(); instance().settings().setValue("saveuserdir", savePath); if(savePath) diff --git a/src/gui/CheckListWidget.cxx b/src/gui/CheckListWidget.cxx index be108863b..20c57c8ec 100644 --- a/src/gui/CheckListWidget.cxx +++ b/src/gui/CheckListWidget.cxx @@ -59,8 +59,8 @@ void CheckListWidget::setList(const StringList& list, const BoolArray& state) _checkList[i]->setFlags(Widget::FLAG_ENABLED); // Then turn off any extras - if(int(_stateList.size()) < _rows) - for(int i = int(_stateList.size()); i < _rows; ++i) + if(static_cast(_stateList.size()) < _rows) + for(int i = static_cast(_stateList.size()); i < _rows; ++i) _checkList[i]->clearFlags(Widget::FLAG_ENABLED); ListWidget::recalc(); @@ -69,7 +69,7 @@ void CheckListWidget::setList(const StringList& list, const BoolArray& state) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CheckListWidget::setLine(int line, const string& str, const bool& state) { - if(line >= int(_list.size())) + if(line >= static_cast(_list.size())) return; _list[line] = str; @@ -81,14 +81,14 @@ void CheckListWidget::drawWidget(bool hilite) { //cerr << "CheckListWidget::drawWidget\n"; FBSurface& s = _boss->dialog().surface(); - int i, pos, len = int(_list.size()); + const int len = static_cast(_list.size()); // Draw a thin frame around the list and to separate columns s.frameRect(_x, _y, _w, _h, hilite ? kWidColorHi : kColor); s.vLine(_x + CheckboxWidget::boxSize(_font) + 5, _y, _y + _h - 1, kColor); // Draw the list items - for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++) + for (int i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++) { // Draw checkboxes for correct lines (takes scrolling into account) _checkList[i]->setState(_stateList[pos]); @@ -98,7 +98,7 @@ void CheckListWidget::drawWidget(bool hilite) const int y = _y + 2 + _lineHeight * i + 2; ColorId textColor = kTextColor; - Common::Rect r(getEditRect()); + const Common::Rect r(getEditRect()); // Draw the selected item inverted, on a highlighted background. if (_selectedItem == pos) @@ -145,7 +145,7 @@ Common::Rect CheckListWidget::getEditRect() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CheckListWidget::getState(int line) const { - if(line >= 0 && line < int(_stateList.size())) + if(line >= 0 && line < static_cast(_stateList.size())) return _stateList[line]; else return false; @@ -171,8 +171,8 @@ void CheckListWidget::handleCommand(CommandSender* sender, int cmd, if(cmd == CheckboxWidget::kCheckActionCmd) { // Figure out which line has been checked - int line = _currentPos + id; - _stateList[line] = bool(data); + const int line = _currentPos + id; + _stateList[line] = static_cast(data); // Let the boss know about it sendCommand(CheckListWidget::kListItemChecked, line, _id); diff --git a/src/gui/ComboDialog.cxx b/src/gui/ComboDialog.cxx index 5f174f045..d9bdc3fa8 100644 --- a/src/gui/ComboDialog.cxx +++ b/src/gui/ComboDialog.cxx @@ -37,7 +37,6 @@ ComboDialog::ComboDialog(GuiObject* boss, const GUI::Font& font, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; WidgetArray wid; // Get maximum width of popupwidget @@ -48,12 +47,11 @@ ComboDialog::ComboDialog(GuiObject* boss, const GUI::Font& font, // Set real dimensions _w = 8 * fontWidth + pwidth + PopUpWidget::dropDownWidth(font) + HBORDER * 2; _h = 8 * (lineHeight + VGAP) + VGAP + buttonHeight + VBORDER * 2 + _th; - xpos = HBORDER; - ypos = VBORDER + _th; + int xpos = HBORDER, ypos = VBORDER + _th; // Add event popup for 8 events myEvents.fill(nullptr); - auto ADD_EVENT_POPUP = [&](int idx, const string& label) + const auto ADD_EVENT_POPUP = [&](int idx, const string& label) { myEvents[idx] = new PopUpWidget(this, font, xpos, ypos, pwidth, lineHeight, combolist, label); @@ -96,7 +94,7 @@ void ComboDialog::loadConfig() { StringList events = instance().eventHandler().getComboListForEvent(myComboEvent); - size_t size = std::min(events.size(), 8); + const size_t size = std::min(events.size(), 8); for(size_t i = 0; i < size; ++i) myEvents[i]->setSelected("", events[i]); diff --git a/src/gui/CommandDialog.cxx b/src/gui/CommandDialog.cxx index 374713569..469fa9ee0 100644 --- a/src/gui/CommandDialog.cxx +++ b/src/gui/CommandDialog.cxx @@ -49,7 +49,7 @@ CommandDialog::CommandDialog(OSystem& osystem, DialogContainer& parent) WidgetArray wid; int xoffset = HBORDER, yoffset = VBORDER + _th; - auto ADD_CD_BUTTON = [&](const string& label, int cmd) + const auto ADD_CD_BUTTON = [&](const string& label, int cmd) { ButtonWidget* b = new ButtonWidget(this, _font, xoffset, yoffset, buttonWidth, buttonHeight, label, cmd); @@ -173,8 +173,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd, { event = Event::NextState; stateCmd = true; - int slot = (instance().state().currentSlot() + 1) % 10; - updateSlot(slot); + updateSlot((instance().state().currentSlot() + 1) % 10); break; } case kLoadStateCmd: diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index ad9ba6b69..e76183201 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -55,14 +55,14 @@ void ContextMenu::addItems(const VariantList& items) _h = 1; // recalculate this in ::recalc() _scrollUpColor = _firstEntry > 0 ? kScrollColor : kColor; - _scrollDnColor = (_firstEntry + _numEntries < int(_entries.size())) ? + _scrollDnColor = (_firstEntry + _numEntries < static_cast(_entries.size())) ? kScrollColor : kColor; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::show(uInt32 x, uInt32 y, const Common::Rect& bossRect, int item) { - uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); + const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); _xorig = bossRect.x() + x * scale; _yorig = bossRect.y() + y * scale; @@ -94,7 +94,7 @@ void ContextMenu::recalc(const Common::Rect& image) { // Now is the time to adjust the height // If it's higher than the screen, we need to scroll through - uInt32 maxentries = std::min(18, (image.h() - 2) / _rowHeight); + const uInt32 maxentries = std::min(18, (image.h() - 2) / _rowHeight); if(_entries.size() > maxentries) { // We show two less than the max, so we have room for two scroll buttons @@ -104,8 +104,8 @@ void ContextMenu::recalc(const Common::Rect& image) } else { - _numEntries = int(_entries.size()); - _h = int(_entries.size()) * _rowHeight + 2; + _numEntries = static_cast(_entries.size()); + _h = static_cast(_entries.size()) * _rowHeight + 2; _showScroll = false; } _isScrolling = false; @@ -114,7 +114,7 @@ void ContextMenu::recalc(const Common::Rect& image) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::setSelectedIndex(int idx) { - if(idx >= 0 && idx < int(_entries.size())) + if(idx >= 0 && idx < static_cast(_entries.size())) _selectedItem = idx; else _selectedItem = -1; @@ -123,7 +123,7 @@ void ContextMenu::setSelectedIndex(int idx) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::setSelected(const Variant& tag, const Variant& defaultTag) { - auto SEARCH_AND_SELECT = [&](const Variant& t) + const auto SEARCH_AND_SELECT = [&](const Variant& t) { for(uInt32 item = 0; item < _entries.size(); ++item) { @@ -147,7 +147,7 @@ void ContextMenu::setSelected(const Variant& tag, const Variant& defaultTag) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::setSelectedMax() { - setSelectedIndex(int(_entries.size()) - 1); + setSelectedIndex(static_cast(_entries.size()) - 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -195,7 +195,7 @@ bool ContextMenu::sendSelectionUp() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool ContextMenu::sendSelectionDown() { - if(isVisible() || _selectedItem >= int(_entries.size()) - 1) + if(isVisible() || _selectedItem >= static_cast(_entries.size()) - 1) return false; _selectedItem++; @@ -220,7 +220,7 @@ bool ContextMenu::sendSelectionLast() if(isVisible()) return false; - _selectedItem = int(_entries.size()) - 1; + _selectedItem = static_cast(_entries.size()) - 1; sendCommand(_cmd ? _cmd : ContextMenu::kItemSelectedCmd, _selectedItem, _id); return true; } @@ -229,7 +229,7 @@ bool ContextMenu::sendSelectionLast() void ContextMenu::handleMouseDown(int x, int y, MouseButton b, int clickCount) { // Compute over which item the mouse is... - int item = findItem(x, y); + const int item = findItem(x, y); // Only do a selection when the left button is in the dialog if(b == MouseButton::LEFT) @@ -248,7 +248,7 @@ void ContextMenu::handleMouseDown(int x, int y, MouseButton b, int clickCount) void ContextMenu::handleMouseMoved(int x, int y) { // Compute over which item the mouse is... - int item = findItem(x, y); + const int item = findItem(x, y); if(item == -1) return; @@ -419,12 +419,12 @@ void ContextMenu::moveDown() // Otherwise, the offset should increase by 1 if(_selectedOffset == _numEntries) scrollDown(); - else if(_selectedOffset < int(_entries.size())) + else if(_selectedOffset < static_cast(_entries.size())) drawCurrentSelection(_selectedOffset+1); } else { - if(_selectedOffset < int(_entries.size()) - 1) + if(_selectedOffset < static_cast(_entries.size()) - 1) drawCurrentSelection(_selectedOffset+1); } } @@ -441,7 +441,7 @@ void ContextMenu::movePgUp() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::movePgDown() { - if(_firstEntry == int(_entries.size() - _numEntries)) + if(_firstEntry == static_cast(_entries.size() - _numEntries)) moveToLast(); else scrollDown(_numEntries); @@ -460,7 +460,7 @@ void ContextMenu::moveToFirst() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::moveToLast() { - _firstEntry = int(_entries.size()) - _numEntries; + _firstEntry = static_cast(_entries.size()) - _numEntries; _scrollUpColor = kScrollColor; _scrollDnColor = kColor; @@ -470,7 +470,7 @@ void ContextMenu::moveToLast() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::moveToSelected() { - if(_selectedItem < 0 || _selectedItem >= int(_entries.size())) + if(_selectedItem < 0 || _selectedItem >= static_cast(_entries.size())) return; // First jump immediately to the item @@ -479,7 +479,7 @@ void ContextMenu::moveToSelected() // Now check if we've gone past the current 'window' size, and scale // back accordingly - int max_offset = int(_entries.size()) - _numEntries; + const int max_offset = static_cast(_entries.size()) - _numEntries; if(_firstEntry > max_offset) { offset = _firstEntry - max_offset; @@ -508,7 +508,7 @@ void ContextMenu::scrollUp(int distance) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::scrollDown(int distance) { - int max_offset = int(_entries.size()) - _numEntries; + const int max_offset = static_cast(_entries.size()) - _numEntries; if(_firstEntry == max_offset) return; @@ -601,7 +601,8 @@ void ContextMenu::drawDialog() s.frameRect(_x, _y, _w, _h, kTextColor); // Draw the entries, taking scroll buttons into account - int x = _x + 1, y = _y + 1, w = _w - 2; + const int x = _x + 1, w = _w - 2; + int y = _y + 1; // Show top scroll area int offset = _selectedOffset; @@ -615,7 +616,7 @@ void ContextMenu::drawDialog() for(int i = _firstEntry, current = 0; i < _firstEntry + _numEntries; ++i, ++current) { - bool hilite = offset == current; + const bool hilite = offset == current; if(hilite) s.fillRect(x, y, w, _rowHeight, kTextColorHi); s.drawString(_font, _entries[i].first, x + _textOfs, y + 2, w, !hilite ? kTextColor : kTextColorInv); diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx index 7dd9ca665..275bb5999 100644 --- a/src/gui/DeveloperDialog.cxx +++ b/src/gui/DeveloperDialog.cxx @@ -56,7 +56,6 @@ DeveloperDialog::DeveloperDialog(OSystem& osystem, DialogContainer& parent, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; // Set real dimensions setSize(53 * fontWidth + HBORDER * 2, @@ -64,7 +63,8 @@ DeveloperDialog::DeveloperDialog(OSystem& osystem, DialogContainer& parent, max_w, max_h); // The tab widget - xpos = 2; ypos = VGAP; + constexpr int xpos = 2; + const int ypos = VGAP; myTab = new TabWidget(this, font, xpos, ypos + _th, _w - 2 * xpos, _h - _th - VGAP - buttonHeight - VBORDER * 2); @@ -406,7 +406,7 @@ void DeveloperDialog::addVideoTab(const GUI::Font& font) kM1ColourChangedCmd, kPFColourChangedCmd, kBLColourChangedCmd }; - auto createDebugColourWidgets = [&](int idx, const string& desc) + const auto createDebugColourWidgets = [&](int idx, const string& desc) { int x = HBORDER + INDENT * 1; myDbgColour[idx] = new PopUpWidget(myTab, font, x, ypos - 1, @@ -512,7 +512,7 @@ void DeveloperDialog::addTimeMachineTab(const GUI::Font& font) xpos += CheckboxWidget::prefixSize(font); ypos += lineHeight + VGAP; - int swidth = fontWidth * 12 + 5; // width of PopUpWidgets below + const int swidth = fontWidth * 12 + 5; // width of PopUpWidgets below myStateSizeWidget = new SliderWidget(myTab, font, xpos, ypos - 1, swidth, lineHeight, "Buffer size (*) ", 0, kSizeChanged, lwidth, " states"); myStateSizeWidget->setMinValue(20); @@ -589,18 +589,16 @@ void DeveloperDialog::addDebuggerTab(const GUI::Font& font) HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); VariantList items; - int xpos, ypos, pwidth; const Common::Size& ds = instance().frameBuffer().desktopSize(BufferType::Debugger); - - xpos = HBORDER; - ypos = VBORDER; + const int xpos = HBORDER; + int ypos = VBORDER; // font size items.clear(); VarList::push_back(items, "Small", "small"); VarList::push_back(items, "Medium", "medium"); VarList::push_back(items, "Large", "large"); - pwidth = font.getStringWidth("Medium"); + int pwidth = font.getStringWidth("Medium"); myDebuggerFontSize = new PopUpWidget(myTab, font, HBORDER, ypos + 1, pwidth, lineHeight, items, "Font size (*) ", 0, kDFontSizeChanged); @@ -800,17 +798,15 @@ void DeveloperDialog::loadConfig() loadSettings(SettingsSet::player); loadSettings(SettingsSet::developer); // ...and select the current one - setWidgetStates(SettingsSet(mySettingsGroupEmulation->getSelected())); + setWidgetStates(static_cast(mySettingsGroupEmulation->getSelected())); // Debug colours handleDebugColours(instance().settings().getString("tia.dbgcolors")); #ifdef DEBUGGER_SUPPORT - uInt32 w, h; - // Debugger size const Common::Size& ds = instance().settings().getSize("dbg.res"); - w = ds.w; h = ds.h; + const int w = ds.w, h = ds.h; myDebuggerWidthSlider->setValue(w); myDebuggerHeightSlider->setValue(h); @@ -835,11 +831,11 @@ void DeveloperDialog::loadConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::saveConfig() { - bool devSettings = mySettingsGroupEmulation->getSelected() == SettingsSet::developer; + const bool devSettings = mySettingsGroupEmulation->getSelected() == SettingsSet::developer; instance().settings().setValue("dev.settings", devSettings); // copy current widget status into set... - getWidgetStates(SettingsSet(mySettingsGroupEmulation->getSelected())); + getWidgetStates(static_cast(mySettingsGroupEmulation->getSelected())); // ...and save both sets saveSettings(SettingsSet::player); saveSettings(SettingsSet::developer); @@ -875,8 +871,8 @@ void DeveloperDialog::saveConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::setDefaults() { - bool devSettings = mySettings; - SettingsSet set = SettingsSet(mySettingsGroupEmulation->getSelected()); + const bool devSettings = mySettings; + const SettingsSet set = static_cast(mySettingsGroupEmulation->getSelected()); switch(myTab->getActiveTab()) { @@ -948,8 +944,8 @@ void DeveloperDialog::setDefaults() #ifdef DEBUGGER_SUPPORT const Common::Size& size = instance().frameBuffer().desktopSize(BufferType::Debugger); - uInt32 w = std::min(size.w, uInt32(DebuggerDialog::kMediumFontMinW)); - uInt32 h = std::min(size.h, uInt32(DebuggerDialog::kMediumFontMinH)); + const uInt32 w = std::min(size.w, static_cast(DebuggerDialog::kMediumFontMinW)); + const uInt32 h = std::min(size.h, static_cast(DebuggerDialog::kMediumFontMinH)); myDebuggerWidthSlider->setValue(w); myDebuggerHeightSlider->setValue(h); myDebuggerFontSize->setSelected("medium"); @@ -1078,8 +1074,8 @@ void DeveloperDialog::handleSettings(bool devSettings) if (mySettings != devSettings) { mySettings = devSettings; // block redundant events first! - SettingsSet set = devSettings ? SettingsSet::developer - : SettingsSet::player; + const SettingsSet set = devSettings ? SettingsSet::developer + : SettingsSet::player; mySettingsGroupEmulation->setSelected(set); mySettingsGroupTia->setSelected(set); mySettingsGroupVideo->setSelected(set); @@ -1102,7 +1098,7 @@ void DeveloperDialog::handleTVJitterChange(bool enable) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::handleConsole() { - bool is7800 = myConsoleWidget->getSelected() == 1; + const bool is7800 = myConsoleWidget->getSelected() == 1; myRandomizeRAMWidget->setEnabled(!is7800); if(is7800) @@ -1112,7 +1108,7 @@ void DeveloperDialog::handleConsole() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::handleTia() { - bool enable = BSPF::equalsIgnoreCase("custom", myTIATypeWidget->getSelectedTag().toString()); + const bool enable = BSPF::equalsIgnoreCase("custom", myTIATypeWidget->getSelectedTag().toString()); myTIATypeWidget->setEnabled(mySettings); myInvPhaseLabel->setEnabled(enable); @@ -1131,7 +1127,7 @@ void DeveloperDialog::handleTia() if(BSPF::equalsIgnoreCase("custom", myTIATypeWidget->getSelectedTag().toString())) { - SettingsSet set = SettingsSet::developer; + const SettingsSet set = SettingsSet::developer; myPlInvPhaseWidget->setState(myPlInvPhase[set]); myMsInvPhaseWidget->setState(myMsInvPhase[set]); @@ -1160,14 +1156,14 @@ void DeveloperDialog::handleTia() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::handleTimeMachine() { - bool enable = myTimeMachineWidget->getState(); + const bool enable = myTimeMachineWidget->getState(); myStateSizeWidget->setEnabled(enable); myUncompressedWidget->setEnabled(enable); myStateIntervalWidget->setEnabled(enable); - uInt32 size = myStateSizeWidget->getValue(); - uInt32 uncompressed = myUncompressedWidget->getValue(); + const uInt32 size = myStateSizeWidget->getValue(); + const uInt32 uncompressed = myUncompressedWidget->getValue(); myStateHorizonWidget->setEnabled(enable && size > uncompressed); } @@ -1175,12 +1171,12 @@ void DeveloperDialog::handleTimeMachine() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::handleSize() { - uInt32 size = myStateSizeWidget->getValue(); - uInt32 uncompressed = myUncompressedWidget->getValue(); + const uInt32 size = myStateSizeWidget->getValue(); + const uInt32 uncompressed = myUncompressedWidget->getValue(); Int32 interval = myStateIntervalWidget->getSelected(); Int32 horizon = myStateHorizonWidget->getSelected(); bool found = false; - Int32 i; + Int32 i = 0; // handle illegal values if(interval == -1) @@ -1193,7 +1189,7 @@ void DeveloperDialog::handleSize() { for(i = horizon; i < NUM_HORIZONS; ++i) { - if(uInt64(size) * instance().state().rewindManager().INTERVAL_CYCLES[interval] + if(static_cast(size) * instance().state().rewindManager().INTERVAL_CYCLES[interval] <= instance().state().rewindManager().HORIZON_CYCLES[i]) { found = true; @@ -1214,8 +1210,8 @@ void DeveloperDialog::handleSize() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::handleUncompressed() { - uInt32 size = myStateSizeWidget->getValue(); - uInt32 uncompressed = myUncompressedWidget->getValue(); + const uInt32 size = myStateSizeWidget->getValue(); + const uInt32 uncompressed = myUncompressedWidget->getValue(); if(size < uncompressed) myStateSizeWidget->setValue(uncompressed); @@ -1226,11 +1222,11 @@ void DeveloperDialog::handleUncompressed() void DeveloperDialog::handleInterval() { uInt32 size = myStateSizeWidget->getValue(); - uInt32 uncompressed = myUncompressedWidget->getValue(); + const uInt32 uncompressed = myUncompressedWidget->getValue(); Int32 interval = myStateIntervalWidget->getSelected(); Int32 horizon = myStateHorizonWidget->getSelected(); bool found = false; - Int32 i; + Int32 i = 0; // handle illegal values if(interval == -1) @@ -1243,7 +1239,7 @@ void DeveloperDialog::handleInterval() { for(i = horizon; i < NUM_HORIZONS; ++i) { - if(uInt64(size) * instance().state().rewindManager().INTERVAL_CYCLES[interval] + if(static_cast(size) * instance().state().rewindManager().INTERVAL_CYCLES[interval] <= instance().state().rewindManager().HORIZON_CYCLES[i]) { found = true; @@ -1264,11 +1260,11 @@ void DeveloperDialog::handleInterval() void DeveloperDialog::handleHorizon() { uInt32 size = myStateSizeWidget->getValue(); - uInt32 uncompressed = myUncompressedWidget->getValue(); + const uInt32 uncompressed = myUncompressedWidget->getValue(); Int32 interval = myStateIntervalWidget->getSelected(); Int32 horizon = myStateHorizonWidget->getSelected(); bool found = false; - Int32 i; + Int32 i = 0; // handle illegal values if(interval == -1) @@ -1281,7 +1277,7 @@ void DeveloperDialog::handleHorizon() { for(i = interval; i >= 0; --i) { - if(uInt64(size) * instance().state().rewindManager().INTERVAL_CYCLES[i] + if(static_cast(size) * instance().state().rewindManager().INTERVAL_CYCLES[i] <= instance().state().rewindManager().HORIZON_CYCLES[horizon]) { found = true; @@ -1338,14 +1334,14 @@ void DeveloperDialog::handleDebugColours(int idx, int color) } }}; - int timing = instance().console().timing() == ConsoleTiming::ntsc ? 0 + const int timing = instance().console().timing() == ConsoleTiming::ntsc ? 0 : instance().console().timing() == ConsoleTiming::pal ? 1 : 2; myDbgColourSwatch[idx]->setColor(dbg_color[timing][color]); myDbgColour[idx]->setSelectedIndex(color); // make sure the selected debug colors are all different - std::array usedCol; + std::array usedCol = {0}; // identify used colors for(int i = 0; i < DEBUG_COLORS; ++i) @@ -1401,8 +1397,8 @@ void DeveloperDialog::handleDebugColours(const string& colors) void DeveloperDialog::handleFontSize() { #ifdef DEBUGGER_SUPPORT - uInt32 minW, minH; - int fontSize = myDebuggerFontSize->getSelected(); + uInt32 minW = 0, minH = 0; + const int fontSize = myDebuggerFontSize->getSelected(); if(fontSize == 0) { @@ -1424,11 +1420,11 @@ void DeveloperDialog::handleFontSize() minH = std::min(size.h, minH); myDebuggerWidthSlider->setMinValue(minW); - if(minW > uInt32(myDebuggerWidthSlider->getValue())) + if(minW > static_cast(myDebuggerWidthSlider->getValue())) myDebuggerWidthSlider->setValue(minW); myDebuggerHeightSlider->setMinValue(minH); - if(minH > uInt32(myDebuggerHeightSlider->getValue())) + if(minH > static_cast(myDebuggerHeightSlider->getValue())) myDebuggerHeightSlider->setValue(minH); #endif } diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 6ad17d282..ad2af1701 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -101,7 +101,7 @@ void Dialog::open() // dialogs cause drawing to occur within loadConfig() if (_surface == nullptr) _surface = instance().frameBuffer().allocateSurface(_w, _h); - else if (uInt32(_w) > _surface->width() || uInt32(_h) > _surface->height()) + else if (static_cast(_w) > _surface->width() || static_cast(_h) > _surface->height()) _surface->resize(_w, _h); _surface->setSrcSize(_w, _h); _layer = parent().addDialog(this); @@ -209,12 +209,12 @@ const string Dialog::getHelpURL() const if(_focusedWidget && _focusedWidget->hasHelp()) return _focusedWidget->getHelpURL(); - if(_tabID < int(_myTabList.size())) + if(_tabID < static_cast(_myTabList.size())) { TabWidget* activeTabGroup = _myTabList[_tabID].widget; // 2. check active tab - int activeTab = activeTabGroup->getActiveTab(); + const int activeTab = activeTabGroup->getActiveTab(); const Widget* parentTab = activeTabGroup->parentWidget(activeTab); if(parentTab->hasHelp()) @@ -286,12 +286,12 @@ void Dialog::positionAt(uInt32 pos) const Common::Size& screen = instance().frameBuffer().screenSize(); const Common::Rect& dst = _surface->dstRect(); // shift stacked dialogs - Int32 hgap = (screen.w >> 6) * _layer + screen.w * overscan; - Int32 vgap = (screen.w >> 6) * _layer + screen.h * overscan; - int top = std::min(std::max(0, Int32(screen.h - dst.h())), vgap); - int btm = std::max(0, Int32(screen.h - dst.h() - vgap)); - int left = std::min(std::max(0, Int32(screen.w - dst.w())), hgap); - int right = std::max(0, Int32(screen.w - dst.w() - hgap)); + const Int32 hgap = (screen.w >> 6) * _layer + screen.w * overscan; + const Int32 vgap = (screen.w >> 6) * _layer + screen.h * overscan; + const int top = std::min(std::max(0, static_cast(screen.h - dst.h())), vgap); + const int btm = std::max(0, static_cast(screen.h - dst.h() - vgap)); + const int left = std::min(std::max(0, static_cast(screen.w - dst.w())), hgap); + const int right = std::max(0, static_cast(screen.w - dst.w() - hgap)); switch (pos) { @@ -347,7 +347,7 @@ void Dialog::render() // A dialog is still on top if a non-shading dialog (e.g. ContextMenu) // is opened above it. - bool onTop = parent().myDialogStack.top() == this + const bool onTop = parent().myDialogStack.top() == this || (parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this && !parent().myDialogStack.top()->isShading()); @@ -356,7 +356,7 @@ void Dialog::render() if(_shadeSurface == nullptr) { // Create shading surface - uInt32 data = 0xff000000; + constexpr uInt32 data = 0xff000000; _shadeSurface = instance().frameBuffer().allocateSurface( 1, 1, ScalingInterpolation::sharp, &data); @@ -416,7 +416,7 @@ void Dialog::addToFocusList(const WidgetArray& list) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::addToFocusList(const WidgetArray& list, TabWidget* w, int tabId) +void Dialog::addToFocusList(const WidgetArray& list, const TabWidget* w, int tabId) { // Only add the list if the tab actually exists if(!w || w->getID() >= _myTabList.size()) @@ -432,7 +432,7 @@ void Dialog::addToFocusList(const WidgetArray& list, TabWidget* w, int tabId) FocusList& focus = _myTabList[w->getID()].focus; // Now insert in the correct place in that focus list - uInt32 id = tabId; + const uInt32 id = tabId; if(id < focus.size()) Vec::append(focus[id].list, list); else @@ -455,7 +455,7 @@ void Dialog::addTabWidget(TabWidget* w) return; // Make sure the array is large enough - uInt32 id = w->getID(); + const uInt32 id = w->getID(); while(_myTabList.size() < id) _myTabList.push_back(TabFocus()); @@ -487,7 +487,7 @@ void Dialog::buildCurrentFocusList(int tabID) // Remember which tab item previously had focus, if applicable // This only applies if this method was called for a tab change Widget* tabFocusWidget = nullptr; - if(tabID >= 0 && tabID < int(_myTabList.size())) + if(tabID >= 0 && tabID < static_cast(_myTabList.size())) { // Save focus in previously selected tab column, // and get focus for new tab column @@ -707,17 +707,17 @@ void Dialog::handleMouseWheel(int x, int y, int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::handleMouseMoved(int x, int y) { - Widget* w; + Widget* w = nullptr; if(_focusedWidget && !_dragWidget) { w = _focusedWidget; - int wx = w->getAbsX() - _x; - int wy = w->getAbsY() - _y; + const int wx = w->getAbsX() - _x; + const int wy = w->getAbsY() - _y; // We still send mouseEntered/Left messages to the focused item // (but to no other items). - bool mouseInFocusedWidget = (x >= wx && x < wx + w->_w && y >= wy && y < wy + w->_h); + const bool mouseInFocusedWidget = (x >= wx && x < wx + w->_w && y >= wy && y < wy + w->_h); if(mouseInFocusedWidget && _mouseWidget != w) { if(_mouseWidget) @@ -777,7 +777,7 @@ void Dialog::handleJoyDown(int stick, int button, bool longPress) // Focused widget receives joystick events if(_focusedWidget) { - Event::Type e = + const Event::Type e = instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); if(_focusedWidget->wantsRaw() || e == Event::NoType) @@ -788,7 +788,7 @@ void Dialog::handleJoyDown(int stick, int button, bool longPress) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::handleJoyUp(int stick, int button) { - Event::Type e = + const Event::Type e = instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); // Unless a widget has claimed all responsibility for data, we assume @@ -811,7 +811,7 @@ Event::Type Dialog::getJoyAxisEvent(int stick, JoyAxis axis, JoyDir adir, int bu // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) { - Event::Type e = getJoyAxisEvent(stick, axis, adir, button); + const Event::Type e = getJoyAxisEvent(stick, axis, adir, button); // Unless a widget has claimed all responsibility for data, we assume // that if an event exists for the given data, it should have priority. @@ -827,7 +827,7 @@ void Dialog::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Dialog::handleJoyHat(int stick, int hat, JoyHatDir hdir, int button) { - Event::Type e = + const Event::Type e = instance().eventHandler().eventForJoyHat(EventMode::kMenuMode, stick, hat, hdir, button); // Unless a widget has claimed all responsibility for data, we assume @@ -916,7 +916,7 @@ bool Dialog::handleNavEvent(Event::Type e, bool repeated) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::getTabIdForWidget(Widget* w) +void Dialog::getTabIdForWidget(const Widget* w) { if(_myTabList.size() == 0 || !w) return; @@ -934,7 +934,7 @@ void Dialog::getTabIdForWidget(Widget* w) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Dialog::cycleTab(int direction) { - if(_tabID >= 0 && _tabID < int(_myTabList.size())) + if(_tabID >= 0 && _tabID < static_cast(_myTabList.size())) { _myTabList[_tabID].widget->cycleTab(direction); return true; @@ -1086,9 +1086,9 @@ void Dialog::addDefaultsExtraOKCancelBGroup( // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::TabFocus::appendFocusList(WidgetArray& list) { - int active = widget->getActiveTab(); + const int active = widget->getActiveTab(); - if(active >= 0 && active < int(focus.size())) + if(active >= 0 && active < static_cast(focus.size())) Vec::append(list, focus[active].list); } @@ -1122,8 +1122,8 @@ bool Dialog::getDynamicBounds(uInt32& w, uInt32& h) const } else { - w = uInt32(0.95 * r.w() / scale); - h = uInt32(0.95 * r.h() / scale); + w = static_cast(0.95 * r.w() / scale); + h = static_cast(0.95 * r.h() / scale); return true; } } @@ -1144,7 +1144,7 @@ bool Dialog::shouldResize(uInt32& w, uInt32& h) const // returns true if the current size is larger than the allowed size or // if the current size is smaller than the allowed and wanted size - return (uInt32(_w) > w || uInt32(_h) > h || - (uInt32(_w) < w && uInt32(_w) < _max_w) || - (uInt32(_h) < h && uInt32(_h) < _max_h)); + return (static_cast(_w) > w || static_cast(_h) > h || + (static_cast(_w) < w && static_cast(_w) < _max_w) || + (static_cast(_h) < h && static_cast(_h) < _max_h)); } diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index b4017eae0..14bc1ba1c 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -77,7 +77,7 @@ class Dialog : public GuiObject void addFocusWidget(Widget* w) override; void addToFocusList(const WidgetArray& list) override; - void addToFocusList(const WidgetArray& list, TabWidget* w, int tabId); + void addToFocusList(const WidgetArray& list, const TabWidget* w, int tabId); void addBGroupToFocusList(const WidgetArray& list) { _buttonGroup = list; } void addTabWidget(TabWidget* w); void addDefaultWidget(ButtonWidget* w) { _defaultWidget = w; } @@ -211,7 +211,7 @@ class Dialog : public GuiObject private: void buildCurrentFocusList(int tabID = -1); bool handleNavEvent(Event::Type e, bool repeated = false); - void getTabIdForWidget(Widget* w); + void getTabIdForWidget(const Widget* w); bool cycleTab(int direction); const string getHelpURL() const override; bool hasHelp() const override { return !getHelpURL().empty(); } diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index 0439ed482..8669439d6 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -153,7 +153,8 @@ int DialogContainer::addDialog(Dialog* d) const Common::Rect& r = myOSystem.frameBuffer().imageRect(); const uInt32 scale = myOSystem.frameBuffer().hidpiScaleFactor(); - if(uInt32(d->getWidth() * scale) > r.w() || uInt32(d->getHeight() * scale) > r.h()) + if(static_cast(d->getWidth() * scale) > r.w() || + static_cast(d->getHeight() * scale) > r.h()) myOSystem.frameBuffer().showTextMessage( "Unable to show dialog box; FIX THE CODE", MessagePosition::BottomCenter, true); else diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index e2dca1ea5..dbadf83bf 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -49,7 +49,7 @@ void EditableWidget::setText(const string& str, bool changed) _backupString = str; // Filter input string _editString = ""; - for(char c: str) + for(const auto c: str) if(_filter(tolower(c))) _editString.push_back(c); if(_maxLen) @@ -61,7 +61,7 @@ void EditableWidget::setText(const string& str, bool changed) myUndoHandler->reset(); myUndoHandler->doo(_editString); - _caretPos = int(_editString.size()); + _caretPos = static_cast(_editString.size()); _selectSize = 0; _editScrollOffset = (_font.getStringWidth(_editString) - (getEditRect().w())); @@ -125,7 +125,7 @@ void EditableWidget::lostFocusWidget() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int EditableWidget::toCaretPos(int x) const { - int i; + int i = 0; x += caretOfs(); for(i = 0; i < static_cast(_editString.size()); ++i) @@ -198,7 +198,7 @@ void EditableWidget::handleMouseMoved(int x, int y) { if(isEditable() && _isDragging) { - int deltaPos = toCaretPos(x) - _caretPos; + const int deltaPos = toCaretPos(x) - _caretPos; if(deltaPos) { @@ -226,7 +226,7 @@ void EditableWidget::handleCommand(CommandSender* sender, int cmd, int data, int { // Copy everything if widget is not editable _caretPos = 0; - _selectSize = int(_editString.length()); + _selectSize = static_cast(_editString.length()); } copySelectedText(); } @@ -282,7 +282,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod) return false; bool handled = true; - Event::Type event = instance().eventHandler().eventForKey(EventMode::kEditMode, key, mod); + const Event::Type event = instance().eventHandler().eventForKey(EventMode::kEditMode, key, mod); switch(event) { @@ -297,7 +297,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod) case Event::MoveRightChar: if(_selectSize) handled = setCaretPos(selectEndPos()); - else if(_caretPos < int(_editString.size())) + else if(_caretPos < static_cast(_editString.size())) handled = setCaretPos(_caretPos + 1); _selectSize = 0; break; @@ -318,7 +318,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod) break; case Event::MoveEnd: - handled = setCaretPos(int(_editString.size())); + handled = setCaretPos(static_cast(_editString.size())); _selectSize = 0; break; @@ -328,7 +328,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod) break; case Event::SelectRightChar: - if(_caretPos < int(_editString.size())) + if(_caretPos < static_cast(_editString.size())) handled = moveCaretPos(+1); break; @@ -345,12 +345,12 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod) break; case Event::SelectEnd: - handled = moveCaretPos(int(_editString.size()) - _caretPos); + handled = moveCaretPos(static_cast(_editString.size()) - _caretPos); break; case Event::SelectAll: - if(setCaretPos(int(_editString.size()))) - _selectSize = -int(_editString.size()); + if(setCaretPos(static_cast(_editString.size()))) + _selectSize = -static_cast(_editString.size()); break; case Event::Backspace: @@ -487,8 +487,8 @@ void EditableWidget::drawCaretSelection() int x = editRect.x(); int y = editRect.y(); int w = editRect.w(); - int h = editRect.h(); - int wt = int(text.length()) * _boss->dialog().fontWidth() + 1; + const int h = editRect.h(); + int wt = static_cast(text.length()) * _boss->dialog().fontWidth() + 1; int dx = selectStartPos() * _boss->dialog().fontWidth() - _editScrollOffset; if(dx < 0) @@ -518,7 +518,7 @@ void EditableWidget::drawCaretSelection() const Common::Rect& editRect = getEditRect(); int x = editRect.x(); int y = editRect.y(); - ColorId color = _caretEnabled ? kTextColorHi : kTextColorInv; + const ColorId color = _caretEnabled ? kTextColorHi : kTextColorInv; x += getCaretOffset(); x += _x; @@ -564,7 +564,7 @@ bool EditableWidget::adjustOffset() // For some reason (differences in ScummVM event handling??), // this method should always return true. - int caretOfs = getCaretOffset(); + const int caretOfs = getCaretOffset(); const int editWidth = getEditRect().w(); if (caretOfs < 0) @@ -615,7 +615,7 @@ bool EditableWidget::killChar(int direction, bool addEdit) } else if(direction == 1) // Delete next character (delete) { - if(_caretPos < int(_editString.size())) + if(_caretPos < static_cast(_editString.size())) { if(_selectSize > 0) _selectSize--; @@ -644,7 +644,7 @@ bool EditableWidget::killLine(int direction) if(direction == -1) // erase from current position to beginning of line count = _caretPos; else if(direction == +1) // erase from current position to end of line - count = int(_editString.size()) - _caretPos; + count = static_cast(_editString.size()) - _caretPos; if(count > 0) { @@ -682,7 +682,7 @@ bool EditableWidget::killWord(int direction) } else if(direction == +1) // move to first character of next word { - while(currentPos < int(_editString.size())) + while(currentPos < static_cast(_editString.size())) { if(currentPos && BSPF::isWhiteSpace(_editString[currentPos - 1])) { @@ -737,7 +737,7 @@ bool EditableWidget::moveWord(int direction, bool select) } else if(direction == +1) // move to first character of next word { - while (currentPos < int(_editString.size())) + while (currentPos < static_cast(_editString.size())) { if (currentPos && BSPF::isWhiteSpace(_editString[currentPos - 1])) { @@ -763,7 +763,7 @@ bool EditableWidget::markWord() { _selectSize = 0; - while(_caretPos + _selectSize < int(_editString.size())) + while(_caretPos + _selectSize < static_cast(_editString.size())) { if(BSPF::isWhiteSpace(_editString[_caretPos + _selectSize])) break; @@ -873,7 +873,7 @@ bool EditableWidget::pasteSelectedText() ostringstream buf; bool lastOk = true; // only one filler char per invalid character (block) - for(char c : pasted) + for(const auto c : pasted) if(_filter(tolower(c))) { buf << c; @@ -888,7 +888,7 @@ bool EditableWidget::pasteSelectedText() _editString.insert(_caretPos, buf.str()); // position cursor at the end of pasted text - setCaretPos(_caretPos + int(buf.str().length())); + setCaretPos(_caretPos + static_cast(buf.str().length())); if(selected || !pasted.empty()) { diff --git a/src/gui/EmulationDialog.cxx b/src/gui/EmulationDialog.cxx index fab449f07..3e681bb4e 100644 --- a/src/gui/EmulationDialog.cxx +++ b/src/gui/EmulationDialog.cxx @@ -43,9 +43,9 @@ namespace { ); } - float unmapSpeed(int speed) + constexpr float unmapSpeed(int speed) { - float f_speed = static_cast(speed) / 100; + const float f_speed = static_cast(speed) / 100; return speed < 0 ? -1 / (f_speed - 1) : 1 + f_speed; } @@ -73,7 +73,6 @@ EmulationDialog::EmulationDialog(OSystem& osystem, DialogContainer& parent, HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), INDENT = Dialog::indent(); - int xpos, ypos; int lwidth = font.getStringWidth("Emulation speed "); WidgetArray wid; VariantList items; @@ -83,7 +82,7 @@ EmulationDialog::EmulationDialog(OSystem& osystem, DialogContainer& parent, _w = 37 * fontWidth + HBORDER * 2 + CheckboxWidget::prefixSize(_font); _h = 13 * (lineHeight + VGAP) + VGAP * 7 + VBORDER * 3 + _th + buttonHeight; - xpos = HBORDER; ypos = VBORDER + _th; + int xpos = HBORDER, ypos = VBORDER + _th; // Speed mySpeed = @@ -170,7 +169,7 @@ EmulationDialog::EmulationDialog(OSystem& osystem, DialogContainer& parent, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EmulationDialog::loadConfig() { - Settings& settings = instance().settings(); + const Settings& settings = instance().settings(); // Emulation speed int speed = mapSpeed(settings.getFloat("speed")); @@ -238,7 +237,7 @@ void EmulationDialog::saveConfig() settings.setValue("confirmexit", myConfirmExitWidget->getState()); // Save on exit - int saveOnExit = mySaveOnExitGroup->getSelected(); + const int saveOnExit = mySaveOnExitGroup->getSelected(); settings.setValue("saveonexit", saveOnExit == 0 ? "none" : saveOnExit == 1 ? "current" : "all"); // Automatically change save state slots diff --git a/src/gui/EventMappingWidget.cxx b/src/gui/EventMappingWidget.cxx index 550e97b4b..38b5e5644 100644 --- a/src/gui/EventMappingWidget.cxx +++ b/src/gui/EventMappingWidget.cxx @@ -47,7 +47,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, VBORDER = boss->dialog().vBorder(), HBORDER = boss->dialog().hBorder(), VGAP = boss->dialog().vGap(); - const int ACTION_LINES = 2; + constexpr int ACTION_LINES = 2; int xpos = HBORDER, ypos = VBORDER; const int listWidth = _w - buttonWidth - HBORDER * 2 - fontWidth; int listHeight = _h - (2 + ACTION_LINES) * lineHeight - VBORDER + 2; @@ -163,7 +163,7 @@ void EventMappingWidget::saveConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventMappingWidget::updateActions() { - myEventGroup = Event::Group(myFilterPopup->getSelectedTag().toInt()); + myEventGroup = static_cast(myFilterPopup->getSelectedTag().toInt()); myEventMode = myEventGroup == Event::Group::Menu ? EventMode::kMenuMode : EventMode::kEmulationMode; @@ -225,7 +225,7 @@ void EventMappingWidget::eraseRemapping() if(myActionSelected < 0) return; - Event::Type event = + const Event::Type event = instance().eventHandler().eventAtIndex(myActionSelected, myEventGroup); instance().eventHandler().eraseMapping(event, myEventMode); @@ -238,7 +238,7 @@ void EventMappingWidget::resetRemapping() if(myActionSelected < 0) return; - Event::Type event = + const Event::Type event = instance().eventHandler().eventAtIndex(myActionSelected, myEventGroup); instance().eventHandler().setDefaultMapping(event, myEventMode); @@ -288,7 +288,7 @@ void EventMappingWidget::enableButtons(bool state) myEraseButton->setEnabled(state); myResetButton->setEnabled(state); - Event::Type e = + const Event::Type e = instance().eventHandler().eventAtIndex(myActionSelected, myEventGroup); myComboButton->setEnabled(state && e >= Event::Combo1 && e <= Event::Combo16); @@ -318,7 +318,7 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod) if (myRemapStatus && myActionSelected >= 0 && (mod & (KBDM_CTRL | KBDM_SHIFT | KBDM_ALT | KBDM_GUI)) == 0) { - Event::Type event = + const Event::Type event = instance().eventHandler().eventAtIndex(myActionSelected, myEventGroup); // if not pressed alone, map left and right modifier keys @@ -359,7 +359,7 @@ void EventMappingWidget::handleJoyUp(int stick, int button) if (myLastStick == stick && myLastButton == button) { EventHandler& eh = instance().eventHandler(); - Event::Type event = eh.eventAtIndex(myActionSelected, myEventGroup); + const Event::Type event = eh.eventAtIndex(myActionSelected, myEventGroup); // map either button/hat, solo button or button/axis combinations if(myLastHat != -1) @@ -395,7 +395,7 @@ void EventMappingWidget::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int else if(myLastStick == stick && axis == myLastAxis && adir == JoyDir::NONE) { EventHandler& eh = instance().eventHandler(); - Event::Type event = eh.eventAtIndex(myActionSelected, myEventGroup); + const Event::Type event = eh.eventAtIndex(myActionSelected, myEventGroup); if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, axis, myLastDir)) stopRemapping(); @@ -426,7 +426,7 @@ bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHatDir hdir, int bu else if(myLastStick == stick && hat == myLastHat && hdir == JoyHatDir::CENTER) { EventHandler& eh = instance().eventHandler(); - Event::Type event = eh.eventAtIndex(myActionSelected, myEventGroup); + const Event::Type event = eh.eventAtIndex(myActionSelected, myEventGroup); if (eh.addJoyHatMapping(event, myEventMode, stick, myLastButton, hat, myLastHatDir)) { diff --git a/src/gui/FavoritesManager.cxx b/src/gui/FavoritesManager.cxx index da5be0660..6ec1ed74d 100644 --- a/src/gui/FavoritesManager.cxx +++ b/src/gui/FavoritesManager.cxx @@ -156,7 +156,7 @@ void FavoritesManager::removeAllUser() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool FavoritesManager::toggleUser(const string& path) { - bool favorize = !existsUser(path); + const bool favorize = !existsUser(path); if(favorize) addUser(path); @@ -188,7 +188,7 @@ const FavoritesManager::UserList& FavoritesManager::userList() const // Sort without path FilesystemNode aNode(a); FilesystemNode bNode(b); - bool realDir = aNode.isDirectory() && !BSPF::endsWithIgnoreCase(aNode.getPath(), ".zip"); + const bool realDir = aNode.isDirectory() && !BSPF::endsWithIgnoreCase(aNode.getPath(), ".zip"); if(realDir != (bNode.isDirectory() && !BSPF::endsWithIgnoreCase(bNode.getPath(), ".zip"))) return realDir; @@ -280,7 +280,7 @@ void FavoritesManager::incPopular(const string& path) static constexpr double factor = 0.7; static constexpr uInt32 max_popular = scale; - auto increased = myPopularMap.find(path); + const auto increased = myPopularMap.find(path); if(increased != myPopularMap.end()) increased->second += scale; else @@ -291,7 +291,7 @@ void FavoritesManager::incPopular(const string& path) PopularList sortedList = sortedPopularList(); // sorted by frequency! for(auto item = sortedList.cbegin(); item != sortedList.cend(); ++item) { - auto entry = myPopularMap.find(item->first); + const auto entry = myPopularMap.find(item->first); if(entry != myPopularMap.end()) { if(entry->second >= scale * (1.0 - factor)) diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index 5bfea5749..449eb13c5 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -66,7 +66,7 @@ void FileListWidget::setDirectory(const FilesystemNode& node, // History is in reverse order; we need to fix that std::reverse(_history.begin(), _history.end()); _currentHistory = std::prev(_history.end(), 1); - _historyHome = int(_currentHistory - _history.begin()); + _historyHome = static_cast(_currentHistory - _history.begin()); // Finally, go to this location setLocation(_node, _selectedFile); @@ -341,7 +341,7 @@ bool FileListWidget::handleText(char text) // Quick selection mode: Go to first list item starting with this key // (or a substring accumulated from the last couple key presses). // Only works in a useful fashion if the list entries are sorted. - uInt64 time = TimerManager::getTicks() / 1000; + const uInt64 time = TimerManager::getTicks() / 1000; if(_quickSelectTime < time) _quickSelectStr = text; @@ -671,7 +671,7 @@ const FileListWidget::Icon* FileListWidget::getIcon(int i) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int FileListWidget::iconWidth() const { - bool smallIcon = _lineHeight < 26; + const bool smallIcon = _lineHeight < 26; return smallIcon ? 16 + 4: 24 + 6; } @@ -690,7 +690,7 @@ string FileListWidget::getToolTip(const Common::Point& pos) const const string value = _list[idx]; - if(uInt32(_font.getStringWidth(value)) > rect.w() - iconWidth()) + if(static_cast(_font.getStringWidth(value)) > rect.w() - iconWidth()) return _toolTipText + value; else return _toolTipText; diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index ccad7c1d8..c1f4fe512 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -100,7 +100,7 @@ class FileListWidget : public StringListWidget /** Gets current node(s) */ const FilesystemNode& selected() { - _selected = BSPF::clamp(_selected, 0U, uInt32(_fileList.size()-1)); + _selected = BSPF::clamp(_selected, 0U, static_cast(_fileList.size()-1)); return _fileList[_selected]; } const FilesystemNode& currentDir() const { return _node; } diff --git a/src/gui/Font.cxx b/src/gui/Font.cxx index 14b085ec3..b2a47f364 100644 --- a/src/gui/Font.cxx +++ b/src/gui/Font.cxx @@ -53,7 +53,7 @@ int Font::getStringWidth(const string& str) const { // If no width table is specified, use the maximum width if(!myFontDesc.width) - return myFontDesc.maxwidth * int(str.size()); + return myFontDesc.maxwidth * static_cast(str.size()); else return std::accumulate(str.cbegin(), str.cend(), 0, [&](int x, char c) { return x + getCharWidth(c); }); diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index e02ec8240..d7748c4f5 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -110,20 +110,19 @@ void GameInfoDialog::addEmulationTab() VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int ypos, pwidth, tabID; WidgetArray wid; VariantList items; - StaticTextWidget* t; + StaticTextWidget* t = nullptr; // 1) Emulation properties - tabID = myTab->addTab("Emulation", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab("Emulation", TabWidget::AUTO_WIDTH); - ypos = VBORDER; + int ypos = VBORDER; t = new StaticTextWidget(myTab, _font, HBORDER, ypos + 1, "Type (*) "); - pwidth = _font.getStringWidth("CM (SpectraVideo CompuMate)"); + int pwidth = _font.getStringWidth("CM (SpectraVideo CompuMate)"); items.clear(); - for(uInt32 i = 0; i < uInt32(Bankswitch::Type::NumSchemes); ++i) + for(uInt32 i = 0; i < static_cast(Bankswitch::Type::NumSchemes); ++i) VarList::push_back(items, Bankswitch::BSList[i].desc, Bankswitch::BSList[i].name); myBSType = new PopUpWidget(myTab, _font, t->getRight() + fontWidth, ypos, pwidth, lineHeight, items); @@ -205,14 +204,14 @@ void GameInfoDialog::addConsoleTab() VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos, lwidth, tabID; WidgetArray wid; // 2) Console properties - tabID = myTab->addTab(" Console ", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab(" Console ", TabWidget::AUTO_WIDTH); - xpos = HBORDER; ypos = VBORDER; - lwidth = _font.getStringWidth(GUI::RIGHT_DIFFICULTY + " "); + const int xpos = HBORDER; + int ypos = VBORDER; + int lwidth = _font.getStringWidth(GUI::RIGHT_DIFFICULTY + " "); new StaticTextWidget(myTab, _font, xpos, ypos + 1, "TV type"); myTVTypeGroup = new RadioButtonGroup(); @@ -263,13 +262,12 @@ void GameInfoDialog::addControllersTab() HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), INDENT = Dialog::indent(); - int xpos, ypos, pwidth, tabID; VariantList items, ctrls; WidgetArray wid; // 3) Controller properties wid.clear(); - tabID = myTab->addTab("Controllers", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab("Controllers", TabWidget::AUTO_WIDTH); items.clear(); VarList::push_back(items, "Auto-detect", "AUTO"); @@ -291,8 +289,8 @@ void GameInfoDialog::addControllersTab() VarList::push_back(items, "MindLink", "MINDLINK"); VarList::push_back(items, "QuadTari", "QUADTARI"); - xpos = HBORDER; ypos = VBORDER; - pwidth = _font.getStringWidth("Paddles_IAxis"); + int xpos = HBORDER, ypos = VBORDER; + int pwidth = _font.getStringWidth("Paddles_IAxis"); myLeftPortLabel = new StaticTextWidget(myTab, _font, HBORDER, ypos+1, "Left port "); myLeftPort = new PopUpWidget(myTab, _font, myLeftPortLabel->getRight(), myLeftPortLabel->getTop()-1, @@ -414,16 +412,16 @@ void GameInfoDialog::addCartridgeTab() HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), HGAP = Dialog::fontWidth() / 4; - int xpos, ypos, lwidth, fwidth, tabID; WidgetArray wid; VariantList items; wid.clear(); - tabID = myTab->addTab("Cartridge", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab("Cartridge", TabWidget::AUTO_WIDTH); - xpos = HBORDER; ypos = VBORDER; - lwidth = _font.getStringWidth("Manufacturer "); - fwidth = _w - lwidth - HBORDER * 2 - 2; + const int xpos = HBORDER; + int ypos = VBORDER; + int lwidth = _font.getStringWidth("Manufacturer "); + const int fwidth = _w - lwidth - HBORDER * 2 - 2; new StaticTextWidget(myTab, _font, xpos, ypos + 1, lwidth, fontHeight, "Name"); myName = new EditTextWidget(myTab, _font, xpos + lwidth, ypos - 1, fwidth, lineHeight, ""); @@ -486,11 +484,10 @@ void GameInfoDialog::addHighScoresTab() HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), INDENT = Dialog::indent(); - int xpos, ypos, lwidth, pwidth, tabID; WidgetArray wid; VariantList items; - tabID = myTab->addTab("High Scores", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab("High Scores", TabWidget::AUTO_WIDTH); EditableWidget::TextFilter fAddr = [](char c) { return (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9'); @@ -503,8 +500,8 @@ void GameInfoDialog::addHighScoresTab() return (c >= 'a' && c <= 'z') || (c >= ' ' && c < ',') || (c > ',' && c < '@'); }; - xpos = HBORDER; ypos = VBORDER; - lwidth = _font.getStringWidth("Variations "); + int xpos = HBORDER, ypos = VBORDER; + int lwidth = _font.getStringWidth("Variations "); myHighScores = new CheckboxWidget(myTab, _font, xpos, ypos + 1, "Enable High Scores", kHiScoresChanged); @@ -516,12 +513,12 @@ void GameInfoDialog::addHighScoresTab() ypos += lineHeight + VGAP;*/ - pwidth = _font.getStringWidth("4"); // popup + int pwidth = _font.getStringWidth("4"); // popup - int awidth = EditTextWidget::calcWidth(_font, 4); // addresses + const int awidth = EditTextWidget::calcWidth(_font, 4); // addresses int vwidth = EditTextWidget::calcWidth(_font, 3); // values - int swidth = EditTextWidget::calcWidth(_font, HSM::MAX_SPECIAL_NAME); // special - int fwidth = EditTextWidget::calcWidth(_font, 3); // variants + const int swidth = EditTextWidget::calcWidth(_font, HSM::MAX_SPECIAL_NAME); // special + const int fwidth = EditTextWidget::calcWidth(_font, 3); // variants myVariationsLabel = new StaticTextWidget(myTab, _font, xpos, ypos + 1, lwidth, fontHeight, "Variations"); @@ -712,7 +709,7 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) if(instance().hasConsole()) { string bs = instance().console().about().BankSwitch; - size_t pos = bs.find_first_of('*'); + const size_t pos = bs.find_first_of('*'); // remove '*': if(pos != string::npos) bs = bs.substr(0, pos) + bs.substr(pos + 1); @@ -741,7 +738,7 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) VarList::push_back(items, "Auto", "AUTO"); if(instance().hasConsole()) { - uInt16 numBanks = instance().console().cartridge().romBankCount(); + const uInt16 numBanks = instance().console().cartridge().romBankCount(); for(uInt16 i = 0; i < numBanks; ++i) VarList::push_back(items, i, i); @@ -772,8 +769,8 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) myFormatDetected->setLabel(""); // if phosphor is always enabled, disable game specific phosphor settings - bool alwaysPhosphor = instance().settings().getString("tv.phosphor") == "always"; - bool usePhosphor = props.get(PropType::Display_Phosphor) == "YES"; + const bool alwaysPhosphor = instance().settings().getString("tv.phosphor") == "always"; + const bool usePhosphor = props.get(PropType::Display_Phosphor) == "YES"; myPhosphor->setState(usePhosphor); myPhosphor->setEnabled(!alwaysPhosphor); if (alwaysPhosphor) @@ -786,7 +783,7 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) myPPBlend->setValue(stringToInt(blend)); // set vertical center - Int32 vcenter = stringToInt(props.get(PropType::Display_VCenter)); + const Int32 vcenter = stringToInt(props.get(PropType::Display_VCenter)); myVCenter->setValueLabel(vcenter); myVCenter->setValue(vcenter); myVCenter->setValueUnit(vcenter ? "px" : ""); @@ -823,7 +820,7 @@ void GameInfoDialog::loadControllerProperties(const Properties& props) istringstream m_axis(props.get(PropType::Controller_MouseAxis)); string m_control, m_range; m_axis >> m_control; - bool autoAxis = equalsIgnoreCase(m_control, "AUTO"); + const bool autoAxis = equalsIgnoreCase(m_control, "AUTO"); myMouseControl->setState(!autoAxis); if(autoAxis) { @@ -867,8 +864,8 @@ void GameInfoDialog::loadCartridgeProperties(const Properties& props) void GameInfoDialog::loadHighScoresProperties(const Properties& props) { HSM::ScoresProps info; - uInt32 numVariations; - bool enable = instance().highScores().get(props, numVariations, info); + uInt32 numVariations = 0; + const bool enable = instance().highScores().get(props, numVariations, info); myHighScores->setState(enable); @@ -922,7 +919,7 @@ void GameInfoDialog::saveProperties() myGameProperties.set(PropType::Display_Phosphor, myPhosphor->getState() ? "YES" : "NO"); myGameProperties.set(PropType::Display_PPBlend, myPPBlend->getValueLabel() == "Off" ? "0" : myPPBlend->getValueLabel()); - Int32 vcenter = myVCenter->getValue(); + const Int32 vcenter = myVCenter->getValue(); myGameProperties.set(PropType::Display_VCenter, to_string(vcenter)); myGameProperties.set(PropType::Cart_Sound, mySound->getState() ? "STEREO" : "MONO"); @@ -1108,7 +1105,7 @@ void GameInfoDialog::setDefaults() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void GameInfoDialog::updateControllerStates() { - bool swapPorts = mySwapPorts->getState(); + const bool swapPorts = mySwapPorts->getState(); bool autoDetect = false; ByteBuffer image; string md5 = myGameProperties.get(PropType::Cart_MD5); @@ -1164,9 +1161,9 @@ void GameInfoDialog::updateControllerStates() bool enableEEEraseButton = false; // Compumate bankswitching scheme doesn't allow to select controllers - bool enableSelectControl = myBSType->getSelectedTag() != "CM"; + const bool enableSelectControl = myBSType->getSelectedTag() != "CM"; // Enable Swap Paddles checkbox only for paddle games - bool enablePaddles = BSPF::startsWithIgnoreCase(contrLeft, "PADDLES") || + const bool enablePaddles = BSPF::startsWithIgnoreCase(contrLeft, "PADDLES") || BSPF::startsWithIgnoreCase(contrRight, "PADDLES") || BSPF::startsWithIgnoreCase(myLeftPortDetected->getLabel(), "Paddles") || BSPF::startsWithIgnoreCase(myRightPortDetected->getLabel(), "Paddles"); @@ -1177,10 +1174,10 @@ void GameInfoDialog::updateControllerStates() const Controller& rport = instance().console().rightController(); // we only enable the button if we have a valid previous and new controller. - bool enableBtnForLeft = + const bool enableBtnForLeft = (contrLeft == "AUTO" || contrLeft == "SAVEKEY" || contrLeft == "ATARIVOX") && (lport.type() == Controller::Type::SaveKey || lport.type() == Controller::Type::AtariVox); - bool enableBtnForRight = + const bool enableBtnForRight = (contrRight == "AUTO" || contrRight == "SAVEKEY" || contrRight == "ATARIVOX") && (rport.type() == Controller::Type::SaveKey || rport.type() == Controller::Type::AtariVox); enableEEEraseButton = enableBtnForLeft || enableBtnForRight; @@ -1208,7 +1205,7 @@ void GameInfoDialog::updateControllerStates() myPaddleXCenter->setEnabled(enablePaddles); myPaddleYCenter->setEnabled(enablePaddles); - bool enableMouse = enablePaddles || + const bool enableMouse = enablePaddles || BSPF::startsWithIgnoreCase(contrLeft, "Driving") || BSPF::startsWithIgnoreCase(contrRight, "Driving") || BSPF::startsWithIgnoreCase(contrLeft, "MindLink") || @@ -1246,7 +1243,7 @@ void GameInfoDialog::eraseEEPROM() void GameInfoDialog::updateLink() { string link = myUrl->getText(); - bool enable = startsWithIgnoreCase(link, "http://") + const bool enable = startsWithIgnoreCase(link, "http://") || startsWithIgnoreCase(link, "https://") || startsWithIgnoreCase(link, "www."); @@ -1256,12 +1253,12 @@ void GameInfoDialog::updateLink() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void GameInfoDialog::updateHighScoresWidgets() { - bool enable = myHighScores->getState(); - bool enableVars = enable && myVariations->getText() > "1"; - bool enableSpecial = enable && !mySpecialName->getText().empty(); - bool enableConsole = instance().hasConsole(); - uInt32 numAddr = instance().highScores().numAddrBytes(myScoreDigits->getSelected() + 1, - myTrailingZeroes->getSelected()); + const bool enable = myHighScores->getState(); + const bool enableVars = enable && myVariations->getText() > "1"; + const bool enableSpecial = enable && !mySpecialName->getText().empty(); + const bool enableConsole = instance().hasConsole(); + const uInt32 numAddr = instance().highScores().numAddrBytes( + myScoreDigits->getSelected() + 1, myTrailingZeroes->getSelected()); // enable widgets //myARMGame->setEnabled(enable); @@ -1317,7 +1314,7 @@ void GameInfoDialog::updateHighScoresWidgets() mySpecialZeroBased->getState()); // update score RAM values and resulting scores - HSM::ScoreAddresses scoreAddr; + HSM::ScoreAddresses scoreAddr{}; for(uInt32 a = 0; a < HSM::MAX_SCORE_ADDR; ++a) { @@ -1331,14 +1328,14 @@ void GameInfoDialog::updateHighScoresWidgets() myScoreAddressVal[a]->setText(""); } - Int32 score = instance().highScores().score(numAddr, myTrailingZeroes->getSelected(), - myScoreBCD->getState(), scoreAddr); + const Int32 score = instance().highScores().score(numAddr, myTrailingZeroes->getSelected(), + myScoreBCD->getState(), scoreAddr); myCurrentScore->setLabel(instance().highScores().formattedScore(score)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void GameInfoDialog::setAddressVal(EditTextWidget* addressWidget, EditTextWidget* valWidget, +void GameInfoDialog::setAddressVal(const EditTextWidget* addressWidget, EditTextWidget* valWidget, bool isBCD, bool zeroBased, uInt8 maxVal) { string strAddr; @@ -1349,20 +1346,18 @@ void GameInfoDialog::setAddressVal(EditTextWidget* addressWidget, EditTextWidget if (instance().hasConsole() && valWidget->isEnabled()) { - uInt16 addr; - uInt8 val; ostringstream ss; // convert to number and read from memory - addr = stringToIntBase16(strAddr, HSM::DEFAULT_ADDRESS); - val = instance().highScores().peek(addr); + const uInt16 addr = stringToIntBase16(strAddr, HSM::DEFAULT_ADDRESS); + uInt8 val = instance().highScores().peek(addr); val = instance().highScores().convert(val, maxVal, isBCD, zeroBased); // format output and display in value widget // if (isBCD) // ss << hex; ss << right // << setw(2) << setfill(' ') - << uppercase << uInt16(val); + << uppercase << static_cast(val); valWidget->setText(ss.str()); } else @@ -1422,11 +1417,11 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd, case kQuadTariPressed: { - bool enableLeft = + const bool enableLeft = BSPF::startsWithIgnoreCase(myLeftPort->getSelectedTag().toString(), "QUADTARI") || BSPF::startsWithIgnoreCase(myLeftPortDetected->getLabel(), "QT") || BSPF::startsWithIgnoreCase(myLeftPortDetected->getLabel(), "QUADTARI"); - bool enableRight = + const bool enableRight = BSPF::startsWithIgnoreCase(myRightPort->getSelectedTag().toString(), "QUADTARI") || BSPF::startsWithIgnoreCase(myRightPortDetected->getLabel(), "QT") || BSPF::startsWithIgnoreCase(myRightPortDetected->getLabel(), "QUADTARI"); @@ -1444,7 +1439,7 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd, case kPhosphorChanged: { - bool status = myPhosphor->getState(); + const bool status = myPhosphor->getState(); myPPBlend->setEnabled(status); break; } @@ -1479,7 +1474,7 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd, case kMCtrlChanged: { - bool state = myMouseControl->getState(); + const bool state = myMouseControl->getState(); myMouseX->setEnabled(state); myMouseY->setEnabled(state); break; diff --git a/src/gui/GameInfoDialog.hxx b/src/gui/GameInfoDialog.hxx index b107ce99a..c04a88168 100644 --- a/src/gui/GameInfoDialog.hxx +++ b/src/gui/GameInfoDialog.hxx @@ -77,7 +77,7 @@ class GameInfoDialog : public Dialog, public CommandSender // update 'High Scores' tab widgets void updateHighScoresWidgets(); // set formatted memory value for given address field - void setAddressVal(EditTextWidget* address, EditTextWidget* val, + void setAddressVal(const EditTextWidget* address, EditTextWidget* val, bool isBCD = true, bool zeroBased = false, uInt8 maxVal = 255); void exportCurrentPropertiesToDisk(const FilesystemNode& node); diff --git a/src/gui/GlobalPropsDialog.cxx b/src/gui/GlobalPropsDialog.cxx index cc89e7dd6..9dfd54549 100644 --- a/src/gui/GlobalPropsDialog.cxx +++ b/src/gui/GlobalPropsDialog.cxx @@ -39,7 +39,6 @@ GlobalPropsDialog::GlobalPropsDialog(GuiObject* boss, const GUI::Font& font) VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; int lwidth = font.getStringWidth("Right difficulty "), pwidth = font.getStringWidth("CM (SpectraVideo CompuMate)"); WidgetArray wid; @@ -51,11 +50,11 @@ GlobalPropsDialog::GlobalPropsDialog(GuiObject* boss, const GUI::Font& font) 49 * infofont.getMaxCharWidth()); _h = _th + 11 * (lineHeight + VGAP) + 3 * infofont.getLineHeight() + VGAP * 12 + buttonHeight + VBORDER * 2; - xpos = HBORDER; ypos = VBORDER + _th; + int xpos = HBORDER, ypos = VBORDER + _th; // Bankswitch type new StaticTextWidget(this, font, xpos, ypos+1, "Bankswitch type"); - for(uInt32 i = 0; i < uInt32(Bankswitch::Type::NumSchemes); ++i) + for(uInt32 i = 0; i < static_cast(Bankswitch::Type::NumSchemes); ++i) VarList::push_back(items, Bankswitch::BSList[i].desc, Bankswitch::BSList[i].name); myBSType = new PopUpWidget(this, font, xpos+lwidth, ypos, pwidth, lineHeight, items, ""); @@ -139,9 +138,9 @@ int GlobalPropsDialog::addHoldWidgets(const GUI::Font& font, int x, int y, WidgetArray& wid) { const int fontWidth = Dialog::fontWidth(), - //fontHeight = Dialog::fontHeight(), VGAP = Dialog::vGap(); - int xpos = x, ypos = y, xdiff = CheckboxWidget::boxSize(font) - 9; + int xpos = x, ypos = y; + const int xdiff = CheckboxWidget::boxSize(font) - 9; // Left joystick StaticTextWidget* t = new StaticTextWidget(this, font, xpos, ypos + 2, "Left joy"); @@ -158,7 +157,7 @@ int GlobalPropsDialog::addHoldWidgets(const GUI::Font& font, int x, int y, ypos += myJoy[kJ0Down]->getHeight() * 2 + VGAP * 2; myJoy[kJ0Fire] = new CheckboxWidget(this, font, xpos, ypos, "Fire", kJ0Fire); - int final_y = ypos; + const int final_y = ypos; xpos = _w / 3; ypos = y; // Right joystick @@ -201,7 +200,7 @@ int GlobalPropsDialog::addHoldWidgets(const GUI::Font& font, int x, int y, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void GlobalPropsDialog::loadConfig() { - Settings& settings = instance().settings(); + const Settings& settings = instance().settings(); myBSType->setSelected(settings.getString("bs"), "AUTO"); myLeftDiff->setSelected(settings.getString("ld"), "DEFAULT"); diff --git a/src/gui/HelpDialog.cxx b/src/gui/HelpDialog.cxx index 645edfc0b..569a0fd6b 100644 --- a/src/gui/HelpDialog.cxx +++ b/src/gui/HelpDialog.cxx @@ -38,7 +38,6 @@ HelpDialog::HelpDialog(OSystem& osystem, DialogContainer& parent, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; WidgetArray wid; // Set real dimensions @@ -46,7 +45,7 @@ HelpDialog::HelpDialog(OSystem& osystem, DialogContainer& parent, _h = _th + 11 * lineHeight + VGAP * 3 + buttonHeight + VBORDER * 2; // Add Previous, Next and Close buttons - xpos = HBORDER; ypos = _h - buttonHeight - VBORDER; + int xpos = HBORDER, ypos = _h - buttonHeight - VBORDER; myPrevButton = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, "<<", GuiObject::kPrevCmd); @@ -79,7 +78,7 @@ HelpDialog::HelpDialog(OSystem& osystem, DialogContainer& parent, "", TextAlign::Center); myTitle->setTextColor(kTextColorEm); - int lwidth = 15 * fontWidth; + const int lwidth = 15 * fontWidth; ypos += lineHeight + VGAP * 2; for(uInt32 i = 0; i < LINES_PER_PAGE; ++i) { @@ -100,19 +99,19 @@ HelpDialog::HelpDialog(OSystem& osystem, DialogContainer& parent, void HelpDialog::updateStrings(uInt8 page, uInt8 lines, string& title) { int i = 0; - auto ADD_BIND = [&](const string& k, const string& d) + const auto ADD_BIND = [&](const string& k, const string& d) { myKeyStr[i] = k; myDescStr[i] = d; i++; }; - auto ADD_EVENT = [&](const Event::Type e, const string & d) + const auto ADD_EVENT = [&](const Event::Type e, const string & d) { string desc = instance().eventHandler().getMappingDesc(e, EventMode::kEmulationMode); if(!desc.length()) desc = instance().eventHandler().getMappingDesc(e, EventMode::kMenuMode); ADD_BIND(desc.length() ? desc : "None", d); }; - auto ADD_TEXT = [&](const string& d) { ADD_BIND("", d); }; - auto ADD_LINE = [&]() { ADD_BIND("", ""); }; + const auto ADD_TEXT = [&](const string& d) { ADD_BIND("", d); }; + const auto ADD_LINE = [&]() { ADD_BIND("", ""); }; setHelpAnchor("Hotkeys"); switch(page) diff --git a/src/gui/HighScoresDialog.cxx b/src/gui/HighScoresDialog.cxx index c129e255b..3debb94b4 100644 --- a/src/gui/HighScoresDialog.cxx +++ b/src/gui/HighScoresDialog.cxx @@ -116,20 +116,20 @@ HighScoresDialog::HighScoresDialog(OSystem& osystem, DialogContainer& parent, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xposRank = HBORDER; + const int xposRank = HBORDER; int xposScore = xposRank + _font.getStringWidth("Rank"); int xposSpecial = xposScore + _font.getStringWidth(" Score "); int xposName = xposSpecial + _font.getStringWidth("Round "); int xposDate = xposName + _font.getStringWidth("Name "); int xposDelete = xposDate + _font.getStringWidth("YY-MM-DD HH:MM "); int nWidth = _font.getStringWidth("ABC") + fontWidth * 0.75; - bool smallFont = _font.getFontHeight() < 24; - int buttonSize = smallFont ? BUTTON_GFX_H : BUTTON_GFX_H_LARGE; - int xpos, ypos; + const bool smallFont = _font.getFontHeight() < 24; + const int buttonSize = smallFont ? BUTTON_GFX_H : BUTTON_GFX_H_LARGE; WidgetArray wid; VariantList items; - ypos = VBORDER + _th; xpos = HBORDER; + const int xpos = HBORDER; + int ypos = VBORDER + _th; ypos += lineHeight + VGAP * 2; // space for game name StaticTextWidget* s = new StaticTextWidget(this, _font, xpos, ypos + 1, "Variation "); @@ -137,7 +137,7 @@ HighScoresDialog::HighScoresDialog(OSystem& osystem, DialogContainer& parent, _font.getStringWidth("256"), lineHeight, items, "", 0, kVariationChanged); wid.push_back(myVariationPopup); - int bWidth = fontWidth * 5; + const int bWidth = fontWidth * 5; myPrevVarButton = new ButtonWidget(this, _font, xposDelete + fontWidth * 2 - bWidth * 2 - BUTTON_GAP, ypos - 1, bWidth, myVariationPopup->getHeight(), smallFont ? PREV_GFX.data() : PREV_GFX_LARGE.data(), @@ -238,7 +238,7 @@ void HighScoresDialog::loadConfig() } myVariationPopup->addItems(items); - Int32 variation; + Int32 variation = 0; if(instance().highScores().numVariations() == 1) variation = HSM::DEFAULT_VARIATION; else @@ -432,19 +432,19 @@ void HighScoresDialog::updateWidgets(bool init) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void HighScoresDialog::handlePlayedVariation() { - Int32 newScore = instance().highScores().score(); + const Int32 newScore = instance().highScores().score(); if (!myHighScoreSaved && newScore > 0) { - Int32 newSpecial = instance().highScores().special(); - bool scoreInvert = instance().highScores().scoreInvert(); + const Int32 newSpecial = instance().highScores().special(); + const bool scoreInvert = instance().highScores().scoreInvert(); for (myHighScoreRank = 0; myHighScoreRank < static_cast(NUM_RANKS); ++myHighScoreRank) { - Int32 highScore = myScores.scores[myHighScoreRank].score; + const Int32 highScore = myScores.scores[myHighScoreRank].score; if ((!scoreInvert && newScore > highScore) || - ((scoreInvert && newScore < highScore) || + ((scoreInvert && newScore < highScore) || highScore == 0)) break; if (newScore == highScore && newSpecial > myScores.scores[myHighScoreRank].special) diff --git a/src/gui/HighScoresMenu.cxx b/src/gui/HighScoresMenu.cxx index a56c8d9e0..ca2d97d8b 100644 --- a/src/gui/HighScoresMenu.cxx +++ b/src/gui/HighScoresMenu.cxx @@ -29,7 +29,7 @@ HighScoresMenu::HighScoresMenu(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HighScoresMenu::~HighScoresMenu() { - delete myHighScoresDialog; myHighScoresDialog = nullptr; + delete myHighScoresDialog; myHighScoresDialog = nullptr; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Icon.hxx b/src/gui/Icon.hxx index 452aef128..090598ba5 100644 --- a/src/gui/Icon.hxx +++ b/src/gui/Icon.hxx @@ -27,7 +27,7 @@ struct IconDesc int width{0}; int height{0}; - explicit IconDesc(int _width, int _height) + explicit constexpr IconDesc(int _width, int _height) : width{_width}, height{_height} { } }; diff --git a/src/gui/Icons.hxx b/src/gui/Icons.hxx index 1942429b0..bab1f21a6 100644 --- a/src/gui/Icons.hxx +++ b/src/gui/Icons.hxx @@ -26,8 +26,8 @@ namespace GUI { /* Exported structure definition. */ -static const IconDesc iconSmallDesc(14, 14); -static const IconDesc iconLargeDesc(19, 20); +static constexpr IconDesc iconSmallDesc(14, 14); +static constexpr IconDesc iconLargeDesc(19, 20); // Settings icon static const Icon icon_settings_small( diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index d1c68415d..49d2046cc 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -51,7 +51,6 @@ InputDialog::InputDialog(OSystem& osystem, DialogContainer& parent, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos, tabID; // Set real dimensions setSize(48 * fontWidth + PopUpWidget::dropDownWidth(_font) + HBORDER * 2, @@ -59,14 +58,15 @@ InputDialog::InputDialog(OSystem& osystem, DialogContainer& parent, max_w, max_h); // The tab widget - xpos = 2; ypos = VGAP + _th; + constexpr int xpos = 2; + const int ypos = VGAP + _th; myTab = new TabWidget(this, _font, xpos, ypos, _w - 2*xpos, _h -_th - VGAP - buttonHeight - VBORDER * 2); addTabWidget(myTab); // 1) Event mapper - tabID = myTab->addTab(" Event Mappings ", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab(" Event Mappings ", TabWidget::AUTO_WIDTH); myEventMapper = new EventMappingWidget(myTab, _font, 2, 2, myTab->getWidth(), myTab->getHeight() - VGAP); @@ -107,14 +107,13 @@ void InputDialog::addDevicePortTab() HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); const int swidth = 13 * fontWidth; - int xpos, ypos, lwidth, tabID; WidgetArray wid; // Devices/ports - tabID = myTab->addTab(" Devices & Ports ", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab(" Devices & Ports ", TabWidget::AUTO_WIDTH); - xpos = HBORDER; ypos = VBORDER; - lwidth = _font.getStringWidth("Digital paddle sensitivity "); + int xpos = HBORDER, ypos = VBORDER; + int lwidth = _font.getStringWidth("Digital paddle sensitivity "); // Add digital dead zone setting myDigitalDeadzone = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, @@ -222,11 +221,9 @@ void InputDialog::addDevicePortTab() "Swap Stelladaptor ports"); wid.push_back(mySAPort); - int fwidth; - // Add EEPROM erase (part 1/2) ypos += VGAP * (3 - 1); - fwidth = _font.getStringWidth("AtariVox/SaveKey"); + int fwidth = _font.getStringWidth("AtariVox/SaveKey"); new StaticTextWidget(myTab, _font, _w - HBORDER - 2 - fwidth, ypos, "AtariVox/SaveKey"); @@ -268,16 +265,15 @@ void InputDialog::addMouseTab() VGAP = Dialog::vGap(), INDENT = Dialog::indent(); const int swidth = 13 * fontWidth; - int xpos = HBORDER, ypos, lwidth, pwidth, tabID; WidgetArray wid; VariantList items; // Mouse - tabID = myTab->addTab(" Mouse ", TabWidget::AUTO_WIDTH); + int tabID = myTab->addTab(" Mouse ", TabWidget::AUTO_WIDTH); - ypos = VBORDER; - lwidth = _font.getStringWidth("Use mouse as a controller "); - pwidth = _font.getStringWidth("-UI, -Emulation"); + int xpos = HBORDER, ypos = VBORDER; + int lwidth = _font.getStringWidth("Use mouse as a controller "); + int pwidth = _font.getStringWidth("-UI, -Emulation"); // Use mouse as controller VarList::push_back(items, "Always", "always"); @@ -352,7 +348,7 @@ void InputDialog::addMouseTab() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::loadConfig() { - Settings& settings = instance().settings(); + const Settings& settings = instance().settings(); // Left & right ports mySAPort->setState(settings.getString("saport") == "rl"); @@ -412,11 +408,12 @@ void InputDialog::loadConfig() // EEPROM erase (only enable in emulation mode and for valid controllers) if(instance().hasConsole()) { - Controller& lport = instance().console().leftController(); - Controller& rport = instance().console().rightController(); + const Controller& lport = instance().console().leftController(); + const Controller& rport = instance().console().rightController(); - myEraseEEPROMButton->setEnabled(lport.type() == Controller::Type::SaveKey || lport.type() == Controller::Type::AtariVox || - rport.type() == Controller::Type::SaveKey || rport.type() == Controller::Type::AtariVox); + myEraseEEPROMButton->setEnabled( + lport.type() == Controller::Type::SaveKey || lport.type() == Controller::Type::AtariVox || + rport.type() == Controller::Type::SaveKey || rport.type() == Controller::Type::AtariVox); } else myEraseEEPROMButton->setEnabled(false); @@ -453,7 +450,7 @@ void InputDialog::saveConfig() settings.setValue("psense", sensitivity); Paddles::setAnalogSensitivity(sensitivity); // Paddle linearity (analog) - int linearity = myPaddleLinearity->getValue(); + const int linearity = myPaddleLinearity->getValue(); settings.setValue("plinear", linearity); Paddles::setAnalogLinearity(linearity); @@ -470,16 +467,16 @@ void InputDialog::saveConfig() Paddles::setDigitalSensitivity(sensitivity); // Autofire mode & rate - bool enabled = myAutoFire->getState(); + const bool enabled = myAutoFire->getState(); settings.setValue("autofire", enabled); Controller::setAutoFire(enabled); - int rate = myAutoFireRate->getValue(); + const int rate = myAutoFireRate->getValue(); settings.setValue("autofirerate", rate); Controller::setAutoFireRate(rate); // Allow all 4 joystick directions - bool allowall4 = myAllowAll4->getState(); + const bool allowall4 = myAllowAll4->getState(); settings.setValue("joyallow4", allowall4); instance().eventHandler().allowAllDirections(allowall4); @@ -518,9 +515,9 @@ void InputDialog::saveConfig() settings.setValue("cursor", cursor); // only allow grab mouse if cursor is hidden in emulation - int state = myCursorState->getSelected(); - bool enableGrab = state != 1 && state != 3; - bool grab = enableGrab ? myGrabMouse->getState() : false; + const int state = myCursorState->getSelected(); + const bool enableGrab = state != 1 && state != 3; + const bool grab = enableGrab ? myGrabMouse->getState() : false; settings.setValue("grabmouse", grab); instance().frameBuffer().enableGrabMouse(grab); @@ -805,7 +802,7 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::updateDejitterAveraging() { - int strength = myDejitterBase->getValue(); + const int strength = myDejitterBase->getValue(); myDejitterBase->setValueLabel(strength ? std::to_string(strength) : "Off"); } @@ -813,7 +810,7 @@ void InputDialog::updateDejitterAveraging() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::updateDejitterReaction() { - int strength = myDejitterDiff->getValue(); + const int strength = myDejitterDiff->getValue(); myDejitterDiff->setValueLabel(strength ? std::to_string(strength) : "Off"); } @@ -821,8 +818,8 @@ void InputDialog::updateDejitterReaction() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::updateAutoFireRate() { - bool enable = myAutoFire->getState(); - int rate = myAutoFireRate->getValue(); + const bool enable = myAutoFire->getState(); + const int rate = myAutoFireRate->getValue(); myAutoFireRate->setEnabled(enable); myAutoFireRate->setValueLabel(rate ? std::to_string(rate) : "Off"); @@ -832,7 +829,7 @@ void InputDialog::updateAutoFireRate() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::handleMouseControlState() { - bool enable = myMouseControl->getSelected() != 2; + const bool enable = myMouseControl->getSelected() != 2; myMPaddleSpeed->setEnabled(enable); myTrackBallSpeed->setEnabled(enable); @@ -841,8 +838,8 @@ void InputDialog::handleMouseControlState() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::handleCursorState() { - int state = myCursorState->getSelected(); - bool enableGrab = state != 1 && state != 3 && myMouseControl->getSelected() != 2; + const int state = myCursorState->getSelected(); + const bool enableGrab = state != 1 && state != 3 && myMouseControl->getSelected() != 2; myGrabMouse->setEnabled(enableGrab); } diff --git a/src/gui/InputTextDialog.cxx b/src/gui/InputTextDialog.cxx index 739452cd5..0cc57915b 100644 --- a/src/gui/InputTextDialog.cxx +++ b/src/gui/InputTextDialog.cxx @@ -72,19 +72,20 @@ void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - uInt32 xpos, ypos, i, lwidth = 0, maxIdx = 0; + uInt32 xpos = 0, lwidth = 0; WidgetArray wid; // Calculate real dimensions _w = HBORDER * 2 + fontWidth * widthChars; - _h = buttonHeight + lineHeight + VGAP + int(labels.size()) * (lineHeight + VGAP) + _th + VBORDER * 2; + _h = buttonHeight + lineHeight + VGAP + static_cast(labels.size()) * (lineHeight + VGAP) + _th + VBORDER * 2; // Determine longest label - for(i = 0; i < labels.size(); ++i) + size_t maxIdx = 0; + for(size_t i = 0; i < labels.size(); ++i) { if(labels[i].length() > lwidth) { - lwidth = int(labels[i].length()); + lwidth = static_cast(labels[i].length()); maxIdx = i; } } @@ -92,8 +93,8 @@ void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont, lwidth = lfont.getStringWidth(labels[maxIdx]); // Create editboxes for all labels - ypos = VBORDER + _th; - for(i = 0; i < labels.size(); ++i) + int ypos = VBORDER + _th; + for(size_t i = 0; i < labels.size(); ++i) { xpos = HBORDER; StaticTextWidget* s = new StaticTextWidget(this, lfont, xpos, ypos + 2, @@ -135,7 +136,7 @@ void InputTextDialog::show() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputTextDialog::show(uInt32 x, uInt32 y, const Common::Rect& bossRect) { - uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); + const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); myXOrig = bossRect.x() + x * scale; myYOrig = bossRect.y() + y * scale; @@ -175,7 +176,7 @@ void InputTextDialog::setMessage(const string& title) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& InputTextDialog::getResult(int idx) { - if(uInt32(idx) < myInput.size()) + if(static_cast(idx) < myInput.size()) return myInput[idx]->getText(); else return EmptyString; @@ -184,28 +185,28 @@ const string& InputTextDialog::getResult(int idx) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputTextDialog::setText(const string& str, int idx) { - if(uInt32(idx) < myInput.size()) + if(static_cast(idx) < myInput.size()) myInput[idx]->setText(str); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputTextDialog::setTextFilter(const EditableWidget::TextFilter& f, int idx) { - if(uInt32(idx) < myInput.size()) + if(static_cast(idx) < myInput.size()) myInput[idx]->setTextFilter(f); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputTextDialog::setToolTip(const string& str, int idx) { - if(uInt32(idx) < myLabel.size()) + if(static_cast(idx) < myLabel.size()) myLabel[idx]->setToolTip(str); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputTextDialog::setFocus(int idx) { - if(uInt32(idx) < myInput.size()) + if(static_cast(idx) < myInput.size()) Dialog::setFocus(getFocusList()[idx]); } diff --git a/src/gui/JoystickDialog.cxx b/src/gui/JoystickDialog.cxx index fea4aab25..d1bfbb30a 100644 --- a/src/gui/JoystickDialog.cxx +++ b/src/gui/JoystickDialog.cxx @@ -29,7 +29,6 @@ JoystickDialog::JoystickDialog(GuiObject* boss, const GUI::Font& font, int max_w, int max_h) : Dialog(boss->instance(), boss->parent(), font, "Controller database", 0, 0, max_w, max_h) { - int xpos, ypos; WidgetArray wid; const int lineHeight = Dialog::lineHeight(), //fontHeight = Dialog::fontHeight(), @@ -39,9 +38,9 @@ JoystickDialog::JoystickDialog(GuiObject* boss, const GUI::Font& font, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(); // Joystick list - xpos = HBORDER; ypos = VBORDER + _th; - int w = _w - 2 * xpos; - int h = _h - buttonHeight - ypos - VBORDER * 2; + int xpos = HBORDER, ypos = VBORDER + _th; + const int w = _w - 2 * xpos; + const int h = _h - buttonHeight - ypos - VBORDER * 2; myJoyList = new StringListWidget(this, font, xpos, ypos, w, h); myJoyList->setEditable(false); wid.push_back(myJoyList); diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 439655918..e4b97a3f3 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -172,7 +172,7 @@ void LauncherDialog::addOptionWidgets(int& ypos) xpos = mySettingsButton->getRight() + LBL_GAP * 2; if(lwFilter) { - StaticTextWidget* s = new StaticTextWidget(this, _font, xpos, ypos, lblFilter); + const StaticTextWidget* s = new StaticTextWidget(this, _font, xpos, ypos, lblFilter); xpos = s->getRight() + LBL_GAP; } @@ -264,7 +264,7 @@ void LauncherDialog::addPathWidgets(int& ypos) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherDialog::addRomWidgets(int& ypos) +void LauncherDialog::addRomWidgets(int ypos) { const bool bottomButtons = instance().settings().getBool("launcherbuttons"); const int fontWidth = Dialog::fontWidth(), @@ -392,7 +392,7 @@ const string& LauncherDialog::selectedRomMD5() myMD5List.clear(); // Lookup MD5, and if not present, cache it - auto iter = myMD5List.find(currentNode().getPath()); + const auto iter = myMD5List.find(currentNode().getPath()); if(iter == myMD5List.end()) myMD5List[currentNode().getPath()] = MD5::hash(currentNode()); @@ -519,7 +519,7 @@ void LauncherDialog::updateUI() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string LauncherDialog::getRomDir() { - Settings& settings = instance().settings(); + const Settings& settings = instance().settings(); const string& tmpromdir = settings.getString("tmpromdir"); return tmpromdir != EmptyString ? tmpromdir : settings.getString("romdir"); @@ -566,14 +566,14 @@ bool LauncherDialog::matchWithWildcards(const string& str, const string& pattern pat.erase(i + 1); // Search for first '*' - size_t pos = pat.find('*'); + const size_t pos = pat.find('*'); if(pos != string::npos) { // '*' found, split pattern into left and right part, search recursively const string leftPat = pat.substr(0, pos); const string rightPat = pat.substr(pos + 1); - size_t posLeft = matchWithJoker(str, leftPat); + const size_t posLeft = matchWithJoker(str, leftPat); if(posLeft != string::npos) return matchWithWildcards(str.substr(pos + posLeft), rightPat); @@ -637,14 +637,14 @@ float LauncherDialog::getRomInfoZoom(int listHeight) const if((_w - (HBORDER * 2 + fontWidth + 30) - zoom * TIAConstants::viewableWidth) / fontWidth < MIN_LAUNCHER_CHARS) { - zoom = float(_w - (HBORDER * 2 + fontWidth + 30) - MIN_LAUNCHER_CHARS * fontWidth) + zoom = static_cast(_w - (HBORDER * 2 + fontWidth + 30) - MIN_LAUNCHER_CHARS * fontWidth) / TIAConstants::viewableWidth; } if((listHeight - 12 - zoom * TIAConstants::viewableHeight) < MIN_ROMINFO_ROWS * smallFont.getLineHeight() + MIN_ROMINFO_LINES * smallFont.getFontHeight()) { - zoom = float(listHeight - 12 - + zoom = static_cast(listHeight - 12 - MIN_ROMINFO_ROWS * smallFont.getLineHeight() - MIN_ROMINFO_LINES * smallFont.getFontHeight()) / TIAConstants::viewableHeight; @@ -654,7 +654,7 @@ float LauncherDialog::getRomInfoZoom(int listHeight) const if((zoom * TIAConstants::viewableWidth) / smallFont.getMaxCharWidth() < MIN_ROMINFO_CHARS + 6) { - zoom = float(MIN_ROMINFO_CHARS * smallFont.getMaxCharWidth() + 6) + zoom = static_cast(MIN_ROMINFO_CHARS * smallFont.getMaxCharWidth() + 6) / TIAConstants::viewableWidth; } } @@ -678,9 +678,9 @@ void LauncherDialog::setRomInfoFont(const Common::Size& area) // only use fonts <= launcher fonts if(Dialog::fontHeight() >= FONTS[i].height) { - if(area.h >= uInt32(MIN_ROMINFO_ROWS * FONTS[i].height + 2 + if(area.h >= static_cast(MIN_ROMINFO_ROWS * FONTS[i].height + 2 + MIN_ROMINFO_LINES * FONTS[i].height) - && area.w >= uInt32(MIN_ROMINFO_CHARS * FONTS[i].maxwidth)) + && area.w >= static_cast(MIN_ROMINFO_CHARS * FONTS[i].maxwidth)) { myROMInfoFont = make_unique(FONTS[i]); return; @@ -889,7 +889,7 @@ void LauncherDialog::handleJoyDown(int stick, int button, bool longPress) void LauncherDialog::handleJoyUp(int stick, int button) { // open power-up options and settings for 2nd and 4th button if not mapped otherwise - Event::Type e = instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); + const Event::Type e = instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); if (button == 1 && (e == Event::UIOK || e == Event::NoType)) openGlobalProps(); diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index 609d1cff7..2b0398ef5 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -124,7 +124,7 @@ class LauncherDialog : public Dialog, CommandSender void updateUI(); void addOptionWidgets(int& ypos); void addPathWidgets(int& ypos); - void addRomWidgets(int& ypos); + void addRomWidgets(int ypos); void addButtonWidgets(int& ypos); string getRomDir(); diff --git a/src/gui/LauncherFileListWidget.cxx b/src/gui/LauncherFileListWidget.cxx index d71ed7239..9401460bb 100644 --- a/src/gui/LauncherFileListWidget.cxx +++ b/src/gui/LauncherFileListWidget.cxx @@ -37,7 +37,7 @@ LauncherFileListWidget::LauncherFileListWidget(GuiObject* boss, const GUI::Font& // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool LauncherFileListWidget::isDirectory(const FilesystemNode& node) const { - bool isDir = node.isDirectory(); + const bool isDir = node.isDirectory(); // Check for virtual directories if(!isDir && !node.exists()) @@ -516,11 +516,11 @@ const FileListWidget::Icon* LauncherFileListWidget::getIcon(int i) const &favrom_large, &favdir_large, &favzip_large, &user_large, &recent_large, &popular_large }; - if(int(_iconTypeList[i]) < int(IconType::numTypes)) + if(int(_iconTypeList[i]) < static_cast(IconType::numTypes)) return FileListWidget::getIcon(i); const bool smallIcon = iconWidth() < 24; - const int iconType = int(_iconTypeList[i]) - int(IconType::numTypes); + const int iconType = int(_iconTypeList[i]) - static_cast(IconType::numTypes); assert(iconType < int(IconType::numLauncherTypes)); diff --git a/src/gui/LauncherFileListWidget.hxx b/src/gui/LauncherFileListWidget.hxx index 68c651638..ca1c4d5b0 100644 --- a/src/gui/LauncherFileListWidget.hxx +++ b/src/gui/LauncherFileListWidget.hxx @@ -78,6 +78,13 @@ class LauncherFileListWidget : public FileListWidget IconType getIconType(const string& path) const override; const Icon* getIcon(int i) const override; bool fullPathToolTip() const override { return myInVirtualDir; } + + private: + // Following constructors and assignment operators not supported + LauncherFileListWidget(const LauncherFileListWidget&) = delete; + LauncherFileListWidget(LauncherFileListWidget&&) = delete; + LauncherFileListWidget& operator=(const LauncherFileListWidget&) = delete; + LauncherFileListWidget& operator=(LauncherFileListWidget&&) = delete; }; #endif diff --git a/src/gui/ListWidget.cxx b/src/gui/ListWidget.cxx index a8e9222f6..476e3e570 100644 --- a/src/gui/ListWidget.cxx +++ b/src/gui/ListWidget.cxx @@ -72,7 +72,7 @@ void ListWidget::setSelected(int item) { setDirty(); - if(item < 0 || item >= int(_list.size())) + if(item < 0 || item >= static_cast(_list.size())) return; if(isEnabled()) @@ -118,7 +118,7 @@ void ListWidget::setSelected(const string& item) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::setHighlighted(int item) { - if(item < -1 || item >= int(_list.size())) + if(item < -1 || item >= static_cast(_list.size())) return; if(isEnabled()) @@ -141,14 +141,14 @@ void ListWidget::setHighlighted(int item) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& ListWidget::getSelectedString() const { - return (_selectedItem >= 0 && _selectedItem < int(_list.size())) + return (_selectedItem >= 0 && _selectedItem < static_cast(_list.size())) ? _list[_selectedItem] : EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::scrollTo(int item) { - int size = int(_list.size()); + const int size = static_cast(_list.size()); if (item >= size) item = size - 1; if (item < 0) @@ -170,7 +170,7 @@ int ListWidget::getWidth() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::recalc() { - int size = int(_list.size()); + const int size = static_cast(_list.size()); if(_currentPos >= size - _rows) { @@ -191,7 +191,7 @@ void ListWidget::recalc() if(_useScrollbar) { - _scrollBar->_numEntries = int(_list.size()); + _scrollBar->_numEntries = static_cast(_list.size()); _scrollBar->_entriesPerPage = _rows; // disable scrollbar if no longer necessary scrollBarRecalc(); @@ -224,7 +224,7 @@ void ListWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) // First check whether the selection changed int newSelectedItem; newSelectedItem = findItem(x, y); - if (newSelectedItem >= int(_list.size())) + if (newSelectedItem >= static_cast(_list.size())) return; if (_selectedItem != newSelectedItem) @@ -314,7 +314,7 @@ void ListWidget::handleJoyDown(int stick, int button, bool longPress) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::handleJoyUp(int stick, int button) { - Event::Type e = _boss->instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); + const Event::Type e = _boss->instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); handleEvent(e); } @@ -326,8 +326,8 @@ bool ListWidget::handleEvent(Event::Type e) return false; bool handled = true; - int oldSelectedItem = _selectedItem; - int size = int(_list.size()); + const int oldSelectedItem = _selectedItem; + const int size = static_cast(_list.size()); switch(e) { @@ -435,14 +435,14 @@ void ListWidget::scrollToCurrent(int item) _currentPos = item - _rows + 1; } - if (_currentPos < 0 || _rows > int(_list.size())) + if (_currentPos < 0 || _rows > static_cast(_list.size())) _currentPos = 0; - else if (_currentPos + _rows > int(_list.size())) - _currentPos = int(_list.size()) - _rows; + else if (_currentPos + _rows > static_cast(_list.size())) + _currentPos = static_cast(_list.size()) - _rows; if(_useScrollbar) { - int oldScrollPos = _scrollBar->_currentPos; + const int oldScrollPos = _scrollBar->_currentPos; _scrollBar->_currentPos = _currentPos; _scrollBar->recalc(); diff --git a/src/gui/LoggerDialog.cxx b/src/gui/LoggerDialog.cxx index eeb894804..82d24f903 100644 --- a/src/gui/LoggerDialog.cxx +++ b/src/gui/LoggerDialog.cxx @@ -44,7 +44,6 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; WidgetArray wid; // Set real dimensions @@ -52,7 +51,7 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent, setSize(4000, 4000, max_w, max_h); // Test listing of the log output - xpos = HBORDER; ypos = VBORDER + _th; + int xpos = HBORDER, ypos = VBORDER + _th; myLogInfo = new StringListWidget(this, uselargefont ? font : instance().frameBuffer().infoFont(), xpos, ypos, _w - 2 * xpos, _h - buttonHeight - ypos - VBORDER - lineHeight - VGAP * 4, false); @@ -105,8 +104,8 @@ void LoggerDialog::loadConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LoggerDialog::saveConfig() { - int loglevel = myLogLevel->getSelectedTag().toInt(); - bool logtoconsole = myLogToConsole->getState(); + const int loglevel = myLogLevel->getSelectedTag().toInt(); + const bool logtoconsole = myLogToConsole->getState(); instance().settings().setValue("loglevel", loglevel); instance().settings().setValue("logtoconsole", logtoconsole); diff --git a/src/gui/MessageBox.cxx b/src/gui/MessageBox.cxx index dd7057d22..1dfb2cff6 100644 --- a/src/gui/MessageBox.cxx +++ b/src/gui/MessageBox.cxx @@ -83,7 +83,6 @@ void MessageBox::addText(const GUI::Font& font, const StringList& text) fontHeight = Dialog::fontHeight(), VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(); - int xpos, ypos; // Set real dimensions int str_w = 0; @@ -92,7 +91,8 @@ void MessageBox::addText(const GUI::Font& font, const StringList& text) _w = std::min(str_w * fontWidth + HBORDER * 2, _w); _h = std::min(uInt32((text.size() + 2) * fontHeight + VBORDER * 2 + _th), uInt32(_h)); - xpos = HBORDER; ypos = VBORDER + _th; + const int xpos = HBORDER; + int ypos = VBORDER + _th; for(const auto& s: text) { new StaticTextWidget(this, font, xpos, ypos, _w - HBORDER * 2, diff --git a/src/gui/MessageMenu.cxx b/src/gui/MessageMenu.cxx index c7d2adc62..7ecec7512 100644 --- a/src/gui/MessageMenu.cxx +++ b/src/gui/MessageMenu.cxx @@ -30,7 +30,7 @@ MessageMenu::MessageMenu(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MessageMenu::~MessageMenu() { - delete myMessageDialog; myMessageDialog = nullptr; + delete myMessageDialog; myMessageDialog = nullptr; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/MinUICommandDialog.cxx b/src/gui/MinUICommandDialog.cxx index 272343947..f911babac 100644 --- a/src/gui/MinUICommandDialog.cxx +++ b/src/gui/MinUICommandDialog.cxx @@ -37,10 +37,10 @@ MinUICommandDialog::MinUICommandDialog(OSystem& osystem, DialogContainer& parent) : Dialog(osystem, parent, osystem.frameBuffer().font(), "Commands") { - const int HBORDER = 10; - const int VBORDER = 10; - const int HGAP = 8; - const int VGAP = 5; + constexpr int HBORDER = 10; + constexpr int VBORDER = 10; + constexpr int HGAP = 8; + constexpr int VGAP = 5; const int buttonWidth = _font.getStringWidth(" Load State 0") + 20, buttonHeight = _font.getLineHeight() + 8, @@ -53,7 +53,7 @@ MinUICommandDialog::MinUICommandDialog(OSystem& osystem, DialogContainer& parent WidgetArray wid; int xoffset = HBORDER, yoffset = VBORDER + _th; - auto ADD_CD_BUTTON = [&](const string& label, int cmd) + const auto ADD_CD_BUTTON = [&](const string& label, int cmd) { ButtonWidget* b = new ButtonWidget(this, _font, xoffset, yoffset, buttonWidth, buttonHeight, label, cmd); @@ -208,7 +208,7 @@ void MinUICommandDialog::handleCommand(CommandSender* sender, int cmd, { event = Event::NextState; stateCmd = true; - int slot = (instance().state().currentSlot() + 1) % 10; + const int slot = (instance().state().currentSlot() + 1) % 10; updateSlot(slot); break; } diff --git a/src/gui/NavigationWidget.cxx b/src/gui/NavigationWidget.cxx index c20333b4f..25b01e0eb 100644 --- a/src/gui/NavigationWidget.cxx +++ b/src/gui/NavigationWidget.cxx @@ -164,7 +164,7 @@ void NavigationWidget::PathWidget::setPath(const string& path) while(node.hasParent() && w >= fontWidth * 1) { const string& name = node.getName(); - int l = int(name.length() + 2); + int l = static_cast(name.length() + 2); if(name.back() == FilesystemNode::PATH_SEPARATOR) l--; @@ -195,7 +195,7 @@ void NavigationWidget::PathWidget::setPath(const string& path) if(it + 1 != paths.rend()) name += " >"; } - const int width = int(name.length() + 1) * fontWidth; + const int width = static_cast(name.length() + 1) * fontWidth; if(myFolderList.size() > idx) { @@ -209,7 +209,7 @@ void NavigationWidget::PathWidget::setPath(const string& path) // Add new widget to list FolderLinkWidget* s = new FolderLinkWidget(_boss, _font, x, _y, width, _h, name, curPath); - s->setID(uInt32(idx)); + s->setID(static_cast(idx)); s->setTarget(myTarget); myFolderList.push_back(s); _boss->addFocusWidget(s); diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index 8a488ed07..967e1bafc 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -77,7 +77,7 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, _h += rowHeight + VGAP * 2; } - auto ADD_OD_BUTTON = [&](const string& label, int cmd) + const auto ADD_OD_BUTTON = [&](const string& label, int cmd) { ButtonWidget* bw = new ButtonWidget(this, _font, xoffset, yoffset, buttonWidth, buttonHeight, label, cmd); diff --git a/src/gui/PlusRomsMenu.cxx b/src/gui/PlusRomsMenu.cxx index 8131782a9..0f906741b 100644 --- a/src/gui/PlusRomsMenu.cxx +++ b/src/gui/PlusRomsMenu.cxx @@ -30,7 +30,7 @@ PlusRomsMenu::PlusRomsMenu(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PlusRomsMenu::~PlusRomsMenu() { - delete myPlusRomsSetupDialog; myPlusRomsSetupDialog = nullptr; + delete myPlusRomsSetupDialog; myPlusRomsSetupDialog = nullptr; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/PlusRomsSetupDialog.cxx b/src/gui/PlusRomsSetupDialog.cxx index 438212d56..401a1988f 100644 --- a/src/gui/PlusRomsSetupDialog.cxx +++ b/src/gui/PlusRomsSetupDialog.cxx @@ -20,7 +20,7 @@ #include "PlusRomsSetupDialog.hxx" -static const int MAX_NICK_LEN = 16; +static constexpr int MAX_NICK_LEN = 16; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent, diff --git a/src/gui/PopUpWidget.cxx b/src/gui/PopUpWidget.cxx index f0b2c7240..0fbe6def2 100644 --- a/src/gui/PopUpWidget.cxx +++ b/src/gui/PopUpWidget.cxx @@ -258,7 +258,7 @@ void PopUpWidget::drawWidget(bool hilite) { FBSurface& s = dialog().surface(); - int x = _x + _labelWidth; + const int x = _x + _labelWidth; int w = _w - _labelWidth; // Draw the label, if any @@ -272,7 +272,7 @@ void PopUpWidget::drawWidget(bool hilite) s.frameRect(x + w - (_arrowWidth * 2 - 1), _y, (_arrowWidth * 2 - 1), _h, kWidColorHi); // Fill the background - ColorId bgCol = isEditable() ? kWidColor : kDlgColor; + const ColorId bgCol = isEditable() ? kWidColor : kDlgColor; s.fillRect(x + 1, _y + 1, w - (_arrowWidth * 2 - 1), _h - 2, _changed ? kDbgChangedColor : bgCol); s.fillRect(x + w - (_arrowWidth * 2 - 2), _y + 1, (_arrowWidth * 2 - 3), _h - 2, @@ -283,11 +283,11 @@ void PopUpWidget::drawWidget(bool hilite) // Draw the selected entry, if any const string& name = editString(); - bool editable = isEditable(); + const bool editable = isEditable(); w -= dropDownWidth(_font); - TextAlign align = (_font.getStringWidth(name) > w && !editable) ? - TextAlign::Right : TextAlign::Left; + const TextAlign align = (_font.getStringWidth(name) > w && !editable) ? + TextAlign::Right : TextAlign::Left; adjustOffset(); s.drawString(_font, name, x + _textOfs, _y + myTextY, w, !isEnabled() ? kColor : _changed ? kDbgChangedTextColor : kTextColor, diff --git a/src/gui/ProgressDialog.cxx b/src/gui/ProgressDialog.cxx index a2df44f0f..acd2cd6d9 100644 --- a/src/gui/ProgressDialog.cxx +++ b/src/gui/ProgressDialog.cxx @@ -39,14 +39,14 @@ ProgressDialog::ProgressDialog(GuiObject* boss, const GUI::Font& font, HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); const int lwidth = font.getStringWidth(message); - int xpos, ypos; WidgetArray wid; // Calculate real dimensions _w = HBORDER * 2 + std::max(lwidth, buttonWidth); _h = VBORDER * 2 + lineHeight * 2 + buttonHeight + VGAP * 6; - xpos = HBORDER; ypos = VBORDER; + const int xpos = HBORDER; + int ypos = VBORDER; myMessage = new StaticTextWidget(this, font, xpos, ypos, lwidth, fontHeight, message, TextAlign::Center); myMessage->setTextColor(kTextColorEm); @@ -87,7 +87,7 @@ void ProgressDialog::setRange(int start, int finish, int step) { myStart = start; myFinish = finish; - myStep = int((step / 100.0) * (myFinish - myStart + 1)); + myStep = static_cast((step / 100.0) * (myFinish - myStart + 1)); mySlider->setMinValue(myStart + myStep); mySlider->setMaxValue(myFinish); diff --git a/src/gui/QuadTariDialog.cxx b/src/gui/QuadTariDialog.cxx index 19501b5a7..2106db62e 100644 --- a/src/gui/QuadTariDialog.cxx +++ b/src/gui/QuadTariDialog.cxx @@ -35,11 +35,10 @@ QuadTariDialog::QuadTariDialog(GuiObject* boss, const GUI::Font& font, int max_w VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; WidgetArray wid; VariantList ctrls; - xpos = HBORDER; ypos = VBORDER + _th; + int xpos = HBORDER, ypos = VBORDER + _th; ctrls.clear(); //VarList::push_back(ctrls, "Auto-detect", "AUTO"); diff --git a/src/gui/R77HelpDialog.cxx b/src/gui/R77HelpDialog.cxx index 559dc0a37..6b5f1c723 100644 --- a/src/gui/R77HelpDialog.cxx +++ b/src/gui/R77HelpDialog.cxx @@ -35,7 +35,6 @@ R77HelpDialog::R77HelpDialog(OSystem& osystem, DialogContainer& parent, BUTTON_GAP = Dialog::buttonGap(), VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(); - int xpos, ypos; WidgetArray wid; // Set real dimensions @@ -43,7 +42,7 @@ R77HelpDialog::R77HelpDialog(OSystem& osystem, DialogContainer& parent, _h = (LINES_PER_PAGE + 2) * lineHeight + VBORDER * 2 + _th; // Add Previous, Next and Close buttons - xpos = HBORDER; ypos = _h - buttonHeight - VBORDER; + int xpos = HBORDER, ypos = _h - buttonHeight - VBORDER; myPrevButton = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, "Previous", GuiObject::kPrevCmd); @@ -101,8 +100,8 @@ void R77HelpDialog::updateStrings(uInt8 page, uInt8 lines, string& title) { myJoyStr[i] = j; myBtnStr[i] = b; myDescStr[i] = d; i++; }; - auto ADD_TEXT = [&](const string & d) { ADD_BIND("", d.substr(0, 11), d.substr(11, 40)); }; - auto ADD_LINE = [&]() { ADD_BIND("-----------", "-----------", "------------------------"); }; + const auto ADD_TEXT = [&](const string & d) { ADD_BIND("", d.substr(0, 11), d.substr(11, 40)); }; + const auto ADD_LINE = [&]() { ADD_BIND("-----------", "-----------", "------------------------"); }; switch (page) { diff --git a/src/gui/RadioButtonWidget.cxx b/src/gui/RadioButtonWidget.cxx index 9c6199f95..cf9e0f0a2 100644 --- a/src/gui/RadioButtonWidget.cxx +++ b/src/gui/RadioButtonWidget.cxx @@ -333,7 +333,7 @@ void RadioButtonGroup::addWidget(RadioButtonWidget* widget) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void RadioButtonGroup::select(RadioButtonWidget* widget) +void RadioButtonGroup::select(const RadioButtonWidget* widget) { uInt32 i = 0; diff --git a/src/gui/RadioButtonWidget.hxx b/src/gui/RadioButtonWidget.hxx index e4e00fe6f..b003746eb 100644 --- a/src/gui/RadioButtonWidget.hxx +++ b/src/gui/RadioButtonWidget.hxx @@ -66,7 +66,7 @@ class RadioButtonGroup // add widget to group void addWidget(RadioButtonWidget* widget); // tell the group which widget was selected - void select(RadioButtonWidget* widget); + void select(const RadioButtonWidget* widget); void setSelected(uInt32 selected); uInt32 getSelected() { return mySelected; } diff --git a/src/gui/RomAuditDialog.cxx b/src/gui/RomAuditDialog.cxx index af7e09b65..ec1aed9df 100644 --- a/src/gui/RomAuditDialog.cxx +++ b/src/gui/RomAuditDialog.cxx @@ -48,7 +48,8 @@ RomAuditDialog::RomAuditDialog(OSystem& osystem, DialogContainer& parent, HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); const int lwidth = font.getStringWidth("ROMs without properties (skipped) "); - int xpos, ypos = _th + VBORDER; + const int xpos = HBORDER + buttonWidth + fontWidth; + int ypos = _th + VBORDER; WidgetArray wid; // Set real dimensions @@ -60,7 +61,6 @@ RomAuditDialog::RomAuditDialog(OSystem& osystem, DialogContainer& parent, new ButtonWidget(this, font, HBORDER, ypos, buttonWidth, buttonHeight, "Audit path" + ELLIPSIS, kChooseAuditDirCmd); wid.push_back(romButton); - xpos = HBORDER + buttonWidth + fontWidth; myRomPath = new EditTextWidget(this, font, xpos, ypos + (buttonHeight - lineHeight) / 2 - 1, _w - xpos - HBORDER, lineHeight); wid.push_back(myRomPath); @@ -124,7 +124,7 @@ void RomAuditDialog::auditRoms() buf << "Auditing ROM files" << ELLIPSIS; progress.setMessage(buf.str()); - progress.setRange(0, int(files.size()) - 1, 5); + progress.setRange(0, static_cast(files.size()) - 1, 5); progress.open(); Properties props; diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index dbe131d60..25e673a58 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -143,13 +143,13 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) myRomInfo.push_back("Rarity: " + value); if((value = myProperties.get(PropType::Cart_Note)) != EmptyString) myRomInfo.push_back("Note: " + value); - bool swappedPorts = myProperties.get(PropType::Console_SwapPorts) == "YES"; + const bool swappedPorts = myProperties.get(PropType::Console_SwapPorts) == "YES"; // Load the image for controller and bankswitch type auto detection string left = myProperties.get(PropType::Controller_Left); string right = myProperties.get(PropType::Controller_Right); - Controller::Type leftType = Controller::getType(left); - Controller::Type rightType = Controller::getType(right); + const Controller::Type leftType = Controller::getType(left); + const Controller::Type rightType = Controller::getType(right); string bsDetected = myProperties.get(PropType::Cart_Type); bool isPlusCart = false; size_t size = 0; @@ -194,7 +194,7 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) if(size < 1_KB) buf << size << "B"; else - buf << (std::round(size / float(1_KB))) << "K"; + buf << (std::round(size / static_cast(1_KB))) << "K"; } myRomInfo.push_back("Type: " + Bankswitch::typeToDesc(Bankswitch::nameToType(bsDetected)) + (isPlusCart ? " - PlusROM" : "") @@ -215,7 +215,7 @@ bool RomInfoWidget::loadPng(const string& filename) const Common::Rect& src = mySurface->srcRect(); const float scale = std::min(float(myAvail.w) / src.w(), float(myAvail.h) / src.h()) * instance().frameBuffer().hidpiScaleFactor(); - mySurface->setDstSize(uInt32(src.w() * scale), uInt32(src.h() * scale)); + mySurface->setDstSize(static_cast(src.w() * scale), static_cast(src.h() * scale)); return true; } @@ -276,7 +276,7 @@ void RomInfoWidget::drawWidget(bool hilite) int ypos = _y + yoff + 5; for(const auto& info : myRomInfo) { - if(info.length() * _font.getMaxCharWidth() <= uInt64(_w - 16)) + if(info.length() * _font.getMaxCharWidth() <= static_cast(_w - 16)) { // 1 line for next entry @@ -290,7 +290,7 @@ void RomInfoWidget::drawWidget(bool hilite) break; } - int lines; + int lines = 0; if(BSPF::startsWithIgnoreCase(info, "Name: ") && myUrl != EmptyString) { diff --git a/src/gui/ScrollBarWidget.cxx b/src/gui/ScrollBarWidget.cxx index 1991b3850..c9e5a2162 100644 --- a/src/gui/ScrollBarWidget.cxx +++ b/src/gui/ScrollBarWidget.cxx @@ -116,7 +116,7 @@ void ScrollBarWidget::handleMouseDown(int x, int y, MouseButton b, if(_draggingPart == Part::Slider) return; - int old_pos = _currentPos; + const int old_pos = _currentPos; // Do nothing if there are less items than fit on one page if(_numEntries <= _entriesPerPage) @@ -162,7 +162,7 @@ void ScrollBarWidget::handleMouseUp(int x, int y, MouseButton b, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ScrollBarWidget::handleMouseWheel(int x, int y, int direction) { - int old_pos = _currentPos; + const int old_pos = _currentPos; if(_numEntries < _entriesPerPage) return; @@ -185,7 +185,7 @@ void ScrollBarWidget::handleMouseMoved(int x, int y) if(_draggingPart == Part::Slider) { - int old_pos = _currentPos; + const int old_pos = _currentPos; _sliderPos = y - _sliderDeltaMouseDownPos; if(_sliderPos < _upDownBoxHeight) @@ -200,7 +200,7 @@ void ScrollBarWidget::handleMouseMoved(int x, int y) } else { - Part old_part = _part; + const Part old_part = _part; if(y <= _upDownBoxHeight) // Up arrow _part = Part::UpArrow; @@ -252,8 +252,8 @@ void ScrollBarWidget::handleMouseLeft() void ScrollBarWidget::recalc() { //cerr << "ScrollBarWidget::recalc()\n"; - int oldSliderHeight = _sliderHeight, - oldSliderPos = _sliderPos; + const int oldSliderHeight = _sliderHeight, + oldSliderPos = _sliderPos; if(_numEntries > _entriesPerPage) { @@ -280,8 +280,8 @@ void ScrollBarWidget::recalc() void ScrollBarWidget::drawWidget(bool hilite) { FBSurface& s = _boss->dialog().surface(); - int bottomY = _y + _h; - bool isSinglePage = (_numEntries <= _entriesPerPage); + const int bottomY = _y + _h; + const bool isSinglePage = (_numEntries <= _entriesPerPage); s.frameRect(_x, _y, _w, _h, hilite ? kWidColorHi : kColor); diff --git a/src/gui/SnapshotDialog.cxx b/src/gui/SnapshotDialog.cxx index f72dcf5ba..47d5fd3d2 100644 --- a/src/gui/SnapshotDialog.cxx +++ b/src/gui/SnapshotDialog.cxx @@ -38,18 +38,16 @@ SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent, HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), INDENT = Dialog::indent(); - int xpos, ypos, fwidth; WidgetArray wid; - ButtonWidget* b; // Set real dimensions setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + VGAP) + VBORDER + _th, max_w, max_h); - xpos = HBORDER; ypos = VBORDER + _th; + int xpos = HBORDER, ypos = VBORDER + _th; // Snapshot path (save files) - b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, - "Save path" + ELLIPSIS, kChooseSnapSaveDirCmd); + ButtonWidget* b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, + "Save path" + ELLIPSIS, kChooseSnapSaveDirCmd); wid.push_back(b); xpos += buttonWidth + fontWidth; mySnapSavePath = new EditTextWidget(this, font, xpos, ypos + (buttonHeight - lineHeight) / 2 - 1, @@ -69,7 +67,7 @@ SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent, wid.push_back(mySnapInterval); // Booleans for saving snapshots - fwidth = font.getStringWidth("When saving snapshots:"); + int fwidth = font.getStringWidth("When saving snapshots:"); xpos = HBORDER; ypos += lineHeight + VGAP * 3; new StaticTextWidget(this, font, xpos, ypos, fwidth, lineHeight, "When saving snapshots:", TextAlign::Left); diff --git a/src/gui/StellaSettingsDialog.cxx b/src/gui/StellaSettingsDialog.cxx index 5cac690fc..d9de40db6 100644 --- a/src/gui/StellaSettingsDialog.cxx +++ b/src/gui/StellaSettingsDialog.cxx @@ -43,7 +43,6 @@ StellaSettingsDialog::StellaSettingsDialog(OSystem& osystem, DialogContainer& pa HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), INDENT = Dialog::indent(); - int xpos, ypos; ButtonWidget* bw = nullptr; WidgetArray wid; @@ -54,8 +53,8 @@ StellaSettingsDialog::StellaSettingsDialog(OSystem& osystem, DialogContainer& pa VBORDER * 2 +_th + 10 * (lineHeight + VGAP) + 3 * (iLineHeight + VGAP) + VGAP * 12 + buttonHeight * 2, max_w, max_h); - xpos = HBORDER; - ypos = VBORDER + _th; + int xpos = HBORDER; + int ypos = VBORDER + _th; bw = new ButtonWidget(this, _font, xpos, ypos, _w - HBORDER * 2 - buttonWidth - 8, buttonHeight, "Use Advanced Settings" + ELLIPSIS, kAdvancedSettings); @@ -94,7 +93,7 @@ StellaSettingsDialog::~StellaSettingsDialog() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void StellaSettingsDialog::addUIOptions(WidgetArray& wid, int& xpos, int& ypos) +void StellaSettingsDialog::addUIOptions(WidgetArray& wid, int xpos, int& ypos) { const int lineHeight = Dialog::lineHeight(), VGAP = Dialog::vGap(); @@ -123,7 +122,7 @@ void StellaSettingsDialog::addUIOptions(WidgetArray& wid, int& xpos, int& ypos) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void StellaSettingsDialog::addVideoOptions(WidgetArray& wid, int& xpos, int& ypos) +void StellaSettingsDialog::addVideoOptions(WidgetArray& wid, int xpos, int& ypos) { const int lineHeight = Dialog::lineHeight(), fontWidth = Dialog::fontWidth(), @@ -132,7 +131,7 @@ void StellaSettingsDialog::addVideoOptions(WidgetArray& wid, int& xpos, int& ypo VariantList items; // TV effects options - int swidth = _font.getMaxCharWidth() * 11; + const int swidth = _font.getMaxCharWidth() * 11; // TV Mode VarList::push_back(items, "Disabled", static_cast(NTSCFilter::Preset::OFF)); @@ -177,7 +176,7 @@ void StellaSettingsDialog::addVideoOptions(WidgetArray& wid, int& xpos, int& ypo } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void StellaSettingsDialog::addGameOptions(WidgetArray& wid, int& xpos, int& ypos) +void StellaSettingsDialog::addGameOptions(WidgetArray& wid, int xpos, int& ypos) { const int lineHeight = Dialog::lineHeight(), VGAP = Dialog::vGap(); @@ -562,7 +561,7 @@ void StellaSettingsDialog::updateControllerStates() myRightPortDetected->setLabel(label); // Compumate bankswitching scheme doesn't allow to select controllers - bool enableSelectControl = myGameProperties.get(PropType::Cart_Type) != "CM"; + const bool enableSelectControl = myGameProperties.get(PropType::Cart_Type) != "CM"; myLeftPortLabel->setEnabled(enableSelectControl); myRightPortLabel->setEnabled(enableSelectControl); diff --git a/src/gui/StellaSettingsDialog.hxx b/src/gui/StellaSettingsDialog.hxx index 412b07194..2b768ffcb 100644 --- a/src/gui/StellaSettingsDialog.hxx +++ b/src/gui/StellaSettingsDialog.hxx @@ -47,9 +47,9 @@ class StellaSettingsDialog : public Dialog void saveConfig() override; void setDefaults() override; - void addVideoOptions(WidgetArray& wid, int& xpos, int& ypos); - void addUIOptions(WidgetArray& wid, int& xpos, int& ypos); - void addGameOptions(WidgetArray& wid, int& xpos, int& ypos); + void addVideoOptions(WidgetArray& wid, int xpos, int& ypos); + void addUIOptions(WidgetArray& wid, int xpos, int& ypos); + void addGameOptions(WidgetArray& wid, int xpos, int& ypos); void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleOverscanChange(); diff --git a/src/gui/StringListWidget.cxx b/src/gui/StringListWidget.cxx index f0612d5de..e3855bb1b 100644 --- a/src/gui/StringListWidget.cxx +++ b/src/gui/StringListWidget.cxx @@ -52,9 +52,9 @@ void StringListWidget::setList(const StringList& list) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int StringListWidget::getToolTipIndex(const Common::Point& pos) const { - int idx = (pos.y - getAbsY()) / _lineHeight + _currentPos; + const int idx = (pos.y - getAbsY()) / _lineHeight + _currentPos; - if(idx >= int(_list.size())) + if(idx >= static_cast(_list.size())) return -1; else return idx; @@ -63,15 +63,15 @@ int StringListWidget::getToolTipIndex(const Common::Point& pos) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string StringListWidget::getToolTip(const Common::Point& pos) const { - Common::Rect rect = getEditRect(); - int idx = getToolTipIndex(pos); + const Common::Rect& rect = getEditRect(); + const int idx = getToolTipIndex(pos); if(idx < 0) return EmptyString; const string value = _list[idx]; - if(uInt32(_font.getStringWidth(value)) > rect.w()) + if(static_cast(_font.getStringWidth(value)) > rect.w()) return _toolTipText + value; else return _toolTipText; @@ -89,7 +89,6 @@ bool StringListWidget::changedToolTip(const Common::Point& oldPos, void StringListWidget::drawWidget(bool hilite) { FBSurface& s = _boss->dialog().surface(); - int i, pos, len = int(_list.size()); // Draw a thin frame around the list. s.frameRect(_x, _y, _w + 1, _h, hilite && _hilite ? kWidColorHi : kColor); @@ -98,7 +97,8 @@ void StringListWidget::drawWidget(bool hilite) s.fillRect(_x + 1, _y + 1, _w - 1, _h - 2, kDlgColor); // Draw the list items - for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++) + const int len = static_cast(_list.size()); + for (int i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++) { const int y = _y + 2 + _lineHeight * i; int iw = 0; @@ -117,7 +117,7 @@ void StringListWidget::drawWidget(bool hilite) } iw = drawIcon(pos, _x, y - 1, textColor); - Common::Rect r(getEditRect()); + const Common::Rect r(getEditRect()); if (_selectedItem == pos && _editMode) { adjustOffset(); diff --git a/src/gui/TabWidget.cxx b/src/gui/TabWidget.cxx index e752fc4f2..47dd2d89b 100644 --- a/src/gui/TabWidget.cxx +++ b/src/gui/TabWidget.cxx @@ -63,17 +63,17 @@ int TabWidget::getChildY() const int TabWidget::addTab(const string& title, int tabWidth) { // Add a new tab page - int newWidth = _font.getStringWidth(title) + 2 * kTabPadding; + const int newWidth = _font.getStringWidth(title) + 2 * kTabPadding; if(tabWidth == AUTO_WIDTH) _tabs.push_back(Tab(title, newWidth)); else _tabs.push_back(Tab(title, tabWidth)); - int numTabs = int(_tabs.size()); + const int numTabs = static_cast(_tabs.size()); // Determine the new tab width int fixedWidth = 0, fixedTabs = 0; - for(int i = 0; i < int(_tabs.size()); ++i) + for(int i = 0; i < static_cast(_tabs.size()); ++i) { if(_tabs[i].tabWidth != NO_WIDTH) { @@ -88,7 +88,7 @@ int TabWidget::addTab(const string& title, int tabWidth) if(numTabs - fixedTabs) { - int maxWidth = (_w - kTabLeftOffset - fixedWidth) / (numTabs - fixedTabs) - kTabLeftOffset; + const int maxWidth = (_w - kTabLeftOffset - fixedWidth) / (numTabs - fixedTabs) - kTabLeftOffset; if(_tabWidth > maxWidth) _tabWidth = maxWidth; } @@ -165,12 +165,12 @@ void TabWidget::cycleTab(int direction) { tabID--; if(tabID == -1) - tabID = int(_tabs.size()) - 1; + tabID = static_cast(_tabs.size()) - 1; } else if(direction == 1) // Go to the next tab, wrap around at end { tabID++; - if(tabID == int(_tabs.size())) + if(tabID == static_cast(_tabs.size())) tabID = 0; } @@ -182,7 +182,7 @@ void TabWidget::cycleTab(int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TabWidget::setParentWidget(int tabID, Widget* parent) { - assert(0 <= tabID && tabID < int(_tabs.size())); + assert(0 <= tabID && tabID < static_cast(_tabs.size())); _tabs[tabID].parentWidget = parent; } @@ -210,9 +210,9 @@ void TabWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) int tabID = -1; x -= kTabLeftOffset; - for(int i = 0; i < int(_tabs.size()); ++i) + for(int i = 0; i < static_cast(_tabs.size()); ++i) { - int tabWidth = _tabs[i].tabWidth ? _tabs[i].tabWidth : _tabWidth; + const int tabWidth = _tabs[i].tabWidth ? _tabs[i].tabWidth : _tabWidth; if(x >= 0 && x < tabWidth) { tabID = i; @@ -283,12 +283,12 @@ void TabWidget::drawWidget(bool hilite) FBSurface& s = dialog().surface(); // Iterate over all tabs and draw them - int i, x = _x + kTabLeftOffset; - for(i = 0; i < int(_tabs.size()); ++i) + int x = _x + kTabLeftOffset; + for(int i = 0; i < static_cast(_tabs.size()); ++i) { - int tabWidth = _tabs[i].tabWidth ? _tabs[i].tabWidth : _tabWidth; - ColorId fontcolor = _tabs[i].enabled ? kTextColor : kColor; - int yOffset = (i == _activeTab) ? 0 : 1; + const int tabWidth = _tabs[i].tabWidth ? _tabs[i].tabWidth : _tabWidth; + const ColorId fontcolor = _tabs[i].enabled ? kTextColor : kColor; + const int yOffset = (i == _activeTab) ? 0 : 1; s.fillRect(x, _y + 1, tabWidth, _tabHeight - 1, (i == _activeTab) ? kDlgColor : kBGColorHi); // ? kWidColor : kDlgColor diff --git a/src/gui/TimeLineWidget.cxx b/src/gui/TimeLineWidget.cxx index eca510ec9..740ba524e 100644 --- a/src/gui/TimeLineWidget.cxx +++ b/src/gui/TimeLineWidget.cxx @@ -25,8 +25,8 @@ #include "TimeLineWidget.hxx" -const int HANDLE_W = 3; -const int HANDLE_H = 3; // size above/below the slider +static constexpr int HANDLE_W = 3; +static constexpr int HANDLE_H = 3; // size above/below the slider // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TimeLineWidget::TimeLineWidget(GuiObject* boss, const GUI::Font& font, @@ -86,7 +86,7 @@ void TimeLineWidget::setStepValues(const IntArray& steps) if(steps.size() > _stepValue.capacity()) _stepValue.reserve(2 * steps.size()); - double scale = (_w - _labelWidth - 2 - HANDLE_W) / double(steps.back()); + const double scale = (_w - _labelWidth - 2 - HANDLE_W) / static_cast(steps.back()); // Skip the very last value; we take care of it outside the end of the loop for(uInt32 i = 0; i < steps.size() - 1; ++i) @@ -149,10 +149,10 @@ void TimeLineWidget::drawWidget(bool hilite) isEnabled() ? kTextColor : kColor, TextAlign::Left); // Frame the handle - const int HANDLE_W2 = (HANDLE_W + 1) / 2; - int p = valueToPos(_value), - x = _x + _labelWidth + HANDLE_W2, - w = _w - _labelWidth - HANDLE_W; + constexpr int HANDLE_W2 = (HANDLE_W + 1) / 2; + const int p = valueToPos(_value), + x = _x + _labelWidth + HANDLE_W2, + w = _w - _labelWidth - HANDLE_W; s.hLine(x + p - HANDLE_W2, _y + 0, x + p - HANDLE_W2 + HANDLE_W, kColorInfo); s.vLine(x + p - HANDLE_W2, _y + 1, _y + _h - 2, kColorInfo); s.hLine(x + p - HANDLE_W2 + 1, _y + _h - 1, x + p - HANDLE_W2 + 1 + HANDLE_W, kBGColor); @@ -171,13 +171,13 @@ void TimeLineWidget::drawWidget(bool hilite) !isEnabled() ? kColor : hilite ? kSliderColorHi : kSliderColor); // Add 4 tickmarks for 5 intervals - int numTicks = std::min(5, int(_stepValue.size())); + const int numTicks = std::min(5, static_cast(_stepValue.size())); for(int i = 1; i < numTicks; ++i) { - int idx = int((_stepValue.size() * i + numTicks / 2) / numTicks); + const int idx = static_cast((_stepValue.size() * i + numTicks / 2) / numTicks); if(idx > 1) { - int xt = x + valueToPos(idx - 1); + const int xt = x + valueToPos(idx - 1); ColorId color = kNone; if(isEnabled()) diff --git a/src/gui/TimeMachine.cxx b/src/gui/TimeMachine.cxx index 0e13274bb..604e5539f 100644 --- a/src/gui/TimeMachine.cxx +++ b/src/gui/TimeMachine.cxx @@ -45,7 +45,7 @@ void TimeMachine::requestResize() { myWidth = w; Dialog* oldPtr = myBaseDialog; - Int32 enterWinds = static_cast(myBaseDialog)->getEnterWinds(); + const Int32 enterWinds = static_cast(myBaseDialog)->getEnterWinds(); delete myBaseDialog; myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth); setEnterWinds(enterWinds); diff --git a/src/gui/TimeMachineDialog.cxx b/src/gui/TimeMachineDialog.cxx index f069ad9ae..cb486384e 100644 --- a/src/gui/TimeMachineDialog.cxx +++ b/src/gui/TimeMachineDialog.cxx @@ -205,12 +205,9 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent, : Dialog(osystem, parent) { const GUI::Font& font = instance().frameBuffer().font(); - const int H_BORDER = 6, BUTTON_GAP = 4, V_BORDER = 4; - const int buttonWidth = BUTTON_W + 10, - buttonHeight = BUTTON_H + 10, - rowHeight = font.getLineHeight(); - - int xpos, ypos; + constexpr int H_BORDER = 6, BUTTON_GAP = 4, V_BORDER = 4; + constexpr int buttonWidth = BUTTON_W + 10, buttonHeight = BUTTON_H + 10; + const int rowHeight = font.getLineHeight(); // Set real dimensions _w = width; // Parent determines our width (based on window size) @@ -220,8 +217,7 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent, this->clearFlags(Widget::FLAG_BORDER); this->setFlags(Widget::FLAG_NOBG); - xpos = H_BORDER; - ypos = V_BORDER; + int xpos = H_BORDER, ypos = V_BORDER; // Add index info myCurrentIdxWidget = new StaticTextWidget(this, font, xpos, ypos, "1000", TextAlign::Left, kBGColor); @@ -242,7 +238,7 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent, ypos += rowHeight; // Add time info - int ypos_s = ypos + (buttonHeight - font.getFontHeight() + 1) / 2; // align to button vertical center + const int ypos_s = ypos + (buttonHeight - font.getFontHeight() + 1) / 2; // align to button vertical center myCurrentTimeWidget = new StaticTextWidget(this, font, xpos, ypos_s, "00:00.00", TextAlign::Left, kBGColor); myCurrentTimeWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG); myCurrentTimeWidget->setTextColor(kColorInfo); @@ -295,7 +291,7 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent, xpos = myLoadAllWidget->getRight() + BUTTON_GAP * 4; // Add message - int mWidth = (myLastTimeWidget->getLeft() - xpos) / font.getMaxCharWidth(); + const int mWidth = (myLastTimeWidget->getLeft() - xpos) / font.getMaxCharWidth(); const string blanks = " "; myMessageWidget = new StaticTextWidget(this, font, xpos, ypos_s, @@ -332,7 +328,7 @@ void TimeMachineDialog::loadConfig() void TimeMachineDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated) { // The following shortcuts duplicate the shortcuts in EventHandler - Event::Type event = instance().eventHandler().eventForKey(EventMode::kEmulationMode, key, mod); + const Event::Type event = instance().eventHandler().eventForKey(EventMode::kEmulationMode, key, mod); switch(event) { @@ -395,7 +391,7 @@ void TimeMachineDialog::handleKeyUp(StellaKey key, StellaMod mod) // The following shortcuts duplicate the shortcuts in EventHandler // Note: mode switches must happen in key UP - Event::Type event = instance().eventHandler().eventForKey(EventMode::kEmulationMode, key, mod); + const Event::Type event = instance().eventHandler().eventForKey(EventMode::kEmulationMode, key, mod); if(event == Event::TogglePlayBackMode || key == KBDK_SPACE) handleCommand(nullptr, kPlayBack, 0, 0); @@ -411,7 +407,7 @@ void TimeMachineDialog::handleCommand(CommandSender* sender, int cmd, { case kTimeline: { - Int32 winds = myTimeline->getValue() - + const Int32 winds = myTimeline->getValue() - instance().state().rewindManager().getCurrentIdx() + 1; handleWinds(winds); break; @@ -468,7 +464,7 @@ void TimeMachineDialog::handleCommand(CommandSender* sender, int cmd, case Event::PreviousState: case Event::NextState: case Event::LoadState: - instance().eventHandler().handleEvent(Event::Type(cmd)); + instance().eventHandler().handleEvent(static_cast(cmd)); break; case Event::TakeSnapshot: @@ -488,7 +484,7 @@ void TimeMachineDialog::initBar() IntArray cycles = r.cyclesList(); // Set range and intervals for timeline - uInt32 maxValue = cycles.size() > 1 ? uInt32(cycles.size() - 1) : 0; + const uInt32 maxValue = cycles.size() > 1 ? static_cast(cycles.size() - 1) : 0; myTimeline->setMaxValue(maxValue); myTimeline->setStepValues(cycles); @@ -504,15 +500,15 @@ string TimeMachineDialog::getTimeString(uInt64 cycles) const { const Int32 scanlines = std::max(instance().console().tia().scanlinesLastFrame(), 240); const bool isNTSC = scanlines <= 287; - const Int32 NTSC_FREQ = 1193182; // ~76*262*60 - const Int32 PAL_FREQ = 1182298; // ~76*312*50 + constexpr Int32 NTSC_FREQ = 1193182; // ~76*262*60 + constexpr Int32 PAL_FREQ = 1182298; // ~76*312*50 const Int32 freq = isNTSC ? NTSC_FREQ : PAL_FREQ; // = cycles/second - uInt32 minutes = uInt32(cycles / (freq * 60)); + const uInt32 minutes = static_cast(cycles / (freq * 60)); cycles -= minutes * (freq * 60); - uInt32 seconds = uInt32(cycles / freq); + const uInt32 seconds = static_cast(cycles / freq); cycles -= seconds * freq; - uInt32 frames = uInt32(cycles / (scanlines * 76)); + const uInt32 frames = static_cast(cycles / (scanlines * 76)); stringstream time; time << Common::Base::toString(minutes, Common::Base::Fmt::_10_02) << ":"; @@ -529,11 +525,11 @@ void TimeMachineDialog::handleWinds(Int32 numWinds) if(numWinds) { - uInt64 startCycles = r.getCurrentCycles(); + const uInt64 startCycles = r.getCurrentCycles(); if(numWinds < 0) r.rewindStates(-numWinds); else if(numWinds > 0) r.unwindStates(numWinds); - uInt64 elapsed = instance().console().tia().cycles() - startCycles; + const uInt64 elapsed = instance().console().tia().cycles() - startCycles; if(elapsed > 0) { string message = r.getUnitString(elapsed); diff --git a/src/gui/ToolTip.cxx b/src/gui/ToolTip.cxx index 2c9f11526..80479afe0 100644 --- a/src/gui/ToolTip.cxx +++ b/src/gui/ToolTip.cxx @@ -143,13 +143,14 @@ void ToolTip::show(const string& tip) { myTipPos = myMousePos; - uInt32 maxWidth = std::min(myWidth - myTextXOfs * 2, uInt32(myFont->getStringWidth(tip))); + const uInt32 maxWidth = std::min(myWidth - myTextXOfs * 2, + static_cast(myFont->getStringWidth(tip))); surface()->fillRect(1, 1, maxWidth + myTextXOfs * 2 - 2, myHeight - 2, kWidColor); - int lines = std::min(MAX_ROWS, - uInt32(surface()->drawString(*myFont, tip, myTextXOfs, myTextYOfs, - maxWidth, myHeight - myTextYOfs * 2, - kTextColor))); + const int lines = std::min(MAX_ROWS, + static_cast(surface()->drawString(*myFont, tip, myTextXOfs, myTextYOfs, + maxWidth, myHeight - myTextYOfs * 2, + kTextColor))); // Calculate maximum width of drawn string lines uInt32 width = 0; string inStr = tip; @@ -165,11 +166,11 @@ void ToolTip::show(const string& tip) // Calculate and set surface size and position const uInt32 height = std::min(myHeight, myFont->getFontHeight() * lines + myTextYOfs * 2); - const uInt32 V_GAP = 1; - const uInt32 H_CURSOR = 18; + constexpr uInt32 V_GAP = 1; + constexpr uInt32 H_CURSOR = 18; // Note: The rects include HiDPI scaling - const Common::Rect imageRect = myDialog.instance().frameBuffer().imageRect(); - const Common::Rect dialogRect = myDialog.surface().dstRect(); + const Common::Rect& imageRect = myDialog.instance().frameBuffer().imageRect(); + const Common::Rect& dialogRect = myDialog.surface().dstRect(); // Limit position to app size and adjust accordingly const Int32 xAbs = myTipPos.x + dialogRect.x() / myScale; const uInt32 yAbs = myTipPos.y + dialogRect.y() / myScale; diff --git a/src/gui/ToolTip.hxx b/src/gui/ToolTip.hxx index 0b2b3b78f..d8d10c64f 100644 --- a/src/gui/ToolTip.hxx +++ b/src/gui/ToolTip.hxx @@ -101,6 +101,13 @@ class ToolTip bool myTipShown{false}; uInt32 myScale{1}; shared_ptr mySurface; + + private: + // Following constructors and assignment operators not supported + ToolTip(const ToolTip&) = delete; + ToolTip(ToolTip&&) = delete; + ToolTip& operator=(const ToolTip&) = delete; + ToolTip& operator=(ToolTip&&) = delete; }; #endif diff --git a/src/gui/UIDialog.cxx b/src/gui/UIDialog.cxx index e9ed72da4..83896f8b0 100644 --- a/src/gui/UIDialog.cxx +++ b/src/gui/UIDialog.cxx @@ -53,8 +53,6 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), INDENT = Dialog::indent(); - int xpos, ypos, tabID; - int lwidth, pwidth, bwidth; WidgetArray wid; VariantList items; const Common::Size& ds = instance().frameBuffer().desktopSize(BufferType::Launcher); @@ -73,10 +71,10 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, ////////////////////////////////////////////////////////// // 1) Misc. options wid.clear(); - tabID = myTab->addTab(" Look & Feel "); - lwidth = font.getStringWidth("Controller repeat delay "); - pwidth = font.getStringWidth("Right bottom"); - xpos = HBORDER; ypos = VBORDER; + int tabID = myTab->addTab(" Look & Feel "); + int lwidth = font.getStringWidth("Controller repeat delay "); + int pwidth = font.getStringWidth("Right bottom"); + int xpos = HBORDER, ypos = VBORDER; // UI Palette ypos += 1; @@ -131,7 +129,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, // Delay between quick-selecting characters in ListWidget xpos = HBORDER; ypos += lineHeight + VGAP * 4; - int swidth = myPalettePopup->getWidth() - lwidth; + const int swidth = myPalettePopup->getWidth() - lwidth; myListDelaySlider = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight, "List input delay ", 0, kListDelay, font.getStringWidth("1 second")); @@ -206,7 +204,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, xpos = HBORDER; ypos = VBORDER; // ROM path - bwidth = font.getStringWidth("ROM path" + ELLIPSIS) + 20 + 1; + int bwidth = font.getStringWidth("ROM path" + ELLIPSIS) + 20 + 1; ButtonWidget* romButton = new ButtonWidget(myTab, font, xpos, ypos, bwidth, buttonHeight, "ROM path" + ELLIPSIS, kChooseRomDirCmd); @@ -379,8 +377,8 @@ void UIDialog::loadConfig() myLauncherButtonsWidget->setState(settings.getBool("launcherbuttons")); // ROM launcher info viewer - float zoom = instance().settings().getFloat("romviewer"); - int percentage = zoom * TIAConstants::viewableWidth * 100 / w; + const float zoom = instance().settings().getFloat("romviewer"); + const int percentage = zoom * TIAConstants::viewableWidth * 100 / w; myRomViewerSize->setValue(percentage); // ROM launcher info viewer image path @@ -469,8 +467,8 @@ void UIDialog::saveConfig() settings.setValue("launcherbuttons", myLauncherButtonsWidget->getState()); // ROM launcher info viewer - int w = myLauncherWidthSlider->getValue(); - float zoom = myRomViewerSize->getValue() * w / 100.F / TIAConstants::viewableWidth; + const int w = myLauncherWidthSlider->getValue(); + const float zoom = myRomViewerSize->getValue() * w / 100.F / TIAConstants::viewableWidth; settings.setValue("romviewer", zoom); // ROM launcher info viewer image path @@ -546,8 +544,8 @@ void UIDialog::setDefaults() const Common::Size& size = instance().frameBuffer().desktopSize(BufferType::Launcher); myRomPath->setText(node.getShortPath()); - uInt32 w = std::min(size.w, 900); - uInt32 h = std::min(size.h, 600); + const uInt32 w = std::min(size.w, 900); + const uInt32 h = std::min(size.h, 600); myLauncherWidthSlider->setValue(w); myLauncherHeightSlider->setValue(h); myLauncherFontPopup->setSelected("medium", ""); @@ -665,9 +663,9 @@ void UIDialog::handleLauncherSize() { // Determine minimal launcher sizebased on the default font // So what fits with default font should fit for any font. - FontDesc fd = instance().frameBuffer().getFontDesc(myDialogFontPopup->getSelectedTag().toString()); - int w = std::max(FBMinimum::Width, FBMinimum::Width * fd.maxwidth / GUI::stellaMediumDesc.maxwidth); - int h = std::max(FBMinimum::Height, FBMinimum::Height * fd.height / GUI::stellaMediumDesc.height); + const FontDesc fd = instance().frameBuffer().getFontDesc(myDialogFontPopup->getSelectedTag().toString()); + const int w = std::max(FBMinimum::Width, FBMinimum::Width * fd.maxwidth / GUI::stellaMediumDesc.maxwidth); + const int h = std::max(FBMinimum::Height, FBMinimum::Height * fd.height / GUI::stellaMediumDesc.height); const Common::Size& ds = instance().frameBuffer().desktopSize(BufferType::Launcher); myLauncherWidthSlider->setMinValue(w); @@ -727,8 +725,8 @@ void UIDialog::handleLauncherSize() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void UIDialog::handleRomViewer() { - int size = myRomViewerSize->getValue(); - bool enable = size > myRomViewerSize->getMinValue(); + const int size = myRomViewerSize->getValue(); + const bool enable = size > myRomViewerSize->getMinValue(); if(enable) { diff --git a/src/gui/UndoHandler.cxx b/src/gui/UndoHandler.cxx index 6db91c612..19226610d 100644 --- a/src/gui/UndoHandler.cxx +++ b/src/gui/UndoHandler.cxx @@ -93,7 +93,7 @@ bool UndoHandler::redo(string& text) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 UndoHandler::lastDiff(const string& text, const string& oldText) const { - uInt32 pos = uInt32(text.size()); + uInt32 pos = static_cast(text.size()); for(auto itn = text.crbegin(), ito = oldText.crbegin(); itn != text.crend() && ito != oldText.crend(); ++itn, ++ito) @@ -102,5 +102,5 @@ uInt32 UndoHandler::lastDiff(const string& text, const string& oldText) const break; pos--; } - return uInt32(pos); + return static_cast(pos); } diff --git a/src/gui/VideoAudioDialog.cxx b/src/gui/VideoAudioDialog.cxx index 4f31a5f33..d215bf76e 100644 --- a/src/gui/VideoAudioDialog.cxx +++ b/src/gui/VideoAudioDialog.cxx @@ -62,7 +62,6 @@ VideoAudioDialog::VideoAudioDialog(OSystem& osystem, DialogContainer& parent, VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); - int xpos, ypos; // Set real dimensions setSize(44 * fontWidth + HBORDER * 2 + PopUpWidget::dropDownWidth(font) * 2, @@ -70,7 +69,8 @@ VideoAudioDialog::VideoAudioDialog(OSystem& osystem, DialogContainer& parent, max_w, max_h); // The tab widget - xpos = 2; ypos = VGAP; + constexpr int xpos = 2; + const int ypos = VGAP; myTab = new TabWidget(this, font, xpos, ypos + _th, _w - 2*xpos, _h - _th - VGAP - buttonHeight - VBORDER * 2); @@ -112,8 +112,8 @@ void VideoAudioDialog::addDisplayTab() const int INDENT = CheckboxWidget::prefixSize(_font); const int lwidth = _font.getStringWidth("V-Size adjust "), pwidth = _font.getStringWidth("OpenGLES2"); - int xpos = HBORDER, - ypos = VBORDER; + const int xpos = HBORDER; + int ypos = VBORDER; WidgetArray wid; VariantList items; const int tabID = myTab->addTab(" Display ", TabWidget::AUTO_WIDTH); @@ -427,14 +427,12 @@ void VideoAudioDialog::addAudioTab() HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); const int INDENT = CheckboxWidget::prefixSize(_font); - int xpos, ypos; - int lwidth = _font.getStringWidth("Volume "), - pwidth; + int lwidth = _font.getStringWidth("Volume "), pwidth = 0; WidgetArray wid; VariantList items; const int tabID = myTab->addTab(" Audio ", TabWidget::AUTO_WIDTH); - xpos = HBORDER; ypos = VBORDER; + int xpos = HBORDER, ypos = VBORDER; // Enable sound mySoundEnableCheckbox = new CheckboxWidget(myTab, _font, xpos, ypos, @@ -552,7 +550,7 @@ void VideoAudioDialog::addAudioTab() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VideoAudioDialog::loadConfig() { - Settings& settings = instance().settings(); + const Settings& settings = instance().settings(); // Display tab // Renderer settings @@ -565,8 +563,8 @@ void VideoAudioDialog::loadConfig() // TIA zoom levels // These are dynamically loaded, since they depend on the size of // the desktop and which renderer we're using - float minZoom = instance().frameBuffer().supportedTIAMinZoom(); // or 2 if we allow lower values - float maxZoom = instance().frameBuffer().supportedTIAMaxZoom(); + const float minZoom = instance().frameBuffer().supportedTIAMinZoom(); // or 2 if we allow lower values + const float maxZoom = instance().frameBuffer().supportedTIAMaxZoom(); myTIAZoom->setMinValue(minZoom * 100); myTIAZoom->setMaxValue(maxZoom * 100); @@ -598,7 +596,7 @@ void VideoAudioDialog::loadConfig() myTIAPalette->setSelected(myPalette, PaletteHandler::SETTING_STANDARD); // Palette adjustables - bool isPAL = instance().hasConsole() + const bool isPAL = instance().hasConsole() && instance().console().timing() == ConsoleTiming::pal; instance().frameBuffer().tiaSurface().paletteHandler().getAdjustables(myPaletteAdj); @@ -641,7 +639,7 @@ void VideoAudioDialog::loadConfig() myTVMode->setSelected( settings.getString("tv.filter"), "0"); int preset = settings.getInt("tv.filter"); - handleTVModeChange(NTSCFilter::Preset(preset)); + handleTVModeChange(static_cast(preset)); // TV Custom adjustables loadTVAdjustables(NTSCFilter::Preset::CUSTOM); @@ -670,8 +668,8 @@ void VideoAudioDialog::loadConfig() myVolumeSlider->setValue(audioSettings.volume()); // Device - uInt32 deviceId = BSPF::clamp(audioSettings.device(), 0U, - uInt32(instance().sound().supportedDevices().size() - 1)); + const uInt32 deviceId = BSPF::clamp(audioSettings.device(), 0U, + static_cast(instance().sound().supportedDevices().size() - 1)); myDevicePopup->setSelected(deviceId); // Stereo @@ -820,7 +818,7 @@ void VideoAudioDialog::saveConfig() cart.setDpcPitch(myDpcPitch->getValue()); } - AudioSettings::Preset preset = static_cast(myModePopup->getSelectedTag().toInt()); + const AudioSettings::Preset preset = static_cast(myModePopup->getSelectedTag().toInt()); audioSettings.setPreset(preset); if (preset == AudioSettings::Preset::custom) { @@ -864,7 +862,7 @@ void VideoAudioDialog::setDefaults() case 1: // Palettes { - bool isPAL = instance().hasConsole() + const bool isPAL = instance().hasConsole() && instance().console().timing() == ConsoleTiming::pal; myTIAPalette->setSelected(PaletteHandler::SETTING_STANDARD); @@ -913,7 +911,7 @@ void VideoAudioDialog::setDefaults() myDpcPitch->setValue(AudioSettings::DEFAULT_DPC_PITCH); myModePopup->setSelected(static_cast(AudioSettings::DEFAULT_PRESET)); - if (AudioSettings::DEFAULT_PRESET == AudioSettings::Preset::custom) { + if constexpr(AudioSettings::DEFAULT_PRESET == AudioSettings::Preset::custom) { myResamplingPopup->setSelected(static_cast(AudioSettings::DEFAULT_RESAMPLING_QUALITY)); myFragsizePopup->setSelected(AudioSettings::DEFAULT_FRAGMENT_SIZE); myFreqPopup->setSelected(AudioSettings::DEFAULT_SAMPLE_RATE); @@ -924,13 +922,16 @@ void VideoAudioDialog::setDefaults() updateEnabledState(); break; + + default: // satisfy compiler + break; } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VideoAudioDialog::handleTVModeChange(NTSCFilter::Preset preset) { - bool enable = preset == NTSCFilter::Preset::CUSTOM; + const bool enable = preset == NTSCFilter::Preset::CUSTOM; myTVSharp->setEnabled(enable); myTVRes->setEnabled(enable); @@ -960,14 +961,14 @@ void VideoAudioDialog::loadTVAdjustables(NTSCFilter::Preset preset) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VideoAudioDialog::handleRendererChanged() { - bool enable = myRenderer->getSelectedTag().toString() != "software"; + const bool enable = myRenderer->getSelectedTag().toString() != "software"; myTIAInterpolate->setEnabled(enable); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VideoAudioDialog::handlePaletteChange() { - bool enable = myTIAPalette->getSelectedTag().toString() == "custom"; + const bool enable = myTIAPalette->getSelectedTag().toString() == "custom"; myPhaseShift->setEnabled(enable); myTVRedScale->setEnabled(enable); @@ -997,7 +998,7 @@ void VideoAudioDialog::handlePaletteUpdate() myTIAPalette->getSelectedTag().toString()); // Palette adjustables PaletteHandler::Adjustable paletteAdj; - bool isPAL = instance().hasConsole() + const bool isPAL = instance().hasConsole() && instance().console().timing() == ConsoleTiming::pal; if(isPAL) @@ -1039,7 +1040,7 @@ void VideoAudioDialog::handlePaletteUpdate() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VideoAudioDialog::handleFullScreenChange() { - bool enable = myFullscreen->getState(); + const bool enable = myFullscreen->getState(); myUseStretch->setEnabled(enable); #ifdef ADAPTABLE_REFRESH_SUPPORT myRefreshAdapt->setEnabled(enable); @@ -1118,7 +1119,7 @@ void VideoAudioDialog::handleCommand(CommandSender* sender, int cmd, case kVSizeChanged: { - int adjust = myVSizeAdjust->getValue(); + const int adjust = myVSizeAdjust->getValue(); if (!adjust) { @@ -1138,7 +1139,7 @@ void VideoAudioDialog::handleCommand(CommandSender* sender, int cmd, break; case kTVModeChanged: - handleTVModeChange(NTSCFilter::Preset(myTVMode->getSelectedTag().toInt())); + handleTVModeChange(static_cast(myTVMode->getSelectedTag().toInt())); break; case kCloneCompositeCmd: loadTVAdjustables(NTSCFilter::Preset::COMPOSITE); @@ -1217,8 +1218,8 @@ void VideoAudioDialog::addPalette(int x, int y, int w, int h) constexpr int NUM_CHROMA = 16; const GUI::Font& ifont = instance().frameBuffer().infoFont(); const int lwidth = ifont.getMaxCharWidth() * 1.5; - const float COLW = float(w - lwidth) / NUM_LUMA; - const float COLH = float(h) / NUM_CHROMA; + const float COLW = static_cast(w - lwidth) / NUM_LUMA; + const float COLH = static_cast(h) / NUM_CHROMA; const int yofs = (COLH - ifont.getFontHeight() + 1) / 2; for(int idx = 0; idx < NUM_CHROMA; ++idx) @@ -1269,9 +1270,9 @@ void VideoAudioDialog::colorPalette() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VideoAudioDialog::updateEnabledState() { - bool active = mySoundEnableCheckbox->getState(); - AudioSettings::Preset preset = static_cast(myModePopup->getSelectedTag().toInt()); - bool userMode = preset == AudioSettings::Preset::custom; + const bool active = mySoundEnableCheckbox->getState(); + const AudioSettings::Preset preset = static_cast(myModePopup->getSelectedTag().toInt()); + const bool userMode = preset == AudioSettings::Preset::custom; myVolumeSlider->setEnabled(active); myDevicePopup->setEnabled(active); @@ -1290,7 +1291,7 @@ void VideoAudioDialog::updateEnabledState() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VideoAudioDialog::updatePreset() { - AudioSettings::Preset preset = static_cast(myModePopup->getSelectedTag().toInt()); + const AudioSettings::Preset preset = static_cast(myModePopup->getSelectedTag().toInt()); // Make a copy that does not affect the actual settings... AudioSettings audioSettings = instance().audioSettings(); diff --git a/src/gui/WhatsNewDialog.cxx b/src/gui/WhatsNewDialog.cxx index e51f9c7bc..34056b3bf 100644 --- a/src/gui/WhatsNewDialog.cxx +++ b/src/gui/WhatsNewDialog.cxx @@ -21,7 +21,7 @@ #include "WhatsNewDialog.hxx" -constexpr int MAX_CHARS = 64; // maximum number of chars per line +static constexpr int MAX_CHARS = 64; // maximum number of chars per line // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WhatsNewDialog::WhatsNewDialog(OSystem& osystem, DialogContainer& parent, diff --git a/src/gui/WhatsNewDialog.hxx b/src/gui/WhatsNewDialog.hxx index be0eb765f..ad25a4567 100644 --- a/src/gui/WhatsNewDialog.hxx +++ b/src/gui/WhatsNewDialog.hxx @@ -29,6 +29,13 @@ class WhatsNewDialog : public Dialog private: void add(int& ypos, const string& text); + + private: + // Following constructors and assignment operators not supported + WhatsNewDialog(const WhatsNewDialog&) = delete; + WhatsNewDialog(WhatsNewDialog&&) = delete; + WhatsNewDialog& operator=(const WhatsNewDialog&) = delete; + WhatsNewDialog& operator=(WhatsNewDialog&&) = delete; }; #endif diff --git a/src/gui/Widget.cxx b/src/gui/Widget.cxx index e16e8e381..9c2119e78 100644 --- a/src/gui/Widget.cxx +++ b/src/gui/Widget.cxx @@ -105,7 +105,7 @@ void Widget::draw() #endif FBSurface& s = _boss->dialog().surface(); - int oldX = _x, oldY = _y; + const int oldX = _x, oldY = _y; // Account for our relative position in the dialog _x = getAbsX(); @@ -336,7 +336,7 @@ Widget* Widget::findWidgetInChain(Widget* w, int x, int y) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Widget::isWidgetInChain(Widget* w, Widget* find) +bool Widget::isWidgetInChain(Widget* w, const Widget* find) { while(w) { @@ -354,13 +354,14 @@ bool Widget::isWidgetInChain(const WidgetArray& list, Widget* find) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr, - Widget* wid, int direction, +Widget* Widget::setFocusForChain(const GuiObject* boss, WidgetArray& arr, + const Widget* wid, int direction, bool emitFocusEvents) { FBSurface& s = boss->dialog().surface(); - int size = int(arr.size()), pos = -1; - Widget* tmp; + const int size = static_cast(arr.size()); + int pos = -1; + Widget* tmp = nullptr; for(int i = 0; i < size; ++i) { @@ -374,8 +375,8 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr, // Note: we must use getXXX() methods and not access the variables // directly, since in some cases (notably those widgets with embedded // ScrollBars) the two quantities may be different - int x = tmp->getAbsX() - 1, y = tmp->getAbsY() - 1, - w = tmp->getWidth() + 2, h = tmp->getHeight() + 2; + const int x = tmp->getAbsX() - 1, y = tmp->getAbsY() - 1, + w = tmp->getWidth() + 2, h = tmp->getHeight() + 2; // First clear area surrounding all widgets if(tmp->_hasFocus) @@ -394,7 +395,7 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr, return nullptr; else { - int oldPos = pos; + const int oldPos = pos; do { switch(direction) @@ -428,8 +429,8 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr, // Note: we must use getXXX() methods and not access the variables // directly, since in some cases (notably those widgets with embedded // ScrollBars) the two quantities may be different - int x = tmp->getAbsX() - 1, y = tmp->getAbsY() - 1, - w = tmp->getWidth() + 2, h = tmp->getHeight() + 2; + const int x = tmp->getAbsX() - 1, y = tmp->getAbsY() - 1, + w = tmp->getWidth() + 2, h = tmp->getHeight() + 2; if(emitFocusEvents) tmp->receivedFocus(); @@ -551,7 +552,7 @@ bool StaticTextWidget::setUrl(const string& url, const string& label, // find end of URL for(size_t i = start; i < _label.size(); ++i) { - char ch = _label[i]; + const char ch = _label[i]; if(ch == ' ' || ch == ')' || ch == '>') { @@ -570,7 +571,7 @@ bool StaticTextWidget::setUrl(const string& url, const string& label, if(len) { - setLink(start, int(len), true); + setLink(start, static_cast(len), true); setCmd(kOpenUrlCmd); return true; } @@ -773,7 +774,7 @@ void ButtonWidget::drawWidget(bool hilite) int x = _x; if(_useBitmap) { - int xb = _useText ? _x + _bmx / 2 : _x + (_w - _bmw) / 2; + const int xb = _useText ? _x + _bmx / 2 : _x + (_w - _bmw) / 2; s.drawBitmap(_bitmap, xb, _y + (_h - _bmh) / 2, !isEnabled() ? _textcolorlo : hilite ? _textcolorhi : _textcolor, @@ -1043,7 +1044,8 @@ void SliderWidget::handleMouseMoved(int x, int y) // TODO: when the mouse is dragged outside the widget, the slider should // snap back to the old value. if(isEnabled() && _isDragging && - x >= int(_labelWidth - 4) && x <= int(_w - _valueLabelGap - _valueLabelWidth + 4)) + x >= static_cast(_labelWidth - 4) && + x <= static_cast(_w - _valueLabelGap - _valueLabelWidth + 4)) setValue(posToValue(x - _labelWidth)); } @@ -1121,7 +1123,7 @@ void SliderWidget::drawWidget(bool hilite) if(_labelWidth > 0) s.drawString(_font, _label, _x, _y + 2, _labelWidth, isEnabled() ? kTextColor : kColor); - int p = valueToPos(_value), + const int p = valueToPos(_value), h = _h - _font.getFontHeight() / 2 - 1, x = _x + _labelWidth, y = _y + 2 + _font.desc().ascent - (_font.getFontHeight() + 1) / 2 - 1; // align to bottom of font @@ -1136,7 +1138,7 @@ void SliderWidget::drawWidget(bool hilite) // Draw the 'tickmarks' for(int i = 1; i < _numIntervals; ++i) { - int xt = x + (_w - _labelWidth - _valueLabelGap - _valueLabelWidth) * i / _numIntervals - 1; + const int xt = x + (_w - _labelWidth - _valueLabelGap - _valueLabelWidth) * i / _numIntervals - 1; ColorId color = kNone; if(isEnabled()) @@ -1170,7 +1172,7 @@ int SliderWidget::valueToPos(int value) const { if(value < _valueMin) value = _valueMin; else if(value > _valueMax) value = _valueMax; - int range = std::max(_valueMax - _valueMin, 1); // don't divide by zero + const int range = std::max(_valueMax - _valueMin, 1); // don't divide by zero return ((_w - _labelWidth - _valueLabelGap - _valueLabelWidth - 2) * (value - _valueMin) / range); } @@ -1178,7 +1180,7 @@ int SliderWidget::valueToPos(int value) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int SliderWidget::posToValue(int pos) const { - int value = (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - _valueLabelGap - _valueLabelWidth - 4) + _valueMin; + const int value = (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - _valueLabelGap - _valueLabelWidth - 4) + _valueMin; // Scale the position to the correct interval (according to step value) return value - (value % _stepValue); diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index d9053d9a6..042f136c8 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -168,15 +168,15 @@ class Widget : public GuiObject static Widget* findWidgetInChain(Widget* start, int x, int y); /** Determine if 'find' is in the chain pointed to by 'start' */ - static bool isWidgetInChain(Widget* start, Widget* find); + static bool isWidgetInChain(Widget* start, const Widget* find); /** Determine if 'find' is in the widget array */ static bool isWidgetInChain(const WidgetArray& list, Widget* find); /** Select either previous, current, or next widget in chain to have focus, and deselects all others */ - static Widget* setFocusForChain(GuiObject* boss, WidgetArray& arr, - Widget* w, int direction, + static Widget* setFocusForChain(const GuiObject* boss, WidgetArray& arr, + const Widget* w, int direction, bool emitFocusEvents = true); /** Sets all widgets in this chain to be dirty (must be redrawn) */